//****************************************************************************************** // LPC1343 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H22.10.25 // Replace date : // History : // Laungage : FreeRTOS ( LPCXpresso/codeRED ) //****************************************************************************************** // Description // //****************************************************************************************** /* Scheduler include files. */ #include "LPC13xx.h" #include "FreeRTOS.h" #include "semphr.h" #include "task.h" void User_Confugration( void ); void Put_PORT(unsigned int ); static void User_TASK_1( void *pvParameters ); static void User_TASK_2( void *pvParameters ); void Move_LED( unsigned int *); // xSemaphoreHandle Ind_Seph; portBASE_TYPE Ind_tmp; volatile unsigned int TASK1_LED = 0x0001; volatile unsigned int TASK2_LED = 0x0010; void main( void ) { // ***************** // 1.Initalized // ***************** User_Confugration( ); vSemaphoreCreateBinary(Ind_Seph); // Create Semaphore // ***************** // 2.Create Task // ***************** xTaskCreate( User_TASK_1, ( const char * const ) "User_Task_1", 100, NULL, 1, NULL ); xTaskCreate( User_TASK_2, ( const char * const ) "User_Task_2", 100, NULL, 1, NULL ); // ***************** // 3.Start Scheduler // ***************** vTaskStartScheduler(); } //****************************************************************************************** // Function Name : User_TASK_1 // Title : // Input : // Output : //****************************************************************************************** static void User_TASK_1( void *pvParameters ) { while(1){ Move_LED(&TASK1_LED); Put_PORT(TASK1_LED | TASK2_LED); if((TASK1_LED & 0x0001)==1) xSemaphoreGiveFromISR(Ind_Seph, &Ind_tmp); vTaskDelay(125 / portTICK_RATE_MS); } } //****************************************************************************************** // Function Name : User_TASK_2 // Title : // Input : // Output : //****************************************************************************************** static void User_TASK_2( void *pvParameters ) { while(1){ Move_LED(&TASK2_LED); Put_PORT(TASK1_LED | TASK2_LED); xSemaphoreTake(Ind_Seph, portMAX_DELAY); } } //****************************************************************************************** // Function Name : Move_LED // Title : // Input : // Output : //****************************************************************************************** void Move_LED( unsigned int *led_lst ) { if((*led_lst & 0b10000000) != 0 ){ *led_lst = ( *led_lst << 1 ) | 0b00000001; }else{ *led_lst = ( *led_lst << 1 ) & 0b11111110; } } //****************************************************************************************** // // Confugration // // //****************************************************************************************** void User_Confugration( void ) { // (1)Define I/O PORT LPC_GPIO2->DIR = 0x000000FF; } void Put_PORT(unsigned int put_data ) { LPC_GPIO2->DATA = put_data ; }