init new PC
This commit is contained in:
190
Core/Application/INIT_Initialization.c
Normal file
190
Core/Application/INIT_Initialization.c
Normal file
@ -0,0 +1,190 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: INIT_Initialization
|
||||
// Filename: INIT_Initialization.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: Initialization module
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
#include "INIT_Initialization.h"
|
||||
|
||||
// Application
|
||||
#include "VARH_VariableHandler.h"
|
||||
#include "PECO_PeltierController.h"
|
||||
#include "MAIN_MainApplication.h"
|
||||
|
||||
// Drivers
|
||||
#include "../Drivers/USFL_UserFlash.h"
|
||||
#include "../Drivers/ANPI_AnalogPortsIn.h"
|
||||
#include "../Drivers/ANPO_AnalogPortsOut.h"
|
||||
#include "../Drivers/SPID_SpiDriver.h"
|
||||
#include "../Drivers/DIPO_DigitalPorts.h"
|
||||
#include "../Drivers/ADCD_AdcDriver.h"
|
||||
#include "../Drivers/TEMP_Temperature.h"
|
||||
#include "../Drivers/CAND_CanDriver.h"
|
||||
#include "../Drivers/ERRH_ErrorHandler.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
{
|
||||
"INIT_Thread", // name of the thread
|
||||
osThreadDetached, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for stack
|
||||
1024, // size of stack
|
||||
osPriorityHigh7, // initial thread priority (default: osPriorityNormal)
|
||||
0, // TrustZone module identifier
|
||||
0, // reserved (must be 0)
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE VOID vTask ( PVOID arg )__NORETURN;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: INIT_boCreateTask
|
||||
// Description: Create the init Task
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL INIT_boCreateTask( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ((m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute )) != NULL); // create init Task
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vInitTask
|
||||
// Description: Initialization Task, priority must be high!
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE VOID vTask( PVOID arg )
|
||||
{
|
||||
UNUSED( arg );
|
||||
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
//boOK &= USFL_boInitializeModule();
|
||||
boOK &= VARH_boInitializeModule();
|
||||
|
||||
boOK &= DIPO_boInitializeModule();
|
||||
boOK &= ANPI_boInitializeModule();
|
||||
boOK &= ANPO_boInitializeModule();
|
||||
boOK &= SPID_boInitializeModule();
|
||||
boOK &= ADCD_boInitializeModule();
|
||||
boOK &= TEMP_boInitializeModule();
|
||||
boOK &= CAND_boInitializeModule();
|
||||
|
||||
boOK &= PECO_boInitializeModule();
|
||||
boOK &= MAIN_boInitializeModule();
|
||||
|
||||
if( !boOK ){
|
||||
osKernelLock(); // lock kernel to prevent task switch
|
||||
while( 1 ){ // Toggle Error LED fast
|
||||
DIPO_vToggleOutput( DIPO_eLED );
|
||||
DELAY_MS( 100 );
|
||||
}
|
||||
}
|
||||
|
||||
osThreadSuspend( m_pstThreadID );
|
||||
while( 1 );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
94
Core/Application/INIT_Initialization.h
Normal file
94
Core/Application/INIT_Initialization.h
Normal file
@ -0,0 +1,94 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Initialization
|
||||
// Filename: INIT_Initialization
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef INIT_INITIALIZATION_H
|
||||
#define INIT_INITIALIZATION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL INIT_boCreateTask( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
319
Core/Application/MAIN_MainApplication.c
Normal file
319
Core/Application/MAIN_MainApplication.c
Normal file
@ -0,0 +1,319 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Main Application
|
||||
// Filename: MAIN_MainApplication.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: TEC - Peltier Controller Communication handler
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "MAIN_MainApplication.h"
|
||||
|
||||
// Application
|
||||
#include "VARH_VariableHandler.h"
|
||||
#include "PECO_PeltierController.h"
|
||||
|
||||
// Drivers
|
||||
#include "../Drivers/TEMP_Temperature.h"
|
||||
#include "../Drivers/DIPO_DigitalPorts.h"
|
||||
#include "../Drivers/CAND_CanDriver.h"
|
||||
#include "../Drivers/ANPI_AnalogPortsIn.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define MSG_QUEUE_SIZE 8
|
||||
|
||||
#define EVENT_NEW_MESSAGE ((U32)(1<<0))
|
||||
#define EVENT_TIMER_UPDATE ((U32)(1<<1))
|
||||
#define EVENT_WATCHDOG ((U32)(1<<2))
|
||||
|
||||
#define EVENT_FLAGS_ALL ( EVENT_NEW_MESSAGE | EVENT_TIMER_UPDATE | EVENT_WATCHDOG )
|
||||
|
||||
#define COMMAND_NONE 0
|
||||
#define COMMAND_ON 1
|
||||
#define COMMAND_OFF 2
|
||||
#define COMMAND_WATCHDOG 3
|
||||
|
||||
#define WATCHDOG 33000
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE VOID vTask( PVOID arg );
|
||||
PRIVATE VOID vEventCallback( PVOID pvData );
|
||||
PRIVATE VOID vMsgRxCallback( CAND_Message stMessage );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
LOCAL osMessageQueueId_t m_pstCANRxMsgQueueID = NULL;
|
||||
LOCAL osEventFlagsId_t m_pstEventID = NULL;
|
||||
|
||||
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
|
||||
LOCAL osTimerId_t m_pstWatchdogTimer = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
{
|
||||
"MAIN_Thread", // name of the thread
|
||||
osThreadDetached, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for stack
|
||||
1024, // size of stack
|
||||
osPriorityAboveNormal1, // initial thread priority (default: osPriorityNormal)
|
||||
0, // TrustZone module identifier
|
||||
0, // reserved (must be 0)
|
||||
};
|
||||
|
||||
LOCAL CONST osMessageQueueAttr_t stCANRxMsgQueueAttribute =
|
||||
{
|
||||
"MAIN_CAN_Rx_Queue", // name of the message queue
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for data storage
|
||||
0, // size of provided memory for data storage
|
||||
};
|
||||
|
||||
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
|
||||
{
|
||||
"MAIN_Event_Flags", // name of the event flags
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
};
|
||||
|
||||
LOCAL CONST osTimerAttr_t stTimerAttribute =
|
||||
{
|
||||
"MAIN_UpdateTimer", // name of the timer
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
};
|
||||
|
||||
LOCAL CONST osTimerAttr_t stWatchdogTimerAttribute =
|
||||
{
|
||||
"MAIN_Watchdog", // name of the timer
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: MAIN_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL MAIN_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ( ( m_pstEventID = osEventFlagsNew( &stEventAttribute ) ) == NULL ) ? FALSE : TRUE;
|
||||
boOK &= ( ( m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute ) ) == NULL ) ? FALSE : TRUE;
|
||||
boOK &= ( ( m_pstCANRxMsgQueueID = osMessageQueueNew( MSG_QUEUE_SIZE, sizeof( CAND_Message ), &stCANRxMsgQueueAttribute ) ) == NULL ) ? FALSE : TRUE;
|
||||
boOK &= ( m_pstUpdateTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute ) ) == NULL ? FALSE : TRUE;
|
||||
boOK &= ( m_pstWatchdogTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stWatchdogTimerAttribute ) ) == NULL ? FALSE : TRUE;
|
||||
|
||||
boOK &= (osTimerStart( m_pstUpdateTimer, 1000 ) == osOK ) ? TRUE : FALSE;
|
||||
//boOK &= (osTimerStart( m_pstWatchdogTimer, WATCHDOG ) == osOK ) ? TRUE : FALSE;
|
||||
|
||||
CAND_vSetRxCallback( vMsgRxCallback );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vMainTask
|
||||
// Description: Main Application Task
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE VOID vTask( PVOID arg )
|
||||
{
|
||||
UNUSED( arg );
|
||||
U32 u32Flags;
|
||||
|
||||
U8 au8Buffer[8];
|
||||
|
||||
while( TRUE )
|
||||
{
|
||||
|
||||
u32Flags = osEventFlagsWait( m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever ); // wait until flags getting triggered
|
||||
|
||||
if( u32Flags & EVENT_NEW_MESSAGE ) { // New message from CAN
|
||||
|
||||
CAND_Message stMessage;
|
||||
osMessageQueueGet( m_pstCANRxMsgQueueID, &stMessage, NULL, 0 ); // get message from queue
|
||||
|
||||
U8 u8Register = stMessage.au8Data[0];
|
||||
U8 u8Type = stMessage.u8Type;
|
||||
|
||||
if( u8Type == MESSAGE_TYPE_READ ){ // Message type read
|
||||
|
||||
osDelay(100);
|
||||
|
||||
if( u8Register >= VARH_eNumberOfVariables ){ // check register
|
||||
// send register not found
|
||||
au8Buffer[0] = 0xFF;
|
||||
CAND_boSendMessage( stMessage.u16Id, au8Buffer, 1 );
|
||||
} else {
|
||||
VARH_UVariable uVariable = VARH_uGetVariableData(u8Register); // get data
|
||||
au8Buffer[0] = u8Register;
|
||||
UTIL_vMemCopy(&uVariable, &au8Buffer[1], 4); // copy data in buffer
|
||||
|
||||
CAND_boSendMessage( stMessage.u16Id, au8Buffer, 5 );
|
||||
}
|
||||
|
||||
} else if( u8Type == MESSAGE_TYPE_WRITE ){ // Message type writeset
|
||||
VARH_UVariable uData;
|
||||
UTIL_vMemCopy(&stMessage.au8Data[1], &uData, 4);
|
||||
|
||||
VARH_vSetVariableData(u8Register, uData);
|
||||
} else if( u8Type == MESSAGE_TYPE_COMMAND ){ // Message type command
|
||||
|
||||
switch (u8Register)
|
||||
{
|
||||
case COMMAND_ON:
|
||||
PECO_Enable( TRUE );
|
||||
break;
|
||||
|
||||
case COMMAND_OFF:
|
||||
PECO_Enable( FALSE );
|
||||
break;
|
||||
case COMMAND_WATCHDOG:
|
||||
osTimerStart( m_pstWatchdogTimer, WATCHDOG );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( u32Flags & EVENT_TIMER_UPDATE )
|
||||
{
|
||||
DIPO_vToggleOutput( DIPO_eLED );
|
||||
}
|
||||
|
||||
if( u32Flags & EVENT_WATCHDOG )
|
||||
{
|
||||
PECO_Enable( FALSE );
|
||||
// TODO: WATCHDOG: what else?
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vEventCallback
|
||||
// Description: Callback for events
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE VOID vEventCallback( PVOID pvData )
|
||||
{
|
||||
osEventFlagsSet( m_pstEventID, (U32)pvData );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vEventCallback
|
||||
// Description: Callback for events
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE VOID vMsgRxCallback( CAND_Message stMessage )
|
||||
{
|
||||
osMessageQueuePut( m_pstCANRxMsgQueueID, &stMessage, 0, 0 );
|
||||
osEventFlagsSet( m_pstEventID, EVENT_NEW_MESSAGE );
|
||||
}
|
||||
|
||||
|
92
Core/Application/MAIN_MainApplication.h
Normal file
92
Core/Application/MAIN_MainApplication.h
Normal file
@ -0,0 +1,92 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Main Application
|
||||
// Filename: MAIN_MainApplication.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MAIN_MAINAPPLICATION_H
|
||||
#define MAIN_MAINAPPLICATION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL MAIN_boInitializeModule( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
321
Core/Application/PECO_PeltierController.c
Normal file
321
Core/Application/PECO_PeltierController.c
Normal file
@ -0,0 +1,321 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Peltier Controller
|
||||
// Filename: PECO_PeltierController.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the Peltier Controller Output
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "PECO_PeltierController.h"
|
||||
|
||||
//Application
|
||||
#include "../Application/VARH_VariableHandler.h"
|
||||
|
||||
// Driver
|
||||
#include "ANPO_AnalogPortsOut.h"
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define REFRESH 100 // Refresh rate in ms
|
||||
|
||||
#define EVENT_TIMER_UPDATE ((U32)(1<<0))
|
||||
|
||||
#define EVENT_FLAGS_ALL ( EVENT_TIMER_UPDATE )
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
|
||||
LOCAL osEventFlagsId_t m_pstEventID = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
{
|
||||
"PECO_Thread", // name of the thread
|
||||
osThreadDetached, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for stack
|
||||
1024, // size of stack
|
||||
osPriorityHigh, // initial thread priority (default: osPriorityNormal)
|
||||
0, // TrustZone module identifier
|
||||
0, // reserved (must be 0)
|
||||
};
|
||||
|
||||
LOCAL CONST osTimerAttr_t stTimerAttribute =
|
||||
{
|
||||
"PECO_UpdateTimer", // name of the timer
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
};
|
||||
|
||||
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
|
||||
{
|
||||
"PECO_Event_Flags", // name of the event flags
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
};
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE VOID vTask( PVOID arg );
|
||||
BOOL boSetPeltierVoltage( FLOAT Voltage );
|
||||
PRIVATE VOID vEventCallback( PVOID pvData );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
extern IWDG_HandleTypeDef hiwdg;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL PECO_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ( ( m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute ) ) == NULL ) ? FALSE : TRUE;
|
||||
boOK &= ( ( m_pstEventID = osEventFlagsNew( &stEventAttribute ) ) == NULL) ? FALSE : TRUE;
|
||||
boOK &= ( m_pstUpdateTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute ) ) == NULL ? FALSE : TRUE;
|
||||
|
||||
boSetPeltierVoltage(0);
|
||||
|
||||
boOK &= (osTimerStart( m_pstUpdateTimer, REFRESH ) == osOK ) ? TRUE : FALSE;
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_Enable
|
||||
// Description: Enables the Peltier Controller Output
|
||||
// Parameters: BOOL boEnable
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID PECO_Enable( BOOL boEnable ){
|
||||
DIPO_vSetState(DIPO_eEN, boEnable);
|
||||
VARH_vSetVariableDataFromSystemU32( VARH_ePowerState, (U32)boEnable );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_isEnabled
|
||||
// Description: Returns true if the Output is enabled
|
||||
// Parameters: None
|
||||
// Returns: BOOL boEnableOutput
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL PECO_isEnabled( VOID ){
|
||||
return (BOOL)VARH_u32GetVariableData( VARH_ePowerState );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vTask
|
||||
// Description: Task
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID vTask( PVOID arg )
|
||||
{
|
||||
|
||||
UNUSED( arg );
|
||||
U32 u32Flags;
|
||||
|
||||
FLOAT last_error = 0;
|
||||
FLOAT integral = 0;
|
||||
FLOAT dT = REFRESH / 1000.0f; // 1s
|
||||
|
||||
while ( TRUE )
|
||||
{
|
||||
|
||||
u32Flags = osEventFlagsWait( m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
|
||||
|
||||
if( u32Flags & EVENT_TIMER_UPDATE )
|
||||
{
|
||||
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
if ( PECO_isEnabled() )
|
||||
{
|
||||
|
||||
if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConstTemp )
|
||||
{
|
||||
// TODO: check the measurements, everything ok?
|
||||
|
||||
|
||||
// PID Regelung
|
||||
|
||||
FLOAT kp = VARH_flGetVariableData( VARH_ePID_kp );
|
||||
FLOAT ki = VARH_flGetVariableData( VARH_ePID_ki );
|
||||
FLOAT kd = VARH_flGetVariableData( VARH_ePID_kd );
|
||||
FLOAT max = VARH_flGetVariableData( VARH_ePID_Max );
|
||||
FLOAT min = VARH_flGetVariableData( VARH_ePID_Min );
|
||||
|
||||
FLOAT Tnow = VARH_flGetVariableData( VARH_eTemp_C );
|
||||
FLOAT Tset = VARH_flGetVariableData( VARH_ePID_Temp );
|
||||
|
||||
// -error
|
||||
FLOAT error = Tnow - Tset;
|
||||
|
||||
// proportional term
|
||||
FLOAT P = kp * error;
|
||||
|
||||
// integral term
|
||||
integral += error * dT;
|
||||
FLOAT I = ki * integral;
|
||||
|
||||
// derivative term
|
||||
FLOAT D = kd * ( error - last_error ) / dT;
|
||||
last_error = error;
|
||||
|
||||
// total
|
||||
FLOAT output = P + I + D;
|
||||
|
||||
// limitter
|
||||
if ( output > max ){
|
||||
output = max;
|
||||
integral = 0;
|
||||
} else if ( output < min ){
|
||||
output = min;
|
||||
integral = 0;
|
||||
}
|
||||
|
||||
boSetPeltierVoltage( output ); // set the output
|
||||
|
||||
} else if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConst_Voltage )
|
||||
{
|
||||
boSetPeltierVoltage( VARH_flGetVariableData( VARH_eControlVoltage ) ); // set the output
|
||||
last_error = 0;
|
||||
integral = 0;
|
||||
}
|
||||
} else {
|
||||
last_error = 0;
|
||||
integral = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boSetPeltierVoltage
|
||||
// Description: Sets the Peltier elements to a specific Voltage
|
||||
// Parameters: S8 Voltage (12V - -3V)
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL boSetPeltierVoltage( FLOAT Voltage ){
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if( Voltage > 12 ) Voltage = 12;
|
||||
if( Voltage < -3 ) Voltage = -3;
|
||||
|
||||
ANPO_boSetVoltage( ( ( (FLOAT)Voltage ) + 20.088) / 34.103 );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vEventCallback
|
||||
// Description: Callback for events
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE VOID vEventCallback( PVOID pvData )
|
||||
{
|
||||
osEventFlagsSet( m_pstEventID, (U32)pvData );
|
||||
}
|
||||
|
||||
|
98
Core/Application/PECO_PeltierController.h
Normal file
98
Core/Application/PECO_PeltierController.h
Normal file
@ -0,0 +1,98 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Peltier Controller
|
||||
// Filename: PECO_PeltierController.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef PECO_PELTIERCONTROLLER_H
|
||||
#define PECO_PELTIERCONTROLLER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
typedef enum {
|
||||
PECO_eConstTemp = 0,
|
||||
PECO_eConst_Voltage = 1
|
||||
} PECO_eMode;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL PECO_boInitializeModule( VOID );
|
||||
VOID PECO_Enable( BOOL Enable );
|
||||
BOOL PECO_isEnabled( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
433
Core/Application/VARH_VariableHandler.c
Normal file
433
Core/Application/VARH_VariableHandler.c
Normal file
@ -0,0 +1,433 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Variable Handler
|
||||
// Filename: VARH_VariableHandler.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with global variables
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "VARH_VariableHandler.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL VARH_StVar m_auVariable[VARH_eNumberOfVariables];
|
||||
|
||||
LOCAL osMutexId_t m_pstMutexID = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL CONST VARH_StVarInfo m_astVarInfo[VARH_eNumberOfVariables] =
|
||||
{
|
||||
{ VARH_FLAGINFO_NONE, (VARH_UVariable)(U32)1, (VARH_UVariable)(U32)0, (VARH_UVariable)(U32)1}, // VARH_eMode
|
||||
|
||||
{ VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-2.0f, (VARH_UVariable)12.0f}, // VARH_eControlVoltage
|
||||
|
||||
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)100.0f }, // VARH_ePID_kp
|
||||
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)100.0f }, // VARH_ePID_ki
|
||||
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)100.0f }, // VARH_ePID_kd
|
||||
{ VARH_FLAGINFO_FLOAT, (VARH_UVariable)23.0f, (VARH_UVariable)-40.0f, (VARH_UVariable)50.0f }, // VARH_ePID_Temp
|
||||
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)10.0f, (VARH_UVariable)0.0f, (VARH_UVariable)12.0f }, // VARH_ePID_Max
|
||||
{ VARH_FLAGINFO_FLASH | VARH_FLAGINFO_FLOAT, (VARH_UVariable)-2.0f, (VARH_UVariable)-2.0f, (VARH_UVariable)0.0f }, // VARH_ePID_Min
|
||||
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-60.0f, (VARH_UVariable)100.0f }, // VARH_eTemp_H
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-60.0f, (VARH_UVariable)100.0f }, // VARH_eTemp_C
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-50.0f, (VARH_UVariable)70.0f }, // VARH_eTemp_Diff
|
||||
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-5.0f, (VARH_UVariable)14.0f }, // VARH_ePeltier_U
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-10.0f, (VARH_UVariable)10.0f }, // VARH_ePeltier_I
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)5.0f }, // VARH_ePeltier_R
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)-50.0f, (VARH_UVariable)150.0f }, // VARH_ePeltier_P
|
||||
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)20.0f, (VARH_UVariable)30.0f }, // VARH_eSupply_U
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)5.0f }, // VARH_eSupply_I
|
||||
{ VARH_FLAGINFO_READONLY | VARH_FLAGINFO_FLOAT, (VARH_UVariable)0.0f, (VARH_UVariable)0.0f, (VARH_UVariable)150.0f }, // VARH_eSupply_P
|
||||
|
||||
{ VARH_FLAGINFO_READONLY, (VARH_UVariable)(U32)0, (VARH_UVariable)(U32)0, (VARH_UVariable)(U32)1 }, // VARH_ePowerState
|
||||
};
|
||||
|
||||
LOCAL CONST osMutexAttr_t m_stMutexAttr =
|
||||
{
|
||||
"VARH_Mutex", // human readable mutex name
|
||||
osMutexRecursive | osMutexPrioInherit, // attr_bits
|
||||
NULL, // memory for control block
|
||||
0U // size for control block
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
// check functions
|
||||
PRIVATE BOOL boCheckRange( U8 u8Variable, VARH_UVariable uNewData );
|
||||
|
||||
PRIVATE BOOL boBooleanVarCheck( U32 u32NewValue );
|
||||
PRIVATE BOOL boU32VarCheck( U8 u8Variable, U32 u32NewValue );
|
||||
PRIVATE BOOL boS32VarCheck( U8 u8Variable, S32 s32NewValue );
|
||||
PRIVATE BOOL boFloatVarCheck( U8 u8Variable, FLOAT flNewValue );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: BOOL boInitConfig
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL VARH_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr ) ) == NULL ) ? FALSE : TRUE;
|
||||
|
||||
VARH_vSetAllVariablesToInitData();
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableData
|
||||
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
|
||||
// Parameters: U8 u8Variable
|
||||
// VARH_UVariable uData
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableData( U8 u8Variable, VARH_UVariable uData )
|
||||
{
|
||||
// check parameters
|
||||
if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_READONLY )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
if( boCheckRange( u8Variable, uData ) ) { m_auVariable[u8Variable].uData = uData; } // store new value
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataU32
|
||||
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
|
||||
// Parameters: U8 u8Variable
|
||||
// U32 u32Data
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableDataU32( U8 u8Variable, U32 u32Data )
|
||||
{
|
||||
VARH_vSetVariableData( u8Variable, (VARH_UVariable)u32Data );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataS32
|
||||
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
|
||||
// Parameters: U8 u8Variable
|
||||
// S32 s32Data
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableDataS32( U8 u8Variable, S32 s32Data )
|
||||
{
|
||||
VARH_vSetVariableData( u8Variable, (VARH_UVariable)s32Data );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataFloat
|
||||
// Description: Sets the Variable Data and checks the parameters (Readonly and Min/Max)
|
||||
// Parameters: U8 u8Variable
|
||||
// FLOAT flData
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableDataFloat( U8 u8Variable, FLOAT flData )
|
||||
{
|
||||
VARH_vSetVariableData( u8Variable, (VARH_UVariable)flData );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataFromSystem
|
||||
// Description: Sets the Variable Data from System
|
||||
// Use only internal, not for User!
|
||||
// Parameters: U8 u8Variable
|
||||
// VARH_UVariable uData
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableDataFromSystem( U8 u8Variable, VARH_UVariable uData )
|
||||
{
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
if( !boCheckRange( u8Variable, uData ) )
|
||||
{
|
||||
m_auVariable[u8Variable].u8Flags |= VARH_FLAG_OUTOFRANGE; // check the value
|
||||
}
|
||||
m_auVariable[u8Variable].uData = uData; // store new value
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataFromSystemU32
|
||||
// Description: Sets the Variable Data from System
|
||||
// Use only internal, not for User!
|
||||
// Parameters: U8 u8Variable
|
||||
// U32 u32Data
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableDataFromSystemU32( U8 u8Variable, U32 u32Data )
|
||||
{
|
||||
VARH_vSetVariableDataFromSystem( u8Variable, (VARH_UVariable)u32Data );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataFromSystemS32
|
||||
// Description: Sets the Variable Data from System
|
||||
// Use only internal, not for User!
|
||||
// Parameters: U8 u8Variable
|
||||
// S32 s32Data
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableDataFromSystemS32( U8 u8Variable, S32 s32Data )
|
||||
{
|
||||
VARH_vSetVariableDataFromSystem( u8Variable, (VARH_UVariable)s32Data );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataFromSystemFloat
|
||||
// Description: Sets the Variable Data from System
|
||||
// Use only internal, not for User!
|
||||
// Parameters: U8 u8Variable
|
||||
// FLOAT flData
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableDataFromSystemFloat( U8 u8Variable, FLOAT flData )
|
||||
{
|
||||
VARH_vSetVariableDataFromSystem( u8Variable, (VARH_UVariable)flData );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_uGetVariableData
|
||||
// Description: Gets the Variable Data
|
||||
// Parameters: U8 u8Variable
|
||||
// Returns: VARH_UVariable
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VARH_UVariable VARH_uGetVariableData( U8 u8Variable )
|
||||
{
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
VARH_UVariable uVar = m_auVariable[u8Variable].uData;
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
return( uVar );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_u32GetVariableData
|
||||
// Description: Gets the Variable Data
|
||||
// Parameters: U8 u8Variable
|
||||
// Returns: U32
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U32 VARH_u32GetVariableData( U8 u8Variable )
|
||||
{
|
||||
return VARH_uGetVariableData( u8Variable ).u32Val;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_s32GetVariableData
|
||||
// Description: Gets the Variable Data
|
||||
// Parameters: U8 u8Variable
|
||||
// Returns: S32
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
S32 VARH_s32GetVariableData( U8 u8Variable )
|
||||
{
|
||||
return VARH_uGetVariableData( u8Variable ).s32Val;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_flGetVariableData
|
||||
// Description: Gets the Variable Data
|
||||
// Parameters: U8 u8Variable
|
||||
// Returns: FLOAT
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
FLOAT VARH_flGetVariableData( U8 u8Variable )
|
||||
{
|
||||
return VARH_uGetVariableData( u8Variable ).flVal;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_uGetVariableFlags
|
||||
// Description: Gets the Variable Flags
|
||||
// Parameters: U8 u8Variable
|
||||
// Returns: u8Flags
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U8 VARH_uGetVariableFlags( U8 u8Variable )
|
||||
{
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
U8 u8Flags = m_auVariable[u8Variable].u8Flags;
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
return( u8Flags );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableToInitData
|
||||
// Description: Sets the variable to its initial data
|
||||
// Parameters: U8 u8Variable
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetVariableToInitData( U8 u8Variable )
|
||||
{
|
||||
VARH_vSetVariableDataFromSystem( u8Variable, m_astVarInfo[u8Variable].uInitData );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetAllVariablesToInitData
|
||||
// Description: Sets all variables to its initial data
|
||||
// Parameters: VARH_EnVariables enVariable
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID VARH_vSetAllVariablesToInitData( VOID )
|
||||
{
|
||||
for( U16 u16Var = 0; u16Var < VARH_eNumberOfVariables; u16Var++ )
|
||||
{
|
||||
VARH_vSetVariableToInitData( u16Var );
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boBooleanVarCheck
|
||||
// Description: Checks the range of a boolean
|
||||
// Parameters: U32 u32NewValue
|
||||
// Returns: TRUE, the variable can be written
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boBooleanVarCheck( U32 u32NewValue )
|
||||
{
|
||||
return( u32NewValue > 1 ? FALSE : TRUE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boU32VarCheck
|
||||
// Description: Checks the range of a U32
|
||||
// Parameters: U8 u8Variable
|
||||
// U32 u32NewValue
|
||||
// Returns: TRUE, the variable can be written
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boU32VarCheck( U8 u8Variable, U32 u32NewValue )
|
||||
{
|
||||
return( (m_astVarInfo[u8Variable].uMinData.u32Val <= u32NewValue) && (u32NewValue <= m_astVarInfo[u8Variable].uMaxData.u32Val) ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boS32VarCheck
|
||||
// Description: Checks the range of a S32
|
||||
// Parameters: U8 u8Variable
|
||||
// S32 s32NewValue
|
||||
// Returns: TRUE, the variable can be written
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boS32VarCheck( U8 u8Variable, S32 s32NewValue )
|
||||
{
|
||||
return( (m_astVarInfo[u8Variable].uMinData.s32Val <= s32NewValue) && (s32NewValue <= m_astVarInfo[u8Variable].uMaxData.s32Val) ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boFloatVarCheck
|
||||
// Description: Checks the range of a Float
|
||||
// Parameters: U8 u8Variable
|
||||
// FLOAT flNewValue
|
||||
// Returns: TRUE, the variable can be written
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boFloatVarCheck( U8 u8Variable, FLOAT flNewValue )
|
||||
{
|
||||
return( (m_astVarInfo[u8Variable].uMinData.flVal <= flNewValue) && (flNewValue <= m_astVarInfo[u8Variable].uMaxData.flVal) ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boCheckRange
|
||||
// Description: Checks the range of the variable
|
||||
// Parameters: U8 u8Variable
|
||||
// VARH_UVariable uNewData
|
||||
// Returns: TRUE, if the value is in the range, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boCheckRange( U8 u8Variable, VARH_UVariable uNewData )
|
||||
{
|
||||
if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_FLOAT )
|
||||
{
|
||||
return( boFloatVarCheck(u8Variable, uNewData.flVal ) );
|
||||
} else if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_SIGNED )
|
||||
{
|
||||
return( boS32VarCheck(u8Variable, uNewData.s32Val ) );
|
||||
} else if( m_astVarInfo[u8Variable].u8Flags & VARH_FLAGINFO_BOOL )
|
||||
{
|
||||
return( boBooleanVarCheck( uNewData.s32Val ) );
|
||||
} else
|
||||
{
|
||||
return( boU32VarCheck( u8Variable, uNewData.u32Val ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
173
Core/Application/VARH_VariableHandler.h
Normal file
173
Core/Application/VARH_VariableHandler.h
Normal file
@ -0,0 +1,173 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Variable Handler
|
||||
// Filename: VARH_VariableHandler.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef VARH_VARIABLEHANDLER_H
|
||||
#define VARH_VARIABLEHANDLER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
// Flags for variable
|
||||
#define VARH_FLAG_VALID (1<<0) // is data valid
|
||||
#define VARH_FLAG_OUTOFRANGE (1<<1) // is data out of range
|
||||
#define VARH_FLAG_MODIFIED (1<<2) // is variable modified (compared to flash)
|
||||
#define VARH_FLAG_FLASHCORRUPT (1<<3) // data from flash is corrupted
|
||||
|
||||
// Flags for variable infos
|
||||
#define VARH_FLAGINFO_NONE 0 // no flag
|
||||
#define VARH_FLAGINFO_FLOAT (1<<0) // variable in floating point format
|
||||
#define VARH_FLAGINFO_SIGNED (1<<1) // variable is signed integer
|
||||
#define VARH_FLAGINFO_BOOL (1<<2) // variable is boolean
|
||||
#define VARH_FLAGINFO_READONLY (1<<3) // variable is readonly, master can not set variable
|
||||
#define VARH_FLAGINFO_FLASH (1<<4) // variable is stored in flash
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
// variables
|
||||
typedef enum
|
||||
{
|
||||
VARH_eMode = 0,
|
||||
|
||||
VARH_eControlVoltage = 1,
|
||||
|
||||
VARH_ePID_kp,
|
||||
VARH_ePID_ki,
|
||||
VARH_ePID_kd,
|
||||
VARH_ePID_Temp,
|
||||
VARH_ePID_Max,
|
||||
VARH_ePID_Min,
|
||||
|
||||
VARH_eTemp_H,
|
||||
VARH_eTemp_C,
|
||||
VARH_eTemp_Diff,
|
||||
|
||||
VARH_ePeltier_U,
|
||||
VARH_ePeltier_I,
|
||||
VARH_ePeltier_R,
|
||||
VARH_ePeltier_P,
|
||||
|
||||
VARH_eSupply_U,
|
||||
VARH_eSupply_I,
|
||||
VARH_eSupply_P,
|
||||
|
||||
VARH_ePowerState,
|
||||
|
||||
VARH_eNumberOfVariables, // Must be last entry
|
||||
} VARH_EnVariables;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#pragma pack(4)
|
||||
typedef union {
|
||||
FLOAT flVal;
|
||||
U32 u32Val;
|
||||
S32 s32Val;
|
||||
} VARH_UVariable;
|
||||
#pragma pack()
|
||||
|
||||
typedef struct
|
||||
{
|
||||
U8 u8Flags; // flags
|
||||
VARH_UVariable uInitData; // initial Data (data is always 32 bit)
|
||||
VARH_UVariable uMinData; // min Value for Data
|
||||
VARH_UVariable uMaxData; // max Value for Data
|
||||
} VARH_StVarInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
VARH_UVariable uData; // Data (data is always 32 bit)
|
||||
U8 u8Flags; // flags
|
||||
} VARH_StVar;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: FUNCTION TYPES
|
||||
// Description: Definition of functions
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL VARH_boInitializeModule( VOID );
|
||||
|
||||
// set data
|
||||
VOID VARH_vSetVariableData( U8 u8Variable, VARH_UVariable uData );
|
||||
VOID VARH_vSetVariableDataU32( U8 u8Variable, U32 u32Data );
|
||||
VOID VARH_vSetVariableDataS32( U8 u8Variable, S32 s32Data );
|
||||
VOID VARH_vSetVariableDataFloat( U8 u8Variable, FLOAT flData );
|
||||
|
||||
// set data from system
|
||||
VOID VARH_vSetVariableDataFromSystem( U8 u8Variable, VARH_UVariable uData );
|
||||
VOID VARH_vSetVariableDataFromSystemU32( U8 u8Variable, U32 u32Data );
|
||||
VOID VARH_vSetVariableDataFromSystemS32( U8 u8Variable, S32 s32Data );
|
||||
VOID VARH_vSetVariableDataFromSystemFloat( U8 u8Variable, FLOAT flData );
|
||||
|
||||
// get data
|
||||
VARH_UVariable VARH_uGetVariableData( U8 u8Variable );
|
||||
U32 VARH_u32GetVariableData( U8 u8Variable );
|
||||
S32 VARH_s32GetVariableData( U8 u8Variable );
|
||||
FLOAT VARH_flGetVariableData( U8 u8Variable );
|
||||
U8 VARH_uGetVariableFlags( U8 u8Variable );
|
||||
|
||||
// reset data
|
||||
VOID VARH_vSetVariableToInitData( U8 u8Variable );
|
||||
VOID VARH_vSetAllVariablesToInitData( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
377
Core/Drivers/ADCD_AdcDriver.c
Normal file
377
Core/Drivers/ADCD_AdcDriver.c
Normal file
@ -0,0 +1,377 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: ADC-Driver
|
||||
// Filename: ADCD_AdcDriver.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the internal ADC-Driver
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "ADCD_AdcDriver.h"
|
||||
|
||||
// Drivers
|
||||
#include "SPID_SpiDriver.h"
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
//#include "EXTI_ExtiHandler.h"
|
||||
|
||||
// Application
|
||||
//#include "../Application/ELOG_ErrorLogger.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// CMSIS OS
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
// define commands
|
||||
#define CMD_READ (0<<7)
|
||||
#define CMD_WRITE (1<<7)
|
||||
|
||||
// define register
|
||||
#define REG_CONFIG 0x00
|
||||
#define REG_RTD_MSB 0x01
|
||||
#define REG_RTD_LSB 0x02
|
||||
#define REG_HIGH_FAULT_MSB 0x03
|
||||
#define REG_HIGH_FAULT_LSB 0x04
|
||||
#define REG_LOW_FAULT_MSB 0x05
|
||||
#define REG_LOW_FAULT_LSB 0x06
|
||||
#define REG_FAULT_STATUS 0x07
|
||||
|
||||
#define CONFIG_VBIAS_ON (1<<7)
|
||||
#define CONFIG_VBIAS_OFF (0<<7)
|
||||
#define CONFIG_MODE_AUTO (1<<6)
|
||||
#define CONFIG_MODE_OFF (0<<6)
|
||||
#define CONFIG_1SHOT (1<<5)
|
||||
#define CONFIG_3WIRE (1<<4)
|
||||
#define CONFIG_24WIRE (0<<4)
|
||||
#define CONFIG_FAULTCYCLE_NO (0<<2)
|
||||
#define CONFIG_FAULTCYCLE_AUTO (1<<2)
|
||||
#define CONFIG_FAULTCYCLE_MANUAL1 (2<<2)
|
||||
#define CONFIG_FAULTCYCLE_MANUAL2 (3<<2)
|
||||
#define CONFIG_FAULTSTATCLEAR (1<<1)
|
||||
#define CONFIG_FILT50HZ (1<<0)
|
||||
#define CONFIG_FILT60HZ (0<<0)
|
||||
|
||||
#define FAULT_HIGHTHRESH 0x80
|
||||
#define FAULT_LOWTHRESH 0x40
|
||||
#define FAULT_REFINLOW 0x20
|
||||
#define FAULT_REFINHIGH 0x10
|
||||
#define FAULT_RTDINLOW 0x08
|
||||
#define FAULT_OVUV 0x04
|
||||
|
||||
#define CONFIG (U8)(CONFIG_VBIAS_ON | CONFIG_MODE_OFF | CONFIG_24WIRE | CONFIG_FILT60HZ) // enable Vbias; autoconvert off; 4-wire; 60Hz;
|
||||
|
||||
#define EVENT_ENABLE ((U32)(1<<0))
|
||||
#define EVENT_DISABLE ((U32)(1<<1))
|
||||
#define EVENT_INVERT ((U32)(1<<2))
|
||||
#define EVENT_EXT_SYNC_ENABLE ((U32)(1<<3))
|
||||
#define EVENT_NEW_SET_VALUE ((U32)(1<<4))
|
||||
#define EVENT_NEW_MODE ((U32)(1<<5))
|
||||
#define EVENT_DAC_START ((U32)(1<<6))
|
||||
#define EVENT_DAC_STOP ((U32)(1<<7))
|
||||
#define EVENT_ADC_DATA_READY ((U32)(1<<8))
|
||||
#define EVENT_RESET_DATA_COUNTER ((U32)(1<<9))
|
||||
|
||||
#define EVENT_FLAGS_ALL ( EVENT_ENABLE | EVENT_DISABLE | EVENT_INVERT | \
|
||||
EVENT_EXT_SYNC_ENABLE | EVENT_NEW_SET_VALUE | EVENT_NEW_MODE | \
|
||||
EVENT_DAC_START | EVENT_DAC_STOP | EVENT_ADC_DATA_READY | \
|
||||
EVENT_RESET_DATA_COUNTER )
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL CONST osMutexAttr_t m_stMutexAttr =
|
||||
{
|
||||
"ADCD_Mutex", // human readable mutex name
|
||||
osMutexRecursive | osMutexPrioInherit, // attr_bits
|
||||
NULL, // memory for control block
|
||||
0U // size for control block
|
||||
};
|
||||
|
||||
// Data Ready Pin
|
||||
//LOCAL CONST GPIO_TypeDef* m_pstDataReadyPort = GPIOD;
|
||||
//LOCAL CONST U16 m_u16DataReadyPin = GPIO_PIN_8;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL U8 m_au8RxData[8];
|
||||
LOCAL U8 m_au8TxData[8];
|
||||
LOCAL osMutexId_t m_pstMutexID = NULL;
|
||||
|
||||
LOCAL SPID_StHandle m_stSPIHandle =
|
||||
{
|
||||
SPID_eADC, // enSPI;
|
||||
0xFF, // enCS (0xFF = hardware chip select)
|
||||
m_au8TxData, // pu8TxBuf;
|
||||
m_au8RxData, // pu8RxBuf;
|
||||
0, // u16TransferSize;
|
||||
};
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit );
|
||||
PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ADCD_boInitializeModule
|
||||
// Description: Initializes the ADC module
|
||||
// Parameters: None
|
||||
// Returns: BOOL TRUE, if initializaiton sucessful, otherwise FALSE
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL ADCD_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr ) ) == NULL ) ? FALSE : TRUE;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
|
||||
// Conifg ADC Cold
|
||||
DIPO_vSetOutput( DIPO_eCS_C );
|
||||
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
|
||||
DIPO_vResetOutput( DIPO_eCS_C );
|
||||
|
||||
DIPO_vSetOutput( DIPO_eCS_C );
|
||||
boOK &= boWriteReg( REG_HIGH_FAULT_MSB, (U16)0x5b12 , TRUE );
|
||||
DIPO_vResetOutput( DIPO_eCS_C );
|
||||
|
||||
DIPO_vSetOutput( DIPO_eCS_C );
|
||||
boOK &= boWriteReg( REG_LOW_FAULT_MSB, (U16)0x2690 , TRUE );
|
||||
DIPO_vResetOutput( DIPO_eCS_C );
|
||||
|
||||
// Config ADC Hot
|
||||
DIPO_vSetOutput( DIPO_eCS_H );
|
||||
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
|
||||
DIPO_vResetOutput( DIPO_eCS_H );
|
||||
|
||||
DIPO_vSetOutput( DIPO_eCS_H );
|
||||
boOK &= boWriteReg( REG_HIGH_FAULT_MSB, (U16)0x5b12 , TRUE );
|
||||
DIPO_vResetOutput( DIPO_eCS_H );
|
||||
|
||||
DIPO_vSetOutput( DIPO_eCS_H );
|
||||
boOK &= boWriteReg( REG_LOW_FAULT_MSB, (U16)0x2690 , TRUE );
|
||||
DIPO_vResetOutput( DIPO_eCS_H );
|
||||
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ADCD_boReadData
|
||||
// Description: Reads the conversion data form the ADC
|
||||
// Parameters: PU8 pu8Error error
|
||||
// Returns: DOUBLE conversion data
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL ADCD_boReadData( ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
*pu8Error = 0; // reset error state
|
||||
U16 u16Data = 0;
|
||||
|
||||
DIPO_EnDigitalOutput CS = DIPO_eCS_H;
|
||||
|
||||
if( eChannel == ADCD_eHot ) CS = DIPO_eCS_H;
|
||||
else if ( eChannel == ADCD_eCold ) CS = DIPO_eCS_C;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boWriteReg( REG_CONFIG, CONFIG | CONFIG_1SHOT , FALSE );
|
||||
DIPO_vResetOutput( CS );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
osDelay(55);
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boReadReg( REG_RTD_MSB, &u16Data, TRUE );
|
||||
DIPO_vResetOutput( CS );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
if( !boOK )
|
||||
{
|
||||
*pu8Error |= ADCD_SPI_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( ( u16Data & 0x00 ) == 0x01 )
|
||||
{
|
||||
*pu8Error |= ADCD_STATUS_DATA_ERROR;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boReadReg( REG_FAULT_STATUS, &u16Data, FALSE );
|
||||
DIPO_vResetOutput( CS );
|
||||
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
|
||||
DIPO_vResetOutput( CS );
|
||||
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boReadReg( REG_HIGH_FAULT_MSB, &u16Data, TRUE );
|
||||
DIPO_vResetOutput( CS );
|
||||
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
*pu8Error |= u16Data & 0xFC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u16Data = u16Data >> 1;
|
||||
|
||||
*pu16Data = u16Data;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boWriteReg( REG_CONFIG, CONFIG | CONFIG_FAULTCYCLE_AUTO , FALSE );
|
||||
DIPO_vResetOutput( CS );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boWriteReg
|
||||
// Description: Writes to the regiser
|
||||
// Parameters: U8 u8Register
|
||||
// U16 u16Data
|
||||
// BOOL boIs16bit TRUE, if Data is 16bit, FALSE, if Data is 8bit
|
||||
// Returns: BOOL TRUE, if successful, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if( boIs16bit ){
|
||||
m_au8TxData[0] = CMD_WRITE | u8Register;
|
||||
m_au8TxData[1] = (U8)u16Data>>8;
|
||||
m_au8TxData[2] = (U8)u16Data;
|
||||
m_stSPIHandle.u16TransferSize = 3;
|
||||
boOK &= SPID_boSendReceive( &m_stSPIHandle );
|
||||
} else {
|
||||
m_au8TxData[0] = CMD_WRITE | u8Register;
|
||||
m_au8TxData[1] = (U8)u16Data;
|
||||
m_stSPIHandle.u16TransferSize = 2;
|
||||
boOK &= SPID_boSendReceive( &m_stSPIHandle );
|
||||
}
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: boReadReg
|
||||
// Description: Reads the regiser
|
||||
// Parameters: U8 u8Register
|
||||
// PU16 pu16Data
|
||||
// BOOL boIs16bit TRUE, if Data is 16bit, FALSE, if Data is 8bit
|
||||
// Returns: BOOL TRUE, if successful, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if( boIs16bit ){
|
||||
m_au8TxData[0] = CMD_READ | u8Register;
|
||||
m_au8TxData[1] = 0;
|
||||
m_au8TxData[2] = 0;
|
||||
m_stSPIHandle.u16TransferSize = 3;
|
||||
|
||||
boOK &= SPID_boSendReceive( &m_stSPIHandle );
|
||||
|
||||
*pu16Data = ( (U16)m_au8RxData[1]<<8 ) | ( (U16)m_au8RxData[2]<<0 );
|
||||
} else {
|
||||
m_au8TxData[0] = CMD_READ | u8Register;
|
||||
m_au8TxData[1] = 0;
|
||||
m_stSPIHandle.u16TransferSize = 2;
|
||||
|
||||
boOK &= SPID_boSendReceive( &m_stSPIHandle );
|
||||
|
||||
*pu16Data = (U16)m_au8RxData[1];
|
||||
}
|
||||
|
||||
return( boOK );
|
||||
}
|
95
Core/Drivers/ADCD_AdcDriver.h
Normal file
95
Core/Drivers/ADCD_AdcDriver.h
Normal file
@ -0,0 +1,95 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: ADC Driver
|
||||
// Filename: ADCD_AdcDriver.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef ADCD_ADCDRIVER_H
|
||||
#define ADCD_ADCDRIVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#define ADCD_STATUS_DATA_ERROR (1<<0)
|
||||
#define ADCD_SPI_FAILURE (1<<1)
|
||||
|
||||
//typedef VOID (*ADCD_pfnCallback)( PVOID pvCallbackArgument );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
typedef enum {
|
||||
ADCD_eHot = 0,
|
||||
ADCD_eCold = 1,
|
||||
|
||||
ADCD_eNumberOfTemps // Must be last
|
||||
}ADCD_EnTemps;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL ADCD_boInitializeModule( VOID );
|
||||
//BOOL ADCD_boConfig( BOOL boFast, ADCD_pfnCallback pfnDataReadyCallback, PVOID pvCallbackArg );
|
||||
BOOL ADCD_boReadData( ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
315
Core/Drivers/ANPI_AnalogPortsIn.c
Normal file
315
Core/Drivers/ANPI_AnalogPortsIn.c
Normal file
@ -0,0 +1,315 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Analog Ports Input
|
||||
// Filename: ANPI_AnalogPortsIn.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the analog input ports
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "ANPI_AnalogPortsIn.h"
|
||||
|
||||
//Application
|
||||
#include "../Application/VARH_VariableHandler.h"
|
||||
|
||||
// Drivers
|
||||
#include "PECO_PeltierController.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define ADC_RES (4096) // ADC resolution: 12 bits
|
||||
#define NR_OF_ADCS ANPI_eInNumberOfInputs // number of internal adc channels
|
||||
|
||||
#define INT_ADC_REF (3.3f)// int. reference voltage for conversion
|
||||
|
||||
#define BUFFER_SIZE NR_OF_ADCS * 2
|
||||
#define BUFFER_HALF_SIZE NR_OF_ADCS
|
||||
|
||||
#define ANPI_ADC_HALF_COMPLETE ((U32)1<<0)
|
||||
#define ANPI_ADC_FULL_COMPLETE ((U32)1<<1)
|
||||
|
||||
#define ANPI_FLAGS_ALL ( ANPI_ADC_HALF_COMPLETE | ANPI_ADC_FULL_COMPLETE )
|
||||
|
||||
#define OVERSAMPLING_DIVISOR 16.0f // calculated with parameters from hardware oversampling
|
||||
// 6 bits(64x) - 2 bit shift = 4bit -> 16x
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL U16 m_au16ADCDataBuffer[BUFFER_SIZE];
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
LOCAL osEventFlagsId_t m_pstEventID = NULL;
|
||||
LOCAL osMutexId_t m_pstMutexID = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
// conversion factors for the values
|
||||
// Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_aflConversionFactor[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
10, // 01 ANPI_eSupplyVoltage24V
|
||||
5, // 02 ANPI_eSupplyCurrent24V
|
||||
10, // 03 ANPI_eOutputVoltage
|
||||
5, // 04 ANPI_eOutputCurrent
|
||||
};
|
||||
|
||||
// Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_aflOffset[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
0.0f, // 01 ANPI_eSupplyVoltage24V
|
||||
8.25f, // 02 ANPI_eSupplyCurrent24V
|
||||
14.85f, // 03 ANPI_eOutputVoltage
|
||||
8.25f, // 04 ANPI_eOutputCurrent
|
||||
};
|
||||
|
||||
// inputs are connected to the following ADCs
|
||||
// ANPI_eSupplyVoltage24V ADC1, Channel 6
|
||||
// ANPI_eSupplyCurrent24V ADC1, Channel 16
|
||||
// ANPI_eOutputVoltage ADC1, Channel 7
|
||||
// ANPI_eOutputCurrent ADC1, Channel 15
|
||||
|
||||
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
{
|
||||
"ANPI_Thread", // name of the thread
|
||||
osThreadDetached, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for stack
|
||||
1024, // size of stack
|
||||
osPriorityBelowNormal, // initial thread priority (default: osPriorityNormal)
|
||||
0, // TrustZone module identifier
|
||||
0, // reserved (must be 0)
|
||||
};
|
||||
|
||||
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
|
||||
{
|
||||
"ANPI_Event_Flags", // name of the event flags
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
};
|
||||
|
||||
LOCAL CONST osMutexAttr_t m_stMutexAttr =
|
||||
{
|
||||
"ANPI_Mutex", // human readable mutex name
|
||||
osMutexRecursive | osMutexPrioInherit, // attr_bits
|
||||
NULL, // memory for control block
|
||||
0U // size for control block
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE VOID vTask( PVOID arg );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ANPI_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL ANPI_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ( ( m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
|
||||
boOK &= ( ( m_pstEventID = osEventFlagsNew( &stEventAttribute )) == NULL) ? FALSE : TRUE;
|
||||
|
||||
boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ANPI_vTask
|
||||
// Description: ANPI_vTask
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID vTask( PVOID arg )
|
||||
{
|
||||
U32 u32Flags;
|
||||
U16 u16Offset;
|
||||
FLOAT flUadc;
|
||||
U32 au32ADCRawData[ANPI_eInNumberOfInputs];
|
||||
FLOAT aflValues[ANPI_eInNumberOfInputs]; // values
|
||||
|
||||
osDelay( 1 ); // Wait 1ms to have a Valid Value
|
||||
|
||||
HAL_ADC_Start_DMA( &hadc1, (PU32)&m_au16ADCDataBuffer[0], BUFFER_SIZE );
|
||||
|
||||
while ( TRUE )
|
||||
{
|
||||
u32Flags = osEventFlagsWait( m_pstEventID, ANPI_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
|
||||
|
||||
if( u32Flags & ANPI_ADC_FULL_COMPLETE ) u16Offset = BUFFER_HALF_SIZE;
|
||||
else if( u32Flags & ANPI_ADC_HALF_COMPLETE ) u16Offset = 0;
|
||||
else continue;
|
||||
|
||||
// aquire mutex: access to m_afcValues blocked for ANPI_flGetInputValue
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
|
||||
// copy the values in the buffer...
|
||||
for( U16 u16Cnt = 0; u16Cnt < BUFFER_HALF_SIZE; u16Cnt++ )
|
||||
au32ADCRawData[ u16Cnt ] = m_au16ADCDataBuffer[u16Cnt + u16Offset];
|
||||
|
||||
// multiply conversion factor and add the offset
|
||||
for( U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
|
||||
{
|
||||
flUadc = (FLOAT)au32ADCRawData[u16Cnt] / OVERSAMPLING_DIVISOR / ADC_RES * INT_ADC_REF;
|
||||
aflValues[u16Cnt] = flUadc * m_aflConversionFactor[u16Cnt] - m_aflOffset[u16Cnt];
|
||||
}
|
||||
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_U, aflValues[ANPI_eOutputVoltage] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_I, aflValues[ANPI_eOutputCurrent] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_R, aflValues[ANPI_eOutputVoltage] / aflValues[ANPI_eOutputCurrent] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_R, aflValues[ANPI_eOutputVoltage] * aflValues[ANPI_eOutputCurrent] );
|
||||
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_eSupply_U, aflValues[ANPI_eSupplyVoltage24V] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_eSupply_I, aflValues[ANPI_eSupplyCurrent24V] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_eSupply_P, aflValues[ANPI_eSupplyVoltage24V] * (aflValues[ANPI_eSupplyCurrent24V]) );
|
||||
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_ADC_ConvCpltCallback
|
||||
// Description: Handles the ADC interrupts
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void HAL_ADC_ConvCpltCallback( ADC_HandleTypeDef* hadc )
|
||||
{
|
||||
osEventFlagsSet( m_pstEventID, ANPI_ADC_FULL_COMPLETE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_ADC_ConvHalfCpltCallback
|
||||
// Description: Handles the ADC interrupts
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void HAL_ADC_ConvHalfCpltCallback( ADC_HandleTypeDef* hadc )
|
||||
{
|
||||
osEventFlagsSet( m_pstEventID, ANPI_ADC_HALF_COMPLETE );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_ADC_ErrorCallback
|
||||
// Description: Error Callback for the ADC
|
||||
// Parameters: ADC_HandleTypeDef* hadc
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void HAL_ADC_ErrorCallback( ADC_HandleTypeDef* hadc )
|
||||
{
|
||||
// TODO: Error Handling
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_NONE )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_INTERNAL )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_OVR )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_DMA )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if( hadc->DMA_Handle->ErrorCode & HAL_DMA_ERROR_TE )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
102
Core/Drivers/ANPI_AnalogPortsIn.h
Normal file
102
Core/Drivers/ANPI_AnalogPortsIn.h
Normal file
@ -0,0 +1,102 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Analog Ports Input
|
||||
// Filename: ANPI_AnalogPortsIn.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef ANPI_ANALOGPORTSIN_H
|
||||
#define ANPI_ANALOGPORTSIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
// Enumeration for analog inputs is used as array index later on. Thus enumeration must start
|
||||
// at zero and must be numbered consecutively. Enumeration must never be changed.
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ANPI_eSupplyVoltage24V = 0, // voltage of 24V power supply
|
||||
ANPI_eSupplyCurrent24V = 1, // current of 24V power supply
|
||||
ANPI_eOutputVoltage = 2, // output voltage peltier element
|
||||
ANPI_eOutputCurrent = 3, // output current peltier element
|
||||
|
||||
ANPI_eInNumberOfInputs, // Must be last entry
|
||||
} ANPI_EnAnalogInput;
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL ANPI_boInitializeModule( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
164
Core/Drivers/ANPO_AnalogPortsOut.c
Normal file
164
Core/Drivers/ANPO_AnalogPortsOut.c
Normal file
@ -0,0 +1,164 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Analog Ports Output
|
||||
// Filename: ANPO_AnalogPortsOut.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the analog outputs ports
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "ANPO_AnalogPortsOut.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
U32 u32ConvertVoltagetoRaw( FLOAT Voltage );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
extern DAC_HandleTypeDef hdac1;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ANPO_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean, TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL ANPO_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= HAL_DAC_Start( &hdac1, DAC_CHANNEL_1 ) == HAL_OK ? TRUE : FALSE;
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ANPO_boSetVoltage
|
||||
// Description: Sets the DAC Output to a specific Voltage
|
||||
// Parameters: FLOAT Voltage
|
||||
// Returns: Boolean, TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL ANPO_boSetVoltage( FLOAT Voltage ){
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
U32 u32RawData = u32ConvertVoltagetoRaw( Voltage );
|
||||
|
||||
boOK &= HAL_DAC_SetValue( &hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, u32RawData );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: u32ConvertVoltagetoRaw
|
||||
// Description: Convert Voltage to Raw value for the DAC
|
||||
// Parameters: FLOAT Voltage
|
||||
// Returns: U32
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U32 u32ConvertVoltagetoRaw( FLOAT Voltage ){
|
||||
U32 RawData;
|
||||
|
||||
RawData = Voltage * 4095 / 3.3;
|
||||
|
||||
return RawData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
96
Core/Drivers/ANPO_AnalogPortsOut.h
Normal file
96
Core/Drivers/ANPO_AnalogPortsOut.h
Normal file
@ -0,0 +1,96 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Analog Ports Output
|
||||
// Filename: ANPO_AnalogPortsOut.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef ANPO_ANALOGPORTSOUT_H
|
||||
#define ANPO_ANALOGPORTSOUT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ANPO_eControlVoltage = 0, // 00 control Voltage
|
||||
|
||||
ANPO_eInNumberOfInputs, // Must be last entry
|
||||
} ANPO_EnAnalogOutput;
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL ANPO_boInitializeModule( VOID );
|
||||
BOOL ANPO_boSetVoltage( FLOAT Voltage );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
262
Core/Drivers/CAND_CanDriver.c
Normal file
262
Core/Drivers/CAND_CanDriver.c
Normal file
@ -0,0 +1,262 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Can Driver
|
||||
// Filename: CAND_CanDriver.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the analog outputs ports
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "CAND_CanDriver.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// Driver
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define CAND_SHIFT 0x1 // Shift address space (0-3)
|
||||
|
||||
#define CAND_PRIVATE 1
|
||||
#define CAND_PUBLIC 0
|
||||
|
||||
#define CAND_RECEIVE 0
|
||||
#define CAND_SEND 1
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
CAND_pfnRxCallback m_pfnRxCallback = NULL;
|
||||
|
||||
U8 u8BoardId = 0x00;
|
||||
|
||||
CAN_FilterTypeDef stFilter_public = {
|
||||
(CAND_SHIFT<<14)|(CAND_PUBLIC<<13)|(CAND_RECEIVE<<11), // FilterIdHigh
|
||||
0x0000, // FilterIdLow
|
||||
0xE800, // FilterMaskIdHigh
|
||||
0x0000, // FilterMaskIdLow
|
||||
CAN_FILTER_FIFO0, // FilterFIFOAssignment
|
||||
0x00, // FilterBank
|
||||
CAN_FILTERMODE_IDMASK, // FilterMode
|
||||
CAN_FILTERSCALE_32BIT, // FilterScale
|
||||
CAN_FILTER_ENABLE, // FilterActivation
|
||||
0x00 // SlaveStartFilterBank
|
||||
};
|
||||
|
||||
CAN_FilterTypeDef stFilter_private = {
|
||||
(CAND_SHIFT<<14)|(CAND_PRIVATE<<13)|(CAND_RECEIVE<<11), // FilterIdHigh
|
||||
0x0000, // FilterIdLow
|
||||
0xE9E0, // FilterMaskIdHigh
|
||||
0x0000, // FilterMaskIdLow
|
||||
CAN_FILTER_FIFO0, // FilterFIFOAssignment
|
||||
0x01, // FilterBank
|
||||
CAN_FILTERMODE_IDMASK, // FilterMode
|
||||
CAN_FILTERSCALE_32BIT, // FilterScale
|
||||
CAN_FILTER_ENABLE, // FilterActivation
|
||||
0x00 // SlaveStartFilterBank
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
extern CAN_HandleTypeDef hcan1;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: CAND_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean, TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL CAND_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
u8BoardId |= DIPO_boGetInput(DIPO_eADR0) << 0;
|
||||
u8BoardId |= DIPO_boGetInput(DIPO_eADR1) << 1;
|
||||
u8BoardId |= DIPO_boGetInput(DIPO_eADR2) << 2;
|
||||
u8BoardId |= DIPO_boGetInput(DIPO_eADR3) << 3;
|
||||
|
||||
stFilter_private.FilterIdHigh |= u8BoardId << 5;
|
||||
|
||||
boOK &= ( HAL_CAN_ConfigFilter(&hcan1, &stFilter_public) == HAL_OK ) ? TRUE : FALSE;
|
||||
boOK &= ( HAL_CAN_ConfigFilter(&hcan1, &stFilter_private) == HAL_OK ) ? TRUE : FALSE;
|
||||
|
||||
boOK &= ( HAL_CAN_Start(&hcan1) == HAL_OK ) ? TRUE : FALSE;
|
||||
|
||||
boOK &= ( HAL_CAN_ActivateNotification( &hcan1, CAN_IT_RX_FIFO0_MSG_PENDING ) == HAL_OK ) ? TRUE : FALSE;
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: CAND_u8GetBoardId
|
||||
// Description: Returns the Board ID
|
||||
// Parameters: None
|
||||
// Returns: U8 Board ID
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U8 CAND_u8GetBoardId( VOID ){
|
||||
return u8BoardId;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: CAND_boSendMessage
|
||||
// Description: Send a Message over the CAN Interface
|
||||
// Parameters: U8 Id
|
||||
// U8 Length
|
||||
// PU8 Data Buffer
|
||||
// Returns: Boolean, TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL CAND_boSendMessage( U16 u16Id, PU8 pu8Buffer, U8 u8Len ){
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if( u8Len > 8 ) return FALSE;
|
||||
|
||||
CAN_TxHeaderTypeDef header = {
|
||||
u16Id | (CAND_SEND<<6),
|
||||
0,
|
||||
CAN_ID_STD,
|
||||
CAN_RTR_DATA,
|
||||
u8Len,
|
||||
DISABLE
|
||||
};
|
||||
|
||||
boOK &= HAL_CAN_AddTxMessage( &hcan1, &header, pu8Buffer, (PU32)CAN_TX_MAILBOX0 ) == HAL_OK ? TRUE : FALSE;
|
||||
|
||||
return boOK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: CAND_vSetRxCallback
|
||||
// Description: Send a Message over the CAN Interface
|
||||
// Parameters: CAND_pfnRxCallback Callback Function
|
||||
// Returns: none
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID CAND_vSetRxCallback( CAND_pfnRxCallback pfnRxCallback ){
|
||||
m_pfnRxCallback = pfnRxCallback;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_CAN_RxFifo0MsgPendingCallback
|
||||
// Description: HAL Can Rx FIFO Msg Pending Callback
|
||||
// Parameters: CAN_HandleTypeDef *hcan
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void HAL_CAN_RxFifo0MsgPendingCallback( CAN_HandleTypeDef *hcan ){
|
||||
|
||||
CAN_RxHeaderTypeDef header;
|
||||
U8 au8Data[8];
|
||||
|
||||
HAL_CAN_GetRxMessage( hcan, CAN_RX_FIFO0, &header, au8Data );
|
||||
|
||||
CAND_Message stMessage;
|
||||
|
||||
stMessage.u16Id = header.StdId;
|
||||
stMessage.u8Type = (header.StdId & 0x030) >> 4;
|
||||
stMessage.u8Len = header.DLC;
|
||||
UTIL_vMemCopy( au8Data,stMessage.au8Data,stMessage.u8Len );
|
||||
|
||||
m_pfnRxCallback( stMessage );
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_CAN_ErrorCallback
|
||||
// Description: HAL Can error callback function
|
||||
// Parameters: CAN_HandleTypeDef *hcan
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
void HAL_CAN_ErrorCallback( CAN_HandleTypeDef *hcan ){
|
||||
U32 u32Error = hcan->ErrorCode;
|
||||
// TODO: Can Error Handling
|
||||
}
|
||||
|
||||
|
||||
|
103
Core/Drivers/CAND_CanDriver.h
Normal file
103
Core/Drivers/CAND_CanDriver.h
Normal file
@ -0,0 +1,103 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Can Driver
|
||||
// Filename: CAND_CanDriver.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef CAND_CANDRIVER_H
|
||||
#define CAND_CANDRIVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#define MESSAGE_TYPE_WRITE 2
|
||||
#define MESSAGE_TYPE_READ 1
|
||||
#define MESSAGE_TYPE_COMMAND 0
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
typedef struct {
|
||||
U8 au8Data[8];
|
||||
U8 u8Len;
|
||||
U8 u8Type;
|
||||
U16 u16Id;
|
||||
} CAND_Message;
|
||||
|
||||
// callback functions
|
||||
typedef VOID (*CAND_pfnRxCallback)( CAND_Message stMessage );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL CAND_boInitializeModule( VOID );
|
||||
BOOL CAND_boSendMessage( U16 u16Id, PU8 pu8Buffer, U8 u8Len );
|
||||
VOID CAND_vSetRxCallback( CAND_pfnRxCallback pfnRxCallback );
|
||||
U8 CAND_u8GetBoardId( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
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é (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Digital Ports
|
||||
// Filename: DIPO_DigitalPorts.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the digtial I/O ports
|
||||
// Convention: TRUE means active, FALSE means not active
|
||||
// The polarity of the signal is set in the initialization struct (boLowActive)
|
||||
// The name of the enumeration does not have any impact on the polarity
|
||||
// Even with a signal nCs, TRUE means active (if low active => output low)
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
|
||||
//Application
|
||||
//#include "../Application/ELOG_ErrorLogger.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GPIO_TypeDef* pstPort; // Port
|
||||
GPIO_InitTypeDef stGPIOInit; // init structure
|
||||
BOOL boResetState; // reset state of pin
|
||||
BOOL boSetState; // set state of pin
|
||||
} StDigitalIO; // Represents one digital input or output
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
// Input order must fit enumeration "DIPO_EnDigitalInput".
|
||||
LOCAL CONST StDigitalIO m_astInputs[DIPO_eInNumberOfInputs] =
|
||||
{
|
||||
|
||||
{ GPIOB, { GPIO_PIN_7, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 00 DIPO_ePG
|
||||
{ GPIOC, { GPIO_PIN_15, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 01 DIPO_eADR3
|
||||
{ GPIOB, { GPIO_PIN_3, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 02 DIPO_eADR2
|
||||
{ GPIOB, { GPIO_PIN_4, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 01 DIPO_eADR1
|
||||
{ GPIOA, { GPIO_PIN_15, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 03 DIPO_eADR0
|
||||
|
||||
};
|
||||
|
||||
// order must fit enumeration "DIPO_EnDigitalOutput".
|
||||
LOCAL CONST StDigitalIO m_astOutputs[DIPO_eOutNumberOfOutputs] =
|
||||
{
|
||||
|
||||
{ GPIOB, { GPIO_PIN_6, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, TRUE, FALSE }, // 00 DIPO_eCS_C
|
||||
{ GPIOB, { GPIO_PIN_5, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, TRUE, FALSE }, // 01 DIPO_eCS_H
|
||||
{ GPIOC, { GPIO_PIN_14, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 02 DIPO_eLED
|
||||
{ GPIOA, { GPIO_PIN_8, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM, 0 }, FALSE, TRUE }, // 03 DIPO_eEN
|
||||
|
||||
};
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: DIPO_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// This function is thread save
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL DIPO_boInitializeModule( VOID )
|
||||
{
|
||||
U8 u8Cnt;
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
// enable APB2 syscfg clock
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
// initialize the inputs
|
||||
// ----------------------
|
||||
if( DIPO_eInNumberOfInputs > 0 )
|
||||
{
|
||||
for( u8Cnt = 0 ; u8Cnt < DIPO_eInNumberOfInputs; u8Cnt++ )
|
||||
{
|
||||
boOK &= (m_astInputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_INPUT) ? TRUE : FALSE;
|
||||
|
||||
// configure the GIO pin
|
||||
HAL_GPIO_Init( m_astInputs[u8Cnt].pstPort, (GPIO_InitTypeDef*)&m_astInputs[u8Cnt].stGPIOInit );
|
||||
}
|
||||
}
|
||||
|
||||
// initialize the outputs
|
||||
// ----------------------
|
||||
if( DIPO_eOutNumberOfOutputs > 0 )
|
||||
{
|
||||
for( u8Cnt = 0 ; u8Cnt < DIPO_eOutNumberOfOutputs; u8Cnt++ )
|
||||
{
|
||||
boOK &= (m_astOutputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_OUTPUT_PP || m_astOutputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_OUTPUT_OD) ? TRUE : FALSE;
|
||||
|
||||
// disable output
|
||||
DIPO_vResetOutput( (DIPO_EnDigitalOutput)u8Cnt );
|
||||
|
||||
HAL_GPIO_Init( m_astOutputs[u8Cnt].pstPort, (GPIO_InitTypeDef*)&m_astOutputs[u8Cnt].stGPIOInit );
|
||||
}
|
||||
}
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: DIPO_vSetOutput
|
||||
// Description: Turns a digital output on or off.
|
||||
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to set on or off
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID DIPO_vSetOutput( DIPO_EnDigitalOutput enOutput )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( enOutput >= DIPO_eOutNumberOfOutputs )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boSetState );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: DIPO_vResetOutput
|
||||
// Description: Sets the output in reset state
|
||||
// Parameters: DIPO_EnDigitalOutput enOutput Digital output
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID DIPO_vResetOutput( DIPO_EnDigitalOutput enOutput )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( enOutput >= DIPO_eOutNumberOfOutputs )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boResetState );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: DIPO_vSetState
|
||||
// Description: Sets the output state
|
||||
// Parameters: DIPO_EnDigitalOutput enOutput Digital output
|
||||
// BOOL boState
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID DIPO_vSetState( DIPO_EnDigitalOutput enOutput, BOOL boState )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( enOutput >= DIPO_eOutNumberOfOutputs )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( boState )
|
||||
{
|
||||
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boSetState );
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boResetState );
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: DIPO_vGetOutput
|
||||
// Description: Reads back a digital output.
|
||||
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to get the data value
|
||||
// Returns: BOOL TRUE, if output is active, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL DIPO_boGetOutput( DIPO_EnDigitalOutput enOutput )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( enOutput >= DIPO_eOutNumberOfOutputs || !IS_GPIO_ALL_INSTANCE( m_astOutputs[enOutput].pstPort ) || !IS_GPIO_PIN( m_astOutputs[enOutput].stGPIOInit.Pin ) )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return( FALSE );
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOL boBitState = TRUE;
|
||||
|
||||
if( READ_BIT( m_astOutputs[enOutput].pstPort->ODR, m_astOutputs[enOutput].stGPIOInit.Pin ) == 0 )
|
||||
{
|
||||
boBitState = FALSE;
|
||||
}
|
||||
|
||||
return( ( m_astOutputs[enOutput].boSetState == TRUE && boBitState == TRUE ) ||\
|
||||
( m_astOutputs[enOutput].boResetState == TRUE && boBitState == FALSE ) ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: DIPO_boGetInput
|
||||
// Description: Reads a digital input
|
||||
// Parameters: DIPO_EnDigitalInput enInput Digital input to read
|
||||
// Returns: BOOL TRUE, if intput is set active, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL DIPO_boGetInput( DIPO_EnDigitalInput enInput )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( enInput >= DIPO_eInNumberOfInputs )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return( FALSE );
|
||||
}
|
||||
#endif
|
||||
|
||||
GPIO_PinState enPinState = HAL_GPIO_ReadPin( m_astInputs[enInput].pstPort, (U16)m_astInputs[enInput].stGPIOInit.Pin );
|
||||
|
||||
return( ( m_astInputs[enInput].boSetState == TRUE && enPinState == GPIO_PIN_SET) ||\
|
||||
( m_astInputs[enInput].boResetState == TRUE && enPinState == GPIO_PIN_RESET) ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: DIPO_vToggleOutput
|
||||
// Description: Toggles the digital output
|
||||
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to toggle
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID DIPO_vToggleOutput( DIPO_EnDigitalOutput enOutput )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( enOutput >= DIPO_eOutNumberOfOutputs )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
HAL_GPIO_TogglePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
132
Core/Drivers/DIPO_DigitalPorts.h
Normal file
132
Core/Drivers/DIPO_DigitalPorts.h
Normal file
@ -0,0 +1,132 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Digital Ports
|
||||
// Filename: DIPO_DigitalPorts.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef DIPO_DIGITALPORTS_H
|
||||
#define DIPO_DIGITALPORTS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
// Enumeration for digital inputs is used as array index later on. Thus enumeration must start
|
||||
// at zero and must be numbered consecutively. Enumeration must never be changed.
|
||||
// Value 0xFF is reserved and must not be used.
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
||||
DIPO_ePG = 0, // 00 DIP 1
|
||||
DIPO_eADR3 = 1, // 01 DIP 2
|
||||
DIPO_eADR2 = 2, // 01 DIP 2
|
||||
DIPO_eADR1 = 3, // 02 DIP 3
|
||||
DIPO_eADR0 = 4, // 03 DIP 4
|
||||
|
||||
DIPO_eInNumberOfInputs, // Must be last entry
|
||||
} DIPO_EnDigitalInput;
|
||||
|
||||
|
||||
// Enumeration for digital outputs is used as array index later on. Thus enumeration must start
|
||||
// at zero and must be numbered consecutively. Enumeration must never be changed.
|
||||
// Value 0xFF is reserved and must not be used.
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
||||
DIPO_eCS_C = 0, // 00 Chip Select Cold
|
||||
DIPO_eCS_H = 1, // 01 Chip Select Hot
|
||||
|
||||
DIPO_eLED = 2, // 02 Test LED
|
||||
DIPO_eEN = 3, // 03 Enable
|
||||
|
||||
|
||||
DIPO_eOutNumberOfOutputs, // Must be last entry
|
||||
} DIPO_EnDigitalOutput;
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL DIPO_boInitializeModule( VOID );
|
||||
VOID DIPO_vSetOutput( DIPO_EnDigitalOutput enOutput );
|
||||
VOID DIPO_vResetOutput( DIPO_EnDigitalOutput enOutput );
|
||||
VOID DIPO_vSetState( DIPO_EnDigitalOutput enOutput, BOOL boState );
|
||||
|
||||
VOID DIPO_vToggleOutput( DIPO_EnDigitalOutput enOutput );
|
||||
BOOL DIPO_boGetInput( DIPO_EnDigitalInput enInput );
|
||||
BOOL DIPO_boGetOutput( DIPO_EnDigitalOutput enOutput );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
123
Core/Drivers/ERRH_ErrorHandler.c
Normal file
123
Core/Drivers/ERRH_ErrorHandler.c
Normal file
@ -0,0 +1,123 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Error Handler
|
||||
// Filename: ERRH_ErrorHandler.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with internal Errors
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "ERRH_ErrorHandler.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: USFL_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL ERRH_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
95
Core/Drivers/ERRH_ErrorHandler.h
Normal file
95
Core/Drivers/ERRH_ErrorHandler.h
Normal file
@ -0,0 +1,95 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Error Handler
|
||||
// Filename: ERRH_ErrorHandler.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef ERRH_ERRORHANDLER_H
|
||||
#define ERRH_ERRORHANDLER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL ERRH_boInitializeModule( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
377
Core/Drivers/SPID_SpiDriver.c
Normal file
377
Core/Drivers/SPID_SpiDriver.c
Normal file
@ -0,0 +1,377 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: SPI-Driver
|
||||
// Filename: SPID_SpiDriver.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the SPI-Driver
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "SPID_SpiDriver.h"
|
||||
|
||||
// Application
|
||||
//#include "../Application/ELOG_ErrorLogger.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// Drivers
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define OS_ADC_SPI_COMPLETE_FLAG ((U32)(1<<0))
|
||||
#define OS_ADC_SPI_ERROR_FLAG ((U32)(1<<1))
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SPI_HandleTypeDef* pstSPIHandle;
|
||||
osMutexId_t pstMutexID;
|
||||
CONST osMutexAttr_t* pstMutexAttribute;
|
||||
U32 u32SPICompleteFlag;
|
||||
U32 u32SPIErrorFlag;
|
||||
} StSPI;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
LOCAL CONST osMutexAttr_t m_stADCMutexAttr =
|
||||
{
|
||||
"SPID_ADC_Mutex", // human readable mutex name
|
||||
osMutexRecursive | osMutexPrioInherit, // attr_bits
|
||||
NULL, // memory for control block
|
||||
0U // size for control block
|
||||
};
|
||||
|
||||
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
|
||||
{
|
||||
"SPID_Event_Flags", // name of the event flags
|
||||
0, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
};
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL StSPI m_astSPI[SPID_eNumberOfSPIs] =
|
||||
{
|
||||
// SPID_eSPI2
|
||||
{
|
||||
&hspi1, // SPI Handle
|
||||
NULL, // pstMutexID
|
||||
&m_stADCMutexAttr, // pstMutexAttribute
|
||||
OS_ADC_SPI_COMPLETE_FLAG, // u32SPICompleteFlag
|
||||
OS_ADC_SPI_ERROR_FLAG, // u32SPIErrorFlag
|
||||
},
|
||||
};
|
||||
|
||||
LOCAL osEventFlagsId_t m_pstEventID = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE SPID_EnSPIs enGetSPI( SPI_HandleTypeDef* pstSPI );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: SPID_boInitializeModule
|
||||
// Description: Initializes the module
|
||||
// Parameters: None
|
||||
// Returns: BOOL, TRUE, if successful, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL SPID_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK= TRUE;
|
||||
|
||||
boOK &= ((m_pstEventID = osEventFlagsNew( &stEventAttribute )) == NULL) ? FALSE : TRUE;
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: SPID_boSend
|
||||
// Description: Sends a number of bytes
|
||||
// Parameters: SPID_StHandle* pstHandle
|
||||
// Returns: BOOL TRUE, if successful, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL SPID_boSend( SPID_StHandle* pstHandle )
|
||||
{
|
||||
BOOL boOK;
|
||||
U32 u32Flags = 0;
|
||||
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( pstHandle == NULL || pstHandle->enSPI >= SPID_eNumberOfSPIs )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return( FALSE );
|
||||
}
|
||||
#endif
|
||||
|
||||
osMutexAcquire( m_astSPI[pstHandle->enSPI].pstMutexID, osWaitForever );
|
||||
|
||||
// clear all flags
|
||||
osEventFlagsClear( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag );
|
||||
|
||||
|
||||
// start SPI transmission
|
||||
boOK = HAL_SPI_Transmit_DMA( m_astSPI[pstHandle->enSPI].pstSPIHandle, pstHandle->pu8TxBuf, pstHandle->u16TransferSize ) == HAL_OK ? TRUE : FALSE;
|
||||
|
||||
if( boOK )
|
||||
{
|
||||
// wait until transmisison done
|
||||
u32Flags = osEventFlagsWait( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag, osFlagsWaitAny, osWaitForever );
|
||||
}
|
||||
|
||||
boOK &= ( u32Flags & m_astSPI[pstHandle->enSPI].u32SPIErrorFlag ) ? FALSE : TRUE;
|
||||
|
||||
osMutexRelease( m_astSPI[pstHandle->enSPI].pstMutexID );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: SPID_boSendReceive
|
||||
// Description: Sends a and receives a number of bytes
|
||||
// Parameters: SPID_StHandle* pstHandle
|
||||
// DIPO_EnDigitalOutput enCS
|
||||
// Returns: BOOL TRUE, if successful, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL SPID_boSendReceive( SPID_StHandle* pstHandle )
|
||||
{
|
||||
BOOL boOK;
|
||||
U32 u32Flags = 0;
|
||||
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( pstHandle == NULL || pstHandle->enSPI >= SPID_eNumberOfSPIs )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return( FALSE );
|
||||
}
|
||||
#endif
|
||||
|
||||
osMutexAcquire( m_astSPI[pstHandle->enSPI].pstMutexID, osWaitForever );
|
||||
|
||||
// clear all flags
|
||||
osEventFlagsClear( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag );
|
||||
|
||||
// start SPI
|
||||
boOK = HAL_SPI_TransmitReceive_DMA( m_astSPI[pstHandle->enSPI].pstSPIHandle, pstHandle->pu8TxBuf, pstHandle->pu8RxBuf, pstHandle->u16TransferSize ) == HAL_OK ? TRUE : FALSE;
|
||||
|
||||
if( boOK )
|
||||
{
|
||||
// wait until transmisison done
|
||||
u32Flags = osEventFlagsWait( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag, osFlagsWaitAny, osWaitForever );
|
||||
}
|
||||
|
||||
boOK &= ( u32Flags & m_astSPI[pstHandle->enSPI].u32SPIErrorFlag ) ? FALSE : TRUE;
|
||||
|
||||
osMutexRelease( m_astSPI[pstHandle->enSPI].pstMutexID );
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_SPI_TxRxCpltCallback
|
||||
// Description: HAL spi rx/tx complete callback function
|
||||
// Parameters: SPI_HandleTypeDef *hspi
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID HAL_SPI_TxRxCpltCallback( SPI_HandleTypeDef *hspi )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( hspi == NULL )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
SPID_EnSPIs enSPI = enGetSPI( hspi );
|
||||
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_SPI_TxCpltCallback
|
||||
// Description: HAL spi tx complete callback function
|
||||
// Parameters: SPI_HandleTypeDef *hspi
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID HAL_SPI_TxCpltCallback( SPI_HandleTypeDef *hspi )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( hspi == NULL )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
SPID_EnSPIs enSPI = enGetSPI( hspi );
|
||||
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_SPI_RxCpltCallback
|
||||
// Description: HAL SPI rx complete callback function
|
||||
// Parameters: SPI_HandleTypeDef *hspi
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID HAL_SPI_RxCpltCallback( SPI_HandleTypeDef *hspi )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( hspi == NULL )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
SPID_EnSPIs enSPI = enGetSPI( hspi );
|
||||
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: HAL_SPI_ErrorCallback
|
||||
// Description: HAL SPI error callback function
|
||||
// Parameters: SPI_HandleTypeDef *hspi
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID HAL_SPI_ErrorCallback( SPI_HandleTypeDef *hspi )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( hspi == NULL )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// check rx overrun error
|
||||
if( hspi->ErrorCode & HAL_SPI_ERROR_OVR )
|
||||
{
|
||||
//ELOG_ADD_LOG( ELOG_eSPIOverrunError );
|
||||
}
|
||||
|
||||
// check rx dma transfer error
|
||||
if( hspi->hdmarx->ErrorCode & HAL_DMA_ERROR_TE )
|
||||
{
|
||||
//ELOG_ADD_LOG( ELOG_eDMAHTransferError );
|
||||
}
|
||||
|
||||
// check tx dma transfer error
|
||||
if( hspi->hdmatx->ErrorCode & HAL_DMA_ERROR_TE )
|
||||
{
|
||||
//ELOG_ADD_LOG( ELOG_eDMAHTransferError );
|
||||
}
|
||||
|
||||
SPID_EnSPIs enSPI = enGetSPI( hspi );
|
||||
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPIErrorFlag );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: enGetSPI
|
||||
// Description: Gets the SPI enumeration to the corresponding SPI handle
|
||||
// Parameters: SPI_HandleTypeDef* pstSPI
|
||||
// Returns: SPID_EnSPIs
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE SPID_EnSPIs enGetSPI( SPI_HandleTypeDef* pstSPI )
|
||||
{
|
||||
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
|
||||
if( pstSPI == NULL )
|
||||
{
|
||||
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
|
||||
ASRT_ASSERT( FALSE );
|
||||
}
|
||||
#endif
|
||||
|
||||
for( U8 u8Cnt = 0; u8Cnt < SPID_eNumberOfSPIs; u8Cnt++ )
|
||||
{
|
||||
if( m_astSPI[u8Cnt].pstSPIHandle == pstSPI )
|
||||
{
|
||||
return( u8Cnt );
|
||||
}
|
||||
}
|
||||
|
||||
//ASRT_ASSERT( FALSE );
|
||||
return( 0 );
|
||||
}
|
||||
|
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
|
190
Core/Drivers/TEMP_Temperature.c
Normal file
190
Core/Drivers/TEMP_Temperature.c
Normal file
@ -0,0 +1,190 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Temp
|
||||
// Filename: TEMP_Temperature.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with the temperature readout
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "TEMP_Temperature.h"
|
||||
|
||||
// Application
|
||||
#include "../Application/VARH_VariableHandler.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// Drivers
|
||||
#include "ADCD_AdcDriver.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define REFRESH_MS 100
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
PRIVATE FLOAT flConvertADCData( U16 dbRTemp );
|
||||
PRIVATE VOID vTask( PVOID arg );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
{
|
||||
"TEMP_Thread", // name of the thread
|
||||
osThreadDetached, // attribute bits
|
||||
NULL, // memory for control block
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for stack
|
||||
1024, // size of stack
|
||||
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
|
||||
0, // TrustZone module identifier
|
||||
0, // reserved (must be 0)
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL FUNCTIONS
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: TEMP_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// This function is thread save
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL TEMP_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
boOK &= ((m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vTempTask
|
||||
// Description: vTempTask
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE VOID vTask( PVOID arg )
|
||||
{
|
||||
UNUSED( arg );
|
||||
|
||||
BOOL boOK = TRUE;
|
||||
U8 error;
|
||||
U16 u16ADC_data[ADCD_eNumberOfTemps];
|
||||
FLOAT flTempData[ADCD_eNumberOfTemps];
|
||||
|
||||
osDelay(10);
|
||||
|
||||
while( TRUE )
|
||||
{
|
||||
boOK &= ADCD_boReadData( ADCD_eHot, &error, &u16ADC_data[ADCD_eHot] );
|
||||
boOK &= ADCD_boReadData( ADCD_eCold, &error, &u16ADC_data[ADCD_eCold] );
|
||||
if( boOK )
|
||||
{
|
||||
flTempData[ADCD_eHot] = flConvertADCData( u16ADC_data[ADCD_eHot] );
|
||||
flTempData[ADCD_eCold] = flConvertADCData( u16ADC_data[ADCD_eCold] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_H, flTempData[ADCD_eHot] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_C, flTempData[ADCD_eCold] );
|
||||
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_Diff, flTempData[ADCD_eHot] - flTempData[ADCD_eCold] );
|
||||
|
||||
}
|
||||
|
||||
osDelay(REFRESH_MS);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: flConvertADCData
|
||||
// Description: Converts resistor value to temperature data
|
||||
// Parameters: U16 u16RTemp
|
||||
// Returns: U16, temperature in Celcius
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE FLOAT flConvertADCData( U16 u16RTemp )
|
||||
{
|
||||
|
||||
FLOAT u16R = u16RTemp / 8192.0f;
|
||||
|
||||
FLOAT flT = 9.9714f * u16R;
|
||||
flT += 235.904f;
|
||||
flT *= u16R;
|
||||
flT += -245.876f;
|
||||
|
||||
return( flT );
|
||||
}
|
87
Core/Drivers/TEMP_Temperature.h
Normal file
87
Core/Drivers/TEMP_Temperature.h
Normal file
@ -0,0 +1,87 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Temperature
|
||||
// Filename: TEMP_Temperature.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef TEMP_TEMPERATURE_H
|
||||
#define TEMP_TEMPERATURE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
#include "ADCD_AdcDriver.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
//typedef VOID (*TEMP_pfnEventCallback)( PVOID pvData );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL TEMP_boInitializeModule( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
275
Core/Drivers/USFL_UserFlash.c
Normal file
275
Core/Drivers/USFL_UserFlash.c
Normal file
@ -0,0 +1,275 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: User Flash
|
||||
// Filename: USFL_UserFlash.c
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This source file contains all functions dealing with internal flash for User Settings
|
||||
//
|
||||
// STM32L432KBUX_FLASH.ld
|
||||
//
|
||||
// DATA (rwx) : ORIGIN = 0x801F800, LENGTH = 2K
|
||||
//
|
||||
// /* Sections */
|
||||
// SECTIONS
|
||||
// {
|
||||
// /* NOLOAD is required for not ereasing this block */
|
||||
// .user_data (NOLOAD) :
|
||||
// {
|
||||
// . = ALIGN(4);
|
||||
// *(.user_data)
|
||||
// . = ALIGN(4);
|
||||
// } > DATA*/
|
||||
// ...
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "USFL_UserFlash.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Application/VARH_VariableHandler.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define USERFLASHSIZE (2000/4) // Bytes -> 64 Bits
|
||||
#define USERFLASHPAGE (63)
|
||||
|
||||
#define VARDEF 0xABCDEF
|
||||
|
||||
#define STARTDEF (((U64)0xAA01F055 << 32) + (VARDEF << 2))
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
FLASH_EraseInitTypeDef stEreaseInit = {
|
||||
FLASH_TYPEERASE_PAGES,
|
||||
FLASH_BANK_1,
|
||||
USERFLASHPAGE,
|
||||
1
|
||||
};
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
U32 u32VarPointer = 0;
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
__attribute__((__section__(".user_data"))) const U64 UserFlash[USERFLASHSIZE];
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL vEreaseUserFlash( void );
|
||||
U32 vFindNextFreePointer( void );
|
||||
U32 u32FindLastPointer( void );
|
||||
U8 u8ConvertWordsToDoubleWords( U8 u8Words );
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: USFL_boInitializeModule
|
||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL USFL_boInitializeModule( VOID )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if( UserFlash[0] != STARTDEF ){
|
||||
boOK &= vEreaseUserFlash();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
VARH_UVariable USFL_uGetVariable ( void ){
|
||||
|
||||
if( u32VarPointer == 0 ) u32VarPointer = u32FindLastPointer();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Descriptionn: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: u32FindNextFreePointer
|
||||
// Description: Finds the next free sector in the flash for saving variables
|
||||
// Parameters: None
|
||||
// Returns: U32 next free pointer
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U32 u32FindNextFreePointer( void ){
|
||||
|
||||
BOOL boFound = FALSE;
|
||||
U32 u32Pointer = u32VarPointer;
|
||||
|
||||
while(!boFound){
|
||||
|
||||
if( ( ( UserFlash[u32Pointer] >> 8 ) & 0xFFFFFF ) == VARDEF ){
|
||||
U8 u8Size = UserFlash[u32Pointer] & 0xFF;
|
||||
if( u8Size == 0 ){
|
||||
boFound = TRUE;
|
||||
} else {
|
||||
u32Pointer += u8ConvertWordsToDoubleWords(u8Size);
|
||||
}
|
||||
} else {
|
||||
u32Pointer += 1;
|
||||
}
|
||||
|
||||
if( u32Pointer >= USERFLASHSIZE ){
|
||||
u32Pointer = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return u32Pointer;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: u32FindLastPointer
|
||||
// Description: Finds the next free sector in the flash for saving variables
|
||||
// Parameters: None
|
||||
// Returns: U32 next free pointer
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U32 u32FindLastPointer( void ){
|
||||
|
||||
BOOL boFound = FALSE;
|
||||
U32 u32Pointer = 0;
|
||||
U8 u8LastSize = 0;
|
||||
|
||||
while(!boFound){
|
||||
|
||||
if( ( UserFlash[u32Pointer] >> 40) == VARDEF ){
|
||||
U8 u8Size = UserFlash[u32Pointer] & 0xFF;
|
||||
if( u8Size == 0 ){
|
||||
boFound = TRUE;
|
||||
u32Pointer -= u8ConvertWordsToDoubleWords(u8LastSize);
|
||||
} else {
|
||||
u32Pointer += u8ConvertWordsToDoubleWords(u8Size);
|
||||
u8LastSize = u8Size;
|
||||
}
|
||||
} else {
|
||||
u32Pointer += 1;
|
||||
}
|
||||
|
||||
if( u32Pointer >= USERFLASHSIZE ){
|
||||
u32Pointer = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return u32Pointer;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: u8ConvertWordsToDoubleWords
|
||||
// Description: Converts 32Bit Word size to 64 Bit Double Word size for saving Vars
|
||||
// Parameters: U8 u8Words
|
||||
// Returns: U8 Double Words
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U8 u8ConvertWordsToDoubleWords( U8 u8Words ) {
|
||||
U8 u8DWords;
|
||||
|
||||
u8Words += 1; // + VARDEF
|
||||
u8DWords = u8Words / 2;
|
||||
u8DWords += u8Words % 2;
|
||||
|
||||
return u8DWords;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vEreaseUserFlash
|
||||
// Description: Ereases the User Flash Sector
|
||||
// Parameters: None
|
||||
// Returns: Boolean TRUE if successful
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL vEreaseUserFlash( void ){
|
||||
uint32_t u32PageError = 0;
|
||||
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
HAL_FLASH_Unlock();
|
||||
boOK &= HAL_FLASHEx_Erase(&stEreaseInit, &u32PageError) == HAL_OK ? TRUE : FALSE;
|
||||
|
||||
if( !boOK ){
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, (U32) &UserFlash[0], STARTDEF);
|
||||
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
95
Core/Drivers/USFL_UserFlash.h
Normal file
95
Core/Drivers/USFL_UserFlash.h
Normal file
@ -0,0 +1,95 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: User Flash
|
||||
// Filename: USFL_UserFlash.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USFL_USERFLASH_H
|
||||
#define USFL_USERFLASH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "../SDEF_StandardDefinitions.h"
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of global macros (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of global Structures (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL VARIABLES
|
||||
// Description: Definition of global variables (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL CONSTANTS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of global functions (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
BOOL USFL_boInitializeModule( VOID );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
174
Core/Inc/FreeRTOSConfig.h
Normal file
174
Core/Inc/FreeRTOSConfig.h
Normal file
@ -0,0 +1,174 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/*
|
||||
* FreeRTOS Kernel V10.3.1
|
||||
* Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* Application specific definitions.
|
||||
*
|
||||
* These definitions should be adjusted for your particular hardware and
|
||||
* application requirements.
|
||||
*
|
||||
* These parameters and more are described within the 'configuration' section of the
|
||||
* FreeRTOS API documentation available on the FreeRTOS.org web site.
|
||||
*
|
||||
* See http://www.freertos.org/a00110.html
|
||||
*----------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* Section where include file can be added */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Ensure definitions are only used by the compiler, and not by the assembler. */
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
|
||||
#include <stdint.h>
|
||||
extern uint32_t SystemCoreClock;
|
||||
void xPortSysTickHandler(void);
|
||||
#endif
|
||||
#ifndef CMSIS_device_header
|
||||
#define CMSIS_device_header "stm32l4xx.h"
|
||||
#endif /* CMSIS_device_header */
|
||||
|
||||
#define configENABLE_FPU 0
|
||||
#define configENABLE_MPU 0
|
||||
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
#define configSUPPORT_DYNAMIC_ALLOCATION 1
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configCPU_CLOCK_HZ ( SystemCoreClock )
|
||||
#define configTICK_RATE_HZ ((TickType_t)1000)
|
||||
#define configMAX_PRIORITIES ( 56 )
|
||||
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)32768)
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 8
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
|
||||
/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
|
||||
/* Defaults to size_t for backward compatibility, but can be changed
|
||||
if lengths will always be less than the number of bytes in a size_t. */
|
||||
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
|
||||
/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
|
||||
|
||||
/* Software timer definitions. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( 2 )
|
||||
#define configTIMER_QUEUE_LENGTH 10
|
||||
#define configTIMER_TASK_STACK_DEPTH 256
|
||||
|
||||
/* The following flag must be enabled only when using newlib */
|
||||
#define configUSE_NEWLIB_REENTRANT 1
|
||||
|
||||
/* CMSIS-RTOS V2 flags */
|
||||
#define configUSE_OS2_THREAD_SUSPEND_RESUME 1
|
||||
#define configUSE_OS2_THREAD_ENUMERATE 1
|
||||
#define configUSE_OS2_EVENTFLAGS_FROM_ISR 1
|
||||
#define configUSE_OS2_THREAD_FLAGS 1
|
||||
#define configUSE_OS2_TIMER 1
|
||||
#define configUSE_OS2_MUTEX 1
|
||||
|
||||
/* Set the following definitions to 1 to include the API function, or zero
|
||||
to exclude the API function. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskCleanUpResources 0
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 1
|
||||
#define INCLUDE_xTimerPendFunctionCall 1
|
||||
#define INCLUDE_xQueueGetMutexHolder 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
||||
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||
#define INCLUDE_eTaskGetState 1
|
||||
|
||||
/*
|
||||
* The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used
|
||||
* by the application thus the correct define need to be enabled below
|
||||
*/
|
||||
#define USE_FreeRTOS_HEAP_4
|
||||
|
||||
/* Cortex-M specific definitions. */
|
||||
#ifdef __NVIC_PRIO_BITS
|
||||
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
|
||||
#define configPRIO_BITS __NVIC_PRIO_BITS
|
||||
#else
|
||||
#define configPRIO_BITS 4
|
||||
#endif
|
||||
|
||||
/* The lowest interrupt priority that can be used in a call to a "set priority"
|
||||
function. */
|
||||
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
|
||||
|
||||
/* The highest interrupt priority that can be used by any interrupt service
|
||||
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
|
||||
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
|
||||
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
|
||||
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
|
||||
|
||||
/* Interrupt priorities used by the kernel port layer itself. These are generic
|
||||
to all Cortex-M ports, and do not rely on any particular library functions. */
|
||||
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
|
||||
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
|
||||
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
|
||||
/* Normal assert() semantics without relying on the provision of an assert.h
|
||||
header file. */
|
||||
/* USER CODE BEGIN 1 */
|
||||
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
|
||||
standard names. */
|
||||
#define vPortSVCHandler SVC_Handler
|
||||
#define xPortPendSVHandler PendSV_Handler
|
||||
|
||||
/* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */
|
||||
|
||||
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1
|
||||
|
||||
/* USER CODE BEGIN Defines */
|
||||
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
|
||||
/* USER CODE END Defines */
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
87
Core/Inc/main.h
Normal file
87
Core/Inc/main.h
Normal file
@ -0,0 +1,87 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define LED_Pin GPIO_PIN_14
|
||||
#define LED_GPIO_Port GPIOC
|
||||
#define ADR3_Pin GPIO_PIN_15
|
||||
#define ADR3_GPIO_Port GPIOC
|
||||
#define EN_Pin GPIO_PIN_8
|
||||
#define EN_GPIO_Port GPIOA
|
||||
#define ADR0_Pin GPIO_PIN_15
|
||||
#define ADR0_GPIO_Port GPIOA
|
||||
#define ADR1_Pin GPIO_PIN_3
|
||||
#define ADR1_GPIO_Port GPIOB
|
||||
#define ADR2_Pin GPIO_PIN_4
|
||||
#define ADR2_GPIO_Port GPIOB
|
||||
#define CS1_Pin GPIO_PIN_5
|
||||
#define CS1_GPIO_Port GPIOB
|
||||
#define CS2_Pin GPIO_PIN_6
|
||||
#define CS2_GPIO_Port GPIOB
|
||||
#define PG_Pin GPIO_PIN_7
|
||||
#define PG_GPIO_Port GPIOB
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
482
Core/Inc/stm32l4xx_hal_conf.h
Normal file
482
Core/Inc/stm32l4xx_hal_conf.h
Normal file
@ -0,0 +1,482 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration template file.
|
||||
* This file should be copied to the application folder and renamed
|
||||
* to stm32l4xx_hal_conf.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef STM32L4xx_HAL_CONF_H
|
||||
#define STM32L4xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
#define HAL_CAN_MODULE_ENABLED
|
||||
/*#define HAL_COMP_MODULE_ENABLED */
|
||||
/*#define HAL_CRC_MODULE_ENABLED */
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
#define HAL_DAC_MODULE_ENABLED
|
||||
/*#define HAL_DCMI_MODULE_ENABLED */
|
||||
/*#define HAL_DMA2D_MODULE_ENABLED */
|
||||
/*#define HAL_DFSDM_MODULE_ENABLED */
|
||||
/*#define HAL_DSI_MODULE_ENABLED */
|
||||
/*#define HAL_FIREWALL_MODULE_ENABLED */
|
||||
/*#define HAL_GFXMMU_MODULE_ENABLED */
|
||||
/*#define HAL_HCD_MODULE_ENABLED */
|
||||
/*#define HAL_HASH_MODULE_ENABLED */
|
||||
/*#define HAL_I2S_MODULE_ENABLED */
|
||||
/*#define HAL_IRDA_MODULE_ENABLED */
|
||||
#define HAL_IWDG_MODULE_ENABLED
|
||||
/*#define HAL_LTDC_MODULE_ENABLED */
|
||||
/*#define HAL_LCD_MODULE_ENABLED */
|
||||
/*#define HAL_LPTIM_MODULE_ENABLED */
|
||||
/*#define HAL_MMC_MODULE_ENABLED */
|
||||
/*#define HAL_NAND_MODULE_ENABLED */
|
||||
/*#define HAL_NOR_MODULE_ENABLED */
|
||||
/*#define HAL_OPAMP_MODULE_ENABLED */
|
||||
/*#define HAL_OSPI_MODULE_ENABLED */
|
||||
/*#define HAL_OSPI_MODULE_ENABLED */
|
||||
/*#define HAL_PCD_MODULE_ENABLED */
|
||||
/*#define HAL_PKA_MODULE_ENABLED */
|
||||
/*#define HAL_QSPI_MODULE_ENABLED */
|
||||
/*#define HAL_QSPI_MODULE_ENABLED */
|
||||
/*#define HAL_RNG_MODULE_ENABLED */
|
||||
/*#define HAL_RTC_MODULE_ENABLED */
|
||||
/*#define HAL_SAI_MODULE_ENABLED */
|
||||
/*#define HAL_SD_MODULE_ENABLED */
|
||||
/*#define HAL_SMBUS_MODULE_ENABLED */
|
||||
/*#define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
#define HAL_SPI_MODULE_ENABLED
|
||||
/*#define HAL_SRAM_MODULE_ENABLED */
|
||||
/*#define HAL_SWPMI_MODULE_ENABLED */
|
||||
/*#define HAL_TIM_MODULE_ENABLED */
|
||||
/*#define HAL_TSC_MODULE_ENABLED */
|
||||
/*#define HAL_UART_MODULE_ENABLED */
|
||||
/*#define HAL_USART_MODULE_ENABLED */
|
||||
/*#define HAL_WWDG_MODULE_ENABLED */
|
||||
/*#define HAL_EXTI_MODULE_ENABLED */
|
||||
/*#define HAL_PSSI_MODULE_ENABLED */
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
#define HAL_EXTI_MODULE_ENABLED
|
||||
#define HAL_I2C_MODULE_ENABLED
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)40000000U) /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal Multiple Speed oscillator (MSI) default value.
|
||||
* This value is the default MSI range value after Reset.
|
||||
*/
|
||||
#if !defined (MSI_VALUE)
|
||||
#define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* MSI_VALUE */
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG.
|
||||
* This internal oscillator is mainly dedicated to provide a high precision clock to
|
||||
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
|
||||
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
|
||||
* which is subject to manufacturing process variations.
|
||||
*/
|
||||
#if !defined (HSI48_VALUE)
|
||||
#define HSI48_VALUE ((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
|
||||
The real value my vary depending on manufacturing process variations.*/
|
||||
#endif /* HSI48_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI1 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI1_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI1_CLOCK_VALUE 2097000U /*!< Value of the SAI1 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI2 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI2_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI2_CLOCK_VALUE 48000U /*!< Value of the SAI2 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 0U
|
||||
#define INSTRUCTION_CACHE_ENABLE 1U
|
||||
#define DATA_CACHE_ENABLE 1U
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Register callback feature configuration ############### */
|
||||
/**
|
||||
* @brief Set below the peripheral configuration to "1U" to add the support
|
||||
* of HAL callback registration/deregistration feature for the HAL
|
||||
* driver(s). This allows user application to provide specific callback
|
||||
* functions thanks to HAL_PPP_RegisterCallback() rather than overwriting
|
||||
* the default weak callback functions (see each stm32l4xx_hal_ppp.h file
|
||||
* for possible callback identifiers defined in HAL_PPP_CallbackIDTypeDef
|
||||
* for each PPP peripheral).
|
||||
*/
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_GFXMMU_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_OSPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_TSC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 0U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DFSDM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dfsdm.h"
|
||||
#endif /* HAL_DFSDM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
#include "Legacy/stm32l4xx_hal_can_legacy.h"
|
||||
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_COMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_comp.h"
|
||||
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_cryp.h"
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DCMI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dcmi.h"
|
||||
#endif /* HAL_DCMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA2D_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dma2d.h"
|
||||
#endif /* HAL_DMA2D_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DSI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dsi.h"
|
||||
#endif /* HAL_DSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GFXMMU_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_gfxmmu.h"
|
||||
#endif /* HAL_GFXMMU_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FIREWALL_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_firewall.h"
|
||||
#endif /* HAL_FIREWALL_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hash.h"
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lcd.h"
|
||||
#endif /* HAL_LCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LTDC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_ltdc.h"
|
||||
#endif /* HAL_LTDC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_mmc.h"
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OPAMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_opamp.h"
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OSPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_ospi.h"
|
||||
#endif /* HAL_OSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PKA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pka.h"
|
||||
#endif /* HAL_PKA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PSSI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pssi.h"
|
||||
#endif /* HAL_PSSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_QSPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_qspi.h"
|
||||
#endif /* HAL_QSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SAI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sai.h"
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMBUS_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smbus.h"
|
||||
#endif /* HAL_SMBUS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SWPMI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_swpmi.h"
|
||||
#endif /* HAL_SWPMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TSC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tsc.h"
|
||||
#endif /* HAL_TSC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t *file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* STM32L4xx_HAL_CONF_H */
|
74
Core/Inc/stm32l4xx_it.h
Normal file
74
Core/Inc/stm32l4xx_it.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_it.h
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L4xx_IT_H
|
||||
#define __STM32L4xx_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void DMA1_Channel2_IRQHandler(void);
|
||||
void DMA1_Channel3_IRQHandler(void);
|
||||
void ADC1_IRQHandler(void);
|
||||
void CAN1_TX_IRQHandler(void);
|
||||
void CAN1_RX0_IRQHandler(void);
|
||||
void CAN1_RX1_IRQHandler(void);
|
||||
void CAN1_SCE_IRQHandler(void);
|
||||
void SPI1_IRQHandler(void);
|
||||
void DMA2_Channel3_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32L4xx_IT_H */
|
198
Core/SDEF_StandardDefinitions.h
Normal file
198
Core/SDEF_StandardDefinitions.h
Normal file
@ -0,0 +1,198 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Standard definitions (data types, structures etc.)
|
||||
// Filename: SDEF_StandardDefinitions.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: This header file contains the data type definitions. These definitions must be
|
||||
// used by all modules. Furthermore all global definitions, structures,
|
||||
// enumerations, etc. are collected inside this file
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
#ifndef STANDARD_DEFINITIONS_H_INCLUDED
|
||||
#define STANDARD_DEFINITIONS_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#define SDEF_S32MAX ((S32)(2147483647)) // Max S32 value
|
||||
#define SDEF_S32MIN ((S32)(-2147483647 - 1) // Min S32 value
|
||||
#define SDEF_U32MAX ((U32)(0xFFFFFFFF)) // Max U32 value
|
||||
#define SDEF_S16MAX ((S16)(32767)) // Max U16 value
|
||||
#define SDEF_S16MIN ((S16)(-32767 - 1)) // Min S16 value
|
||||
#define SDEF_U16MAX ((U16)(0xFFFF)) // Max S16 value
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// DATA TYPES: Definition of standard data types to be used by all modules.
|
||||
//
|
||||
// Prefixes: Each data type has its own prefix (see data type definitions below).
|
||||
// Other definitions are:
|
||||
// XXXX_ Module identifer and file name. Example: "RTCK_RealtimeClock.c". The
|
||||
// identifer is also used for global (public) definitions inside the module.
|
||||
// g_ Global scope (variables). Example: "g_u32ElapsedTime".
|
||||
// m_ Module scope (variables). Example: "m_u32ElapsedTime".
|
||||
// a Array.
|
||||
// p Pointer.
|
||||
// pfn Pointer to function.
|
||||
// St Definition of a structure.
|
||||
// st Instance of a structure. Example:
|
||||
// typedef struct
|
||||
// {
|
||||
// S32 s32CurrentMainsL1;
|
||||
// S32 s32CurrentMainsL2;
|
||||
// S32 s32CurrentMainsL3;
|
||||
// } StMainsCurrent;
|
||||
// StMainsCurrent m_stMainsCurrent;
|
||||
// En Definition of an enumneration.
|
||||
// e Member of an enumeration.
|
||||
// en Instance of an enumeration. Example:
|
||||
// typedef enum
|
||||
// {
|
||||
// eDeviceIdle = 0,
|
||||
// eDeviceActive,
|
||||
// } EnDeviceState;
|
||||
// EnDeviceState m_enDeviceState = eDeviceIdle;
|
||||
//
|
||||
// Example: module scope, array of enums:
|
||||
// m_aenInputs[] = [ eInput1, eInput2, eInput3];
|
||||
//=================================================================================================
|
||||
|
||||
// Allow direct access to variables and functions while unit testing using GCC. This makes
|
||||
// writing the test script much easier. The definition of the datatypes makes the code protable.
|
||||
|
||||
#define LOCAL static // m_ Local data type and visible within the
|
||||
// actual file only
|
||||
#define PRIVATE static // Private function and visible within the
|
||||
// actual file only
|
||||
#define INLINE __inline // force the compiler to inline the function
|
||||
#define EXTERN extern // Defined at external level
|
||||
#define CONST const // Constant data definition
|
||||
#define VOLATILE volatile // Not to be placed in register
|
||||
#define VOID void // v Void type
|
||||
typedef VOID* PVOID; // pv Pointer to void type
|
||||
typedef char CHAR; // c Character
|
||||
typedef CHAR* PCHAR; // pc Pointer to character
|
||||
typedef CHAR* PSZ; // psz Pointer to zero terminated string
|
||||
typedef CONST CHAR* PSZC; // psz Pointer to constant zero terminated string
|
||||
typedef unsigned char U8; // u8 Unsigned byte (DSP is 16 bit anyway)
|
||||
typedef U8* PU8; // pu8 Pointer to unsigned byte
|
||||
typedef signed char S8; // s8 Signed byte (DSP is 16 bit anyway)
|
||||
typedef S8* PS8; // ps8 Pointer to signed byte
|
||||
typedef unsigned short int U16; // u16 Unsigned short integer
|
||||
typedef U16* PU16; // pu16 Pointer to unsigned short integer
|
||||
typedef signed short int S16; // s16 Signed short integer
|
||||
typedef S16* PS16; // ps16 Pointer to signed short integer
|
||||
typedef long unsigned int U32; // u32 Unsigned integer
|
||||
typedef U32* PU32; // pu32 Pointer to unsigned int integer
|
||||
typedef long signed int S32; // s32 Signed integer
|
||||
typedef S32* PS32; // ps32 Pointer to signed integer
|
||||
typedef unsigned long long U64; // u64 Unsigned long long integer
|
||||
typedef U64* PU64; // pu64 Pointer to unsigned long long integer
|
||||
typedef signed long long S64; // s64 Signed long long integer
|
||||
typedef S64* PS64; // ps64 Pointer to signed long long integer
|
||||
typedef float FLOAT; // fl Float data type (32 bit)
|
||||
typedef FLOAT* PFLOAT; // pfl Pointer to float
|
||||
typedef double DOUBLE; // db Double data type (64 bit)
|
||||
typedef DOUBLE* PDOUBLE; // pdb Pointer to double
|
||||
typedef U32 BOOL; // bo Boolean
|
||||
typedef BOOL* PBOOL; // pbo Pointer to bool data type
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0 // False --> must be zero,
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1 // True --> must be one
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((VOID *) 0)
|
||||
#endif
|
||||
|
||||
#define __NORETURN __attribute__((noreturn)) // funciton attribute, function does not return
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SDEF_eNormalByteOrder = 0,
|
||||
SDEF_eReverseByteOrder = 1,
|
||||
} SDEF_EnByteOrder;
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// 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).
|
||||
//=================================================================================================
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
60
Core/Src/freertos.c
Normal file
60
Core/Src/freertos.c
Normal file
@ -0,0 +1,60 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : freertos.c
|
||||
* Description : Code for freertos applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Variables */
|
||||
|
||||
/* USER CODE END Variables */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
651
Core/Src/main.c
Normal file
651
Core/Src/main.c
Normal file
@ -0,0 +1,651 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Filename: main.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 for starting the PeltierController
|
||||
//
|
||||
//=================================================================================================
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "../Application/INIT_Initialization.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
ADC_HandleTypeDef hadc1;
|
||||
DMA_HandleTypeDef hdma_adc1;
|
||||
|
||||
CAN_HandleTypeDef hcan1;
|
||||
|
||||
DAC_HandleTypeDef hdac1;
|
||||
|
||||
I2C_HandleTypeDef hi2c1;
|
||||
|
||||
IWDG_HandleTypeDef hiwdg;
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
DMA_HandleTypeDef hdma_spi1_rx;
|
||||
DMA_HandleTypeDef hdma_spi1_tx;
|
||||
|
||||
/* Definitions for Default */
|
||||
osThreadId_t DefaultHandle;
|
||||
const osThreadAttr_t Default_attributes = {
|
||||
.name = "Default",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_DMA_Init(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_CAN1_Init(void);
|
||||
static void MX_DAC1_Init(void);
|
||||
static void MX_SPI1_Init(void);
|
||||
static void MX_I2C1_Init(void);
|
||||
static void MX_IWDG_Init(void);
|
||||
void vDefaultTask(void *argument);
|
||||
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_CAN1_Init();
|
||||
MX_DAC1_Init();
|
||||
MX_SPI1_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_IWDG_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Init scheduler */
|
||||
osKernelInitialize();
|
||||
|
||||
/* USER CODE BEGIN RTOS_MUTEX */
|
||||
/* add mutexes, ... */
|
||||
/* USER CODE END RTOS_MUTEX */
|
||||
|
||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||
/* add semaphores, ... */
|
||||
/* USER CODE END RTOS_SEMAPHORES */
|
||||
|
||||
/* USER CODE BEGIN RTOS_TIMERS */
|
||||
/* start timers, add new ones, ... */
|
||||
/* USER CODE END RTOS_TIMERS */
|
||||
|
||||
/* USER CODE BEGIN RTOS_QUEUES */
|
||||
/* add queues, ... */
|
||||
/* USER CODE END RTOS_QUEUES */
|
||||
|
||||
/* Create the thread(s) */
|
||||
/* creation of Default */
|
||||
DefaultHandle = osThreadNew(vDefaultTask, NULL, &Default_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
|
||||
/* USER CODE BEGIN RTOS_EVENTS */
|
||||
/* add events, ... */
|
||||
/* USER CODE END RTOS_EVENTS */
|
||||
|
||||
/* Start scheduler */
|
||||
osKernelStart();
|
||||
|
||||
/* We should never get here as control is now taken by the scheduler */
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
||||
RCC_OscInitStruct.PLL.PLLN = 16;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
|
||||
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_ADC1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 0 */
|
||||
|
||||
/* USER CODE END ADC1_Init 0 */
|
||||
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 1 */
|
||||
|
||||
/* USER CODE END ADC1_Init 1 */
|
||||
/** Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
||||
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
|
||||
hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
|
||||
hadc1.Init.LowPowerAutoWait = DISABLE;
|
||||
hadc1.Init.ContinuousConvMode = ENABLE;
|
||||
hadc1.Init.NbrOfConversion = 4;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc1.Init.DMAContinuousRequests = ENABLE;
|
||||
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||
hadc1.Init.OversamplingMode = ENABLE;
|
||||
hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256;
|
||||
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
|
||||
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
|
||||
hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_6;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_16;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_2;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_7;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_3;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_15;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_4;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
|
||||
HAL_ADCEx_Calibration_Start( &hadc1, ADC_SINGLE_ENDED );
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CAN1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_CAN1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN CAN1_Init 0 */
|
||||
|
||||
/* USER CODE END CAN1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN CAN1_Init 1 */
|
||||
|
||||
/* USER CODE END CAN1_Init 1 */
|
||||
hcan1.Instance = CAN1;
|
||||
hcan1.Init.Prescaler = 32;
|
||||
hcan1.Init.Mode = CAN_MODE_NORMAL;
|
||||
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||
hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
|
||||
hcan1.Init.TimeSeg2 = CAN_BS2_6TQ;
|
||||
hcan1.Init.TimeTriggeredMode = DISABLE;
|
||||
hcan1.Init.AutoBusOff = DISABLE;
|
||||
hcan1.Init.AutoWakeUp = DISABLE;
|
||||
hcan1.Init.AutoRetransmission = ENABLE;
|
||||
hcan1.Init.ReceiveFifoLocked = DISABLE;
|
||||
hcan1.Init.TransmitFifoPriority = DISABLE;
|
||||
if (HAL_CAN_Init(&hcan1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN CAN1_Init 2 */
|
||||
|
||||
/* USER CODE END CAN1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DAC1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_DAC1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN DAC1_Init 0 */
|
||||
|
||||
/* USER CODE END DAC1_Init 0 */
|
||||
|
||||
DAC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN DAC1_Init 1 */
|
||||
|
||||
/* USER CODE END DAC1_Init 1 */
|
||||
/** DAC Initialization
|
||||
*/
|
||||
hdac1.Instance = DAC1;
|
||||
if (HAL_DAC_Init(&hdac1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** DAC channel OUT1 config
|
||||
*/
|
||||
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
|
||||
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
|
||||
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
|
||||
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
|
||||
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
|
||||
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN DAC1_Init 2 */
|
||||
|
||||
if (HAL_DACEx_SelfCalibrate( &hdac1, &sConfig , DAC_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE END DAC1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_I2C1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 0 */
|
||||
|
||||
/* USER CODE END I2C1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 1 */
|
||||
|
||||
/* USER CODE END I2C1_Init 1 */
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.Timing = 0x10909CEC;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Analogue filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure Digital filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN I2C1_Init 2 */
|
||||
|
||||
/* USER CODE END I2C1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IWDG Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_IWDG_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 0 */
|
||||
|
||||
/* USER CODE END IWDG_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 1 */
|
||||
|
||||
/* USER CODE END IWDG_Init 1 */
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
|
||||
hiwdg.Init.Window = 4095;
|
||||
hiwdg.Init.Reload = 150;
|
||||
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN IWDG_Init 2 */
|
||||
|
||||
/* USER CODE END IWDG_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_SPI1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN SPI1_Init 0 */
|
||||
|
||||
/* USER CODE END SPI1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN SPI1_Init 1 */
|
||||
|
||||
/* USER CODE END SPI1_Init 1 */
|
||||
/* SPI1 parameter configuration*/
|
||||
hspi1.Instance = SPI1;
|
||||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 7;
|
||||
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
||||
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
|
||||
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN SPI1_Init 2 */
|
||||
|
||||
/* USER CODE END SPI1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void)
|
||||
{
|
||||
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
__HAL_RCC_DMA2_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel2_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn);
|
||||
/* DMA1_Channel3_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
|
||||
/* DMA2_Channel3_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA2_Channel3_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA2_Channel3_IRQn);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, CS1_Pin|CS2_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : LED_Pin */
|
||||
GPIO_InitStruct.Pin = LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : ADR3_Pin */
|
||||
GPIO_InitStruct.Pin = ADR3_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(ADR3_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : EN_Pin */
|
||||
GPIO_InitStruct.Pin = EN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(EN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : ADR0_Pin */
|
||||
GPIO_InitStruct.Pin = ADR0_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(ADR0_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : ADR1_Pin ADR2_Pin PG_Pin */
|
||||
GPIO_InitStruct.Pin = ADR1_Pin|ADR2_Pin|PG_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : CS1_Pin CS2_Pin */
|
||||
GPIO_InitStruct.Pin = CS1_Pin|CS2_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/* USER CODE BEGIN Header_vDefaultTask */
|
||||
/**
|
||||
* @brief Function implementing the Default thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_vDefaultTask */
|
||||
void vDefaultTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
INIT_boCreateTask();
|
||||
osThreadSuspend( DefaultHandle );
|
||||
while(1);
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
528
Core/Src/stm32l4xx_hal_msp.c
Normal file
528
Core/Src/stm32l4xx_hal_msp.c
Normal file
@ -0,0 +1,528 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_msp.c
|
||||
* @brief This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
extern DMA_HandleTypeDef hdma_adc1;
|
||||
|
||||
extern DMA_HandleTypeDef hdma_spi1_rx;
|
||||
|
||||
extern DMA_HandleTypeDef hdma_spi1_tx;
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* External functions --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ExternalFunctions */
|
||||
|
||||
/* USER CODE END ExternalFunctions */
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
/* PendSV_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hadc: ADC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(hadc->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_ADC_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**ADC1 GPIO Configuration
|
||||
PA1 ------> ADC1_IN6
|
||||
PA2 ------> ADC1_IN7
|
||||
PB0 ------> ADC1_IN15
|
||||
PB1 ------> ADC1_IN16
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* ADC1 DMA Init */
|
||||
/* ADC1 Init */
|
||||
hdma_adc1.Instance = DMA2_Channel3;
|
||||
hdma_adc1.Init.Request = DMA_REQUEST_0;
|
||||
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||||
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
|
||||
hdma_adc1.Init.Mode = DMA_CIRCULAR;
|
||||
hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH;
|
||||
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
|
||||
|
||||
/* ADC1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(ADC1_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(ADC1_IRQn);
|
||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hadc: ADC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
if(hadc->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ADC_CLK_DISABLE();
|
||||
|
||||
/**ADC1 GPIO Configuration
|
||||
PA1 ------> ADC1_IN6
|
||||
PA2 ------> ADC1_IN7
|
||||
PB0 ------> ADC1_IN15
|
||||
PB1 ------> ADC1_IN16
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_2);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1);
|
||||
|
||||
/* ADC1 DMA DeInit */
|
||||
HAL_DMA_DeInit(hadc->DMA_Handle);
|
||||
|
||||
/* ADC1 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(ADC1_IRQn);
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CAN MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hcan: CAN handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(hcan->Instance==CAN1)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_MspInit 0 */
|
||||
|
||||
/* USER CODE END CAN1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_CAN1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**CAN1 GPIO Configuration
|
||||
PA11 ------> CAN1_RX
|
||||
PA12 ------> CAN1_TX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* CAN1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(CAN1_TX_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
|
||||
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
|
||||
HAL_NVIC_SetPriority(CAN1_RX1_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(CAN1_RX1_IRQn);
|
||||
HAL_NVIC_SetPriority(CAN1_SCE_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(CAN1_SCE_IRQn);
|
||||
/* USER CODE BEGIN CAN1_MspInit 1 */
|
||||
|
||||
/* USER CODE END CAN1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CAN MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hcan: CAN handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
|
||||
{
|
||||
if(hcan->Instance==CAN1)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END CAN1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_CAN1_CLK_DISABLE();
|
||||
|
||||
/**CAN1 GPIO Configuration
|
||||
PA11 ------> CAN1_RX
|
||||
PA12 ------> CAN1_TX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
|
||||
|
||||
/* CAN1 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(CAN1_TX_IRQn);
|
||||
HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn);
|
||||
HAL_NVIC_DisableIRQ(CAN1_RX1_IRQn);
|
||||
HAL_NVIC_DisableIRQ(CAN1_SCE_IRQn);
|
||||
/* USER CODE BEGIN CAN1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END CAN1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DAC MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hdac: DAC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(hdac->Instance==DAC1)
|
||||
{
|
||||
/* USER CODE BEGIN DAC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END DAC1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_DAC1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**DAC1 GPIO Configuration
|
||||
PA4 ------> DAC1_OUT1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_4;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN DAC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END DAC1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DAC MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hdac: DAC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
|
||||
{
|
||||
if(hdac->Instance==DAC1)
|
||||
{
|
||||
/* USER CODE BEGIN DAC1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END DAC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_DAC1_CLK_DISABLE();
|
||||
|
||||
/**DAC1 GPIO Configuration
|
||||
PA4 ------> DAC1_OUT1
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);
|
||||
|
||||
/* USER CODE BEGIN DAC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END DAC1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hi2c: I2C handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(hi2c->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 0 */
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
|
||||
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**I2C1 GPIO Configuration
|
||||
PA9 ------> I2C1_SCL
|
||||
PA10 ------> I2C1_SDA
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN I2C1_MspInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hi2c: I2C handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
|
||||
{
|
||||
if(hi2c->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_I2C1_CLK_DISABLE();
|
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PA9 ------> I2C1_SCL
|
||||
PA10 ------> I2C1_SDA
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10);
|
||||
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hspi: SPI handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(hspi->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* SPI1 DMA Init */
|
||||
/* SPI1_RX Init */
|
||||
hdma_spi1_rx.Instance = DMA1_Channel2;
|
||||
hdma_spi1_rx.Init.Request = DMA_REQUEST_1;
|
||||
hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_spi1_rx.Init.Mode = DMA_NORMAL;
|
||||
hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(hspi,hdmarx,hdma_spi1_rx);
|
||||
|
||||
/* SPI1_TX Init */
|
||||
hdma_spi1_tx.Instance = DMA1_Channel3;
|
||||
hdma_spi1_tx.Init.Request = DMA_REQUEST_1;
|
||||
hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_spi1_tx.Init.Mode = DMA_NORMAL;
|
||||
hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx);
|
||||
|
||||
/* SPI1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(SPI1_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(SPI1_IRQn);
|
||||
/* USER CODE BEGIN SPI1_MspInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hspi: SPI handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
||||
{
|
||||
if(hspi->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
/* SPI1 DMA DeInit */
|
||||
HAL_DMA_DeInit(hspi->hdmarx);
|
||||
HAL_DMA_DeInit(hspi->hdmatx);
|
||||
|
||||
/* SPI1 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(SPI1_IRQn);
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
320
Core/Src/stm32l4xx_it.c
Normal file
320
Core/Src/stm32l4xx_it.c
Normal file
@ -0,0 +1,320 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "stm32l4xx_it.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern DMA_HandleTypeDef hdma_adc1;
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern CAN_HandleTypeDef hcan1;
|
||||
extern DMA_HandleTypeDef hdma_spi1_rx;
|
||||
extern DMA_HandleTypeDef hdma_spi1_tx;
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M4 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
#if (INCLUDE_xTaskGetSchedulerState == 1 )
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
|
||||
{
|
||||
#endif /* INCLUDE_xTaskGetSchedulerState */
|
||||
xPortSysTickHandler();
|
||||
#if (INCLUDE_xTaskGetSchedulerState == 1 )
|
||||
}
|
||||
#endif /* INCLUDE_xTaskGetSchedulerState */
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32L4xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32l4xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel2 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel2_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_spi1_rx);
|
||||
/* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA1 channel3 global interrupt.
|
||||
*/
|
||||
void DMA1_Channel3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA1_Channel3_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA1_Channel3_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_spi1_tx);
|
||||
/* USER CODE BEGIN DMA1_Channel3_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA1_Channel3_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles ADC1 global interrupt.
|
||||
*/
|
||||
void ADC1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_IRQn 0 */
|
||||
|
||||
/* USER CODE END ADC1_IRQn 0 */
|
||||
HAL_ADC_IRQHandler(&hadc1);
|
||||
/* USER CODE BEGIN ADC1_IRQn 1 */
|
||||
|
||||
/* USER CODE END ADC1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CAN1 TX interrupt.
|
||||
*/
|
||||
void CAN1_TX_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_TX_IRQn 0 */
|
||||
|
||||
/* USER CODE END CAN1_TX_IRQn 0 */
|
||||
HAL_CAN_IRQHandler(&hcan1);
|
||||
/* USER CODE BEGIN CAN1_TX_IRQn 1 */
|
||||
|
||||
/* USER CODE END CAN1_TX_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CAN1 RX0 interrupt.
|
||||
*/
|
||||
void CAN1_RX0_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_RX0_IRQn 0 */
|
||||
|
||||
/* USER CODE END CAN1_RX0_IRQn 0 */
|
||||
HAL_CAN_IRQHandler(&hcan1);
|
||||
/* USER CODE BEGIN CAN1_RX0_IRQn 1 */
|
||||
|
||||
/* USER CODE END CAN1_RX0_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CAN1 RX1 interrupt.
|
||||
*/
|
||||
void CAN1_RX1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_RX1_IRQn 0 */
|
||||
|
||||
/* USER CODE END CAN1_RX1_IRQn 0 */
|
||||
HAL_CAN_IRQHandler(&hcan1);
|
||||
/* USER CODE BEGIN CAN1_RX1_IRQn 1 */
|
||||
|
||||
/* USER CODE END CAN1_RX1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CAN1 SCE interrupt.
|
||||
*/
|
||||
void CAN1_SCE_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_SCE_IRQn 0 */
|
||||
|
||||
/* USER CODE END CAN1_SCE_IRQn 0 */
|
||||
HAL_CAN_IRQHandler(&hcan1);
|
||||
/* USER CODE BEGIN CAN1_SCE_IRQn 1 */
|
||||
|
||||
/* USER CODE END CAN1_SCE_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SPI1 global interrupt.
|
||||
*/
|
||||
void SPI1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_IRQn 0 */
|
||||
|
||||
/* USER CODE END SPI1_IRQn 0 */
|
||||
HAL_SPI_IRQHandler(&hspi1);
|
||||
/* USER CODE BEGIN SPI1_IRQn 1 */
|
||||
|
||||
/* USER CODE END SPI1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA2 channel3 global interrupt.
|
||||
*/
|
||||
void DMA2_Channel3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA2_Channel3_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA2_Channel3_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_adc1);
|
||||
/* USER CODE BEGIN DMA2_Channel3_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA2_Channel3_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
156
Core/Src/syscalls.c
Normal file
156
Core/Src/syscalls.c
Normal file
@ -0,0 +1,156 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file syscalls.c
|
||||
* @author Auto-generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE Minimal System calls file
|
||||
*
|
||||
* For more information about which c-functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the Newlib libc-manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
/* Variables */
|
||||
extern int __io_putchar(int ch) __attribute__((weak));
|
||||
extern int __io_getchar(void) __attribute__((weak));
|
||||
|
||||
|
||||
char *__env[1] = { 0 };
|
||||
char **environ = __env;
|
||||
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles()
|
||||
{
|
||||
}
|
||||
|
||||
int _getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int status)
|
||||
{
|
||||
_kill(status, -1);
|
||||
while (1) {} /* Make sure we hang here */
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = __io_getchar();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
__io_putchar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _close(int file)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty(int file)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _lseek(int file, int ptr, int dir)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open(char *path, int flags, ...)
|
||||
{
|
||||
/* Pretend like we always fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _wait(int *status)
|
||||
{
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink(char *name)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _times(struct tms *buf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _stat(char *file, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _link(char *old, char *new)
|
||||
{
|
||||
errno = EMLINK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fork(void)
|
||||
{
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _execve(char *name, char **argv, char **env)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
80
Core/Src/sysmem.c
Normal file
80
Core/Src/sysmem.c
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sysmem.c
|
||||
* @author Generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE System Memory calls file
|
||||
*
|
||||
* For more information about which C functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the newlib libc manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Pointer to the current high watermark of the heap usage
|
||||
*/
|
||||
static uint8_t *__sbrk_heap_end = NULL;
|
||||
|
||||
/**
|
||||
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
|
||||
* and others from the C library
|
||||
*
|
||||
* @verbatim
|
||||
* ############################################################################
|
||||
* # .data # .bss # newlib heap # MSP stack #
|
||||
* # # # # Reserved by _Min_Stack_Size #
|
||||
* ############################################################################
|
||||
* ^-- RAM start ^-- _end _estack, RAM end --^
|
||||
* @endverbatim
|
||||
*
|
||||
* This implementation starts allocating at the '_end' linker symbol
|
||||
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
|
||||
* The implementation considers '_estack' linker symbol to be RAM end
|
||||
* NOTE: If the MSP stack, at any point during execution, grows larger than the
|
||||
* reserved size, please increase the '_Min_Stack_Size'.
|
||||
*
|
||||
* @param incr Memory size
|
||||
* @return Pointer to allocated memory
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern uint8_t _end; /* Symbol defined in the linker script */
|
||||
extern uint8_t _estack; /* Symbol defined in the linker script */
|
||||
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
|
||||
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
|
||||
const uint8_t *max_heap = (uint8_t *)stack_limit;
|
||||
uint8_t *prev_heap_end;
|
||||
|
||||
/* Initialize heap end at first call */
|
||||
if (NULL == __sbrk_heap_end)
|
||||
{
|
||||
__sbrk_heap_end = &_end;
|
||||
}
|
||||
|
||||
/* Protect heap from growing into the reserved MSP stack */
|
||||
if (__sbrk_heap_end + incr > max_heap)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
prev_heap_end = __sbrk_heap_end;
|
||||
__sbrk_heap_end += incr;
|
||||
|
||||
return (void *)prev_heap_end;
|
||||
}
|
352
Core/Src/system_stm32l4xx.c
Normal file
352
Core/Src/system_stm32l4xx.c
Normal file
@ -0,0 +1,352 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32l4xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File
|
||||
*
|
||||
* This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32l4xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* After each device reset the MSI (4 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* This file configures the system clock as follows:
|
||||
*=============================================================================
|
||||
*-----------------------------------------------------------------------------
|
||||
* System Clock source | MSI
|
||||
*-----------------------------------------------------------------------------
|
||||
* SYSCLK(Hz) | 4000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* HCLK(Hz) | 4000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* AHB Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB1 Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB2 Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_M | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_N | 8
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_P | 7
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_Q | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_R | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI1_P | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI1_Q | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI1_R | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI2_P | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI2_Q | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI2_R | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* Require 48MHz for USB OTG FS, | Disabled
|
||||
* SDIO and RNG clock |
|
||||
*-----------------------------------------------------------------------------
|
||||
*=============================================================================
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Apache License, Version 2.0,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/Apache-2.0
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32l4xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32l4xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (MSI_VALUE)
|
||||
#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* MSI_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/* Note: Following vector table addresses must be defined in line with linker
|
||||
configuration. */
|
||||
/*!< Uncomment the following line if you need to relocate the vector table
|
||||
anywhere in Flash or Sram, else the vector table is kept at the automatic
|
||||
remap of boot address selected */
|
||||
/* #define USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in Sram else user remap will be done in Flash. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS SRAM1_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#else
|
||||
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/* The SystemCoreClock variable is updated in three ways:
|
||||
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||
Note: If you use this function to configure the system clock; then there
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 4000000U;
|
||||
|
||||
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
|
||||
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
|
||||
const uint32_t MSIRangeTable[12] = {100000U, 200000U, 400000U, 800000U, 1000000U, 2000000U, \
|
||||
4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U};
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system.
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void SystemInit(void)
|
||||
{
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/* Configure the Vector Table location -------------------------------------*/
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
|
||||
#endif
|
||||
|
||||
/* FPU settings ------------------------------------------------------------*/
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << 20U)|(3UL << 22U)); /* set CP10 and CP11 Full Access */
|
||||
#endif
|
||||
|
||||
/* Reset the RCC clock configuration to the default reset state ------------*/
|
||||
/* Set MSION bit */
|
||||
RCC->CR |= RCC_CR_MSION;
|
||||
|
||||
/* Reset CFGR register */
|
||||
RCC->CFGR = 0x00000000U;
|
||||
|
||||
/* Reset HSEON, CSSON , HSION, and PLLON bits */
|
||||
RCC->CR &= 0xEAF6FFFFU;
|
||||
|
||||
/* Reset PLLCFGR register */
|
||||
RCC->PLLCFGR = 0x00001000U;
|
||||
|
||||
/* Reset HSEBYP bit */
|
||||
RCC->CR &= 0xFFFBFFFFU;
|
||||
|
||||
/* Disable all interrupts */
|
||||
RCC->CIER = 0x00000000U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
|
||||
* or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
|
||||
*
|
||||
* (*) MSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
|
||||
* 4 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
|
||||
* 16 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (***) HSE_VALUE is a constant defined in stm32l4xx_hal.h file (default value
|
||||
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
|
||||
* frequency of the crystal used. Otherwise, this function may
|
||||
* have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
uint32_t tmp, msirange, pllvco, pllsource, pllm, pllr;
|
||||
|
||||
/* Get MSI Range frequency--------------------------------------------------*/
|
||||
if ((RCC->CR & RCC_CR_MSIRGSEL) == 0U)
|
||||
{ /* MSISRANGE from RCC_CSR applies */
|
||||
msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
|
||||
}
|
||||
else
|
||||
{ /* MSIRANGE from RCC_CR applies */
|
||||
msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
|
||||
}
|
||||
/*MSI frequency range in HZ*/
|
||||
msirange = MSIRangeTable[msirange];
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
switch (RCC->CFGR & RCC_CFGR_SWS)
|
||||
{
|
||||
case 0x00: /* MSI used as system clock source */
|
||||
SystemCoreClock = msirange;
|
||||
break;
|
||||
|
||||
case 0x04: /* HSI used as system clock source */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
|
||||
case 0x08: /* HSE used as system clock source */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
|
||||
case 0x0C: /* PLL used as system clock source */
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
|
||||
SYSCLK = PLL_VCO / PLLR
|
||||
*/
|
||||
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
|
||||
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U ;
|
||||
|
||||
switch (pllsource)
|
||||
{
|
||||
case 0x02: /* HSI used as PLL clock source */
|
||||
pllvco = (HSI_VALUE / pllm);
|
||||
break;
|
||||
|
||||
case 0x03: /* HSE used as PLL clock source */
|
||||
pllvco = (HSE_VALUE / pllm);
|
||||
break;
|
||||
|
||||
default: /* MSI used as PLL clock source */
|
||||
pllvco = (msirange / pllm);
|
||||
break;
|
||||
}
|
||||
pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U);
|
||||
pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U;
|
||||
SystemCoreClock = pllvco/pllr;
|
||||
break;
|
||||
|
||||
default:
|
||||
SystemCoreClock = msirange;
|
||||
break;
|
||||
}
|
||||
/* Compute HCLK clock frequency --------------------------------------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
432
Core/Toolbox/UTIL_Utility.c
Normal file
432
Core/Toolbox/UTIL_Utility.c
Normal file
@ -0,0 +1,432 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V3
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Utility
|
||||
// Filename: UTIL_Utility.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 a few utility functions
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "UTIL_Utility.h"
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: DEFINITIONS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
// defines the registers for the debug printf via trace
|
||||
#define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
|
||||
#define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
|
||||
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
|
||||
#define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
|
||||
#define TRCENA 0x01000000
|
||||
|
||||
#define DBGMCU_IDCOE 0xE0042000
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
// Description: Definition of local macros (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of local enumerations (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: STRUCTURES
|
||||
// Description: Definition of local Structures (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL VARIABLES
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: 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: UTIL_u16StringLength
|
||||
// Description: Returns the length of the string without zero termination
|
||||
// Parameters: PSZ pszString
|
||||
// Returns: U16, string length
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U16 UTIL_u16StringLength( PSZ pszString )
|
||||
{
|
||||
U16 u16Cnt = 0;
|
||||
|
||||
while( *pszString++ != '\0' )
|
||||
{
|
||||
u16Cnt++;
|
||||
}
|
||||
return( u16Cnt );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u16CheckStringLength
|
||||
// Description: Returns TRUE, if the string leght (withouth zero termination) is less or equal the u16MaxLength
|
||||
// Parameters: PSZ pszString
|
||||
// U16 u16MaxLength
|
||||
// Returns: U16, string length
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength )
|
||||
{
|
||||
while( *pszString++ != '\0' )
|
||||
{
|
||||
if( u16MaxLength == 0 )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
u16MaxLength--;
|
||||
}
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_vPuts
|
||||
// Description: Prints a string
|
||||
// Parameters: PSZ pszString
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID UTIL_vPuts( PSZ pszString )
|
||||
{
|
||||
while( *pszString != '\0' )
|
||||
{
|
||||
putchar( *pszString++ );
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u8FindMajority
|
||||
// Description: Finds the majority element of a given data set
|
||||
// Parameters: PU8 pu8Data
|
||||
// U16 u16Length
|
||||
// Returns: U8
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length )
|
||||
{
|
||||
U32 u32MaxCount = 0;
|
||||
S32 s32Index = -1;
|
||||
|
||||
for( U32 i = 0; i < u16Length; i++)
|
||||
{
|
||||
U32 u32Count = 0;
|
||||
for( int j = 0; j < u16Length; j++ )
|
||||
{
|
||||
if(pu8Data[i] == pu8Data[j])
|
||||
u32Count++;
|
||||
}
|
||||
|
||||
// update maxCount if count of
|
||||
// current element is greater
|
||||
if( u32Count > u32MaxCount )
|
||||
{
|
||||
u32MaxCount = u32Count;
|
||||
s32Index = i;
|
||||
}
|
||||
}
|
||||
|
||||
// if maxCount is greater than n/2
|
||||
// return the corresponding element
|
||||
if( u32MaxCount > u16Length/2 && s32Index >= 0 )
|
||||
{
|
||||
return( pu8Data[s32Index] );
|
||||
}
|
||||
else
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_vMemCopy
|
||||
// Description: Copies a set of data.
|
||||
// Parameters: PVOID pvSource pointer to the source data
|
||||
// VOID pvDest pointer destination data
|
||||
// U16 u16Length number of bytes to copy
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length )
|
||||
{
|
||||
// use memcpy for better performance
|
||||
memcpy( pvDest, pvSource, u16Length );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u32MemCopy
|
||||
// Description: Copies a set of data.
|
||||
// Parameters: PVOID pvSource pointer to the source data
|
||||
// PVOID pvDest pointer destination data
|
||||
// U16 u16Length number of bytes to copy
|
||||
// SDEF_EnByteOrder enByteOrder byte order
|
||||
// Returns: U32 Number of Bytes copied
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder )
|
||||
{
|
||||
if( enByteOrder == SDEF_eNormalByteOrder )
|
||||
{
|
||||
UTIL_vMemCopy( pvSource, pvDest, u16Length );
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy the bytes in reverse order
|
||||
PU8 pu8Source = pvSource;
|
||||
PU8 pu8Dest = pvDest;
|
||||
for( U16 u16Cnt = 0; u16Cnt < (u16Length+1)/2; u16Cnt++ )
|
||||
{
|
||||
pu8Dest[u16Cnt] = pu8Source[u16Length - 1 - u16Cnt];
|
||||
pu8Dest[u16Length - 1 - u16Cnt] = pu8Source[u16Cnt];
|
||||
}
|
||||
}
|
||||
|
||||
return( u16Length );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_vMemCopyU32
|
||||
// Description: Copies a set of four byte data types.
|
||||
// Parameters: PU32 pu32Source pointer to the source data
|
||||
// PU32 pu32Dest pointer destination data
|
||||
// U16 u16Length number of bytes to copy
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length )
|
||||
{
|
||||
while( u16Length-- > 0 )
|
||||
{
|
||||
*pu32Dest++ = *pu32Source++;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_boMemCompare
|
||||
// Description: Compares a set of data to equality
|
||||
// Parameters: PU8 pu8Data1 pointer to first data set
|
||||
// PU8 pu8Data2 pointer to second data set
|
||||
// U32 u32Length number of bytes to compare
|
||||
// Returns: BOOL TRUE, if compared data is equal, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length )
|
||||
{
|
||||
while( u32Length-- > 0 )
|
||||
{
|
||||
if( *pu8Data1++ != *pu8Data2++ )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_boMemCompareVal
|
||||
// Description: Compares if the all the data has the value specifed with u8Value.
|
||||
// Parameters: PU8 pu8Data pointer to data set
|
||||
// U8 u8Value value to compare
|
||||
// U32 u32Length number of bytes to compare
|
||||
// Returns: BOOL TRUE, if compared data is equal, otherwise FALSE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL UTIL_boMemCompareVal( PU8 pu8Data, U8 u8Value, U32 u32Length )
|
||||
{
|
||||
while( u32Length-- > 0 )
|
||||
{
|
||||
if( *pu8Data != u8Value)
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
pu8Data++;
|
||||
}
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u8DecToBCD
|
||||
// Description: Converts decimal encoded byte to bcd value
|
||||
// Parameters: decimal value to convert to bcd
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U8 UTIL_u8DecToBCD( U8 u8Value )
|
||||
{
|
||||
return ( (u8Value/10*16) + (u8Value%10) );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u8BCDToDec
|
||||
// Description: Converts bcd to decimal
|
||||
// Parameters: bcd value to convert to decimal
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U8 UTIL_u8BCDToDec( U8 u8Value )
|
||||
{
|
||||
return ( (u8Value/16*10) + (u8Value%16) );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_vReverseBytes
|
||||
// Description: Reverses the byte order
|
||||
// Parameters: PU8 pu8Data data
|
||||
// U16 u16NumberOfBytes number of bytes
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes )
|
||||
{
|
||||
U8 u8Tmp;
|
||||
for( U16 u16Cnt = 0; u16Cnt < u16NumberOfBytes/2; u16Cnt++ )
|
||||
{
|
||||
u8Tmp = pu8Data[u16Cnt];
|
||||
pu8Data[u16Cnt] = pu8Data[u16NumberOfBytes - 1 - u16Cnt];
|
||||
pu8Data[u16NumberOfBytes - 1 - u16Cnt] = u8Tmp;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u32RevU32
|
||||
// Description: Reverses the bytes of an U32
|
||||
// Parameters: U32 u32Data
|
||||
// Returns: U32 reversed data
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U32 UTIL_u32RevU32( U32 u32Data )
|
||||
{
|
||||
return( __REV(u32Data) );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u32RevFLOAT
|
||||
// Description: Reverses the bytes of an FLOAT
|
||||
// Parameters: FLOAT flData
|
||||
// Returns: U32 reversed data
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U32 UTIL_u32RevFLOAT( FLOAT flData )
|
||||
{
|
||||
U32 u32Data = *(PU32)&flData;
|
||||
return( __REV(u32Data) );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_u16RevU16
|
||||
// Description: Reverses the bytes of an U16
|
||||
// Parameters: U16 u16Data
|
||||
// Returns: U16 reversed data
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
U16 UTIL_u16RevU16( U16 u16Data )
|
||||
{
|
||||
return( (U16)__REV16(u16Data) );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: UTIL_cGetDeviceRevision
|
||||
// Description: Gets the silicon revision of the STM32F437
|
||||
// Parameters: None
|
||||
// Returns: CHAR
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
CHAR UTIL_cGetDeviceRevision( VOID )
|
||||
{
|
||||
U16 u16DeviceID = (*(PU32)DBGMCU_IDCOE) >> 16;
|
||||
|
||||
switch( u16DeviceID )
|
||||
{
|
||||
case 0x100:
|
||||
return( 'A' );
|
||||
|
||||
case 0x1001:
|
||||
return( 'Z' );
|
||||
|
||||
case 0x1003:
|
||||
return( 'Y' );
|
||||
|
||||
case 0x1007:
|
||||
return( '1' );
|
||||
|
||||
case 0x2001:
|
||||
return( '3' );
|
||||
|
||||
default:
|
||||
return( '0' );
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: fputc
|
||||
// Description: Prototype for printf
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
int fputc( int ch, FILE *f )
|
||||
{
|
||||
UNUSED( f ); // file stream not used
|
||||
|
||||
if( DEMCR & TRCENA )
|
||||
{
|
||||
while( ITM_Port32(0) == 0 );
|
||||
ITM_Port8(0) = (U8)ch;
|
||||
}
|
||||
return( ch );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL FUNCTIONS
|
||||
// Description: Definition (implementation) of local functions.
|
||||
//=================================================================================================
|
||||
|
202
Core/Toolbox/UTIL_Utility.h
Normal file
202
Core/Toolbox/UTIL_Utility.h
Normal file
@ -0,0 +1,202 @@
|
||||
//=================================================================================================
|
||||
//
|
||||
// Company: Paul Scherrer Institut
|
||||
// 5232 Villigen PSI
|
||||
// Switzerland
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V3
|
||||
// Author: Noah Piqué (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Module: Utility
|
||||
// Filename: UTIL_Utility.h
|
||||
// Date: Handled by Subversion (version control system)
|
||||
// Revision: Handled by Subversion (version control system)
|
||||
// History: Handled by Subversion (version control system)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef UTIL_UTILITY_H
|
||||
#define UTIL_UTILITY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "../SDEF_StandardDefinitions.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).
|
||||
//=================================================================================================
|
||||
|
||||
//macro for filename without path
|
||||
/* #define _FILE_ ((PSZ)(strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : \
|
||||
(strrchr(__FILE__, '\\') ? (strrchr(__FILE__, '\\') + 1) : __FILE__)))*/
|
||||
|
||||
#define _FILE_ __FILE__
|
||||
|
||||
#define _LINE_ __LINE__
|
||||
|
||||
//checks if a pointer is valid
|
||||
#define UTIL_IS_FUNC( pfnFoo ) ( pfnFoo != NULL )
|
||||
|
||||
#define UTIL_32BitAlign( u32Address ) ((((U32)((u32Address)+4UL)/4UL))*4UL)
|
||||
|
||||
#define UTIL_IS_POWER_OF_TWO( u32Numb ) ((u32Numb & (u32Numb - 1)) == 0)
|
||||
|
||||
#define UTIL_u16ConcatenateBytes( u8UpperByte, u8LowerByte) ( (U16)((U16)u8UpperByte << 8) | (U16)u8LowerByte )
|
||||
|
||||
// approx delay of 1us
|
||||
#define DELAY_US( u32Us ) do{\
|
||||
for( U32 u32Cnt = (SystemCoreClock >> 24U) * (u32Us); u32Cnt > 0U; u32Cnt-- ) \
|
||||
{ \
|
||||
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
|
||||
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
#define DELAY_MS( u32Ms ) do{\
|
||||
for( U32 u32Cnt = (SystemCoreClock >> 14U) * (u32Ms); u32Cnt > 0U; u32Cnt-- ) \
|
||||
{ \
|
||||
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\
|
||||
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(x) ((void)(x))
|
||||
#endif
|
||||
|
||||
#define UTIL_SET_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add |= (u32BitMask) )
|
||||
#define UTIL_CLEAR_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add &= ~(u32BitMask) )
|
||||
|
||||
#define UTIL_DEFINE_CRITICAL() U32 u32PRIMASK
|
||||
|
||||
// Enter Critical:
|
||||
// implements a memory barrier to ensure memory operations completed before
|
||||
// stores the interrupt status register
|
||||
// disables interrupts
|
||||
#define UTIL_ENTER_CRITICAL() do{ \
|
||||
__DMB(); \
|
||||
u32PRIMASK = __get_PRIMASK(); \
|
||||
__disable_irq(); \
|
||||
}while(0)
|
||||
|
||||
// Exit Critical:
|
||||
// implements a memory barrier to ensure memory operations completed before
|
||||
// restores the interrupt status register
|
||||
#define UTIL_EXIT_CRITICAL() do{ \
|
||||
__DMB(); \
|
||||
__set_PRIMASK( u32PRIMASK ); \
|
||||
}while(0)
|
||||
|
||||
// bit band definitions
|
||||
#define UTIL_BB_SRAM( Address, BitNumber ) (*(VOLATILE PU32)(SRAM_BB_BASE + ((U32)Address - SRAM_BASE)*32 + BitNumber*4 ) )
|
||||
#define UTIL_BB_BKRAM( Address, BitNumber ) (*(VOLATILE PU32)(BKPSRAM_BB_BASE + ((U32)Address - BKPSRAM_BASE)*32 + BitNumber*4 ) )
|
||||
#define UTIL_BB_PERI( Address, BitNumber ) (*(VOLATILE PU32)(PERIPH_BB_BASE + ((U32)Address - PERIPH_BASE)*32 + BitNumber*4 ) )
|
||||
|
||||
// Basic bit band function definitions
|
||||
#define UTIL_BB_SRAM_ClearBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 0)
|
||||
#define UTIL_BB_SRAM_SetBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 1)
|
||||
#define UTIL_BB_SRAM_GetBit( Address, BitNumber) UTIL_BB_SRAM( Address, BitNumber )
|
||||
|
||||
#define UTIL_BB_PERI_ClearBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 0)
|
||||
#define UTIL_BB_PERI_SetBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 1)
|
||||
#define UTIL_BB_PERI_GetBit( Address, BitNumber) UTIL_BB_PERI( Address, BitNumber )
|
||||
|
||||
#define UTIL_BB_BKRAM_ClearBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 0)
|
||||
#define UTIL_BB_BKRAM_SetBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 1)
|
||||
#define UTIL_BB_BKRMA_GetBit( Address, BitNumber) UTIL_BB_BKRAM( Address, BitNumber )
|
||||
|
||||
// Checks, if the core is in debug mode
|
||||
#define UTIL_IS_DEBUGGER_ATTACHED() (CoreDebug_DHCSR_C_DEBUGEN_Msk & CoreDebug->DHCSR)
|
||||
|
||||
//=================================================================================================
|
||||
// Section: ENUMERATIONS
|
||||
// Description: Definition of global enumerations (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: 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).
|
||||
//=================================================================================================
|
||||
|
||||
U16 UTIL_u16StringLength( PSZ pszString );
|
||||
BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength );
|
||||
VOID UTIL_vPuts( PSZ pszString );
|
||||
|
||||
VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length );
|
||||
U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder );
|
||||
VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length );
|
||||
BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length );
|
||||
BOOL UTIL_boMemCompareVal( PU8 pu8Data1, U8 u8Value, U32 u32Length );
|
||||
|
||||
U8 UTIL_u8GetPinSource( U16 u16GIPO_Pin );
|
||||
U8 UTIL_u8DecToBCD( U8 u8Value );
|
||||
U8 UTIL_u8BCDToDec( U8 u8Value );
|
||||
VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes );
|
||||
U32 UTIL_u32RevU32( U32 u32Data );
|
||||
U32 UTIL_u32RevFLOAT( FLOAT flData );
|
||||
U16 UTIL_u16RevU16( U16 u16Data );
|
||||
U8 UTIL_u8GetNumberOfClkCycles( DOUBLE dtime );
|
||||
|
||||
CHAR UTIL_cGetDeviceRevision( VOID );
|
||||
|
||||
U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length );
|
||||
|
||||
// printf prototype for debug printf
|
||||
int fputc( int ch, FILE *f );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user