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

📄 lin_low_level.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_low_level.h

   Module Description         : This file contains the system defines for the low
                                level LIN functions.

   MCU Family                 : R8C

   Author                     : Bob Chamberlain

   Version                    : LIN API 2.0 Version 1.1

 *********************************************************************/
#ifndef  LIN_LOW_LEVEL_H
#define  LIN_LOW_LEVEL_H

/**********************************************************************
 * Include files
 *********************************************************************/

/**********************************************************************
 * Constant and Macro Definitions using #define
 *********************************************************************/
/* These defines are used in the declaractions of the schedule tables to
 * identify the type of frame being sent.  */
#define UNCONDITION_FRAME  0

/* Define checksum types.  The "classic" checksum was defined in the LIN
 * 1.3 specification.  The "enhanced" checksum was defined in th LIN 2.0
 * specification.  The "enhanced" checksum is used for all message frames
 * except the Diagnostic message frames.  */
#define LIN_CLASSIC      0    /* "classic" checksum does not include ID Byte.  */
#define LIN_ENHANCED     1    /* "enhanced" checksum includes ID Byte.  */

#define LIN_MAX_RESPONSE_LENGTH     8

/* Break state defines.  */
#define  BREAK_INVALID  0x00
#define  BREAK_WAIT     0x01
#define  SYNC_WAIT      0x02

/* Defines for "LIN-node_status" states.  */
#define DISCONNECT            0
#define CONNECT               1
#define SLEEP_STATE           2
#define WAKE_UP_STATE         3

/* Defines for "LIN_bus_status" states.  */
#define QUIET_STATE              0
#define SYNC_RECEIVE_STATE       1
#define IDENTIFY_RECEIVE_STATE   2
#define DATA_RECEIVE_STATE       3
#define DATA_SEND_STATE          4
#define WAKEUP_SEND_STATE        5

/* Defines for LIN flag operations from within the API.  */
#define API_TX_END_FLG     LIN_flags[0]
#define API_RX_END_FLG     LIN_flags[1]
#define API_AWAKE_FLG      LIN_flags[2]
#define API_DIAG_RESP_FLG  LIN_flags[3]

/* Define for calculating the number of "slices" in a LIN bit period.
 * Used for calculating the break timer preloads.  The math is done by
 * the preprocessor.  */
#define BIT_FACTOR   (unsigned char)((76800 + (LIN_SPEED / 2)) / LIN_SPEED)
#define DIVISOR      (unsigned long)(LIN_SPEED * LIN_TIMER_RATE * BIT_FACTOR)
#define H_DIVISOR    (unsigned long)(DIVISOR / 2)

/**********************************************************************
 * Enumerations, Structures and Typedefs
 *********************************************************************/
/* Defines the various Master node schedule tables used in the system.  */
typedef struct {
   unsigned char  num_slots;           /* Number of frame slots in the schedule table.  */
   unsigned char  *schedule_address;   /* Address of the schedule table.  */
} SCHEDULE_TBL;

/* Defines the elements of a schedule table.  */
typedef struct {
   unsigned char  frame_type;    /* Type of LIN message frame.  */
   unsigned char  frame_name;    /* Name (index number) of LIN message frame.  */
   int            delay_time;    /* Actual slot time in ms for the frame.  */
} SCHEDULE_DATA;

/* Defines the table that associates a collision resolution schedule table with each
 * EVENT_TRIG frame that may be sent.  */
typedef struct {
   unsigned char  frame_name; /* Name (index number) of an Event Triggered message frame.  */
   unsigned char  sched_name; /* Name (index number) of the collision resolution schedule table.  */
} COLL_RESOLUTION_TBL;

/* Defines the elements of a frame that may be sent in a slot.  A frame
 * may pack multiple signals into its data field.  */
typedef struct {
   unsigned char  frame_id;         /* LIN message frame ID for this frame.  */
   unsigned char  node_name;        /* Name of the node that publishes the data.  */
   unsigned int   message_id;       /* Message ID for node configuration.  */
   unsigned char  frame_type;       /* Type of LIN message frame.  */
   unsigned char  data_length;      /* Number of bytes in the data field.  */
   unsigned char  check_sum_type;   /* Type of checksum to be used (enhanced or classic).  */
   unsigned char  num_sigs;         /* Number of signals associated with this frame.  */
   unsigned char  *data_address;    /* Address of the structure that lists the signals.  */
} FRAME_ID_TBL;

/* Defines the signal list stucture for signals associated with a particular LIN message frame.  */
typedef struct {
   unsigned char  signal_name;      /* Signal name.  Actually, an enumerated value, not a string.  */
   unsigned char  signal_offset;    /* Bit offset of the signal data in the frame data field.  */
} FRAME_SIGNAL_TBL;

/* Defines the elements of a LIN signal structure.  */
typedef struct {
   unsigned char  signal_byte;      /* Signal data size in bytes.  */
   unsigned char  signal_bit;       /* Signal data size in bits.  */
   unsigned char  *signal_address;  /* Address of the signal data [byte 0 is status byte].  */
} SIGNAL_TBL;

/**********************************************************************
 * Global Variable extern Declarations
 *********************************************************************/
extern unsigned char LIN_node_status;
extern unsigned char LIN_bus_status;

extern int LIN_slot_time;

extern unsigned char LIN_now_schedule;
extern unsigned char LIN_now_entry;
extern unsigned char LIN_change_schedule;
extern unsigned char LIN_change_entry;
extern unsigned char LIN_frame_error_flag;
extern unsigned char LIN_retry_count;
extern unsigned char LIN_schedule_stop_flag;
extern unsigned char LIN_TX_check_error;
extern unsigned char LIN_collision_flag;
extern unsigned char LIN_collision_resolution;
extern unsigned char LIN_save_schedule;
extern unsigned char LIN_save_entry;
extern unsigned char LIN_event_start;

extern unsigned char LIN_frame_type;
extern unsigned char LIN_frame_name;
extern unsigned char LIN_ident;
extern unsigned char LIN_ident_PB;
extern unsigned char LIN_data[];
extern unsigned char LIN_flags[];
extern const unsigned int LIN_bit_masks[];

extern unsigned char LIN_sum_code;
extern unsigned char LIN_RX_count;
extern unsigned char LIN_TX_count;
extern unsigned char LIN_tx_send_length;
extern unsigned char LIN_rx_receive_length;
extern unsigned char LIN_ifc_status[];

extern unsigned char LIN_DIAG_mode;

extern unsigned char LIN_xmt_overrun_err;
extern unsigned char LIN_xmt_framing_err;
extern unsigned char LIN_xmt_checksum_err;
extern unsigned char LIN_xmt_readback_err;
extern unsigned char LIN_rcv_overrun_err;
extern unsigned char LIN_rcv_framing_err;
extern unsigned char LIN_rcv_checksum_err;

extern const unsigned char LIN_sleep_cmd[];

/* The following variables are required to implement the basic Node Configuration
 * commands.  */
extern unsigned char LIN_diag_xfr_state;
extern unsigned char LIN_diag_xfr_status;
extern unsigned char LIN_diag_read_by_id;
extern unsigned char *LIN_diag_return_ptr;

/* The following variable is used to implement the LIN_DIAG_RESP_FLG.  */
extern unsigned char diag_response_wait;

/* The following variables are used to implement the transmit and receive queues
 * required for the Diagnostic Transport Layer.  */
extern unsigned char LIN_xmt_queue[];
extern unsigned char *LIN_xmt_queue_start;
extern unsigned char *LIN_xmt_queue_end;
extern unsigned char *LIN_xmt_queue_write;
extern unsigned char *LIN_xmt_queue_read;
extern unsigned char LIN_xmt_queue_slots_free;
extern unsigned char LIN_raw_xmt_error;
extern unsigned char LIN_raw_xmt_frame;
extern unsigned char LIN_rcv_queue[];
extern unsigned char *LIN_rcv_queue_start;
extern unsigned char *LIN_rcv_queue_end;
extern unsigned char *LIN_rcv_queue_write;
extern unsigned char *LIN_rcv_queue_read;
extern unsigned char LIN_rcv_queue_slots_free;
extern unsigned char LIN_raw_rcv_error;

/* The following variables are used by the cooked Diagnostic Transport
 * routines.  */
extern unsigned char LD_send_status;
extern unsigned char *LD_send_ptr;
extern unsigned char LD_send_NAD;
extern unsigned int LD_send_byte_rem;
extern unsigned char LD_send_data[];
extern unsigned char LD_send_frame_count;
extern unsigned char LD_send_call_continuation;
extern unsigned char LD_receive_status;
extern unsigned char *LD_receive_ptr;
extern unsigned char LD_receive_NAD;
extern unsigned int LD_receive_byte_rem;
extern unsigned char LD_receive_data[];
extern unsigned char LD_receive_frame_count;
extern unsigned char *LD_receive_NAD_ptr;
extern unsigned int *LD_receive_length_ptr;

/**********************************************************************
 * Function Prototypes
 *********************************************************************/
void lin_init_timer(void);
void lin_init_schedule_timer(void);
void lin_init_serial_if(void);
void lin_init_diag_transmit_queue(void);
void lin_init_diag_receive_queue(void);
void lin_set_ifc_status(unsigned char ident, unsigned char status);
void lin_goto_sleep(void);
void lin_change_node_status(unsigned char status);
void lin_change_bus_status(unsigned char status);
void lin_init_check_sum(unsigned char check_sum_type);
void lin_make_check_sum(unsigned char data);
unsigned char lin_make_protected_identifier(unsigned char id_data);
void lin_reset_signal_update_flg(unsigned char frame_name);
void lin_send_break(void);
void lin_send_response(void);
void lin_first_send_data(void);
unsigned char lin_read_serial_data(unsigned char *p);
void lin_make_frame_data(unsigned char frame_name);
void lin_make_signal_data(unsigned char frame_name);
void lin_signal_write(unsigned char signal_name, unsigned char bit_size, unsigned int write_data);
void ld_send_continuation(unsigned char ifc_name);
void ld_receive_continuation(unsigned char ifc_name);

/**********************************************************************
 *
 * Modification Record
 *
 **********************************************************************
 *
 *    Version 1.1 for R8C 16 Mar 2006   Bob Chamberlain
 *    08.24.2007 RTA-CSS defines EVENT_TRIG_FRAME and SPORADIC_FRAME removed 
 *    from LIN Starter Demo version.
 *********************************************************************/

#endif   /* LIN_LOW_LEVEL_H  */

⌨️ 快捷键说明

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