ISR Demo

```language #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include "UART.h" #include "osa.h" #include "cgpio.h" #include "gpio.h" #define sdk_uart_printf(fmt, args...) do { fatal_printf("[sdk]"fmt, ##args); } while(0) #define BU_REG_WRITE(x,y) ((*(volatile unsigned long *)(x)) = y ) extern UINT32 getGPIOPinmuxAddress(UINT32 GPIONum); OS_HISR Detect_Hisr; OSATimerRef DectectTimerRef = NULL; OSFlagRef DetectFlgRef=NULL; OSATaskRef Detect_taskref=NULL; char Detect_StackPtr[1024]={0}; #define GPIO_ISR_PIN_NUM 71 //PIN 1 void GPIOIRQHandler (void); void Detect_TaskEntry(void); void DetectTimerHandler(UINT32 arg); void Detect_Handler(void); // Device bootup hook before Phase1Inits. // If you have some work to be init, you may implete it here. // ex: you may start your task here. or do some initialize here. extern void Phase1Inits_enter(void); // Device bootup hook after Phase1Inits. // If you have some work to be init, you may implete it here. // ex: you may start your task here. or do some initialize here. extern void Phase1Inits_exit(void); // Device bootup hook before Phase2Inits. // If you have some work to be init, you may implete it here. // ex: you may start your task here. or do some initialize here. extern void Phase2Inits_enter(void); // Device bootup hook after Phase2Inits. // If you have some work to be init, you may implete it here. // ex: you may start your task here. or do some initialize here. extern void Phase2Inits_exit(void); void Phase1Inits_enter(void) { } void Phase1Inits_exit(void) { } void Phase2Inits_enter(void) { } void Phase2Inits_exit(void) { int ret; GPIOReturnCode status = GPIORC_OK; GPIOConfiguration config; OSATimerCreate(&DectectTimerRef); OSAFlagCreate( &DetectFlgRef); Os_Create_HISR(&Detect_Hisr, "Detect_Hisr", Detect_Handler, 2); OSATaskCreate(&Detect_taskref, Detect_StackPtr,1024,100,"Detect_task",Detect_TaskEntry,NULL); BU_REG_WRITE(getGPIOPinmuxAddress(GPIO_ISR_PIN_NUM), 0x1080); // GPIO_12 config.pinDir = GPIO_IN_PIN; config.pinEd = GPIO_TWO_EDGE; config.pinPull = GPIO_PULLUP_ENABLE; config.isr = GPIOIRQHandler; GpioInitConfiguration(GPIO_ISR_PIN_NUM,config); } void GPIOIRQHandler (void) { OS_Activate_HISR(&Detect_Hisr); } void Detect_TaskEntry(void) { GPIO_ReturnCode ret; UINT32 value; OSA_STATUS status = OS_SUCCESS; UINT32 flag_value = 0; while(1) { sdk_uart_printf("Detect_TaskEntry\r\n"); status = OSAFlagWait(DetectFlgRef, 0x01, OSA_FLAG_OR_CLEAR, &flag_value, OSA_SUSPEND); if(flag_value & 0x01) { value = GpioGetLevel(GPIO_ISR_PIN_NUM); sdk_uart_printf("GPIOWAKEDetect_TaskEntry value=%d\r\n", value); } } } void DetectTimerHandler(UINT32 arg) { OS_STATUS os_status; os_status = OSAFlagSet(DetectFlgRef, 0x01, OSA_FLAG_OR); ASSERT(os_status==OS_SUCCESS); } void Detect_Handler(void) { OS_STATUS status; OSATimerStop(DectectTimerRef); status = OSATimerStart(DectectTimerRef, 2, 0, DetectTimerHandler, 0); } ```