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 "queue.h"
- #include "DigitalIoPin.h"
- /*****************************************************************************
- * Private types/enumerations/variables
- ****************************************************************************/
- QueueHandle_t xQueue;
- typedef int qItem;
- /*****************************************************************************
- * Public types/enumerations/variables
- ****************************************************************************/
- /*****************************************************************************
- * Private functions
- ****************************************************************************/
- /* Sets up system hardware */
- static void prvSetupHardware(void)
- {
- SystemCoreClockUpdate();
- Board_Init();
- /* Initial LED0 state is off */
- Board_LED_Set(0, false);
- }
- DigitalIoPin SW1(0,17,DigitalIoPin::pullup, true);
- static void Task1(void *pvParameters) {
- qItem charnum = 0;
- for (;;)
- {
- vTaskDelay(configTICK_RATE_HZ / 10);
- char x = (char) Board_UARTGetChar();
- if (48 <= x && x <= 122)
- {
- Board_UARTPutChar(x);
- charnum++;
- }
- else if (x == '\n' || x == '\r')
- {
- Board_UARTPutSTR(" \r\n");
- xQueueSendToBack( xQueue, &charnum, 0 );
- charnum = 0;
- }
- }
- }
- static void Task2(void *pvParameters) {
- for (;;)
- {
- vTaskDelay(configTICK_RATE_HZ / 10);
- if ( SW1.read() == true )
- {
- qItem tmp = -1;
- xQueueSendToBack( xQueue, &tmp, 0 );
- }
- }
- }
- static void Task3(void *pvParameters) {
- int total = 0;
- for (;;)
- {
- vTaskDelay(configTICK_RATE_HZ / 10);
- char buff[40];
- qItem num;
- xQueueReceive( xQueue, &num, portMAX_DELAY );
- if (num == -1)
- {
- sprintf(buff,"You have typed %d characters. \r\n", total);
- Board_UARTPutSTR(buff);
- total = 0;
- }
- else
- {
- total += num;
- }
- }
- }
- /*****************************************************************************
- * 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();
- xQueue = xQueueCreate( 5, sizeof( int ));
- xTaskCreate(Task1, "Task1",
- configMINIMAL_STACK_SIZE * 3, NULL, (tskIDLE_PRIORITY + 1UL),
- (TaskHandle_t *) NULL);
- xTaskCreate(Task2, "Task2",
- configMINIMAL_STACK_SIZE * 3, NULL, (tskIDLE_PRIORITY + 1UL),
- (TaskHandle_t *) NULL);
- xTaskCreate(Task3, "Task3",
- configMINIMAL_STACK_SIZE * 3, 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