Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c
mmi 71ae4c6832 checked in missing file
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@240 05563f52-14a8-4384-a975-3d1654cca0fa
2017-10-06 09:04:50 +00:00

260 lines
7.7 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 "Display.h"
#include "hwValidationMenu.h"
#include "repairProcess.h"
#include "misc.h"
#include "stm32f10x_rcc.h"
#include "DisplayDevice.h"
#include "MAX5715.h"
#include "nhd0420.h"
#include "platform.h"
#include "adc.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"
#include "Version.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 )
// -----------------------------------------------------------------------------
// 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 Display _display;
struct Display* display = &_display;
static struct NHD0420 nhd0420 = {.initialized = false};
static struct MAX5715 max5715 = {.initialized = false};
static struct RepairProcess _rp = {.initialized = false};
static struct HwValidationMenu _hwValidation = {.initialized = false};
static struct HwValidationMenuItems hwTestItems;
struct RepairProcess* rp = &_rp;
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 = 2;
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(display->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(mainLog->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(keypad->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(rp->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(hwValidation->taskHandle);
return errorStatus;
}
static void initTask(void* parameters)
{
initPlatform();
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 100, &ledTaskArguments, 0, &ledTaskHandle);
Logger_construct(mainLog, &uart3->device, 2, 512);
NHD0420_construct(&nhd0420, &spiDisplay->device);
Display_construct(display, &nhd0420.displayDevice, 0, 256, 10, 1000, 5000);
Display_clearScreen(display);
Display_setBrightness(display, 6);
Display_setContrast(display, 40);
Display_write(display, pcba->name, strlen(pcba->name), 1, 1);
char buffer[20];
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "SW V. %d.%d.%d.%d", Version_getInstance()->major,
Version_getInstance()->minor,
Version_getInstance()->branch,
Version_getInstance()->patch);
Display_write(display, buffer, strlen(buffer), 3, 4);
hwTestItems.display = &nhd0420.displayDevice;
hwTestItems.internalADC = adc1;
hwTestItems.externalDAC = &max5715;
hwTestItems.power6v5Enable = NULL;
hwTestItems.interlock1 = NULL;
hwTestItems.interlock2 = NULL;
hwTestItems.solenoid = NULL;
hwTestItems.mcp0Relay = NULL;
hwTestItems.mcp1Relay = NULL;
hwTestItems.mcp2Relay = NULL;
hwTestItems.cat0Relay = NULL;
hwTestItems.cat1Relay = NULL;
hwTestItems.cat2Relay = NULL;
hwTestItems.pcba = pcba;
// EEPROM TO BE DONE
// HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 2, 1024);
MAX5715_construct(&max5715, &spiDAC->device);
MAX5715_writeREF_ON_2V5(&max5715, MAX5715_SEL_DACA | MAX5715_SEL_DACB | MAX5715_SEL_DACC);
MAX5715Channel_construct(&max5715.dac[0], &max5715, 0);
repairProcess_construct(rp, 3, 1024);
xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 1, &sysTaskHandle);
// Delete this init task
vTaskDelete(NULL);
}
static void ledBlinkTask (void* parameters)
{
char high = 1;
char low = 0;
struct LedTaskArguments* arguments = (struct LedTaskArguments*) parameters;
struct Gpio* gpio = arguments->led;
int frequency = arguments->frequency;
while (1)
{
IODevice_write(&gpio->device, &high, 1);
Display_write(display, pcba->name, 1, 1, 20);
vTaskDelay(configTICK_RATE_HZ / (frequency * 2));
IODevice_write(&gpio->device, &low, 1);
Display_write(display, " ", 1, 1, 20);
vTaskDelay(configTICK_RATE_HZ / (frequency * 2));
}
}