Advertisement
yigitusta9

EmbeddedOS_Lab2_2

Aug 30th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. /*
  2. ===============================================================================
  3.  Name        : main.c
  4.  Author      : $(author)
  5.  Version     :
  6.  Copyright   : $(copyright)
  7.  Description : main definition
  8. ===============================================================================
  9. */
  10.  
  11. #if defined (__USE_LPCOPEN)
  12. #if defined(NO_BOARD_LIB)
  13. #include "chip.h"
  14. #else
  15. #include "board.h"
  16. #endif
  17. #endif
  18.  
  19. #include <cr_section_macros.h>
  20.  
  21. // TODO: insert other include files here
  22.  
  23. // TODO: insert other definitions and declarations here
  24.  
  25. #include "FreeRTOS.h"
  26. #include "task.h"
  27. #include "semphr.h"
  28. /*****************************************************************************
  29.  * Private types/enumerations/variables
  30.  ****************************************************************************/
  31.  
  32. /*****************************************************************************
  33.  * Public types/enumerations/variables
  34.  ****************************************************************************/
  35.  
  36. SemaphoreHandle_t xSemaphore =  NULL;
  37. /*****************************************************************************
  38.  * Private functions
  39.  ****************************************************************************/
  40.  
  41. /* Sets up system hardware */
  42. static void prvSetupHardware(void)
  43. {
  44.     SystemCoreClockUpdate();
  45.     Board_Init();
  46.  
  47.     /* Initial LED0 state is off */
  48.     Board_LED_Set(0, false);
  49. }
  50.  
  51. static void Task1(void *pvParameters) {
  52.     for (;;)
  53.     {
  54.         char x = (char) Board_UARTGetChar();
  55.         if (48 <= x && x <= 122)
  56.         {
  57.             Board_UARTPutChar(x);
  58.             xSemaphoreGive( xSemaphore );
  59.         }
  60.     }
  61. }
  62.  
  63. static void Task2(void *pvParameters) {
  64.     for(;;)
  65.     {
  66.         if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE)
  67.         {
  68.             Board_LED_Set(1, 1);
  69.             vTaskDelay(configTICK_RATE_HZ / 10);
  70.             Board_LED_Set(1, 0);
  71.             vTaskDelay(configTICK_RATE_HZ / 10);
  72.         }
  73.     }
  74. }
  75.  
  76. /*****************************************************************************
  77.  * Public functions
  78.  ****************************************************************************/
  79.  
  80. /* the following is required if runtime statistics are to be collected */
  81. extern "C" {
  82.  
  83. void vConfigureTimerForRunTimeStats( void ) {
  84.     Chip_SCT_Init(LPC_SCTSMALL1);
  85.     LPC_SCTSMALL1->CONFIG = SCT_CONFIG_32BIT_COUNTER;
  86.     LPC_SCTSMALL1->CTRL_U = SCT_CTRL_PRE_L(255) | SCT_CTRL_CLRCTR_L; // set prescaler to 256 (255 + 1), and start timer
  87. }
  88.  
  89. }
  90. /* end runtime statictics collection */
  91.  
  92. /**
  93.  * @brief   main routine for FreeRTOS blinky example
  94.  * @return  Nothing, function should not exit
  95.  */
  96. int main(void)
  97. {
  98.     prvSetupHardware();
  99.  
  100.     xSemaphore = xSemaphoreCreateBinary();
  101.     xSemaphoreGive(xSemaphore);
  102.  
  103.     xTaskCreate(Task1, "Task1",
  104.                 configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
  105.                 (TaskHandle_t *) NULL);
  106.  
  107.     xTaskCreate(Task2, "Task2",
  108.                 configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
  109.                 (TaskHandle_t *) NULL);
  110.  
  111.     /* Start the scheduler */
  112.     vTaskStartScheduler();
  113.  
  114.     /* Should never arrive here */
  115.     return 1;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement