From 9976c747d7209b33e1a009f84539812366146cfb Mon Sep 17 00:00:00 2001 From: Roland Sahlsten Date: Mon, 24 Oct 2011 21:09:29 +0000 Subject: git-svn-id: https://svn.spreadspace.org/mur.sat@180 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/mpu/MurSatMPU Debug.launch | 19 ++++++++-- software/mpu/MurSatMPU Release.launch | 17 ++++++++- software/mpu/inc/Types.h | 14 ++++++-- software/mpu/src/boot.c | 57 ++++++++++++++++++----------- software/mpu/src/kernel.c | 67 +++++++++++++++++++++++------------ software/mpu/src/main.c | 5 +++ 6 files changed, 131 insertions(+), 48 deletions(-) (limited to 'software') diff --git a/software/mpu/MurSatMPU Debug.launch b/software/mpu/MurSatMPU Debug.launch index 1bbeecc..8f240df 100644 --- a/software/mpu/MurSatMPU Debug.launch +++ b/software/mpu/MurSatMPU Debug.launch @@ -1,17 +1,32 @@ - + + + + + + + + - + + + + + + + + + diff --git a/software/mpu/MurSatMPU Release.launch b/software/mpu/MurSatMPU Release.launch index f7927bc..8183be3 100644 --- a/software/mpu/MurSatMPU Release.launch +++ b/software/mpu/MurSatMPU Release.launch @@ -1,13 +1,28 @@ - + + + + + + + + + + + + + + + + diff --git a/software/mpu/inc/Types.h b/software/mpu/inc/Types.h index 501d359..1ceeaad 100644 --- a/software/mpu/inc/Types.h +++ b/software/mpu/inc/Types.h @@ -2,6 +2,8 @@ #include "task.h" #include "queue.h" +#define MS(ms) portTICK_RATE_MS * (ms) + typedef enum { STATUS_OK = 0x0U, @@ -27,7 +29,13 @@ typedef struct typedef struct { - xTaskHandle *pxTask_Lightsens; - xQueueHandle *pxQueue; -}Task_Param_t; + xQueueHandle hxq_Kernel; + xQueueHandle hxq_Camera; + xQueueHandle hxq_LightSens; +}QH_t; +typedef struct +{ + xTaskHandle hxTask_Self; + QH_t QueueHandles; +}Task_Param_t; diff --git a/software/mpu/src/boot.c b/software/mpu/src/boot.c index 1f18918..d3b4d59 100644 --- a/software/mpu/src/boot.c +++ b/software/mpu/src/boot.c @@ -10,46 +10,63 @@ #include "task.h" #include "queue.h" -//static void kernel_Process_Task(void *Param); -//static xTaskHandle *pkernel_TaskHandle; -//static Task_Param_t kernel_Param; +#define NUM_QUEUE_ITEMS_KERNEL ((unsigned long) 2) +#define NUM_QUEUE_ITEMS_CAMERA ((unsigned long) 2) +#define NUM_QUEUE_ITEMS_LIGHTSENS ((unsigned long) 2) -Status_t kernel_Init_Kernel(xQueueHandle * pxQueue); +Status_t kernel_Init_Kernel(QH_t xQueues); +Status_t camera_Init_Camera(QH_t xQueues); +Status_t lightsens_Init_LightSens(QH_t xQueues); -Status_t boot_Init_Kernel(xQueueHandle * pxQueue) +/* + * Globals */ +static QH_t qh; + +Status_t boot_Init_Kernel(QH_t xQueues) { - return kernel_Init_Kernel( pxQueue ); + return kernel_Init_Kernel( xQueues ); } -Status_t boot_Init_Camera(xQueueHandle * pxQueue) +Status_t boot_Init_Camera(QH_t xQueues) { - return STATUS_OK; + return camera_Init_Camera( xQueues ); } -Status_t boot_Init_LightSens(xQueueHandle * pxQueue) +Status_t boot_Init_LightSens(QH_t xQueues) { - return STATUS_OK; + return lightsens_Init_LightSens( xQueues ); } -Status_t boot_CreateQueues( xQueueHandle *pxQueue_Kernel, - xQueueHandle *pxQueue_Camera, - xQueueHandle *pxQueue_LightSens) +Status_t boot_CreateQueues( xQueueHandle *phxQueue_Kernel, + xQueueHandle *phxQueue_Camera, + xQueueHandle *phxQueue_LightSens) { + *phxQueue_Kernel = xQueueCreate(NUM_QUEUE_ITEMS_KERNEL, sizeof(Message_t)); + *phxQueue_Camera = xQueueCreate(NUM_QUEUE_ITEMS_CAMERA, sizeof(Message_t)); + *phxQueue_LightSens = xQueueCreate(NUM_QUEUE_ITEMS_LIGHTSENS, sizeof(Message_t)); + return STATUS_OK; + } void boot_Main(void) { /* * * */ + + xQueueHandle hxQueue_Kernel; + xQueueHandle hxQueue_Camera; + xQueueHandle hxQueue_LightSens; + Status_t Status; - xQueueHandle * pxQueue_Kernel = NULL, - * pxQueue_Camera = NULL, - * pxQueue_LightSens = NULL; - Status = boot_CreateQueues(pxQueue_Kernel, pxQueue_Camera, pxQueue_LightSens); + Status = boot_CreateQueues(&hxQueue_Kernel, &hxQueue_Camera, &hxQueue_LightSens); + + qh.hxq_Kernel = hxQueue_Kernel; + qh.hxq_Camera = hxQueue_Camera; + qh.hxq_LightSens = hxQueue_LightSens; - Status = boot_Init_Kernel(pxQueue_Kernel); - Status = boot_Init_Camera(pxQueue_Camera); - Status = boot_Init_LightSens(pxQueue_LightSens); + Status = boot_Init_Kernel(qh); + Status = boot_Init_Camera(qh); + Status = boot_Init_LightSens(qh); /* Start the tasks. */ vTaskStartScheduler(); diff --git a/software/mpu/src/kernel.c b/software/mpu/src/kernel.c index 71ef57f..d75f9dd 100644 --- a/software/mpu/src/kernel.c +++ b/software/mpu/src/kernel.c @@ -8,15 +8,11 @@ #include "FreeRTOS.h" #include "queue.h" -#define kernel_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) -#define kernel_TASK_STACK_SIZE ( ( unsigned short ) 32 ) +#define kernel_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 ) +#define kernel_TASK_STACK_SIZE ( ( unsigned short ) 64 ) /* Globals */ -xQueueHandle * gpxQueue_Kernel; -//static xTaskHandle *pkernel_TaskHandle; -//static Task_Param_t kernel_Param; -xTaskHandle *pkernel_TaskHandle; -Task_Param_t kernel_Param; +static Task_Param_t kernel_Param; /* * Wake up other tasks, send them messages telling what to do, @@ -26,29 +22,56 @@ Task_Param_t kernel_Param; 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) { - xQueueReceive( gpxQueue_Kernel, &Msg, portMAX_DELAY ); - /*TODO: execute desired command of message */ - - /* - * switch Msg.Sender - * - * case Sender_Kernel: - * yeah, that's myself - * - */ + 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(xQueueHandle * pxQueue) +Status_t kernel_Init_Kernel(QH_t hxQueues) { - kernel_Param.pxQueue = pxQueue; +portBASE_TYPE xResult; + + xResult = xTaskCreate( kernel_Process_Task, (signed char *) "Kernel", + kernel_TASK_STACK_SIZE, &kernel_Param, + kernel_TASK_PRIORITY, &(kernel_Param.hxTask_Self) ); - xTaskCreate( kernel_Process_Task, (signed char *) "Kernel", - kernel_TASK_STACK_SIZE, &kernel_Param, - kernel_TASK_PRIORITY, pkernel_TaskHandle ); + kernel_Param.QueueHandles = hxQueues; /*TODO: check for success and pass it over to caller. */ return STATUS_OK; diff --git a/software/mpu/src/main.c b/software/mpu/src/main.c index e23c44b..e7f69f1 100644 --- a/software/mpu/src/main.c +++ b/software/mpu/src/main.c @@ -11,5 +11,10 @@ void boot_Main(void); int main(void) { +#if 1 boot_Main(); +#endif + + /* If we ever reach this point, then there is something very wrong. */ + return -1; } -- cgit v1.2.3