Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c
mmi 54b6afe5a3 Added Interlock
Fixed PID regulation functionality

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@250 05563f52-14a8-4384-a975-3d1654cca0fa
2017-10-12 07:16:50 +00:00

207 lines
6.4 KiB
C

// -----------------------------------------------------------------------------
/// @file repairMenu.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 repairMenu.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "stdio.h"
#include "string.h"
#include "repairMenu.h"
#include "repairProcess.h"
#include "Display.h"
#include "Logger.h"
#include "internalADC.h"
#include "MAX5715.h"
#include "KeyboardDevice.h"
#include "storm700.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static void repairMenu_task(void* parameters);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* display, int taskPriority, uint16_t stackSize)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
// Create a semaphore to sync access to the display shadow
vSemaphoreCreateBinary(self->secondsSyncronisation);
xSemaphoreGive(self->secondsSyncronisation);
BaseType_t rv = xTaskCreate(repairMenu_task, "RepairMenu", stackSize, self, taskPriority, &self->taskHandle);
if (rv != pdTRUE)
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
LOGGER_INFO(mainLog, "Repair Menu task started");
self->runTask = true;
self->initialized = true;
self->display = display;
}
else
{
LOGGER_ERROR(mainLog, "FAILED to start repair Menu with code %d", (int)rv);
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void repairMenu_destruct (struct RepairMenu* self)
{
self->initialized = false;
}
void repairMenu_feedSecondsCounter(struct RepairMenu* self)
{
if (self->initialized)
{
xSemaphoreGive(self->secondsSyncronisation);
}
}
void repairMenu_feedSecondsCounterFromISR(struct RepairMenu* self)
{
portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
if (self->initialized)
{
xSemaphoreGiveFromISR(self->secondsSyncronisation, &higherPriorityTaskWoken);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
static struct RepairProcess _rp = {.initialized = false};
struct RepairProcess* rp = &_rp;
extern struct MAX5715* dac;
extern struct Storm700* storm700;
static void repairMenu_task(void* parameters)
{
struct RepairMenu* self = (struct RepairMenu*)parameters;
Display_clearLine(self->display, 3);
struct RepairProcessParameters rpParameters;
rpParameters.adcRow1 = &adc1->channel[0];
rpParameters.adcRow2 = &adc1->channel[1];
rpParameters.adcRow3 = &adc1->channel[2];
rpParameters.dacRow1 = &dac->dac[0];
rpParameters.dacRow2 = &dac->dac[1];
rpParameters.dacRow3 = &dac->dac[2];
// struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 300, .softstartDuration = 120};
// struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 120, .softstartDuration = 30};
struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 7200, .softstartDuration = 1800};
struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 1800, .softstartDuration = 900};
struct RepairPreset repairPreset;
repairPreset.numberOfStages = 2;
repairPreset.preset[0] = presetStage1;
repairPreset.preset[1] = presetStage2;
rp->repairPreset = &repairPreset;
repairProcess_construct(rp, &rpParameters, 2, 512);
while(self->runTask)
{
xSemaphoreTake(self->secondsSyncronisation, portMAX_DELAY);
uint32_t secondsCounter;
repairProcess_getRepairTime(rp, &secondsCounter);
int hours = (secondsCounter / (60 * 60));
int minutes = (secondsCounter - (hours * 60 * 60)) / 60;
int seconds = (secondsCounter - (hours * 60 * 60) - (minutes * 60));
char buffer[20];
snprintf (buffer, sizeof(buffer) / sizeof(buffer[0]), "%02d:%02d:%02d", hours, minutes, seconds);
Display_write(self->display, buffer, strlen(buffer), 2, 7);
Display_write(self->display, "R1", strlen("R1"), 3, 3);
Display_write(self->display, "R2", strlen("R2"), 3, 10);
Display_write(self->display, "R3", strlen("R3"), 3, 17);
uint16_t value;
ADCChannel_read(rp->adc[0], &value);
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value);
Display_write(self->display, buffer, strlen(buffer), 4, 1);
ADCChannel_read(rp->adc[1], &value);
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value);
Display_write(self->display, buffer, strlen(buffer), 4, 8);
ADCChannel_read(rp->adc[2], &value);
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value);
Display_write(self->display, buffer, strlen(buffer), 4, 15);
}
LOGGER_INFO(mainLog, "Deleting RepairMenu task");
vTaskDelete(self->taskHandle);
}