// ----------------------------------------------------------------------------- /// @file main.c /// @brief Description // ----------------------------------------------------------------------------- // Micro-Key bv // Industrieweg 28, 9804 TG Noordhorn // Postbus 92, 9800 AB Zuidhorn // The Netherlands // Tel: +31 594 503020 // Fax: +31 594 505825 // Email: support@microkey.nl // Web: www.microkey.nl // ----------------------------------------------------------------------------- /// $Revision$ /// $Author$ /// $Date$ // (c) 2017 Micro-Key bv // ----------------------------------------------------------------------------- /// @file main.c /// @ingroup {group_name} // ----------------------------------------------------------------------------- // Include files // ----------------------------------------------------------------------------- #include #include #include // FreeRTOS includes #include "FreeRTOS.h" #include "task.h" #include "stm32f10x.h" #include "misc.h" #include "ADConverters.h" #include "DAConverters.h" #include "DeviceParameters.h" #include "Displays.h" #include "Error.h" #include "hsb-mrts.h" #include "hwValidationMenu.h" #include "repairMenus.h" #include "Warning.h" #include "CathodeMCP.h" #include "CoverSolenoid.h" #include "Interlock.h" #include "Logger.h" #include "nhd0420.h" #include "Power6V5Supply.h" #include "TeslaGunSafety.h" #include "PCBA.h" #include "uart.h" // ----------------------------------------------------------------------------- // Constant and macro definitions // ----------------------------------------------------------------------------- /* The time between cycles of the 'check' functionality (defined within the tick hook. */ #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS ) #define INIT_START_SCREEN_DELAY (5000) // ----------------------------------------------------------------------------- // Type definitions // ----------------------------------------------------------------------------- struct LedTaskArguments { struct Gpio* led; int frequency; }; // ----------------------------------------------------------------------------- // File-scope variables // ----------------------------------------------------------------------------- /* Variable that counts at 20KHz to provide the time base for the run time stats. */ unsigned long ulRunTimeStatsClock = 0UL; static struct LedTaskArguments ledTaskArguments; static xTaskHandle initTaskHandle; static xTaskHandle ledTaskHandle; static xTaskHandle sysTaskHandle; static struct HwValidationMenu _hwValidation = {.initialized = false}; static struct HwValidationMenuItems hwTestItems; struct HwValidationMenu* hwValidation = &_hwValidation; static struct CachedStorage cs = {.initialized = false}; static struct CachedStorage deviceParameters = {.initialized = false}; // ----------------------------------------------------------------------------- // Function declarations // ----------------------------------------------------------------------------- static ErrorStatus systeminfoCommandHandler(void); static void initTask(void* parameters); static void ledBlinkTask(void* parameters); // ----------------------------------------------------------------------------- // Function definitions // ----------------------------------------------------------------------------- int main (void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); // Create TaskHandles ledTaskArguments.led = ledOrange; ledTaskArguments.frequency = 1; xTaskCreate(initTask, (const char* const)"initTask", 1024, NULL, 5, &initTaskHandle); /* Start the scheduler. */ vTaskStartScheduler(); /* Will only get here if there was insufficient memory to create the idle task. The idle task is created within vTaskStartScheduler(). */ for( ;; ); return -1; } void vApplicationTickHook () { } static void printSystemInfoTask(void* parameters) { while (1) { LOGGER_INFO(mainLog, "---------------------------------------"); systeminfoCommandHandler(); vTaskDelay(20000); } } static ErrorStatus systeminfoCommandHandler(void) { ErrorStatus errorStatus = SUCCESS; size_t freeMemory; char text[128]; freeMemory = xPortGetFreeHeapSize(); snprintf(text, sizeof(text), "Free heap memory: %d bytes", (int)freeMemory); LOGGER_INFO(mainLog, text); return errorStatus; } static void initTask(void* parameters) { ErrorStatus returnValue = SUCCESS; if (returnValue == SUCCESS) { // Create the error handler Error_construct(); } if (returnValue == SUCCESS) { // Create the warning handler Warning_construct(); } if (returnValue == SUCCESS) { // Initialize the platform first // All IO is initialized here // Also, all periphery and platform-specifics are initialized here // IRQs are defined here initPlatform(); } if (returnValue == SUCCESS) { // Construct the displays Displays_construct(); } if (returnValue == SUCCESS) { // Construct the AD Converters ADConverters_construct(); } if (returnValue == SUCCESS) { // Construct the DA Converters DAConverters_construct(); } if (returnValue == SUCCESS) { hsb_generateStartScreen(mainDisplay); // Let start screen stay for 5 seconds vTaskDelay(INIT_START_SCREEN_DELAY); } if (returnValue == SUCCESS) { // Construct/Load the device parameters DeviceParameters_construct(&deviceParameters, &iFlash->memoryDevice); } if (returnValue == SUCCESS) { // Construct the repair presets RepairPresets_construct(&cs, &iFlash->memoryDevice); } if (returnValue == SUCCESS) { hwTestItems.display = &nhd0420->displayDevice; hwTestItems.internalADC = adc1; hwTestItems.externalDAC = max5715; hwTestItems.power6v5Enable = Power6V5Supply_getGPIO(); hwTestItems.interlockNO = interlock->NO.io; hwTestItems.interlockNC = interlock->NC.io; hwTestItems.TeslaSecurity = TeslaGunSafety_getGpio(); hwTestItems.solenoid = CoverSolenoid_getGpio(); hwTestItems.mcp0Relay = CathodeMCP_getInstance()->mcp0; hwTestItems.mcp1Relay = CathodeMCP_getInstance()->mcp1; hwTestItems.mcp2Relay = CathodeMCP_getInstance()->mcp2; hwTestItems.cat0Relay = CathodeMCP_getInstance()->cat0; hwTestItems.cat1Relay = CathodeMCP_getInstance()->cat1; hwTestItems.cat2Relay = CathodeMCP_getInstance()->cat2; hwTestItems.pcba = PCBA_getInstance(); hwTestItems.keypad = keypad; // EEPROM TO BE DONE HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 1024); } if (returnValue == SUCCESS) { // Create task that repeats to print out TASK information on the logger xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 0, &sysTaskHandle); // Create a small task that only blinks a LED and flashes the identification letter on the display xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 100, &ledTaskArguments, 0, &ledTaskHandle); } if (returnValue == SUCCESS) { // Construct the repair menu repairMenus_construct(); } // Delete this init task vTaskDelete(NULL); } static void ledBlinkTask (void* parameters) { char high = 1; char low = 0; char indicator[2]; indicator[0] = ' '; indicator[1] = '\0'; struct LedTaskArguments* arguments = (struct LedTaskArguments*) parameters; struct Gpio* gpio = arguments->led; int frequency = arguments->frequency; while (1) { IODevice_write(&gpio->device, &high, 1); if (PCBA_getInstance()->pcba == PCBA_CathodeMCP) { indicator[0] = CathodeMCP_getInstance()->name[0]; Display_write(mainDisplay, indicator, 1, 20); } else { indicator[0] = PCBA_getInstance()->name[0]; Display_write(mainDisplay, indicator, 1, 20); } vTaskDelay(configTICK_RATE_HZ / (frequency * 2)); IODevice_write(&gpio->device, &low, 1); indicator[0] = ' '; // Display_write(mainDisplay, indicator, 1, 20); vTaskDelay(configTICK_RATE_HZ / (frequency * 2)); } }