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"
- #include "stdlib.h"
- #include "ITM_write.h"
- /*****************************************************************************
- * Private types/enumerations/variables
- ****************************************************************************/
- QueueHandle_t xQueue;
- typedef int qItem;
- struct debugEvent {
- char *format;
- uint32_t data[3];
- };
- char *debugFormat[] = {"Received %d characters at %d \r\n", "Pressed SW1 for %d \r\n"};
- /*****************************************************************************
- * 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;
- debugEvent e;
- for (;;)
- {
- vTaskDelay(100);
- char x = (char) Board_UARTGetChar();
- if ( (32 <= x && x < 127) || x == 9 || x == '\n' || x == '\r')
- {
- if (x != '\n' && x != '\r')
- {
- Board_UARTPutChar(x);
- if (32 < x && x < 127)
- {
- charnum++;
- }
- }
- if ( (x == 32 || x == 9 || x == '\n' || x == '\r') )
- {
- e.format = debugFormat[0];
- e.data[0] = charnum;
- e.data[1] = xTaskGetTickCount();
- if (x == '\n' || x == '\r')
- {
- Board_UARTPutSTR(" \r\n");
- }
- xQueueSendToBack( xQueue, &e, 0 );
- charnum = 0;
- }
- }
- }
- }
- static void Task2(void *pvParameters) {
- bool onread = false;
- debugEvent e;
- TickType_t t = 0;
- for (;;)
- {
- if ( SW1.read() == true)
- {
- if (t == 0)
- t = xTaskGetTickCount();
- }
- else if ( t > 0 )
- {
- e.format = debugFormat[1];
- e.data[0] = xTaskGetTickCount() - t;
- xQueueSendToBack( xQueue, &e, 0 );
- t = 0;
- }
- vTaskDelay(10);
- }
- }
- static void Task3(void *pvParameters) {
- char buffer[64];
- debugEvent e;
- for (;;)
- {
- xQueueReceive( xQueue, &e, portMAX_DELAY );
- snprintf(buffer, 64, e.format, e.data[0], e.data[1], e.data[3]);
- ITM_write(buffer);
- }
- }
- /*****************************************************************************
- * 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();
- ITM_init();
- xQueue = xQueueCreate( 20, sizeof( debugEvent ));
- xTaskCreate(Task1, "Task1",
- configMINIMAL_STACK_SIZE * 3, NULL, (tskIDLE_PRIORITY + 2UL),
- (TaskHandle_t *) NULL);
- xTaskCreate(Task2, "Task2",
- configMINIMAL_STACK_SIZE * 3, NULL, (tskIDLE_PRIORITY + 2UL),
- (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