Update Header

This commit is contained in:
pique_n 2021-10-27 07:53:23 +02:00
parent 6b7bb4593e
commit e15e692e89
5 changed files with 727 additions and 729 deletions

View File

@ -167,7 +167,8 @@ PRIVATE VOID vInitTask( PVOID arg )
// boOK &= RTOS_boInitializeModule(); // boOK &= RTOS_boInitializeModule();
boOK &= DIPO_boInitializeModule(); boOK &= DIPO_boInitializeModule();
boOK &= ANPI_boInitializeModule();
boOK &= ANPI_boInitializeModule();
boOK &= ANPO_boInitializeModule(); boOK &= ANPO_boInitializeModule();
boOK &= SPID_boInitializeModule(); boOK &= SPID_boInitializeModule();

View File

@ -7,7 +7,7 @@
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Project: Peltier Controller V2 // Project: Peltier Controller V2
// Author: Noah Piqu<EFBFBD> (noah.pique@psi.ch) // Author: Noah Piqué (noah.pique@psi.ch)
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //

View File

@ -1,90 +1,90 @@
//================================================================================================= //=================================================================================================
// //
// Company: Paul Scherrer Institut // Company: Paul Scherrer Institut
// 5232 Villigen PSI // 5232 Villigen PSI
// Switzerland // Switzerland
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Project: Peltier Controller V2 // Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch) // Author: Noah Piqué (noah.pique@psi.ch)
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Module: Temperature // Module: Temperature
// Filename: TEMP_Temperature.h // Filename: TEMP_Temperature.h
// Date: Handled by Subversion (version control system) // Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system) // Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system) // History: Handled by Subversion (version control system)
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
#ifndef TEMP_TEMPERATURE_H #ifndef TEMP_TEMPERATURE_H
#define TEMP_TEMPERATURE_H #define TEMP_TEMPERATURE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
//================================================================================================= //=================================================================================================
// Section: INCLUDES // Section: INCLUDES
// Description: List of required include files (visible by all modules). // Description: List of required include files (visible by all modules).
//================================================================================================= //=================================================================================================
#include "../SDEF_StandardDefinitions.h" #include "../SDEF_StandardDefinitions.h"
#include "ADCD_AdcDriver.h" #include "ADCD_AdcDriver.h"
//================================================================================================= //=================================================================================================
// Section: DEFINITIONS // Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules). // Description: Definition of global constants (visible by all modules).
//================================================================================================= //=================================================================================================
//typedef VOID (*TEMP_pfnEventCallback)( PVOID pvData ); //typedef VOID (*TEMP_pfnEventCallback)( PVOID pvData );
//================================================================================================= //=================================================================================================
// Section: MACROS // Section: MACROS
// Description: Definition of global macros (visible by all modules). // Description: Definition of global macros (visible by all modules).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: ENUMERATIONS // Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules). // Description: Definition of global enumerations (visible by all modules).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: STRUCTURES // Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules). // Description: Definition of global Structures (visible by all modules).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: GLOBAL VARIABLES // Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules). // Description: Definition of global variables (visible by all modules).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: GLOBAL CONSTANTS // Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules). // Description: Definition of global constants (visible by all modules).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES) // Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules). // Description: Definition of global functions (visible by all modules).
//================================================================================================= //=================================================================================================
BOOL TEMP_boInitializeModule( VOID ); BOOL TEMP_boInitializeModule( VOID );
//BOOL TEMP_boRegisterEventNotification( TEMP_pfnEventCallback pfnCallback, PVOID pvCallbackArgument ); //BOOL TEMP_boRegisterEventNotification( TEMP_pfnEventCallback pfnCallback, PVOID pvCallbackArgument );
FLOAT TEMP_dGetValue( ADCD_EnTemps enTemp ); FLOAT TEMP_dGetValue( ADCD_EnTemps enTemp );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@ -1,432 +1,432 @@
//================================================================================================= //=================================================================================================
// //
// Company: Paul Scherrer Institut // Company: Paul Scherrer Institut
// 5232 Villigen PSI // 5232 Villigen PSI
// Switzerland // Switzerland
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Project: High Stability Current Source // Project: Peltier Controller V3
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch) // Author: Noah Piqué (noah.pique@psi.ch)
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Module: Utility // Module: Utility
// Filename: "UTIL_Utility.h".c // Filename: UTIL_Utility.c
// Date: Handled by Subversion (version control system) // Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system) // Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system) // History: Handled by Subversion (version control system)
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Description: Source file utility // Description: This source file contains a few utility functions
// //
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: INCLUDES // Section: INCLUDES
// Description: List of required include files. // Description: List of required include files.
//================================================================================================= //=================================================================================================
#include "UTIL_Utility.h" #include "UTIL_Utility.h"
//================================================================================================= //=================================================================================================
// Section: DEFINITIONS // Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only). // Description: Definition of local constants (visible by this module only).
//================================================================================================= //=================================================================================================
// defines the registers for the debug printf via trace // defines the registers for the debug printf via trace
#define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
#define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n))) #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n))) #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
#define DEMCR (*((volatile unsigned long *)(0xE000EDFC))) #define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
#define TRCENA 0x01000000 #define TRCENA 0x01000000
#define DBGMCU_IDCOE 0xE0042000 #define DBGMCU_IDCOE 0xE0042000
//================================================================================================= //=================================================================================================
// Section: MACROS // Section: MACROS
// Description: Definition of local macros (visible by this module only). // Description: Definition of local macros (visible by this module only).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: ENUMERATIONS // Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only). // Description: Definition of local enumerations (visible by this module only).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: STRUCTURES // Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only). // Description: Definition of local Structures (visible by this module only).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: LOCAL VARIABLES // Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only). // Description: Definition of local variables (visible by this module only).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: LOCAL CONSTANTS // Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only). // Description: Definition of local constants (visible by this module only).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES) // Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only). // Description: Definition of local functions (visible by this module only).
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: EXTERNAL FUNCTIONS // Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions. // Description: Definition of external (global) functions.
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: EXTERNAL VARIABLES // Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables. // Description: Definition of external (global) variables.
//================================================================================================= //=================================================================================================
//================================================================================================= //=================================================================================================
// Section: GLOBAL FUNCTIONS // Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions. // Description: Definition (implementation) of global functions.
//================================================================================================= //=================================================================================================
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u16StringLength // Function: UTIL_u16StringLength
// Description: Returns the length of the string without zero termination // Description: Returns the length of the string without zero termination
// Parameters: PSZ pszString // Parameters: PSZ pszString
// Returns: U16, string length // Returns: U16, string length
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U16 UTIL_u16StringLength( PSZ pszString ) U16 UTIL_u16StringLength( PSZ pszString )
{ {
U16 u16Cnt = 0; U16 u16Cnt = 0;
while( *pszString++ != '\0' ) while( *pszString++ != '\0' )
{ {
u16Cnt++; u16Cnt++;
} }
return( u16Cnt ); return( u16Cnt );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u16CheckStringLength // Function: UTIL_u16CheckStringLength
// Description: Returns TRUE, if the string leght (withouth zero termination) is less or equal the u16MaxLength // Description: Returns TRUE, if the string leght (withouth zero termination) is less or equal the u16MaxLength
// Parameters: PSZ pszString // Parameters: PSZ pszString
// U16 u16MaxLength // U16 u16MaxLength
// Returns: U16, string length // Returns: U16, string length
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength ) BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength )
{ {
while( *pszString++ != '\0' ) while( *pszString++ != '\0' )
{ {
if( u16MaxLength == 0 ) if( u16MaxLength == 0 )
{ {
return( FALSE ); return( FALSE );
} }
u16MaxLength--; u16MaxLength--;
} }
return( TRUE ); return( TRUE );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_vPuts // Function: UTIL_vPuts
// Description: Prints a string // Description: Prints a string
// Parameters: PSZ pszString // Parameters: PSZ pszString
// Returns: None // Returns: None
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
VOID UTIL_vPuts( PSZ pszString ) VOID UTIL_vPuts( PSZ pszString )
{ {
while( *pszString != '\0' ) while( *pszString != '\0' )
{ {
putchar( *pszString++ ); putchar( *pszString++ );
} }
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u8FindMajority // Function: UTIL_u8FindMajority
// Description: Finds the majority element of a given data set // Description: Finds the majority element of a given data set
// Parameters: PU8 pu8Data // Parameters: PU8 pu8Data
// U16 u16Length // U16 u16Length
// Returns: U8 // Returns: U8
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length ) U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length )
{ {
U32 u32MaxCount = 0; U32 u32MaxCount = 0;
S32 s32Index = -1; S32 s32Index = -1;
for( U32 i = 0; i < u16Length; i++) for( U32 i = 0; i < u16Length; i++)
{ {
U32 u32Count = 0; U32 u32Count = 0;
for( int j = 0; j < u16Length; j++ ) for( int j = 0; j < u16Length; j++ )
{ {
if(pu8Data[i] == pu8Data[j]) if(pu8Data[i] == pu8Data[j])
u32Count++; u32Count++;
} }
// update maxCount if count of // update maxCount if count of
// current element is greater // current element is greater
if( u32Count > u32MaxCount ) if( u32Count > u32MaxCount )
{ {
u32MaxCount = u32Count; u32MaxCount = u32Count;
s32Index = i; s32Index = i;
} }
} }
// if maxCount is greater than n/2 // if maxCount is greater than n/2
// return the corresponding element // return the corresponding element
if( u32MaxCount > u16Length/2 && s32Index >= 0 ) if( u32MaxCount > u16Length/2 && s32Index >= 0 )
{ {
return( pu8Data[s32Index] ); return( pu8Data[s32Index] );
} }
else else
{ {
return( 0 ); return( 0 );
} }
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_vMemCopy // Function: UTIL_vMemCopy
// Description: Copies a set of data. // Description: Copies a set of data.
// Parameters: PVOID pvSource pointer to the source data // Parameters: PVOID pvSource pointer to the source data
// VOID pvDest pointer destination data // VOID pvDest pointer destination data
// U16 u16Length number of bytes to copy // U16 u16Length number of bytes to copy
// Returns: None // Returns: None
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length ) VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length )
{ {
// use memcpy for better performance // use memcpy for better performance
memcpy( pvDest, pvSource, u16Length ); memcpy( pvDest, pvSource, u16Length );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u32MemCopy // Function: UTIL_u32MemCopy
// Description: Copies a set of data. // Description: Copies a set of data.
// Parameters: PVOID pvSource pointer to the source data // Parameters: PVOID pvSource pointer to the source data
// PVOID pvDest pointer destination data // PVOID pvDest pointer destination data
// U16 u16Length number of bytes to copy // U16 u16Length number of bytes to copy
// SDEF_EnByteOrder enByteOrder byte order // SDEF_EnByteOrder enByteOrder byte order
// Returns: U32 Number of Bytes copied // Returns: U32 Number of Bytes copied
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder ) U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder )
{ {
if( enByteOrder == SDEF_eNormalByteOrder ) if( enByteOrder == SDEF_eNormalByteOrder )
{ {
UTIL_vMemCopy( pvSource, pvDest, u16Length ); UTIL_vMemCopy( pvSource, pvDest, u16Length );
} }
else else
{ {
// copy the bytes in reverse order // copy the bytes in reverse order
PU8 pu8Source = pvSource; PU8 pu8Source = pvSource;
PU8 pu8Dest = pvDest; PU8 pu8Dest = pvDest;
for( U16 u16Cnt = 0; u16Cnt < (u16Length+1)/2; u16Cnt++ ) for( U16 u16Cnt = 0; u16Cnt < (u16Length+1)/2; u16Cnt++ )
{ {
pu8Dest[u16Cnt] = pu8Source[u16Length - 1 - u16Cnt]; pu8Dest[u16Cnt] = pu8Source[u16Length - 1 - u16Cnt];
pu8Dest[u16Length - 1 - u16Cnt] = pu8Source[u16Cnt]; pu8Dest[u16Length - 1 - u16Cnt] = pu8Source[u16Cnt];
} }
} }
return( u16Length ); return( u16Length );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_vMemCopyU32 // Function: UTIL_vMemCopyU32
// Description: Copies a set of four byte data types. // Description: Copies a set of four byte data types.
// Parameters: PU32 pu32Source pointer to the source data // Parameters: PU32 pu32Source pointer to the source data
// PU32 pu32Dest pointer destination data // PU32 pu32Dest pointer destination data
// U16 u16Length number of bytes to copy // U16 u16Length number of bytes to copy
// Returns: None // Returns: None
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length ) VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length )
{ {
while( u16Length-- > 0 ) while( u16Length-- > 0 )
{ {
*pu32Dest++ = *pu32Source++; *pu32Dest++ = *pu32Source++;
} }
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_boMemCompare // Function: UTIL_boMemCompare
// Description: Compares a set of data to equality // Description: Compares a set of data to equality
// Parameters: PU8 pu8Data1 pointer to first data set // Parameters: PU8 pu8Data1 pointer to first data set
// PU8 pu8Data2 pointer to second data set // PU8 pu8Data2 pointer to second data set
// U32 u32Length number of bytes to compare // U32 u32Length number of bytes to compare
// Returns: BOOL TRUE, if compared data is equal, otherwise FALSE // Returns: BOOL TRUE, if compared data is equal, otherwise FALSE
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length ) BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length )
{ {
while( u32Length-- > 0 ) while( u32Length-- > 0 )
{ {
if( *pu8Data1++ != *pu8Data2++ ) if( *pu8Data1++ != *pu8Data2++ )
{ {
return( FALSE ); return( FALSE );
} }
} }
return( TRUE ); return( TRUE );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_boMemCompareVal // Function: UTIL_boMemCompareVal
// Description: Compares if the all the data has the value specifed with u8Value. // Description: Compares if the all the data has the value specifed with u8Value.
// Parameters: PU8 pu8Data pointer to data set // Parameters: PU8 pu8Data pointer to data set
// U8 u8Value value to compare // U8 u8Value value to compare
// U32 u32Length number of bytes to compare // U32 u32Length number of bytes to compare
// Returns: BOOL TRUE, if compared data is equal, otherwise FALSE // Returns: BOOL TRUE, if compared data is equal, otherwise FALSE
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
BOOL UTIL_boMemCompareVal( PU8 pu8Data, U8 u8Value, U32 u32Length ) BOOL UTIL_boMemCompareVal( PU8 pu8Data, U8 u8Value, U32 u32Length )
{ {
while( u32Length-- > 0 ) while( u32Length-- > 0 )
{ {
if( *pu8Data != u8Value) if( *pu8Data != u8Value)
{ {
return( FALSE ); return( FALSE );
} }
pu8Data++; pu8Data++;
} }
return( TRUE ); return( TRUE );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u8DecToBCD // Function: UTIL_u8DecToBCD
// Description: Converts decimal encoded byte to bcd value // Description: Converts decimal encoded byte to bcd value
// Parameters: decimal value to convert to bcd // Parameters: decimal value to convert to bcd
// Returns: None // Returns: None
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U8 UTIL_u8DecToBCD( U8 u8Value ) U8 UTIL_u8DecToBCD( U8 u8Value )
{ {
return ( (u8Value/10*16) + (u8Value%10) ); return ( (u8Value/10*16) + (u8Value%10) );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u8BCDToDec // Function: UTIL_u8BCDToDec
// Description: Converts bcd to decimal // Description: Converts bcd to decimal
// Parameters: bcd value to convert to decimal // Parameters: bcd value to convert to decimal
// Returns: None // Returns: None
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U8 UTIL_u8BCDToDec( U8 u8Value ) U8 UTIL_u8BCDToDec( U8 u8Value )
{ {
return ( (u8Value/16*10) + (u8Value%16) ); return ( (u8Value/16*10) + (u8Value%16) );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_vReverseBytes // Function: UTIL_vReverseBytes
// Description: Reverses the byte order // Description: Reverses the byte order
// Parameters: PU8 pu8Data data // Parameters: PU8 pu8Data data
// U16 u16NumberOfBytes number of bytes // U16 u16NumberOfBytes number of bytes
// Returns: None // Returns: None
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes ) VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes )
{ {
U8 u8Tmp; U8 u8Tmp;
for( U16 u16Cnt = 0; u16Cnt < u16NumberOfBytes/2; u16Cnt++ ) for( U16 u16Cnt = 0; u16Cnt < u16NumberOfBytes/2; u16Cnt++ )
{ {
u8Tmp = pu8Data[u16Cnt]; u8Tmp = pu8Data[u16Cnt];
pu8Data[u16Cnt] = pu8Data[u16NumberOfBytes - 1 - u16Cnt]; pu8Data[u16Cnt] = pu8Data[u16NumberOfBytes - 1 - u16Cnt];
pu8Data[u16NumberOfBytes - 1 - u16Cnt] = u8Tmp; pu8Data[u16NumberOfBytes - 1 - u16Cnt] = u8Tmp;
} }
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u32RevU32 // Function: UTIL_u32RevU32
// Description: Reverses the bytes of an U32 // Description: Reverses the bytes of an U32
// Parameters: U32 u32Data // Parameters: U32 u32Data
// Returns: U32 reversed data // Returns: U32 reversed data
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U32 UTIL_u32RevU32( U32 u32Data ) U32 UTIL_u32RevU32( U32 u32Data )
{ {
return( __REV(u32Data) ); return( __REV(u32Data) );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u32RevFLOAT // Function: UTIL_u32RevFLOAT
// Description: Reverses the bytes of an FLOAT // Description: Reverses the bytes of an FLOAT
// Parameters: FLOAT flData // Parameters: FLOAT flData
// Returns: U32 reversed data // Returns: U32 reversed data
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U32 UTIL_u32RevFLOAT( FLOAT flData ) U32 UTIL_u32RevFLOAT( FLOAT flData )
{ {
U32 u32Data = *(PU32)&flData; U32 u32Data = *(PU32)&flData;
return( __REV(u32Data) ); return( __REV(u32Data) );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_u16RevU16 // Function: UTIL_u16RevU16
// Description: Reverses the bytes of an U16 // Description: Reverses the bytes of an U16
// Parameters: U16 u16Data // Parameters: U16 u16Data
// Returns: U16 reversed data // Returns: U16 reversed data
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
U16 UTIL_u16RevU16( U16 u16Data ) U16 UTIL_u16RevU16( U16 u16Data )
{ {
return( (U16)__REV16(u16Data) ); return( (U16)__REV16(u16Data) );
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: UTIL_cGetDeviceRevision // Function: UTIL_cGetDeviceRevision
// Description: Gets the silicon revision of the STM32F437 // Description: Gets the silicon revision of the STM32F437
// Parameters: None // Parameters: None
// Returns: CHAR // Returns: CHAR
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
CHAR UTIL_cGetDeviceRevision( VOID ) CHAR UTIL_cGetDeviceRevision( VOID )
{ {
U16 u16DeviceID = (*(PU32)DBGMCU_IDCOE) >> 16; U16 u16DeviceID = (*(PU32)DBGMCU_IDCOE) >> 16;
switch( u16DeviceID ) switch( u16DeviceID )
{ {
case 0x100: case 0x100:
return( 'A' ); return( 'A' );
case 0x1001: case 0x1001:
return( 'Z' ); return( 'Z' );
case 0x1003: case 0x1003:
return( 'Y' ); return( 'Y' );
case 0x1007: case 0x1007:
return( '1' ); return( '1' );
case 0x2001: case 0x2001:
return( '3' ); return( '3' );
default: default:
return( '0' ); return( '0' );
} }
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// Function: fputc // Function: fputc
// Description: Prototype for printf // Description: Prototype for printf
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
int fputc( int ch, FILE *f ) int fputc( int ch, FILE *f )
{ {
UNUSED( f ); // file stream not used UNUSED( f ); // file stream not used
if( DEMCR & TRCENA ) if( DEMCR & TRCENA )
{ {
while( ITM_Port32(0) == 0 ); while( ITM_Port32(0) == 0 );
ITM_Port8(0) = (U8)ch; ITM_Port8(0) = (U8)ch;
} }
return( ch ); return( ch );
} }
//================================================================================================= //=================================================================================================
// Section: LOCAL FUNCTIONS // Section: LOCAL FUNCTIONS
// Description: Definition (implementation) of local functions. // Description: Definition (implementation) of local functions.
//================================================================================================= //=================================================================================================

View File

@ -1,205 +1,202 @@
//================================================================================================= //=================================================================================================
// //
// Company: Paul Scherrer Institut // Company: Paul Scherrer Institut
// 5232 Villigen PSI // 5232 Villigen PSI
// Switzerland // Switzerland
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Project: High Stability Current Source // Project: Peltier Controller V3
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch) // Author: Noah Piqué (noah.pique@psi.ch)
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// //
// Module: Utility // Module: Utility
// Filename: UTIL_Utility.h // Filename: UTIL_Utility.h
// Date: Handled by Subversion (version control system) // Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system) // Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system) // History: Handled by Subversion (version control system)
// //
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
//
// Description: Header file utility
// #ifndef UTIL_UTILITY_H
//================================================================================================= #define UTIL_UTILITY_H
#ifndef UTIL_UTILITY_H #ifdef __cplusplus
#define UTIL_UTILITY_H extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//================================================================================================= //=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules). #include "string.h"
//================================================================================================= #include "stdio.h"
#include "../SDEF_StandardDefinitions.h"
#include "string.h"
#include "stdio.h" // include STM32 drivers
#include "../SDEF_StandardDefinitions.h" #include "stm32l4xx_hal.h"
// include STM32 drivers //=================================================================================================
#include "stm32l4xx_hal.h" // Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//================================================================================================= //=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//================================================================================================= //=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules). //macro for filename without path
//================================================================================================= //#define _FILE_ ((PSZ)(strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : \
// (strrchr(__FILE__, '\\') ? (strrchr(__FILE__, '\\') + 1) : __FILE__)))
//macro for filename without path
//#define _FILE_ ((PSZ)(strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : \ #define _FILE_ __FILE__
// (strrchr(__FILE__, '\\') ? (strrchr(__FILE__, '\\') + 1) : __FILE__)))
#define _LINE_ __LINE__
#define _FILE_ __FILE__
//checks if a pointer is valid
#define _LINE_ __LINE__ #define UTIL_IS_FUNC( pfnFoo ) ( pfnFoo != NULL )
//checks if a pointer is valid #define UTIL_32BitAlign( u32Address ) ((((U32)((u32Address)+4UL)/4UL))*4UL)
#define UTIL_IS_FUNC( pfnFoo ) ( pfnFoo != NULL )
#define UTIL_IS_POWER_OF_TWO( u32Numb ) ((u32Numb & (u32Numb - 1)) == 0)
#define UTIL_32BitAlign( u32Address ) ((((U32)((u32Address)+4UL)/4UL))*4UL)
#define UTIL_u16ConcatenateBytes( u8UpperByte, u8LowerByte) ( (U16)((U16)u8UpperByte << 8) | (U16)u8LowerByte )
#define UTIL_IS_POWER_OF_TWO( u32Numb ) ((u32Numb & (u32Numb - 1)) == 0)
// approx delay of 1us
#define UTIL_u16ConcatenateBytes( u8UpperByte, u8LowerByte) ( (U16)((U16)u8UpperByte << 8) | (U16)u8LowerByte ) #define DELAY_US( u32Us ) do{\
for( U32 u32Cnt = (SystemCoreClock >> 24U) * (u32Us); u32Cnt > 0U; u32Cnt-- ) \
// approx delay of 1us { \
#define DELAY_US( u32Us ) do{\ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
for( U32 u32Cnt = (SystemCoreClock >> 24U) * (u32Us); u32Cnt > 0U; u32Cnt-- ) \ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
{ \ }\
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \ }while(0)
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
}\ #define DELAY_MS( u32Ms ) do{\
}while(0) for( U32 u32Cnt = (SystemCoreClock >> 14U) * (u32Ms); u32Cnt > 0U; u32Cnt-- ) \
{ \
#define DELAY_MS( u32Ms ) do{\ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\
for( U32 u32Cnt = (SystemCoreClock >> 14U) * (u32Ms); u32Cnt > 0U; u32Cnt-- ) \ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\
{ \ }\
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\ }while(0)
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\
}\
}while(0) #ifndef UNUSED
#define UNUSED(x) ((void)(x))
#endif
#ifndef UNUSED
#define UNUSED(x) ((void)(x)) #define UTIL_SET_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add |= (u32BitMask) )
#endif #define UTIL_CLEAR_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add &= ~(u32BitMask) )
#define UTIL_SET_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add |= (u32BitMask) ) #define UTIL_DEFINE_CRITICAL() U32 u32PRIMASK
#define UTIL_CLEAR_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add &= ~(u32BitMask) )
// Enter Critical:
#define UTIL_DEFINE_CRITICAL() U32 u32PRIMASK // implements a memory barrier to ensure memory operations completed before
// stores the interrupt status register
// Enter Critical: // disables interrupts
// implements a memory barrier to ensure memory operations completed before #define UTIL_ENTER_CRITICAL() do{ \
// stores the interrupt status register __DMB(); \
// disables interrupts u32PRIMASK = __get_PRIMASK(); \
#define UTIL_ENTER_CRITICAL() do{ \ __disable_irq(); \
__DMB(); \ }while(0)
u32PRIMASK = __get_PRIMASK(); \
__disable_irq(); \ // Exit Critical:
}while(0) // implements a memory barrier to ensure memory operations completed before
// restores the interrupt status register
// Exit Critical: #define UTIL_EXIT_CRITICAL() do{ \
// implements a memory barrier to ensure memory operations completed before __DMB(); \
// restores the interrupt status register __set_PRIMASK( u32PRIMASK ); \
#define UTIL_EXIT_CRITICAL() do{ \ }while(0)
__DMB(); \
__set_PRIMASK( u32PRIMASK ); \ // bit band definitions
}while(0) #define UTIL_BB_SRAM( Address, BitNumber ) (*(VOLATILE PU32)(SRAM_BB_BASE + ((U32)Address - SRAM_BASE)*32 + BitNumber*4 ) )
#define UTIL_BB_BKRAM( Address, BitNumber ) (*(VOLATILE PU32)(BKPSRAM_BB_BASE + ((U32)Address - BKPSRAM_BASE)*32 + BitNumber*4 ) )
// bit band definitions #define UTIL_BB_PERI( Address, BitNumber ) (*(VOLATILE PU32)(PERIPH_BB_BASE + ((U32)Address - PERIPH_BASE)*32 + BitNumber*4 ) )
#define UTIL_BB_SRAM( Address, BitNumber ) (*(VOLATILE PU32)(SRAM_BB_BASE + ((U32)Address - SRAM_BASE)*32 + BitNumber*4 ) )
#define UTIL_BB_BKRAM( Address, BitNumber ) (*(VOLATILE PU32)(BKPSRAM_BB_BASE + ((U32)Address - BKPSRAM_BASE)*32 + BitNumber*4 ) ) // Basic bit band function definitions
#define UTIL_BB_PERI( Address, BitNumber ) (*(VOLATILE PU32)(PERIPH_BB_BASE + ((U32)Address - PERIPH_BASE)*32 + BitNumber*4 ) ) #define UTIL_BB_SRAM_ClearBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 0)
#define UTIL_BB_SRAM_SetBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 1)
// Basic bit band function definitions #define UTIL_BB_SRAM_GetBit( Address, BitNumber) UTIL_BB_SRAM( Address, BitNumber )
#define UTIL_BB_SRAM_ClearBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 0)
#define UTIL_BB_SRAM_SetBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 1) #define UTIL_BB_PERI_ClearBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 0)
#define UTIL_BB_SRAM_GetBit( Address, BitNumber) UTIL_BB_SRAM( Address, BitNumber ) #define UTIL_BB_PERI_SetBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 1)
#define UTIL_BB_PERI_GetBit( Address, BitNumber) UTIL_BB_PERI( Address, BitNumber )
#define UTIL_BB_PERI_ClearBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 0)
#define UTIL_BB_PERI_SetBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 1) #define UTIL_BB_BKRAM_ClearBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 0)
#define UTIL_BB_PERI_GetBit( Address, BitNumber) UTIL_BB_PERI( Address, BitNumber ) #define UTIL_BB_BKRAM_SetBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 1)
#define UTIL_BB_BKRMA_GetBit( Address, BitNumber) UTIL_BB_BKRAM( Address, BitNumber )
#define UTIL_BB_BKRAM_ClearBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 0)
#define UTIL_BB_BKRAM_SetBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 1) // Checks, if the core is in debug mode
#define UTIL_BB_BKRMA_GetBit( Address, BitNumber) UTIL_BB_BKRAM( Address, BitNumber ) #define UTIL_IS_DEBUGGER_ATTACHED() (CoreDebug_DHCSR_C_DEBUGEN_Msk & CoreDebug->DHCSR)
// Checks, if the core is in debug mode //=================================================================================================
#define UTIL_IS_DEBUGGER_ATTACHED() (CoreDebug_DHCSR_C_DEBUGEN_Msk & CoreDebug->DHCSR) // Section: ENUMERATIONS
// Description: Definition of global enumerations (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: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (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 CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//================================================================================================= //=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules). U16 UTIL_u16StringLength( PSZ pszString );
//================================================================================================= BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength );
VOID UTIL_vPuts( PSZ pszString );
U16 UTIL_u16StringLength( PSZ pszString );
BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength ); VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length );
VOID UTIL_vPuts( PSZ pszString ); U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder );
VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length );
VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length ); BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length );
U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder ); BOOL UTIL_boMemCompareVal( PU8 pu8Data1, U8 u8Value, U32 u32Length );
VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length );
BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length ); U8 UTIL_u8GetPinSource( U16 u16GIPO_Pin );
BOOL UTIL_boMemCompareVal( PU8 pu8Data1, U8 u8Value, U32 u32Length ); U8 UTIL_u8DecToBCD( U8 u8Value );
U8 UTIL_u8BCDToDec( U8 u8Value );
U8 UTIL_u8GetPinSource( U16 u16GIPO_Pin ); VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes );
U8 UTIL_u8DecToBCD( U8 u8Value ); U32 UTIL_u32RevU32( U32 u32Data );
U8 UTIL_u8BCDToDec( U8 u8Value ); U32 UTIL_u32RevFLOAT( FLOAT flData );
VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes ); U16 UTIL_u16RevU16( U16 u16Data );
U32 UTIL_u32RevU32( U32 u32Data ); U8 UTIL_u8GetNumberOfClkCycles( DOUBLE dtime );
U32 UTIL_u32RevFLOAT( FLOAT flData );
U16 UTIL_u16RevU16( U16 u16Data ); CHAR UTIL_cGetDeviceRevision( VOID );
U8 UTIL_u8GetNumberOfClkCycles( DOUBLE dtime );
U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length );
CHAR UTIL_cGetDeviceRevision( VOID );
// printf prototype for debug printf
U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length ); int fputc( int ch, FILE *f );
// printf prototype for debug printf #ifdef __cplusplus
int fputc( int ch, FILE *f ); }
#endif
#ifdef __cplusplus
} #endif
#endif
#endif