paul@15 | 1 | /* |
paul@15 | 2 | * PIC32 peripheral configuration and initialisation. |
paul@15 | 3 | * |
paul@15 | 4 | * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> |
paul@15 | 5 | * |
paul@15 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@15 | 7 | * it under the terms of the GNU General Public License as published by |
paul@15 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@15 | 9 | * (at your option) any later version. |
paul@15 | 10 | * |
paul@15 | 11 | * This program is distributed in the hope that it will be useful, |
paul@15 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@15 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@15 | 14 | * GNU General Public License for more details. |
paul@15 | 15 | * |
paul@15 | 16 | * You should have received a copy of the GNU General Public License |
paul@15 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@15 | 18 | */ |
paul@15 | 19 | |
paul@0 | 20 | #ifndef __INIT_H__ |
paul@0 | 21 | #define __INIT_H__ |
paul@0 | 22 | |
paul@10 | 23 | #include "pic32_c.h" |
paul@10 | 24 | |
paul@15 | 25 | |
paul@15 | 26 | |
paul@0 | 27 | /* Basic initialisation. */ |
paul@0 | 28 | |
paul@0 | 29 | void init_memory(void); |
paul@0 | 30 | void init_pins(void); |
paul@0 | 31 | void init_outputs(void); |
paul@0 | 32 | |
paul@15 | 33 | |
paul@15 | 34 | |
paul@0 | 35 | /* Peripheral pin configuration. */ |
paul@0 | 36 | |
paul@0 | 37 | void config_uart(void); |
paul@0 | 38 | void lock_config(void); |
paul@0 | 39 | void unlock_config(void); |
paul@0 | 40 | |
paul@15 | 41 | |
paul@15 | 42 | |
paul@0 | 43 | /* Convenience operations. */ |
paul@0 | 44 | |
paul@0 | 45 | void interrupts_on(void); |
paul@0 | 46 | |
paul@15 | 47 | |
paul@15 | 48 | |
paul@3 | 49 | /* DMA configuration. */ |
paul@3 | 50 | |
paul@3 | 51 | void init_dma(void); |
paul@3 | 52 | |
paul@10 | 53 | void dma_init(int channel, uint8_t pri); |
paul@10 | 54 | |
paul@10 | 55 | void dma_set_auto_enable(int channel, int auto_enable); |
paul@10 | 56 | |
paul@10 | 57 | void dma_set_chaining(int channel, enum dma_chain chain); |
paul@3 | 58 | |
paul@3 | 59 | void dma_init_interrupt(int channel, uint8_t conditions, |
paul@7 | 60 | uint8_t pri, uint8_t sub); |
paul@3 | 61 | |
paul@3 | 62 | void dma_on(int channel); |
paul@3 | 63 | |
paul@3 | 64 | void dma_set_interrupt(int channel, uint8_t int_num, int enable); |
paul@0 | 65 | |
paul@3 | 66 | void dma_set_transfer(int channel, |
paul@3 | 67 | uint32_t source_start_address, uint16_t source_size, |
paul@3 | 68 | uint32_t destination_start_address, uint16_t destination_size, |
paul@3 | 69 | uint16_t cell_size); |
paul@3 | 70 | |
paul@10 | 71 | int DMA_INT_FLAGS(int channel, uint8_t flags); |
paul@10 | 72 | |
paul@7 | 73 | uint32_t DMA_IPC_PRI(int channel, uint8_t pri, uint8_t sub); |
paul@7 | 74 | |
paul@15 | 75 | |
paul@15 | 76 | |
paul@15 | 77 | /* Output compare configuration. */ |
paul@7 | 78 | |
paul@14 | 79 | void oc_init(int unit, uint8_t mode, int timer); |
paul@14 | 80 | |
paul@14 | 81 | void oc_set_pulse(int unit, uint32_t start); |
paul@14 | 82 | |
paul@14 | 83 | void oc_set_pulse_end(int unit, uint32_t end); |
paul@14 | 84 | |
paul@14 | 85 | void oc_init_interrupt(int unit, uint8_t pri, uint8_t sub); |
paul@14 | 86 | |
paul@14 | 87 | void oc_on(int unit); |
paul@14 | 88 | |
paul@14 | 89 | int OC_INT_FLAGS(int unit, uint8_t flags); |
paul@14 | 90 | |
paul@14 | 91 | uint32_t OC_IPC_PRI(int unit, uint8_t pri, uint8_t sub); |
paul@14 | 92 | uint32_t OC_IPC_REG(int unit); |
paul@14 | 93 | |
paul@15 | 94 | |
paul@15 | 95 | |
paul@14 | 96 | /* Timer configuration. */ |
paul@14 | 97 | |
paul@7 | 98 | void timer_init(int timer, uint8_t prescale, uint16_t limit); |
paul@7 | 99 | |
paul@7 | 100 | void timer_init_interrupt(int timer, uint8_t pri, uint8_t sub); |
paul@7 | 101 | |
paul@7 | 102 | void timer_on(int timer); |
paul@7 | 103 | |
paul@10 | 104 | int TIMER_INT_FLAGS(int timer, uint8_t flags); |
paul@10 | 105 | |
paul@7 | 106 | uint32_t TIMER_IPC_PRI(int timer, uint8_t pri, uint8_t sub); |
paul@7 | 107 | uint32_t TIMER_IPC_REG(int timer); |
paul@7 | 108 | |
paul@15 | 109 | |
paul@15 | 110 | |
paul@3 | 111 | /* UART configuration. */ |
paul@3 | 112 | |
paul@7 | 113 | void uart_init(int uart, uint32_t baudrate); |
paul@3 | 114 | |
paul@7 | 115 | void uart_init_interrupt(int uart, uint8_t conditions, |
paul@7 | 116 | uint8_t pri, uint8_t sub); |
paul@3 | 117 | |
paul@7 | 118 | void uart_on(int uart); |
paul@3 | 119 | |
paul@10 | 120 | int UART_INT_FLAGS(int uart, uint8_t flags); |
paul@10 | 121 | |
paul@7 | 122 | uint32_t UART_IPC_PRI(int uart, uint8_t pri, uint8_t sub); |
paul@7 | 123 | uint32_t UART_IPC_REG(int uart); |
paul@3 | 124 | |
paul@0 | 125 | #endif /* __INIT_H__ */ |