Advertisement
yigitusta9

EmbeddedOS_Lab2_1

Aug 29th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.72 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. #include "DigitalIoPin.h"
  29.  
  30. /*****************************************************************************
  31.  * Private types/enumerations/variables
  32.  ****************************************************************************/
  33.  
  34. /*****************************************************************************
  35.  * Public types/enumerations/variables
  36.  ****************************************************************************/
  37. SemaphoreHandle_t xSemaphore = NULL;
  38. DigitalIoPin SW1(0,17,DigitalIoPin::pullup, true);
  39. DigitalIoPin SW2(1,11,DigitalIoPin::pullup, true);
  40. DigitalIoPin SW3(1,9,DigitalIoPin::pullup, true);
  41. /*****************************************************************************
  42.  * Private functions
  43.  ****************************************************************************/
  44.  
  45. /* Sets up system hardware */
  46. static void prvSetupHardware(void)
  47. {
  48.     SystemCoreClockUpdate();
  49.     Board_Init();
  50.  
  51.     /* Initial LED0 state is off */
  52.     Board_LED_Set(0, false);
  53. }
  54.  
  55. static void monitorSW1(void *pvParameters) {
  56.     while(1) {
  57.         if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE)
  58.         {
  59.             if ( SW1.read() == true ) {
  60.                 DEBUGOUT("SW1 pressed \r\n");
  61.             }
  62.             xSemaphoreGive( xSemaphore );
  63.         }
  64.         vTaskDelay(configTICK_RATE_HZ / 10);
  65.     }
  66. }
  67.  
  68. static void monitorSW2(void *pvParameters) {
  69.     while(1) {
  70.         if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE )
  71.         {
  72.             if ( SW2.read() == true ) {
  73.                 DEBUGOUT("SW2 pressed \r\n");
  74.             }
  75.             xSemaphoreGive( xSemaphore );
  76.         }
  77.         vTaskDelay(configTICK_RATE_HZ / 10);
  78.     }
  79. }
  80.  
  81. static void monitorSW3(void *pvParameters) {
  82.     while(1) {
  83.         if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE )
  84.         {
  85.             if ( SW3.read() == true ) {
  86.                 DEBUGOUT("SW3 pressed \r\n");
  87.             }
  88.             xSemaphoreGive( xSemaphore );
  89.         }
  90.         vTaskDelay(configTICK_RATE_HZ / 10);
  91.     }
  92. }
  93.  
  94. /*****************************************************************************
  95.  * Public functions
  96.  ****************************************************************************/
  97.  
  98. /* the following is required if runtime statistics are to be collected */
  99. extern "C" {
  100.  
  101. void vConfigureTimerForRunTimeStats( void ) {
  102.     Chip_SCT_Init(LPC_SCTSMALL1);
  103.     LPC_SCTSMALL1->CONFIG = SCT_CONFIG_32BIT_COUNTER;
  104.     LPC_SCTSMALL1->CTRL_U = SCT_CTRL_PRE_L(255) | SCT_CTRL_CLRCTR_L; // set prescaler to 256 (255 + 1), and start timer
  105. }
  106.  
  107. }
  108. /* end runtime statictics collection */
  109.  
  110. /**
  111.  * @brief   main routine for FreeRTOS blinky example
  112.  * @return  Nothing, function should not exit
  113.  */
  114. int main(void)
  115. {
  116.     prvSetupHardware();
  117.  
  118.     xSemaphore = xSemaphoreCreateMutex();
  119.  
  120.     /* UART output thread, simply counts seconds */
  121.     xTaskCreate(monitorSW1, "monitorSW1",
  122.                     configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL),
  123.                     (TaskHandle_t *) NULL);
  124.     xTaskCreate(monitorSW2, "monitorSW2",
  125.                     configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL),
  126.                     (TaskHandle_t *) NULL);
  127.     xTaskCreate(monitorSW3, "monitorSW3",
  128.                 configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL),
  129.                 (TaskHandle_t *) NULL);
  130.  
  131.     /* Start the scheduler */
  132.     vTaskStartScheduler();
  133.  
  134.     /* Should never arrive here */
  135.     return 1;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement