📄 lld_gpio.c
字号:
/*____________________________________________________________________________| FILE: lld_gpio.c| PROJECT: OS20_ACCORDO+| SW-COMPONENT: |_____________________________________________________________________________| DESCRIPTION: Low level driver for General Purpose I/O Ports |_____________________________________________________________________________| COPYRIGHT: (c) 2005 STMicroelectronics, Arzano (ITALY)| HISTORY:| Date | Modification | Author|_____________________________________________________________________________| 05.10.27 | Initial revision | M. De Martino |____________________________________________________________________________*/#include "lld_gpio.h"#ifdef __cplusplusextern "C" {#endif/************************************************************************| external declarations |-----------------------------------------------------------------------*//************************************************************************| defines and macros (scope: module-local)|-----------------------------------------------------------------------*//************************************************************************| typedefs (scope: module-local)|-----------------------------------------------------------------------*//************************************************************************| variable definitions (scope: global)|-----------------------------------------------------------------------*//************************************************************************| variable definitions (scope: module-local)|-----------------------------------------------------------------------*//* Place Gpio's pheripheral according to scatter file */#pragma arm section zidata = "GpioA_map" volatile rGpio GpioA; #pragma arm section zidata#pragma arm section zidata = "GpioB_map" volatile rGpio GpioB; #pragma arm section zidata /************************************************************************| function prototypes (scope: module-local)|-----------------------------------------------------------------------*//************************************************************************| function implementations (scope: module-local)|-----------------------------------------------------------------------*//************************************************************************| function implementations (scope: global)|-----------------------------------------------------------------------*//************************************************************************* ** FUNCTIONS ** ** LLD_GPIO_SetOutput ** ** DESCRIPTION ** ** Program the u8Pin of the id GPIO port as output push pull. ** ** CALLS ** ** LLD macros ** ** INPUTS ** ** GPIO_ID id: GPIO identificator ** tU8 u8in: Pin number ** ** OUTPUTS ** ** None ** *************************************************************************/tVoid LLD_GPIO_SetPPOutput(GPIO_ID id, tU8 u8Pin){ /* The Output configuration is Pc0=1, Pc1=0, Pc2=1 */ tU16 u16Buffer; if( GPIO_A == id ) { u16Buffer = rd16_reg(GpioA,Pc0); wr16_reg(GpioA,Pc0,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ u16Buffer = rd16_reg(GpioA,Pc1); wr16_reg(GpioA,Pc1,u16Buffer & ~(1<<u8Pin)); /* clear bit u8Pin. */ u16Buffer = rd16_reg(GpioA,Pc2); wr16_reg(GpioA,Pc2,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ } if( GPIO_B == id ) { u16Buffer = rd16_reg(GpioB,Pc0); wr16_reg(GpioB,Pc0,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ u16Buffer = rd16_reg(GpioB,Pc1); wr16_reg(GpioB,Pc1,u16Buffer & ~(1<<u8Pin)); /* clear bit u8Pin. */ u16Buffer = rd16_reg(GpioB,Pc2); wr16_reg(GpioB,Pc2,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ }}/************************************************************************* ** FUNCTIONS ** ** LLD_GPIO_SetOutput ** ** DESCRIPTION ** ** Program the u8Pin of the id GPIO port as output open drain. ** ** CALLS ** ** LLD macros ** ** INPUTS ** ** GPIO_ID id: GPIO identificator ** tU8 u8in: Pin number ** ** OUTPUTS ** ** None ** *************************************************************************/tVoid LLD_GPIO_SetODOutput(GPIO_ID id, tU8 u8Pin){ /* The Output configuration is Pc0=0, Pc1=0, Pc2=1 */ tU16 u16Buffer; if( GPIO_A == id ) { u16Buffer = rd16_reg(GpioA,Pc0); wr16_reg(GpioA,Pc0,u16Buffer & ~(1<<u8Pin)); /* clear bit u8Pin. */ u16Buffer = rd16_reg(GpioA,Pc1); wr16_reg(GpioA,Pc1,u16Buffer & ~(1<<u8Pin)); /* clear bit u8Pin. */ u16Buffer = rd16_reg(GpioA,Pc2); wr16_reg(GpioA,Pc2,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ } if( GPIO_B == id ) { u16Buffer = rd16_reg(GpioB,Pc0); wr16_reg(GpioB,Pc0,u16Buffer & ~(1<<u8Pin)); /* clear bit u8Pin. */ u16Buffer = rd16_reg(GpioB,Pc1); wr16_reg(GpioB,Pc1,u16Buffer & ~(1<<u8Pin)); /* clear bit u8Pin. */ u16Buffer = rd16_reg(GpioB,Pc2); wr16_reg(GpioB,Pc2,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ }}/************************************************************************* ** FUNCTIONS ** ** LLD_GPIO_SetAFPPOutput ** ** DESCRIPTION ** ** Program the u8Pin of the id GPIO port as output alternate ** function push pull ** CALLS ** ** LLD macros ** ** INPUTS ** ** GPIO_ID id: GPIO identificator ** tU8 u8in: Pin number ** ** OUTPUTS ** ** None ** *************************************************************************/tVoid LLD_GPIO_SetAFPPOutput(GPIO_ID id, tU8 u8Pin){ /* The Output configuration is Pc0=1, Pc1=1, Pc2=1 */ tU16 u16Buffer; if( GPIO_A == id ) { u16Buffer = rd16_reg(GpioA,Pc0); wr16_reg(GpioA,Pc0,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ u16Buffer = rd16_reg(GpioA,Pc1); wr16_reg(GpioA,Pc1,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ u16Buffer = rd16_reg(GpioA,Pc2); wr16_reg(GpioA,Pc2,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ } if( GPIO_B == id ) { u16Buffer = rd16_reg(GpioB,Pc0); wr16_reg(GpioB,Pc0,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ u16Buffer = rd16_reg(GpioB,Pc1); wr16_reg(GpioB,Pc1,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ u16Buffer = rd16_reg(GpioB,Pc2); wr16_reg(GpioB,Pc2,u16Buffer | (1<<u8Pin)); /* set bit u8Pin. */ }}/************************************************************************* ** FUNCTIONS ** ** LLD_GPIO_SetAFODOutput ** ** DESCRIPTION ** ** Program the u8Pin of the id GPIO port as output alternate ** function open drain. ** CALLS ** ** LLD macros ** ** INPUTS ** ** GPIO_ID id: GPIO identificator ** tU8 u8in: Pin number ** ** OUTPUTS *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -