init new PC

This commit is contained in:
2022-10-19 14:34:01 +02:00
commit b0e950332c
181 changed files with 178428 additions and 0 deletions

View File

@ -0,0 +1,190 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: INIT_Initialization
// Filename: INIT_Initialization.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: Initialization module
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
#include "INIT_Initialization.h"
// Application
#include "VARH_VariableHandler.h"
#include "PECO_PeltierController.h"
#include "MAIN_MainApplication.h"
// Drivers
#include "../Drivers/USFL_UserFlash.h"
#include "../Drivers/ANPI_AnalogPortsIn.h"
#include "../Drivers/ANPO_AnalogPortsOut.h"
#include "../Drivers/SPID_SpiDriver.h"
#include "../Drivers/DIPO_DigitalPorts.h"
#include "../Drivers/ADCD_AdcDriver.h"
#include "../Drivers/TEMP_Temperature.h"
#include "../Drivers/CAND_CanDriver.h"
#include "../Drivers/ERRH_ErrorHandler.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"INIT_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityHigh7, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID vTask ( PVOID arg )__NORETURN;
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: INIT_boCreateTask
// Description: Create the init Task
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL INIT_boCreateTask( VOID )
{
BOOL boOK = TRUE;
boOK &= ((m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute )) != NULL); // create init Task
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: vInitTask
// Description: Initialization Task, priority must be high!
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vTask( PVOID arg )
{
UNUSED( arg );
BOOL boOK = TRUE;
//boOK &= USFL_boInitializeModule();
boOK &= VARH_boInitializeModule();
boOK &= DIPO_boInitializeModule();
boOK &= ANPI_boInitializeModule();
boOK &= ANPO_boInitializeModule();
boOK &= SPID_boInitializeModule();
boOK &= ADCD_boInitializeModule();
boOK &= TEMP_boInitializeModule();
boOK &= CAND_boInitializeModule();
boOK &= PECO_boInitializeModule();
boOK &= MAIN_boInitializeModule();
if( !boOK ){
osKernelLock(); // lock kernel to prevent task switch
while( 1 ){ // Toggle Error LED fast
DIPO_vToggleOutput( DIPO_eLED );
DELAY_MS( 100 );
}
}
osThreadSuspend( m_pstThreadID );
while( 1 );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================

View File

@ -0,0 +1,94 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Initialization
// Filename: INIT_Initialization
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef INIT_INITIALIZATION_H
#define INIT_INITIALIZATION_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL INIT_boCreateTask( VOID );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,319 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Main Application
// Filename: MAIN_MainApplication.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: TEC - Peltier Controller Communication handler
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "MAIN_MainApplication.h"
// Application
#include "VARH_VariableHandler.h"
#include "PECO_PeltierController.h"
// Drivers
#include "../Drivers/TEMP_Temperature.h"
#include "../Drivers/DIPO_DigitalPorts.h"
#include "../Drivers/CAND_CanDriver.h"
#include "../Drivers/ANPI_AnalogPortsIn.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define MSG_QUEUE_SIZE 8
#define EVENT_NEW_MESSAGE ((U32)(1<<0))
#define EVENT_TIMER_UPDATE ((U32)(1<<1))
#define EVENT_WATCHDOG ((U32)(1<<2))
#define EVENT_FLAGS_ALL ( EVENT_NEW_MESSAGE | EVENT_TIMER_UPDATE | EVENT_WATCHDOG )
#define COMMAND_NONE 0
#define COMMAND_ON 1
#define COMMAND_OFF 2
#define COMMAND_WATCHDOG 3
#define WATCHDOG 33000
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID vTask( PVOID arg );
PRIVATE VOID vEventCallback( PVOID pvData );
PRIVATE VOID vMsgRxCallback( CAND_Message stMessage );
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osMessageQueueId_t m_pstCANRxMsgQueueID = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
LOCAL osTimerId_t m_pstWatchdogTimer = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"MAIN_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityAboveNormal1, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
LOCAL CONST osMessageQueueAttr_t stCANRxMsgQueueAttribute =
{
"MAIN_CAN_Rx_Queue", // name of the message queue
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for data storage
0, // size of provided memory for data storage
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"MAIN_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osTimerAttr_t stTimerAttribute =
{
"MAIN_UpdateTimer", // name of the timer
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osTimerAttr_t stWatchdogTimerAttribute =
{
"MAIN_Watchdog", // name of the timer
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: MAIN_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL MAIN_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ( ( m_pstEventID = osEventFlagsNew( &stEventAttribute ) ) == NULL ) ? FALSE : TRUE;
boOK &= ( ( m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute ) ) == NULL ) ? FALSE : TRUE;
boOK &= ( ( m_pstCANRxMsgQueueID = osMessageQueueNew( MSG_QUEUE_SIZE, sizeof( CAND_Message ), &stCANRxMsgQueueAttribute ) ) == NULL ) ? FALSE : TRUE;
boOK &= ( m_pstUpdateTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute ) ) == NULL ? FALSE : TRUE;
boOK &= ( m_pstWatchdogTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stWatchdogTimerAttribute ) ) == NULL ? FALSE : TRUE;
boOK &= (osTimerStart( m_pstUpdateTimer, 1000 ) == osOK ) ? TRUE : FALSE;
//boOK &= (osTimerStart( m_pstWatchdogTimer, WATCHDOG ) == osOK ) ? TRUE : FALSE;
CAND_vSetRxCallback( vMsgRxCallback );
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: vMainTask
// Description: Main Application Task
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vTask( PVOID arg )
{
UNUSED( arg );
U32 u32Flags;
U8 au8Buffer[8];
while( TRUE )
{
u32Flags = osEventFlagsWait( m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever ); // wait until flags getting triggered
if( u32Flags & EVENT_NEW_MESSAGE ) { // New message from CAN
CAND_Message stMessage;
osMessageQueueGet( m_pstCANRxMsgQueueID, &stMessage, NULL, 0 ); // get message from queue
U8 u8Register = stMessage.au8Data[0];
U8 u8Type = stMessage.u8Type;
if( u8Type == MESSAGE_TYPE_READ ){ // Message type read
osDelay(100);
if( u8Register >= VARH_eNumberOfVariables ){ // check register
// send register not found
au8Buffer[0] = 0xFF;
CAND_boSendMessage( stMessage.u16Id, au8Buffer, 1 );
} else {
VARH_UVariable uVariable = VARH_uGetVariableData(u8Register); // get data
au8Buffer[0] = u8Register;
UTIL_vMemCopy(&uVariable, &au8Buffer[1], 4); // copy data in buffer
CAND_boSendMessage( stMessage.u16Id, au8Buffer, 5 );
}
} else if( u8Type == MESSAGE_TYPE_WRITE ){ // Message type writeset
VARH_UVariable uData;
UTIL_vMemCopy(&stMessage.au8Data[1], &uData, 4);
VARH_vSetVariableData(u8Register, uData);
} else if( u8Type == MESSAGE_TYPE_COMMAND ){ // Message type command
switch (u8Register)
{
case COMMAND_ON:
PECO_Enable( TRUE );
break;
case COMMAND_OFF:
PECO_Enable( FALSE );
break;
case COMMAND_WATCHDOG:
osTimerStart( m_pstWatchdogTimer, WATCHDOG );
break;
default:
break;
}
}
}
if( u32Flags & EVENT_TIMER_UPDATE )
{
DIPO_vToggleOutput( DIPO_eLED );
}
if( u32Flags & EVENT_WATCHDOG )
{
PECO_Enable( FALSE );
// TODO: WATCHDOG: what else?
}
}
}
//-------------------------------------------------------------------------------------------------
// Function: vEventCallback
// Description: Callback for events
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vEventCallback( PVOID pvData )
{
osEventFlagsSet( m_pstEventID, (U32)pvData );
}
//-------------------------------------------------------------------------------------------------
// Function: vEventCallback
// Description: Callback for events
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vMsgRxCallback( CAND_Message stMessage )
{
osMessageQueuePut( m_pstCANRxMsgQueueID, &stMessage, 0, 0 );
osEventFlagsSet( m_pstEventID, EVENT_NEW_MESSAGE );
}

View File

@ -0,0 +1,92 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Main Application
// Filename: MAIN_MainApplication.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef MAIN_MAINAPPLICATION_H
#define MAIN_MAINAPPLICATION_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL MAIN_boInitializeModule( VOID );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,321 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Peltier Controller
// Filename: PECO_PeltierController.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the Peltier Controller Output
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "PECO_PeltierController.h"
//Application
#include "../Application/VARH_VariableHandler.h"
// Driver
#include "ANPO_AnalogPortsOut.h"
#include "DIPO_DigitalPorts.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define REFRESH 100 // Refresh rate in ms
#define EVENT_TIMER_UPDATE ((U32)(1<<0))
#define EVENT_FLAGS_ALL ( EVENT_TIMER_UPDATE )
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"PECO_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityHigh, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
LOCAL CONST osTimerAttr_t stTimerAttribute =
{
"PECO_UpdateTimer", // name of the timer
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"PECO_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID vTask( PVOID arg );
BOOL boSetPeltierVoltage( FLOAT Voltage );
PRIVATE VOID vEventCallback( PVOID pvData );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern IWDG_HandleTypeDef hiwdg;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: PECO_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL PECO_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ( ( m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute ) ) == NULL ) ? FALSE : TRUE;
boOK &= ( ( m_pstEventID = osEventFlagsNew( &stEventAttribute ) ) == NULL) ? FALSE : TRUE;
boOK &= ( m_pstUpdateTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute ) ) == NULL ? FALSE : TRUE;
boSetPeltierVoltage(0);
boOK &= (osTimerStart( m_pstUpdateTimer, REFRESH ) == osOK ) ? TRUE : FALSE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: PECO_Enable
// Description: Enables the Peltier Controller Output
// Parameters: BOOL boEnable
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID PECO_Enable( BOOL boEnable ){
DIPO_vSetState(DIPO_eEN, boEnable);
VARH_vSetVariableDataFromSystemU32( VARH_ePowerState, (U32)boEnable );
}
//-------------------------------------------------------------------------------------------------
// Function: PECO_isEnabled
// Description: Returns true if the Output is enabled
// Parameters: None
// Returns: BOOL boEnableOutput
//-------------------------------------------------------------------------------------------------
BOOL PECO_isEnabled( VOID ){
return (BOOL)VARH_u32GetVariableData( VARH_ePowerState );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: vTask
// Description: Task
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID vTask( PVOID arg )
{
UNUSED( arg );
U32 u32Flags;
FLOAT last_error = 0;
FLOAT integral = 0;
FLOAT dT = REFRESH / 1000.0f; // 1s
while ( TRUE )
{
u32Flags = osEventFlagsWait( m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
if( u32Flags & EVENT_TIMER_UPDATE )
{
HAL_IWDG_Refresh(&hiwdg);
if ( PECO_isEnabled() )
{
if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConstTemp )
{
// TODO: check the measurements, everything ok?
// PID Regelung
FLOAT kp = VARH_flGetVariableData( VARH_ePID_kp );
FLOAT ki = VARH_flGetVariableData( VARH_ePID_ki );
FLOAT kd = VARH_flGetVariableData( VARH_ePID_kd );
FLOAT max = VARH_flGetVariableData( VARH_ePID_Max );
FLOAT min = VARH_flGetVariableData( VARH_ePID_Min );
FLOAT Tnow = VARH_flGetVariableData( VARH_eTemp_C );
FLOAT Tset = VARH_flGetVariableData( VARH_ePID_Temp );
// -error
FLOAT error = Tnow - Tset;
// proportional term
FLOAT P = kp * error;
// integral term
integral += error * dT;
FLOAT I = ki * integral;
// derivative term
FLOAT D = kd * ( error - last_error ) / dT;
last_error = error;
// total
FLOAT output = P + I + D;
// limitter
if ( output > max ){
output = max;
integral = 0;
} else if ( output < min ){
output = min;
integral = 0;
}
boSetPeltierVoltage( output ); // set the output
} else if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConst_Voltage )
{
boSetPeltierVoltage( VARH_flGetVariableData( VARH_eControlVoltage ) ); // set the output
last_error = 0;
integral = 0;
}
} else {
last_error = 0;
integral = 0;
}
}
}
}
//-------------------------------------------------------------------------------------------------
// Function: boSetPeltierVoltage
// Description: Sets the Peltier elements to a specific Voltage
// Parameters: S8 Voltage (12V - -3V)
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL boSetPeltierVoltage( FLOAT Voltage ){
BOOL boOK = TRUE;
if( Voltage > 12 ) Voltage = 12;
if( Voltage < -3 ) Voltage = -3;
ANPO_boSetVoltage( ( ( (FLOAT)Voltage ) + 20.088) / 34.103 );
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: vEventCallback
// Description: Callback for events
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vEventCallback( PVOID pvData )
{
osEventFlagsSet( m_pstEventID, (U32)pvData );
}

View File

@ -0,0 +1,98 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Peltier Controller
// Filename: PECO_PeltierController.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef PECO_PELTIERCONTROLLER_H
#define PECO_PELTIERCONTROLLER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
typedef enum {
PECO_eConstTemp = 0,
PECO_eConst_Voltage = 1
} PECO_eMode;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL PECO_boInitializeModule( VOID );
VOID PECO_Enable( BOOL Enable );
BOOL PECO_isEnabled( VOID );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,433 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Variable Handler
// Filename: VARH_VariableHandler.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with global variables
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "VARH_VariableHandler.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL VARH_StVar m_auVariable[VARH_eNumberOfVariables];
LOCAL osMutexId_t m_pstMutexID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST VARH_StVarInfo m_astVarInfo[VARH_eNumberOfVariables] =
{
{ VARH_FLAGINFO_NONE, (VARH_UVariable)(U32)1, (VARH_UVariable)(U32)0, (VARH_UVariable)(U32)1}, // VARH_eMode
{ VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-2.0f, (VARH_UVariable)12.0f}, // VARH_eControlVoltage
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)100.0f }, // VARH_ePID_kp
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)100.0f }, // VARH_ePID_ki
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)100.0f }, // VARH_ePID_kd
{ VARH_FLAGINFO_FLOAT, (VARH_UVariable)23.0f, (VARH_UVariable)-40.0f, (VARH_UVariable)50.0f }, // VARH_ePID_Temp
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)10.0f, (VARH_UVariable)0.0f, (VARH_UVariable)12.0f }, // VARH_ePID_Max
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)-2.0f, (VARH_UVariable)-2.0f, (VARH_UVariable)0.0f }, // VARH_ePID_Min
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-60.0f, (VARH_UVariable)100.0f }, // VARH_eTemp_H
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-60.0f, (VARH_UVariable)100.0f }, // VARH_eTemp_C
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-50.0f, (VARH_UVariable)70.0f }, // VARH_eTemp_Diff
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-5.0f, (VARH_UVariable)14.0f }, // VARH_ePeltier_U
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-10.0f, (VARH_UVariable)10.0f }, // VARH_ePeltier_I
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)5.0f }, // VARH_ePeltier_R
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-50.0f, (VARH_UVariable)150.0f }, // VARH_ePeltier_P
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)20.0f, (VARH_UVariable)30.0f }, // VARH_eSupply_U
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)5.0f }, // VARH_eSupply_I
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)150.0f }, // VARH_eSupply_P
{ VARH_FLAGINFO_READONLY, (VARH_UVariable)(U32)0, (VARH_UVariable)(U32)0, (VARH_UVariable)(U32)1 }, // VARH_ePowerState
};
LOCAL CONST osMutexAttr_t m_stMutexAttr =
{
"VARH_Mutex", // human readable mutex name
osMutexRecursive | osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
// check functions
PRIVATE BOOL boCheckRange( U8 u8Variable, VARH_UVariable uNewData );
PRIVATE BOOL boBooleanVarCheck( U32 u32NewValue );
PRIVATE BOOL boU32VarCheck( U8 u8Variable, U32 u32NewValue );
PRIVATE BOOL boS32VarCheck( U8 u8Variable, S32 s32NewValue );
PRIVATE BOOL boFloatVarCheck( U8 u8Variable, FLOAT flNewValue );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: VARH_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: BOOL boInitConfig
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL VARH_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr ) ) == NULL ) ? FALSE : TRUE;
VARH_vSetAllVariablesToInitData();
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableData
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
// Parameters: U8 u8Variable
// VARH_UVariable uData
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableData( U8 u8Variable, VARH_UVariable uData )
{
// check parameters
if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_READONLY )
{
return;
}
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
if( boCheckRange( u8Variable, uData ) ) { m_auVariable[u8Variable].uData = uData; } // store new value
osMutexRelease( m_pstMutexID ); // release mutex
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableDataU32
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
// Parameters: U8 u8Variable
// U32 u32Data
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableDataU32( U8 u8Variable, U32 u32Data )
{
VARH_vSetVariableData( u8Variable, (VARH_UVariable)u32Data );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableDataS32
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
// Parameters: U8 u8Variable
// S32 s32Data
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableDataS32( U8 u8Variable, S32 s32Data )
{
VARH_vSetVariableData( u8Variable, (VARH_UVariable)s32Data );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableDataFloat
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
// Parameters: U8 u8Variable
// FLOAT flData
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableDataFloat( U8 u8Variable, FLOAT flData )
{
VARH_vSetVariableData( u8Variable, (VARH_UVariable)flData );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableDataFromSystem
// Description: Sets the Variable Data from System
// Use only internal, not for User!
// Parameters: U8 u8Variable
// VARH_UVariable uData
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableDataFromSystem( U8 u8Variable, VARH_UVariable uData )
{
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
if( !boCheckRange( u8Variable, uData ) )
{
m_auVariable[u8Variable].u8Flags |= VARH_FLAG_OUTOFRANGE; // check the value
}
m_auVariable[u8Variable].uData = uData; // store new value
osMutexRelease( m_pstMutexID ); // release mutex
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableDataFromSystemU32
// Description: Sets the Variable Data from System
// Use only internal, not for User!
// Parameters: U8 u8Variable
// U32 u32Data
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableDataFromSystemU32( U8 u8Variable, U32 u32Data )
{
VARH_vSetVariableDataFromSystem( u8Variable, (VARH_UVariable)u32Data );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableDataFromSystemS32
// Description: Sets the Variable Data from System
// Use only internal, not for User!
// Parameters: U8 u8Variable
// S32 s32Data
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableDataFromSystemS32( U8 u8Variable, S32 s32Data )
{
VARH_vSetVariableDataFromSystem( u8Variable, (VARH_UVariable)s32Data );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableDataFromSystemFloat
// Description: Sets the Variable Data from System
// Use only internal, not for User!
// Parameters: U8 u8Variable
// FLOAT flData
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableDataFromSystemFloat( U8 u8Variable, FLOAT flData )
{
VARH_vSetVariableDataFromSystem( u8Variable, (VARH_UVariable)flData );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_uGetVariableData
// Description: Gets the Variable Data
// Parameters: U8 u8Variable
// Returns: VARH_UVariable
//-------------------------------------------------------------------------------------------------
VARH_UVariable VARH_uGetVariableData( U8 u8Variable )
{
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
VARH_UVariable uVar = m_auVariable[u8Variable].uData;
osMutexRelease( m_pstMutexID ); // release mutex
return( uVar );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_u32GetVariableData
// Description: Gets the Variable Data
// Parameters: U8 u8Variable
// Returns: U32
//-------------------------------------------------------------------------------------------------
U32 VARH_u32GetVariableData( U8 u8Variable )
{
return VARH_uGetVariableData( u8Variable ).u32Val;
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_s32GetVariableData
// Description: Gets the Variable Data
// Parameters: U8 u8Variable
// Returns: S32
//-------------------------------------------------------------------------------------------------
S32 VARH_s32GetVariableData( U8 u8Variable )
{
return VARH_uGetVariableData( u8Variable ).s32Val;
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_flGetVariableData
// Description: Gets the Variable Data
// Parameters: U8 u8Variable
// Returns: FLOAT
//-------------------------------------------------------------------------------------------------
FLOAT VARH_flGetVariableData( U8 u8Variable )
{
return VARH_uGetVariableData( u8Variable ).flVal;
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_uGetVariableFlags
// Description: Gets the Variable Flags
// Parameters: U8 u8Variable
// Returns: u8Flags
//-------------------------------------------------------------------------------------------------
U8 VARH_uGetVariableFlags( U8 u8Variable )
{
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
U8 u8Flags = m_auVariable[u8Variable].u8Flags;
osMutexRelease( m_pstMutexID ); // release mutex
return( u8Flags );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetVariableToInitData
// Description: Sets the variable to its initial data
// Parameters: U8 u8Variable
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetVariableToInitData( U8 u8Variable )
{
VARH_vSetVariableDataFromSystem( u8Variable, m_astVarInfo[u8Variable].uInitData );
}
//-------------------------------------------------------------------------------------------------
// Function: VARH_vSetAllVariablesToInitData
// Description: Sets all variables to its initial data
// Parameters: VARH_EnVariables enVariable
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID VARH_vSetAllVariablesToInitData( VOID )
{
for( U16 u16Var = 0; u16Var < VARH_eNumberOfVariables; u16Var++ )
{
VARH_vSetVariableToInitData( u16Var );
}
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: boBooleanVarCheck
// Description: Checks the range of a boolean
// Parameters: U32 u32NewValue
// Returns: TRUE, the variable can be written
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boBooleanVarCheck( U32 u32NewValue )
{
return( u32NewValue > 1 ? FALSE : TRUE );
}
//-------------------------------------------------------------------------------------------------
// Function: boU32VarCheck
// Description: Checks the range of a U32
// Parameters: U8 u8Variable
// U32 u32NewValue
// Returns: TRUE, the variable can be written
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boU32VarCheck( U8 u8Variable, U32 u32NewValue )
{
return( (m_astVarInfo[u8Variable].uMinData.u32Val <= u32NewValue) && (u32NewValue <= m_astVarInfo[u8Variable].uMaxData.u32Val) ? TRUE : FALSE );
}
//-------------------------------------------------------------------------------------------------
// Function: boS32VarCheck
// Description: Checks the range of a S32
// Parameters: U8 u8Variable
// S32 s32NewValue
// Returns: TRUE, the variable can be written
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boS32VarCheck( U8 u8Variable, S32 s32NewValue )
{
return( (m_astVarInfo[u8Variable].uMinData.s32Val <= s32NewValue) && (s32NewValue <= m_astVarInfo[u8Variable].uMaxData.s32Val) ? TRUE : FALSE );
}
//-------------------------------------------------------------------------------------------------
// Function: boFloatVarCheck
// Description: Checks the range of a Float
// Parameters: U8 u8Variable
// FLOAT flNewValue
// Returns: TRUE, the variable can be written
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boFloatVarCheck( U8 u8Variable, FLOAT flNewValue )
{
return( (m_astVarInfo[u8Variable].uMinData.flVal <= flNewValue) && (flNewValue <= m_astVarInfo[u8Variable].uMaxData.flVal) ? TRUE : FALSE );
}
//-------------------------------------------------------------------------------------------------
// Function: boCheckRange
// Description: Checks the range of the variable
// Parameters: U8 u8Variable
// VARH_UVariable uNewData
// Returns: TRUE, if the value is in the range, otherwise FALSE
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boCheckRange( U8 u8Variable, VARH_UVariable uNewData )
{
if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_FLOAT )
{
return( boFloatVarCheck(u8Variable, uNewData.flVal ) );
} else if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_SIGNED )
{
return( boS32VarCheck(u8Variable, uNewData.s32Val ) );
} else if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_BOOL )
{
return( boBooleanVarCheck( uNewData.s32Val ) );
} else
{
return( boU32VarCheck( u8Variable, uNewData.u32Val ) );
}
}

View File

@ -0,0 +1,173 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Variable Handler
// Filename: VARH_VariableHandler.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef VARH_VARIABLEHANDLER_H
#define VARH_VARIABLEHANDLER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
// Flags for variable
#define VARH_FLAG_VALID (1<<0) // is data valid
#define VARH_FLAG_OUTOFRANGE (1<<1) // is data out of range
#define VARH_FLAG_MODIFIED (1<<2) // is variable modified (compared to flash)
#define VARH_FLAG_FLASHCORRUPT (1<<3) // data from flash is corrupted
// Flags for variable infos
#define VARH_FLAGINFO_NONE 0 // no flag
#define VARH_FLAGINFO_FLOAT (1<<0) // variable in floating point format
#define VARH_FLAGINFO_SIGNED (1<<1) // variable is signed integer
#define VARH_FLAGINFO_BOOL (1<<2) // variable is boolean
#define VARH_FLAGINFO_READONLY (1<<3) // variable is readonly, master can not set variable
#define VARH_FLAGINFO_FLASH (1<<4) // variable is stored in flash
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
// variables
typedef enum
{
VARH_eMode = 0,
VARH_eControlVoltage = 1,
VARH_ePID_kp,
VARH_ePID_ki,
VARH_ePID_kd,
VARH_ePID_Temp,
VARH_ePID_Max,
VARH_ePID_Min,
VARH_eTemp_H,
VARH_eTemp_C,
VARH_eTemp_Diff,
VARH_ePeltier_U,
VARH_ePeltier_I,
VARH_ePeltier_R,
VARH_ePeltier_P,
VARH_eSupply_U,
VARH_eSupply_I,
VARH_eSupply_P,
VARH_ePowerState,
VARH_eNumberOfVariables, // Must be last entry
} VARH_EnVariables;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
#pragma pack(4)
typedef union {
FLOAT flVal;
U32 u32Val;
S32 s32Val;
} VARH_UVariable;
#pragma pack()
typedef struct
{
U8 u8Flags; // flags
VARH_UVariable uInitData; // initial Data (data is always 32 bit)
VARH_UVariable uMinData; // min Value for Data
VARH_UVariable uMaxData; // max Value for Data
} VARH_StVarInfo;
typedef struct
{
VARH_UVariable uData; // Data (data is always 32 bit)
U8 u8Flags; // flags
} VARH_StVar;
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: FUNCTION TYPES
// Description: Definition of functions
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL VARH_boInitializeModule( VOID );
// set data
VOID VARH_vSetVariableData( U8 u8Variable, VARH_UVariable uData );
VOID VARH_vSetVariableDataU32( U8 u8Variable, U32 u32Data );
VOID VARH_vSetVariableDataS32( U8 u8Variable, S32 s32Data );
VOID VARH_vSetVariableDataFloat( U8 u8Variable, FLOAT flData );
// set data from system
VOID VARH_vSetVariableDataFromSystem( U8 u8Variable, VARH_UVariable uData );
VOID VARH_vSetVariableDataFromSystemU32( U8 u8Variable, U32 u32Data );
VOID VARH_vSetVariableDataFromSystemS32( U8 u8Variable, S32 s32Data );
VOID VARH_vSetVariableDataFromSystemFloat( U8 u8Variable, FLOAT flData );
// get data
VARH_UVariable VARH_uGetVariableData( U8 u8Variable );
U32 VARH_u32GetVariableData( U8 u8Variable );
S32 VARH_s32GetVariableData( U8 u8Variable );
FLOAT VARH_flGetVariableData( U8 u8Variable );
U8 VARH_uGetVariableFlags( U8 u8Variable );
// reset data
VOID VARH_vSetVariableToInitData( U8 u8Variable );
VOID VARH_vSetAllVariablesToInitData( VOID );
#ifdef __cplusplus
}
#endif
#endif