diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/GPIO.c b/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/GPIO.c deleted file mode 100644 index dd4bb55b1a..0000000000 --- a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/GPIO.c +++ /dev/null @@ -1,762 +0,0 @@ -/******************** (C) COPYRIGHT 2017 SONiX ******************************* -* COMPANY: SONiX -* DATE: 2017/07 -* AUTHOR: SA1 -* IC: SN32F240B -* DESCRIPTION: GPIO related functions. -*____________________________________________________________________________ -* REVISION Date User Description -* 1.0 2017/07/07 SA1 1. First release -* -*____________________________________________________________________________ -* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS TIME TO MARKET. -* SONiX SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL -* DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH SOFTWARE -* AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN -* IN CONNECTION WITH THEIR PRODUCTS. -*****************************************************************************/ - -/*_____ I N C L U D E S ____________________________________________________*/ -#include "GPIO.h" - - -/*_____ D E C L A R A T I O N S ____________________________________________*/ - - -/*_____ D E F I N I T I O N S ______________________________________________*/ - - -/*_____ M A C R O S ________________________________________________________*/ - - -/*_____ F U N C T I O N S __________________________________________________*/ - -/***************************************************************************** -* Function : GPIO_Init -* Description : GPIO Init -* Input : None -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -void GPIO_Init (void) -{ - //P2.0 as Input - GPIO_Mode (GPIO_PORT2, GPIO_PIN0, GPIO_MODE_INPUT); - //P2.0 need to add External Pull-down Resistors for Demo rising edge trigger - //P2.0 as rising edge - GPIO_P2Trigger(GPIO_PIN0, GPIO_IS_EDGE, GPIO_IBS_EDGE_TRIGGER, GPIO_IEV_RISING_EDGE); - GPIO_Interrupt(GPIO_PORT2, GPIO_PIN0, GPIO_IE_EN); - - //P2.1 as Input Pull-up - GPIO_Mode (GPIO_PORT2, GPIO_PIN1, GPIO_MODE_INPUT); - GPIO_Config (GPIO_PORT2, GPIO_PIN1, GPIO_CFG_PULL_UP); - //P2.1 as falling edge - GPIO_P2Trigger(GPIO_PIN1, GPIO_IS_EDGE, GPIO_IBS_EDGE_TRIGGER, GPIO_IEV_FALLING_EDGE); - GPIO_Interrupt(GPIO_PORT2, GPIO_PIN1, GPIO_IE_EN); - - //P2.2 as Input Pull-up - GPIO_Mode (GPIO_PORT2, GPIO_PIN2, GPIO_MODE_INPUT); - GPIO_Config (GPIO_PORT2, GPIO_PIN2, GPIO_CFG_PULL_UP); - //P2.2 as both edge - GPIO_P2Trigger(GPIO_PIN2, GPIO_IS_EDGE, GPIO_IBS_BOTH_EDGE_TRIGGER, GPIO_IEV_RISING_EDGE); - GPIO_Interrupt(GPIO_PORT2, GPIO_PIN2, GPIO_IE_EN); - - //P2.3 as Input - GPIO_Mode (GPIO_PORT2, GPIO_PIN3, GPIO_MODE_INPUT); - //P2.3 need to add External Pull-down Resistors for Demo high level trigger - //P2.3 as high level - GPIO_P2Trigger(GPIO_PIN3, GPIO_IS_EVENT, GPIO_IBS_EDGE_TRIGGER, GPIO_IEV_RISING_EDGE); - GPIO_Interrupt(GPIO_PORT2, GPIO_PIN3, GPIO_IE_EN); - - //P2.4 as Input Pullup - GPIO_Mode (GPIO_PORT2, GPIO_PIN4, GPIO_MODE_INPUT); - GPIO_Config (GPIO_PORT2, GPIO_PIN4, GPIO_CFG_PULL_UP); - //P2.4 as low level trigger - GPIO_P2Trigger(GPIO_PIN4, GPIO_IS_EVENT, GPIO_IBS_EDGE_TRIGGER, GPIO_IEV_FALLING_EDGE); - GPIO_Interrupt(GPIO_PORT2, GPIO_PIN4, GPIO_IE_EN); - - //P2.5 as Output Low - GPIO_Mode (GPIO_PORT2, GPIO_PIN5, GPIO_MODE_OUTPUT); - GPIO_Clr (GPIO_PORT2, GPIO_PIN5); -} - -/***************************************************************************** -* Function : GPIO_Mode -* Description : set GPIO as input or output -* Input : port_number - GPIO0, GPIO1, GPIO2, GPIO3 - pin_number - GPIO_PIN0, 1, 2, ...,15 - mode - 0 as Input - 1 as output -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -void GPIO_Mode(uint32_t port_number, uint32_t pin_number, uint32_t mode) -{ - uint32_t wGpiomode=0; - switch(port_number){ - case 0: - wGpiomode=(uint32_t)SN_GPIO0->MODE; - wGpiomode&=~(1<<(uint32_t) pin_number); - wGpiomode|=(mode<<(uint32_t) pin_number); - SN_GPIO0->MODE=wGpiomode; - wGpiomode=SN_GPIO0->MODE; //for check - break; - case 1: - wGpiomode=(uint32_t)SN_GPIO1->MODE; - wGpiomode&=~(1<<(uint32_t) pin_number); - wGpiomode|=(mode<<(uint32_t) pin_number); - SN_GPIO1->MODE=wGpiomode; - wGpiomode=SN_GPIO1->MODE; //for check - break; - case 2: - wGpiomode=(uint32_t)SN_GPIO2->MODE; - wGpiomode&=~(1<<(uint32_t) pin_number); - wGpiomode|=(mode<<(uint32_t) pin_number); - SN_GPIO2->MODE=wGpiomode; - wGpiomode=SN_GPIO2->MODE; //for check - break; - case 3: - wGpiomode=(uint32_t)SN_GPIO3->MODE; - wGpiomode&=~(1<<(uint32_t) pin_number); - wGpiomode|=(mode<<(uint32_t) pin_number); - SN_GPIO3->MODE=wGpiomode; - wGpiomode=SN_GPIO3->MODE; //for check - break; - default: - break; - } - return; -} - -/***************************************************************************** -* Function : GPIO_Set -* Description : set GPIO high -* Input : port_number - GPIO0, GPIO1, GPIO2, GPIO3 - pin_number - GPIO_PIN0, 1, 2, ...,15 -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -void GPIO_Set(uint32_t port_number, uint32_t pin_number) -{ - switch(port_number){ - case 0: - SN_GPIO0->BSET|=(1<BSET|=(1<BSET|=(1<BSET|=(1<BCLR|=(1<BCLR|=(1<BCLR|=(1<BCLR|=(1<IS; - wGpiovalue&=~(1<IS=wGpiovalue; - wGpiovalue=SN_GPIO0->IBS; - wGpiovalue&=~(1<IBS=wGpiovalue; - wGpiovalue=SN_GPIO0->IEV; - wGpiovalue&=~(1<IEV=wGpiovalue; -} - -/***************************************************************************** -* Function : GPIO_P1Trigger -* Description : set GPIO as edge or level trigger -* Input : port_number - GPIO0, GPIO1, GPIO2, GPIO3 - pin_number - GPIO_PIN0, 1, 2, ...,15 - is - 0: edge sensitive - 1: event sensitive - ibs - 0: edge trigger - 1: both edge trigger - iev - 0: Rising edges or HIGH level trigger - 1: Falling edges or LOW level trigger -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -void GPIO_P1Trigger(uint32_t pin_number, uint32_t is, uint32_t ibs,uint32_t iev) -{ - uint32_t wGpiovalue=0; - - wGpiovalue=SN_GPIO1->IS; - wGpiovalue&=~(1<IS=wGpiovalue; - wGpiovalue=SN_GPIO1->IBS; - wGpiovalue&=~(1<IBS=wGpiovalue; - wGpiovalue=SN_GPIO1->IEV; - wGpiovalue&=~(1<IEV=wGpiovalue; -} - -/***************************************************************************** -* Function : GPIO_P2Trigger -* Description : set GPIO as edge or level trigger -* Input : port_number - GPIO0, GPIO1, GPIO2, GPIO3 - pin_number - GPIO_PIN0, 1, 2, ...,15 - is - 0: edge sensitive - 1: event sensitive - ibs - 0: edge trigger - 1: both edge trigger - iev - 0: Rising edges or HIGH level trigger - 1: Falling edges or LOW level trigger -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -void GPIO_P2Trigger(uint32_t pin_number, uint32_t is, uint32_t ibs,uint32_t iev) -{ - uint32_t wGpiovalue=0; - - wGpiovalue=SN_GPIO2->IS; - wGpiovalue&=~(1<IS=wGpiovalue; - wGpiovalue=SN_GPIO2->IBS; - wGpiovalue&=~(1<IBS=wGpiovalue; - wGpiovalue=SN_GPIO2->IEV; - wGpiovalue&=~(1<IEV=wGpiovalue; -} - -/***************************************************************************** -* Function : GPIO_P3Trigger -* Description : set GPIO as edge or level trigger -* Input : port_number - GPIO0, GPIO1, GPIO2, GPIO3 - pin_number - GPIO_PIN0, 1, 2, ...,15 - is - 0: edge sensitive - 1: event sensitive - ibs - 0: edge trigger - 1: both edge trigger - iev - 0: Rising edges or HIGH level trigger - 1: Falling edges or LOW level trigger -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -void GPIO_P3Trigger(uint32_t pin_number, uint32_t is, uint32_t ibs,uint32_t iev) -{ - uint32_t wGpiovalue=0; - - wGpiovalue=SN_GPIO3->IS; - wGpiovalue&=~(1<IS=wGpiovalue; - wGpiovalue=SN_GPIO3->IBS; - wGpiovalue&=~(1<IBS=wGpiovalue; - wGpiovalue=SN_GPIO3->IEV; - wGpiovalue&=~(1<IEV=wGpiovalue; -} - -/***************************************************************************** -* Function : GPIO_Interrupt -* Description : set GPIO interrupt and NVIC -* Input : port_number - GPIO0, GPIO1, GPIO2, GPIO3 - pin_number - GPIO_PIN0, 1, 2, ...,15 - enable - 0 as disable - 1 as enable -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -void GPIO_Interrupt(uint32_t port_number, uint32_t pin_number, uint32_t enable) -{ - switch(port_number){ - case 0: - //check SWD pin - if ((pin_number == GPIO_PIN8) || (pin_number == GPIO_PIN9)){ - if(SN_SYS0->SWDCTRL!=0x1) return; - } - SN_GPIO0->IC=0xFFFF; - SN_GPIO0->IE&=~(1<IE|=(enable<IC=0xFFFF; - SN_GPIO1->IE&=~(1<IE|=(enable<IC=0xFFFF; - SN_GPIO2->IE&=~(1<IE|=(enable<EXRSTCTRL!=1) return; - } - SN_GPIO3->IC=0xFFFF; - SN_GPIO3->IE&=~(1<IE|=(enable<IC=(1<IC=(1<IC=(1<IC=(1<CFG&=~(3<CFG|=(value<CFG&=~(3<CFG|=(value<CFG&=~(3<CFG|=(value<CFG&=~(3<CFG|=(value<RIS >>pin_number); - break; - case 1: - wreturn_value=(SN_GPIO1->RIS >>pin_number); - break; - case 2: - wreturn_value=(SN_GPIO2->RIS >>pin_number); - break; - case 3: - wreturn_value=(SN_GPIO3->RIS >>pin_number); - break; - default: - break; - } - wreturn_value&=0x01; - return wreturn_value; -} - - -/***************************************************************************** -* Function : P0_IRQHandler -* Description : Set GPIO P0 IRQ -* Input : None -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -__irq void P0_IRQHandler(void) -{ - if (GPIO_IntStatus(GPIO_PORT0,GPIO_PIN0)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN0); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN1)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN1); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN2)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN2); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN3)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN3); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN4)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN4); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN5)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN5); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN6)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN6); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN7)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN7); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN8)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN8); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN9)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN9); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN10)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN10); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN11)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN11); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN12)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN12); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN13)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN13); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN14)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN14); - } - else if(GPIO_IntStatus(GPIO_PORT0,GPIO_PIN15)==1) - { - GPIO_IntClr(GPIO_PORT0,GPIO_PIN15); - } -} - -/***************************************************************************** -* Function : P1_IRQHandler -* Description : Set GPIO P1 IRQ -* Input : None -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -__irq void P1_IRQHandler(void) -{ - if (GPIO_IntStatus(GPIO_PORT1,GPIO_PIN0)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN0); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN1)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN1); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN2)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN2); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN3)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN3); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN4)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN4); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN5)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN5); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN6)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN6); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN7)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN7); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN8)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN8); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN9)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN9); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN10)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN10); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN11)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN11); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN12)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN12); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN13)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN13); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN14)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN14); - } - else if(GPIO_IntStatus(GPIO_PORT1,GPIO_PIN15)==1) - { - GPIO_IntClr(GPIO_PORT1,GPIO_PIN15); - } -} - -/***************************************************************************** -* Function : P2_IRQHandler -* Description : Set GPIO P2 IRQ -* Input : None -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -__irq void P2_IRQHandler(void) -{ - if (GPIO_IntStatus(GPIO_PORT2,GPIO_PIN0)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN0); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN1)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN1); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN2)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN2); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN3)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN3); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN4)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN4); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN5)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN5); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN6)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN6); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN7)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN7); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN8)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN8); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN9)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN9); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN10)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN10); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN11)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN11); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN12)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN12); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN13)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN13); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN14)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN14); - } - else if(GPIO_IntStatus(GPIO_PORT2,GPIO_PIN15)==1) - { - GPIO_IntClr(GPIO_PORT2,GPIO_PIN15); - } -} - -/***************************************************************************** -* Function : P3_IRQHandler -* Description : Set GPIO P3 IRQ -* Input : None -* Output : None -* Return : None -* Note : None -*****************************************************************************/ -__irq void P3_IRQHandler(void) -{ - if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN3)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN3); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN4)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN4); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN5)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN5); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN6)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN6); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN7)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN7); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN8)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN8); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN9)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN9); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN10)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN10); - } - else if(GPIO_IntStatus(GPIO_PORT3,GPIO_PIN11)==1) - { - GPIO_IntClr(GPIO_PORT3,GPIO_PIN11); - } -} - diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/GPIO.h b/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/GPIO.h deleted file mode 100644 index 28f9941b7d..0000000000 --- a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/GPIO.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef __SN32F2XX_GPIO_H -#define __SN32F2XX_GPIO_H - -/*_____ I N C L U D E S ____________________________________________________*/ -#include - - -/*_____ D E F I N I T I O N S ______________________________________________*/ -/* -Base Address: 0x4004 4000 (GPIO 0) - 0x4004 6000 (GPIO 1) - 0x4004 8000 (GPIO 2) - 0x4004 A000 (GPIO 3) -*/ - -/* GPIO Port n Data register (0x00) */ - - -/* GPIO Port n Mode register (0x04) */ -#define GPIO_MODE_INPUT 0 -#define GPIO_MODE_OUTPUT 1 - - -/* GPIO Port n Configuration register (0x08) */ -#define GPIO_CFG_PULL_UP 0 -#define GPIO_CFG_INACTIVE_Schmitt_EN 2 -#define GPIO_CFG_INACTIVE_Schmitt_DIS 3 - -/* GPIO Port n Interrupt Sense register (0x0C) */ -#define GPIO_IS_EDGE 0 -#define GPIO_IS_EVENT 1 - - -/* GPIO Port n Interrupt Both-edge Sense registe (0x10) */ -#define GPIO_IBS_EDGE_TRIGGER 0 -#define GPIO_IBS_BOTH_EDGE_TRIGGER 1 - - -/* GPIO Port n Interrupt Event register (0x14) */ -#define GPIO_IEV_RISING_EDGE 0 -#define GPIO_IEV_FALLING_EDGE 1 - - -/* GPIO Port n Interrupt Enable register (0x18) */ -#define GPIO_IE_DIS 0 -#define GPIO_IE_EN 1 - - -/* GPIO Port n Raw Interrupt Status register (0x1C/0x20) */ -#define mskPIN0IF (0x1<<0) -#define mskPIN1IF (0x1<<1) -#define mskPIN2IF (0x1<<2) -#define mskPIN3IF (0x1<<3) -#define mskPIN4IF (0x1<<4) -#define mskPIN5IF (0x1<<5) -#define mskPIN6IF (0x1<<6) -#define mskPIN7IF (0x1<<7) -#define mskPIN8IF (0x1<<8) -#define mskPIN9IF (0x1<<9) -#define mskPIN10IF (0x1<<10) -#define mskPIN11IF (0x1<<11) -#define mskPIN12IF (0x1<<12) -#define mskPIN13IF (0x1<<13) -#define mskPIN14IF (0x1<<14) -#define mskPIN15IF (0x1<<15) - -/* GPIO Port Name Define */ -//GPIO name define -#define GPIO_PORT0 0 -#define GPIO_PORT1 1 -#define GPIO_PORT2 2 -#define GPIO_PORT3 3 - -/* GPIO Pin Name Define */ -#define GPIO_PIN0 0 -#define GPIO_PIN1 1 -#define GPIO_PIN2 2 -#define GPIO_PIN3 3 -#define GPIO_PIN4 4 -#define GPIO_PIN5 5 -#define GPIO_PIN6 6 -#define GPIO_PIN7 7 -#define GPIO_PIN8 8 -#define GPIO_PIN9 9 -#define GPIO_PIN10 10 -#define GPIO_PIN11 11 -#define GPIO_PIN12 12 -#define GPIO_PIN13 13 -#define GPIO_PIN14 14 -#define GPIO_PIN15 15 - - -/*_____ M A C R O S ________________________________________________________*/ - - -/*_____ D E C L A R A T I O N S ____________________________________________*/ -void GPIO_Init (void); -void GPIO_Mode(uint32_t port_number, uint32_t pin_number, uint32_t mode); -void GPIO_Set(uint32_t port_number, uint32_t pin_number); -void GPIO_Clr(uint32_t port_number, uint32_t pin_number); -void GPIO_P0Trigger(uint32_t pin_number, uint32_t is, uint32_t ibs,uint32_t iev); -void GPIO_P1Trigger(uint32_t pin_number, uint32_t is, uint32_t ibs,uint32_t iev); -void GPIO_P2Trigger(uint32_t pin_number, uint32_t is, uint32_t ibs,uint32_t iev); -void GPIO_P3Trigger(uint32_t pin_number, uint32_t is, uint32_t ibs,uint32_t iev); -void GPIO_Interrupt(uint32_t port_number, uint32_t pin_number, uint32_t enable); -void GPIO_IntClr(uint32_t port_number, uint32_t pin_number); -void GPIO_Config(uint32_t port_number, uint32_t pin_number, uint32_t value); -void GPIO_OpenDrain(uint32_t port_number, uint32_t pin_number, uint32_t value); -uint32_t GPIO_IntStatus(uint32_t port_number, uint32_t pin_number); -#endif /*__SN32F2XX_GPIO_H*/ diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.c b/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.c index a771c4bac2..0a0d87f7d4 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.c +++ b/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.c @@ -34,6 +34,10 @@ /* Driver exported variables. */ /*===========================================================================*/ +#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) +palevent_t _pal_events[TOTAL_PORTS * PAL_IOPORTS_WIDTH]; +#endif /* (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) */ + /*===========================================================================*/ /* Driver local variables and types. */ /*===========================================================================*/ @@ -42,17 +46,63 @@ /* Driver local functions. */ /*===========================================================================*/ -static void initgpio(SN_GPIO0_Type *gpiop, const sn32_gpio_setup_t *config) { - +static void initgpio(ioportid_t gpiop, const sn32_gpio_setup_t *config) { gpiop->DATA = config->data; gpiop->MODE = config->mode; gpiop->CFG = config->cfg; } +#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) +static void irq_handler(ioportid_t port, uint32_t offset) { + chSysLockFromISR(); + uint32_t ris = port->RIS; /* Get pending interrupts on this port. */ + port->IC = 0xFFFFFFFFU; /* Clear all pending interrupts on this port. */ + chSysUnlockFromISR(); + + /* invoke callbacks for pending interrupts */ + for (iopadid_t pad = 0; pad < PAL_IOPORTS_WIDTH; pad++) { + if (ris & (1 << pad)) { + _pal_isr_code(offset + pad); + } + } +} +#endif /* (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) */ + /*===========================================================================*/ /* Driver interrupt handlers. */ /*===========================================================================*/ +#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) +#if SN32_HAS_GPIOA +OSAL_IRQ_HANDLER(SN32_GPIOA_HANDLER) { + OSAL_IRQ_PROLOGUE(); + irq_handler(GPIOA, 0); + OSAL_IRQ_EPILOGUE(); +} +#endif +#if SN32_HAS_GPIOB +OSAL_IRQ_HANDLER(SN32_GPIOB_HANDLER) { + OSAL_IRQ_PROLOGUE(); + irq_handler(GPIOB, PAL_IOPORTS_WIDTH); + OSAL_IRQ_EPILOGUE(); +} +#endif +#if SN32_HAS_GPIOC +OSAL_IRQ_HANDLER(SN32_GPIOC_HANDLER) { + OSAL_IRQ_PROLOGUE(); + irq_handler(GPIOC, PAL_IOPORTS_WIDTH * 2); + OSAL_IRQ_EPILOGUE(); +} +#endif +#if SN32_HAS_GPIOD +OSAL_IRQ_HANDLER(SN32_GPIOD_HANDLER) { + OSAL_IRQ_PROLOGUE(); + irq_handler(GPIOD, PAL_IOPORTS_WIDTH * 3); + OSAL_IRQ_EPILOGUE(); +} +#endif +#endif /* (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) */ + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -67,6 +117,29 @@ static void initgpio(SN_GPIO0_Type *gpiop, const sn32_gpio_setup_t *config) { */ void _pal_lld_init(const PALConfig *config) { +#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) +#if SN32_HAS_GPIOA + sys1EnableP0(); + nvicEnableVector(SN32_GPIOA_NUMBER, SN32_GPIOA_IRQ_PRIORITY); +#endif +#if SN32_HAS_GPIOB + sys1EnableP1(); + nvicEnableVector(SN32_GPIOB_NUMBER, SN32_GPIOB_IRQ_PRIORITY); +#endif +#if SN32_HAS_GPIOC + sys1EnableP2(); + nvicEnableVector(SN32_GPIOC_NUMBER, SN32_GPIOC_IRQ_PRIORITY); +#endif +#if SN32_HAS_GPIOD + sys1EnableP3(); + nvicEnableVector(SN32_GPIOD_NUMBER, SN32_GPIOD_IRQ_PRIORITY); +#endif + + for (uint8_t i = 0; i < TOTAL_PORTS * PAL_IOPORTS_WIDTH; i++) { + _pal_init_event(i); + } +#endif + /* * Initial GPIO setup. */ @@ -83,7 +156,6 @@ void _pal_lld_init(const PALConfig *config) { #if SN32_HAS_GPIOD initgpio(GPIOD, &config->PDData); #endif - } /** @@ -100,7 +172,7 @@ void _pal_lld_init(const PALConfig *config) { * @notapi */ void _pal_lld_setpadmode(ioportid_t port, - uint32_t pad, + iopadid_t pad, iomode_t mode) { switch (mode) { @@ -139,6 +211,104 @@ void _pal_lld_setpadmode(ioportid_t port, } } +#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) +/** + * @brief Returns a PAL event structure associated to a pad. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * + * @notapi + */ +palevent_t* _pal_lld_get_pad_event(ioportid_t port, + iopadid_t pad) { + if (port == GPIOA) { + return _pal_events + pad; + } else if (port == GPIOB) { + return _pal_events + PAL_IOPORTS_WIDTH + pad; + } else if (port == GPIOC) { + return _pal_events + PAL_IOPORTS_WIDTH * 2 + pad; + } else if (port == GPIOD) { + return _pal_events + PAL_IOPORTS_WIDTH * 3 + pad; + } + return NULL; +} + +/** + * @brief Enables a pad event. + * + * @param[in] port port containing pad whose event is to be enabled + * @param[in] pad pad whose event is to be enabled + * @param[in] mode mode of the event + * + * @notapi + */ +void _pal_lld_enablepadevent(ioportid_t port, + iopadid_t pad, + iomode_t mode) { + switch(mode) { + case PAL_EVENT_MODE_RISING_EDGE: + port->IS &= ~(1 << pad); + port->IBS &= ~(1 << pad); + port->IEV &= ~(1 << pad); + port->IE |= (1 << pad); + break; + case PAL_EVENT_MODE_FALLING_EDGE: + port->IS &= ~(1 << pad); + port->IBS &= ~(1 << pad); + port->IEV |= (1 << pad); + port->IE |= (1 << pad); + break; + case PAL_EVENT_MODE_BOTH_EDGES: + port->IS &= ~(1 << pad); + port->IBS |= (1 << pad); + port->IE |= (1 << pad); + break; + case PAL_EVENT_MODE_DISABLED: + port->IS &= ~(1 << pad); + port->IBS &= ~(1 << pad); + port->IEV &= ~(1 << pad); + port->IE &= ~(1 << pad); + break; + default: + return; + } +} + +/** + * @brief Disables a pad event + * + * @param[in] port port containing pad whose event is to be disabled + * @param[in] pad pad whose event is to be disabled + * + * @notapi + */ +void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad) { + _pal_lld_enablepadevent(port, pad, PAL_EVENT_MODE_DISABLED); + + if (port == GPIOA) { + _pal_clear_event(pad); + } else if (port == GPIOB) { + _pal_clear_event(PAL_IOPORTS_WIDTH + pad); + } else if (port == GPIOC) { + _pal_clear_event(PAL_IOPORTS_WIDTH * 2 + pad); + } else if (port == GPIOD) { + _pal_clear_event(PAL_IOPORTS_WIDTH * 3 + pad); + } +} + +/** + * @brief Returns whether a pad event is enabled + * + * @param[in] port port containing the pad + * @param[in] pad pad whose event is to be queried + * + * @notapi + */ +bool _pal_lld_ispadeventenabled(ioportid_t port, iopadid_t pad) { + return ((port->IE >> pad) & 1); +} +#endif /* (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) */ #endif /* HAL_USE_PAL */ /** @} */ diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.h b/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.h index a29a8c80b0..32c3ea5865 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/GPIO/hal_pal_lld.h @@ -45,6 +45,11 @@ #undef GPIOC #undef GPIOD + +/*===========================================================================*/ +/* I/O Ports Types and constants. */ +/*===========================================================================*/ + /** * @name GPIO ports definitions * @{ @@ -56,18 +61,15 @@ /** @} */ -/*===========================================================================*/ -/* I/O Ports Types and constants. */ -/*===========================================================================*/ - /** * @name Port related definitions * @{ */ +#define TOTAL_PORTS 4U /** * @brief Width, in bits, of an I/O port. */ -#define PAL_IOPORTS_WIDTH 16 +#define PAL_IOPORTS_WIDTH 16U /** * @brief Whole port mask. @@ -202,6 +204,11 @@ typedef uint32_t ioline_t; */ typedef SN_GPIO0_Type * ioportid_t; +/** + * @brief Type of an pad identifier. + */ +typedef uint32_t iopadid_t; + /*===========================================================================*/ /* I/O Ports Identifiers. */ /* The low level driver wraps the definitions already present in the SN32 */ @@ -236,6 +243,34 @@ typedef SN_GPIO0_Type * ioportid_t; #define IOPORT4 GPIOD #endif +/** + * @brief GPIO port A interrupt priority level setting. + */ +#if !defined(SN32_GPIOA_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define SN32_GPIOA_IRQ_PRIORITY 3 +#endif + +/** + * @brief GPIO port B interrupt priority level setting. + */ +#if !defined(SN32_GPIOB_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define SN32_GPIOB_IRQ_PRIORITY 3 +#endif + +/** + * @brief GPIO port A interrupt priority level setting. + */ +#if !defined(SN32_GPIOC_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define SN32_GPIOC_IRQ_PRIORITY 3 +#endif + +/** + * @brief GPIO port A interrupt priority level setting. + */ +#if !defined(SN32_GPIOD_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define SN32_GPIOD_IRQ_PRIORITY 3 +#endif + /*===========================================================================*/ /* Implementation, some of the following macros could be implemented as */ /* functions, if so please put them in pal_lld.c. */ @@ -419,14 +454,93 @@ typedef SN_GPIO0_Type * ioportid_t; #define pal_lld_setpadmode(port, pad, mode) \ _pal_lld_setpadmode(port, pad, mode) + +/** + * @brief Returns a PAL event structure associated to a pad. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * + * @notapi + */ +#define pal_lld_get_pad_event(port, pad) \ + _pal_lld_get_pad_event(port, pad) + +/** + * @brief Returns a PAL event structure associated to a line. + * + * @param[in] line line identifier + * + * @notapi + */ +#define pal_lld_get_line_event(line) \ + pal_lld_get_pad_event(PAL_PORT(line), PAL_PAD(line)) + +/** + * @brief Pad event enable. + * @note Programming an unknown or unsupported mode is silently ignored. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @param[in] mode pad event mode + * + * @notapi + */ +#define pal_lld_enablepadevent(port, pad, mode) \ + _pal_lld_enablepadevent(port, pad, mode) + +/** + * @brief Pad event disable. + * @details This function disables previously programmed event callbacks. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * + * @notapi + */ +#define pal_lld_disablepadevent(port, pad) \ + _pal_lld_disablepadevent(port, pad) + +/** + * @brief Pad event enable check. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @return Pad event status. + * @retval false if the pad event is disabled. + * @retval true if the pad event is enabled. + * + * @notapi + */ +#define pal_lld_ispadeventenabled(port, pad) \ + _pal_lld_ispadeventenabled(port, pad) + +#if !defined(__DOXYGEN__) +extern const PALConfig pal_default_config; +#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) +extern palevent_t _pal_events[TOTAL_PORTS * PAL_IOPORTS_WIDTH]; +#endif /* (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) */ +#endif + #ifdef __cplusplus extern "C" { #endif extern const PALConfig pal_default_config; void _pal_lld_init(const PALConfig *config); void _pal_lld_setpadmode(ioportid_t port, - uint32_t pad, + iopadid_t pad, iomode_t mode); +#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) + palevent_t* _pal_lld_get_pad_event(ioportid_t port, + iopadid_t pad); + void _pal_lld_enablepadevent(ioportid_t port, + iopadid_t pad, + iomode_t mode); + void _pal_lld_disablepadevent(ioportid_t port, + iopadid_t pad); + bool _pal_lld_ispadeventenabled(ioportid_t port, + iopadid_t pad); +#endif /* (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) */ #ifdef __cplusplus } #endif