?? des_mc33742.c
字號:
/*******************************************************************************/
/**
Copyright (c) 2007 Freescale Semiconductor
\file des_MC33742.c
\brief Functions for basic SBC (MC33742) 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"
/** SBC definitions */
#include "des_MC33742.h"
/** SPI definitions */
#include "lle_SPI.h"
#include "lle_TIME.h"
UINT8 u8WDT_Value = SBC_TIM1_INIT; /* Watchdog period value */
UINT8 u8LPC_Value = SBC_LPC_INIT; /* Low power control register value */
UINT8 u8SBC_Command[1]; /* Data array to be sent to the SBC */
/*******************************************************************************/
/**
* \brief Write SBC register
* \author B05114
* \param u8TXByte: Register to be accessed + data
* \return void
*/
void des_MC33742_Write(UINT8 u8TXByte)
{
DISABLE_INTERRUPTS();
u8SBC_Command[0] = u8TXByte | SBC_W; /* Force write command */
lle_SW_Delay(SPI_DELAY);
CS_MC33742 = 0; /* CS low */
(void)lle_SPI_8(u8SBC_Command); /* Send data to SBC */
CS_MC33742 = 1; /* CS high */
lle_SW_Delay(SPI_DELAY);
ENABLE_INTERRUPTS();
}
/*******************************************************************************/
/**
* \brief Read SBC register
* \author B05114
* \param u8TXByte: Register to be accessed
* \return Data byte returned by SBC
*/
UINT8 des_MC33742_Read(UINT8 u8RegByte)
{
/* Variable to store received data */
UINT8 u8Temp = 0;
u8SBC_Command[0] = u8RegByte; /* Register stored in frame command */
lle_SW_Delay(SPI_DELAY);
CS_MC33742 = 0; /* CS low */
u8Temp = lle_SPI_8(u8SBC_Command); /* Send read command and receive data */
CS_MC33742 = 1; /* CS high */
lle_SW_Delay(SPI_DELAY);
return u8Temp; /* Return data received from SBC */
}
/*******************************************************************************/
/**
* \brief SBC initial configuration with default values from des_MC33742.h
* \author B05114
* \param void
* \return void
*/
void des_MC33742_Config(void)
{
des_MC33742_Write(SBC_TIM1| SBC_TIM1_INIT);
des_MC33742_Write(SBC_RCR | SBC_RCR_INIT);
des_MC33742_Write(SBC_CAN | SBC_CAN_INIT);
des_MC33742_Write(SBC_IOR | SBC_IOR_INIT);
des_MC33742_Write(SBC_WUR | SBC_WUR_INIT);
des_MC33742_Write(SBC_TIM2| SBC_TIM2_INIT);
des_MC33742_Write(SBC_LPC | SBC_LPC_INIT);
des_MC33742_Write(SBC_INTR| SBC_INTR_INIT);
}
/*******************************************************************************/
/**
* \brief Sets the SBC Mode
* \author B05114
* \param u8Mode: Code for operating mode as defined in des_MC33742.h: \n
SBC_NORMAL, SBC_STANDBY, SBC_STOP, SBC_SLEEP
* \return void
*/
void des_MC33742_SetMode(UINT8 u8Mode)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write SBC Watchdog */
des_MC33742_Write(SBC_MCR|u8Mode); /* Send Mode command */
}
/*******************************************************************************/
/**
* \brief Sets the SBC in Debug-Normal mode
* \author B05114
* \param void
* \return void
*/
void des_MC33742_SetDebugMode(void)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
des_MC33742_Write(SBC_MCR|SBC_DEBUGMODE); /* Send Debug mode command */
des_MC33742_Write(SBC_MCR|SBC_DBGNORMAL); /* Send Debug-Normal mode command */
}
/*******************************************************************************/
/**
* \brief Exits SBC from Debug mode
* \author B05114
* \param void
* \return void
*/
void des_MC33742_ExitDebugMode(void)
{
des_MC33742_Write(SBC_MCR|SBC_DEBUGMODE); /* Send Debug mode command */
}
/*******************************************************************************/
/**
* \brief Resets the SBC watchdog
* \author B05114
* \param void
* \return void
*/
void des_MC33742_ClearWDT(void)
{
/* Watchdog cleared by writing the TIM1 Register */
des_MC33742_Write(SBC_TIM1|u8WDT_Value);
}
/*******************************************************************************/
/**
* \brief Sets the SBC watchdog period
* \author B05114
* \param u8WDT_Period: Code for desired period as defined in des_MC33742.h
(SBC_WDOG_10MS, SBC_WDOG_45MS, SBC_WDOG_100MS,...)
* \return void
*/
void des_MC33742_SetWDTperiod(UINT8 u8WDT_Period)
{
/* Watchdog cleared by writing the TIM1 Register */
des_MC33742_Write(SBC_TIM1|u8WDT_Period);
u8WDT_Value = u8WDT_Period; /* Updates watchdog period value */
}
/*******************************************************************************/
/**
* \brief Enable/ disable the watchdog in stop mode
* \author B05114
* \param u8Select: ENABLE/ DISABLE
* \return void
*/
void des_MC33742_WDT_StopMode(UINT8 u8Select)
{
UINT8 u8Register;
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
/* Read RCR to keep the other bits values */
u8Register = des_MC33742_Read(SBC_RCR);
u8Register &= 0x0F; /* Bitmask */
if(u8Select) u8Register |= SBC_WDSTOP;
else u8Register &= ~SBC_WDSTOP;
des_MC33742_Write(SBC_RCR|u8Register); /* Update register */
}
/*******************************************************************************/
/**
* \brief Enable/ disable CAN sleep mode
* \author B05114
* \param u8Select: ENABLE/ DISABLE
* \return void
*/
void des_MC33742_CAN_SleepMode(UINT8 u8Select)
{
UINT8 u8Register;
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
/* Read RCR to keep the other bits values */
u8Register = des_MC33742_Read(SBC_RCR);
u8Register &= 0x0F; /* Bitmask */
if(u8Select) u8Register |= SBC_CANSLEEP;
else u8Register &= ~SBC_CANSLEEP;
des_MC33742_Write(SBC_RCR|u8Register); /* Update register */
}
/*******************************************************************************/
/**
* \brief CAN transceiver slew rate selection
* \author B05114
* \param u8SlewRate: Code for desired slew rate as defined in des_MC33742.h
(SBC_SLEWRATE0, SBC_SLEWRATE1, SBC_SLEWRATE2,...)
* \return void
*/
void des_MC33742_CAN_SlewRate(UINT8 u8SlewRate)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
des_MC33742_Write(SBC_CAN|u8SlewRate); /* Update register */
}
/*******************************************************************************/
/**
* \brief Enable/ disable CAN transceiver wake-up when in sleep mode
* \author B05114
* \param u8Select: ENABLE/ DISABLE
* \return void
*/
void des_MC33742_CAN_Wkup_SleepMode(UINT8 u8Select)
{
UINT8 u8Register;
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
if(u8Select) u8Register = SBC_SLEEP_WKPENABLE;
else u8Register = SBC_SLEEP_WKPDISABLE;
des_MC33742_Write(SBC_CAN|u8Register); /* Update register */
}
/*******************************************************************************/
/**
* \brief Set Lx sensitivity for Wake-up
* \author B05114
* \param u8LxSens: Code for Lx sensitivity as defined in des_MC33742.h
(SBC_L0L1DISABLED, SBC_L0L1HIGH, SBC_L0L1LOW,...)
* \return void
*/
void des_MC33742_SetLxSens(UINT8 u8LxSens)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
des_MC33742_Write(SBC_WUR|u8LxSens); /* Update register */
}
/*******************************************************************************/
/**
* \brief Enable/ disable HS in stop and sleep modes
* \author B05114
* \param u8Select: ENABLE/ DISABLE
* \return void
*/
void des_MC33742_HSCyclic(UINT8 u8Select)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
if(u8Select) u8LPC_Value |= SBC_HSAUTO;
else u8LPC_Value &= ~SBC_HSAUTO;
des_MC33742_Write(SBC_LPC|u8LPC_Value); /* Update register */
}
/*******************************************************************************/
/**
* \brief Select cyclic sense period
* \author B05114
* \param u8CycSens_Period: Code for cyclic sense period as defined in des_MC33742.h
(SBC_CYCLICSENSE_5MS, SBC_CYCLICSENSE_9MS, SBC_CYCLICSENSE_18MS,...)
* \return void
*/
void des_MC33742_SetCyclicSense(UINT8 u8CycSens_Period)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
des_MC33742_Write(SBC_TIM2|u8CycSens_Period); /* Update register */
}
/*******************************************************************************/
/**
* \brief Enable/ disable HS
* \author B05114
* \param u8Select: ON/ OFF
* \return void
*/
void des_MC33742_HS(UINT8 u8Select)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
if(u8Select) des_MC33742_Write(SBC_IOR|SBC_HSON);
else des_MC33742_Write(SBC_IOR|0);
}
/*******************************************************************************/
/**
* \brief Enable interrupt sources
* \author B05114
* \param u8InterrSelect: Code for interrupts sources as defined in des_MC33742.h
(SBC_INTVSUPLOW, SBC_HSOT_V2LOW, SBC_VDDTEMP, SBC_CANF)
* \return void
*/
void des_MC33742_SetInterrupts(UINT8 u8InterrSelect)
{
des_MC33742_Write(SBC_TIM1|u8WDT_Value); /* Write Watchdog */
des_MC33742_Write(SBC_INTR|u8InterrSelect); /* Update register */
}
/*******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -