diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/MAX5715.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/MAX5715.c index 2aaf980..1248273 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/MAX5715.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/MAX5715.c @@ -186,9 +186,11 @@ ErrorStatus MAX5715Channel_setValue(struct MAX5715_DAC* self, uint16_t value) { ErrorStatus returnValue = SUCCESS; - // Send data + // Send data to CODEn register + MAX5715_writeCODEn(self->parent, MAX5715_SEL_DACB, value); - // Send GO + // Load CODEn register to DAC output + MAX5715_writeLOADn(self->parent, MAX5715_SEL_DACB); return returnValue; } diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/PCBA.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/PCBA.h index 7b0fcc1..e22a506 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/PCBA.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/PCBA.h @@ -81,4 +81,20 @@ struct Pcba */ extern struct Pcba* PCBA_getInstance(void); + +/** ---------------------------------------------------------------------------- + * PCBA_setIO + * Sets the IO used for PCBA detection + * + * @param A0 Input 0 + * @param A1 Input 1 + * + * @return ErrorStatus SUCCESS if setting was successful + * ERROR otherwise + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus PCBA_setIO(T_PL_GPIO* A0, T_PL_GPIO* A1); + #endif /* PCBA_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c index 3293655..ae90ede 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/PCBA.c @@ -81,6 +81,25 @@ struct Pcba* PCBA_getInstance(void) return instance; } + +ErrorStatus PCBA_setIO(T_PL_GPIO* A0, T_PL_GPIO* A1) +{ + ErrorStatus returnValue = SUCCESS; + + if ((A0 != NULL) && (A1 != NULL)) + { + thisPCBA.A0 = *A0; + thisPCBA.A1 = *A1; + } + else + { + returnValue = ERROR; + } + + return returnValue; +} + + static ErrorStatus PCBA_construct(struct Pcba* self) { ErrorStatus returnValue = SUCCESS; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c index d774030..01138b0 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c @@ -430,20 +430,21 @@ static ErrorStatus initIO (void) /*PCBA IO initialisation -------------------------------------------------*/ // A0 - gpio.GPIO_Typedef = GPIOC; - gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD; - gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0; - gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); - PCBA_getInstance()->A0 = gpio; + T_PL_GPIO A0; + A0.GPIO_Typedef = GPIOC; + A0.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD; + A0.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0; + A0.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(A0.GPIO_Typedef, &A0.GPIO_InitStruct); // A1 - gpio.GPIO_Typedef = GPIOC; - gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD; - gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1; - gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz; - GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); - PCBA_getInstance()->A1 = gpio; + T_PL_GPIO A1; + A1.GPIO_Typedef = GPIOC; + A1.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD; + A1.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1; + A1.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz; + GPIO_Init(A1.GPIO_Typedef, &A1.GPIO_InitStruct); + PCBA_setIO(&A0, &A1); /*LED IO initialisation --------------------------------------------------*/ @@ -504,17 +505,20 @@ static ErrorStatus initIO (void) /* USART3 initialisation -------------------------------------------------*/ // Init TX line - uart3->USART_TX.GPIO_Typedef = GPIOB; - uart3->USART_TX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; - uart3->USART_TX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; - uart3->USART_TX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(uart3->USART_TX.GPIO_Typedef, &uart3->USART_TX.GPIO_InitStruct); + gpio.GPIO_Typedef = GPIOB; + gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; + gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; + gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; + uart1->USART_TX = gpio; + GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); + // Init RX line - uart3->USART_RX.GPIO_Typedef = GPIOB; - uart3->USART_RX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; - uart3->USART_RX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; - uart3->USART_RX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; + gpio.GPIO_Typedef = GPIOB; + gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; + gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; + uart1->USART_RX = gpio; + GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); GPIO_Init(uart3->USART_RX.GPIO_Typedef, &uart3->USART_RX.GPIO_InitStruct); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairPreset.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairPreset.h new file mode 100644 index 0000000..0e96763 --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairPreset.h @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------------- +/// @file repairPreset.h +/// @brief File 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) 2015 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @defgroup {group_name} {group_description} +/// Description + +/// @file repairPreset.h +/// @ingroup {group_name} + +#ifndef REPAIRPRESET_H_ +#define REPAIRPRESET_H_ + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + +#define REPAIR_PRESET_MAX_STAGES (2) + +// ----------------------------------------------------------------------------- +// Type definitions. +// ----------------------------------------------------------------------------- + +struct RepairPresetParameters +{ + int voltage; + int duration; + int softstartDuration; +}; + +struct RepairPreset +{ + size_t numberOfStages; + struct RepairPresetParameters preset[REPAIR_PRESET_MAX_STAGES]; +}; + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + +#endif /* REPAIRPRESET_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h new file mode 100644 index 0000000..a768e71 --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h @@ -0,0 +1,122 @@ +// ----------------------------------------------------------------------------- +/// @file repairProcess.h +/// @brief File 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) 2015 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @defgroup {group_name} {group_description} +/// Description + +/// @file repairProcess.h +/// @ingroup {group_name} + +#ifndef REPAIRPROCESS_H_ +#define REPAIRPROCESS_H_ + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- +#include + +#include "stm32f10x.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions. +// ----------------------------------------------------------------------------- + +typedef enum +{ + IDLE = 0, + SOFTSTART = 1, + VOLTAGE_HOLD = 2, + PAUSE = 3 +} RepairState; + + +struct RepairProcess +{ + TaskHandle_t taskHandle; + int TaskPriority; + uint16_t stackSize; + bool runTask; + SemaphoreHandle_t secondsSyncronisation; + uint32_t secondsCounter; + RepairState currentState; + bool initialized; +}; + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + +/** ---------------------------------------------------------------------------- + * repairProcess_construct + * Description of function + * + * @param self The process object + * @param taskPriority Task priority for the repair process + * @param stackSize Stacksize of the task + * + * @return ErrorStatus SUCCESS if construction was successful + * ERROR otherwise + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus repairProcess_construct(struct RepairProcess* self, int taskPriority, uint16_t stackSize); + + +/** ---------------------------------------------------------------------------- + * repairProcess_feedSecondsCounter + * Feeds the seconds counter of the repair process. + * The process is designed to be run every second, so this feed function should + * be called every second. + * + * @param self The repair process + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void repairProcess_feedSecondsCounter(struct RepairProcess* self); + + +/** ---------------------------------------------------------------------------- + * repairProcess_feedSecondsCounterFromISR + * Feeds the seconds counter of the repair process. + * This function should be called in an ISR context + * The process is designed to be run every second, so this feed function should + * be called every second. + * + * @param self The repair process + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void repairProcess_feedSecondsCounterFromISR(struct RepairProcess* self); + +#endif /* REPAIRPROCESS_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c index 2d47083..ba620e2 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c @@ -221,13 +221,15 @@ static void initTask(void* parameters) hwTestItems.cat2Relay = NULL; hwTestItems.pcba = pcba; // EEPROM TO BE DONE - HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 2, 1024); +// 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); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c new file mode 100644 index 0000000..10314c1 --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c @@ -0,0 +1,130 @@ +// ----------------------------------------------------------------------------- +/// @file repairProcess.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 repairProcess.c +/// @ingroup {group_name} + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "FreeRTOS.h" +#include "queue.h" +#include "semphr.h" +#include "task.h" + +#include "repairProcess.h" +#include "repairPreset.h" + +#include "Logger.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// File-scope variables +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + +static void repairProcess_task(void* parameters); + +// ----------------------------------------------------------------------------- +// Function definitions +// ----------------------------------------------------------------------------- + + +ErrorStatus repairProcess_construct(struct RepairProcess* self, 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); + + + if (xTaskCreate(repairProcess_task, "RepairProcess", stackSize, self, taskPriority, &self->taskHandle) != pdTRUE) + { + returnValue = ERROR; + } + + if (returnValue == SUCCESS) + { + self->runTask = true; + } + } + else + { + returnValue = ERROR; + } + + return returnValue; +} + + +void repairProcess_feedSecondsCounter(struct RepairProcess* self) +{ + xSemaphoreGive(self->secondsSyncronisation); + +} + +void repairProcess_feedSecondsCounterFromISR(struct RepairProcess* self) +{ + portBASE_TYPE higherPriorityTaskWoken = pdFALSE; + + xSemaphoreGiveFromISR(self->secondsSyncronisation, &higherPriorityTaskWoken); + + portEND_SWITCHING_ISR(higherPriorityTaskWoken); + +} + + +static void repairProcess_task(void* parameters) +{ + struct RepairProcess* self = (struct RepairProcess*)parameters; + + + while(self->runTask) + { + xSemaphoreTake(self->secondsSyncronisation, portMAX_DELAY); + int hours = (self->secondsCounter / (60 * 60)); + int minutes = (self->secondsCounter - (hours * 60 * 60)) / 60; + int seconds = (self->secondsCounter - (hours * 60 * 60) - (minutes * 60)); + LOGGER_WARNING(mainLog, "--- Repair clock %02i %02d %02d", hours, minutes, seconds); + + self->secondsCounter++; + } + + vTaskDelete(self->taskHandle); +}