lin_frame_management.h

来自「芯科原厂所有c8051fxx程序的例子。」· C头文件 代码 · 共 151 行

H
151
字号
// Copyright (c) 2006 SILICON LABORATORIES, INC.
//
// FILE NAME   : LIN_Frame_Management.h
// TARGET MCU  : C8051F52xA-53xA
// DESCRIPTION : Header file for LIN_Frame_Management.c
//

#ifndef _LIN_FRAME_MANAGEMENT_H_
#define _LIN_FRAME_MANAGEMENT_H_


//-----------------------------------------------------------------------------
// Constant Definitions
//-----------------------------------------------------------------------------

// Definitions for frame_checksum.
#define  CLASSIC_CHECKSUM  0x00
#define  ENHANCED_CHECKSUM 0x01
#define  VARIABLE_CHECKSUM 0x02

// Definitions for frame_type.
#define  UNCONDITIONAL_FRAME     0x00
#define  EVENT_TRIGGERED_FRAME   0x01
#define  SPORADIC_FRAME          0x02

// Definitions for frame_direction.
#define  IGNORE_FRAME      0x00
#define  IN_FRAME          0x01
#define  OUT_FRAME         0x02

// Number of system ticks for a frame of length len to transmit
#define  _FRAME_LENGTH_SYSTEM_TICKS(len)   ((((len + 1) * 10 + 34) * 1.4 * FREQUENCY_SYSTEM_TICK / LIN_BIT_RATE) + 1)

// L_NULL_FRAME is a frame with no ID, length, or type.
#define  L_NULL_FRAME   (l_frame *) 0x00

// L_NULL_SCHEDULE_ENTRY is a null entry in a schedule table.
// All schedule tables should be terminated with an L_NULL_SCHEDULE_ENTRY.
#define  L_NULL_SCHEDULE_ENTRY   { L_NULL_FRAME, 0 }

// EMPTY_FRAME_SLOT is returned by l_get_sporadic_frame_id () when no
// unconditional frames associated with the pending sporadic frame should be
// sent in the next frame slot.
#define  SILENT_FRAME_SLOT     0xFF

// Bit definitions for SCHEDULE_TYPE.
#define  NORMAL_SCHEDULE               0x00
#define  COLLISION_RESOLUTION_SCHEDULE 0x01

// L_NULL_SCHEDULE is a schedule that will not send or receive frames.
#define  L_NULL_SCHEDULE   (l_schedule) 0x00

// Specification-defined diagnostic frame identifiers.
#define  MASTER_REQUEST_FRAME_ID   0x3C
#define  SLAVE_RESPONSE_FRAME_ID   0x3D

// Lengths for diagnostic frames
#define  MASTER_REQUEST_FRAME_ID_LEN  0x08
#define  SLAVE_RESPONSE_FRAME_ID_LEN  0x08

// Define Application ID's
#define  LED_SLAVE_SPORADIC_ID                     0x00
#define  LED_SLAVE_UNCONDITIONAL_ID                0x01
#define  SW_SLAVE_EVENT_TRIGGERED_ID               0x02
#define  SW_SLAVE_ID_0_UNCONDITIONAL_ID            0x03
#define  SW_SLAVE_ID_1_UNCONDITIONAL_ID            0x04
#define  SW_SLAVE_ID_2_UNCONDITIONAL_ID            0x05

// Define the length of each frame
#define  LED_SLAVE_SPORADIC_ID_LEN                 0x00
#define  LED_SLAVE_UNCONDITIONAL_ID_LEN            0x01
#define  SW_SLAVE_EVENT_TRIGGERED_ID_LEN           0x02
#define  SW_SLAVE_ID_0_UNCONDITIONAL_ID_LEN        0x01
#define  SW_SLAVE_ID_1_UNCONDITIONAL_ID_LEN        0x01
#define  SW_SLAVE_ID_2_UNCONDITIONAL_ID_LEN        0x01


//-----------------------------------------------------------------------------
// Typedefs
//-----------------------------------------------------------------------------
typedef code struct
{
   l_u8  frame_id;
   l_u8  frame_len;
   l_u8  frame_direction:  2;
   l_u8  frame_type     :  2;
   l_u8  frame_checksum :  2;
   l_u8                 :  0;

#if (LIN_MODE == LIN_MASTER)
   void code *   collision_resolution_schedule;
#endif

} l_frame;

typedef code struct
{
   l_frame * frame_ptr;
   l_u8                 delay_num_ticks;
} l_schedule_entry;

typedef l_schedule_entry l_schedule[];

typedef struct
{
   l_schedule_entry *   current_schedule;
   l_u8                 current_schedule_type;
   l_u8                 current_schedule_counter;
   l_u8                 current_frame_ticks_remaining;
   l_schedule_entry *   next_schedule;
   l_u8                 next_schedule_counter;
   l_schedule_entry *   saved_schedule;
   l_u8                 saved_schedule_counter;
} l_schedule_controller;

typedef l_schedule l_schedule_handle;


//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

// Callout functions
l_irqmask   l_sys_irq_disable (void);
void        l_sys_irq_restore (l_irqmask previous);

// Frame operations
l_frame * l_get_frame (l_u8 frame_id);

// Schedule operations
l_u8     l_sch_tick_std_ifc (void);
void     l_sch_set_std_ifc (l_schedule_handle next_schedule_std_ifc, l_u8 entry);
l_u8     l_sch_increment_schedule_controller_std_ifc (void);
void     l_sch_save_std_ifc (void);


//-----------------------------------------------------------------------------
// Extern Variable Declarations
//-----------------------------------------------------------------------------
extern l_schedule normal_schedule;
extern l_schedule diagnostic_master_request_schedule;
extern l_frame application_frame_descriptor[];
extern l_u8 frame_direction;

//-----------------------------------------------------------------------------
// Additional SFR Definitions
//-----------------------------------------------------------------------------



#endif	// _LIN_FRAME_MANAGEMENT_H_

⌨️ 快捷键说明

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