summaryrefslogtreecommitdiff
path: root/software/mpu/src/kernel.c
blob: d75f9ddf7f54f7746ca3ecd5e2657f2f06b79f46 (plain) (blame)
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
/*
 * kernel.c
 *
 *  Created on: 13.09.2011
 *      Author: Roland
 */
#include "Types.h"
#include "FreeRTOS.h"
#include "queue.h"

#define	kernel_TASK_PRIORITY		    ( tskIDLE_PRIORITY + 5 )
#define kernel_TASK_STACK_SIZE			( ( unsigned short ) 64 )

/* Globals */
static Task_Param_t kernel_Param;

/*
 * 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 kernel_Process_Task(void *Param)
{
	Message_t Msg;
	Message_t SndMsg;
	portTickType tick;
	portCHAR chBufCam[10] = "Seas Cam!";
	portCHAR chBufLSen[10] = "Seas LSe!";

	if(NULL == kernel_Param.QueueHandles.hxq_Kernel)
	{
		return;
	}

	tick = xTaskGetTickCount();
	while(1)
	{
		vTaskDelayUntil(&tick, MS(3));

		if( xQueueReceive( kernel_Param.QueueHandles.hxq_Kernel, &Msg, MS(5)))
		{
			/*
			 * switch Msg.Sender and act accordingly.
			 */
			switch (Msg.Sender)
			{
			case Sender_Camera:
			{
				SndMsg.Sender = Sender_Kernel;
				SndMsg.pData = chBufCam;
				xQueueSend(kernel_Param.QueueHandles.hxq_Camera, &SndMsg, MS(10));
			}

			case Sender_LightSens:
			{
				SndMsg.Sender = Sender_Kernel;
				SndMsg.pData = chBufLSen;
				xQueueSend(kernel_Param.QueueHandles.hxq_LightSens, &SndMsg, MS(10));
			}
			default: {;}
			}
		}
	}
}

Status_t kernel_Init_Kernel(QH_t  hxQueues)
{
portBASE_TYPE xResult;

	xResult = xTaskCreate( kernel_Process_Task, (signed char *) "Kernel",
						   kernel_TASK_STACK_SIZE, &kernel_Param,
						   kernel_TASK_PRIORITY, &(kernel_Param.hxTask_Self) );

	kernel_Param.QueueHandles = hxQueues;

	/*TODO: check for success and pass it over to caller. */
	return STATUS_OK;
}