Init Repo
This commit is contained in:
395
Core/Drivers/ADCD_AdcDriver.c
Normal file
395
Core/Drivers/ADCD_AdcDriver.c
Normal file
@ -0,0 +1,395 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// 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 "../PDEF_ProjectDefinitions.h"
|
||||
#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)
|
||||
// Fault Detection not implemented yet
|
||||
#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 VOID vAttachDataReadyISR ( VOID );
|
||||
//PRIVATE VOID vDeattachDataReadyISR ( VOID );
|
||||
|
||||
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;
|
||||
U16 u16Data = 0;
|
||||
|
||||
boOK &= ((m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
|
||||
DIPO_vSetOutput(DIPO_eCS_C);
|
||||
boOK &= boWriteReg(REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE);
|
||||
DIPO_vResetOutput(DIPO_eCS_C);
|
||||
|
||||
DIPO_vSetOutput(DIPO_eCS_H);
|
||||
boOK &= boWriteReg(REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE);
|
||||
DIPO_vResetOutput(DIPO_eCS_H);
|
||||
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ADCD_dReadData
|
||||
// Description: Reads the conversion data form the ADC
|
||||
// Parameters: PU8 pu8Error error
|
||||
// Returns: DOUBLE conversion data
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL ADCD_dReadData(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 & 0x01) == 0x01)
|
||||
{
|
||||
*pu8Error |= ADCD_STATUS_DATA_ERROR;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DIPO_vSetOutput(CS);
|
||||
boOK &= boReadReg(REG_FAULT_STATUS, &u16Data, FALSE);
|
||||
DIPO_vResetOutput(CS);
|
||||
osMutexRelease( m_pstMutexID );
|
||||
//boWriteReg(REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE);
|
||||
*pu8Error |= u16Data & 0xFC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u16Data = u16Data >> 1;
|
||||
|
||||
*pu16Data = u16Data;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vEventCallback
|
||||
// Description: Callback for events
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//PRIVATE VOID vEventCallback( PVOID pvData )
|
||||
//{
|
||||
// osEventFlagsSet( m_pstEventID, (U32)pvData );
|
||||
//}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vAttachDataReadyISR
|
||||
// Description: Set Data Ready Pin Mode to ISR falling Edge
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//PRIVATE VOID vAttachDataReadyISR ( VOID )
|
||||
//{
|
||||
// GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
// /*Configure GPIO pin : ADC_RDY_Pin */
|
||||
// GPIO_InitStruct.Pin = m_u16DataReadyPin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// HAL_GPIO_Init((GPIO_TypeDef*)m_pstDataReadyPort, &GPIO_InitStruct);
|
||||
//}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vDeattachDataReadyISR
|
||||
// Description: Set Data Ready Pin Mode to Input
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//PRIVATE VOID vDeattachDataReadyISR ( VOID )
|
||||
//{
|
||||
//
|
||||
// HAL_GPIO_DeInit((GPIO_TypeDef*)m_pstDataReadyPort, m_u16DataReadyPin);
|
||||
|
||||
//}
|
||||
|
98
Core/Drivers/ADCD_AdcDriver.h
Normal file
98
Core/Drivers/ADCD_AdcDriver.h
Normal file
@ -0,0 +1,98 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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"
|
||||
//#include "../Application/CALI_Calibration.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_dReadData(ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
381
Core/Drivers/ANPI_AnalogPortsIn.c
Normal file
381
Core/Drivers/ANPI_AnalogPortsIn.c
Normal file
@ -0,0 +1,381 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// 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 "../PDEF_ProjectDefinitions.h"
|
||||
#include "ANPI_AnalogPortsIn.h"
|
||||
|
||||
//Application
|
||||
//#include "../Application/ELOG_ErrorLogger.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 5 // number of internal adc channels
|
||||
|
||||
// definitions of internal adc
|
||||
#define INT_ADC_REF_HI (3.28f) // HI int. reference voltage for conversion
|
||||
#define INT_ADC_REF_LO (0.0f) // LO int. reference voltage for conversion
|
||||
#define INT_ADC_REF (INT_ADC_REF_HI-INT_ADC_REF_LO)// int. reference voltage for conversion
|
||||
|
||||
#define BUFFER_SIZE NR_OF_ADCS * ANPI_OVERSAMPLING_FACTOR * 2
|
||||
#define BUFFER_HALF_SIZE NR_OF_ADCS * ANPI_OVERSAMPLING_FACTOR
|
||||
|
||||
#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 OFFSET 1.026f
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
// the number of ADCs
|
||||
typedef enum
|
||||
{
|
||||
eADC1 = 0,
|
||||
eNumberOfADCs,
|
||||
} EnADC;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ADC_TypeDef* pstADC;
|
||||
} StADCInit; // struct for internal ACD
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL FLOAT m_aflValues[ANPI_eInNumberOfInputs]; // values
|
||||
|
||||
LOCAL U16 m_au16ADCDataBuffer[eNumberOfADCs][BUFFER_SIZE];
|
||||
LOCAL U32 m_au32ADCRawData[eNumberOfADCs*NR_OF_ADCS] = {0}; // raw adc values
|
||||
|
||||
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] =
|
||||
{
|
||||
34.103f * 1.0f / ADC_RES * INT_ADC_REF, // 00 ANPI_eControlVoltage
|
||||
10.0f / ADC_RES * INT_ADC_REF, // 01 ANPI_eSupplyVoltage24V
|
||||
-(1.0f / (2.0f / 10.0f)) / ADC_RES * INT_ADC_REF, // 02 ANPI_eSupplyCurrent24V
|
||||
34.103f * 1.0f / ADC_RES * INT_ADC_REF, // 03 ANPI_eOutputVoltage
|
||||
(1.0f / (2.0f / 10.0f)) / ADC_RES * INT_ADC_REF, // 04 ANPI_eOutputCurrent
|
||||
};
|
||||
|
||||
// offsets for the values before it gets multiplied
|
||||
// Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_aflOffset1[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
0.0f, // 00 ANPI_eControlVoltage
|
||||
0.0f, // 01 ANPI_eSupplyVoltage24V
|
||||
1.65f * ADC_RES / INT_ADC_REF, // 02 ANPI_eSupplyCurrent24V
|
||||
0.0f, // 03 ANPI_eOutputVoltage
|
||||
1.65f * ADC_RES / INT_ADC_REF, // 04 ANPI_eOutputCurrent
|
||||
};
|
||||
|
||||
// offsets for the values after it gets multiplied
|
||||
// Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_aflOffset2[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
18.788f, // 00 ANPI_eControlVoltage
|
||||
0.0f, // 01 ANPI_eSupplyVoltage24V
|
||||
0.0f, // 02 ANPI_eSupplyCurrent24V
|
||||
18.788f, // 03 ANPI_eOutputVoltage
|
||||
0.0f, // 04 ANPI_eOutputCurrent
|
||||
};
|
||||
|
||||
// initial values. Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_afInitValues[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
0.0f, // 00 ANPI_eControlVoltage
|
||||
0.0f, // 01 ANPI_eSupplyVoltage24V
|
||||
0.0f, // 02 ANPI_eSupplyCurrent24V
|
||||
0.0f, // 03 ANPI_eOutputVoltage
|
||||
0.0f, // 04 ANPI_eOutputCurrent
|
||||
};
|
||||
|
||||
// configuration data for the ADC
|
||||
// order must fit enumeration EnADC
|
||||
LOCAL CONST StADCInit m_astADCInit[eNumberOfADCs] =
|
||||
{
|
||||
{ADC1}, // 00 eADC1
|
||||
};
|
||||
// inputs are connected to the following ADCs
|
||||
// ANPI_eControlVoltage ADC1, Channel 8
|
||||
// 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 ANPI_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;
|
||||
|
||||
// set the init values
|
||||
UTIL_vMemCopyU32( (PU32)m_afInitValues, (PU32)m_aflValues, sizeof(m_aflValues)/sizeof(FLOAT) );
|
||||
|
||||
boOK &= ((m_pstThreadID = osThreadNew( ANPI_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 ANPI_vTask( PVOID arg )
|
||||
{
|
||||
U32 u32Flags;
|
||||
U16 u16Offset;
|
||||
|
||||
osDelay( 1 ); // Wait 1ms to have a Valid Value
|
||||
|
||||
HAL_ADC_Start_DMA( &hadc1, (PU32)&m_au16ADCDataBuffer[eADC1][0], BUFFER_SIZE);
|
||||
|
||||
|
||||
while ( TRUE )
|
||||
{
|
||||
u32Flags = osEventFlagsWait( m_pstEventID, ANPI_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
|
||||
|
||||
if( u32Flags & ANPI_ADC_FULL_COMPLETE )
|
||||
{
|
||||
u16Offset = BUFFER_HALF_SIZE;
|
||||
}
|
||||
|
||||
if( u32Flags & ANPI_ADC_HALF_COMPLETE )
|
||||
{
|
||||
u16Offset = 0;
|
||||
}
|
||||
|
||||
// reset the sum for calculating the mean
|
||||
memset( m_au32ADCRawData, 0, sizeof(m_au32ADCRawData) );
|
||||
|
||||
// calculate the mean of the samples to get a better result
|
||||
|
||||
// build the sum of the values...
|
||||
for(U16 u16Cnt = 0; u16Cnt < BUFFER_HALF_SIZE; u16Cnt++ )
|
||||
{
|
||||
m_au32ADCRawData[ u16Cnt % NR_OF_ADCS ] += m_au16ADCDataBuffer[eADC1][u16Cnt + u16Offset];
|
||||
}
|
||||
|
||||
// ... multiply by the conversion factor and add the offset
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
|
||||
for(U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
|
||||
{
|
||||
m_aflValues[u16Cnt] = ((((FLOAT)m_au32ADCRawData[u16Cnt] / (FLOAT)ANPI_OVERSAMPLING_FACTOR * OFFSET) - (FLOAT)m_aflOffset1[u16Cnt] ) *
|
||||
(FLOAT)m_aflConversionFactor[u16Cnt]) - (FLOAT)m_aflOffset2[u16Cnt];
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ANPI_flGetInputValue
|
||||
// Description: Gets the value of the analog input
|
||||
// Parameters: ANPI_EnAnalogInput enInput Analog input to read
|
||||
// Returns: FLOAT flValue Value from ADC in V
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
FLOAT ANPI_flGetInputValue( ANPI_EnAnalogInput enInput )
|
||||
{
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
FLOAT flValue = m_aflValues[enInput];
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
|
||||
return( flValue );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// 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 )
|
||||
{
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_NONE )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_INTERNAL )
|
||||
{
|
||||
|
||||
}
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_OVR )
|
||||
{
|
||||
//ELOG_ADDLOG( ELOG_eADCOverrunError, NULL );
|
||||
}
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_DMA )
|
||||
{
|
||||
// ELOG_ADDLOG( ELOG_eDMAHTransferError, NULL );
|
||||
}
|
||||
|
||||
// check rx dma transfer error
|
||||
if( hadc->DMA_Handle->ErrorCode & HAL_DMA_ERROR_TE )
|
||||
{
|
||||
// ELOG_ADDLOG( ELOG_eDMAHTransferError, NULL );
|
||||
}
|
||||
|
||||
}
|
110
Core/Drivers/ANPI_AnalogPortsIn.h
Normal file
110
Core/Drivers/ANPI_AnalogPortsIn.h
Normal file
@ -0,0 +1,110 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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).
|
||||
//=================================================================================================
|
||||
|
||||
// attention: perhaps you have to change the ADC sample time in ANPI_AnalogPortsIn.c
|
||||
#define ANPI_OVERSAMPLING_FACTOR 64
|
||||
|
||||
#if( ANPI_OVERSAMPLING_FACTOR % 2 != 0 )
|
||||
#error "ANPI_OVERSAMPLING_FACTOR must be power of 2!"
|
||||
#endif
|
||||
|
||||
//=================================================================================================
|
||||
// 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_eControlVoltage = 0, // 00 control Voltage
|
||||
ANPI_eSupplyVoltage24V = 1, // 01 voltage of 24V power supply
|
||||
ANPI_eSupplyCurrent24V = 2, // 02 current of 24V power supply
|
||||
ANPI_eOutputVoltage = 3, // 03 output voltage peltier element
|
||||
ANPI_eOutputCurrent = 4, // 04 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 );
|
||||
FLOAT ANPI_flGetInputValue( ANPI_EnAnalogInput enInput );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
169
Core/Drivers/ANPO_AnalogPortsOut.c
Normal file
169
Core/Drivers/ANPO_AnalogPortsOut.c
Normal file
@ -0,0 +1,169 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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 "../PDEF_ProjectDefinitions.h"
|
||||
#include "ANPO_AnalogPortsOut.h"
|
||||
|
||||
//Application
|
||||
//#include "../Application/ELOG_ErrorLogger.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;
|
||||
|
||||
HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// 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 RawData = u32ConvertVoltagetoRaw( Voltage );
|
||||
|
||||
boOK &= HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, RawData);
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// 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.28;
|
||||
|
||||
return RawData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
99
Core/Drivers/ANPO_AnalogPortsOut.h
Normal file
99
Core/Drivers/ANPO_AnalogPortsOut.h
Normal file
@ -0,0 +1,99 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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
|
214
Core/Drivers/CAND_CanDriver.c
Normal file
214
Core/Drivers/CAND_CanDriver.c
Normal file
@ -0,0 +1,214 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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 "../PDEF_ProjectDefinitions.h"
|
||||
#include "CAND_CanDriver.h"
|
||||
|
||||
//Application
|
||||
//#include "../Application/ELOG_ErrorLogger.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).
|
||||
//=================================================================================================
|
||||
CAND_pfnRxCallback m_pfnRxCallback = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// 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;
|
||||
|
||||
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_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( U8 u8Id, U8 u8Len, PU8 pu8Buffer ){
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if( u8Len > 8 ) return FALSE;
|
||||
|
||||
CAN_TxHeaderTypeDef header = {
|
||||
u8Id,
|
||||
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.u8Id = header.StdId;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
101
Core/Drivers/CAND_CanDriver.h
Normal file
101
Core/Drivers/CAND_CanDriver.h
Normal file
@ -0,0 +1,101 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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 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).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// 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 u8Id;
|
||||
U8 au8Data[8];
|
||||
U8 u8Len;
|
||||
} 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( U8 u8Id, U8 u8Len, PU8 pu8Buffer );
|
||||
VOID CAND_vSetRxCallback( CAND_pfnRxCallback pfnRxCallback );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
330
Core/Drivers/DIPO_DigitalPorts.c
Normal file
330
Core/Drivers/DIPO_DigitalPorts.c
Normal file
@ -0,0 +1,330 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// 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.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 "../PDEF_ProjectDefinitions.h"
|
||||
#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
|
||||
{GPIOB, {GPIO_PIN_4, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE}, // 01 DIPO_eADR2
|
||||
{GPIOB, {GPIO_PIN_3, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE}, // 02 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
|
||||
{GPIOA, {GPIO_PIN_10, 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.
|
||||
//=================================================================================================
|
131
Core/Drivers/DIPO_DigitalPorts.h
Normal file
131
Core/Drivers/DIPO_DigitalPorts.h
Normal file
@ -0,0 +1,131 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// 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_eADR2 = 1, // 01 DIP 2
|
||||
DIPO_eADR1 = 2, // 02 DIP 3
|
||||
DIPO_eADR0 = 3, // 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
|
95
Core/Drivers/EXTI_ExtiHandler.h
Normal file
95
Core/Drivers/EXTI_ExtiHandler.h
Normal file
@ -0,0 +1,95 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: High Stability Current Source
|
||||
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: EXTI Handler
|
||||
// Filename: EXTI_ExtiHandler.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef EXTI_EXTIHANDLER_H
|
||||
#define EXTI_EXTIHANDLER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
typedef VOID (*EXTI_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).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// 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).
|
||||
//=================================================================================================
|
||||
|
||||
VOID EXTI_vSetCallback( U16 GPIO_Pin, EXTI_pfnCallback pfnCallback, PVOID pvCallbackArgument );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
225
Core/Drivers/PECO_PeltierController.c
Normal file
225
Core/Drivers/PECO_PeltierController.c
Normal file
@ -0,0 +1,225 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Peltier Controller
|
||||
// Filename: PECO_PeltierController.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the Peltier Controller Output
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "../PDEF_ProjectDefinitions.h"
|
||||
#include "PECO_PeltierController.h"
|
||||
|
||||
// Driver
|
||||
#include "../Drivers/ANPO_AnalogPortsOut.h"
|
||||
#include "../Drivers/DIPO_DigitalPorts.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
{
|
||||
"PECO_Thread", // name of the thread
|
||||
osThreadDetached, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for stack
|
||||
1024, // size of stack
|
||||
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
|
||||
0, // TrustZone module identifier
|
||||
0, // reserved (must be 0)
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE VOID PECO_vTask( PVOID arg );
|
||||
BOOL boSetPeltierVoltage( S16 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: PECO_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL PECO_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ((m_pstThreadID = osThreadNew( PECO_vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
|
||||
|
||||
boSetPeltierVoltage(0);
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_boSetTemperature
|
||||
// Description: Sets the Peltier Controller to a Specific Temperature
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL PECO_boSetTemperature( S16 Temperature ){
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= boSetPeltierVoltage( Temperature );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_Enable
|
||||
// Description: Enables the Peltier Controller Output
|
||||
// Parameters: BOOL Enable
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID PECO_Enable( BOOL Enable ){
|
||||
DIPO_vSetState(DIPO_eEN, Enable);
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_vTask
|
||||
// Description: PECO_vTask
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID PECO_vTask( PVOID arg )
|
||||
{
|
||||
|
||||
/*PECO_Enable(TRUE);
|
||||
|
||||
while ( TRUE )
|
||||
{
|
||||
|
||||
boSetPeltierVoltage(1);
|
||||
osDelay(5000);
|
||||
boSetPeltierVoltage(0);
|
||||
osDelay(5000);
|
||||
boSetPeltierVoltage(-1);
|
||||
osDelay(5000);
|
||||
boSetPeltierVoltage(0);
|
||||
osDelay(5000);
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boSetPeltierVoltage
|
||||
// Description: Sets the Peltier elements to a specific Voltage
|
||||
// Parameters: S8 Voltage (14V - -8V)
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL boSetPeltierVoltage( S16 Voltage ){
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if( Voltage > 14000 ) Voltage = 14000;
|
||||
if( Voltage < -8000 ) Voltage = -8000;
|
||||
|
||||
//Voltage -= 0.6; // Offset (hoffentlich nicht mehr)
|
||||
|
||||
boOK &= ANPO_boSetVoltage( ((((FLOAT)Voltage)/1000) + 20.088) / 34.103 );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
|
95
Core/Drivers/PECO_PeltierController.h
Normal file
95
Core/Drivers/PECO_PeltierController.h
Normal file
@ -0,0 +1,95 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Peltier Controller
|
||||
// Filename: PECO_PeltierController.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef PECO_PELTIERCONTROLLER_H
|
||||
#define PECO_PELTIERCONTROLLER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL PECO_boInitializeModule( VOID );
|
||||
BOOL PECO_boSetTemperature( S16 Temperature );
|
||||
VOID PECO_Enable( BOOL Enable );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
378
Core/Drivers/SPID_SpiDriver.c
Normal file
378
Core/Drivers/SPID_SpiDriver.c
Normal file
@ -0,0 +1,378 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// 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 "../PDEF_ProjectDefinitions.h"
|
||||
#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 );
|
||||
}
|
||||
|
113
Core/Drivers/SPID_SpiDriver.h
Normal file
113
Core/Drivers/SPID_SpiDriver.h
Normal 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
|
332
Core/Drivers/TEMP_Temperature.c
Normal file
332
Core/Drivers/TEMP_Temperature.c
Normal file
@ -0,0 +1,332 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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 "../Application/VARH_VariableHandler.h"
|
||||
#include "../PDEF_ProjectDefinitions.h"
|
||||
#include "TEMP_Temperature.h"
|
||||
|
||||
// Application
|
||||
//#include "../Application/ELOG_ErrorLogger.h"
|
||||
//#include "../Application/RTOS_RealTimeOs.h"
|
||||
|
||||
// Toolbox
|
||||
//#include "../Toolbox/ASRT_Assert.h"
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// Drivers
|
||||
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
#include "SPID_SpiDriver.h"
|
||||
#include "ADCD_ADCDriver.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define REFRESH_MS 100
|
||||
|
||||
// Konstanten f<>r Temperaturberechung
|
||||
#define RTD_A 3.9083e-3
|
||||
#define RTD_B -5.775e-7
|
||||
|
||||
#define R_REF 3900
|
||||
#define R_NOMINAL 1000
|
||||
|
||||
//=================================================================================================
|
||||
// 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 vTempTask( PVOID arg );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL CONST osMutexAttr_t m_stMutexAttr =
|
||||
{
|
||||
"TEMP_Mutex", // human readable mutex name
|
||||
osMutexRecursive | osMutexPrioInherit, // attr_bits
|
||||
NULL, // memory for control block
|
||||
0U // size for control block
|
||||
};
|
||||
|
||||
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;
|
||||
LOCAL osMutexId_t m_pstMutexID = NULL;
|
||||
|
||||
LOCAL FLOAT m_flTempData[ADCD_eNumberOfTemps];
|
||||
|
||||
//=================================================================================================
|
||||
// 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( vTempTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
|
||||
boOK &= ((m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: TEMP_dGetValue
|
||||
// Description: Gets the desired temperature
|
||||
// Parameters: ATEMP_EnTemperature enInput
|
||||
// Returns: DOUBLE DValue Value from ADC
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
FLOAT TEMP_dGetValue( ADCD_EnTemps enTemp )
|
||||
{
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DOUBLE dValue = m_flTempData[enTemp];
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
return( dValue );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: TEMP_boRegisterEventNotification
|
||||
// Description: Register for a notification when there are new values
|
||||
// Parameters: TEMP_pfnEventCallback pfnCallback
|
||||
// PVOID pvCallbackArgument
|
||||
// Returns: TRUE, if successfull, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//BOOL TEMP_boRegisterEventNotification( TEMP_pfnEventCallback pfnCallback, PVOID pvCallbackArgument )
|
||||
//{
|
||||
// BOOL boRet = FALSE;
|
||||
// osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
// for( U16 u16Cnt = 0; u16Cnt < NUMBER_OF_EVENT_CALLBACKS; u16Cnt++ )
|
||||
// {
|
||||
// if( m_apfnEventCallback[u16Cnt] == NULL )
|
||||
// {
|
||||
// m_apfnEventCallback[u16Cnt] = pfnCallback;
|
||||
// m_apvCallbackArgument[u16Cnt] = pvCallbackArgument;
|
||||
// boRet = TRUE;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// osMutexRelease( m_pstMutexID );
|
||||
// return( boRet );
|
||||
//}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vTempTask
|
||||
// Description: vTempTask
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE VOID vTempTask( PVOID arg )
|
||||
{
|
||||
UNUSED( arg );
|
||||
U32 u32Flags;
|
||||
|
||||
BOOL boOK = TRUE;
|
||||
U8 error;
|
||||
U16 u16ADC_data[ADCD_eNumberOfTemps];
|
||||
U8 u8Channel;
|
||||
|
||||
FLOAT temp = 0;
|
||||
|
||||
osDelay(10);
|
||||
|
||||
while( TRUE )
|
||||
{
|
||||
|
||||
|
||||
//u32Flags = osEventFlagsWait( m_pstEventID, EVENT_REFRESH, osFlagsWaitAny, osWaitForever );
|
||||
|
||||
//if( u32Flags & EVENT_REFRESH )
|
||||
//{
|
||||
|
||||
boOK &= ADCD_dReadData(ADCD_eHot, &error, &u16ADC_data[ADCD_eHot]);
|
||||
if( boOK )
|
||||
{
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
m_flTempData[ADCD_eHot] = flConvertADCData( u16ADC_data[ADCD_eHot] );
|
||||
//temp = flConvertADCData( u16ADC_data[ADCD_eHot] ); // for debugging
|
||||
//VARH_vSetVariableData( VARH_eTempHeatSink + u8Channel, (VARH_UVariable)(FLOAT)m_dbTempData[u8Channel] );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
} else {
|
||||
boOK = TRUE;
|
||||
}
|
||||
boOK &= ADCD_dReadData(ADCD_eCold, &error, &u16ADC_data[ADCD_eCold]);
|
||||
if( boOK )
|
||||
{
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
m_flTempData[ADCD_eCold] = flConvertADCData( u16ADC_data[ADCD_eCold] );
|
||||
//temp = flConvertADCData( u16ADC_data[ADCD_eCold] ); // for debugging
|
||||
//VARH_vSetVariableData( VARH_eTempHeatSink + u8Channel, (VARH_UVariable)(FLOAT)m_dbTempData[u8Channel] );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
} else {
|
||||
boOK = TRUE;
|
||||
}
|
||||
//}
|
||||
|
||||
osDelay(REFRESH_MS);
|
||||
|
||||
|
||||
|
||||
|
||||
// wait for ADC conversions completed
|
||||
// u32Flags = osEventFlagsWait( m_pstEventID, OS_EVENT_ADC_COMPLETED_FLAG, osFlagsWaitAll , ADC_TIMEOUT_MS );
|
||||
// boTimeout = (u32Flags == osFlagsErrorTimeout) ? TRUE : FALSE;
|
||||
// boError = FALSE;
|
||||
//
|
||||
// // check if we have a timeout
|
||||
// if( boTimeout )
|
||||
// {
|
||||
// //ELOG_ADD_LOG( ELOG_eADCTimeout );
|
||||
// }
|
||||
//
|
||||
// // read ADC data
|
||||
// if( !(boSuccess = boReadADCData() ) )
|
||||
// {
|
||||
// //ELOG_ADD_LOG( ELOG_eADCReadingDataFailed );
|
||||
// }
|
||||
//// vIncrementChannel();
|
||||
//
|
||||
// // reinit ADC on error, on spi failure or when timeout reached
|
||||
// if( boTimeout || !boSuccess )
|
||||
// {
|
||||
// boError = TRUE;
|
||||
//// vADCInit();
|
||||
// }
|
||||
|
||||
// // send event to worker task, if all channels completed and no error
|
||||
// if( m_stADCData.u8Cannel == 0 && !boError )
|
||||
// {
|
||||
// // send event to tasks
|
||||
// for( U16 u16Cnt = 0; u16Cnt < NUMBER_OF_EVENT_CALLBACKS; u16Cnt++ )
|
||||
// {
|
||||
// if( m_apfnEventCallback[u16Cnt] != NULL )
|
||||
// {
|
||||
// m_apfnEventCallback[u16Cnt]( m_apvCallbackArgument[u16Cnt] );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: flConvertADCData
|
||||
// Description: Converts resistor value to temperature data
|
||||
// Parameters: U16 u16RTemp
|
||||
// Returns: U16, temperature in Celcius
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE FLOAT flConvertADCData( U16 u16RTemp )
|
||||
{
|
||||
|
||||
u16RTemp = u16RTemp / 1000;
|
||||
|
||||
FLOAT flT = 9.9714f * u16RTemp;
|
||||
flT += 235.904f;
|
||||
flT *= u16RTemp;
|
||||
flT += -245.876f;
|
||||
|
||||
return( flT );
|
||||
}
|
90
Core/Drivers/TEMP_Temperature.h
Normal file
90
Core/Drivers/TEMP_Temperature.h
Normal file
@ -0,0 +1,90 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (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 );
|
||||
//BOOL TEMP_boRegisterEventNotification( TEMP_pfnEventCallback pfnCallback, PVOID pvCallbackArgument );
|
||||
FLOAT TEMP_dGetValue( ADCD_EnTemps enTemp );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user