?? des_mc33972.c
字號:
/*******************************************************************************/
/**
Copyright (c) 2007 Freescale Semiconductor
\file des_MC33972.c
\brief Functions for MSD (MC33972) handling
\author Freescale Semiconductor
\author B05114
\version 0.2
\date May/2007
*/
/*******************************************************************************/
/** Variable types and common definitions */
#include "typedefs.h"
/** GPIO definitions */
#include "lle_GPIO.h"
/** SPI definitions */
#include "lle_SPI.h"
/** SBC definitions */
#include "des_MC33972.h"
/** Backup arrays for MSDI configuration */
/** SPx inputs configuration */
UINT8 u8MSDI_SPxConfig[2] ={MSDI_I_SETTINGS_INIT,
MSDI_II_SETTINGS_INIT};
/** Wetting current settings for SPx inputs */
UINT8 u8MSDI_SPx_Wettingcurrent[2] ={MSDI_I_WETCURRENTSP_INIT,
MSDI_II_WETCURRENTSP_INIT};
/** Wetting current settings for SGx inputs */
UINT16 u16MSDI_SGx_Wettingcurrent[2] ={MSDI_I_WETCURRENTSP_INIT,
MSDI_II_WETCURRENTSP_INIT};
/** Wetting timer settings for SPx inputs */
UINT8 u8MSDI_SPx_Wettingtimer[2] ={MSDI_I_WETTIMERSP_INIT,
MSDI_II_WETTIMERSP_INIT};
/** Wetting timer settings for SGx inputs */
UINT16 u16MSDI_SGx_Wettingtimer[2] ={MSDI_I_WETTIMERSG_INIT,
MSDI_II_WETTIMERSG_INIT};
/*******************************************************************************/
/**
* \brief Write MSDI register and read Serial Output response
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8MSDI_Comm: MSDI configuration command \n
u8MSDI_H: Higher byte with configuration data \n
u8MSDI_L: Lower byte with configuration data
* \return void (Received data are stored in array u8MSDI_Frame)
*/
void des_MC33972_SendCommand(UINT8 u8MSDI, UINT8 u8MSDI_Command, UINT16 u8MSDI_Data)
{
UINT8 u8MSDI_Frame[3]; /* Data array to be sent to the MSDI */
u8MSDI_Frame[2] = 0xFF & u8MSDI_Data;
u8MSDI_Frame[1] = u8MSDI_Data>> 8;
u8MSDI_Frame[0] = u8MSDI_Command;
if(!u8MSDI) CS_MC33972_I = 0; /* CS low */
if(u8MSDI) CS_MC33972_II = 0;
lle_SPI_24(u8MSDI_Frame); /* Send data to SBC */
if(!u8MSDI) CS_MC33972_I = 1; /* CS high */
if(u8MSDI) CS_MC33972_II = 1;
}
/*******************************************************************************/
/**
* \brief MSDI I initial configuration with values from des_MC33972.h
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II
* \return void
*/
void des_MC33972_Config(UINT8 u8MSDI)
{
if(!u8MSDI) /* Default configuration for MSDI I */
{
des_MC33972_SendCommand(u8MSDI, MSDI_SETTINGS_CMD, MSDI_I_SETTINGS_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WAKEUPINTSP_CMD, MSDI_I_WKPINTSP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WAKEUPINTSG_CMD, MSDI_I_WKPINTSG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETCURRENTSP_CMD, MSDI_I_WETCURRENTSP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETCURRENTSG_CMD, MSDI_I_WETCURRENTSG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_ANALOG_CMD, MSDI_I_ANALOG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETTINGTIMERSP_CMD, MSDI_I_WETTIMERSP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETTINGTIMERSG_CMD, MSDI_I_WETTIMERSG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_TRISTATESP_CMD, MSDI_I_TRISTATESP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_TRISTATESG_CMD, MSDI_I_TRISTATESG_INIT);
}
if(u8MSDI) /* Default configuration for MSDI II */
{
des_MC33972_SendCommand(u8MSDI, MSDI_SETTINGS_CMD, MSDI_II_SETTINGS_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WAKEUPINTSP_CMD, MSDI_II_WKPINTSP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WAKEUPINTSG_CMD, MSDI_II_WKPINTSG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETCURRENTSP_CMD, MSDI_II_WETCURRENTSP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETCURRENTSG_CMD, MSDI_II_WETCURRENTSG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_ANALOG_CMD, MSDI_II_ANALOG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETTINGTIMERSP_CMD, MSDI_II_WETTIMERSP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_WETTINGTIMERSG_CMD, MSDI_II_WETTIMERSG_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_TRISTATESP_CMD, MSDI_II_TRISTATESP_INIT);
des_MC33972_SendCommand(u8MSDI, MSDI_TRISTATESG_CMD, MSDI_II_TRISTATESG_INIT);
}
}
/*******************************************************************************/
/**
* \brief Set MSDI in sleep mode and configures scan and interrupt timers
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8TimersConfig: Scan and interrupt timer values as defined in des_MC33972.h
* \return void
*/
void des_MC33972_SleepMode_IntTimers(UINT8 u8MSDI, UINT8 u8TimersConfig)
{
des_MC33972_SendCommand(u8MSDI, MSDI_SLEEP_CMD, u8TimersConfig);
}
/*******************************************************************************/
/**
* \brief Configure MSDI SPx pin(s) as switch to battery or switch to ground
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8SelectSP: SPx pin(s) as defined in des_MC33972.h \n
(MSDI_SP0, MSDI_SP1, ...MSDI_SP7) OR combinations are valid \n
u8Connect: MSDI_SWtoBAT, MSDI_SWtoGND
* \return void
*/
void des_MC33972_Set_SPinputs(UINT8 u8MSDI, UINT8 u8SelectSP, UINT8 u8Connect)
{
if(u8Connect)
u8MSDI_SPxConfig[u8MSDI] |= u8SelectSP; /* Set selected bits */
if(!u8Connect)
u8MSDI_SPxConfig[u8MSDI] &= ~u8SelectSP; /* Clear selected bits */
des_MC33972_SendCommand(u8MSDI, MSDI_SETTINGS_CMD, u8MSDI_SPxConfig[u8MSDI]);
}
/*******************************************************************************/
/**
* \brief Select SPx inputs wetting current
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8SPin: SPx pin(s) as defined in des_MC33972.h \n
(MSDI_SP0, MSDI_SP1, ... MSDI_SP7) OR combinations are valid \n
bCurrent: MSDI_2mA, MSDI_16mA
* \return void
*/
void des_MC33972_Set_SP_WettingCurrent(UINT8 u8MSDI, UINT8 u8SPin, UINT8 bCurrent)
{
if(!bCurrent)
u8MSDI_SPx_Wettingcurrent[u8MSDI] &= ~u8SPin; /* Clear selected bits */
if(bCurrent)
u8MSDI_SPx_Wettingcurrent[u8MSDI] |= u8SPin; /* Set selected bits */
des_MC33972_SendCommand(u8MSDI, MSDI_WETCURRENTSP_CMD,
u8MSDI_SPx_Wettingcurrent[u8MSDI]);
}
/*******************************************************************************/
/**
* \brief Select SGx inputs wetting current
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u16SGin: SGx pin(s) as defined in des_MC33972.h \n
(MSDI_SG0, MSDI_SG1, ...MSDI_SG13) OR combinations are valid \n
bCurrent: MSDI_2mA, MSDI_16mA
* \return void
*/
void des_MC33972_Set_SG_WettingCurrent(UINT8 u8MSDI, UINT16 u16SGin, UINT8 bCurrent)
{
if(!bCurrent)
u16MSDI_SGx_Wettingcurrent[u8MSDI] &= ~u16SGin; /* Clear selected bits */
if(bCurrent)
u16MSDI_SGx_Wettingcurrent[u8MSDI] |= u16SGin; /* Set selected bits */
des_MC33972_SendCommand(u8MSDI, MSDI_WETCURRENTSG_CMD,
u16MSDI_SGx_Wettingcurrent[u8MSDI]);
}
/*******************************************************************************/
/**
* \brief Enable/ disable the wetting timer for SPx inputs
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8SPin: SPx pin(s) as defined in des_MC33972.h \n
(MSDI_SP0, MSDI_SP1, ...MSDI_SP7) OR combinations are valid \n
u8Select: ENABLE, DISABLE
* \return void
*/
void des_MC33972_SPinputs_WettingTimer(UINT8 u8MSDI, UINT8 u8SPin, UINT8 u8Select)
{
if(u8Select)
u8MSDI_SPx_Wettingtimer[u8MSDI] |= u8SPin; /* Set selected bits */
if(!u8Select)
u8MSDI_SPx_Wettingtimer[u8MSDI] &= ~u8SPin; /* Clear selected bits */
des_MC33972_SendCommand(u8MSDI, MSDI_WETTINGTIMERSP_CMD,
u8MSDI_SPx_Wettingtimer[u8MSDI]);
}
/*******************************************************************************/
/**
* \brief Enable/ disable the wetting timer for SGx inputs
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u16SGin: SGx pin(s) as defined in des_MC33972.h \n
(MSDI_SG0, MSDI_SG1, ...MSDI_SG13) OR combinations are valid \n
u8Select: ENABLE, DISABLE
* \return void
*/
void des_MC33972_SGinputs_WettingTimer(UINT8 u8MSDI, UINT16 u16SGin,UINT8 u8Select)
{
if(u8Select)
u16MSDI_SGx_Wettingtimer[u8MSDI] |= u16SGin; /* Set selected bits */
if(!u8Select)
u16MSDI_SGx_Wettingtimer[u8MSDI] &= ~u16SGin; /* Clear selected bits */
des_MC33972_SendCommand(u8MSDI, MSDI_WETTINGTIMERSG_CMD,
u16MSDI_SGx_Wettingtimer[u8MSDI]);
}
/*******************************************************************************/
/**
* \brief Set SPx inputs in high impedance state
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8SPin: SPx pin(s) as defined in des_MC33972.h \n
(MSDI_SP0, MSDI_SP1, ..., MSDI_SP7) OR combinations are allowed
* \return void
*/
void des_MC33972_Set_SP_HighImpedance(UINT8 u8MSDI, UINT8 u8SPin)
{
des_MC33972_SendCommand(u8MSDI, MSDI_TRISTATESP_CMD, u8SPin);
}
/*******************************************************************************/
/**
* \brief Set SGx inputs in high impedance state
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u16SGin: SGx pin(s) as defined in des_MC33972.h \n
(MSDI_SG0, MSDI_SG1,..., MSDI_SG13) OR combinations are allowed.
* \return void
*/
void des_MC33972_Set_SG_HighImpedance(UINT8 u8MSDI, UINT16 u16SGin)
{
des_MC33972_SendCommand(u8MSDI, MSDI_TRISTATESG_CMD, u16SGin);
}
/*******************************************************************************/
/**
* \brief Select SPx/ SGx inputs for wake-up interrupt
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8SPin, u16SGin: SPx pin(s) as defined in des_MC33972.h \n
(MSDI_SP0, MSDI_SP1, ..., MSDI_SG12, MSDI_SG13) OR combinations are valid
* \return void
*/
void des_MC33972_Select_WakeUp_Interrupt(UINT8 u8MSDI, UINT8 u8SPin, UINT16 u16SGin)
{
des_MC33972_SendCommand(u8MSDI, MSDI_WAKEUPINTSP_CMD, u8SPin);
des_MC33972_SendCommand(u8MSDI, MSDI_WAKEUPINTSG_CMD, u16SGin);
}
/*******************************************************************************/
/**
* \brief Select analog input channel and desired current or high impedance
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II \n
u8Channel: Analog channel as defined in des_MC33972.h \n
(MSDI_AN_SG0, MSDI_AN_SG1,..., MSDI_AN_SP7, MSDI_AN_SP7) \n
u8Mode: MSDI_AN_HiImpedance, MSDI_AN_2mA, MSDI_AN_16mA
* \return void
*/
void des_MC33972_Set_Analog_Channel(UINT8 u8MSDI, UINT8 u8Channel, UINT8 u8Mode)
{
des_MC33972_SendCommand(u8MSDI, MSDI_ANALOG_CMD, u8Channel | u8Mode);
}
/*******************************************************************************/
/**
* \brief Read SPx, SGx and flags status
* \author B05114
* \param u8MSDI: MSDI identifier, MSD_I, MSDI, II
* \return u32MSDI_Status: Structure with status of flags, SP inputs ans SG inputs
*/
MSDI_Stat32b des_MC33972_Read_Status(UINT8 u8MSDI)
{
MSDI_Stat32b u32MSDI_Status;
UINT8 u8Aux;
UINT8 u8MSDI_Frame[]={0, 0, 0}; /* Data array to be sent to the MSDI */
if(!u8MSDI) CS_MC33972_I = 0; /* CS low */
if(u8MSDI) CS_MC33972_II = 0;
lle_SPI_24(u8MSDI_Frame); /* Send data to SBC */
if(!u8MSDI) CS_MC33972_I = 1; /* CS high */
if(u8MSDI) CS_MC33972_II = 1;
u32MSDI_Status.Flags = u8MSDI_Frame[0] & 0xC0; /* Flags */
u32MSDI_Status.SPinputs = u8MSDI_Frame[0]<<2;
u8Aux = u8MSDI_Frame[1] >> 6;
u32MSDI_Status.SPinputs |= u8Aux; /* SP input status */
u32MSDI_Status.SGinputs = 0x3F00 & (u8MSDI_Frame[1] << 8);
u32MSDI_Status.SGinputs |= u8MSDI_Frame[2]; /* SP input status */
return u32MSDI_Status;
}
/*******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -