/** * @brief Text * @param None * @retval None */ void backgroundTask(void *pvParameters) { prvHardwareInit(); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); /* Create the blink timer */ prvBlinkTimer = xTimerCreate("RefreshTimer", 500 / portTICK_PERIOD_MS, pdTRUE, 0, prvBlinkTimerCallback); if (prvBlinkTimer != NULL) xTimerStart(prvBlinkTimer, portMAX_DELAY); UART1_Init(); vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); I2C_EEPROM_Init(); // I2C_EEPROM_WriteByte(0x00, 0xEC); // data = 0x00; // data = I2C_EEPROM_ReadByte(0x00); // if (data != 0xEC) // BUZZER_BeepNumOfTimes(20); // else // BUZZER_BeepNumOfTimes(5); while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); } }
/** * @brief The main task for the CAN2 channel * @param pvParameters: * @retval None */ void can2Task(void *pvParameters) { /* Mutex semaphore to manage when it's ok to send and receive new data */ xSemaphore = xSemaphoreCreateMutex(); /* Mutex semaphore for accessing the settings for this channel */ xSettingsSemaphore = xSemaphoreCreateMutex(); /* Create software timers */ prvBuffer1ClearTimer = xTimerCreate("Buf1Clear4", 10, pdFALSE, 0, prvBuffer1ClearTimerCallback); prvBuffer2ClearTimer = xTimerCreate("Buf2Clear5", 10, pdFALSE, 0, prvBuffer2ClearTimerCallback); /* Initialize hardware */ prvHardwareInit(); vTaskDelay(2000); // can2SetTermination(CANTermination_Connected); can2SetConnection(CANConnection_Connected); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); } }
/* Main ----------------------------------------------------------------------*/ int main(void) { SystemInit(); prvHardwareInit(); vTraceInitTraceData(); c_common_usart_puts(USART2, "Programa iniciado!\n\r"); vTraceConsoleMessage("Starting application..."); //sprintf(str, "Line, %d \n\r", __LINE__); //c_common_usart_puts(USART2, str); if (! uiTraceStart() ) vTraceConsoleMessage("Could not start recorder!"); /* create tasks */ xTaskCreate(blink_led_task, (signed char *)"Blink led", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY+1, NULL); xTaskCreate(sonar_task, (signed char *)"Sonar task", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY+1, NULL); //xTaskCreate(echo_task, (signed char *)"Echo task", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY+1, NULL); //xTaskCreate(blctrl_task, (signed char *)"blctrl task" , configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY+1, NULL); //xTaskCreate(uart_task , (signed char *)"UART task", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY+1, NULL); //xTaskCreate(rc_servo_task , (signed char *)"Servo task", configMINIMAL_STACK_SIZE, (void *)NULL, tskIDLE_PRIORITY+1, NULL); /* Start the scheduler. */ vTaskStartScheduler(); /* should never reach here! */ for(;;); }
/** * @brief The main task for the CAN1 channel * @param pvParameters: * @retval None */ void can1Task(void *pvParameters) { /* Mutex semaphore to manage when it's ok to send and receive new data */ xSemaphore = xSemaphoreCreateMutex(); /* Mutex semaphore for accessing the settings for this channel */ xSettingsSemaphore = xSemaphoreCreateMutex(); /* Create software timers */ prvBuffer1ClearTimer = xTimerCreate("Buf1ClearCan1", 10, pdFALSE, 0, prvBuffer1ClearTimerCallback); prvBuffer2ClearTimer = xTimerCreate("Buf2ClearCan1", 10, pdFALSE, 0, prvBuffer2ClearTimerCallback); /* Initialize hardware */ prvHardwareInit(); /* Wait to make sure the SPI FLASH is initialized */ while (SPI_FLASH_Initialized() == false) { vTaskDelay(100 / portTICK_PERIOD_MS); } /* Try to read the settings from SPI FLASH */ prvReadSettingsFromSpiFlash(); can1Clear(); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); uint8_t count = 0; prvDoneInitializing = true; while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); // /* Transmit debug data */ // if (prvCurrentSettings.connection == CANConnection_Connected) // { // /* Set the data to be transmitted */ // uint8_t data[2] = {0xAA, count}; // can1Transmit(0x321, data, CANDataLength_2, 50); // count++; // // if (count % 10 == 0) // { // uint8_t data2[5] = {0x72, 0x21, 0xDE, 0x03, 0xFA}; // can1Transmit(0x321, data2, CANDataLength_5, 50); // } // } } }
/** * @brief The main task for the UART1 channel * @param pvParameters: * @retval None */ void uart1Task(void *pvParameters) { /* Mutex semaphore to manage when it's ok to send and receive new data */ xSemaphore = xSemaphoreCreateMutex(); /* Mutex semaphore for accessing the settings for this channel */ xSettingsSemaphore = xSemaphoreCreateMutex(); /* Create software timers */ prvBuffer1ClearTimer = xTimerCreate("Buf1ClearUart1", 10, pdFALSE, 0, prvBuffer1ClearTimerCallback); prvBuffer2ClearTimer = xTimerCreate("Buf2ClearUart1", 10, pdFALSE, 0, prvBuffer2ClearTimerCallback); /* Initialize hardware */ prvHardwareInit(); /* Wait to make sure the SPI FLASH is initialized */ while (SPI_FLASH_Initialized() == false) { vTaskDelay(100 / portTICK_PERIOD_MS); } /* Try to read the settings from SPI FLASH */ prvReadSettingsFromSpiFlash(); /* * TODO: Figure out a good way to allow saved data in SPI FLASH to be read next time we wake up so that we * don't have to do a clear every time we start up the device. */ uart1Clear(); // uint8_t* data = "UART1 Debug! "; uint8_t* data = "Prevas Student Embedded Awards 2014 - "; /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); prvDoneInitializing = true; while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); /* Transmit debug data if that mode is active */ if (prvCurrentSettings.connection == UARTConnection_Connected && prvCurrentSettings.mode == UARTMode_DebugTX) uart1Transmit(data, strlen(data)); } /* Something has gone wrong */ error: while (1); }
/** * @brief The main task for the GPIO0 channel * @param pvParameters: * @retval None */ void gpio0Task(void *pvParameters) { prvHardwareInit(); gpio0SetDirection(GPIODirection_Output); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); } }
/** * @brief The main task for the CAN2 channel * @param pvParameters: * @retval None */ void can2Task(void *pvParameters) { /* Mutex semaphore to manage when it's ok to send and receive new data */ xSemaphore = xSemaphoreCreateMutex(); /* Mutex semaphore for accessing the settings for this channel */ xSettingsSemaphore = xSemaphoreCreateMutex(); /* Create software timers */ prvBuffer1ClearTimer = xTimerCreate("Buf1ClearCan2", 10, pdFALSE, 0, prvBuffer1ClearTimerCallback); prvBuffer2ClearTimer = xTimerCreate("Buf2ClearCan2", 10, pdFALSE, 0, prvBuffer2ClearTimerCallback); /* Initialize hardware */ prvHardwareInit(); /* Wait to make sure the SPI FLASH is initialized */ while (SPI_FLASH_Initialized() == false) { vTaskDelay(100 / portTICK_PERIOD_MS); } /* Try to read the settings from SPI FLASH */ prvReadSettingsFromSpiFlash(); can2Clear(); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); prvDoneInitializing = true; while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); } }
/** * @brief Text * @param None * @retval None */ void lcdTask(void *pvParameters) { /* Initialize the hardware */ prvHardwareInit(); /* Display splash screen */ prvSplashScreen(); /* Create the LCDEventMessage queue */ xLCDEventQueue = xQueueCreate(10, sizeof(LCDEventMessage)); if (xLCDEventQueue == 0) { /* TODO */ // Queue was not created and must not be used. } MAIN_TASK_NotifyLcdTaskIsDone(); prvRefreshTimer = xTimerCreate("RefreshTimer", 25 / portTICK_PERIOD_MS, pdTRUE, 0, prvRefreshTimerCallback); if (prvRefreshTimer != NULL) xTimerStart(prvRefreshTimer, portMAX_DELAY); LCDEventMessage receivedMessage; while (1) { /* Wait for a message to be received or the timeout to happen */ if (xLCDEventQueue != 0 && xQueueReceive(xLCDEventQueue, &receivedMessage, 50) == pdTRUE) { /* Item successfully removed from the queue */ switch (receivedMessage.event) { /* New touch data received */ case LCDEvent_TouchEvent: if (receivedMessage.data[3] == FT5206Point_1) { if (receivedMessage.data[2] == FT5206Event_PutUp) GUI_TouchAtPosition(GUITouchEvent_Up, receivedMessage.data[0], receivedMessage.data[1]); else if (receivedMessage.data[2] == FT5206Event_Contact || receivedMessage.data[2] == FT5206Event_PutDown) GUI_TouchAtPosition(GUITouchEvent_Down, receivedMessage.data[0], receivedMessage.data[1]); HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13); #if 0 /* DEBUG */ if (GUI_GetDisplayStateForTextBox(GUITextBoxId_Debug) == GUIDisplayState_NotHidden) { GUITextBox_SetWritePosition(GUITextBoxId_Debug, 5, 5); GUITextBox_Clear(GUITextBoxId_Debug); GUITextBox_WriteString(GUITextBoxId_Debug, "X:"); GUITextBox_WriteNumber(GUITextBoxId_Debug, receivedMessage.data[0]); GUITextBox_WriteString(GUITextBoxId_Debug, ", Y:"); GUITextBox_WriteNumber(GUITextBoxId_Debug, receivedMessage.data[1]); GUITextBox_WriteString(GUITextBoxId_Debug, ", EVENT:"); GUITextBox_WriteNumber(GUITextBoxId_Debug, receivedMessage.data[2]); } #endif #if 0 /* Draw a dot on debug */ LCD_DrawPixelOnLayer(0xFFFFFFFF, receivedMessage.data[0], receivedMessage.data[1], LCD_LAYER_1); // LCD_DrawFilledCircleOnLayer(0xFFFFFFFF, receivedMessage.data[0], receivedMessage.data[1], 10, LCD_LAYER_1); prvRefreshDisplay = true; #endif } break; default: break; } } else { /* Timeout has occured i.e. no message available */ // HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2); /* Do something else */ } } }
/** * @brief The main task for the LCD * @param pvParameters: * @retval None */ void lcdTask(void *pvParameters) { /* Initialize the hardware */ prvHardwareInit(); /* Display splash screen */ prvSplashScreen(); /* Make sure all channels have started up before we initialize the GUI */ while (!prvAllChanneAreDoneInitializing()) { vTaskDelay(1 / portTICK_PERIOD_MS); } /* Initialize the GUI elements */ prvInitGuiElements(); xLCDEventQueue = xQueueCreate(10, sizeof(LCDEventMessage)); if (xLCDEventQueue == 0) { // Queue was not created and must not be used. } prvMainTextBoxRefreshTimer = xTimerCreate("MainTextBoxTimer", 10 / portTICK_PERIOD_MS, pdTRUE, 0, prvMainContainerRefreshTimerCallback); if (prvMainTextBoxRefreshTimer != NULL) xTimerStart(prvMainTextBoxRefreshTimer, portMAX_DELAY); LCDEventMessage receivedMessage; // GUITextBox_WriteString(GUITextBoxId_Clock, "14:15:12"); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); while (1) { /* Wait for a message to be received or the timeout to happen */ if (xQueueReceive(xLCDEventQueue, &receivedMessage, 50) == pdTRUE) { /* Item successfully removed from the queue */ switch (receivedMessage.event) { /* New touch data received */ case LCDEvent_TouchEvent: if (receivedMessage.data[3] == FT5206Point_1) { #if 0 /* DEBUG */ if (GUI_GetDisplayStateForTextBox(GUITextBoxId_Debug) == GUIDisplayState_NotHidden) { GUITextBox_SetWritePosition(GUITextBoxId_Debug, 5, 5); GUITextBox_Clear(GUITextBoxId_Debug); GUITextBox_WriteString(GUITextBoxId_Debug, "X:"); GUITextBox_WriteNumber(GUITextBoxId_Debug, receivedMessage.data[0]); GUITextBox_WriteString(GUITextBoxId_Debug, ", Y:"); GUITextBox_WriteNumber(GUITextBoxId_Debug, receivedMessage.data[1]); GUITextBox_WriteString(GUITextBoxId_Debug, ", EVENT:"); GUITextBox_WriteNumber(GUITextBoxId_Debug, receivedMessage.data[2]); } #endif #if 0 /* Draw a dot on debug */ if (!prvDebugConsoleIsHidden) { LCD_SetForegroundColor(LCD_COLOR_GREEN); LCD_DrawCircle(receivedMessage.data[0], receivedMessage.data[1], 2, 1); } #endif GUITouchEvent touchEvent; if (receivedMessage.data[2] == FT5206Event_PutUp) touchEvent = GUITouchEvent_Up; else if (receivedMessage.data[2] == FT5206Event_PutDown) touchEvent = GUITouchEvent_Down; /* Check all buttons */ GUIButton_CheckAllActiveForTouchEventAt(touchEvent, receivedMessage.data[0], receivedMessage.data[1]); /* Check all text boxes */ GUITextBox_CheckAllActiveForTouchEventAt(touchEvent, receivedMessage.data[0], receivedMessage.data[1]); /* Check all containers */ GUIContainer_CheckAllActiveForTouchEventAt(touchEvent, receivedMessage.data[0], receivedMessage.data[1]); } break; /* New temperature data received */ case LCDEvent_TemperatureData: memcpy(&prvTemperature, receivedMessage.data, sizeof(float)); int8_t currentTemp = (int8_t)prvTemperature - 11; GUITextBox_Draw(GUITextBoxId_Temperature); GUITextBox_SetWritePosition(GUITextBoxId_Temperature, 50, 3); GUITextBox_WriteNumber(GUITextBoxId_Temperature, (int32_t)currentTemp); GUITextBox_WriteString(GUITextBoxId_Temperature, " C"); break; /* Debug message received */ case LCDEvent_DebugMessage: GUITextBox_SetWritePosition(GUITextBoxId_Debug, 5, 5); GUITextBox_Clear(GUITextBoxId_Debug); GUITextBox_WriteNumber(GUITextBoxId_Debug, receivedMessage.data[0]); GUITextBox_WriteString(GUITextBoxId_Debug, " - "); GUITextBox_WriteString(GUITextBoxId_Debug, (uint8_t*)receivedMessage.data[1]); break; default: break; } } else { /* Timeout has occured i.e. no message available */ // HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2); /* Do something else */ } } }