lin.h

来自「飞思卡尔汽车LIN总线解决方案实例源代码」· C头文件 代码 · 共 59 行

H
59
字号
/////////////////////////////////////////////////////////////////////////////////////////
//
// LIN Sample for Freescale EVB9S08DZ60
// LIN communication data from master to slave
//
// --------------------------------------------------------------------------------------
//
// Copyright (c) 2006 SofTec Microsystems
// http://www.softecmicro.com/
//
/////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////
//
// NOTES:
//
// - LIN bus communication is set to work about at 20Kb/s.
// - Only standard checksum is used.
//
/////////////////////////////////////////////////////////////////////////////////////////

#include <hidef.h>

/////////////////////////////////////////////////////////////////////////////////////////
// Defines
/////////////////////////////////////////////////////////////////////////////////////////

#define MAX_DATA      1               // Max bytes lin frame data

#define SCI_BAUDRATE  19200           // SCI baud rate
#define SCI_CLOCK     2000000         // Bus clock in Hz 

#define BIT(A,B)      ((A>>B)&0x01)   // A is the variable while 
                                      // B is the bit number

enum lin_state { IDLE, _BREAK, SYNCH, PROTECTED_IDENTIFIER, DATA_0, DATA_1, 
                 DATA_2, DATA_3, DATA_4, DATA_5, DATA_6, DATA_7, CHECKSUM };

struct message {
  unsigned char identifier;
  unsigned char data_field[MAX_DATA];
};

struct frame {
  unsigned char protected_id;
  unsigned char data[MAX_DATA];
  unsigned char check;
  enum lin_state state;
  unsigned char error;
};

/////////////////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////////////////
void LINInit(void);
Bool LINGetMsg(Bool get_data, struct  message *msg);
Bool LINSendMsg(Bool master, Bool send_data, struct message msg);
enum lin_state LINCheckState(void);

⌨️ 快捷键说明

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