1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* lightsens.c
*
* Created on: 23.10.2011
* Author: Roland
*/
#include "Types.h"
#include "FreeRTOS.h"
#include "queue.h"
#include "adc.h"
#define LED_PORT 0 // Port for led
#define LED_BIT 7 // Bit on port for led
#define TASK_PRIORITY_lightsens ( tskIDLE_PRIORITY + 2 )
#define TASK_STACK_SIZE_lightsens ( ( unsigned short ) 64 )
/* Debug Helper */
Status_t lightsens_ValueToString()
{
}
/* Globals */
static Task_Param_t TaskParam_LightSens;
/*
* Wake up other tasks, send them messages telling what to do,
* wait for them to have processed the commands or not, maybe
* put them to sleep again, ...
* */
static void lightsens_Process_Task(void *Param)
{
Message_t Msg;
portCHAR chBufLSe[10] = "Seas Knl!";
portCHAR led;
portCHAR i;
// volatile uint32_t ADCValue[ADC_NUM];
uint32_t ADCValue[ADC_NUM];
// set led port to output
LPC_GPIO0->DIR |= 1<<LED_BIT;
if(NULL == TaskParam_LightSens.QueueHandles.hxq_LightSens)
{
return;
}
Msg.Sender = Sender_LightSens;
Msg.pData = chBufLSe;
xQueueSend(TaskParam_LightSens.QueueHandles.hxq_Kernel, &Msg, MS(10));
/* Initialize ADC */
ADCInit( ADC_CLK );
for ( i = 0; i < ADC_NUM; i++ )
{
ADCValue[i] = ADCRead( i ); /* Polling */
}
while(1)
{
if( xQueueReceive( TaskParam_LightSens.QueueHandles.hxq_LightSens, &Msg, MS(5)))
{
/*
* switch Msg.Sender
*
*/
switch (Msg.Sender)
{
case Sender_Kernel:
{
if (((portCHAR*)(Msg.pData))[0] == 'l')
{
if(led)
led = 0;
else
led = 1<<LED_BIT;
// LPC_GPIO0->MASKED_ACCESS[(1<<LED_BIT)] = led;
}
if(((portCHAR*)(Msg.pData))[0] == 'r')
{
for ( i = 0; i < ADC_NUM; i++ )
{
ADCValue[i] = ADCRead( i ); /* Polling */
}
}
Msg.Sender = Sender_LightSens;
Msg.pData = chBufLSe;
Msg.pData = ADCValue;
xQueueSend(TaskParam_LightSens.QueueHandles.hxq_Kernel, &Msg, MS(10));
}
default: {;} /* for the time being we ignore messages received from
someone other than the kernel. */
}
}
}
}
Status_t lightsens_Init_LightSens(QH_t hxQueues)
{
TaskParam_LightSens.QueueHandles = hxQueues;
if(!xTaskCreate( lightsens_Process_Task, (signed char *) "LightSensor",
TASK_STACK_SIZE_lightsens, &TaskParam_LightSens,
TASK_PRIORITY_lightsens, &(TaskParam_LightSens.hxTask_Self)))
return STATUS_ERROR_INIT;
/*TODO: check for success and pass it over to caller. */
return STATUS_OK;
}
|