Major updates:

- added DAConverter(s)
- added ADConverter(s)
- Fixed some display issues
- Made repair process and signalProfileGenerator calculate with voltages (signed) instead of DAC/ADC values
- Fixed several bugs in task handlings
- Put display data mirror into dedicated file displaycontent

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@261 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-24 13:56:55 +00:00
parent e3ca058c96
commit bb08cae83a
35 changed files with 1689 additions and 288 deletions

View File

@@ -23,6 +23,8 @@ CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb $(PLATFORM) $(RELE
ARFLAGS = rs ARFLAGS = rs
OBJECTS = \ OBJECTS = \
ADCDevice.o \
DACDevice.o \
DisplayDevice.o \ DisplayDevice.o \
hsb-mrts.o \ hsb-mrts.o \
Interlock.o \ Interlock.o \

View File

@@ -31,22 +31,71 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <stdbool.h>
#include "stm32f10x.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
struct ADCDevice;
typedef uint32_t (*ADCReadFunction)(const struct ADCDevice* self);
// ----------------------------------------------------------------------------- struct ADCDevice
// Type definitions. {
// ----------------------------------------------------------------------------- ADCReadFunction _read;
bool initialized;
unsigned int resolutionInBits;
};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function declarations // Function declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* ADCDevice_construct
* Constructor for ADC device
*
* @param self ADC object
* @param read Pointer to read function
*
* @return ErrorStatus SUCCESS if construction was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus ADCDevice_construct(struct ADCDevice* self, ADCReadFunction read, unsigned int resolutionInBits);
/** ----------------------------------------------------------------------------
* ADCDevice_destruct
* Destructor for ADC device
*
* @param self ADC object
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void ADCDevice_destruct(struct ADCDevice* self);
/** ----------------------------------------------------------------------------
* ADCDevice_read
* Reads a value from the ADC device input
*
* @param self ADC object
* @param voltage value in volt (signed) to write to output
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern uint32_t ADCDevice_read(const struct ADCDevice* self);
#endif /* INC_ADCDEVICE_H_ */ #endif /* INC_ADCDEVICE_H_ */

View File

@@ -31,6 +31,10 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <stdbool.h>
#include "stm32f10x.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constant and macro definitions // Constant and macro definitions
@@ -42,11 +46,64 @@
// Type definitions. // Type definitions.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
struct DACDevice;
typedef ErrorStatus (*DACWriteFunction)(const struct DACDevice* self, uint32_t voltage);
struct DACDevice
{
DACWriteFunction _write;
bool initialized;
unsigned int resolutionInBits;
};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function declarations // Function declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* DACDevice_construct
* Constructor for DAC device
*
* @param self DAC object
* @param write Pointer to write function
*
* @return ErrorStatus SUCCESS if construction was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus DACDevice_construct(struct DACDevice* self, DACWriteFunction write, unsigned int resolutionInBits);
/** ----------------------------------------------------------------------------
* DACDevice_destruct
* Destructor for DAC device
*
* @param self DAC object
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void DACDevice_destruct(struct DACDevice* self);
/** ----------------------------------------------------------------------------
* DACDevice_construct
* Writes a value to the DAC device output
*
* @param self DAC object
* @param voltage value in volt (signed) to write to output
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus DACDevice_write(const struct DACDevice* self, uint32_t voltage);
#endif /* INC_DACDEVICE_H_ */ #endif /* INC_DACDEVICE_H_ */

View File

@@ -31,6 +31,9 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <stdbool.h>
#include "DACDevice.h"
#include "IODevice.h" #include "IODevice.h"
#include "spi.h" #include "spi.h"
@@ -38,6 +41,7 @@
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define MAX5715_NUMBER_OF_DACS (4) #define MAX5715_NUMBER_OF_DACS (4)
#define MAX5715_RESOLUTION_IN_BITS (12)
#define MAX5715_SPI_MAX_CLK_HZ (50000000) #define MAX5715_SPI_MAX_CLK_HZ (50000000)
// SPI settings // SPI settings
@@ -120,6 +124,7 @@ struct MAX5715;
struct MAX5715_DAC struct MAX5715_DAC
{ {
struct DACDevice dacDevice;
struct MAX5715* parent; struct MAX5715* parent;
uint8_t id; uint8_t id;
uint16_t value; uint16_t value;

View File

@@ -0,0 +1,112 @@
// -----------------------------------------------------------------------------
/// @file ADCDevice.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 ADCDevice.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdio.h>
#include "ADCDevice.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus ADCDevice_construct(struct ADCDevice* self, ADCReadFunction read, unsigned int resolutionInBits)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
if (read != NULL)
{
self->_read = read;
self->resolutionInBits = resolutionInBits;
self->initialized = true;
}
else
{
returnValue = ERROR;
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void ADCDevice_destruct(struct ADCDevice* self)
{
if (self->initialized)
{
self->initialized = false;
self->_read = NULL;
}
}
uint32_t ADCDevice_read(const struct ADCDevice* self)
{
uint32_t returnValue = 0;
if (self->initialized)
{
if (self->_read != NULL)
{
returnValue = self->_read(self);
}
else
{
returnValue = 0;
}
}
else
{
returnValue = 0;
}
return returnValue;
}

View File

@@ -0,0 +1,113 @@
// -----------------------------------------------------------------------------
/// @file DACDevice.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 DACDevice.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdio.h>
#include "DACDevice.h"
#include "Logger.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus DACDevice_construct(struct DACDevice* self, DACWriteFunction write, unsigned int resolutionInBits)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
if (write != NULL)
{
self->_write = write;
self->resolutionInBits = resolutionInBits;
self->initialized = true;
}
else
{
returnValue = ERROR;
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void DACDevice_destruct(struct DACDevice* self)
{
if (self->initialized)
{
self->initialized = false;
self->_write = NULL;
}
}
ErrorStatus DACDevice_write(const struct DACDevice* self, uint32_t voltage)
{
ErrorStatus returnValue = SUCCESS;
if (self->initialized)
{
if (self->_write != NULL)
{
returnValue = self->_write(self, voltage);
}
else
{
returnValue = ERROR;
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}

View File

@@ -52,7 +52,7 @@
// Function declarations // Function declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static ErrorStatus channelWrite(const struct DACDevice* self, uint32_t voltage);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function definitions // Function definitions
@@ -163,6 +163,11 @@ ErrorStatus MAX5715Channel_construct(struct MAX5715_DAC* self, struct MAX5715* p
self->parent = parent; self->parent = parent;
self->value = 0; self->value = 0;
self->initialized = true; self->initialized = true;
if (returnValue == SUCCESS)
{
returnValue = DACDevice_construct(&self->dacDevice, channelWrite, MAX5715_RESOLUTION_IN_BITS);
}
} }
else else
{ {
@@ -208,3 +213,11 @@ ErrorStatus MAX5715Channel_setValue(const struct MAX5715_DAC* self, uint16_t val
return returnValue; return returnValue;
} }
static ErrorStatus channelWrite(const struct DACDevice* self, uint32_t voltage)
{
// MASK the uint32_t DAC value (voltage) with the resolution of the MAX5715 DAC
return MAX5715Channel_setValue((struct MAX5715_DAC*)self, (((1 << MAX5715_RESOLUTION_IN_BITS) - 1) & voltage));
}

View File

@@ -34,7 +34,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "platform.h" #include "platform.h"
#include "IODevice.h" #include "ADCDevice.h"
#include "stm32f10x.h" #include "stm32f10x.h"
#include "stm32f10x_adc.h" #include "stm32f10x_adc.h"
@@ -43,6 +43,7 @@
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define ADC_RESOLUTION_IN_BITS (12)
#define ADC_AVERAGE_DEPTH (10) #define ADC_AVERAGE_DEPTH (10)
#define ADC_NUMBER_OF_CHANNELS (18) // 16 IOs + Temp + Vcc #define ADC_NUMBER_OF_CHANNELS (18) // 16 IOs + Temp + Vcc
@@ -61,7 +62,7 @@ struct AdcChannelParameters
struct AdcChannel struct AdcChannel
{ {
struct IODevice device; struct ADCDevice adcDevice;
struct Adc* parent; struct Adc* parent;
uint8_t channel; uint8_t channel;
uint8_t Rank; uint8_t Rank;

View File

@@ -26,7 +26,11 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include "stm32f10x.h" #include "stm32f10x.h"
#include "ADCDevice.h"
#include "internalADC.h" #include "internalADC.h"
#include "Logger.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constant and macro definitions // Constant and macro definitions
@@ -49,8 +53,8 @@
// Function declarations // Function declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// NO WRITE - ADCs cannot write
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength); static uint32_t channelRead(const struct ADCDevice* self);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function definitions // Function definitions
@@ -160,8 +164,10 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
{ {
if (!self->initialized) if (!self->initialized)
{ {
IODevice_construct(&self->device, read, NULL); returnValue = ADCDevice_construct(&self->adcDevice, channelRead, ADC_RESOLUTION_IN_BITS);
if (returnValue == SUCCESS)
{
if ((parameters->Rank) > 0 && (parameters->Rank <= 16)) if ((parameters->Rank) > 0 && (parameters->Rank <= 16))
{ {
self->Rank = parameters->Rank; self->Rank = parameters->Rank;
@@ -178,7 +184,7 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
{ {
returnValue = ERROR; returnValue = ERROR;
} }
}
if (returnValue == SUCCESS) if (returnValue == SUCCESS)
{ {
@@ -213,6 +219,8 @@ ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value)
{ {
ErrorStatus returnValue = SUCCESS; ErrorStatus returnValue = SUCCESS;
if (self->initialized)
{
// Reading ADC value is automatically combined with an floating averaging // Reading ADC value is automatically combined with an floating averaging
uint32_t average = 0; uint32_t average = 0;
int loopCounter; int loopCounter;
@@ -221,27 +229,24 @@ ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value)
average = average + self->parent->channelValue[loopCounter]; average = average + self->parent->channelValue[loopCounter];
} }
*value = average / ADC_AVERAGE_DEPTH; *value = average / ADC_AVERAGE_DEPTH;
}
else
{
returnValue = ERROR;
}
return returnValue; return returnValue;
} }
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength) static uint32_t channelRead(const struct ADCDevice* self)
{ {
ErrorStatus returnValue = SUCCESS; uint32_t returnValue = 0;
(void)length; uint16_t value;
if (ADCChannel_read((struct AdcChannel*)self, &value) == SUCCESS)
uint16_t adcValue = 0; {
returnValue = ADCChannel_read((struct AdcChannel*)self, &adcValue); returnValue = (((1 << ADC_RESOLUTION_IN_BITS) - 1) & value);
}
buffer[0] = adcValue >> 8;
buffer[1] = adcValue;
*actualLength = 2;
return returnValue; return returnValue;
} }

View File

@@ -37,6 +37,7 @@
#include "Logger.h" #include "Logger.h"
#include "platform.h" #include "platform.h"
#include "CathodeMCP.h"
#include "gpio.h" #include "gpio.h"
#include "Interlock.h" #include "Interlock.h"
#include "internalADC.h" #include "internalADC.h"
@@ -792,6 +793,7 @@ static ErrorStatus initPlatformDevices (void)
/* NewHavenDispplay 04 20 */ /* NewHavenDispplay 04 20 */
/* --------------------------------------------------------------------*/ /* --------------------------------------------------------------------*/
returnValue = NHD0420_construct(nhd0420, &spiDisplay->device); returnValue = NHD0420_construct(nhd0420, &spiDisplay->device);
// returnValue = NHD0420_construct(nhd0420, &uart1->device);
} }
if (returnValue == SUCCESS) if (returnValue == SUCCESS)

View File

@@ -12,8 +12,13 @@ system_stm32f10x.o \
sysmem.o \ sysmem.o \
startup_stm32f10x_cl.o \ startup_stm32f10x_cl.o \
\ \
ADConverter.o \
ADConverters.o \
DAConverter.o \
DAConverters.o \
Display.o \ Display.o \
Displays.o \ Displays.o \
DisplayContent.o \
Error.o \ Error.o \
FreeRTOSFixes.o \ FreeRTOSFixes.o \
hwValidationMenu.o \ hwValidationMenu.o \

View File

@@ -31,7 +31,11 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <stdbool.h>
#include "stm32f10x.h"
#include "ADCDevice.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -42,11 +46,57 @@
// Type definitions. // Type definitions.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
struct ADConverter
{
bool initialized;
int minVoltage;
int maxVoltage;
struct ADCDevice* adcDevice;
};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function declarations // Function declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* ADConverter_construct
* Description of function
*
* @param self
* @param
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus ADConverter_construct(struct ADConverter* self, int minVoltage, int maxVoltage, struct ADCDevice* adcDevice);
/** ----------------------------------------------------------------------------
* ADConverter_destruct
* Description of function
*
* @param self
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void ADConverter_destruct(struct ADConverter* self);
/** ----------------------------------------------------------------------------
* ADConverter_setOutputVoltage
* Description of function
*
* @param self
*
* @return int
*
* @todo
* -----------------------------------------------------------------------------
*/
extern int ADConverter_getInputVoltage(const struct ADConverter* self);
#endif /* ADCONVERTER_H_ */ #endif /* ADCONVERTER_H_ */

View File

@@ -0,0 +1,80 @@
// -----------------------------------------------------------------------------
/// @file ADConverters.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 ADConverters.h
/// @ingroup {group_name}
#ifndef ADCONVERTERS_H_
#define ADCONVERTERS_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "stm32f10x.h"
#include "ADConverter.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
extern struct ADConverter* adcRow1;
extern struct ADConverter* adcRow2;
extern struct ADConverter* adcRow3;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* ADConverters_construct
* Constructor for ADConverters
*
* @return ErrorStatus SUCCESS if constructor was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus ADConverters_construct(void);
/** ----------------------------------------------------------------------------
* ADConverters_destruct
* Destructor for ADConverters
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void ADConverters_destruct(void);
#endif /* ADCONVERTERS_H_ */

View File

@@ -31,7 +31,11 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <stdbool.h>
#include "stm32f10x.h"
#include "DACDevice.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -42,11 +46,60 @@
// Type definitions. // Type definitions.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
struct DAConverter
{
bool initialized;
int minVoltage;
int maxVoltage;
struct DACDevice* dacDevice;
};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function declarations // Function declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* DAConverter_construct
* Description of function
*
* @param self
* @param
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus DAConverter_construct(struct DAConverter* self, int minVoltage, int maxVoltage, struct DACDevice* dacDevice);
/** ----------------------------------------------------------------------------
* DAConverter_destruct
* Description of function
*
* @param self
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void DAConverter_destruct(struct DAConverter* self);
/** ----------------------------------------------------------------------------
* DAConverter_setOutputVoltage
* Description of function
*
* @param self
* @param voltage
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus DAConverter_setOutputVoltage(const struct DAConverter* self, int voltage);
#endif /* DACONVERTER_H_ */ #endif /* DACONVERTER_H_ */

View File

@@ -0,0 +1,83 @@
// -----------------------------------------------------------------------------
/// @file DAConverters.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 DAConverters.h
/// @ingroup {group_name}
#ifndef DACONVERTERS_H_
#define DACONVERTERS_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "stm32f10x.h"
#include "DAConverter.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
extern struct DAConverter* dacRow1;
extern struct DAConverter* dacRow2;
extern struct DAConverter* dacRow3;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* DAConverters_construct
* Constructor for DAConverters
*
* @return ErrorStatus SUCCESS if constructor was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus DAConverters_construct(void);
/** ----------------------------------------------------------------------------
* DAConverters_destruct
* Destructor for DAConverters
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void DAConverters_destruct(void);
#endif /* DACONVERTERS_H_ */

View File

@@ -39,24 +39,20 @@
#include "stm32f10x.h" #include "stm32f10x.h"
#include "DisplayContent.h"
#include "DisplayDevice.h" #include "DisplayDevice.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define DISPLAY_MAX_ROWS (6)
#define DISPLAY_MAX_COLUMNS (25)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Type definitions. // Type definitions.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
struct DisplayCharacter
{
char character;
bool isUpdated;
};
struct Display struct Display
{ {
@@ -65,9 +61,8 @@ struct Display
int TaskPriority; int TaskPriority;
uint16_t stackSize; uint16_t stackSize;
bool runTask; bool runTask;
SemaphoreHandle_t displayShadowAccessSemaphore;
SemaphoreHandle_t displayWriteRequest; SemaphoreHandle_t displayWriteRequest;
struct DisplayCharacter displayShadow[DISPLAY_MAX_ROWS][DISPLAY_MAX_COLUMNS]; struct DisplayContent displayContent;
int maxCharactersPerTransmit; int maxCharactersPerTransmit;
int refreshFeedCounter; int refreshFeedCounter;
int refreshFeedFrequency_ms; int refreshFeedFrequency_ms;
@@ -233,5 +228,6 @@ extern ErrorStatus Display_write(struct Display* self, const char* buffer, size_
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
extern void Display_feedRefreshCounter(struct Display* self); extern void Display_feedRefreshCounter(struct Display* self);
extern void Display_feedRefreshCounterFromISR(struct Display* self);
#endif /* DISPLAY_H_ */ #endif /* DISPLAY_H_ */

View File

@@ -0,0 +1,178 @@
// -----------------------------------------------------------------------------
/// @file DisplayContent.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 DisplayContent.h
/// @ingroup {group_name}
#ifndef DISPLAYCONTENT_H_
#define DISPLAYCONTENT_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "FreeRTOS.h"
#include "semphr.h"
#include "stm32f10x.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define DISPLAY_MAX_ROWS (6)
#define DISPLAY_MAX_COLUMNS (25)
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct DisplayCharacter
{
char character;
bool isUpdated;
};
struct DisplayContent
{
bool initialized;
SemaphoreHandle_t contentAccess;
size_t numberOfRows;
size_t numberOfColumns;
struct DisplayCharacter DisplayContent[DISPLAY_MAX_ROWS][DISPLAY_MAX_COLUMNS];
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* DisplayContent_construct
* Description of function
*
* @param self
* @param numberOfRows
* @param numberOfColumns
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus DisplayContent_construct(struct DisplayContent* self, size_t numberOfRows, size_t numberOfColumns);
/** ----------------------------------------------------------------------------
* DisplayContent_destruct
* Description of function
*
* @param self
* @param
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void DisplayContent_destruct(struct DisplayContent* self);
/** ----------------------------------------------------------------------------
* DisplayContent_updateCharacter
* Description of function
*
* @param self
* @param row
* @param column
* @param character
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void DisplayContent_updateCharacter(struct DisplayContent* self, unsigned int row, unsigned int column, char character);
/** ----------------------------------------------------------------------------
* DisplayContent_isCharacterUpdated
* Description of function
*
* @param self
* @param row
* @param column
*
* @return bool
*
* @todo
* -----------------------------------------------------------------------------
*/
extern bool DisplayContent_isCharacterUpdated(struct DisplayContent* self, unsigned int row, unsigned int column);
/** ----------------------------------------------------------------------------
* DisplayContent_getCharacter
* Description of function
*
* @param self
* @param row
* @param column
*
* @return char
*
* @todo
* -----------------------------------------------------------------------------
*/
extern char DisplayContent_getCharacter(struct DisplayContent* self, unsigned int row, unsigned int column);
/** ----------------------------------------------------------------------------
* DisplayContent_refresh
* Description of function
*
* @param self
* @param
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void DisplayContent_refresh(struct DisplayContent* self);
/** ----------------------------------------------------------------------------
* DisplayContent_clear
* Description of function
*
* @param self
*
* @return return_type
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void DisplayContent_clear(struct DisplayContent* self);
#endif /* DISPLAYCONTENT_H_ */

View File

@@ -44,7 +44,7 @@
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 5 ) #define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 256 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 256 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 0x8000 ) ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 0xA000 ) )
#define configMAX_TASK_NAME_LEN ( 16 ) #define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1 #define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0 #define configUSE_16_BIT_TICKS 0
@@ -69,7 +69,6 @@ to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1 #define INCLUDE_vTaskDelay 1

View File

@@ -39,7 +39,7 @@
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define HSB_MAINMENU_TASK_PRIORITY (5) #define HSB_MAINMENU_TASK_PRIORITY (2)
#define HSB_MAINMENU_TASK_STACKSIZE (1024) #define HSB_MAINMENU_TASK_STACKSIZE (1024)
#define HSB_MAINDISP_TASK_PRIORITY (2) #define HSB_MAINDISP_TASK_PRIORITY (2)
@@ -47,8 +47,22 @@
#define HSB_MAINREPR_TASK_PRIORITY (2) #define HSB_MAINREPR_TASK_PRIORITY (2)
#define HSB_MAINREPR_TASK_STACKSIZE (1024) #define HSB_MAINREPR_TASK_STACKSIZE (1024)
#define HSB_MAINREPR_OOL_DURATION (10) #define HSB_MAINREPR_OOL_DURATION (20)
#define HSB_MAINREPR_OOL_VALUE (100) #define HSB_MAINREPR_OOL_VALUE (200)
#define HSB_ADC_ANODE_MIN_VOLTAGE (0)
#define HSB_ADC_ANODE_MAX_VOLTAGE (10042)
#define HSB_ADC_CMCP_MIN_VOLTAGE (0)
#define HSB_ADC_CMCP_MAX_VOLTAGE (-2018)
#define HSB_ADC_TESLA_MIN_VOLTAGE (0)
#define HSB_ADC_TESLA_MAX_VOLTAGE (6070)
#define HSB_DAC_ANODE_MIN_VOLTAGE (0)
#define HSB_DAC_ANODE_MAX_VOLTAGE (10500)
#define HSB_DAC_CMCP_MIN_VOLTAGE (0)
#define HSB_DAC_CMCP_MAX_VOLTAGE (-2200)
#define HSB_DAC_TESLA_MIN_VOLTAGE (0)
#define HSB_DAC_TESLA_MAX_VOLTAGE (6200)
// Exports of objects on application level // Exports of objects on application level

View File

@@ -38,6 +38,8 @@
#include "stm32f10x.h" #include "stm32f10x.h"
#include "ADConverter.h"
#include "DAConverter.h"
#include "repairPreset.h" #include "repairPreset.h"
#include "repairProcessRow.h" #include "repairProcessRow.h"
#include "SignalProfileGenerator.h" #include "SignalProfileGenerator.h"
@@ -60,12 +62,12 @@
struct RepairProcessParameters struct RepairProcessParameters
{ {
const struct AdcChannel* adcRow1; const struct ADConverter* adcR1;
const struct AdcChannel* adcRow2; const struct ADConverter* adcR2;
const struct AdcChannel* adcRow3; const struct ADConverter* adcR3;
const struct MAX5715_DAC* dacRow1; const struct DAConverter* dacR1;
const struct MAX5715_DAC* dacRow2; const struct DAConverter* dacR2;
const struct MAX5715_DAC* dacRow3; const struct DAConverter* dacR3;
}; };

View File

@@ -56,10 +56,10 @@ struct RepairProcessRowErrorData
struct RepairProcessRow struct RepairProcessRow
{ {
bool initialized; bool initialized;
const struct AdcChannel* adcChannel; const struct ADConverter* adcChannel;
uint16_t lastADCValue; int lastADCValue;
const struct MAX5715_DAC* dacChannel; const struct DAConverter* dacChannel;
uint16_t lastDACValue; int lastDACValue;
int pidError; int pidError;
struct Pid pid; struct Pid pid;
struct RepairProcessRowErrorData errorData; struct RepairProcessRowErrorData errorData;
@@ -88,7 +88,7 @@ struct RepairProcessRow
* @todo * @todo
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
extern ErrorStatus repairProcessRow_construct(struct RepairProcessRow* self, const struct AdcChannel* adcChannel, const struct MAX5715_DAC* dacChannel, int outOfLimitsDuration, int outOfLimitsValue); extern ErrorStatus repairProcessRow_construct(struct RepairProcessRow* self, const struct ADConverter* adcChannel, const struct DAConverter* dacChannel, int outOfLimitsDuration, int outOfLimitsValue);
/** ---------------------------------------------------------------------------- /** ----------------------------------------------------------------------------

View File

@@ -0,0 +1,123 @@
// -----------------------------------------------------------------------------
/// @file ADConverter.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 ADConverter.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "ADConverter.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static int calculateVoltage(const struct ADConverter* self, uint32_t adcValue);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus ADConverter_construct(struct ADConverter* self, int minVoltage, int maxVoltage, struct ADCDevice* adcDevice)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
self->minVoltage = minVoltage;
self->maxVoltage = maxVoltage;
self->adcDevice = adcDevice;
self->initialized = true;
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void ADConverter_destruct(struct ADConverter* self)
{
self->initialized = false;
}
int ADConverter_getInputVoltage(const struct ADConverter* self)
{
int returnValue = 0;
if (self->initialized)
{
uint32_t adcValue;
adcValue = ADCDevice_read(self->adcDevice);
returnValue = calculateVoltage(self, adcValue);
}
return returnValue;
}
static int calculateVoltage(const struct ADConverter* self, uint32_t adcValue)
{
int returnValue = 0;
if (self->initialized)
{
uint32_t maxAdcValue = ((1 << self->adcDevice->resolutionInBits) - 1);
returnValue = adcValue * (self->maxVoltage - self->minVoltage);
returnValue = returnValue / maxAdcValue;
returnValue = returnValue + self->minVoltage;
if (returnValue < self->minVoltage)
{
returnValue = self->minVoltage;
}
else if (returnValue > self->maxVoltage)
{
returnValue = self->maxVoltage;
}
}
else
{
returnValue = 0;
}
return returnValue;
}

View File

@@ -0,0 +1,119 @@
// -----------------------------------------------------------------------------
/// @file ADConverters.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 ADConverters.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "ADConverters.h"
#include "hsb-mrts.h"
#include "internalADC.h"
#include "PCBA.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static struct ADConverter _adcRow1;
static struct ADConverter _adcRow2;
static struct ADConverter _adcRow3;
struct ADConverter* adcRow1 = &_adcRow1;
struct ADConverter* adcRow2 = &_adcRow2;
struct ADConverter* adcRow3 = &_adcRow3;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus ADConverters_construct(void)
{
ErrorStatus returnValue = SUCCESS;
int minVoltage;
int maxVoltage;
if (returnValue == SUCCESS)
{
if (PCBA_getInstance()->pcba == PCBA_Anode)
{
minVoltage = HSB_ADC_ANODE_MIN_VOLTAGE;
maxVoltage = HSB_ADC_ANODE_MAX_VOLTAGE;
}
else if (PCBA_getInstance()->pcba == PCBA_CathodeMCP)
{
minVoltage = HSB_ADC_CMCP_MIN_VOLTAGE;
maxVoltage = HSB_ADC_CMCP_MAX_VOLTAGE;
}
else if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
minVoltage = HSB_ADC_TESLA_MIN_VOLTAGE;
maxVoltage = HSB_ADC_TESLA_MAX_VOLTAGE;
}
else
{
minVoltage = 0;
maxVoltage = 0;
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
returnValue = ADConverter_construct(adcRow1, minVoltage, maxVoltage, &adc1->channel[0].adcDevice);
}
if (returnValue == SUCCESS)
{
returnValue = ADConverter_construct(adcRow2, minVoltage, maxVoltage, &adc1->channel[1].adcDevice);
}
if (returnValue == SUCCESS)
{
returnValue = ADConverter_construct(adcRow3, minVoltage, maxVoltage, &adc1->channel[2].adcDevice);
}
}
return returnValue;
}
void ADConverters_destruct(void)
{
ADConverter_destruct(adcRow1);
ADConverter_destruct(adcRow2);
ADConverter_destruct(adcRow3);
}

View File

@@ -0,0 +1,120 @@
// -----------------------------------------------------------------------------
/// @file DAConverter.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 DAConverter.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "DAConverter.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static uint32_t calculateDACValue(const struct DAConverter* self, int voltage);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus DAConverter_construct(struct DAConverter* self, int minVoltage, int maxVoltage, struct DACDevice* dacDevice)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
self->minVoltage = minVoltage;
self->maxVoltage = maxVoltage;
self->dacDevice = dacDevice;
self->initialized = true;
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void DAConverter_destruct(struct DAConverter* self)
{
self->initialized = false;
}
extern ErrorStatus DAConverter_setOutputVoltage(const struct DAConverter* self, int voltage)
{
ErrorStatus returnValue = SUCCESS;
if (returnValue == SUCCESS)
{
if (self->initialized)
{
uint32_t dacValue;
dacValue = calculateDACValue(self, voltage);
DACDevice_write(self->dacDevice, dacValue);
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
static uint32_t calculateDACValue(const struct DAConverter* self, int voltage)
{
uint32_t dacValue;
if (self->initialized)
{
uint32_t maxDacValue = ((1 << self->dacDevice->resolutionInBits) - 1);
dacValue = (voltage - self->minVoltage) * maxDacValue;
dacValue/= (self->maxVoltage - self->minVoltage);
if (dacValue > maxDacValue)
{
dacValue = maxDacValue;
}
}
else
{
dacValue = 0;
}
return dacValue;
}

View File

@@ -0,0 +1,120 @@
// -----------------------------------------------------------------------------
/// @file DAConverters.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 DAConverters.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "DAConverters.h"
#include "hsb-mrts.h"
#include "MAX5715.h"
#include "PCBA.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static struct DAConverter _dacRow1;
static struct DAConverter _dacRow2;
static struct DAConverter _dacRow3;
struct DAConverter* dacRow1 = &_dacRow1;
struct DAConverter* dacRow2 = &_dacRow2;
struct DAConverter* dacRow3 = &_dacRow3;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus DAConverters_construct(void)
{
ErrorStatus returnValue = SUCCESS;
int minVoltage;
int maxVoltage;
if (returnValue == SUCCESS)
{
if (PCBA_getInstance()->pcba == PCBA_Anode)
{
minVoltage = HSB_DAC_ANODE_MIN_VOLTAGE;
maxVoltage = HSB_DAC_ANODE_MAX_VOLTAGE;
}
else if (PCBA_getInstance()->pcba == PCBA_CathodeMCP)
{
minVoltage = HSB_DAC_CMCP_MIN_VOLTAGE;
maxVoltage = HSB_DAC_CMCP_MAX_VOLTAGE;
}
else if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
minVoltage = HSB_DAC_TESLA_MIN_VOLTAGE;
maxVoltage = HSB_DAC_TESLA_MAX_VOLTAGE;
}
else
{
minVoltage = 0;
maxVoltage = 0;
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
returnValue = DAConverter_construct(dacRow1, minVoltage, maxVoltage, &max5715->dac[0].dacDevice);
}
if (returnValue == SUCCESS)
{
returnValue = DAConverter_construct(dacRow2, minVoltage, maxVoltage, &max5715->dac[1].dacDevice);
}
if (returnValue == SUCCESS)
{
returnValue = DAConverter_construct(dacRow3, minVoltage, maxVoltage, &max5715->dac[2].dacDevice);
}
}
return returnValue;
}
void DAConverters_destruct(void)
{
DAConverter_destruct(dacRow1);
DAConverter_destruct(dacRow2);
DAConverter_destruct(dacRow3);
}

View File

@@ -25,6 +25,8 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <string.h>
#include "Display.h" #include "Display.h"
#include "Logger.h" #include "Logger.h"
@@ -53,12 +55,6 @@
static void DisplayTask(void* parameters); static void DisplayTask(void* parameters);
inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character);
inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter);
inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter);
inline static void Display_characterUpdateAll(struct Display* self);
inline static void Display_clearShadow(struct Display* self);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function definitions // Function definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -81,13 +77,12 @@ ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displa
if(returnValue == SUCCESS) if(returnValue == SUCCESS)
{ {
// Create a semaphore to sync access to the display shadow
vSemaphoreCreateBinary(self->displayShadowAccessSemaphore);
// Create a semaphore to sync writing requests to the display // Create a semaphore to sync writing requests to the display
vSemaphoreCreateBinary(self->displayWriteRequest); vSemaphoreCreateBinary(self->displayWriteRequest);
}
if (returnValue == SUCCESS)
Display_clearShadow(self); {
returnValue = DisplayContent_construct(&self->displayContent, self->displayDevice->parameters.numberOfRows, self->displayDevice->parameters.numberOfColumns);
} }
self->runTask = true; self->runTask = true;
@@ -118,15 +113,14 @@ ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displa
void Display_destruct(struct Display* self) void Display_destruct(struct Display* self)
{ {
self->runTask = false; self->runTask = false;
vSemaphoreDelete(self->displayShadowAccessSemaphore);
} }
ErrorStatus Display_clearScreen(struct Display* self) ErrorStatus Display_clearScreen(struct Display* self)
{ {
ErrorStatus returnValue = SUCCESS; ErrorStatus returnValue = SUCCESS;
returnValue = DisplayDevice_clear(self->displayDevice); DisplayContent_clear(&self->displayContent);
Display_clearShadow(self); xSemaphoreGive(self->displayWriteRequest);
return returnValue; return returnValue;
} }
@@ -203,16 +197,12 @@ ErrorStatus Display_write(struct Display* self, const char* buffer, size_t row,
if (returnValue == SUCCESS) if (returnValue == SUCCESS)
{ {
// Get the access semaphore to the display memory - wait for access
xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY);
int loopCounter; int loopCounter;
for (loopCounter = 0; loopCounter < length; loopCounter++) for (loopCounter = 0; loopCounter < length; loopCounter++)
{ {
Display_characterUpdate(&self->displayShadow[row - 1][(column - 1) + loopCounter], buffer[loopCounter]); DisplayContent_updateCharacter(&self->displayContent, (row - 1), (column - 1) + loopCounter, buffer[loopCounter]);
} }
xSemaphoreGive(self->displayShadowAccessSemaphore);
xSemaphoreGive(self->displayWriteRequest); xSemaphoreGive(self->displayWriteRequest);
} }
@@ -230,74 +220,25 @@ void Display_feedRefreshCounter(struct Display* self)
if (self->initialized) if (self->initialized)
{ {
self->refreshFeedCounter++; self->refreshFeedCounter++;
} if (self->refreshFeedCounter * self->refreshFeedFrequency_ms > self->refreshPeriod_ms)
}
inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character)
{
// Sending the same character should not lead to an updated character
if (displayCharacter->character != character)
{ {
displayCharacter->character = character;
displayCharacter->isUpdated = true;
}
}
inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter)
{
return displayCharacter->isUpdated;
}
inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter)
{
displayCharacter->isUpdated = false;
return displayCharacter->character;
}
inline static void Display_characterUpdateAll(struct Display* self)
{
size_t rowCounter;
size_t colCounter;
// Get the access semaphore to the shadow - wait until the other functions are finished with updating the shadow
xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY);
// Clear the display shadow
for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++)
{
for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++)
{
self->displayShadow[rowCounter][colCounter].isUpdated = true;
}
}
// Give back display memory access semaphore to allow new updates
xSemaphoreGive(self->displayShadowAccessSemaphore);
xSemaphoreGive(self->displayWriteRequest); xSemaphoreGive(self->displayWriteRequest);
}
}
} }
void Display_feedRefreshCounterFromISR(struct Display* self)
inline static void Display_clearShadow(struct Display* self)
{ {
// Clear the display shadow portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
size_t rowCounter; if (self->initialized)
size_t colCounter;
xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY);
for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++)
{ {
for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++) self->refreshFeedCounter++;
if (self->refreshFeedCounter * self->refreshFeedFrequency_ms > self->refreshPeriod_ms)
{ {
// All characters of the display shadow are set to BLANK, but the isUpdated flag is kept at FALSE xSemaphoreGiveFromISR(self->displayWriteRequest, &higherPriorityTaskWoken);
// this is, because the display itself has already received a command to clear its content. So
// blanking the shadow without setting isUpdated to TRUE is only an action to update the
// shadow to the actual situation on the screen
self->displayShadow[rowCounter][colCounter].character = 0x20;
self->displayShadow[rowCounter][colCounter].isUpdated = false;
} }
} }
xSemaphoreGive(self->displayShadowAccessSemaphore); portEND_SWITCHING_ISR(higherPriorityTaskWoken);
} }
@@ -305,108 +246,32 @@ static void DisplayTask(void* parameters)
{ {
struct Display* self = (struct Display*)parameters; struct Display* self = (struct Display*)parameters;
bool leaveLoops = false; char buffer;
char buffer[NHD0420_NUMBER_OF_COLUMNS];
int bufferIndex = 0;
int rowCounter = 0; int rowCounter = 0;
int colCounter = 0; int colCounter = 0;
size_t rowStart;
size_t columnStart;
while (self->runTask) while (self->runTask)
{ {
// Wait until a write or refresh function has requested this task to write to the display xSemaphoreTake(self->displayWriteRequest, portMAX_DELAY);
// xSemaphoreTake(self->displayWriteRequest, portMAX_DELAY);
// for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++)
{
// Get the access semaphore to the shadow - wait until the other functions are finished with updating the shadow
xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY);
leaveLoops = false;
bufferIndex = 0;
// Fragment display writing - writing will be done per line
for (; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++)
{
if (Display_isCharacterUpdated(&self->displayShadow[rowCounter][colCounter]))
{
// Found a character that has been updated
// Put the display cursor at the appropriate coordinates
rowStart = rowCounter + 1;
columnStart = colCounter + 1;
for (bufferIndex = 0; (colCounter < self->displayDevice->parameters.numberOfColumns); colCounter++, bufferIndex++)
{
// Respect the max number of bytes to transmit
if (bufferIndex < self->maxCharactersPerTransmit)
{
// Still within the boundaries
if (Display_isCharacterUpdated(&self->displayShadow[rowCounter][colCounter]))
{
// Current character has been updated and must be sent to display
// But data from display shadow to transmit buffer
buffer[bufferIndex] = Display_getUpdatedCharacter(&self->displayShadow[rowCounter][colCounter]);
}
else
{
// Current character is already on the display
// Stop scanning for more updated characters here and leave the loops in order
// to start transmission to the display
leaveLoops = true;
break;
}
}
else
{
// Max number of characters reached
// Stop scanning for more updated characters here and leave the loops in order
// to start transmission to the display
leaveLoops = true;
break;
}
}
}
// Check if loop should be left
if (leaveLoops)
{
// An inner loop decided to leave, so leave
break;
}
}
// Give back display memory access semaphore to allow new updates
xSemaphoreGive(self->displayShadowAccessSemaphore);
if (bufferIndex > 0)
{
// If there was an update found, send it to the display
DisplayDevice_write(self->displayDevice, buffer, bufferIndex, rowStart, columnStart);
}
// Handle the counters for row and column
if (colCounter > (self->displayDevice->parameters.numberOfColumns - 1))
{
// End of row reached - reset column and increment row
colCounter = 0;
if (rowCounter < (self->displayDevice->parameters.numberOfRows - 1))
{
// Increment row
rowCounter++;
}
else
{
// Last row reached - restart at row 0
rowCounter = 0;
}
}
// Check for display refresh timings // Check for display refresh timings
if (self->refreshFeedCounter * self->refreshFeedFrequency_ms > self->refreshPeriod_ms) if (self->refreshFeedCounter * self->refreshFeedFrequency_ms > self->refreshPeriod_ms)
{ {
self->refreshFeedCounter = 0; self->refreshFeedCounter = 0;
Display_characterUpdateAll(self); DisplayContent_refresh(&self->displayContent);
}
for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++)
{
for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++)
{
if (DisplayContent_isCharacterUpdated(&self->displayContent, rowCounter, colCounter))
{
buffer = DisplayContent_getCharacter(&self->displayContent, rowCounter, colCounter);
DisplayDevice_write(self->displayDevice, &buffer, 1, rowCounter + 1, colCounter + 1);
} }
} }
}
vTaskDelay(10); vTaskDelay(10);
} }

View File

@@ -0,0 +1,192 @@
// -----------------------------------------------------------------------------
/// @file DisplayContent.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 DisplayContent.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "DisplayContent.h"
#include "Logger.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus DisplayContent_construct(struct DisplayContent* self, size_t numberOfRows, size_t numberOfColumns)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
vSemaphoreCreateBinary(self->contentAccess);
self->numberOfRows = numberOfRows;
self->numberOfColumns = numberOfColumns;
self->initialized = true;
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void DisplayContent_destruct(struct DisplayContent* self)
{
vSemaphoreDelete(self->contentAccess);
self->initialized = false;
}
void DisplayContent_updateCharacter(struct DisplayContent* self, unsigned int row, unsigned int column, char character)
{
if (self->initialized)
{
if ((row < self->numberOfRows) && (column < self->numberOfColumns))
{
if (self->DisplayContent[row][column].character != character)
{
xSemaphoreTake(self->contentAccess, portMAX_DELAY);
self->DisplayContent[row][column].character = character;
self->DisplayContent[row][column].isUpdated = true;
xSemaphoreGive(self->contentAccess);
}
}
}
}
bool DisplayContent_isCharacterUpdated(struct DisplayContent* self, unsigned int row, unsigned int column)
{
bool returnValue = false;
if (self->initialized)
{
if ((row < self->numberOfRows) && (column < self->numberOfColumns))
{
returnValue = self->DisplayContent[row][column].isUpdated;
}
else
{
returnValue = false;
}
}
else
{
returnValue = false;
}
return returnValue;
}
char DisplayContent_getCharacter(struct DisplayContent* self, unsigned int row, unsigned int column)
{
char returnValue = 0;
if (self->initialized)
{
if ((row < self->numberOfRows) && (column < self->numberOfColumns))
{
xSemaphoreTake(self->contentAccess, portMAX_DELAY);
returnValue = self->DisplayContent[row][column].character;
self->DisplayContent[row][column].isUpdated = false;
xSemaphoreGive(self->contentAccess);
}
else
{
returnValue = 0;
}
}
else
{
returnValue = 0;
}
return returnValue;
}
void DisplayContent_refresh(struct DisplayContent* self)
{
if (self->initialized)
{
int rowCounter;
int columnCounter;
xSemaphoreTake(self->contentAccess, portMAX_DELAY);
for (rowCounter = 0; rowCounter < self->numberOfRows; rowCounter++)
{
for (columnCounter = 0; columnCounter < self->numberOfColumns; columnCounter++)
{
self->DisplayContent[rowCounter][columnCounter].isUpdated = true;
}
}
xSemaphoreGive(self->contentAccess);
}
}
void DisplayContent_clear(struct DisplayContent* self)
{
if (self->initialized)
{
int rowCounter;
int columnCounter;
xSemaphoreTake(self->contentAccess, portMAX_DELAY);
for (rowCounter = 0; rowCounter < self->numberOfRows; rowCounter++)
{
for (columnCounter = 0; columnCounter < self->numberOfColumns; columnCounter++)
{
self->DisplayContent[rowCounter][columnCounter].character = ' ';
self->DisplayContent[rowCounter][columnCounter].isUpdated = true;
}
}
xSemaphoreGive(self->contentAccess);
}
}

View File

@@ -108,6 +108,6 @@ extern void Displays_destruct(void)
static ErrorStatus Displays_mainDisplayObserverFromISR(const void* const data) static ErrorStatus Displays_mainDisplayObserverFromISR(const void* const data)
{ {
Display_feedRefreshCounter(mainDisplay); Display_feedRefreshCounterFromISR(mainDisplay);
return SUCCESS; return SUCCESS;
} }

View File

@@ -70,7 +70,7 @@ ErrorStatus Error_construct(void)
Observable_construct(&observable); Observable_construct(&observable);
errorQueue = xQueueCreate(ERROR_QUEUE_SIZE, sizeof(struct ErrorQueueItem)); errorQueue = xQueueCreate(ERROR_QUEUE_SIZE, sizeof(struct ErrorQueueItem));
xTaskCreate(ErrorTask, "ErrorTask", 300, NULL, 1, &errorTaskHandle); xTaskCreate(ErrorTask, "ErrorTask", 1024, NULL, 1, &errorTaskHandle);
return SUCCESS; return SUCCESS;
} }
@@ -111,6 +111,5 @@ static void ErrorTask (void* parameters)
{ {
xQueueReceive(errorQueue, &queueItem, portMAX_DELAY); xQueueReceive(errorQueue, &queueItem, portMAX_DELAY);
Observable_notifyObservers(&observable, (const void* const)queueItem.errorCode); Observable_notifyObservers(&observable, (const void* const)queueItem.errorCode);
vTaskDelay(1);
} }
} }

View File

@@ -27,13 +27,17 @@
#include "SignalProfileGenerator.h" #include "SignalProfileGenerator.h"
#include "PCBA.h"
#include "Logger.h" #include "Logger.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define SPG_0V_OFFSET (450) #define SPG_0V_OFFSET_ANODE (1153)
#define SPG_0V_OFFSET_CMCP (-241)
#define SPG_0V_OFFSET_TESLA (681)
#define SPG_PAUSE_SOFTSTART (300) // 5 minutes softstart after pause #define SPG_PAUSE_SOFTSTART (300) // 5 minutes softstart after pause
#define SPG_FIXPOINT_FACTOR (1000) #define SPG_FIXPOINT_FACTOR (1000)
@@ -106,7 +110,18 @@ void SignalProfileGenerator_calculate(struct SignalProfileGenerator* self)
// If first preset, start voltage is 0 // If first preset, start voltage is 0
if (self->currentPresetIndex == 0) if (self->currentPresetIndex == 0)
{ {
self->startVoltage = SPG_0V_OFFSET; if (PCBA_getInstance()->pcba == PCBA_Anode)
{
self->startVoltage = SPG_0V_OFFSET_ANODE;
}
else if (PCBA_getInstance()->pcba == PCBA_CathodeMCP)
{
self->startVoltage = SPG_0V_OFFSET_CMCP;
}
else if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
self->startVoltage = SPG_0V_OFFSET_TESLA;
}
} }
else else
{ {
@@ -165,7 +180,18 @@ void SignalProfileGenerator_calculate(struct SignalProfileGenerator* self)
} }
case SPG_PAUSE_RESTORE_SOFTSTART: case SPG_PAUSE_RESTORE_SOFTSTART:
{ {
self->pauseStartVoltage = SPG_0V_OFFSET; if (PCBA_getInstance()->pcba == PCBA_Anode)
{
self->pauseStartVoltage = SPG_0V_OFFSET_ANODE;
}
else if (PCBA_getInstance()->pcba == PCBA_CathodeMCP)
{
self->pauseStartVoltage = SPG_0V_OFFSET_CMCP;
}
else if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
self->pauseStartVoltage = SPG_0V_OFFSET_TESLA;
}
self->signal = ((self->voltagePriorToPause * SPG_FIXPOINT_FACTOR - self->pauseStartVoltage * SPG_FIXPOINT_FACTOR) / SPG_PAUSE_SOFTSTART) * (self->secondsCounter - self->pauseStartTime) + self->pauseStartVoltage * SPG_FIXPOINT_FACTOR; self->signal = ((self->voltagePriorToPause * SPG_FIXPOINT_FACTOR - self->pauseStartVoltage * SPG_FIXPOINT_FACTOR) / SPG_PAUSE_SOFTSTART) * (self->secondsCounter - self->pauseStartTime) + self->pauseStartVoltage * SPG_FIXPOINT_FACTOR;
self->signal = self->signal / SPG_FIXPOINT_FACTOR; self->signal = self->signal / SPG_FIXPOINT_FACTOR;

View File

@@ -33,7 +33,8 @@
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "CathodeMCP.h" #include "ADConverters.h"
#include "DAConverters.h"
#include "Displays.h" #include "Displays.h"
#include "Error.h" #include "Error.h"
#include "hsb-mrts.h" #include "hsb-mrts.h"
@@ -52,6 +53,7 @@
#include "nhd0420.h" #include "nhd0420.h"
#include "platform.h" #include "platform.h"
#include "CathodeMCP.h"
#include "Interlock.h" #include "Interlock.h"
#include "internalADC.h" #include "internalADC.h"
#include "gpio.h" #include "gpio.h"
@@ -196,7 +198,7 @@ static void initTask(void* parameters)
initPlatform(); initPlatform();
// Disable power // Disable power
GPIO_setValue(power6v5Enable, true); GPIO_setValue(power6v5Enable, false);
// Create a small task that only blinks a LED and flashes the identification letter on the display // 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); xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 100, &ledTaskArguments, 0, &ledTaskHandle);
@@ -204,9 +206,15 @@ static void initTask(void* parameters)
// Construct the displays // Construct the displays
Displays_construct(); Displays_construct();
// Construct the AD Converters
ADConverters_construct();
// Construct the DA Converters
DAConverters_construct();
hsb_generateStartScreen(mainDisplay); hsb_generateStartScreen(mainDisplay);
// Let start screen stay for 5 seconds // Let start screen stay for 5 seconds
// vTaskDelay(INIT_START_SCREEN_DELAY); vTaskDelay(INIT_START_SCREEN_DELAY);
hwTestItems.display = &nhd0420->displayDevice; hwTestItems.display = &nhd0420->displayDevice;
@@ -232,6 +240,7 @@ static void initTask(void* parameters)
// Construct the repair menu // Construct the repair menu
repairMenus_construct(); repairMenus_construct();
// xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 0, &sysTaskHandle); // xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 0, &sysTaskHandle);
// Delete this init task // Delete this init task

View File

@@ -31,7 +31,9 @@
#include "repairProcess.h" #include "repairProcess.h"
#include "repairProcesses.h" #include "repairProcesses.h"
#include "ADConverters.h"
#include "CathodeMCP.h" #include "CathodeMCP.h"
#include "DAConverters.h"
#include "Display.h" #include "Display.h"
#include "Error.h" #include "Error.h"
#include "hsb-mrts.h" #include "hsb-mrts.h"
@@ -69,7 +71,7 @@ static const char cursorValue[2] = {0x7E, '\0'};
// TEMPORARY PRESET STORAGE // TEMPORARY PRESET STORAGE
static const struct RepairPreset preset1 = {.numberOfStages = 1, .preset[0].softstartDuration = 100, .preset[0].duration = 200, .preset[0].voltage = 1000}; static const struct RepairPreset preset1 = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 60, .preset[0].voltage = 1000};
static const struct RepairPreset preset2 = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = 3000}; static const struct RepairPreset preset2 = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = 3000};
static const struct RepairPreset preset3 = {.numberOfStages = 1, .preset[0].softstartDuration = 300, .preset[0].duration = 600, .preset[0].voltage = 300}; static const struct RepairPreset preset3 = {.numberOfStages = 1, .preset[0].softstartDuration = 300, .preset[0].duration = 600, .preset[0].voltage = 300};
static const struct RepairPreset preset4 = {.numberOfStages = 1, .preset[0].softstartDuration = 400, .preset[0].duration = 800, .preset[0].voltage = 400}; static const struct RepairPreset preset4 = {.numberOfStages = 1, .preset[0].softstartDuration = 400, .preset[0].duration = 800, .preset[0].voltage = 400};
@@ -77,7 +79,7 @@ static const struct RepairPreset preset5 = {.numberOfStages = 1, .preset[0].soft
static const struct RepairPreset preset6 = {.numberOfStages = 1, .preset[0].softstartDuration = 600, .preset[0].duration = 1200, .preset[0].voltage = 600}; static const struct RepairPreset preset6 = {.numberOfStages = 1, .preset[0].softstartDuration = 600, .preset[0].duration = 1200, .preset[0].voltage = 600};
static const struct RepairPreset preset7 = {.numberOfStages = 1, .preset[0].softstartDuration = 700, .preset[0].duration = 1400, .preset[0].voltage = 700}; static const struct RepairPreset preset7 = {.numberOfStages = 1, .preset[0].softstartDuration = 700, .preset[0].duration = 1400, .preset[0].voltage = 700};
static const struct RepairPreset preset8 = {.numberOfStages = 1, .preset[0].softstartDuration = 800, .preset[0].duration = 1600, .preset[0].voltage = 800}; static const struct RepairPreset preset8 = {.numberOfStages = 1, .preset[0].softstartDuration = 800, .preset[0].duration = 1600, .preset[0].voltage = 800};
static const struct RepairPreset preset9 = {.numberOfStages = 1, .preset[0].softstartDuration = 900, .preset[0].duration = 1800, .preset[0].voltage = 900}; static const struct RepairPreset preset9 = {.numberOfStages = 2, .preset[0].softstartDuration = 900, .preset[0].duration = 1800, .preset[0].voltage = 6000, .preset[1].softstartDuration = 100, .preset[1].duration = 1800, .preset[1].voltage = 8000};
static const struct RepairPreset* presetArray[9] = {&preset1, &preset2, &preset3, &preset4, &preset5, &preset6, &preset7, &preset8, &preset9}; static const struct RepairPreset* presetArray[9] = {&preset1, &preset2, &preset3, &preset4, &preset5, &preset6, &preset7, &preset8, &preset9};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -204,6 +206,7 @@ void repairMenu_destruct (struct RepairMenu* self)
void repairMenu_interlockFailed(struct RepairMenu* self, T_INTERLOCK_ID interlockID) void repairMenu_interlockFailed(struct RepairMenu* self, T_INTERLOCK_ID interlockID)
{ {
repairMenu_changeState(self, ERROR_STATE); repairMenu_changeState(self, ERROR_STATE);
if (interlockID == COMMON_INTERLOCK) if (interlockID == COMMON_INTERLOCK)
{ {
snprintf(self->errorMessage, sizeof(self->errorMessage) / sizeof(self->errorMessage[0]), "COVER OPEN"); snprintf(self->errorMessage, sizeof(self->errorMessage) / sizeof(self->errorMessage[0]), "COVER OPEN");
@@ -275,13 +278,12 @@ static void repairMenu_task(void* parameters)
else if (self->menuState == REPAIR_ASK_PAUSE) else if (self->menuState == REPAIR_ASK_PAUSE)
{ {
uint32_t remainingTime = repairProcess_getRemainingRepairTime(repairProcesses_getMainRepairProcess()); uint32_t remainingTime = repairProcess_getRemainingRepairTime(repairProcesses_getMainRepairProcess());
repairMenu_printAskPause(self);
if (tempScreenCounter >= remainingTime) if (tempScreenCounter >= remainingTime)
{ {
// POPUP screen time is over, return to previous state // POPUP screen time is over, return to previous state
repairMenu_changeState(self, tempMenuState); repairMenu_changeState(self, tempMenuState);
} }
repairMenu_printAskPause(self);
} }
else if (self->menuState == REPAIR_PAUSE) else if (self->menuState == REPAIR_PAUSE)
{ {
@@ -358,7 +360,6 @@ static void repairMenu_printRepair(struct RepairMenu* self)
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), " %02d:%02d:%02d remain ", remainingTime.hours, remainingTime.minutes, remainingTime.seconds); snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), " %02d:%02d:%02d remain ", remainingTime.hours, remainingTime.minutes, remainingTime.seconds);
Display_write(self->display, buffer, 1, 1); Display_write(self->display, buffer, 1, 1);
LOGGER_DEBUG(mainLog, "%s", buffer);
// Regulation is unique for each row // Regulation is unique for each row
// For TESLA repair only row 1 (out of 0,1,2) is used // For TESLA repair only row 1 (out of 0,1,2) is used
@@ -369,14 +370,14 @@ static void repairMenu_printRepair(struct RepairMenu* self)
row = repairProcess_getRowInformation(repairProcess, loopCounter); row = repairProcess_getRowInformation(repairProcess, loopCounter);
snprintf (buffer, sizeof(buffer) / sizeof(buffer[0]), "R%d", loopCounter + 1); snprintf (buffer, sizeof(buffer) / sizeof(buffer[0]), "R%d", loopCounter + 1);
Display_write(self->display, buffer, 2, ((loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer))); Display_write(self->display, buffer, 2, ((loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) + loopCounter) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer)));
if (!row->errorData.rowHasError) if (!row->errorData.rowHasError)
{ {
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%05dV", row->lastADCValue); snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%5dV", row->lastADCValue);
Display_write(self->display, buffer, 3, (loopCounter + (loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer))); Display_write(self->display, buffer, 3, (loopCounter + (loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer)));
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04dER", row->pidError); snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%4dER", row->pidError);
Display_write(self->display, buffer, 4, (loopCounter + (loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer))); Display_write(self->display, buffer, 4, (loopCounter + (loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer)));
} }
else else
@@ -631,12 +632,12 @@ static void repairMenu_solenoidUnlock(struct RepairMenu* self, int cursorIndex)
static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorIndex) static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorIndex)
{ {
ErrorStatus returnValue = SUCCESS; ErrorStatus returnValue = SUCCESS;
self->rpParameters.adcRow1 = &adc1->channel[0]; self->rpParameters.adcR1 = adcRow1;
self->rpParameters.adcRow2 = &adc1->channel[1]; self->rpParameters.adcR2 = adcRow2;
self->rpParameters.adcRow3 = &adc1->channel[2]; self->rpParameters.adcR3 = adcRow3;
self->rpParameters.dacRow1 = &max5715->dac[0]; self->rpParameters.dacR1 = dacRow1;
self->rpParameters.dacRow2 = &max5715->dac[1]; self->rpParameters.dacR2 = dacRow2;
self->rpParameters.dacRow3 = &max5715->dac[2]; self->rpParameters.dacR3 = dacRow3;
if (returnValue == SUCCESS) if (returnValue == SUCCESS)
{ {
@@ -700,11 +701,13 @@ static void repairMenu_pauseRepairProcess(struct RepairMenu* self, int cursorInd
{ {
repairMenu_changeState(self, REPAIR_PAUSE); repairMenu_changeState(self, REPAIR_PAUSE);
repairProcess_pauseProcess(repairProcesses_getMainRepairProcess()); repairProcess_pauseProcess(repairProcesses_getMainRepairProcess());
hsb_disableSafety();
} }
static void repairMenu_continueRepairProcess(struct RepairMenu* self, int cursorIndex) static void repairMenu_continueRepairProcess(struct RepairMenu* self, int cursorIndex)
{ {
hsb_enableSafety();
repairMenu_changeState(self, REPAIR_RUNNING); repairMenu_changeState(self, REPAIR_RUNNING);
repairProcess_continueProcess(repairProcesses_getMainRepairProcess()); repairProcess_continueProcess(repairProcesses_getMainRepairProcess());
} }

View File

@@ -103,6 +103,7 @@ struct RepairMenu* repairMenus_getMainRepairMenu(void)
static ErrorStatus repairMenu_errorReceive(const void* const data) static ErrorStatus repairMenu_errorReceive(const void* const data)
{ {
T_ErrorCode errorCode = (T_ErrorCode)data; T_ErrorCode errorCode = (T_ErrorCode)data;
// Only respond to the errors necessary // Only respond to the errors necessary
if (errorCode == INTERLOCK_COMMON_FAIL) if (errorCode == INTERLOCK_COMMON_FAIL)

View File

@@ -100,15 +100,15 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro
} }
if (returnValue == SUCCESS) if (returnValue == SUCCESS)
{ {
returnValue = repairProcessRow_construct(&self->row[0], parameters->adcRow1, parameters->dacRow1, HSB_MAINREPR_OOL_DURATION, HSB_MAINREPR_OOL_VALUE); returnValue = repairProcessRow_construct(&self->row[0], parameters->adcR1, parameters->dacR1, HSB_MAINREPR_OOL_DURATION, HSB_MAINREPR_OOL_VALUE);
} }
if (returnValue == SUCCESS) if (returnValue == SUCCESS)
{ {
returnValue = repairProcessRow_construct(&self->row[1], parameters->adcRow2, parameters->dacRow2, HSB_MAINREPR_OOL_DURATION, HSB_MAINREPR_OOL_VALUE); returnValue = repairProcessRow_construct(&self->row[1], parameters->adcR2, parameters->dacR2, HSB_MAINREPR_OOL_DURATION, HSB_MAINREPR_OOL_VALUE);
} }
if (returnValue == SUCCESS) if (returnValue == SUCCESS)
{ {
returnValue = repairProcessRow_construct(&self->row[2], parameters->adcRow3, parameters->dacRow3, HSB_MAINREPR_OOL_DURATION, HSB_MAINREPR_OOL_VALUE); returnValue = repairProcessRow_construct(&self->row[2], parameters->adcR3, parameters->dacR3, HSB_MAINREPR_OOL_DURATION, HSB_MAINREPR_OOL_VALUE);
} }
if (returnValue == SUCCESS) if (returnValue == SUCCESS)
{ {
@@ -132,22 +132,27 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro
void repairProcess_destruct(struct RepairProcess* self) void repairProcess_destruct(struct RepairProcess* self)
{ {
if (self->initialized)
MAX5715Channel_setValue(self->row[0].dacChannel, 0); {
MAX5715Channel_setValue(self->row[1].dacChannel, 0); // SET ALL DACs to 0
MAX5715Channel_setValue(self->row[2].dacChannel, 0); DAConverter_setOutputVoltage(self->row[0].dacChannel, 0);
DAConverter_setOutputVoltage(self->row[1].dacChannel, 0);
DAConverter_setOutputVoltage(self->row[2].dacChannel, 0);
self->runTask = false; self->runTask = false;
xSemaphoreGive(self->secondsSyncronisation);
while (!self->taskIsRunning) while (!self->taskIsRunning)
{ {
vTaskDelay(1); vTaskDelay(1);
} }
SignalProfileGenerator_destruct(&self->signalProfileGenerator);
Observable_destruct(&self->observable); Observable_destruct(&self->observable);
repairProcessRow_destruct(&self->row[0]); repairProcessRow_destruct(&self->row[0]);
repairProcessRow_destruct(&self->row[1]); repairProcessRow_destruct(&self->row[1]);
repairProcessRow_destruct(&self->row[2]); repairProcessRow_destruct(&self->row[2]);
vSemaphoreDelete(self->secondsSyncronisation); vSemaphoreDelete(self->secondsSyncronisation);
self->initialized = false; self->initialized = false;
}
} }
@@ -213,9 +218,9 @@ static void repairProcess_task(void* parameters)
self->taskIsRunning = true; self->taskIsRunning = true;
// Reset the seconds counter to 0 // Reset the seconds counter to 0
MAX5715Channel_setValue(self->row[0].dacChannel, self->row[0].lastDACValue); DAConverter_setOutputVoltage(self->row[0].dacChannel, self->row[0].lastDACValue);
MAX5715Channel_setValue(self->row[1].dacChannel, self->row[1].lastDACValue); DAConverter_setOutputVoltage(self->row[1].dacChannel, self->row[1].lastDACValue);
MAX5715Channel_setValue(self->row[2].dacChannel, self->row[2].lastDACValue); DAConverter_setOutputVoltage(self->row[2].dacChannel, self->row[2].lastDACValue);
while(self->runTask) while(self->runTask)
{ {
@@ -237,7 +242,7 @@ static void repairProcess_task(void* parameters)
if (!self->row[loopCounter].errorData.rowHasError) if (!self->row[loopCounter].errorData.rowHasError)
{ {
// Read the last ADC channel value // Read the last ADC channel value
ADCChannel_read(self->row[loopCounter].adcChannel, &self->row[loopCounter].lastADCValue); self->row[loopCounter].lastADCValue = ADConverter_getInputVoltage(self->row[loopCounter].adcChannel);
// Calculate the error // Calculate the error
self->row[loopCounter].pidError = self->signalProfileGenerator.signal - (int)self->row[loopCounter].lastADCValue; self->row[loopCounter].pidError = self->signalProfileGenerator.signal - (int)self->row[loopCounter].lastADCValue;
// Calculate the PID // Calculate the PID
@@ -280,7 +285,7 @@ static void repairProcess_task(void* parameters)
} }
} }
// Send the PID value to the DAC // Send the PID value to the DAC
MAX5715Channel_setValue(self->row[loopCounter].dacChannel, self->row[loopCounter].lastDACValue); DAConverter_setOutputVoltage(self->row[loopCounter].dacChannel, self->row[loopCounter].lastDACValue);
LOGGER_DEBUG(mainLog, "Row %d --- ADC: %d Error: %d PID: %d", loopCounter, self->row[loopCounter].lastADCValue, self->row[loopCounter].pidError, self->row[loopCounter].lastDACValue); LOGGER_DEBUG(mainLog, "Row %d --- ADC: %d Error: %d PID: %d", loopCounter, self->row[loopCounter].lastADCValue, self->row[loopCounter].pidError, self->row[loopCounter].lastDACValue);
} }
@@ -288,7 +293,7 @@ static void repairProcess_task(void* parameters)
{ {
// ROW is in error state // ROW is in error state
self->row[loopCounter].lastDACValue = 0; self->row[loopCounter].lastDACValue = 0;
MAX5715Channel_setValue(self->row[loopCounter].dacChannel, self->row[loopCounter].lastDACValue); 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

@@ -54,7 +54,7 @@
// Function definitions // Function definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
ErrorStatus repairProcessRow_construct(struct RepairProcessRow* self, const struct AdcChannel* adcChannel, const struct MAX5715_DAC* dacChannel, int outOfLimitsDuration, int outOfLimitsValue) ErrorStatus repairProcessRow_construct(struct RepairProcessRow* self, const struct ADConverter* adcChannel, const struct DAConverter* dacChannel, int outOfLimitsDuration, int outOfLimitsValue)
{ {
ErrorStatus returnValue = SUCCESS; ErrorStatus returnValue = SUCCESS;