Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ===============================================================================
- Name : main.c
- Author : $(author)
- Version :
- Copyright : $(copyright)
- Description : main definition
- ===============================================================================
- */
- #if defined (__USE_LPCOPEN)
- #if defined(NO_BOARD_LIB)
- #include "chip.h"
- #else
- #include "board.h"
- #endif
- #endif
- #include <cr_section_macros.h>
- // TODO: insert other include files here
- // TODO: insert other definitions and declarations here
- #include "FreeRTOS.h"
- #include "task.h"
- #include "semphr.h"
- /*****************************************************************************
- * Private types/enumerations/variables
- ****************************************************************************/
- /*****************************************************************************
- * Public types/enumerations/variables
- ****************************************************************************/
- SemaphoreHandle_t xSemaphore = NULL;
- /*****************************************************************************
- * Private functions
- ****************************************************************************/
- /* Sets up system hardware */
- static void prvSetupHardware(void)
- {
- SystemCoreClockUpdate();
- Board_Init();
- /* Initial LED0 state is off */
- Board_LED_Set(0, false);
- }
- static void Task1(void *pvParameters) {
- for (;;)
- {
- char x = (char) Board_UARTGetChar();
- if (48 <= x && x <= 122)
- {
- Board_UARTPutChar(x);
- xSemaphoreGive( xSemaphore );
- }
- }
- }
- static void Task2(void *pvParameters) {
- for(;;)
- {
- if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE)
- {
- Board_LED_Set(1, 1);
- vTaskDelay(configTICK_RATE_HZ / 10);
- Board_LED_Set(1, 0);
- vTaskDelay(configTICK_RATE_HZ / 10);
- }
- }
- }
- /*****************************************************************************
- * Public functions
- ****************************************************************************/
- /* the following is required if runtime statistics are to be collected */
- extern "C" {
- void vConfigureTimerForRunTimeStats( void ) {
- Chip_SCT_Init(LPC_SCTSMALL1);
- LPC_SCTSMALL1->CONFIG = SCT_CONFIG_32BIT_COUNTER;
- LPC_SCTSMALL1->CTRL_U = SCT_CTRL_PRE_L(255) | SCT_CTRL_CLRCTR_L; // set prescaler to 256 (255 + 1), and start timer
- }
- }
- /* end runtime statictics collection */
- /**
- * @brief main routine for FreeRTOS blinky example
- * @return Nothing, function should not exit
- */
- int main(void)
- {
- prvSetupHardware();
- xSemaphore = xSemaphoreCreateBinary();
- xSemaphoreGive(xSemaphore);
- xTaskCreate(Task1, "Task1",
- configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
- (TaskHandle_t *) NULL);
- xTaskCreate(Task2, "Task2",
- configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
- (TaskHandle_t *) NULL);
- /* Start the scheduler */
- vTaskStartScheduler();
- /* Should never arrive here */
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement