Add VARH Files
This commit is contained in:
parent
167f69a9cc
commit
8672cb52c8
538
Core/Application/VARH_VariableHandler.c
Normal file
538
Core/Application/VARH_VariableHandler.c
Normal file
@ -0,0 +1,538 @@
|
|||||||
|
//=================================================================================================
|
||||||
|
//
|
||||||
|
// 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 variables
|
||||||
|
//
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Section: INCLUDES
|
||||||
|
// Description: List of required include files.
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
#include "../PDEF_ProjectDefinitions.h"
|
||||||
|
#include "VARH_VariableHandler.h"
|
||||||
|
|
||||||
|
// Toolbox
|
||||||
|
#include "../Toolbox/ASRT_Assert.h"
|
||||||
|
#include "../Toolbox/UTIL_Utility.h"
|
||||||
|
|
||||||
|
#include "cmsis_os2.h"
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Section: DEFINITIONS
|
||||||
|
// Description: Definition of local constants (visible by this module only).
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
// define the number of notifications according the need
|
||||||
|
#define NUMBER_OF_NOTIFICATOINS 1
|
||||||
|
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// 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).
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
VARH_pfnNotification pfnCallback;
|
||||||
|
PVOID pvArgument;
|
||||||
|
} StNotification;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
VARH_pfnRangeCheck pfnCallback;
|
||||||
|
PVOID pvArgument;
|
||||||
|
} StRangeCheck;
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Section: LOCAL VARIABLES
|
||||||
|
// Description: Definition of local variables (visible by this module only).
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
LOCAL VARH_UVariable m_auVariable[VARH_eNumberOfVariables];
|
||||||
|
LOCAL StNotification m_astNotifications[VARH_eNumberOfVariables][VARH_eNumberOfNotificationTypes][NUMBER_OF_NOTIFICATOINS] = { 0 };
|
||||||
|
LOCAL StRangeCheck m_astRangeCheck[VARH_eNumberOfVariables] = { 0 };
|
||||||
|
|
||||||
|
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] =
|
||||||
|
{
|
||||||
|
{"Status", VARH_FLAG_READONLY, VARH_eUnitByte, VARH_ePrefixNone, (VARH_UVariable)TRUE}, // VARH_eEnable,
|
||||||
|
|
||||||
|
{"VoltageRef En", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eSetMode,
|
||||||
|
|
||||||
|
{"Status G", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertA,
|
||||||
|
{"Status R", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertB,
|
||||||
|
{"Enabled G", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertA,
|
||||||
|
{"Enabled R", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertB,
|
||||||
|
{"Inverted G", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertA,
|
||||||
|
{"Inverted R", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertB,
|
||||||
|
{"Spare G", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertA,
|
||||||
|
{"Spare R", VARH_FLAG_NONE, VARH_eUnitBoolean, VARH_ePrefixNone, (VARH_UVariable)FALSE}, // VARH_eInvertB,
|
||||||
|
|
||||||
|
{"Temp HeatSink", VARH_FLAG_FLOAT | VARH_FLAG_READONLY, VARH_eUnitCelsius, VARH_ePrefixNone, (VARH_UVariable)0.0f}, // VARH_eTempCS,
|
||||||
|
{"Temp Shunt", VARH_FLAG_FLOAT | VARH_FLAG_READONLY, VARH_eUnitCelsius, VARH_ePrefixNone, (VARH_UVariable)0.0f}, // VARH_eTempRef,
|
||||||
|
{"Temp VoltageRef", VARH_FLAG_FLOAT | VARH_FLAG_READONLY, VARH_eUnitCelsius, VARH_ePrefixNone, (VARH_UVariable)0.0f}, // VARH_eTempShunt,
|
||||||
|
{"Temp CurrentSrc", VARH_FLAG_FLOAT | VARH_FLAG_READONLY, VARH_eUnitCelsius, VARH_ePrefixNone, (VARH_UVariable)0.0f}, // VARH_eTempShunt,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
PRIVATE VOID vSetVariablesToInitDataCallback( PVOID pvData );
|
||||||
|
|
||||||
|
PRIVATE VOID vCallNotifications( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData );
|
||||||
|
PRIVATE BOOL boCheckRange( U8 u8Variable, VARH_UVariable uNewData );
|
||||||
|
|
||||||
|
PRIVATE BOOL boRising( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData );
|
||||||
|
PRIVATE BOOL boFalling( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData );
|
||||||
|
PRIVATE BOOL boNewValue( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData );
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// 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( BOOL boInitConfig )
|
||||||
|
{
|
||||||
|
ASRT_STATIC_ASSERT( VARH_eNumberOfVariables <= 255 );
|
||||||
|
BOOL boOK = TRUE;
|
||||||
|
|
||||||
|
boOK &= ((m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
|
||||||
|
|
||||||
|
memset( &m_astNotifications, 0, sizeof(m_astNotifications) ); // reset the notifications
|
||||||
|
memset( &m_astRangeCheck, 0, sizeof(m_astRangeCheck) ); // reset the function pointers
|
||||||
|
|
||||||
|
if( boInitConfig )
|
||||||
|
{
|
||||||
|
VARH_vSetAllVariablesToInitData();
|
||||||
|
}
|
||||||
|
|
||||||
|
return( boOK );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_boRegisterNotification
|
||||||
|
// Description: Registers a notification to the specified variable
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// VARH_EnNotification enNotification
|
||||||
|
// VARH_pfnNotification pfnCallback
|
||||||
|
// PVOID pvCallbackArgument
|
||||||
|
// Returns: Boolean TRUE if register of Callback was successful, otherwise FALSE
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
BOOL VARH_boRegisterNotification( U8 u8Variable, VARH_EnNotification enNotification, VARH_pfnNotification pfnCallback, PVOID pvCallbackArgument )
|
||||||
|
{
|
||||||
|
// check parameters
|
||||||
|
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||||
|
if( enNotification >= VARH_eNumberOfNotificationTypes || pfnCallback == NULL)
|
||||||
|
{
|
||||||
|
return( FALSE );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for( U8 u8Notification = 0; u8Notification < NUMBER_OF_NOTIFICATOINS; u8Notification++ )
|
||||||
|
{
|
||||||
|
if( m_astNotifications[u8Variable][enNotification][u8Notification].pfnCallback == NULL )
|
||||||
|
{
|
||||||
|
m_astNotifications[u8Variable][enNotification][u8Notification].pfnCallback = pfnCallback;
|
||||||
|
m_astNotifications[u8Variable][enNotification][u8Notification].pvArgument = pvCallbackArgument;
|
||||||
|
return( TRUE );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return( FALSE ); // registration not successful
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_boRegisterRangeCheck
|
||||||
|
// Description: Registers the range check function
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// VARH_pfnRangeCheck pfnCallback
|
||||||
|
// PVOID pvCallbackArgument
|
||||||
|
// Returns: Boolean TRUE if register of Callback was successful, otherwise FALSE
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
BOOL VARH_boRegisterRangeCheck( U8 u8Variable, VARH_pfnRangeCheck pfnCallback, PVOID pvCallbackArgument )
|
||||||
|
{
|
||||||
|
if( m_astRangeCheck[u8Variable].pfnCallback == NULL )
|
||||||
|
{
|
||||||
|
m_astRangeCheck[u8Variable].pfnCallback = pfnCallback;
|
||||||
|
m_astRangeCheck[u8Variable].pvArgument = pvCallbackArgument;
|
||||||
|
return( TRUE );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_vSetVariableData
|
||||||
|
// Description: Sets the Variable Data
|
||||||
|
// Parameters: VARH_EnVariables enVariable
|
||||||
|
// VARH_UVariable uData
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
VOID VARH_vSetVariableData( U8 u8Variable, VARH_UVariable uData )
|
||||||
|
{
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
VARH_UVariable uOldValue = m_auVariable[u8Variable]; // remember old value
|
||||||
|
if( boCheckRange( u8Variable, uData ) ) { m_auVariable[u8Variable] = uData; } // store new value
|
||||||
|
vCallNotifications( u8Variable, uOldValue, m_auVariable[u8Variable] ); // call notifications
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_vSetBit
|
||||||
|
// Description: Sets the bit specified with the bitmask in the specified variable
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// U32 u32BitMask
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
VOID VARH_vSetBit( U8 u8Variable, U32 u32BitMask )
|
||||||
|
{
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
U32 u32Data = m_auVariable[u8Variable].u32Val; // read
|
||||||
|
UTIL_SET_BIT( &u32Data, u32BitMask ); // modify
|
||||||
|
VARH_vSetVariableData( u8Variable, (VARH_UVariable) u32Data ); // write
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_vClearBit
|
||||||
|
// Description: Clears the bit specified with the bitmask in the specified variable
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// U32 u32BitMask
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
VOID VARH_vClearBit( U8 u8Variable, U32 u32BitMask )
|
||||||
|
{
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
U32 u32Data = m_auVariable[u8Variable].u32Val; // read
|
||||||
|
UTIL_CLEAR_BIT( &u32Data, u32BitMask ); // modify
|
||||||
|
VARH_vSetVariableData( u8Variable, (VARH_UVariable) u32Data ); // write
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_u32GetBit
|
||||||
|
// Description: Gets the bits specified with the bitmask in the specified variable
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// U32 u32BitMask
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
U32 VARH_u32GetBit( U8 u8Variable, U32 u32BitMask )
|
||||||
|
{
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
U32 u32Ret = m_auVariable[u8Variable].u32Val & u32BitMask;
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
return( u32Ret );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_vIncrement
|
||||||
|
// Description: Increments the specifiend variable
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
VOID VARH_vIncrement( U8 u8Variable )
|
||||||
|
{
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
VARH_vSetVariableData( u8Variable, (VARH_UVariable) m_auVariable[u8Variable].u32Val++ );
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_vSetVariableDataFromClient
|
||||||
|
// Description: Sets the Variable Data from Client Protocol.
|
||||||
|
// Only use this function from Client interpreter
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// PVOID pvData
|
||||||
|
// SDEF_EnByteOrder enByteOrder
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
VOID VARH_vSetVariableDataFromClient( U8 u8Variable, VARH_UVariable uData )
|
||||||
|
{
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
|
||||||
|
// check parameters
|
||||||
|
if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAG_READONLY )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VARH_UVariable uOldValue = m_auVariable[u8Variable]; // remember old value
|
||||||
|
if( boCheckRange( u8Variable, uData ) ) { m_auVariable[u8Variable] = uData; } // store new value
|
||||||
|
vCallNotifications( u8Variable, uOldValue, m_auVariable[u8Variable] ); // call notifications
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_u32GetVariableData
|
||||||
|
// 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];
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
return( uVar );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_u32GetVariableDataFromMSCB
|
||||||
|
// Description: Gets the Variable Data from MSCB Protocol
|
||||||
|
// Only use this function from MSCB interpreter
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// PVOID pvData
|
||||||
|
// SDEF_EnByteOrder enByteOrder
|
||||||
|
// Returns: Number of elements copied
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
VARH_UVariable VARH_u32GetVariableDataFromClient( U8 u8Variable )
|
||||||
|
{
|
||||||
|
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
VARH_UVariable uVar = m_auVariable[u8Variable];
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
|
||||||
|
return( uVar );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_pstGetVariableInfo
|
||||||
|
// Description: Gets the Variable Info
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// Returns: VARH_StVarInfo*
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
CONST VARH_StVarInfo* VARH_pstGetVariableInfo( U8 u8Variable )
|
||||||
|
{
|
||||||
|
return( (CONST VARH_StVarInfo*)&m_astVarInfo[u8Variable] );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_vSetVariableToInitData
|
||||||
|
// Description: Sets the variable to its initial data
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
VOID VARH_vSetVariableToInitData( U8 u8Variable )
|
||||||
|
{
|
||||||
|
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||||
|
VARH_vSetVariableData( u8Variable, m_astVarInfo[u8Variable].uInitData );
|
||||||
|
osMutexRelease( m_pstMutexID ); // release mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_vGetNumberOfVariables
|
||||||
|
// Description: Gets the number of used variables
|
||||||
|
// Parameters: None
|
||||||
|
// Returns: U8 number of used variables
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
U8 VARH_u8GetNumberOfVariables( VOID )
|
||||||
|
{
|
||||||
|
return( VARH_eNumberOfVariables );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: VARH_boBooleanVarCheck
|
||||||
|
// Description: Checks the range of a boolean
|
||||||
|
// Parameters: PVOID pvCallbackData
|
||||||
|
// VARH_UVariable uNewValue
|
||||||
|
// Returns: TRUE, the variable can be written
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
BOOL VARH_boBooleanVarCheck( PVOID pvCallbackData, VARH_UVariable uNewValue )
|
||||||
|
{
|
||||||
|
UNUSED( pvCallbackData );
|
||||||
|
return( uNewValue.u32Val > 1 ? FALSE : TRUE );
|
||||||
|
}
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Section: LOCAL FUNCTIONS
|
||||||
|
// Descriptionn: Definition (implementation) of local functions.
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: vCallNotifications
|
||||||
|
// Description: Calls the notification callback functions
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// VARH_UVariable uOldData
|
||||||
|
// VARH_UVariable uNewData
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
PRIVATE VOID vCallNotifications( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData )
|
||||||
|
{
|
||||||
|
for( U8 u8Notification = 0; u8Notification < NUMBER_OF_NOTIFICATOINS; u8Notification++ )
|
||||||
|
{
|
||||||
|
if( m_astNotifications[u8Variable][VARH_eWrite][u8Notification].pfnCallback != NULL )
|
||||||
|
{
|
||||||
|
m_astNotifications[u8Variable][VARH_eWrite][u8Notification].pfnCallback( m_astNotifications[u8Variable][VARH_eWrite][u8Notification].pvArgument );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( boNewValue( u8Variable, uOldData, uNewData ) )
|
||||||
|
{
|
||||||
|
if( m_astNotifications[u8Variable][VARH_eNewValue][u8Notification].pfnCallback != NULL )
|
||||||
|
{
|
||||||
|
m_astNotifications[u8Variable][VARH_eNewValue][u8Notification].pfnCallback( m_astNotifications[u8Variable][VARH_eNewValue][u8Notification].pvArgument );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( boRising( u8Variable, uOldData, uNewData ) )
|
||||||
|
{
|
||||||
|
if( m_astNotifications[u8Variable][VARH_eRising][u8Notification].pfnCallback != NULL )
|
||||||
|
{
|
||||||
|
m_astNotifications[u8Variable][VARH_eRising][u8Notification].pfnCallback( m_astNotifications[u8Variable][VARH_eRising][u8Notification].pvArgument );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( boFalling( u8Variable, uOldData, uNewData ) )
|
||||||
|
{
|
||||||
|
if( m_astNotifications[u8Variable][VARH_eFalling][u8Notification].pfnCallback != NULL )
|
||||||
|
{
|
||||||
|
m_astNotifications[u8Variable][VARH_eFalling][u8Notification].pfnCallback( m_astNotifications[u8Variable][VARH_eFalling][u8Notification].pvArgument );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// 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_astRangeCheck[u8Variable].pfnCallback == NULL )
|
||||||
|
{
|
||||||
|
return( TRUE );
|
||||||
|
}
|
||||||
|
return( m_astRangeCheck[u8Variable].pfnCallback( m_astRangeCheck[u8Variable].pvArgument, uNewData ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: boRising
|
||||||
|
// Description: returns True, if there is a rising edge on this variable (only for boolean types)
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// VARH_UVariable uOldData
|
||||||
|
// VARH_UVariable uNewData
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
PRIVATE BOOL boRising( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData )
|
||||||
|
{
|
||||||
|
return( uOldData.u32Val == 0 && uNewData.u32Val == 1 ? TRUE : FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: boFalling
|
||||||
|
// Description: returns True, if there is a falling edge on this variable (only for boolean types)
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// VARH_UVariable uOldData
|
||||||
|
// VARH_UVariable uNewData
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
PRIVATE BOOL boFalling( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData )
|
||||||
|
{
|
||||||
|
return( uOldData.u32Val == 1 && uNewData.u32Val == 0 ? TRUE : FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: boNewValue
|
||||||
|
// Description: returns True, if there is a new value for this variable
|
||||||
|
// Parameters: U8 u8Variable
|
||||||
|
// VARH_UVariable uOldData
|
||||||
|
// VARH_UVariable uNewData
|
||||||
|
// Returns: None
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
PRIVATE BOOL boNewValue( U8 u8Variable, VARH_UVariable uOldData, VARH_UVariable uNewData )
|
||||||
|
{
|
||||||
|
UNUSED( u8Variable );
|
||||||
|
return( uNewData.u32Val != uOldData.u32Val ? TRUE : FALSE);
|
||||||
|
}
|
243
Core/Application/VARH_VariableHandler.h
Normal file
243
Core/Application/VARH_VariableHandler.h
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
//=================================================================================================
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
#define VARH_FLAG_NONE 0 // no flag
|
||||||
|
#define VARH_FLAG_FLOAT (1<<0) // channel in floating point format
|
||||||
|
#define VARH_FLAG_SIGNED (1<<1) // channel is signed integer
|
||||||
|
#define VARH_FLAG_DATALESS (1<<2) // channel doesn't contain data; displayed on the host, but not writable
|
||||||
|
#define VARH_FLAG_HIDDEN (1<<3) // used for internal config parameters; not displayed on the host pc, but writable
|
||||||
|
#define VARH_FLAG_REMIN (1<<4) // get variable from remote node on subbus
|
||||||
|
#define VARH_FLAG_REMOUT (1<<5) // send variable to remote node on subbus
|
||||||
|
#define VARH_FLAG_READONLY (1<<7) // variable is readonly, host can not set variable
|
||||||
|
|
||||||
|
#define VARH_HV_MAX (300.0f)
|
||||||
|
#define VARH_I_MAX (1000.0f)
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Section: MACROS
|
||||||
|
// Description: Definition of global macros (visible by all modules).
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Section: ENUMERATIONS
|
||||||
|
// Description: Definition of global enumerations (visible by all modules).
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
// Units
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
// physical units
|
||||||
|
VARH_eUnitUndefined = 0, // 00 Undefined unit
|
||||||
|
VARH_eUnitMeter = 1, // 01 Meter
|
||||||
|
VARH_eUnitGram = 2, // 02 Gram
|
||||||
|
VARH_eUnitSecond = 3, // 03 Second
|
||||||
|
VARH_eUnitMinute = 4, // 04 Minute
|
||||||
|
VARH_eUnitHour = 5, // 05 Hour
|
||||||
|
VARH_eUnitAmpere = 6, // 06 Ampere
|
||||||
|
VARH_eUnitKelvin = 7, // 07 Kelvin
|
||||||
|
VARH_eUnitCelsius = 8, // 08 Celsius
|
||||||
|
VARH_eUnitFarenheit = 9, // 09 Farenheit
|
||||||
|
|
||||||
|
// SI base units
|
||||||
|
VARH_eUnitHertz = 20, // 20 Hertz
|
||||||
|
VARH_eUnitPascal = 21, // 21 Pascal
|
||||||
|
VARH_eUnitBar = 22, // 22 Bar
|
||||||
|
VARH_eUnitWatt = 23, // 23 Watt
|
||||||
|
VARH_eUnitVolt = 24, // 24 Volt
|
||||||
|
VARH_eUnitOhm = 25, // 25 Ohm
|
||||||
|
VARH_eUnitTesla = 26, // 26 Tesla
|
||||||
|
VARH_eUnitLiterPerSec = 27, // 27 Liter per second
|
||||||
|
VARH_eUnitRPM = 28, // 28 Rounds per minute
|
||||||
|
VARH_eUnitFarad = 29, // 29 Farad
|
||||||
|
VARH_eUnitJoule = 30, // 30 Joule
|
||||||
|
|
||||||
|
// computer units
|
||||||
|
VARH_eUnitBoolean = 50, // 50 Boolean
|
||||||
|
VARH_eUnitByte = 52, // 52 Byte
|
||||||
|
VARH_eUnitWord = 53, // 53 Word (16Bit)
|
||||||
|
VARH_eUnitDoubleWord = 54, // 54 Double Word (32Bit)
|
||||||
|
VARH_eUnitASCII = 55, // 55 ASCII character
|
||||||
|
VARH_eUnitString = 56, // 56 String
|
||||||
|
VARH_eUnitBaud = 57, // 57 Baud
|
||||||
|
|
||||||
|
// others
|
||||||
|
VARH_eUnitPercent = 90, // 90 Percent
|
||||||
|
VARH_eUnitPPM = 91, // 91 Parts per million
|
||||||
|
VARH_eUnitCount = 92, // 92 Count
|
||||||
|
VARH_eUnitFactor = 93, // 93 Factor
|
||||||
|
|
||||||
|
} VARH_EnUnit;
|
||||||
|
|
||||||
|
// Prefix
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
VARH_ePrefixPico = -12,
|
||||||
|
VARH_ePrefixNano = -9,
|
||||||
|
VARH_ePrefixMicro = -6,
|
||||||
|
VARH_ePrefixMilli = -3,
|
||||||
|
VARH_ePrefixNone = 0,
|
||||||
|
VARH_ePrefixKilo = 3,
|
||||||
|
VARH_ePrefixMega = 6,
|
||||||
|
VARH_ePrefixGiga = 9,
|
||||||
|
VARH_ePrefixTera = 12,
|
||||||
|
} VARH_EnPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
VARH_eWrite = 0,
|
||||||
|
VARH_eNewValue,
|
||||||
|
VARH_eRising,
|
||||||
|
VARH_eFalling,
|
||||||
|
|
||||||
|
VARH_eNumberOfNotificationTypes,
|
||||||
|
} VARH_EnNotification;
|
||||||
|
|
||||||
|
|
||||||
|
// variables
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
VARH_eStatus,
|
||||||
|
|
||||||
|
VARH_eVoltageRefEn,
|
||||||
|
|
||||||
|
VARH_eStatusG,
|
||||||
|
VARH_eStatusR,
|
||||||
|
VARH_eEnabledG,
|
||||||
|
VARH_eEnabledR,
|
||||||
|
VARH_eInvertedG,
|
||||||
|
VARH_eInvertedR,
|
||||||
|
VARH_eSpareG,
|
||||||
|
VARH_eSpareR,
|
||||||
|
|
||||||
|
VARH_eTempHeatSink,
|
||||||
|
VARH_eTempShunt,
|
||||||
|
VARH_eTempVoltageRef,
|
||||||
|
VARH_eTempCurrentSrc,
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
CHAR acName[16]; // name
|
||||||
|
U8 u8Flags; // flags
|
||||||
|
VARH_EnUnit eUnit; // unit
|
||||||
|
VARH_EnPrefix ePrefix; // prefix
|
||||||
|
VARH_UVariable uInitData; // initial Data (data is always 32 bit, at least internal)
|
||||||
|
} VARH_StVarInfo;
|
||||||
|
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// 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
|
||||||
|
//=================================================================================================
|
||||||
|
typedef VOID (*VARH_pfnNotification)( PVOID pvData );
|
||||||
|
typedef BOOL (*VARH_pfnRangeCheck)( PVOID pvCallbackData, VARH_UVariable uNewValue );
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||||
|
// Description: Definition of global functions (visible by all modules).
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
BOOL VARH_boInitializeModule( BOOL boInitConfig );
|
||||||
|
BOOL VARH_boRegisterNotification( U8 u8Variable, VARH_EnNotification enNotification, VARH_pfnNotification pfnCallback, PVOID pvCallbackArgument );
|
||||||
|
BOOL VARH_boRegisterRangeCheck( U8 u8Variable, VARH_pfnRangeCheck pfnCallback, PVOID pvCallbackArgument );
|
||||||
|
|
||||||
|
// set data functions
|
||||||
|
VOID VARH_vSetVariableData( U8 u8Variable, VARH_UVariable uData );
|
||||||
|
VOID VARH_vSetBit( U8 u8Variable, U32 u32BitMask );
|
||||||
|
U32 VARH_u32GetBit( U8 u8Variable, U32 u32BitMask );
|
||||||
|
VOID VARH_vClearBit( U8 u8Variable, U32 u32BitMask );
|
||||||
|
VOID VARH_vIncrement( U8 u8Variable );
|
||||||
|
VOID VARH_vSetVariableDataFromClient( U8 u8Variable, VARH_UVariable uData );
|
||||||
|
|
||||||
|
// get data function
|
||||||
|
VARH_UVariable VARH_uGetVariableData( U8 u8Variable );
|
||||||
|
VARH_UVariable VARH_u32GetVariableDataFromClient( U8 u8Variable );
|
||||||
|
|
||||||
|
// check functions
|
||||||
|
BOOL VARH_boBooleanVarCheck( PVOID pvCallbackData, VARH_UVariable uNewValue );
|
||||||
|
|
||||||
|
CONST VARH_StVarInfo* VARH_pstGetVariableInfo( U8 u8Variable );
|
||||||
|
VOID VARH_vSetVariableToInitData( U8 u8Variable );
|
||||||
|
VOID VARH_vSetAllVariablesToInitData( VOID );
|
||||||
|
|
||||||
|
U8 VARH_u8GetNumberOfVariables( VOID );
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user