Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
cascoda_chili_gpio.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 /*
29  * Cascoda Interface to Vendor BSP/Library Support Package.
30  * MCU: Nuvoton Nano120
31  * MODULE: Chili 1 (1.2, 1.3)
32  * Module Pin and GPIO Mapping
33  */
36 #include "cascoda_chili_config.h"
37 
38 #ifndef CASCODA_CHILI_GPIO_H
39 #define CASCODA_CHILI_GPIO_H
40 
41 /******************************************************************************/
42 /* Helper Macros for Port Handling ******/
43 /******************************************************************************/
44 #ifndef GPIO_BASE
45 #define GPIO_BASE GPIOA_BASE
46 #endif
47 /* gives port (GPIO_T *), i.e. PA */
48 #define MGPIO_PORT(portnum) ((GPIO_T *)(GPIO_BASE + (portnum * 0x40UL)))
49 /* gives port pin, i.e. PA0 */
50 #define MGPIO_PORTPIN(portnum, pin) (*((volatile uint32_t *)((GPIO_PIN_DATA_BASE + (0x40 * (portnum))) + ((pin) << 2))))
51 /* gives register bit mask for port pin x */
52 #define BITMASK(x) (1UL << x)
53 
54 /* port numbers */
55 typedef enum enPortnum
56 {
57  PN_A = 0,
58  PN_B = 1,
59  PN_C = 2,
60  PN_D = 3,
61  PN_E = 4,
62  PN_F = 5,
63  PN_NA = 255 /* not available */
65 
66 /* MFP definitions (need to be checked when changing pins or package!) */
67 #define PMFP_GPIO 0
68 #define PMFP_SPI 3
69 #define PMFP_UART 1
70 #define PMFP_ADC 1
71 
72 /******************************************************************************/
73 /****** Hard Connected Ports / Pins ******/
74 /******************************************************************************/
75 /****** Use CASCODA_CHILI_REV to specify Chili Rev. 1.x ******/
76 /******************************************************************************/
77 /*
78  * PORTNAME_PORT: port module, i.e. PA
79  * PORTNAME_PNUM: port numbers, 0=PA, 1=PB, 2=PC etc.
80  * PORTNAME_PIN: port pin, i.e. 20 for PA.20
81  * PORTNAME_PVAL: port value for r/w, i.e. PA20
82  */
83 /* ZIG_RESET: PA.11 */
84 #define ZIG_RESET_PORT PA
85 #define ZIG_RESET_PNUM PN_A
86 #define ZIG_RESET_PIN 11
87 #define ZIG_RESET_PVAL PA11
88 /* ZIG_IRQB: PA.10 */
89 #define ZIG_IRQB_PORT PA
90 #define ZIG_IRQB_PNUM PN_A
91 #define ZIG_IRQB_PIN 10
92 #define ZIG_IRQB_PVAL PA10
93 #define ZIG_IRQB_IRQn GPABC_IRQn
94 /* SPI_MOSI: PB.0 */
95 #define SPI_MOSI_PORT PB
96 #define SPI_MOSI_PNUM PN_B
97 #define SPI_MOSI_PIN 0
98 #define SPI_MOSI_PVAL PB0
99 /* SPI_MISO: PB.1 */
100 #define SPI_MISO_PORT PB
101 #define SPI_MISO_PNUM PN_B
102 #define SPI_MISO_PIN 1
103 #define SPI_MISO_PVAL PB1
104 /* SPI_SCLK: PB.2 */
105 #define SPI_SCLK_PORT PB
106 #define SPI_SCLK_PNUM PN_B
107 #define SPI_SCLK_PIN 2
108 #define SPI_SCLK_PVAL PB2
109 /* SPI_CS: PB.3 */
110 #define SPI_CS_PORT PB
111 #define SPI_CS_PNUM PN_B
112 #define SPI_CS_PIN 3
113 #define SPI_CS_PVAL PB3
114 /* CHARGE_STAT: PA.12 */
115 #define CHARGE_STAT_PORT PA
116 #define CHARGE_STAT_PNUM PN_A
117 #define CHARGE_STAT_PIN 12
118 #define CHARGE_STAT_PVAL PA12
119 /* PROGRAM: PB.15 */
120 #if (CASCODA_CHILI_REV == 3)
121 #define PROGRAM_PORT PB
122 #define PROGRAM_PNUM PN_B
123 #define PROGRAM_PIN 15
124 #define PROGRAM_PVAL PB15
125 #endif
126 /* VOLTS_TEST: PB.12 */
127 #define VOLTS_TEST_PORT PB
128 #define VOLTS_TEST_PNUM PN_B
129 #define VOLTS_TEST_PIN 12
130 #define VOLTS_TEST_PVAL PB12
131 /* VOLTS: PA.0 */
132 #define VOLTS_PORT PA
133 #define VOLTS_PNUM PN_A
134 #define VOLTS_PIN 0
135 #define VOLTS_PVAL PA0
136 /* UART_TXD: PB.5 */
137 #if defined(USE_UART)
138 #define UART_TXD_PORT PB
139 #define UART_TXD_PNUM PN_B
140 #define UART_TXD_PIN 5
141 #define UART_TXD_PVAL PB5
142 #endif
143 /* UART_RXD: PB.4 */
144 #if defined(USE_UART)
145 #define UART_RXD_PORT PB
146 #define UART_RXD_PNUM PN_B
147 #define UART_RXD_PIN 4
148 #define UART_RXD_PVAL PB4
149 #endif
150 /* BATT_ON: PA.8 */
151 #if (CASCODA_CHILI_REV == 2)
152 #define BATT_ON_PORT PA
153 #define BATT_ON_PNUM PN_A
154 #define BATT_ON_PIN 8
155 #define BATT_ON_PVAL PA8
156 #endif
157 
158 #if (CASCODA_CHILI_REV != 2) && (CASCODA_CHILI_REV != 3)
159 #error "Unsupported Chili Revision"
160 #endif
161 
162 /******************************************************************************/
163 /****** Functions ******/
164 /******************************************************************************/
165 
166 /******************************************************************************/
167 /***************************************************************************/
177 
178 /******************************************************************************/
179 /***************************************************************************/
188 
189 /******************************************************************************/
190 /***************************************************************************/
199 
200 /******************************************************************************/
201 /***************************************************************************/
210 
211 /******************************************************************************/
212 /***************************************************************************/
220 void CHILI_ModuleSetMFP(enPortnum portnum, u8_t portbit, u8_t func);
221 
222 /******************************************************************************/
223 /***************************************************************************/
227 void CHILI_ModulePowerDownGPIOs(void);
228 
229 /******************************************************************************/
230 /***************************************************************************/
234 void CHILI_ModulePowerUpGPIOs(void);
235 
236 /******************************************************************************/
237 /***************************************************************************/
242 
243 #endif /* CASCODA_CHILI_GPIO_H */
Declaration of platform abstraction functions.
Type definitions used by Cascoda baremetal drivers.
unsigned char u8_t
Definition: cascoda_types.h:46
void CHILI_ModuleSetMFP(enPortnum portnum, u8_t portbit, u8_t func)
Sets MFP Functionality.
Definition: cascoda_gpio_chili.c:193
u8_t CHILI_ModuleGetPortBitFromPin(u8_t mpin)
Gets pin number from module pin.
Definition: cascoda_gpio_chili.c:154
enPortnum
Definition: cascoda_chili_gpio.h:56
@ PN_NA
Definition: cascoda_chili_gpio.h:63
@ PN_A
Definition: cascoda_chili_gpio.h:57
@ PN_D
Definition: cascoda_chili_gpio.h:60
@ PN_F
Definition: cascoda_chili_gpio.h:62
@ PN_E
Definition: cascoda_chili_gpio.h:61
@ PN_B
Definition: cascoda_chili_gpio.h:58
@ PN_C
Definition: cascoda_chili_gpio.h:59
u8_t CHILI_ModuleGetIndexFromPin(u8_t mpin)
Gets List Index from Module Pin.
Definition: cascoda_gpio_chili.c:180
void CHILI_ModulePowerUpGPIOs(void)
Re-configure GPIOs for PowerUp.
Definition: cascoda_gpio_chili.c:252
void CHILI_ModulePowerDownGPIOs(void)
Re-configure GPIOs for PowerDown.
Definition: cascoda_gpio_chili.c:231
void CHILI_ModulePinIRQHandler(enPortnum portnum)
ISR: Module Pin Interrupt Handling.
Definition: cascoda_gpio_chili.c:271
u8_t CHILI_ModuleGetPortNumFromPin(u8_t mpin)
Gets port number from module pin.
Definition: cascoda_gpio_chili.c:167
u8_t CHILI_ModuleGetPinFromPort(enPortnum portnum, u8_t portbit)
Gets Module Pin from List index.
Definition: cascoda_gpio_chili.c:141