📄 main_lin_master.c
字号:
/******************************************************************************
* DISCLAIMER:
* The software supplied by Renesas Technology America Inc. is
* intended and supplied for use on Renesas Technology products.
* This software is owned by Renesas Technology America, Inc. or
* Renesas Technology Corporation and is protected under applicable
* copyright laws. All rights are reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS,
* IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* APPLY TO THIS SOFTWARE. RENESAS TECHNOLOGY AMERICA, INC. AND
* AND RENESAS TECHNOLOGY CORPORATION RESERVE THE RIGHT, WITHOUT
* NOTICE, TO MAKE CHANGES TO THIS SOFTWARE. NEITHER RENESAS
* TECHNOLOGY AMERICA, INC. NOR RENESAS TECHNOLOGY CORPORATION SHALL,
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
* CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER ARISING OUT OF THE
* USE OR APPLICATION OF THIS SOFTWARE.
******************************************************************************
******************************************************************************
File: main_lin_master.c
For CAN/LIN Demonstration and Development Kit. LIN demo MAIN file. This file
contains the application routines needed to implement a LIN Master using the
R8C/23 RSK board.
tab space = 4
Revision History
21.05.2007 AE version 1.16r. Released to RTA CAN download page.
01.08.2007 AE version 1.17. id0x8 fix done in lin_low_level.c by Bob C.
15.08.2007 AE version 1.18. Linted.
******************************************************************************/
/******************************************************************************
System includes (Compiler Level Includes)
******************************************************************************/
//#include <xxxx.h>
/******************************************************************************
User includes (Project level includes)
******************************************************************************/
#include "lin_api.h"
#include "lcd.h"
/* RSKR8C23def.h provides common defines for widely used items. */
#include "rskR8C23def.h"
/******************************************************************************
Typedef definitions
******************************************************************************/
typedef signed char int8;
typedef signed short int16;
typedef signed long int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
/******************************************************************************
Constant definitions
******************************************************************************/
static const char * renstring = "RENESAS\0";
static const char * techstring = "Technlgy\0";
/******************************************************************************
Macro definitions
******************************************************************************/
#define PAUSELENGTH 10
/******************************************************************************
Global variables and functions imported
******************************************************************************/
void HardwareSetup(void);
/******************************************************************************
Global variables and functions private to the file
******************************************************************************/
/* Data from Node A */
static uint8 node_a_val;
static uint8 node_a_switch;
static uint8 node_a_counter;
/* Data from Node B */
static uint8 node_b_val;
static uint8 node_b_switch;
static uint8 node_b_counter;
/* Functions */
static void InitialJobs(void);
static void NormalJobs(void);
static void display_intro_0(void);
static void display_intro_1(void);
static void display_intro_2(void);
static void display_intro_3(void);
static void pause(int i);
/******************************************************************************
Function Name: main
Parameters: none
Return value: none
Description: Main function
******************************************************************************/
void main(void)
{
InitialJobs();
NormalJobs();
return; /* Should never execute. */
}
/******************************************************************************
Function Name: InitialJobs
Parameters: none
Return value: none
Description: init all
******************************************************************************/
void InitialJobs(void)
{
_asm("FCLR I"); /* Interrupts disabled. */
HardwareSetup();
ENABLE_LEDS
ENABLE_SWITCHES
InitDisplay();
/* Master display intro sequence */
display_intro_0();
display_intro_1();
display_intro_2();
/* LIN init */
l_sys_init();
l_ifc_init(LIN);
l_ifc_connect(LIN);
l_sch_set(LIN, (l_schedule_handle)LIN_SCHEDULE, 0);
_asm("FSET I"); /* Interrupts enabled. */
return;
}
/******************************************************************************
Function Name: NormalJobs
Parameters: none
Return value: none
Description: Loop to receive, transmit and display. Starts when app
is ready
******************************************************************************/
static void NormalJobs(void)
{
/* Remove this line to get LCD feedback on bus fault! */
display_intro_3();
while (1)
{
/*-----------------------------------------------------------------
MASTER Read Node A
-----------------------------------------------------------------*/
if (l_flg_tst((uint8)LIN_SIG_NODE_A_AD) == 1)
{
RED_LED = ACTIVE;
/* LIN-received data! Node A data value */
node_a_val = (uint8)l_u16_rd((uint8)LIN_SIG_NODE_A_AD);
lcd_show_2dig_hex(node_a_val, (uint8)(LINE1_1STCH + 6));
}
if (l_flg_tst((uint8)LIN_SIG_NODE_A_COUNTER) == 1)
{
YLW_LED = ACTIVE;
/* LIN-received data! Node A status value */
node_a_counter = l_u8_rd((uint8)LIN_SIG_NODE_A_COUNTER);
lcd_show_2dig_hex(node_a_counter, (uint8)(LINE1_1STCH + 4));
}
/* Node switch pressed? */
if (l_flg_tst((uint8)LIN_SIG_NODE_A_SWITCH) == 1)
{
GRN_LED = ACTIVE;
/* LIN-received data! Node A relay value */
node_a_switch = l_u8_rd((uint8)LIN_SIG_NODE_A_SWITCH);
//l_flg_clr(LIN_SIG_NodeA_Switch); /* l_u8_rd() does this for you */
if (node_a_switch == 1)
{
DisplayString((uint8)(LINE1_1STCH + 2), "S1");
}
else if (node_a_switch == 2)
{
DisplayString((uint8)(LINE1_1STCH + 2), "S2");
}
else if (node_a_switch == 3)
{
DisplayString((uint8)(LINE1_1STCH + 2), "S3");
}
else
{
node_a_switch = 0;
DisplayString((uint8)(LINE1_1STCH + 2), "--");
}
}
/*-----------------------------------------------------------------
MASTER Read Node B
-----------------------------------------------------------------*/
if (l_flg_tst((uint8)LIN_SIG_NODE_B_AD) == 1)
{
RED_LED = ACTIVE;
/* LIN-received data! Node B data value */
node_b_val = (uint8)l_u16_rd((uint8)LIN_SIG_NODE_B_AD);
lcd_show_2dig_hex(node_b_val, (uint8)(LINE2_1STCH + 6));
}
if (l_flg_tst((uint8)LIN_SIG_NODE_B_COUNTER) == 1)
{
YLW_LED = ACTIVE;
/* LIN-received data! Node B status value */
node_b_counter = l_u8_rd((uint8)LIN_SIG_NODE_B_COUNTER);
lcd_show_2dig_hex(node_b_counter, (uint8)(LINE2_1STCH + 4));
}
/* Node switch pressed? */
if (l_flg_tst((uint8)LIN_SIG_NODE_B_SWITCH) == 1)
{
GRN_LED = ACTIVE;
/* LIN-received data! Node B relay value */
node_b_switch = l_u8_rd((uint8)LIN_SIG_NODE_B_SWITCH);
//l_flg_clr(LIN_SIG_NodeB_Switch); /* l_u8_rd() does this for you */
if (node_b_switch == 1)
{
DisplayString((uint8)(LINE2_1STCH + 2), "S1");
}
else if (node_b_switch == 2)
{
DisplayString((uint8)(LINE2_1STCH + 2), "S2");
}
else if (node_b_switch == 3)
{
DisplayString((uint8)(LINE2_1STCH + 2), "S3");
}
else
{
node_b_switch = 0;
DisplayString((uint8)(LINE2_1STCH + 2), "--");
}
}
/*-----------------------------------------------------------------
MASTER PUBLISH
-----------------------------------------------------------------*/
if (SW1 == ACTIVE)
{
l_u8_wr((uint8)LIN_SIG_CMD_SWITCH, 0x01);
RED_LED = ACTIVE;
}
else if (SW2 == ACTIVE)
{
l_u8_wr((uint8)LIN_SIG_CMD_SWITCH, 0x02);
RED_LED = ACTIVE;
}
else if (SW3 == ACTIVE)
{
l_u8_wr((uint8)LIN_SIG_CMD_SWITCH, 0x03);
RED_LED = ACTIVE;
}
else /* Switches off */
{
l_u8_wr((uint8)LIN_SIG_CMD_SWITCH, 0x00);
}
}
}
/******************************************************************************
Function Name: display_intro_0
Parameters: none
Return value: none
Description: Startup LCD message
******************************************************************************/
static void display_intro_0(void)
{
/* Slave display intro 0 */
const uint8* rp = renstring;
const uint8* tp = techstring;
uint8 i = 0;
/* Leave for test */
//lcd_show_2dig_hex(0x12, 0); lcd_show_2dig_hex(0x34, 4); lcd_show_4dig_hex(0x12, 0x34, 16); lcd_show_4dig_hex(0x56, 0x78, 20);
DisplayString((uint8)(LINE1_1STCH + 0), rp);
DisplayString((uint8)(LINE2_1STCH + 0), tp);
pause(30);
DisplayString((uint8)(LINE1_1STCH + 0), " ");
DisplayString((uint8)(LINE2_1STCH + 0), " ");
while (i++ < 8)
{
DisplayString((uint8)(LINE1_1STCH + i), rp);
DisplayString((uint8)(LINE2_1STCH + i), tp);
if (i < 8)
{
DisplayString((uint8)(LINE1_1STCH + 0), " ");
DisplayString((uint8)(LINE2_1STCH + 0), " ");
}
}
}
/******************************************************************************
Function Name: display_intro_1
Parameters: none
Return value: none
Description: Startup LCD message
******************************************************************************/
static void display_intro_1(void)
{
/* Master display intro 1 */
DisplayString((uint8)(LINE1_1STCH + 0), " LIN ");
DisplayString((uint8)(LINE2_1STCH + 0), " Master ");
pause(20);
}
/*****************************************************************************
Name: display_intro
Description: Startup LCD message
*****************************************************************************/
static void display_intro_2(void)
{
/* Master display intro 2 */
DisplayString((uint8)(LINE1_1STCH + 0), "power up");
DisplayString((uint8)(LINE2_1STCH + 0), "trnscvr");
}
/******************************************************************************
Function Name: display_intro_3
Parameters: none
Return value: none
Description: Startup LCD message
******************************************************************************/
static void display_intro_3(void)
{
/* Master display intro 3 */
DisplayString((uint8)(LINE1_1STCH + 0), "Node A: ");
DisplayString((uint8)(LINE2_1STCH + 0), "Node B: ");
pause(10);
/* Master. Receiving from.. */
/* ..Node A */
DisplayString((uint8)(LINE1_1STCH + 0), "A: ");
/* ..Node B */
DisplayString((uint8)(LINE2_1STCH + 0), "B: ");
}
/******************************************************************************
Function Name: pause
Parameters: i; nr of loops to do x n
Return value: none
Description: Simple pause for switch debounce and displaying text
******************************************************************************/
static void pause(int i)
{
/* Pausing with i = 1 will cause delay looping of n times */
unsigned int n = PAUSELENGTH;
while (i--)
{
while (n--)
{
/*asm("nop")*/;
}
}
n = PAUSELENGTH;
}
/* eof */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -