New VARH einbinden + Code verschönern,syntax check
This commit is contained in:
@ -53,42 +53,42 @@
|
||||
//=================================================================================================
|
||||
|
||||
// define commands
|
||||
#define CMD_READ (0<<7)
|
||||
#define CMD_WRITE (1<<7)
|
||||
#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 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 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 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 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))
|
||||
@ -155,11 +155,11 @@ 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;
|
||||
SPID_eADC, // enSPI;
|
||||
0xFF, // enCS (0xFF = hardware chip select)
|
||||
m_au8TxData, // pu8TxBuf;
|
||||
m_au8RxData, // pu8RxBuf;
|
||||
0, // u16TransferSize;
|
||||
};
|
||||
|
||||
|
||||
@ -168,9 +168,6 @@ LOCAL SPID_StHandle m_stSPIHandle =
|
||||
// Description: Definition of local functions (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
//PRIVATE VOID vAttachDataReadyISR ( VOID );
|
||||
//PRIVATE VOID vDeattachDataReadyISR ( VOID );
|
||||
|
||||
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit );
|
||||
PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit );
|
||||
|
||||
@ -204,29 +201,35 @@ BOOL ADCD_boInitializeModule( VOID )
|
||||
BOOL boOK = TRUE;
|
||||
U16 u16Data = 0;
|
||||
|
||||
boOK &= ((m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
|
||||
boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr ) ) == NULL ) ? FALSE : TRUE;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
|
||||
DIPO_vSetOutput(DIPO_eCS_C);
|
||||
boOK &= boWriteReg(REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE);
|
||||
DIPO_vResetOutput(DIPO_eCS_C);
|
||||
DIPO_vSetOutput(DIPO_eCS_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);
|
||||
|
||||
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);
|
||||
// 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 );
|
||||
|
||||
@ -238,61 +241,56 @@ BOOL ADCD_boInitializeModule( VOID )
|
||||
// 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 ADCD_boReadData( ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
*pu8Error = 0; // reset error state
|
||||
U16 u16Data = 0;
|
||||
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 );
|
||||
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 );
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boReadReg( REG_RTD_MSB, &u16Data, TRUE );
|
||||
DIPO_vResetOutput( CS );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
if( !boOK )
|
||||
{
|
||||
*pu8Error |= ADCD_SPI_FAILURE;
|
||||
*pu8Error |= ADCD_SPI_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if((u16Data & 0x01) == 0x01)
|
||||
if( ( u16Data & 0x01 ) == 0x01 )
|
||||
{
|
||||
*pu8Error |= ADCD_STATUS_DATA_ERROR;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DIPO_vSetOutput(CS);
|
||||
boOK &= boReadReg(REG_FAULT_STATUS, &u16Data, FALSE);
|
||||
DIPO_vResetOutput(CS);
|
||||
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);
|
||||
|
||||
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;
|
||||
@ -304,16 +302,12 @@ BOOL ADCD_boReadData(ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data)
|
||||
*pu16Data = u16Data;
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DIPO_vSetOutput( CS );
|
||||
boOK &= boWriteReg( REG_CONFIG, CONFIG | CONFIG_FAULTCYCLE_AUTO , FALSE );
|
||||
DIPO_vResetOutput( CS );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
DIPO_vSetOutput(CS);
|
||||
|
||||
boOK &= boWriteReg(REG_CONFIG, CONFIG | CONFIG_FAULTCYCLE_AUTO , FALSE);
|
||||
|
||||
DIPO_vResetOutput(CS);
|
||||
|
||||
osMutexRelease( m_pstMutexID );
|
||||
|
||||
return( boOK );
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
@ -332,11 +326,11 @@ BOOL ADCD_boReadData(ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data)
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit )
|
||||
{
|
||||
BOOL boOK = TRUE;
|
||||
BOOL boOK = TRUE;
|
||||
|
||||
if(boIs16bit){
|
||||
if( boIs16bit ){
|
||||
m_au8TxData[0] = CMD_WRITE | u8Register;
|
||||
m_au8TxData[1] = (U8)(u16Data>>8);
|
||||
m_au8TxData[1] = (U8)u16Data>>8;
|
||||
m_au8TxData[2] = (U8)u16Data;
|
||||
m_stSPIHandle.u16TransferSize = 3;
|
||||
boOK &= SPID_boSendReceive( &m_stSPIHandle );
|
||||
@ -347,7 +341,7 @@ PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit )
|
||||
boOK &= SPID_boSendReceive( &m_stSPIHandle );
|
||||
}
|
||||
|
||||
return( boOK );
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
@ -355,14 +349,14 @@ PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit )
|
||||
// Description: Reads the regiser
|
||||
// Parameters: U8 u8Register
|
||||
// PU16 pu16Data
|
||||
// BOOL boIs16bit TRUE, if Data is 16bit, FALSE, if Data is 8bit
|
||||
// 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){
|
||||
if( boIs16bit ){
|
||||
m_au8TxData[0] = CMD_READ | u8Register;
|
||||
m_au8TxData[1] = 0;
|
||||
m_au8TxData[2] = 0;
|
||||
@ -370,7 +364,7 @@ PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit )
|
||||
|
||||
boOK &= SPID_boSendReceive( &m_stSPIHandle );
|
||||
|
||||
*pu16Data = ((U16)m_au8RxData[1]<<8) | ((U16)m_au8RxData[2]<<0);
|
||||
*pu16Data = ( (U16)m_au8RxData[1]<<8 ) | ( (U16)m_au8RxData[2]<<0 );
|
||||
} else {
|
||||
m_au8TxData[0] = CMD_READ | u8Register;
|
||||
m_au8TxData[1] = 0;
|
||||
@ -383,44 +377,3 @@ PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit )
|
||||
|
||||
return( boOK );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vEventCallback
|
||||
// Description: Callback for events
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//PRIVATE VOID vEventCallback( PVOID pvData )
|
||||
//{
|
||||
// osEventFlagsSet( m_pstEventID, (U32)pvData );
|
||||
//}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vAttachDataReadyISR
|
||||
// Description: Set Data Ready Pin Mode to ISR falling Edge
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//PRIVATE VOID vAttachDataReadyISR ( VOID )
|
||||
//{
|
||||
// GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
// /*Configure GPIO pin : ADC_RDY_Pin */
|
||||
// GPIO_InitStruct.Pin = m_u16DataReadyPin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// HAL_GPIO_Init((GPIO_TypeDef*)m_pstDataReadyPort, &GPIO_InitStruct);
|
||||
//}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: vDeattachDataReadyISR
|
||||
// Description: Set Data Ready Pin Mode to Input
|
||||
// Parameters: None
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//PRIVATE VOID vDeattachDataReadyISR ( VOID )
|
||||
//{
|
||||
//
|
||||
// HAL_GPIO_DeInit((GPIO_TypeDef*)m_pstDataReadyPort, m_u16DataReadyPin);
|
||||
|
||||
//}
|
||||
|
||||
|
Reference in New Issue
Block a user