1 /* 2 * PIC32 peripheral configuration and initialisation. 3 * 4 * Copyright (C) 2017, 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 __INIT_H__ 21 #define __INIT_H__ 22 23 #include "pic32_c.h" 24 25 26 27 /* Basic initialisation. */ 28 29 void init_memory(void); 30 void init_pins(void); 31 void init_outputs(void); 32 33 34 35 /* Peripheral pin configuration. */ 36 37 void lock_config(void); 38 void unlock_config(void); 39 40 41 42 /* Convenience operations. */ 43 44 void interrupts_on(void); 45 46 47 48 /* DMA configuration. */ 49 50 void init_dma(void); 51 52 void dma_init(int channel, uint8_t pri); 53 54 void dma_init_interrupt(int channel, uint8_t conditions, 55 uint8_t pri, uint8_t sub); 56 57 void dma_off(int channel); 58 59 void dma_on(int channel); 60 61 void dma_set_auto_enable(int channel, int enable); 62 63 void dma_set_chaining(int channel, enum dma_chain chain); 64 65 void dma_set_enable(int channel, int enable); 66 67 void dma_set_interrupt(int channel, uint8_t int_num, int enable); 68 69 void dma_set_interrupt_enable(int channel, int enable); 70 71 void dma_set_receive_events(int channel, int enable); 72 73 void dma_set_transfer(int channel, 74 uint32_t source_start_address, uint16_t source_size, 75 uint32_t destination_start_address, uint16_t destination_size, 76 uint16_t cell_size); 77 78 int DMA_INT_FLAGS(int channel, uint8_t flags); 79 80 uint32_t DMA_IPC_PRI(int channel, uint8_t pri, uint8_t sub); 81 82 83 84 /* External interrupt configuration. */ 85 86 void int_init_interrupt(int int_num, uint8_t pri, uint8_t sub); 87 88 int INT_INT_FLAGS(int int_num, uint8_t flags); 89 90 uint32_t INT_IPC_PRI(int int_num, uint8_t pri, uint8_t sub); 91 uint32_t INT_IPC_REG(int int_num); 92 93 94 95 /* Output compare configuration. */ 96 97 void oc_init(int unit, uint8_t mode, int timer); 98 99 void oc_init_interrupt(int unit, uint8_t pri, uint8_t sub); 100 101 void oc_on(int unit); 102 103 void oc_set_pulse(int unit, uint32_t start); 104 105 void oc_set_pulse_end(int unit, uint32_t end); 106 107 int OC_INT_FLAGS(int unit, uint8_t flags); 108 109 uint32_t OC_IPC_PRI(int unit, uint8_t pri, uint8_t sub); 110 uint32_t OC_IPC_REG(int unit); 111 112 113 114 /* Parallel mode configuration. */ 115 116 void init_pm(void); 117 118 void pm_init(int port, uint8_t mode); 119 120 void pm_init_interrupt(int port, uint8_t pri, uint8_t sub); 121 122 void pm_off(int port); 123 124 void pm_on(int port); 125 126 void pm_set_output(int port, int write_enable, int read_enable); 127 128 int PM_INT_FLAGS(int port, uint8_t flags); 129 130 uint32_t PM_IPC_PRI(int port, uint8_t pri, uint8_t sub); 131 uint32_t PM_IPC_REG(int port); 132 133 134 135 /* Timer configuration. */ 136 137 void timer_init(int timer, uint8_t prescale, uint16_t limit); 138 139 void timer_init_interrupt(int timer, uint8_t pri, uint8_t sub); 140 141 void timer_on(int timer); 142 143 int TIMER_INT_FLAGS(int timer, uint8_t flags); 144 145 uint32_t TIMER_IPC_PRI(int timer, uint8_t pri, uint8_t sub); 146 uint32_t TIMER_IPC_REG(int timer); 147 148 149 150 /* UART configuration. */ 151 152 void uart_init(int uart, uint32_t baudrate); 153 154 void uart_init_interrupt(int uart, uint8_t conditions, 155 uint8_t pri, uint8_t sub); 156 157 void uart_on(int uart); 158 159 int UART_INT_FLAGS(int uart, uint8_t flags); 160 161 uint32_t UART_IPC_PRI(int uart, uint8_t pri, uint8_t sub); 162 uint32_t UART_IPC_REG(int uart); 163 164 #endif /* __INIT_H__ */