summaryrefslogtreecommitdiff
path: root/software/mpu.old/src/lightsens.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-05-28 19:22:38 +0000
committerChristian Pointner <equinox@mur.at>2013-05-28 19:22:38 +0000
commit3ab7176e463268a471eb0e90c8520be4ff15a42f (patch)
tree24f228d74d9bdd4f5db2e9ea6009364b09f0f5d8 /software/mpu.old/src/lightsens.c
parentDRC passes (diff)
moved old FreeRTOS based MPU Softeware to mpu.old
git-svn-id: https://svn.spreadspace.org/mur.sat@768 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/mpu.old/src/lightsens.c')
-rw-r--r--software/mpu.old/src/lightsens.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/software/mpu.old/src/lightsens.c b/software/mpu.old/src/lightsens.c
new file mode 100644
index 0000000..ed280f0
--- /dev/null
+++ b/software/mpu.old/src/lightsens.c
@@ -0,0 +1,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;
+}