📄 master.c
字号:
{
GotoSleep(); /* yes, send the goto sleep command */
ChangeList(0); /* clear the active node list */
Crg.crgint.bit.rtie = 0; /* disable rti */
}
if (sleep_mode) /* cluster in sleep mode? */
{
NewNode(); /* yes, flash the LED */
LostNode();
}
/* switch turned off and cluster in sleep mode? */
if (sleep_mode && (!(PORTJ & 0x40)))
{
Crg.crgint.bit.rtie = 1; /* yes, enable rti */
Crg.rtictl.byte = RTI_DIVIDER; /* set the RTI divider to 16*2^16 */
l_ifc_init_i1(); /* Initialize the interface */
l_ifc_connect_i1(); /* Connect driver to I/O pins */
l_sch_set_i1(sch_conflict_resolving, 0); /* start conflict resolving */
while (l_sch_tick_i1() != 1) /* one round */
{
BusyWaitUntilNextPeriod();
}
l_sch_set_i1 (normal_mode,0); /* set the normal runing mode */
sleep_mode = 0;
ChangeList(1); /* reactive active node list */
}
}
/*******************************************************************************
* *
* Function name: Process *
* Function: Process the received messages and change internal states *
* as well as send out responds to the slave. *
* *
*******************************************************************************/
void Process (void)
{
static l_u16 periods_until_enter_low_power = PERIODS_PER_SECOND;
l_sch_tick_i1 (); /* Give processing time to LIN */
#ifdef PET_WATCHDOG
PET_WATCHDOG();
#endif
LinActive(); /* check the switch */
l_u8_wr_info(0xAA); /* send info to slave nodes */
if (l_u8_rd_SlaveRespB0_demo_net() == 0x81) /* new node detected? */
{
l_frame_SlaveResp_demo_net_buf[0] = 0x80;
Crg.crgint.bit.rtie = 0; /* disable rti */
NewNode();
while (l_sch_tick_i1() != 1) /* one round */
{
BusyWaitUntilNextPeriod();
}
l_sch_set_i1 (sch_conflict_resolving, 0); /* start schedule table */
while (l_sch_tick_i1() != 1) /* one round */
{
BusyWaitUntilNextPeriod();
}
ChangeList(1);
Crg.crgint.bit.rtie = 1; /* enable rti */
l_sch_set_i1 (normal_mode, 0); /* Set & start schedule table */
}
messages[0] = l_u8_rd_data_20(); /* */
messages[1] = l_u8_rd_data_18(); /* fill in the messages bufer with */
messages[2] = l_u8_rd_data_10(); /* the data from the nodes */
messages[3] = l_u8_rd_data_28(); /* */
status = l_ifc_read_status_i1();
/* l_ifc_read_status call without any frame transfer returns zero */
if ((status != 0x0000) & !(status & 0x0002))/* no response from the node? */
{
status &= 0xFF00; /* mask low byte */
switch (status)
{
case 0x2000:
if (active_nodes[0])
{
Crg.crgint.bit.rtie = 0; /* disable rti */
LostNode();
Crg.crgint.bit.rtie = 1; /* enable rti */
}
active_nodes[0] = 0; /* clear the active node flag*/
break;
case 0xD800:
if (active_nodes[1])
{
Crg.crgint.bit.rtie = 0; /* disable rti */
LostNode();
Crg.crgint.bit.rtie = 1; /* enable rti */
}
active_nodes[1] = 0; /* clear the active node flag*/
break;
case 0x5000:
if (active_nodes[2])
{
Crg.crgint.bit.rtie = 0; /* disable rti */
LostNode();
Crg.crgint.bit.rtie = 1; /* enable rti */
}
active_nodes[2] = 0; /* clear the active node flag*/
break;
case 0xA800:
if (active_nodes[3])
{
Crg.crgint.bit.rtie = 0; /* disable rti */
LostNode();
Crg.crgint.bit.rtie = 1; /* enable rti */
}
active_nodes[3] = 0; /* clear the active node flag*/
}
}
if ((l_ifc_read_status_i1() & 0x0010) == L_WAKEUP_REQUEST)
{
l_ifc_init_i1(); /* Initialize the interface */
l_ifc_connect_i1(); /* Connect driver to I/O pins */
l_sch_set_i1(sch_conflict_resolving, 0); /* start conflict resolving */
while (l_sch_tick_i1() != 1) /* one round */
{
BusyWaitUntilNextPeriod();
}
l_sch_set_i1(normal_mode,0);
}
BusyWaitUntilNextPeriod(); /* Wait until start of next period */
}
/*******************************************************************************
* *
* Function name: Check *
* Function: Check that the call return_value is success, or enter *
* failure mode. *
* *
*******************************************************************************/
void Check (l_bool return_value)
{
if (return_value)
{
NodeFailure();
}
}
/*******************************************************************************
* *
* Function name: main *
* Function: Start the system and then enter the eternal operation loop.*
* *
*******************************************************************************/
void main (void)
{
l_bool result;
#ifdef PET_WATCHDOG
PET_WATCHDOG();
#endif
previous_start_time = l_get_us_counter (); /* used in busy wait function */
DDRJ = 0x80; /* set PTJ7 as output pin, PTJ6 as input */
PORTJ = 0x80; /* enable LIN interface */
Pim.perj.byte |= 0x40; /* enable pull up/down on PTJ6 */
Pim.ppsj.byte &= 0xBF; /* enable pull up on PTJ6 */
Crg.copctl.byte |= 0x04; /* enable COP */
Crg.crgint.bit.rtie = 1; /* enable rti */
Crg.rtictl.byte = RTI_DIVIDER; /* set the RTI divider to 16*2^16 */
init_target(); /* Initialize non-LIN hardware */
result = l_sys_init(); /* Initialize LIN system component */
Check (result);
l_ifc_init_i1(); /* Initialize the interface */
ENABLE_INTS(); /* Turn on interrupts */
result = l_ifc_connect_i1(); /* Connect driver to I/O pins */
Check(result);
DDRB = 0xFF; /* set PTB as output port */
PORTB = 0xFF; /* set test pattern on PTB */
l_bool_wr_resolving_done(1); /* set the conflict resolving done flag */
l_sch_set_i1(sch_conflict_resolving, 0); /* start conflict resolving */
while (l_sch_tick_i1() != 1) /* one round */
{
BusyWaitUntilNextPeriod();
}
l_sch_set_i1(normal_mode, 0); /* Set & start schedule table */
for EVER /* forever */
{
Process(); /* Do all the processing */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -