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"
- #include "DigitalIoPin.h"
- /*****************************************************************************
- * Private types/enumerations/variables
- ****************************************************************************/
- /*****************************************************************************
- * Public types/enumerations/variables
- ****************************************************************************/
- SemaphoreHandle_t xSemaphore = NULL;
- DigitalIoPin SW1(0,17,DigitalIoPin::pullup, true);
- DigitalIoPin SW2(1,11,DigitalIoPin::pullup, true);
- DigitalIoPin SW3(1,9,DigitalIoPin::pullup, true);
- /*****************************************************************************
- * 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 monitorSW1(void *pvParameters) {
- while(1) {
- if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE)
- {
- if ( SW1.read() == true ) {
- DEBUGOUT("SW1 pressed \r\n");
- }
- xSemaphoreGive( xSemaphore );
- }
- vTaskDelay(configTICK_RATE_HZ / 10);
- }
- }
- static void monitorSW2(void *pvParameters) {
- while(1) {
- if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE )
- {
- if ( SW2.read() == true ) {
- DEBUGOUT("SW2 pressed \r\n");
- }
- xSemaphoreGive( xSemaphore );
- }
- vTaskDelay(configTICK_RATE_HZ / 10);
- }
- }
- static void monitorSW3(void *pvParameters) {
- while(1) {
- if (xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE )
- {
- if ( SW3.read() == true ) {
- DEBUGOUT("SW3 pressed \r\n");
- }
- xSemaphoreGive( xSemaphore );
- }
- 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 = xSemaphoreCreateMutex();
- /* UART output thread, simply counts seconds */
- xTaskCreate(monitorSW1, "monitorSW1",
- configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL),
- (TaskHandle_t *) NULL);
- xTaskCreate(monitorSW2, "monitorSW2",
- configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL),
- (TaskHandle_t *) NULL);
- xTaskCreate(monitorSW3, "monitorSW3",
- configMINIMAL_STACK_SIZE + 128, 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