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

📄 can.h

📁 TQ公司的STK16x开发系统的源码
💻 H
字号:
/* File: CAN.H */

/****************************************************************************
* 
* CAN.100
* ========
*
* CAN bus routines for CPU 167, C164 
*
* TQ-Systems GmbH
* ----------------                                                         
* Costumer: TQC
* Project : STK16X, STK16XU 
* Module  : CAN
* Hardware: TQM167C, TQM164
* Tools   : uVision 2.10 with Keil C166 Compiler V4.10
*
* Used modules:
* -------------
* 
* Rev: Date:     Name:            Modification:
* ----+---------+----------------+------------------------------------------
* 100  13.10.98  F. Hattenhauer   initial version
*****************************************************************************/

/*==========================================================================*
* extern available definitions (#DEFINE):
*===========================================================================*/

/*--------------------------------------------------------------------------*
* baudrate definitions:
*---------------------------------------------------------------------------*/
#define BPS50      0x00
#define BPS125     0x01
#define BPS250     0x02
#define BPS500     0x03

/*--------------------------------------------------------------------------*
* number of available nodes:
*---------------------------------------------------------------------------*/
#define NODEMAX    0x3F        /* max. number of nodes (must be < 0x7F)   */

/*--------------------------------------------------------------------------*
* number CAN message variables:
*---------------------------------------------------------------------------*/
#define CAN_CMS_MAX  14        /* max. number of CAN variables (80C164)   */

/*--------------------------------------------------------------------------*
* positions of variables within CAN controller:
*---------------------------------------------------------------------------*/
#define NMT           0        /* network management                      */
#define PDO1_tx       1        /* process data object 1 to be transmitted */
#define PDO1_rx       2        /* process data object 1 to be received    */
#define PDO2_tx       3        /* process data object 2 to be transmitted */
#define PDO2_rx       4        /* process data object 2 to be received    */
#define SDO_tx        5        /* service data object to be transmitted   */
#define SDO_rx        6        /* service data object to be receiced      */
#define EMERGENCY     7        /* emergency object                        */
#define NODEGUARD     8        /* node guard object                       */
#define NU          100        /* not used (NU must be > 14)              */

/*--------------------------------------------------------------------------*
* general definitions:
*---------------------------------------------------------------------------*/
#ifndef FALSE
#define FALSE  0
#endif

#ifndef TRUE
#define TRUE   (!FALSE)
#endif

#ifndef BOOL
#define BOOL   bit
#endif

#ifndef BYTE
#define BYTE   unsigned char
#endif

#ifndef INT
#define INT    signed int
#endif

#ifndef USHORT
#define USHORT unsigned short int
#endif

#ifndef ULONG
#define ULONG  unsigned long
#endif

/*==========================================================================*
* extern available type definitions (TYPEDEF):
*===========================================================================*/

/*--------------------------------------------------------------------------*
* CAN bus variables:
* msgtyp:      message type to determine identifier
* access_type: data direction (READ, WRITE)
* control:     UPDATE: data are copied into CAN controller's data register,
*              but no frame is genererated (data are accessable only by remote 
*              request from another node)
*              SEND: data are sent to bus 
*---------------------------------------------------------------------------*/
typedef struct
	{
	  int                   msgtyp;
	  enum {READ, WRITE}    access_type;
	  enum {UPDATE, EVENT}  control;
       } CAN_CMS_T;

/*--------------------------------------------------------------------------*
* data structure for CAN handling (8 bit data frame, status):
* data:      8 byte CAN data frame
* status:    handling status to application software
* canstatus: value of CAN controller's status register while receiving of 
	     previous frame
*---------------------------------------------------------------------------*/
typedef struct
	{
          BYTE   data[8];
	  enum   {EMPTY=0, NEWDATA, OVERLOAD, INITIALIZED} status;
	  USHORT canstatus;
	} CAN_DATA_T;

/*==========================================================================*
* extern available functions:
*===========================================================================*/

/*--------------------------------------------------------------------------*
* void can_init(BYTE node, BYTE baud)
*---------------------------------------------------------------------------*
* FT: init CAN bus
* EP: node = node number (0..NODEMAX)
*     baud = baud rate (BPS50, BPS125, BPS250, BPS500)
* RV: -
* GP: BPSxxx, I_CAN_BTR0_xxx, canreg
*---------------------------------------------------------------------------*/
void can_init(BYTE node, BYTE baud);

/*--------------------------------------------------------------------------*
* int can_write(int cmsnr, CAN_DATA_T *buf)
*---------------------------------------------------------------------------*
* FT: write CAN message
* EP: cmsnr = CAN message number
*     buf   = message buffer
* RV: TRUE = function succesfully; FALSE = function failed
* GP: -
*---------------------------------------------------------------------------*/
int can_write(int cmsnr, CAN_DATA_T *buf);

/*--------------------------------------------------------------------------*
* int can_read(int cmsnr, CAN_DATA_T *buf)
*---------------------------------------------------------------------------*
* FT: read CAN message object
* EP: cmsnr = CAN message number
*     buf   = message buffer
* RV: TRUE = function succesfully; FALSE = function failed
* GP: -
*---------------------------------------------------------------------------*/
int can_read(int cmsnr, CAN_DATA_T *buf);

⌨️ 快捷键说明

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