Added buzzer

Added powerloss detector

Added buzzer behaviour to system.
Added powerloss behaviour to system 

Added french translation to menu texts

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@359 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-12-13 13:22:06 +00:00
parent 9a5bbf8a7a
commit a48164fe7a
24 changed files with 973 additions and 160 deletions

View File

@@ -68,7 +68,7 @@ static void MenuCore_scrollDownIndexHandler(struct MenuCore* self);
// -----------------------------------------------------------------------------
ErrorStatus MenuCore_construct(struct MenuCore* self, struct Display* display, struct KeyboardDevice* keyboardDevice, int taskPriority, uint16_t stackSize, MenuCoreFunctionCall createMenu, MenuCoreFunctionCall stateHandle)
ErrorStatus MenuCore_construct(struct MenuCore* self, struct Display* display, struct KeyboardDevice* keyboardDevice, struct Buzzer* buzzer, int taskPriority, uint16_t stackSize, MenuCoreFunctionCall createMenu, MenuCoreFunctionCall stateHandle)
{
ErrorStatus returnValue = SUCCESS;
@@ -98,6 +98,18 @@ ErrorStatus MenuCore_construct(struct MenuCore* self, struct Display* display, s
}
}
if (returnValue == SUCCESS)
{
if (buzzer->initialized)
{
self->buzzer = buzzer;
}
else
{
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
// Let Task run as soon as it has been created
@@ -225,6 +237,12 @@ static ErrorStatus MenuCore_performAction(struct MenuCore* self, char key, Keypa
struct KeyActionBinding keyAction = MenuCore_findKeyAction(self, key, keyState);
if (keyAction.action != NO_ACTION)
{
// Give audible feedback of valid key
BUZZER_KEYPAD_ACKNOWLEDGE(self->buzzer);
}
switch (keyAction.action)
{
case NO_ACTION:

View File

@@ -0,0 +1,199 @@
// -----------------------------------------------------------------------------
/// @file PowerLossDetector.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 PowerLossDetector.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "FreeRTOS.h"
#include "task.h"
#include "PowerLossDetector.h"
#include "Logger.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define PLD_MASK_FREE (0xFFFFFFFF)
#define PLD_MASK_BUSY (0xDEADC01A)
#define PLD_MASK_USED (0x00000000)
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
struct PowerLossDetector
{
bool initialized;
bool loaded;
unsigned int pageNumber;
unsigned int startAddress;
unsigned int length;
struct MemoryDevice* memoryDevice;
};
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static struct PowerLossDetector _plDetector = {.initialized = false, .loaded = false};
struct PowerLossDetector* const plDetector = &_plDetector;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus PowerLossDetector_construct(struct MemoryDevice* memoryDevice, unsigned int pageNumber, unsigned int startAddress, unsigned int length)
{
ErrorStatus returnValue = SUCCESS;
if (!plDetector->initialized)
{
if (returnValue == SUCCESS)
{
plDetector->pageNumber = pageNumber;
plDetector->startAddress = startAddress;
plDetector->length = length;
}
if (returnValue == SUCCESS)
{
if (memoryDevice != NULL)
{
if (memoryDevice->initialized)
{
plDetector->memoryDevice = memoryDevice;
plDetector->initialized = true;
LOGGER_DEBUG(mainLog, "PowerLossDetector constructed");
}
else
{
returnValue = ERROR;
}
}
else
{
returnValue = ERROR;
}
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
extern void PowerLossDetector_destruct(void)
{
plDetector->initialized = false;
}
void PowerLossDetector_setBusyFlag(void)
{
bool freeAddressFound = false;
uint32_t buffer;
unsigned int flagAddress;
unsigned int loopcounter;
// Find the first available free address
for (loopcounter = plDetector->startAddress; loopcounter < (plDetector->startAddress + plDetector->length); loopcounter += 4)
{
MemoryDevice_read(plDetector->memoryDevice, &buffer, loopcounter, 1);
if (buffer == PLD_MASK_FREE)
{
// Found free space
flagAddress = loopcounter;
freeAddressFound = true;
LOGGER_DEBUG(mainLog, "Found free address at: %X", loopcounter);
break;
}
}
// In case no free address has been found, the complete page must be cleared
// After clearing, the address to write the busy flag to is equal to the start address
if (!freeAddressFound)
{
MemoryDevice_erasePage(plDetector->memoryDevice, plDetector->pageNumber);
flagAddress = plDetector->startAddress;
}
buffer = PLD_MASK_BUSY;
MemoryDevice_write(plDetector->memoryDevice, &buffer, flagAddress, 1);
}
extern void PowerLossDetector_clearBusyFlag(void)
{
uint32_t buffer;
unsigned int loopcounter;
// Find the first available free address
for (loopcounter = plDetector->startAddress; loopcounter < (plDetector->startAddress + plDetector->length); loopcounter += 4)
{
MemoryDevice_read(plDetector->memoryDevice, &buffer, loopcounter, 1);
if (buffer == PLD_MASK_BUSY)
{
// Found the busy flag
buffer = PLD_MASK_USED;
LOGGER_DEBUG(mainLog, "Found busyFlag at address %X", loopcounter);
MemoryDevice_write(plDetector->memoryDevice, &buffer, loopcounter, 1);
break;
}
}
}
bool PowerLossDetection_isFlagSet(void)
{
bool returnValue = false;
uint32_t buffer;
unsigned int loopcounter;
// Find the first available free address
for (loopcounter = plDetector->startAddress; loopcounter < (plDetector->startAddress + plDetector->length); loopcounter += 4)
{
MemoryDevice_read(plDetector->memoryDevice, &buffer, loopcounter, 1);
if (buffer == PLD_MASK_BUSY)
{
// Found the busy flag
returnValue = true;
LOGGER_DEBUG(mainLog, "Found busyFlag at address %X", loopcounter);
break;
}
}
return returnValue;
}

View File

@@ -81,6 +81,8 @@ ErrorStatus hsb_generateStartScreen(struct Display* Display)
if (returnValue == SUCCESS)
{
Display_setCursorToPosition(mainDisplay, 1, 1);
vTaskDelay(10);
returnValue = Display_write(mainDisplay, PCBA_getInstance()->name, 1, 1);
}
else
@@ -116,29 +118,29 @@ ErrorStatus hsb_enableSafetyWithError(void)
CoverSolenoid_lock();
}
if (returnValue == SUCCESS)
{
// Check for INTERLOCK CLOSE
if (Interlock_isClosed(interlock))
{
// Enable Interrupt for interlock switch
Interlock_setEXTI(interlock, ENABLE);
}
else
{
Error_postError(INTERLOCK_COMMON_FAIL);
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
// In case of a TESLA repair, release the teslaGunSafety
if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
TeslaGunSafety_release();
}
}
// if (returnValue == SUCCESS)
// {
// // Check for INTERLOCK CLOSE
// if (Interlock_isClosed(interlock))
// {
// // Enable Interrupt for interlock switch
// Interlock_setEXTI(interlock, ENABLE);
// }
// else
// {
// Error_postError(INTERLOCK_COMMON_FAIL);
// returnValue = ERROR;
// }
// }
//
// if (returnValue == SUCCESS)
// {
// // In case of a TESLA repair, release the teslaGunSafety
// if (PCBA_getInstance()->pcba == PCBA_Tesla)
// {
// TeslaGunSafety_release();
// }
// }
if (returnValue == SUCCESS)
{
@@ -162,29 +164,29 @@ ErrorStatus hsb_enableSafetyWithWarning(void)
CoverSolenoid_lock();
}
if (returnValue == SUCCESS)
{
// Check for INTERLOCK CLOSE
if (Interlock_isClosed(interlock))
{
// Enable Interrupt for interlock switch
Interlock_setEXTI(interlock, ENABLE);
}
else
{
Warning_postWarning(WARNING_INTERLOCK_COMMON_FAIL);
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
// In case of a TESLA repair, release the teslaGunSafety
if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
TeslaGunSafety_release();
}
}
// if (returnValue == SUCCESS)
// {
// // Check for INTERLOCK CLOSE
// if (Interlock_isClosed(interlock))
// {
// // Enable Interrupt for interlock switch
// Interlock_setEXTI(interlock, ENABLE);
// }
// else
// {
// Warning_postWarning(WARNING_INTERLOCK_COMMON_FAIL);
// returnValue = ERROR;
// }
// }
//
// if (returnValue == SUCCESS)
// {
// // In case of a TESLA repair, release the teslaGunSafety
// if (PCBA_getInstance()->pcba == PCBA_Tesla)
// {
// TeslaGunSafety_release();
// }
// }
if (returnValue == SUCCESS)
{
@@ -202,29 +204,22 @@ ErrorStatus hsb_disableSafety(void)
{
ErrorStatus returnValue = SUCCESS;
int adcR1Value = HSB_SECURITY_VOLTAGE_THRESHOLD;
int adcR2Value = HSB_SECURITY_VOLTAGE_THRESHOLD;
int adcR3Value = HSB_SECURITY_VOLTAGE_THRESHOLD;
if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
TeslaGunSafety_block();
}
// Display_clearScreen(mainDisplay);
char buffer[mainDisplay->displayDevice->parameters.numberOfColumns];
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "WAITING FOR");
Display_write(mainDisplay, buffer, 3, 5);
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "POWER DOWN");
Display_write(mainDisplay, buffer, 4, 6);
// Power-down the DAC outputs
DAConverter_setOutputVoltage(dacRow1, 0);
DAConverter_setOutputVoltage(dacRow2, 0);
DAConverter_setOutputVoltage(dacRow3, 0);
char buffer[mainDisplay->displayDevice->parameters.numberOfColumns];
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "WAITING FOR");
Display_write(mainDisplay, buffer, 3, 5);
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "POWER DOWN");
Display_write(mainDisplay, buffer, 4, 6);
while (HighVoltageDetection_isVoltagePresent())
{

View File

@@ -44,8 +44,10 @@
#include "Error.h"
#include "hsb-mrts.h"
#include "hwValidationMenu.h"
#include "PowerLossDetector.h"
#include "repairMenu.h"
#include "repairMenus.h"
#include "repairProcesses.h"
#include "Warning.h"
#include "CathodeMCP.h"
@@ -150,7 +152,7 @@ static void printSystemInfoTask(void* parameters)
{
LOGGER_INFO(mainLog, "---------------------------------------");
systeminfoCommandHandler();
vTaskDelay(20000);
vTaskDelay(10000);
}
}
@@ -173,9 +175,14 @@ static ErrorStatus systeminfoCommandHandler(void)
vTaskDelay(10);
OS_logTaskInfo(mainMenu->menuCore->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(rp->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(mainDisplay->taskHandle);
vTaskDelay(10);
OS_logTaskInfo(errorTaskHandle);
vTaskDelay(10);
OS_logTaskInfo(mainBuzzer->taskHandle);
@@ -189,13 +196,13 @@ static void initTask(void* parameters)
if (returnValue == SUCCESS)
{
// Create the error handler
Error_construct();
returnValue = Error_construct();
}
if (returnValue == SUCCESS)
{
// Create the warning handler
Warning_construct();
returnValue = Warning_construct();
}
if (returnValue == SUCCESS)
@@ -204,30 +211,36 @@ static void initTask(void* parameters)
// All IO is initialized here
// Also, all periphery and platform-specifics are initialized here
// IRQs are defined here
initPlatform();
returnValue = initPlatform();
}
if (returnValue == SUCCESS)
{
// Construct the displays
Displays_construct();
returnValue = Displays_construct();
}
if (returnValue == SUCCESS)
{
// Construct the powerloss detector
returnValue = PowerLossDetector_construct(&iFlash->memoryDevice, APP_FLASH_POWERLOSS_PAGE, APP_FLASH_STORAGE_POWERLOSS, APP_FLASH_POWERLOSS_PAGESIZE);
}
if (returnValue == SUCCESS)
{
// Construct the AD Converters
ADConverters_construct();
returnValue = ADConverters_construct();
}
if (returnValue == SUCCESS)
{
// Construct the DA Converters
DAConverters_construct();
returnValue = DAConverters_construct();
}
if (returnValue == SUCCESS)
{
hsb_generateStartScreen(mainDisplay);
returnValue = hsb_generateStartScreen(mainDisplay);
// Let start screen stay for 5 seconds
vTaskDelay(INIT_START_SCREEN_DELAY);
}
@@ -235,13 +248,13 @@ static void initTask(void* parameters)
if (returnValue == SUCCESS)
{
// Construct/Load the device parameters
DeviceParameters_construct(&deviceParameters, &iFlash->memoryDevice);
returnValue = DeviceParameters_construct(&deviceParameters, &iFlash->memoryDevice);
}
if (returnValue == SUCCESS)
{
// Construct the repair presets
RepairPresets_construct(&cs, &iFlash->memoryDevice);
returnValue = RepairPresets_construct(&cs, &iFlash->memoryDevice);
}
#ifdef ENABLE_HW_VALIDATION
@@ -278,7 +291,16 @@ static void initTask(void* parameters)
if (returnValue == SUCCESS)
{
// Construct the repair menu
repairMenus_construct();
returnValue = repairMenus_construct();
}
if (PowerLossDetection_isFlagSet())
{
LOGGER_ERROR(mainLog, "Powerloss detection triggered");
Error_postError(ERROR_POWER_LOSS);
returnValue = ERROR;
// Flag may be restored now
PowerLossDetector_clearBusyFlag();
}
// Delete this init task

View File

@@ -31,6 +31,7 @@
#include "DeviceParameters.h"
#include "PIDParameters.h"
#include "PowerLossDetector.h"
#include "repairMenu.h"
#include "repairMenus.h"
#include "RepairPreset.h"
@@ -254,6 +255,13 @@ void repairMenu_interlockFailed(struct RepairMenu* self, T_INTERLOCK_ID interloc
}
void repairMenu_powerLossDetected(struct RepairMenu* self)
{
MenuCore_changeState(self->menuCore, RM_ERROR_STATE);
snprintf(self->menuCore->errorMessage, sizeof(self->menuCore->errorMessage) / sizeof(self->menuCore->errorMessage[0]), MenuText_ERROR_POWER_LOSS[languageIndex]);
}
void repairMenu_processFailed(struct RepairMenu* self)
{
MenuCore_changeState(self->menuCore, RM_ERROR_STATE);
@@ -1012,6 +1020,8 @@ static void repairMenu_startRepairProcess(struct MenuCore* self)
{
// repair process is running
MenuCore_changeState(self, RM_REPAIR_RUNNING);
// Set Flag in FLASH
PowerLossDetector_setBusyFlag();
}
else
{
@@ -1060,9 +1070,17 @@ static void repairMenu_gotoLastState(struct MenuCore* self)
void repairMenu_menuStateHandle(struct MenuCore* self)
{
// Stop the buzzer from recovered error or warning
if ((self->lastMenuState == RM_ERROR_STATE) || (self->lastMenuState == RM_WARNING_STATE))
{
if ((self->menuState != RM_ERROR_STATE) && (self->menuState != RM_WARNING_STATE))
Buzzer_stop(self->buzzer);
}
// Catch ERROR state
if (self->menuState == RM_ERROR_STATE)
{
self->lastMenuState = self->menuState;
// Show ERROR message
repairMenu_printError(self);
// Handle error
@@ -1073,6 +1091,7 @@ void repairMenu_menuStateHandle(struct MenuCore* self)
}
else if (self->menuState == RM_WARNING_STATE)
{
self->lastMenuState = self->menuState;
repairMenu_printWarning(self);
}
@@ -1119,6 +1138,7 @@ void repairMenu_menuStateHandle(struct MenuCore* self)
else if (self->menuState == RM_FINISH_CONTROL)
{
repairMenu_stopRepairProcess(self);
PowerLossDetector_clearBusyFlag();
MenuCore_changeState(self, RM_FINISH);
}
else if (self->menuState == RM_FINISH)

View File

@@ -36,6 +36,7 @@
#include "Warning.h"
#include "platform.h"
#include "Buzzer.h"
#include "Logger.h"
#include "Observable.h"
#include "rtc.h"
@@ -82,13 +83,13 @@ ErrorStatus repairMenus_construct(void)
if (returnValue == SUCCESS)
{
// Create the Menu core
returnValue = MenuCore_construct(menuCore, mainDisplay, &storm700->keyboardDevice, HSB_MAINMENU_TASK_PRIORITY, HSB_MAINMENU_TASK_STACKSIZE, repairMenu_createMenuEntries, repairMenu_menuStateHandle);
returnValue = MenuCore_construct(menuCore, mainDisplay, &storm700->keyboardDevice, mainBuzzer, HSB_MAINMENU_TASK_PRIORITY, HSB_MAINMENU_TASK_STACKSIZE, repairMenu_createMenuEntries, repairMenu_menuStateHandle);
}
if (returnValue == SUCCESS)
{
// Create first repair menu
returnValue = repairMenu_construct(mainMenu, menuCore,&iFlash->memoryDevice, repairMenus_freeMainMenuRepairScreenUpdateSemaphore);
returnValue = repairMenu_construct(mainMenu, menuCore, &iFlash->memoryDevice, repairMenus_freeMainMenuRepairScreenUpdateSemaphore);
}
if (returnValue == SUCCESS)
@@ -124,9 +125,16 @@ static ErrorStatus repairMenus_errorReceive(const void* const data)
switch (errorCode)
{
case ERROR_POWER_LOSS:
{
repairMenu_powerLossDetected(mainMenu);
BUZZER_ERROR(mainBuzzer);
break;
}
case INTERLOCK_COMMON_FAIL:
{
repairMenu_interlockFailed(mainMenu, COMMON_INTERLOCK);
BUZZER_ERROR(mainBuzzer);
break;
}
case POWERENABLE_FAIL:
@@ -136,6 +144,7 @@ static ErrorStatus repairMenus_errorReceive(const void* const data)
case REPAIR_FAIL:
{
repairMenu_processFailed(mainMenu);
BUZZER_ERROR(mainBuzzer);
break;
}
case ERROR_CRC_PIN:
@@ -143,6 +152,7 @@ static ErrorStatus repairMenus_errorReceive(const void* const data)
case ERROR_CRC_PRESETS:
{
repairMenu_printCRCFailure(mainMenu, errorCode);
BUZZER_ERROR(mainBuzzer);
break;
}
default:
@@ -163,6 +173,7 @@ static ErrorStatus repairMenus_warningReceive(const void* const data)
case WARNING_INTERLOCK_COMMON_FAIL:
{
repairMenu_interlockWarning(mainMenu, COMMON_INTERLOCK);
BUZZER_WARNING(mainBuzzer);
break;
}

View File

@@ -266,7 +266,7 @@ static void repairProcess_task(void* parameters)
{
// The current ADC value is outside the error boundaries
self->row[loopCounter].errorData.outOfLimitsCounter += 1;
LOGGER_WARNING(mainLog, "Row %d outside boundaries", loopCounter);
// LOGGER_WARNING(mainLog, "Row %d outside boundaries", loopCounter);
}
else
{
@@ -282,7 +282,7 @@ static void repairProcess_task(void* parameters)
// ROW is in error state
self->row[loopCounter].lastDACValue = 0;
DAConverter_setOutputVoltage(self->row[loopCounter].dacChannel, self->row[loopCounter].lastDACValue);
LOGGER_ERROR(mainLog, "Row %d --- Row in ERROR state", loopCounter);
// LOGGER_ERROR(mainLog, "Row %d --- Row in ERROR state", loopCounter);
}
}
}

View File

@@ -50,6 +50,7 @@
// -----------------------------------------------------------------------------
static struct RepairProcess mainRepairProcess;
struct RepairProcess* const rp = &mainRepairProcess;
// -----------------------------------------------------------------------------
// Function declarations