Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c
mmi e3b613c976 Updated all GPIO to PCBA updated version
Added LED module

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@321 05563f52-14a8-4384-a975-3d1654cca0fa
2017-12-01 13:48:28 +00:00

311 lines
8.6 KiB
C

// -----------------------------------------------------------------------------
/// @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 <FreeRTOSFixes.h>
#include <stdio.h>
#include <string.h>
// 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 "Leds.h"
#include "Logger.h"
#include "nhd0420.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
{
Led 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;
#ifdef ENABLE_HW_VALIDATION
static struct HwValidationMenu _hwValidation = {.initialized = false};
static struct HwValidationMenuItems hwTestItems;
struct HwValidationMenu* hwValidation = &_hwValidation;
#endif
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 = LED_ONBOARD_ORANGE;
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 LEDs
Led_construct();
}
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);
}
#ifdef ENABLE_HW_VALIDATION
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, &uart3->device, &hwTestItems, 1, 1024);
}
#endif
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 indicator[2];
indicator[0] = ' ';
indicator[1] = '\0';
struct LedTaskArguments* arguments = (struct LedTaskArguments*) parameters;
int frequency = arguments->frequency;
while (1)
{
Led_on(arguments->led);
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));
Led_off(arguments->led);
indicator[0] = ' ';
// Display_write(mainDisplay, indicator, 1, 20);
vTaskDelay(configTICK_RATE_HZ / (frequency * 2));
}
}