init new PC

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

View File

@ -0,0 +1,377 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: ADC-Driver
// Filename: ADCD_AdcDriver.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the internal ADC-Driver
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "ADCD_AdcDriver.h"
// Drivers
#include "SPID_SpiDriver.h"
#include "DIPO_DigitalPorts.h"
//#include "EXTI_ExtiHandler.h"
// Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// CMSIS OS
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
// define commands
#define CMD_READ (0<<7)
#define CMD_WRITE (1<<7)
// define register
#define REG_CONFIG 0x00
#define REG_RTD_MSB 0x01
#define REG_RTD_LSB 0x02
#define REG_HIGH_FAULT_MSB 0x03
#define REG_HIGH_FAULT_LSB 0x04
#define REG_LOW_FAULT_MSB 0x05
#define REG_LOW_FAULT_LSB 0x06
#define REG_FAULT_STATUS 0x07
#define CONFIG_VBIAS_ON (1<<7)
#define CONFIG_VBIAS_OFF (0<<7)
#define CONFIG_MODE_AUTO (1<<6)
#define CONFIG_MODE_OFF (0<<6)
#define CONFIG_1SHOT (1<<5)
#define CONFIG_3WIRE (1<<4)
#define CONFIG_24WIRE (0<<4)
#define CONFIG_FAULTCYCLE_NO (0<<2)
#define CONFIG_FAULTCYCLE_AUTO (1<<2)
#define CONFIG_FAULTCYCLE_MANUAL1 (2<<2)
#define CONFIG_FAULTCYCLE_MANUAL2 (3<<2)
#define CONFIG_FAULTSTATCLEAR (1<<1)
#define CONFIG_FILT50HZ (1<<0)
#define CONFIG_FILT60HZ (0<<0)
#define FAULT_HIGHTHRESH 0x80
#define FAULT_LOWTHRESH 0x40
#define FAULT_REFINLOW 0x20
#define FAULT_REFINHIGH 0x10
#define FAULT_RTDINLOW 0x08
#define FAULT_OVUV 0x04
#define CONFIG (U8)(CONFIG_VBIAS_ON | CONFIG_MODE_OFF | CONFIG_24WIRE | CONFIG_FILT60HZ) // enable Vbias; autoconvert off; 4-wire; 60Hz;
#define EVENT_ENABLE ((U32)(1<<0))
#define EVENT_DISABLE ((U32)(1<<1))
#define EVENT_INVERT ((U32)(1<<2))
#define EVENT_EXT_SYNC_ENABLE ((U32)(1<<3))
#define EVENT_NEW_SET_VALUE ((U32)(1<<4))
#define EVENT_NEW_MODE ((U32)(1<<5))
#define EVENT_DAC_START ((U32)(1<<6))
#define EVENT_DAC_STOP ((U32)(1<<7))
#define EVENT_ADC_DATA_READY ((U32)(1<<8))
#define EVENT_RESET_DATA_COUNTER ((U32)(1<<9))
#define EVENT_FLAGS_ALL ( EVENT_ENABLE | EVENT_DISABLE | EVENT_INVERT | \
EVENT_EXT_SYNC_ENABLE | EVENT_NEW_SET_VALUE | EVENT_NEW_MODE | \
EVENT_DAC_START | EVENT_DAC_STOP | EVENT_ADC_DATA_READY | \
EVENT_RESET_DATA_COUNTER )
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osMutexAttr_t m_stMutexAttr =
{
"ADCD_Mutex", // human readable mutex name
osMutexRecursive | osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
// Data Ready Pin
//LOCAL CONST GPIO_TypeDef* m_pstDataReadyPort = GPIOD;
//LOCAL CONST U16 m_u16DataReadyPin = GPIO_PIN_8;
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL U8 m_au8RxData[8];
LOCAL U8 m_au8TxData[8];
LOCAL osMutexId_t m_pstMutexID = NULL;
LOCAL SPID_StHandle m_stSPIHandle =
{
SPID_eADC, // enSPI;
0xFF, // enCS (0xFF = hardware chip select)
m_au8TxData, // pu8TxBuf;
m_au8RxData, // pu8RxBuf;
0, // u16TransferSize;
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit );
PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit );
//=================================================================================================
// 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: ADCD_boInitializeModule
// Description: Initializes the ADC module
// Parameters: None
// Returns: BOOL TRUE, if initializaiton sucessful, otherwise FALSE
//
//-------------------------------------------------------------------------------------------------
BOOL ADCD_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr ) ) == NULL ) ? FALSE : TRUE;
osMutexAcquire( m_pstMutexID, osWaitForever );
// Conifg ADC Cold
DIPO_vSetOutput( DIPO_eCS_C );
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
DIPO_vResetOutput( DIPO_eCS_C );
DIPO_vSetOutput( DIPO_eCS_C );
boOK &= boWriteReg( REG_HIGH_FAULT_MSB, (U16)0x5b12 , TRUE );
DIPO_vResetOutput( DIPO_eCS_C );
DIPO_vSetOutput( DIPO_eCS_C );
boOK &= boWriteReg( REG_LOW_FAULT_MSB, (U16)0x2690 , TRUE );
DIPO_vResetOutput( DIPO_eCS_C );
// Config ADC Hot
DIPO_vSetOutput( DIPO_eCS_H );
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
DIPO_vResetOutput( DIPO_eCS_H );
DIPO_vSetOutput( DIPO_eCS_H );
boOK &= boWriteReg( REG_HIGH_FAULT_MSB, (U16)0x5b12 , TRUE );
DIPO_vResetOutput( DIPO_eCS_H );
DIPO_vSetOutput( DIPO_eCS_H );
boOK &= boWriteReg( REG_LOW_FAULT_MSB, (U16)0x2690 , TRUE );
DIPO_vResetOutput( DIPO_eCS_H );
osMutexRelease( m_pstMutexID );
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ADCD_boReadData
// Description: Reads the conversion data form the ADC
// Parameters: PU8 pu8Error error
// Returns: DOUBLE conversion data
//-------------------------------------------------------------------------------------------------
BOOL ADCD_boReadData( ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data )
{
BOOL boOK = TRUE;
*pu8Error = 0; // reset error state
U16 u16Data = 0;
DIPO_EnDigitalOutput CS = DIPO_eCS_H;
if( eChannel == ADCD_eHot ) CS = DIPO_eCS_H;
else if ( eChannel == ADCD_eCold ) CS = DIPO_eCS_C;
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput( CS );
boOK &= boWriteReg( REG_CONFIG, CONFIG | CONFIG_1SHOT , FALSE );
DIPO_vResetOutput( CS );
osMutexRelease( m_pstMutexID );
osDelay(55);
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput( CS );
boOK &= boReadReg( REG_RTD_MSB, &u16Data, TRUE );
DIPO_vResetOutput( CS );
osMutexRelease( m_pstMutexID );
if( !boOK )
{
*pu8Error |= ADCD_SPI_FAILURE;
return 0;
}
if( ( u16Data & 0x00 ) == 0x01 )
{
*pu8Error |= ADCD_STATUS_DATA_ERROR;
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput( CS );
boOK &= boReadReg( REG_FAULT_STATUS, &u16Data, FALSE );
DIPO_vResetOutput( CS );
DIPO_vSetOutput( CS );
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
DIPO_vResetOutput( CS );
DIPO_vSetOutput( CS );
boOK &= boReadReg( REG_HIGH_FAULT_MSB, &u16Data, TRUE );
DIPO_vResetOutput( CS );
osMutexRelease( m_pstMutexID );
*pu8Error |= u16Data & 0xFC;
return 0;
}
u16Data = u16Data >> 1;
*pu16Data = u16Data;
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput( CS );
boOK &= boWriteReg( REG_CONFIG, CONFIG | CONFIG_FAULTCYCLE_AUTO , FALSE );
DIPO_vResetOutput( CS );
osMutexRelease( m_pstMutexID );
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: boWriteReg
// Description: Writes to the regiser
// Parameters: U8 u8Register
// U16 u16Data
// BOOL boIs16bit TRUE, if Data is 16bit, FALSE, if Data is 8bit
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit )
{
BOOL boOK = TRUE;
if( boIs16bit ){
m_au8TxData[0] = CMD_WRITE | u8Register;
m_au8TxData[1] = (U8)u16Data>>8;
m_au8TxData[2] = (U8)u16Data;
m_stSPIHandle.u16TransferSize = 3;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
} else {
m_au8TxData[0] = CMD_WRITE | u8Register;
m_au8TxData[1] = (U8)u16Data;
m_stSPIHandle.u16TransferSize = 2;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
}
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: boReadReg
// Description: Reads the regiser
// Parameters: U8 u8Register
// PU16 pu16Data
// BOOL boIs16bit TRUE, if Data is 16bit, FALSE, if Data is 8bit
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit )
{
BOOL boOK = TRUE;
if( boIs16bit ){
m_au8TxData[0] = CMD_READ | u8Register;
m_au8TxData[1] = 0;
m_au8TxData[2] = 0;
m_stSPIHandle.u16TransferSize = 3;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
*pu16Data = ( (U16)m_au8RxData[1]<<8 ) | ( (U16)m_au8RxData[2]<<0 );
} else {
m_au8TxData[0] = CMD_READ | u8Register;
m_au8TxData[1] = 0;
m_stSPIHandle.u16TransferSize = 2;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
*pu16Data = (U16)m_au8RxData[1];
}
return( boOK );
}

View File

@ -0,0 +1,95 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: ADC Driver
// Filename: ADCD_AdcDriver.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef ADCD_ADCDRIVER_H
#define ADCD_ADCDRIVER_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).
//=================================================================================================
#define ADCD_STATUS_DATA_ERROR (1<<0)
#define ADCD_SPI_FAILURE (1<<1)
//typedef VOID (*ADCD_pfnCallback)( PVOID pvCallbackArgument );
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
typedef enum {
ADCD_eHot = 0,
ADCD_eCold = 1,
ADCD_eNumberOfTemps // Must be last
}ADCD_EnTemps;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL ADCD_boInitializeModule( VOID );
//BOOL ADCD_boConfig( BOOL boFast, ADCD_pfnCallback pfnDataReadyCallback, PVOID pvCallbackArg );
BOOL ADCD_boReadData( ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,315 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Input
// Filename: ANPI_AnalogPortsIn.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the analog input ports
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "ANPI_AnalogPortsIn.h"
//Application
#include "../Application/VARH_VariableHandler.h"
// Drivers
#include "PECO_PeltierController.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define ADC_RES (4096) // ADC resolution: 12 bits
#define NR_OF_ADCS ANPI_eInNumberOfInputs // number of internal adc channels
#define INT_ADC_REF (3.3f)// int. reference voltage for conversion
#define BUFFER_SIZE NR_OF_ADCS * 2
#define BUFFER_HALF_SIZE NR_OF_ADCS
#define ANPI_ADC_HALF_COMPLETE ((U32)1<<0)
#define ANPI_ADC_FULL_COMPLETE ((U32)1<<1)
#define ANPI_FLAGS_ALL ( ANPI_ADC_HALF_COMPLETE | ANPI_ADC_FULL_COMPLETE )
#define OVERSAMPLING_DIVISOR 16.0f // calculated with parameters from hardware oversampling
// 6 bits(64x) - 2 bit shift = 4bit -> 16x
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL U16 m_au16ADCDataBuffer[BUFFER_SIZE];
LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL osMutexId_t m_pstMutexID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
// conversion factors for the values
// Order must fit enumeration "ANPI_EnAnalogInput"
LOCAL CONST FLOAT m_aflConversionFactor[ANPI_eInNumberOfInputs] =
{
10, // 01 ANPI_eSupplyVoltage24V
5, // 02 ANPI_eSupplyCurrent24V
10, // 03 ANPI_eOutputVoltage
5, // 04 ANPI_eOutputCurrent
};
// Order must fit enumeration "ANPI_EnAnalogInput"
LOCAL CONST FLOAT m_aflOffset[ANPI_eInNumberOfInputs] =
{
0.0f, // 01 ANPI_eSupplyVoltage24V
8.25f, // 02 ANPI_eSupplyCurrent24V
14.85f, // 03 ANPI_eOutputVoltage
8.25f, // 04 ANPI_eOutputCurrent
};
// inputs are connected to the following ADCs
// ANPI_eSupplyVoltage24V ADC1, Channel 6
// ANPI_eSupplyCurrent24V ADC1, Channel 16
// ANPI_eOutputVoltage ADC1, Channel 7
// ANPI_eOutputCurrent ADC1, Channel 15
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"ANPI_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityBelowNormal, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"ANPI_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osMutexAttr_t m_stMutexAttr =
{
"ANPI_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 vTask( PVOID arg );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern ADC_HandleTypeDef hadc1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: ANPI_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPI_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ( ( m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
boOK &= ( ( m_pstEventID = osEventFlagsNew( &stEventAttribute )) == NULL) ? FALSE : TRUE;
boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ANPI_vTask
// Description: ANPI_vTask
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID vTask( PVOID arg )
{
U32 u32Flags;
U16 u16Offset;
FLOAT flUadc;
U32 au32ADCRawData[ANPI_eInNumberOfInputs];
FLOAT aflValues[ANPI_eInNumberOfInputs]; // values
osDelay( 1 ); // Wait 1ms to have a Valid Value
HAL_ADC_Start_DMA( &hadc1, (PU32)&m_au16ADCDataBuffer[0], BUFFER_SIZE );
while ( TRUE )
{
u32Flags = osEventFlagsWait( m_pstEventID, ANPI_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
if( u32Flags & ANPI_ADC_FULL_COMPLETE ) u16Offset = BUFFER_HALF_SIZE;
else if( u32Flags & ANPI_ADC_HALF_COMPLETE ) u16Offset = 0;
else continue;
// aquire mutex: access to m_afcValues blocked for ANPI_flGetInputValue
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
// copy the values in the buffer...
for( U16 u16Cnt = 0; u16Cnt < BUFFER_HALF_SIZE; u16Cnt++ )
au32ADCRawData[ u16Cnt ] = m_au16ADCDataBuffer[u16Cnt + u16Offset];
// multiply conversion factor and add the offset
for( U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
{
flUadc = (FLOAT)au32ADCRawData[u16Cnt] / OVERSAMPLING_DIVISOR / ADC_RES * INT_ADC_REF;
aflValues[u16Cnt] = flUadc * m_aflConversionFactor[u16Cnt] - m_aflOffset[u16Cnt];
}
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_U, aflValues[ANPI_eOutputVoltage] );
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_I, aflValues[ANPI_eOutputCurrent] );
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_R, aflValues[ANPI_eOutputVoltage] / aflValues[ANPI_eOutputCurrent] );
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_R, aflValues[ANPI_eOutputVoltage] * aflValues[ANPI_eOutputCurrent] );
VARH_vSetVariableDataFromSystemFloat( VARH_eSupply_U, aflValues[ANPI_eSupplyVoltage24V] );
VARH_vSetVariableDataFromSystemFloat( VARH_eSupply_I, aflValues[ANPI_eSupplyCurrent24V] );
VARH_vSetVariableDataFromSystemFloat( VARH_eSupply_P, aflValues[ANPI_eSupplyVoltage24V] * (aflValues[ANPI_eSupplyCurrent24V]) );
osMutexRelease( m_pstMutexID ); // release mutex
}
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ConvCpltCallback
// Description: Handles the ADC interrupts
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_ADC_ConvCpltCallback( ADC_HandleTypeDef* hadc )
{
osEventFlagsSet( m_pstEventID, ANPI_ADC_FULL_COMPLETE );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ConvHalfCpltCallback
// Description: Handles the ADC interrupts
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_ADC_ConvHalfCpltCallback( ADC_HandleTypeDef* hadc )
{
osEventFlagsSet( m_pstEventID, ANPI_ADC_HALF_COMPLETE );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ErrorCallback
// Description: Error Callback for the ADC
// Parameters: ADC_HandleTypeDef* hadc
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_ADC_ErrorCallback( ADC_HandleTypeDef* hadc )
{
// TODO: Error Handling
if( hadc->ErrorCode == HAL_ADC_ERROR_NONE )
{
}
if( hadc->ErrorCode == HAL_ADC_ERROR_INTERNAL )
{
}
if( hadc->ErrorCode == HAL_ADC_ERROR_OVR )
{
}
if( hadc->ErrorCode == HAL_ADC_ERROR_DMA )
{
}
if( hadc->DMA_Handle->ErrorCode & HAL_DMA_ERROR_TE )
{
}
}

View File

@ -0,0 +1,102 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Input
// Filename: ANPI_AnalogPortsIn.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef ANPI_ANALOGPORTSIN_H
#define ANPI_ANALOGPORTSIN_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
// Enumeration for analog inputs is used as array index later on. Thus enumeration must start
// at zero and must be numbered consecutively. Enumeration must never be changed.
typedef enum
{
ANPI_eSupplyVoltage24V = 0, // voltage of 24V power supply
ANPI_eSupplyCurrent24V = 1, // current of 24V power supply
ANPI_eOutputVoltage = 2, // output voltage peltier element
ANPI_eOutputCurrent = 3, // output current peltier element
ANPI_eInNumberOfInputs, // Must be last entry
} ANPI_EnAnalogInput;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL ANPI_boInitializeModule( VOID );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,164 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Output
// Filename: ANPO_AnalogPortsOut.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the analog outputs ports
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "ANPO_AnalogPortsOut.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
U32 u32ConvertVoltagetoRaw( FLOAT Voltage );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern DAC_HandleTypeDef hdac1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: ANPO_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= HAL_DAC_Start( &hdac1, DAC_CHANNEL_1 ) == HAL_OK ? TRUE : FALSE;
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: ANPO_boSetVoltage
// Description: Sets the DAC Output to a specific Voltage
// Parameters: FLOAT Voltage
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boSetVoltage( FLOAT Voltage ){
BOOL boOK = TRUE;
U32 u32RawData = u32ConvertVoltagetoRaw( Voltage );
boOK &= HAL_DAC_SetValue( &hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, u32RawData );
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: u32ConvertVoltagetoRaw
// Description: Convert Voltage to Raw value for the DAC
// Parameters: FLOAT Voltage
// Returns: U32
//-------------------------------------------------------------------------------------------------
U32 u32ConvertVoltagetoRaw( FLOAT Voltage ){
U32 RawData;
RawData = Voltage * 4095 / 3.3;
return RawData;
}

View File

@ -0,0 +1,96 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Output
// Filename: ANPO_AnalogPortsOut.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef ANPO_ANALOGPORTSOUT_H
#define ANPO_ANALOGPORTSOUT_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
typedef enum
{
ANPO_eControlVoltage = 0, // 00 control Voltage
ANPO_eInNumberOfInputs, // Must be last entry
} ANPO_EnAnalogOutput;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL ANPO_boInitializeModule( VOID );
BOOL ANPO_boSetVoltage( FLOAT Voltage );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,262 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Can Driver
// Filename: CAND_CanDriver.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the analog outputs ports
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "CAND_CanDriver.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// Driver
#include "DIPO_DigitalPorts.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define CAND_SHIFT 0x1 // Shift address space (0-3)
#define CAND_PRIVATE 1
#define CAND_PUBLIC 0
#define CAND_RECEIVE 0
#define CAND_SEND 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).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
CAND_pfnRxCallback m_pfnRxCallback = NULL;
U8 u8BoardId = 0x00;
CAN_FilterTypeDef stFilter_public = {
(CAND_SHIFT<<14)|(CAND_PUBLIC<<13)|(CAND_RECEIVE<<11), // FilterIdHigh
0x0000, // FilterIdLow
0xE800, // FilterMaskIdHigh
0x0000, // FilterMaskIdLow
CAN_FILTER_FIFO0, // FilterFIFOAssignment
0x00, // FilterBank
CAN_FILTERMODE_IDMASK, // FilterMode
CAN_FILTERSCALE_32BIT, // FilterScale
CAN_FILTER_ENABLE, // FilterActivation
0x00 // SlaveStartFilterBank
};
CAN_FilterTypeDef stFilter_private = {
(CAND_SHIFT<<14)|(CAND_PRIVATE<<13)|(CAND_RECEIVE<<11), // FilterIdHigh
0x0000, // FilterIdLow
0xE9E0, // FilterMaskIdHigh
0x0000, // FilterMaskIdLow
CAN_FILTER_FIFO0, // FilterFIFOAssignment
0x01, // FilterBank
CAN_FILTERMODE_IDMASK, // FilterMode
CAN_FILTERSCALE_32BIT, // FilterScale
CAN_FILTER_ENABLE, // FilterActivation
0x00 // SlaveStartFilterBank
};
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern CAN_HandleTypeDef hcan1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: CAND_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL CAND_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
u8BoardId |= DIPO_boGetInput(DIPO_eADR0) << 0;
u8BoardId |= DIPO_boGetInput(DIPO_eADR1) << 1;
u8BoardId |= DIPO_boGetInput(DIPO_eADR2) << 2;
u8BoardId |= DIPO_boGetInput(DIPO_eADR3) << 3;
stFilter_private.FilterIdHigh |= u8BoardId << 5;
boOK &= ( HAL_CAN_ConfigFilter(&hcan1, &stFilter_public) == HAL_OK ) ? TRUE : FALSE;
boOK &= ( HAL_CAN_ConfigFilter(&hcan1, &stFilter_private) == HAL_OK ) ? TRUE : FALSE;
boOK &= ( HAL_CAN_Start(&hcan1) == HAL_OK ) ? TRUE : FALSE;
boOK &= ( HAL_CAN_ActivateNotification( &hcan1, CAN_IT_RX_FIFO0_MSG_PENDING ) == HAL_OK ) ? TRUE : FALSE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: CAND_u8GetBoardId
// Description: Returns the Board ID
// Parameters: None
// Returns: U8 Board ID
//-------------------------------------------------------------------------------------------------
U8 CAND_u8GetBoardId( VOID ){
return u8BoardId;
}
//-------------------------------------------------------------------------------------------------
// Function: CAND_boSendMessage
// Description: Send a Message over the CAN Interface
// Parameters: U8 Id
// U8 Length
// PU8 Data Buffer
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL CAND_boSendMessage( U16 u16Id, PU8 pu8Buffer, U8 u8Len ){
BOOL boOK = TRUE;
if( u8Len > 8 ) return FALSE;
CAN_TxHeaderTypeDef header = {
u16Id | (CAND_SEND<<6),
0,
CAN_ID_STD,
CAN_RTR_DATA,
u8Len,
DISABLE
};
boOK &= HAL_CAN_AddTxMessage( &hcan1, &header, pu8Buffer, (PU32)CAN_TX_MAILBOX0 ) == HAL_OK ? TRUE : FALSE;
return boOK;
}
//-------------------------------------------------------------------------------------------------
// Function: CAND_vSetRxCallback
// Description: Send a Message over the CAN Interface
// Parameters: CAND_pfnRxCallback Callback Function
// Returns: none
//-------------------------------------------------------------------------------------------------
VOID CAND_vSetRxCallback( CAND_pfnRxCallback pfnRxCallback ){
m_pfnRxCallback = pfnRxCallback;
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: HAL_CAN_RxFifo0MsgPendingCallback
// Description: HAL Can Rx FIFO Msg Pending Callback
// Parameters: CAN_HandleTypeDef *hcan
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_CAN_RxFifo0MsgPendingCallback( CAN_HandleTypeDef *hcan ){
CAN_RxHeaderTypeDef header;
U8 au8Data[8];
HAL_CAN_GetRxMessage( hcan, CAN_RX_FIFO0, &header, au8Data );
CAND_Message stMessage;
stMessage.u16Id = header.StdId;
stMessage.u8Type = (header.StdId & 0x030) >> 4;
stMessage.u8Len = header.DLC;
UTIL_vMemCopy( au8Data,stMessage.au8Data,stMessage.u8Len );
m_pfnRxCallback( stMessage );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_CAN_ErrorCallback
// Description: HAL Can error callback function
// Parameters: CAN_HandleTypeDef *hcan
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_CAN_ErrorCallback( CAN_HandleTypeDef *hcan ){
U32 u32Error = hcan->ErrorCode;
// TODO: Can Error Handling
}

View File

@ -0,0 +1,103 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Can Driver
// Filename: CAND_CanDriver.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef CAND_CANDRIVER_H
#define CAND_CANDRIVER_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).
//=================================================================================================
#define MESSAGE_TYPE_WRITE 2
#define MESSAGE_TYPE_READ 1
#define MESSAGE_TYPE_COMMAND 0
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
typedef struct {
U8 au8Data[8];
U8 u8Len;
U8 u8Type;
U16 u16Id;
} CAND_Message;
// callback functions
typedef VOID (*CAND_pfnRxCallback)( CAND_Message stMessage );
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL CAND_boInitializeModule( VOID );
BOOL CAND_boSendMessage( U16 u16Id, PU8 pu8Buffer, U8 u8Len );
VOID CAND_vSetRxCallback( CAND_pfnRxCallback pfnRxCallback );
U8 CAND_u8GetBoardId( VOID );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,330 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Digital Ports
// Filename: DIPO_DigitalPorts.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the digtial I/O ports
// Convention: TRUE means active, FALSE means not active
// The polarity of the signal is set in the initialization struct (boLowActive)
// The name of the enumeration does not have any impact on the polarity
// Even with a signal nCs, TRUE means active (if low active => output low)
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "DIPO_DigitalPorts.h"
//Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
typedef struct
{
GPIO_TypeDef* pstPort; // Port
GPIO_InitTypeDef stGPIOInit; // init structure
BOOL boResetState; // reset state of pin
BOOL boSetState; // set state of pin
} StDigitalIO; // Represents one digital input or output
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
// Input order must fit enumeration "DIPO_EnDigitalInput".
LOCAL CONST StDigitalIO m_astInputs[DIPO_eInNumberOfInputs] =
{
{ GPIOB, { GPIO_PIN_7, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 00 DIPO_ePG
{ GPIOC, { GPIO_PIN_15, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 01 DIPO_eADR3
{ GPIOB, { GPIO_PIN_3, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 02 DIPO_eADR2
{ GPIOB, { GPIO_PIN_4, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 01 DIPO_eADR1
{ GPIOA, { GPIO_PIN_15, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 03 DIPO_eADR0
};
// order must fit enumeration "DIPO_EnDigitalOutput".
LOCAL CONST StDigitalIO m_astOutputs[DIPO_eOutNumberOfOutputs] =
{
{ GPIOB, { GPIO_PIN_6, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, TRUE, FALSE }, // 00 DIPO_eCS_C
{ GPIOB, { GPIO_PIN_5, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, TRUE, FALSE }, // 01 DIPO_eCS_H
{ GPIOC, { GPIO_PIN_14, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 02 DIPO_eLED
{ GPIOA, { GPIO_PIN_8, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 03 DIPO_eEN
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//=================================================================================================
// 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: DIPO_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// This function is thread save
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL DIPO_boInitializeModule( VOID )
{
U8 u8Cnt;
BOOL boOK = TRUE;
// enable APB2 syscfg clock
__HAL_RCC_SYSCFG_CLK_ENABLE();
// initialize the inputs
// ----------------------
if( DIPO_eInNumberOfInputs > 0 )
{
for( u8Cnt = 0 ; u8Cnt < DIPO_eInNumberOfInputs; u8Cnt++ )
{
boOK &= (m_astInputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_INPUT) ? TRUE : FALSE;
// configure the GIO pin
HAL_GPIO_Init( m_astInputs[u8Cnt].pstPort, (GPIO_InitTypeDef*)&m_astInputs[u8Cnt].stGPIOInit );
}
}
// initialize the outputs
// ----------------------
if( DIPO_eOutNumberOfOutputs > 0 )
{
for( u8Cnt = 0 ; u8Cnt < DIPO_eOutNumberOfOutputs; u8Cnt++ )
{
boOK &= (m_astOutputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_OUTPUT_PP || m_astOutputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_OUTPUT_OD) ? TRUE : FALSE;
// disable output
DIPO_vResetOutput( (DIPO_EnDigitalOutput)u8Cnt );
HAL_GPIO_Init( m_astOutputs[u8Cnt].pstPort, (GPIO_InitTypeDef*)&m_astOutputs[u8Cnt].stGPIOInit );
}
}
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vSetOutput
// Description: Turns a digital output on or off.
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to set on or off
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vSetOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boSetState );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vResetOutput
// Description: Sets the output in reset state
// Parameters: DIPO_EnDigitalOutput enOutput Digital output
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vResetOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boResetState );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vSetState
// Description: Sets the output state
// Parameters: DIPO_EnDigitalOutput enOutput Digital output
// BOOL boState
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vSetState( DIPO_EnDigitalOutput enOutput, BOOL boState )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
if( boState )
{
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boSetState );
}
else
{
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boResetState );
}
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vGetOutput
// Description: Reads back a digital output.
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to get the data value
// Returns: BOOL TRUE, if output is active, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL DIPO_boGetOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs || !IS_GPIO_ALL_INSTANCE( m_astOutputs[enOutput].pstPort ) || !IS_GPIO_PIN( m_astOutputs[enOutput].stGPIOInit.Pin ) )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
BOOL boBitState = TRUE;
if( READ_BIT( m_astOutputs[enOutput].pstPort->ODR, m_astOutputs[enOutput].stGPIOInit.Pin ) == 0 )
{
boBitState = FALSE;
}
return( ( m_astOutputs[enOutput].boSetState == TRUE && boBitState == TRUE ) ||\
( m_astOutputs[enOutput].boResetState == TRUE && boBitState == FALSE ) ? TRUE : FALSE );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_boGetInput
// Description: Reads a digital input
// Parameters: DIPO_EnDigitalInput enInput Digital input to read
// Returns: BOOL TRUE, if intput is set active, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL DIPO_boGetInput( DIPO_EnDigitalInput enInput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enInput >= DIPO_eInNumberOfInputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
GPIO_PinState enPinState = HAL_GPIO_ReadPin( m_astInputs[enInput].pstPort, (U16)m_astInputs[enInput].stGPIOInit.Pin );
return( ( m_astInputs[enInput].boSetState == TRUE && enPinState == GPIO_PIN_SET) ||\
( m_astInputs[enInput].boResetState == TRUE && enPinState == GPIO_PIN_RESET) ? TRUE : FALSE );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vToggleOutput
// Description: Toggles the digital output
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to toggle
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vToggleOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
HAL_GPIO_TogglePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================

View File

@ -0,0 +1,132 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Digital Ports
// Filename: DIPO_DigitalPorts.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef DIPO_DIGITALPORTS_H
#define DIPO_DIGITALPORTS_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
// Enumeration for digital inputs is used as array index later on. Thus enumeration must start
// at zero and must be numbered consecutively. Enumeration must never be changed.
// Value 0xFF is reserved and must not be used.
typedef enum
{
DIPO_ePG = 0, // 00 DIP 1
DIPO_eADR3 = 1, // 01 DIP 2
DIPO_eADR2 = 2, // 01 DIP 2
DIPO_eADR1 = 3, // 02 DIP 3
DIPO_eADR0 = 4, // 03 DIP 4
DIPO_eInNumberOfInputs, // Must be last entry
} DIPO_EnDigitalInput;
// Enumeration for digital outputs is used as array index later on. Thus enumeration must start
// at zero and must be numbered consecutively. Enumeration must never be changed.
// Value 0xFF is reserved and must not be used.
typedef enum
{
DIPO_eCS_C = 0, // 00 Chip Select Cold
DIPO_eCS_H = 1, // 01 Chip Select Hot
DIPO_eLED = 2, // 02 Test LED
DIPO_eEN = 3, // 03 Enable
DIPO_eOutNumberOfOutputs, // Must be last entry
} DIPO_EnDigitalOutput;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL DIPO_boInitializeModule( VOID );
VOID DIPO_vSetOutput( DIPO_EnDigitalOutput enOutput );
VOID DIPO_vResetOutput( DIPO_EnDigitalOutput enOutput );
VOID DIPO_vSetState( DIPO_EnDigitalOutput enOutput, BOOL boState );
VOID DIPO_vToggleOutput( DIPO_EnDigitalOutput enOutput );
BOOL DIPO_boGetInput( DIPO_EnDigitalInput enInput );
BOOL DIPO_boGetOutput( DIPO_EnDigitalOutput enOutput );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,123 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Error Handler
// Filename: ERRH_ErrorHandler.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 internal Errors
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "ERRH_ErrorHandler.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: USFL_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ERRH_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================

View File

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

View File

@ -0,0 +1,377 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: SPI-Driver
// Filename: SPID_SpiDriver.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the SPI-Driver
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "SPID_SpiDriver.h"
// Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// Drivers
#include "DIPO_DigitalPorts.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define OS_ADC_SPI_COMPLETE_FLAG ((U32)(1<<0))
#define OS_ADC_SPI_ERROR_FLAG ((U32)(1<<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
{
SPI_HandleTypeDef* pstSPIHandle;
osMutexId_t pstMutexID;
CONST osMutexAttr_t* pstMutexAttribute;
U32 u32SPICompleteFlag;
U32 u32SPIErrorFlag;
} StSPI;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osMutexAttr_t m_stADCMutexAttr =
{
"SPID_ADC_Mutex", // human readable mutex name
osMutexRecursive | osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"SPID_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern SPI_HandleTypeDef hspi1;
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL StSPI m_astSPI[SPID_eNumberOfSPIs] =
{
// SPID_eSPI2
{
&hspi1, // SPI Handle
NULL, // pstMutexID
&m_stADCMutexAttr, // pstMutexAttribute
OS_ADC_SPI_COMPLETE_FLAG, // u32SPICompleteFlag
OS_ADC_SPI_ERROR_FLAG, // u32SPIErrorFlag
},
};
LOCAL osEventFlagsId_t m_pstEventID = NULL;
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE SPID_EnSPIs enGetSPI( SPI_HandleTypeDef* pstSPI );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: SPID_boInitializeModule
// Description: Initializes the module
// Parameters: None
// Returns: BOOL, TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL SPID_boInitializeModule( VOID )
{
BOOL boOK= TRUE;
boOK &= ((m_pstEventID = osEventFlagsNew( &stEventAttribute )) == NULL) ? FALSE : TRUE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: SPID_boSend
// Description: Sends a number of bytes
// Parameters: SPID_StHandle* pstHandle
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL SPID_boSend( SPID_StHandle* pstHandle )
{
BOOL boOK;
U32 u32Flags = 0;
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( pstHandle == NULL || pstHandle->enSPI >= SPID_eNumberOfSPIs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
osMutexAcquire( m_astSPI[pstHandle->enSPI].pstMutexID, osWaitForever );
// clear all flags
osEventFlagsClear( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag );
// start SPI transmission
boOK = HAL_SPI_Transmit_DMA( m_astSPI[pstHandle->enSPI].pstSPIHandle, pstHandle->pu8TxBuf, pstHandle->u16TransferSize ) == HAL_OK ? TRUE : FALSE;
if( boOK )
{
// wait until transmisison done
u32Flags = osEventFlagsWait( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag, osFlagsWaitAny, osWaitForever );
}
boOK &= ( u32Flags & m_astSPI[pstHandle->enSPI].u32SPIErrorFlag ) ? FALSE : TRUE;
osMutexRelease( m_astSPI[pstHandle->enSPI].pstMutexID );
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: SPID_boSendReceive
// Description: Sends a and receives a number of bytes
// Parameters: SPID_StHandle* pstHandle
// DIPO_EnDigitalOutput enCS
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL SPID_boSendReceive( SPID_StHandle* pstHandle )
{
BOOL boOK;
U32 u32Flags = 0;
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( pstHandle == NULL || pstHandle->enSPI >= SPID_eNumberOfSPIs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
osMutexAcquire( m_astSPI[pstHandle->enSPI].pstMutexID, osWaitForever );
// clear all flags
osEventFlagsClear( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag );
// start SPI
boOK = HAL_SPI_TransmitReceive_DMA( m_astSPI[pstHandle->enSPI].pstSPIHandle, pstHandle->pu8TxBuf, pstHandle->pu8RxBuf, pstHandle->u16TransferSize ) == HAL_OK ? TRUE : FALSE;
if( boOK )
{
// wait until transmisison done
u32Flags = osEventFlagsWait( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag, osFlagsWaitAny, osWaitForever );
}
boOK &= ( u32Flags & m_astSPI[pstHandle->enSPI].u32SPIErrorFlag ) ? FALSE : TRUE;
osMutexRelease( m_astSPI[pstHandle->enSPI].pstMutexID );
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
///-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_TxRxCpltCallback
// Description: HAL spi rx/tx complete callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_TxRxCpltCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_TxCpltCallback
// Description: HAL spi tx complete callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_TxCpltCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_RxCpltCallback
// Description: HAL SPI rx complete callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_RxCpltCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_ErrorCallback
// Description: HAL SPI error callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_ErrorCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
// check rx overrun error
if( hspi->ErrorCode & HAL_SPI_ERROR_OVR )
{
//ELOG_ADD_LOG( ELOG_eSPIOverrunError );
}
// check rx dma transfer error
if( hspi->hdmarx->ErrorCode & HAL_DMA_ERROR_TE )
{
//ELOG_ADD_LOG( ELOG_eDMAHTransferError );
}
// check tx dma transfer error
if( hspi->hdmatx->ErrorCode & HAL_DMA_ERROR_TE )
{
//ELOG_ADD_LOG( ELOG_eDMAHTransferError );
}
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPIErrorFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: enGetSPI
// Description: Gets the SPI enumeration to the corresponding SPI handle
// Parameters: SPI_HandleTypeDef* pstSPI
// Returns: SPID_EnSPIs
//-------------------------------------------------------------------------------------------------
PRIVATE SPID_EnSPIs enGetSPI( SPI_HandleTypeDef* pstSPI )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( pstSPI == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
ASRT_ASSERT( FALSE );
}
#endif
for( U8 u8Cnt = 0; u8Cnt < SPID_eNumberOfSPIs; u8Cnt++ )
{
if( m_astSPI[u8Cnt].pstSPIHandle == pstSPI )
{
return( u8Cnt );
}
}
//ASRT_ASSERT( FALSE );
return( 0 );
}

View File

@ -0,0 +1,113 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: SPI-Driver
// Filename: SPID_SpiDriver.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef SPID_SPIDRIVER_H
#define SPID_SPIDRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
#include "../Drivers/DIPO_DigitalPorts.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
// do not change the order of the enumeration!
typedef enum
{
SPID_eADC = 0,
SPID_eNumberOfSPIs, // Must be last
} SPID_EnSPIs;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
typedef struct
{
SPID_EnSPIs enSPI;
DIPO_EnDigitalOutput enCS;
PU8 pu8TxBuf;
PU8 pu8RxBuf;
U16 u16TransferSize;
SPI_InitTypeDef stInit;
} SPID_StHandle;
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL SPID_boInitializeModule( VOID );
BOOL SPID_boSend( SPID_StHandle* pstHandle );
BOOL SPID_boSendReceive( SPID_StHandle* pstHandle );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,190 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Temp
// Filename: TEMP_Temperature.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the temperature readout
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "TEMP_Temperature.h"
// Application
#include "../Application/VARH_VariableHandler.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// Drivers
#include "ADCD_AdcDriver.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define REFRESH_MS 100
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE FLOAT flConvertADCData( U16 dbRTemp );
PRIVATE VOID vTask( PVOID arg );
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"TEMP_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
//=================================================================================================
// 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: TEMP_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// This function is thread save
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL TEMP_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ((m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: vTempTask
// Description: vTempTask
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vTask( PVOID arg )
{
UNUSED( arg );
BOOL boOK = TRUE;
U8 error;
U16 u16ADC_data[ADCD_eNumberOfTemps];
FLOAT flTempData[ADCD_eNumberOfTemps];
osDelay(10);
while( TRUE )
{
boOK &= ADCD_boReadData( ADCD_eHot, &error, &u16ADC_data[ADCD_eHot] );
boOK &= ADCD_boReadData( ADCD_eCold, &error, &u16ADC_data[ADCD_eCold] );
if( boOK )
{
flTempData[ADCD_eHot] = flConvertADCData( u16ADC_data[ADCD_eHot] );
flTempData[ADCD_eCold] = flConvertADCData( u16ADC_data[ADCD_eCold] );
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_H, flTempData[ADCD_eHot] );
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_C, flTempData[ADCD_eCold] );
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_Diff, flTempData[ADCD_eHot] - flTempData[ADCD_eCold] );
}
osDelay(REFRESH_MS);
}
}
//-------------------------------------------------------------------------------------------------
// Function: flConvertADCData
// Description: Converts resistor value to temperature data
// Parameters: U16 u16RTemp
// Returns: U16, temperature in Celcius
//-------------------------------------------------------------------------------------------------
PRIVATE FLOAT flConvertADCData( U16 u16RTemp )
{
FLOAT u16R = u16RTemp / 8192.0f;
FLOAT flT = 9.9714f * u16R;
flT += 235.904f;
flT *= u16R;
flT += -245.876f;
return( flT );
}

View File

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

View File

@ -0,0 +1,275 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: User Flash
// Filename: USFL_UserFlash.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 internal flash for User Settings
//
// STM32L432KBUX_FLASH.ld
//
// DATA (rwx) : ORIGIN = 0x801F800, LENGTH = 2K
//
// /* Sections */
// SECTIONS
// {
// /* NOLOAD is required for not ereasing this block */
// .user_data (NOLOAD) :
// {
// . = ALIGN(4);
// *(.user_data)
// . = ALIGN(4);
// } > DATA*/
// ...
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "USFL_UserFlash.h"
// Toolbox
#include "../Application/VARH_VariableHandler.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define USERFLASHSIZE (2000/4) // Bytes -> 64 Bits
#define USERFLASHPAGE (63)
#define VARDEF 0xABCDEF
#define STARTDEF (((U64)0xAA01F055 << 32) + (VARDEF << 2))
//=================================================================================================
// 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).
//=================================================================================================
FLASH_EraseInitTypeDef stEreaseInit = {
FLASH_TYPEERASE_PAGES,
FLASH_BANK_1,
USERFLASHPAGE,
1
};
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
U32 u32VarPointer = 0;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
__attribute__((__section__(".user_data"))) const U64 UserFlash[USERFLASHSIZE];
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
BOOL vEreaseUserFlash( void );
U32 vFindNextFreePointer( void );
U32 u32FindLastPointer( void );
U8 u8ConvertWordsToDoubleWords( U8 u8Words );
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: USFL_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL USFL_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
if( UserFlash[0] != STARTDEF ){
boOK &= vEreaseUserFlash();
}
return( boOK );
}
VARH_UVariable USFL_uGetVariable ( void ){
if( u32VarPointer == 0 ) u32VarPointer = u32FindLastPointer();
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: u32FindNextFreePointer
// Description: Finds the next free sector in the flash for saving variables
// Parameters: None
// Returns: U32 next free pointer
//-------------------------------------------------------------------------------------------------
U32 u32FindNextFreePointer( void ){
BOOL boFound = FALSE;
U32 u32Pointer = u32VarPointer;
while(!boFound){
if( ( ( UserFlash[u32Pointer] >> 8 ) & 0xFFFFFF ) == VARDEF ){
U8 u8Size = UserFlash[u32Pointer] & 0xFF;
if( u8Size == 0 ){
boFound = TRUE;
} else {
u32Pointer += u8ConvertWordsToDoubleWords(u8Size);
}
} else {
u32Pointer += 1;
}
if( u32Pointer >= USERFLASHSIZE ){
u32Pointer = 1;
break;
}
}
return u32Pointer;
}
//-------------------------------------------------------------------------------------------------
// Function: u32FindLastPointer
// Description: Finds the next free sector in the flash for saving variables
// Parameters: None
// Returns: U32 next free pointer
//-------------------------------------------------------------------------------------------------
U32 u32FindLastPointer( void ){
BOOL boFound = FALSE;
U32 u32Pointer = 0;
U8 u8LastSize = 0;
while(!boFound){
if( ( UserFlash[u32Pointer] >> 40) == VARDEF ){
U8 u8Size = UserFlash[u32Pointer] & 0xFF;
if( u8Size == 0 ){
boFound = TRUE;
u32Pointer -= u8ConvertWordsToDoubleWords(u8LastSize);
} else {
u32Pointer += u8ConvertWordsToDoubleWords(u8Size);
u8LastSize = u8Size;
}
} else {
u32Pointer += 1;
}
if( u32Pointer >= USERFLASHSIZE ){
u32Pointer = 1;
break;
}
}
return u32Pointer;
}
//-------------------------------------------------------------------------------------------------
// Function: u8ConvertWordsToDoubleWords
// Description: Converts 32Bit Word size to 64 Bit Double Word size for saving Vars
// Parameters: U8 u8Words
// Returns: U8 Double Words
//-------------------------------------------------------------------------------------------------
U8 u8ConvertWordsToDoubleWords( U8 u8Words ) {
U8 u8DWords;
u8Words += 1; // + VARDEF
u8DWords = u8Words / 2;
u8DWords += u8Words % 2;
return u8DWords;
}
//-------------------------------------------------------------------------------------------------
// Function: vEreaseUserFlash
// Description: Ereases the User Flash Sector
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL vEreaseUserFlash( void ){
uint32_t u32PageError = 0;
BOOL boOK = TRUE;
HAL_FLASH_Unlock();
boOK &= HAL_FLASHEx_Erase(&stEreaseInit, &u32PageError) == HAL_OK ? TRUE : FALSE;
if( !boOK ){
return FALSE;
}
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, (U32) &UserFlash[0], STARTDEF);
HAL_FLASH_Lock();
return TRUE;
}

View File

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