1 |
#include "FreeRTOS.h" |
---|
2 |
#include "semphr.h" |
---|
3 |
#include "task.h" |
---|
4 |
#include "MetersIncludes.h" |
---|
5 |
|
---|
6 |
extern xMetersSemaphore; |
---|
7 |
extern xTickCount; /* millisecond tick counter */ |
---|
8 |
|
---|
9 |
void handleGasMeterTick(void); |
---|
10 |
|
---|
11 |
/* The interrupt entry point. */ |
---|
12 |
void vP2_0_ISR_Wrapper( void ) __attribute__((naked)); |
---|
13 |
|
---|
14 |
/* The function that actually performs the interrupt processing. This must be |
---|
15 |
separate to the wrapper to ensure the correct stack frame is set up. */ |
---|
16 |
void vP2_0_ISR_Handler( void ); |
---|
17 |
|
---|
18 |
void vP2_0_ISR_Handler( void ) |
---|
19 |
{ |
---|
20 |
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; |
---|
21 |
|
---|
22 |
if ((IO2_INT_STAT_R & (1 << 10)) != 0) /* P2.10 interrupt triggered */ |
---|
23 |
{ |
---|
24 |
handleGasMeterTick(); |
---|
25 |
} |
---|
26 |
// else if ((IO2_INT_STAT_R & (1 << n)) != 0) /* some other interrupt triggered */ |
---|
27 |
{ |
---|
28 |
; |
---|
29 |
} |
---|
30 |
|
---|
31 |
/* Clear the interrupt. */ |
---|
32 |
IO2_INT_CLR |= (1<<10); |
---|
33 |
VICVectAddr = 0; |
---|
34 |
|
---|
35 |
/* Unblock the Meters task as data has arrived. */ |
---|
36 |
xSemaphoreGiveFromISR( xMetersSemaphore, &xHigherPriorityTaskWoken ); |
---|
37 |
|
---|
38 |
if( xHigherPriorityTaskWoken ) |
---|
39 |
{ |
---|
40 |
/* If the Meters task was unblocked then calling "Yield from ISR" here |
---|
41 |
will ensure the interrupt returns directly to the Meters task, if it |
---|
42 |
is the highest priority read task. */ |
---|
43 |
portYIELD_FROM_ISR(); |
---|
44 |
} |
---|
45 |
} |
---|
46 |
/*-----------------------------------------------------------*/ |
---|
47 |
|
---|
48 |
void vP2_0_ISR_Wrapper( void ) |
---|
49 |
{ |
---|
50 |
/* Save the context of the interrupted task. */ |
---|
51 |
portSAVE_CONTEXT(); |
---|
52 |
|
---|
53 |
/* Call the handler function. This must be separate from the wrapper |
---|
54 |
function to ensure the correct stack frame is set up. */ |
---|
55 |
vP2_0_ISR_Handler(); |
---|
56 |
|
---|
57 |
/* Restore the context of whichever task is going to run next. */ |
---|
58 |
portRESTORE_CONTEXT(); |
---|
59 |
} |
---|
60 |
|
---|
61 |
void handleGasMeterTick(void) |
---|
62 |
{ |
---|
63 |
meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick; /* when did the tick before the last tick occur? */ |
---|
64 |
meterItems[METER_INDEX_GAS].timeLastTick = getEpochTimeWithMs(); /* when did the last tick occur? epoch (seconds) */ |
---|
65 |
meterItems[METER_INDEX_GAS].valueLastTick = 0; /* what value did we have at the last tick? */ |
---|
66 |
meterItems[METER_INDEX_GAS].valueBeforeLastTick = 1; /* what value did we have at the tick before the last tick? */ |
---|
67 |
} |
---|
68 |
|
---|