1 /* 2 * PIC32 peripheral access utilities. 3 * 4 * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __ASSEMBLER__ 21 22 #ifndef __PIC32_C_H__ 23 #define __PIC32_C_H__ 24 25 #include <stdint.h> 26 #include "mips.h" 27 #include "pic32.h" 28 29 30 31 /* Access. */ 32 33 #define REG(mem) *((volatile uint32_t *) (mem)) 34 35 36 37 /* Bit clearing, setting and inverting. */ 38 39 static inline void CLR_REG(uint32_t mem, uint32_t val) 40 { 41 REG(mem + CLR) = val; 42 } 43 44 static inline void SET_REG(uint32_t mem, uint32_t val) 45 { 46 REG(mem + SET) = val; 47 } 48 49 static inline void INV_REG(uint32_t mem, uint32_t val) 50 { 51 REG(mem + INV) = val; 52 } 53 54 55 56 /* Address translation. */ 57 58 static inline uint32_t PHYSICAL(uint32_t addr) 59 { 60 return ((uint32_t) addr) - KSEG0_BASE; 61 } 62 63 static inline uint32_t HW_PHYSICAL(uint32_t addr) 64 { 65 return ((uint32_t) addr) - KSEG1_BASE; 66 } 67 68 69 70 /* Register collection access. */ 71 72 static inline uint32_t DMA_REG(int channel, uint32_t reg) 73 { 74 return DCHBASE + reg + (channel - DCHMIN) * DCHSTEP; 75 } 76 77 static inline uint32_t OC_REG(int unit, uint32_t reg) 78 { 79 return OCBASE + reg + (unit - OCMIN) * OCSTEP; 80 } 81 82 static inline uint32_t TIMER_REG(int timer, uint32_t reg) 83 { 84 return TIMERBASE + reg + (timer - TIMERMIN) * TIMERSTEP; 85 } 86 87 static inline uint32_t UART_REG(int uart, uint32_t reg) 88 { 89 return UARTBASE + reg + (uart - UARTMIN) * UARTSTEP; 90 } 91 92 93 94 /* Convenience types. */ 95 96 enum dma_chain 97 { 98 dma_chain_none, 99 dma_chain_next, 100 dma_chain_previous, 101 }; 102 103 #endif /* __PIC32_C_H__ */ 104 105 #endif /* __ASSEMBLER__ */