1 |
|
---|
2 |
#include "FreeRTOS.h" |
---|
3 |
#include "semphr.h" |
---|
4 |
#include "task.h" |
---|
5 |
|
---|
6 |
#define metersSTACK_SIZE configMINIMAL_STACK_SIZE |
---|
7 |
/* masks for RTC */ |
---|
8 |
#define MASKSEC 0x3F // Second 00..59 00000000:00000000:00xxxxxx |
---|
9 |
#define MASKMIN 0x3F00 // Minute 00..59 00000000:00xxxxxx:00000000 |
---|
10 |
#define MASKHR 0x1F0000 // Hour 00..23 000xxxxx:00000000:00000000 |
---|
11 |
|
---|
12 |
|
---|
13 |
portBASE_TYPE Init_P2_0(void); |
---|
14 |
void basementGasCalculation(void); |
---|
15 |
|
---|
16 |
portLONG basementGasReading = 0; |
---|
17 |
portTickType basementGasLastTime = 0; |
---|
18 |
|
---|
19 |
/* The semaphore used to wake the Meters task when a pulse was received or the timer expired. */ |
---|
20 |
xSemaphoreHandle xMetersSemaphore = NULL; |
---|
21 |
|
---|
22 |
portTickType xLastMeterTaskRunTime; /* keeps the last time the meter calculation ran */ |
---|
23 |
portTickType xMeterIdleRate = 1000; /* the rate (in ticks = ms) at which the calculation runs when no pulses triggered a calculation */ |
---|
24 |
|
---|
25 |
|
---|
26 |
int rtcHOURS; |
---|
27 |
int rtcMINUTES; |
---|
28 |
int rtcSECONDS; |
---|
29 |
static portTASK_FUNCTION( vMeters_Task, pvParameters ) |
---|
30 |
{ |
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 |
vSemaphoreCreateBinary( xMetersSemaphore ); |
---|
35 |
|
---|
36 |
Init_P2_0(); /* init GPIO for meters */ |
---|
37 |
xLastMeterTaskRunTime = xTaskGetTickCount(); /* init last run time */ |
---|
38 |
|
---|
39 |
|
---|
40 |
for( ;; ) |
---|
41 |
{ |
---|
42 |
|
---|
43 |
basementGasCalculation(); |
---|
44 |
|
---|
45 |
portENTER_CRITICAL(); |
---|
46 |
// example: do stuff |
---|
47 |
portEXIT_CRITICAL(); |
---|
48 |
|
---|
49 |
/* We did not receive a pulse, and there was no periodic |
---|
50 |
processing to perform. Block for a fixed period. If a pulse |
---|
51 |
is received during this period we will be woken by the ISR |
---|
52 |
giving us the Semaphore. */ |
---|
53 |
xLastMeterTaskRunTime = xTaskGetTickCount(); /* update last run time */ |
---|
54 |
|
---|
55 |
rtcHOURS = (RTC_CTIME0 & MASKHR)>>16; // Read Hour |
---|
56 |
rtcMINUTES = (RTC_CTIME0 & MASKMIN)>>8; // Read Minute |
---|
57 |
rtcSECONDS = RTC_CTIME0 & MASKSEC; // Read Second |
---|
58 |
|
---|
59 |
xSemaphoreTake( xMetersSemaphore, 1000 ); /* timeout 1 sec */ |
---|
60 |
|
---|
61 |
/* Yield in case cooperative scheduling is being used. */ |
---|
62 |
#if configUSE_PREEMPTION == 0 |
---|
63 |
{ |
---|
64 |
taskYIELD(); |
---|
65 |
} |
---|
66 |
#endif |
---|
67 |
} |
---|
68 |
} |
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 |
void vStartMetersTask( unsigned portBASE_TYPE uxPriority ) |
---|
73 |
{ |
---|
74 |
|
---|
75 |
/* Spawn the task. */ |
---|
76 |
xTaskCreate( vMeters_Task, ( signed portCHAR * ) "Meters", metersSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL ); |
---|
77 |
} |
---|
78 |
|
---|
79 |
void vP2_0_ISR_Wrapper( void ); |
---|
80 |
|
---|
81 |
// configure port-pins for use with LAN-controller, |
---|
82 |
// reset it and send the configuration-sequence |
---|
83 |
|
---|
84 |
portBASE_TYPE Init_P2_0(void) |
---|
85 |
{ |
---|
86 |
// not needed yet : SCS |= 1; // Enable FAST GPIO |
---|
87 |
portBASE_TYPE xReturn = 1; // return value |
---|
88 |
|
---|
89 |
/* Enable Pins. */ |
---|
90 |
|
---|
91 |
PINSEL4 &= 0xfffff3ff; /* reset bit 20 and 21, P2.10 = GPIO Port 2.10 */ |
---|
92 |
PINMODE4 &= 0xfffff3ff; /* reset bit 20 and 21, enable on-chip pull-up resistor on Port 2.10 */ |
---|
93 |
IO2_INT_EN_R |= (1<<10); /* enable rising edge interrupt for P2:10 */ |
---|
94 |
IO2_INT_EN_F &= ~(1<<10); /* disable falling edge interrupt for P2:10 */ |
---|
95 |
|
---|
96 |
VICVectAddr17 = (portLONG) vP2_0_ISR_Wrapper; /* EINT-3 interrupt handler */ |
---|
97 |
|
---|
98 |
VICIntEnable |= (1<<17); /* Enable VIC index-17 (shared by EINT3 and GPIO) */ |
---|
99 |
|
---|
100 |
return xReturn; |
---|
101 |
} |
---|
102 |
|
---|
103 |
|
---|
104 |
void basementGasCalculation(void) |
---|
105 |
{ |
---|
106 |
|
---|
107 |
} |
---|