?? app_boardwakefnc.c
字號:
/*******************************************************************************/
/**
Copyright (c) 2008 Freescale Semiconductor
\file app_boardWakeFnc.c
\brief Wake-up functionalities
\author Freescale Semiconductor
\author RC574C/ B05114
\version 0.2
\date March/ 2008
*/
/*******************************************************************************/
/** S12X derivative information */
#include <MC9S12XEP100.h>
#include "main.h"
#include "app_boardDevCtrl.h"
#include "app_boardWakeFnc.h"
#include "app_boardLowPower.h"
#include "app_boardInit.h"
#include "app_connectivity.h"
#include "app_rkeRlt.h"
#include "des_MC33742.h"
#include "des_MC33661.h"
#include "des_MC10XS3412.h"
#include "lle_Cpu.h"
#include "lle_GPIO.h"
#include "lle_MSCAN.h"
#include "lle_TIME.h"
/* FreeMaster driver initialization */
extern void app_fmInit(void);
/* FreeMaster command */
extern UINT8 fm_action14;
/* Local timebase */
UINT8 u8CounterAPI;
/*******************************************************************************/
/**
* \brief This module writes byte to emulated EEPROM.
* \author rc574c
* \param WAKE_Data: wake up function code
(Address given by WAKE_ACT_EEPROM_ADR macro)
* \return void
*/
void app_EEPROMWriteWakeFunc(UINT8 u8WAKE_Data)
{
*((unsigned char *far)WAKE_ACT_EEPROM_ADR) = u8WAKE_Data;
}
/*******************************************************************************/
/**
* \brief This module clears byte from emulated EEPROM.
* \author rc574c
* \param Address given by WAKE_ACT_EEPROM_ADR macro
* \return void
*/
void app_EEPROMClearWakeAct(void)
{
*((unsigned char *far)WAKE_ACT_EEPROM_ADR) = WAKE_ACT_CLR;
}
/*******************************************************************************/
/**
* \brief This module reads Wake-up action byte from emulated EEPROM.
* \author rc574c
* \param Address given by WAKE_ACT_EEPROM_ADR macro
* \return void
*/
UINT8 app_RequiredBoardWakeFunctionality(void)
{
return *((unsigned char *far)WAKE_ACT_EEPROM_ADR);
}
/*******************************************************************************/
/**
* \brief This module search across predefined EEPROM memory area byte with
value not 0xFF and returns contents of read byte.
* \author rc574c
* \param EEPROM space given by DATA_START_EEPROM_ADR and
DATA_BYTES_VOLUME_EEPROM.
* \return EEPROM data
*/
UINT8 app_EEPROMReadData(void)
{
volatile UINT8 Data, i, overflow;
// Reset position counter
i = 0;
// Determine number of read cycles
overflow = 1;
// Search new data (data not 0xFF)
do
{
// Number of read cycles reached?
if (i > DATA_BYTES_VOLUME_EEPROM)
{
overflow = 0;
}
else
{
// Read new data
Data = *(UINT8 *)(DATA_START_EEPROM_ADR + (unsigned long)i);
}
// Select next sector (4 bytes)
i = i + 4;
}
while ((Data == 0xFF) && (overflow));
// Return Data
return Data;
}
/*******************************************************************************/
/**
* \brief This module search across predefined EEPROM memory area byte with
value not 0xFF. Then erases position and write new value to the
next sector (4bytes distance).
* \author rc574c
* \param EEPROM space given by DATA_START_EEPROM_ADR and
* DATA_BYTES_VOLUME_EEPROM.
* \return None
*/
void app_EEPROMStoreData(UINT8 Data)
{
volatile UINT8 Data1, i, overflow;
// Reset position counter
i = 0;
// Determine number of read cycles
overflow = 1;
// Search last data field (data not 0xFF)
do
{
// Number of read cycles reached?
if (i > DATA_BYTES_VOLUME_EEPROM)
{
overflow = 0;
}
else
{
// Read new data
Data1 = *(UINT8 *)(DATA_START_EEPROM_ADR + (unsigned long)i);
}
// Select next sector (4 bytes)
i = i + 4;
}
while ((Data1 == 0xFF) && (overflow));
// Erase sector contained last data (0xFF)
// Reset position (only 20 EEPROM sectors used)
if (i > DATA_BYTES_VOLUME_EEPROM)
{
i = 0;
}
// Write data to EEPROM next sector
}
/*******************************************************************************/
/**
* \brief This is the Wake-up functionality 1 routine.
It turns on Cabin lights 2 on 100ms, period 2s. Then it reads
LIN node data, and put board into Stop mode.
* \author RC574C/ B05114
* \param None
* \return None
*/
void app_WakeUp1(void)
{
// APD devices sleep mode
app_apdDevSleep();
// Load counter value
u8CounterAPI = 19;
// Configure API to interrupt at 100ms rate
lle_Init_API(API_100ms);
do
{
// MC33742 STOP mode enter
// Lx inputs wake-up disabled
des_MC33742_SetLxSens(SBC_L0L1DISABLED|SBC_L2L3DISABLED);
// Watchdog disabled
des_MC33742_WDT_StopMode(DISABLED);
// CAN wake-up disabled
des_MC33742_CAN_Wkup_SleepMode(DISABLED);
// CAN disabled
des_MC33742_CAN_SleepMode(DISABLED);
// Clear BATFAIL bit in MCR by reading MCR
(void)des_MC33742_Read(SBC_MCR);
// Enter STOP mode
des_MC33742_SetMode(SBC_STOP);
// MCU stop mode
lle_MCU_FullStop_Mode();
/* Execution is stopped at this point, */
/* it resumes when interrupt is asserted */
lle_Init_XOSC(); /* Re-enable PLL */
// Set SBC in normal mode
des_MC33742_SetMode(SBC_NORMAL);
des_MC33742_Config();
// LIN physical layer enable
des_MC33661_SetMode(LIN_NORMAL);
// Select action (turn ON/OFF MC10XS3412 HS3 LED, duty cycle 100ms on, period 2s)
if (u8CounterAPI == 20)
{
// Reset API interrupt counter
u8CounterAPI = 0;
// MC10XS3412 - eSwitch enable
des_MC10XS3412_SetMode(XS_NORMAL);
// LIN message
app_LIN_Message(LIN_SLAVE_ID);
// Turn-ON MC10XS3412 HS3 LED
app_lightImobON();
// Keep HS3 on 100ms
while (u8CounterAPI == 0);
// Turn-OFF MC10XS3412 HS3 LED
app_lightImobOFF();
// MC10XS3412 enters sleep mode
des_MC10XS3412_SetMode(XS_SLEEP);
}
// LIN message
app_LIN_Message(LIN_SLAVE_ID);
// Clear MC33472 Watchdog
des_MC33742_ClearWDT();
// Give processing time to LIN module
lle_Delay10ms();
// LIN physical layer disable
des_MC33661_SetMode(LIN_SLEEP);
}
while(S1 == 1);
VREGAPICL_APIFE = 0; /* Disable API */
// Init SBC, ESwitches, MSDIs, COSS, H-bridge, LIN interface, CAN interface
app_initAPDDevices();
// Init variables, clear freeMASTER variables
app_initSystemVariables();
// Initialize FreeMASTER driver
app_fmInit();
// Init MC33696 device and RKE driver
app_rkeInit();
// Init LIN and CAN SW drivers
app_initConnectivity();
}
/*******************************************************************************/
/**
* \brief This is the Wake-up functionality 2 routine.
MC33742 HS cyclic sense wakes the Main Board from
sleep mode each 100ms. Then reads LIN node data and returns back
to sleep mode.
* \author RC574C/ B05114
* \param None
* \return None
*/
void app_WakeUp2(void)
{
// Clear MC33472 Watchdog (350ms timeout period)
des_MC33742_ClearWDT();
// LIN message
app_LIN_Message(LIN_SLAVE_ID);
// Give processing time to LIN module
lle_Delay10ms();
// MC33742 cyclic sense unit activation
// Configure L0, L1 high level sensitive, L2, L3 disabled
des_MC33742_SetLxSens(SBC_L0L1HIGH|SBC_L2L3DISABLED);
// CAN does not wakes-up SBC from sleep mode
des_MC33742_CAN_Wkup_SleepMode(DISABLED);
// CAN sleep enabled
des_MC33742_CAN_SleepMode(ENABLE);
// HS ON in normal and low power modes */
des_MC33742_HS(ON);
// HS cyclic sense timing cca. 74ms period
des_MC33742_SetCyclicSense(SBC_CYCLICSENSE_74MS);
// Enable MC33742 forced wake-up
des_MC33742_Write(SBC_LPC | 0x0D);
// Clear BATFAIL bit in MCR by reading MCR
(void)des_MC33742_Read(SBC_MCR);
// Set NOSTOP in RCR register (allow sleep mode)
des_MC33742_Write(SBC_RCR | SBC_NOSTOP |SBC_CANSLEEP);
// Enter SLEEP mode
des_MC33742_SetMode(SBC_SLEEP);
// Wait, until the power supply voltage disappear
while (1)
{
}
}
/*******************************************************************************/
/**
* \brief This is the Wake-up functionality 3 routine.
It sends 8 data byte CAN frame on CAN wake-up message.
Then the main board is put in stop mode.
* \author RC574C/ B05114
* \param None
* \return None
*/
void app_WakeUp3(void)
{
// APD devices sleep mode
app_apdDevSleep();
do
{
// MC33742 STOP mode enter
// Lx inputs wake-up disabled
des_MC33742_SetLxSens(SBC_L0L1DISABLED|SBC_L2L3DISABLED);
// Watchdog disabled
des_MC33742_WDT_StopMode(DISABLED);
// CAN wake-up enabled
des_MC33742_CAN_Wkup_SleepMode(ENABLE);
// CAN sleep mode disabled
des_MC33742_CAN_SleepMode(DISABLED);
// Clear BATFAIL bit in MCR by reading MCR
(void)des_MC33742_Read(SBC_MCR);
// Enter STOP mode
des_MC33742_SetMode(SBC_STOP);
/* Enable IRQ detection (driven by MC33742 INT pin)*/
IRQCR_IRQEN = 1;
// MCU stop mode
lle_MCU_FullStop_Mode();
/* Execution is stopped at this point, */
/* it resumes when interrupt is asserted */
IRQCR_IRQEN = 0; /* Disable IRQ detection */
lle_Init_XOSC(); /* Re-enable PLL */
// Set SBC in normal mode
des_MC33742_SetMode(SBC_NORMAL);
des_MC33742_Config();
// Send 8byte CAN message
app_Send_CAN_Message(ST_ID_081);
}
while(S1 == 1);
// Init SBC, ESwitches, MSDIs, COSS, H-bridge, LIN interface, CAN interface
app_initAPDDevices();
// Init variables, clear freeMASTER variables
app_initSystemVariables();
// Initialize FreeMASTER driver
app_fmInit();
// Init MC33696 device and RKE driver
app_rkeInit();
// Init LIN and CAN SW drivers
app_initConnectivity();
}
/*******************************************************************************/
/**
* \brief This is the Wake-up functionality 4 routine.
It sends 8 data byte CAN frame on CAN wake-up message.
Then the main board is put in sleep mode.
* \author RC574C/ B05114
* \param None
* \return None
*/
void app_WakeUp4(void)
{
/* Send 8byte message */
app_Send_CAN_Message(ST_ID_081);
// give processing time to MSCAN module
lle_Delay4ms();
/* MSCAN in listen-only mode to avoid signal on tx pin when rx goes low */
lle_CAN_ListenOnly();
// Enter Sleep mode
app_boardSleepMode();
}
/*******************************************************************************/
/**
* \brief This is the Wake-up routine selector, called after processor reset.
* \author rc574c
* \param None
* \return None
*/
void app_boardWakeUpFncTst(void)
{
static UINT8 cmd;
// Read Wake-up fnc from EEPROM
cmd = app_RequiredBoardWakeFunctionality();
// Default value 0xFF -> no wake-up function)
if (cmd != WAKE_ACT_CLR)
{
// Pushbutton SW is not switched
if(S1 == 1)
{
// Run Wake-up functionality
switch (cmd)
{
case WAKE_UP_1 :
{
app_WakeUp1();
break;
}
case WAKE_UP_2 :
{
app_WakeUp2();
break;
}
case WAKE_UP_3 :
{
app_WakeUp3();
break;
}
case WAKE_UP_4 :
{
app_WakeUp4();
break;
}
}
}
else
{
// Clear stored variable, finish wake-up functionality
app_EEPROMClearWakeAct();
}
}
}
/*******************************************************************************/
/**
* \brief This is the Wake-up routine selector.
* \author rc574c
* \param None
* \return None
*/
void app_boardWakeUpFnc(UINT8 cmd)
{
// Run Wake-up functionality
switch (cmd)
{
case WAKE_UP_1 :
{
app_WakeUp1();
break;
}
case WAKE_UP_2 :
{
if(app_RequiredBoardWakeFunctionality()!= WAKE_UP_2)
{
app_EEPROMWriteWakeFunc(WAKE_UP_2);
}
app_WakeUp2();
break;
}
case WAKE_UP_3 :
{
app_WakeUp3();
break;
}
case WAKE_UP_4 :
{
if(app_RequiredBoardWakeFunctionality()!= WAKE_UP_4)
{
app_EEPROMWriteWakeFunc(WAKE_UP_4);
}
app_WakeUp4();
break;
}
}
}
/*******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -