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_cell(int channel, uint32_t size); 74 void dma_set_destination(int channel, uint32_t start_address, uint32_t size); 75 void dma_set_source(int channel, uint32_t start_address, uint32_t size); 76 77 void dma_set_transfer(int channel, 78 uint32_t source_start_address, uint32_t source_size, 79 uint32_t destination_start_address, uint32_t destination_size, 80 uint32_t cell_size); 81 82 int DMA_INT_FLAGS(int channel, uint8_t flags); 83 84 uint32_t DMA_IPC_PRI(int channel, uint8_t pri, uint8_t sub); 85 86 87 88 /* External interrupt configuration. */ 89 90 void int_init_interrupt(int int_num, uint8_t pri, uint8_t sub); 91 92 int INT_INT_FLAGS(int int_num, uint8_t flags); 93 94 uint32_t INT_IPC_PRI(int int_num, uint8_t pri, uint8_t sub); 95 uint32_t INT_IPC_REG(int int_num); 96 97 98 99 /* Output compare configuration. */ 100 101 void oc_init(int unit, uint8_t mode, int timer); 102 103 void oc_init_interrupt(int unit, uint8_t pri, uint8_t sub); 104 105 void oc_on(int unit); 106 107 void oc_set_pulse(int unit, uint32_t start); 108 109 void oc_set_pulse_end(int unit, uint32_t end); 110 111 int OC_INT_FLAGS(int unit, uint8_t flags); 112 113 uint32_t OC_IPC_PRI(int unit, uint8_t pri, uint8_t sub); 114 uint32_t OC_IPC_REG(int unit); 115 116 117 118 /* Parallel mode configuration. */ 119 120 void init_pm(void); 121 122 void pm_init(int port, uint8_t mode); 123 124 void pm_init_interrupt(int port, uint8_t pri, uint8_t sub); 125 126 void pm_off(int port); 127 128 void pm_on(int port); 129 130 void pm_set_output(int port, int write_enable, int read_enable); 131 132 int PM_INT_FLAGS(int port, uint8_t flags); 133 134 uint32_t PM_IPC_PRI(int port, uint8_t pri, uint8_t sub); 135 uint32_t PM_IPC_REG(int port); 136 137 138 139 /* Timer configuration. */ 140 141 void timer_init(int timer, uint8_t prescale, uint16_t limit); 142 143 void timer_init_interrupt(int timer, uint8_t pri, uint8_t sub); 144 145 int timer_interrupt_number(int timer); 146 147 void timer_on(int timer); 148 149 int TIMER_INT_FLAGS(int timer, uint8_t flags); 150 151 uint32_t TIMER_IPC_PRI(int timer, uint8_t pri, uint8_t sub); 152 uint32_t TIMER_IPC_REG(int timer); 153 154 155 156 /* UART configuration. */ 157 158 void uart_init(int uart, int fpb, uint32_t baudrate); 159 160 void uart_init_interrupt(int uart, uint8_t conditions, 161 uint8_t pri, uint8_t sub); 162 163 void uart_on(int uart); 164 165 int UART_INT_FLAGS(int uart, uint8_t flags); 166 167 uint32_t UART_IPC_PRI(int uart, uint8_t pri, uint8_t sub); 168 uint32_t UART_IPC_REG(int uart); 169 170 #endif /* __INIT_H__ */