/*
===============================================================================
Name : main.c
Author :
Version :
Copyright : (C) Copyright
Description : main definition
===============================================================================
*/
#ifdef __USE_CMSIS
#include "LPC11xx.h"
#endif
#include "debug.h"
#include "gpio.h"
#include "uart.h"
#include "CoOs.h"
#define LED_PORT0
#defineLED_BIT7
enum {RED_PORT=1, BLUE_PORT=1, GREEN_PORT=1};
enum {RED_BIT=9, BLUE_BIT=2, GREEN_BIT=10};
enum{PRIORITY_BLINK_TASK0=2, PRIORITY_BLINK_TASK1=3, PRIORITY_RECIEVE=2};
enum{SIZE_BLINK_TASK0=100, SIZE_BLINK_TASK1=100, SIZE_RECEIVE=100};
OS_STK stkBlink0[SIZE_BLINK_TASK0];
OS_STK stkBlink1[SIZE_BLINK_TASK1];
OS_STK stkReceive[SIZE_RECEIVE];
OS_MutexIDmut_Serial;//mutex for access to serial port
void __assertion_failed(char *_Expr, char *_File, int _Line, const char *_Func) {
//Put a breakpoint here to check for failed assertions, or put a loop and some hardware indicator
}
void taskBlink0(void *param);
void taskBlink1(void *param);
void taskReceiveFromUart(void* param);
int main(void)
{
/* Enable GPIO block clock */
//SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);
UARTInit(115200);
UARTSend((uint8_t *)"Starting\r\n",10);
GPIOInit();
LPC_IOCON->JTAG_nTRST_PIO1_2&= ~0x07;
LPC_IOCON->JTAG_nTRST_PIO1_2|= 0x01;
GPIOSetDir(RED_PORT,RED_BIT,1);
GPIOSetDir(BLUE_PORT,BLUE_BIT,1);
GPIOSetDir(GREEN_PORT,GREEN_BIT,1);
GPIOSetValue(RED_PORT,RED_BIT,0);
GPIOSetValue(BLUE_PORT,BLUE_BIT,0);
GPIOSetValue(GREEN_PORT,GREEN_BIT ,0);
CoInitOS();
mut_Serial = CoCreateMutex();
/* Create Blink Task 0 */
CoCreateTask( taskBlink0,
(void *)0,
PRIORITY_BLINK_TASK0,
&stkBlink0[SIZE_BLINK_TASK0-1],
SIZE_BLINK_TASK0 );
/* Create Blink Task 1 */
CoCreateTask( taskBlink1,
(void *)0,
PRIORITY_BLINK_TASK1,
&stkBlink1[SIZE_BLINK_TASK1-1],
SIZE_BLINK_TASK1 );
/* Create Recieve Task 1 */
CoCreateTask( taskReceiveFromUart,
(void *)0,
PRIORITY_RECIEVE,
&stkReceive[SIZE_RECEIVE-1],
SIZE_RECEIVE );
ASSERT(1==0);
CoStartOS();
while(1);
}
void taskReceiveFromUart( void *param ) {
for(;; ) {
CoEnterMutexSection(mut_Serial);
UARTSend((uint8_t *)"In recieve routine\r\n",20);
CoLeaveMutexSection(mut_Serial);
CoTickDelay(20);/* Delay 200ms */
}
}
void taskBlink0(void *param)
{
/* Set PIO7 as output. */
GPIOSetDir( LED_PORT, LED_BIT, 1 );
for(;;) {
/* Turn On Led */
GPIOSetValue(LED_PORT, LED_BIT,0 );
CoTickDelay(20);/* Delay 200ms */
CoEnterMutexSection(mut_Serial);
UARTSend((uint8_t *)"In 0\r\n",6);
CoLeaveMutexSection(mut_Serial);
/* Turn Off Led */
GPIOSetValue( LED_PORT, LED_BIT,1 );
CoTickDelay(20);/* Delay 200ms */
}
}
void taskBlink1(void *param)
{
/* Set PIO2_1 as output. */
uint32_t state = 0;
GPIOSetDir( RED_PORT, RED_BIT, 1 );
GPIOSetDir( BLUE_PORT, BLUE_BIT, 1 );
GPIOSetDir( GREEN_PORT, GREEN_BIT, 1 );
for(;;) {
/* Turn On Led */
switch( state ) {
case 0:
GPIOSetValue( RED_PORT, RED_BIT,1 );
break;
case 1:
GPIOSetValue( BLUE_PORT, BLUE_BIT ,1 );
break;
case 2:
GPIOSetValue( GREEN_PORT, GREEN_BIT,1 );
break;
}
CoTickDelay(40);/* Delay 400ms */
CoEnterMutexSection(mut_Serial);
UARTSend((uint8_t *)"In 1\r\n",6);
CoLeaveMutexSection(mut_Serial);
/* Turn Off Led */
switch( state ) {
case 0:
GPIOSetValue( RED_PORT, RED_BIT,0 );
state++;
break;
case 1:
GPIOSetValue( BLUE_PORT, BLUE_BIT,0 );
state++;
break;
case 2:
GPIOSetValue( GREEN_PORT, GREEN_BIT,0 );
state=0;
break;
}
CoTickDelay(40);/* Delay 400ms */
}
}
|