?? master.c
字號:
/*******************************************************************************
* (c) Freescale Inc. 2004 all rights reserved. *
* *
* *
* An example application for AN2767 based on MC68HC908GZ60A,master node. *
* ===================================================================== *
* *
* $File Name : master.c$ *
* $Author : re004c$ *
* $Date : Nov-8-2004$ *
* $Version : 1.1.6.0$ *
* Function: *
* *
* ============================================================================ *
* THIS SOFTWARE IS PROVIDED BY FREESCALE SEMICONDUCTOR "AS IS" AND ANY *
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL FREESCALE SEMICONDUCTOR OR ITS CONTRIBUTORS *
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF *
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN *
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
*******************************************************************************/
#include <lin.h>
#include "target.h"
unsigned char ErrCount; /* errors counter */
unsigned char MsgCount; /* messages counter */
unsigned int Time; /* time from real time counter */
l_u8 messages [4];
unsigned char messages_counter = 1;
l_bool active_nodes [4] = {1,1,1,1};
l_u16 status;
l_bool sleep_mode = 0;
#define PERIODS_PER_SECOND (200u)
#define EVER (;;) /* to avoid warning message */
static l_u16 previous_start_time = 0; /* Wraps around but usage is safe */
/*******************************************************************************
* *
* Function name: NodeFailure *
* Function: Do the processing necessary to re-start or enter *
* limp-home mode. In this example we enter an endless loop. *
* *
*******************************************************************************/
void NodeFailure (void)
{
for EVER /* to avoid warning message */
{
/* forever */
}
}
/*******************************************************************************
* *
* Function name: BusyWaitUntilNextPeriod *
* Function: Waits until it is time for the next processing call. Call *
* this routine when you are done with all processing expected*
* for the present processing period. The first time might *
* take some time (since start_time is uninitialized), but *
* then it will run fine. *
*******************************************************************************/
void BusyWaitUntilNextPeriod (void)
{
l_u16 t_now; /* The time counter value for now */
l_u16 elapsed; /* Time elapsed since previous ideal start time */
do
{
#ifdef PET_WATCHDOG
PET_WATCHDOG();
#endif
t_now = l_get_us_counter();
elapsed = (l_u16) (t_now - previous_start_time);
}
while (elapsed < HW_DELAY);
previous_start_time += HW_DELAY;
/* This construct avoids time drift, previous_start_time = t_now, wouldn't */
}
/*******************************************************************************
* *
* Function name: Delay *
* Function: Simple delay routine. Delay for n ms. *
* *
*******************************************************************************/
void Delay(unsigned int n)
{
unsigned int stopTime = 30 * n;
while (stopTime != 0)
{
#ifdef PET_WATCHDOG
PET_WATCHDOG();
#endif
stopTime--;
}
}
/*******************************************************************************
* *
* Function name: NewNode *
* Function: Flash LEDs in sequence low to high. *
* *
*******************************************************************************/
void NewNode()
{
char i;
unsigned char strip = 0x01;
for (i = 0; i < 8; i++)
{
PTF = ~strip;
Delay(125);
strip = strip<<1;
}
}
/*******************************************************************************
* *
* Function name: LostNode *
* Function: Flash LEDs in sequence low to high. *
* *
*******************************************************************************/
void LostNode()
{
char i;
unsigned char strip = 0x80;
for (i = 0; i < 8; i++)
{
PTF = ~strip;
Delay(125);
strip = strip>>1;
}
}
/*******************************************************************************
* *
* Function name: GotoSleep *
* Function: Manage the goto the sleep transition. *
* *
******************************************************************************/
void GotoSleep (void)
{
while (l_sch_tick_i1() != 1) /* one round */
{
BusyWaitUntilNextPeriod();
}
l_ifc_goto_sleep_i1(); /* send the sleep commnand */
sleep_mode = 1; /* set the sleep mode flag */
}
/*******************************************************************************
* *
* Function name: ChangeList *
* Function: Change the status of the active_nodes list. *
* *
******************************************************************************/
void ChangeList (l_bool value)
{
unsigned char i;
for (i = 0; i<4 ; i++)
{
active_nodes [i] = value; /* change the active node list status*/
}
}
/*******************************************************************************
* *
* Function name: LinActive *
* Function: Flashes LEDs if LIN is disabled. *
* *
*******************************************************************************/
void LinActive()
{
/* switch turned on and cluster not previously in sleep mode? */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -