#include "FreeRTOS.h" #include "semphr.h" #include "task.h" #include "MetersIncludes.h" extern xMetersSemaphore; extern xTickCount; /* millisecond tick counter */ void handleGasMeterTick(void); /* The interrupt entry point. */ void vP2_0_ISR_Wrapper( void ) __attribute__((naked)); /* The function that actually performs the interrupt processing. This must be separate to the wrapper to ensure the correct stack frame is set up. */ void vP2_0_ISR_Handler( void ); void vP2_0_ISR_Handler( void ) { portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; if ((IO2_INT_STAT_R & (1 << 10)) != 0) /* P2.10 interrupt triggered */ { handleGasMeterTick(); } // else if ((IO2_INT_STAT_R & (1 << n)) != 0) /* some other interrupt triggered */ { ; } /* Clear the interrupt. */ IO2_INT_CLR |= (1<<10); VICVectAddr = 0; /* Unblock the Meters task as data has arrived. */ xSemaphoreGiveFromISR( xMetersSemaphore, &xHigherPriorityTaskWoken ); if( xHigherPriorityTaskWoken ) { /* If the Meters task was unblocked then calling "Yield from ISR" here will ensure the interrupt returns directly to the Meters task, if it is the highest priority read task. */ portYIELD_FROM_ISR(); } } /*-----------------------------------------------------------*/ void vP2_0_ISR_Wrapper( void ) { /* Save the context of the interrupted task. */ portSAVE_CONTEXT(); /* Call the handler function. This must be separate from the wrapper function to ensure the correct stack frame is set up. */ vP2_0_ISR_Handler(); /* Restore the context of whichever task is going to run next. */ portRESTORE_CONTEXT(); } void handleGasMeterTick(void) { meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick; /* when did the tick before the last tick occur? */ meterItems[METER_INDEX_GAS].timeLastTick = getEpochTimeWithMs(); /* when did the last tick occur? epoch (seconds) */ meterItems[METER_INDEX_GAS].valueLastTick = 0; /* what value did we have at the last tick? */ meterItems[METER_INDEX_GAS].valueBeforeLastTick = 1; /* what value did we have at the tick before the last tick? */ }