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 /* Output compare configuration. */ 85 86 void oc_init(int unit, uint8_t mode, int timer); 87 88 void oc_init_interrupt(int unit, uint8_t pri, uint8_t sub); 89 90 void oc_on(int unit); 91 92 void oc_set_pulse(int unit, uint32_t start); 93 94 void oc_set_pulse_end(int unit, uint32_t end); 95 96 int OC_INT_FLAGS(int unit, uint8_t flags); 97 98 uint32_t OC_IPC_PRI(int unit, uint8_t pri, uint8_t sub); 99 uint32_t OC_IPC_REG(int unit); 100 101 102 103 /* Timer configuration. */ 104 105 void timer_init(int timer, uint8_t prescale, uint16_t limit); 106 107 void timer_init_interrupt(int timer, uint8_t pri, uint8_t sub); 108 109 void timer_on(int timer); 110 111 int TIMER_INT_FLAGS(int timer, uint8_t flags); 112 113 uint32_t TIMER_IPC_PRI(int timer, uint8_t pri, uint8_t sub); 114 uint32_t TIMER_IPC_REG(int timer); 115 116 117 118 /* UART configuration. */ 119 120 void uart_init(int uart, uint32_t baudrate); 121 122 void uart_init_interrupt(int uart, uint8_t conditions, 123 uint8_t pri, uint8_t sub); 124 125 void uart_on(int uart); 126 127 int UART_INT_FLAGS(int uart, uint8_t flags); 128 129 uint32_t UART_IPC_PRI(int uart, uint8_t pri, uint8_t sub); 130 uint32_t UART_IPC_REG(int uart); 131 132 #endif /* __INIT_H__ */