Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c
2017-10-25 14:50:20 +00:00

277 lines
7.9 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 "ADConverters.h"
#include "DAConverters.h"
#include "Displays.h"
#include "Error.h"
#include "hsb-mrts.h"
#include "hwValidationMenu.h"
#include "repairMenu.h"
#include "repairMenus.h"
#include "repairProcess.h"
#include "repairProcesses.h"
#include "misc.h"
#include "stm32f10x_rcc.h"
#include "DisplayDevice.h"
#include "KeyboardDevice.h"
#include "MAX5715.h"
#include "nhd0420.h"
#include "platform.h"
#include "CathodeMCP.h"
#include "Interlock.h"
#include "internalADC.h"
#include "gpio.h"
#include "IODevice.h"
#include "keypadMatrix.h"
#include "Logger.h"
#include "PCBA.h"
#include "uart.h"
#include "spi.h"
#include "spiDevice.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;
// -----------------------------------------------------------------------------
// 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", freeMemory);
LOGGER_INFO(mainLog, text);
vTaskDelay(10);
OS_logTaskInfo(ledTaskHandle);
vTaskDelay(10);
OS_logTaskInfo(sysTaskHandle);
vTaskDelay(10);
OS_logTaskInfo(interlock->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(keypad->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(mainDisplay->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(repairMenus_getMainRepairMenu()->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(repairProcesses_getMainRepairProcess()->taskHandle);
return errorStatus;
}
static void initTask(void* parameters)
{
// Create the error handler
Error_construct();
// Initialize the platform first
// All IO is initialized here
// Also, all periphery and platform-specifics are initialized here
// IRQs are defined here
initPlatform();
// 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);
// Construct the displays
Displays_construct();
// Construct the AD Converters
ADConverters_construct();
// Construct the DA Converters
DAConverters_construct();
hsb_generateStartScreen(mainDisplay);
// Let start screen stay for 5 seconds
vTaskDelay(INIT_START_SCREEN_DELAY);
///TODO MUST BE UPDATED
// hwTestItems.display = &nhd0420->displayDevice;
// hwTestItems.internalADC = adc1;
// hwTestItems.externalDAC = max5715;
// hwTestItems.power6v5Enable = power6v5Enable;
// hwTestItems.interlockNO = interlockNO;
// hwTestItems.interlockNC = interlockNC;
// hwTestItems.solenoid = solenoid;
// hwTestItems.mcp0Relay = mcp0Relay;
// hwTestItems.mcp1Relay = mcp1Relay;
// hwTestItems.mcp2Relay = mcp2Relay;
// hwTestItems.cat0Relay = cat0Relay;
// hwTestItems.cat1Relay = cat1Relay;
// hwTestItems.cat2Relay = cat2Relay;
// hwTestItems.pcba = PCBA_getInstance();
// hwTestItems.keypad = keypad;
// EEPROM TO BE DONE
// HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 1024);
// Construct the repair menu
repairMenus_construct();
// xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 0, &sysTaskHandle);
// 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));
}
}