⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lin_hdw.h

📁 针对日本瑞莎单片机r8c/23 开发的LIN网络通讯程序包括主节点和从节点
💻 H
字号:
/******************************************************************************/
/*             Renesas Technology America, Inc. Legal Disclaimer              */
/******************************************************************************/
/* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY      */
/* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE        */
/* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR      */
/* PURPOSE.                                                                   */
/*                                                                            */
/* BY USING THE SOFTWARE HEREIN, YOU (AND YOUR COMPANY) AGREE TO BE BOUND BY  */
/* THE TERMS AND CONDITIONS OF RENESAS TECHNOLOGY AMERICA, INC.'S SOURCE CODE */
/* LICENSE AGREEMENT. PLEASE READ THIS AGREEMENT CAREFULLY. IF YOU (OR YOUR   */
/* COMPANY) DO NOT AGREE TO ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT,   */
/* DO NOT INSTALL OR USE THIS SOFTWARE AND ASSOCIATED DOCUMENTATION.          */
/*                                                                            */
/*  Copyright (c) 2003, 2004, 2005 and 2006 Renesas Technology America, Inc.  */
/******************************************************************************/
/**********************************************************************
   Title                      : lin_hdw.h

   Module Description         : This file contains the MCU specific and hardware
                                specific defines for the LIN device.

   MCU Family                 : R8C

   Author                     : Bob Chamberlain

   Version                    : LIN API 2.0 Version 1.1

 *********************************************************************/
#ifndef  LIN_HDW_H
#define  LIN_HDW_H

/**********************************************************************
 * Include User Header file
 *********************************************************************/
/* This include references the standard SFR definition header file for the
 * Renesas MCU being used in this project.  */
#include "sfr_r823.h"
#include "lin_dev.h"

/**********************************************************************
 * Constant and Macro Definitions using #define
 *********************************************************************/
/* The following defines are used to configure specific operating
 * parameters for the LIN interface.  */

/* Define the system clock frequency in MHz.  */
#if (LIN_MASTER_NODE == LIN_MY_NODE_NAME)
#define LIN_MY_FREQUENCY      20
#else
#define LIN_MY_FREQUENCY      10
#endif

/* Define the timeout count for the readback data "fail safe" wait loop.  This
 * value is calculated as follows:
 *      (LIN_MY_FREQUENCY * 50) / 26
 * For R8C/Tiny family procesors, roughly 26 clock cycles are consumed by each
 * pass through the wait loop.  The maximum wait period for readback data to
 * complete should be set to roughly 50us, to avoid delaying too long in the
 * UART transmit interrupt routine.  If the readback data has not completed
 * within 50us (plus the transmit interrupt response time), it isn't going to
 * complete.  */
#define LIN_READBACK_FAIL_SAFE 40

/* Define the prescaler divide value used to configure the LIN break
 * timer.  The bit value of the break timer (also used as the wake-up
 * timer) is this value multiplied by the period of the system clock.
 * This value must be left at 2 if the Baud rate is adjusted by
 * measuring the SYNC period.  The code to do this expects that the
 * break timer is being prescaled by 2.  */
#define LIN_TIMER_RATE        2

/* Optional LIN resource allocations for the R8C - User defined.  */

/* Uncomment the following line to enable the use of a dedicated hardware timer as the
 * Master node schedule timer.  If this define is commented out, the LIN API will not
 * "manage" the Master schedule timer in any way.  At times when the schedule timer
 * normally would be turned off, the LIN API will instead disable the "l_sch_tick()"
 * function.  However, the user application will be responsible for calling "l_sch_tick()"
 * every "LIN_TIME_BASE" milliseconds, with high reliability and low jitter.  The proper
 * operation of the LIN cluster is very dependent upon the calls to "l_sch_tick()".  If
 * this define is uncommented, the LIN API will allocate, configure and manage the LIN
 * Master schedule timer without any action on the part of the user application.  The
 * timer slected for this purpose is defined below.  This define has no meaning for a
 * Slave node, since the schedule timer is used only by Master nodes.  */
#define DEDICATED_SCHEDULE_TIMER

/* Uncomment the following define to enable an output pin that may be used
 * as a hardware enable for a LIN transceiver chip.  Many designs may not
 * require this pin.  */
#define LIN_XCVR_ENABLE

/* Define the output pin for the LIN transceiver enable (used only if "LIN_XCVR_ENABLE"
 * is defined).  Any desired and otherwise unused pin may be selected for this function.
 * In addition, the value assigned in the macro "LIN_TXCVR_ENABLE" must be set to the
 * logic level expected by the transceiver chip to be enabled.  The logic level assigned
 * in the port direction macro must remain "1".  */
#define LIN_TXCVR_ENABLE      	(p1_6=1)
#define LIN_TXCVR_ENABLE_DIR  	(pd1_6=1)

/* Uncomment the following define to enable an output pin that is set high each time
 * one of the LIN API core functions is executing.  */
//#define LIN_CORE_TIME_ENABLE

/* Define the output pin for LIN core execution time measurements (used only if
 * "LIN_CORE_TIME_ENABLE" is defined).  Any desired and otherwise unused pin may be
 * selected for this function.  The logic level assigned in the port direction macro
 * must remain "1".  */
#define LIN_CORE_TIME         (p1_3)
#define LIN_CORE_TIME_DIR     (pd1_3=1)

/* !!!!!!!!!! Nothing below this line may be changed by the user. !!!!!!!!!! */

/* Fixed LIN resource allocations for the R8C - No options
 *    LIN Break Timer    - TimerRA
 *    LIN Break Detect   - TimerRA
 *    LIN Serial Port    - UART0
 *    LIN Schedule Timer - TimerRB  */

/* LIN Break Timer Definitions.  */
#define BRK_TMR_INT_CTL       traic
#define BRK_TMR_INT_PRIO      0x06
#define BRK_TMR_CNT_REG       tra
#define BRK_TMR_PRECNT_REG    trapre
#define BRK_TMR_MODE_REG      tramr
#define BRK_TMR_MST_MODE      0x30
#define BRK_TMR_SLV_MODE      0x33
#define BRK_TMR_IO_REG        traioc
#define BRK_TMR_MST_IO        0x09
#define BRK_TMR_SLV_IO        0x08
#define BRK_TMR_INT_CFG       lincr
#define BRK_INT_NONE          0xf8
#define BRK_INT_BREAK         sbie_lincr
#define BRK_INT_SYNC          sfie_lincr
#define BRK_INT_COLL          bcie_lincr
#define BRK_TMR_ARMED         lstart_lincr
#define BRK_TMR_FLAGS         linst
#define BRK_TMR_SYNC_FLG      sfdct_linst
#define BRK_TMR_BRK_FLG       sbdct_linst
#define BRK_TMR_COLL_FLG      bcdct_linst
#define BRK_CLR_ALL_FLGS      0x38
#define BRK_TMR_RUN           tstart_tracr

/* LIN Serial Port Definitions.  */
#define LIN_CONTROL_REG       lincr
#define LIN_FUNCTION_ENABLE   line_lincr
#define LIN_UART_OP_MODE      u0c1
#define LIN_UART_OP_OFF       0x10
#define LIN_UART_OP_IDLE      0x11
#define LIN_UART_OP_RCV       0x15
#define LIN_UART_OP_XMT       0x15
#define LIN_UART_RCV_EN       re_u0c1
#define LIN_UART_MODE_REG     u0mr
#define LIN_UART_MODE         0x05
#define LIN_UART_MODE_REG2    u0c0
#define LIN_UART_MODE2        0x00
#define LIN_UART_BRG_CKS      u0c0
#define LIN_UART_RCV_ERR_FLGS error_bits
#define LIN_RCV_ERRS          0x30
#define LIN_OVERRUN_ERR       0x10
#define LIN_FRAME_ERR         0x20
#define LIN_UART_TBUFE_FLG    ti_u0c1
#define LIN_UART_RBUFF_FLG    ri_u0c1
#define LIN_UART_TXEND_FLG    ir_s0tic
#define LIN_UART_BRG          u0brg
#define LIN_UART_TDAT         u0tbl
#define LIN_UART_RDAT         u0rb
#define LIN_UART_RX_INT_CTL   s0ric
#define LIN_UART_TX_INT_CTL   s0tic
#define LIN_UART_RX_INT_PRIO  0x04
#define LIN_UART_TX_INT_PRIO  0x04

/* LIN Schedule Timer Definitions.  */
#define SCH_TMR_INT_CFG       trbic
#define SCH_INT_DIS           0x00
#define SCH_INT_EN            0x01     /* Interrupt priority 1.  */
#define SCH_TMR_FLAG_REG      trbic
#define SCH_TMR_FLAG          ir_trbic
#define SCH_CLR_FLG           0xf7
#define SCH_TMR_CNT_REG       trbpr
#define SCH_TMR_INIT_CNT      (unsigned char)((unsigned char)(LIN_TIME_BASE * 10) - 1)
#define SCH_TMR_PRECNT_REG    trbpre
#define SCH_TMR_INIT_PRECNT   (unsigned char)((unsigned char)((unsigned short)(LIN_MY_FREQUENCY * 100) / 8) - 1)
#define SCH_TMR_MODE_REG      trbmr
#define SCH_TMR_MODE          0x10
#define SCH_TMR_IO_REG        trbioc
#define SCH_TMR_IO_MODE       0x00
#define SCH_TMR_RUN           tstart_trbcr

/* UART TxD and RxD Port macros.  */
#define LIN_PORT_DATA_OUT     (p1_4)
#define LIN_PORT_DATA_IN      (p1_5)
#define LIN_PORT_TXD_DIR      (pd1_4 = 1)
#define LIN_PORT_RXD_DIR      (pd1_5 = 0)

/**********************************************************************
 * Enumerations, Structures and Typedefs
 *********************************************************************/

/**********************************************************************
 * Global Variable extern Declarations
 *********************************************************************/
extern unsigned char LIN_wake_up_period;
extern unsigned char LIN_break_count;
extern unsigned char LIN_break_prescale;
extern unsigned char LIN_smr_value;
extern unsigned char LIN_brr_value;
extern unsigned char LIN_sleep_timer;
extern unsigned char LIN_step_mode;

/* The following (optional) variables are used to implement Node Configuration,
 * but are never required for the Master node.  */
extern unsigned char LIN_my_NAD;
extern const unsigned int LIN_supplier_ID;
extern const unsigned int LIN_function_ID;
extern const unsigned char LIN_function_variant;
extern const unsigned long LIN_serial_number;

/**********************************************************************
 * Function Prototypes
 *********************************************************************/
/* This function is available to both Master and Slave nodes as a "hook"
 * function to be alerted to the reception of an unexpected Single Frame
 * ISO diagnostic messgae.  */
void LIN_ISO_SF_diag_request(unsigned char SID);

/* These functions are available for Slave nodes as "hook" functions to
 * allow applications to make use of the user defined diagnostic options
 * provided in the LIN 2.0 Specification.  */
unsigned char LIN_user_diag_frame(void);
void LIN_user_diag_request(void);
void LIN_user_NAD_request(unsigned char NAD);
void LIN_diag_data_dump(void);
void LIN_read_user_ID(unsigned char id);

/**********************************************************************
 *
 * Modification Record
 *
 **********************************************************************
 *
 *    Version 1.1 for R8C 16 Mar 2006   Bob Chamberlain
 *
 *********************************************************************/

#endif   /* LIN_HDW_H  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -