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

📄 can.h

📁 意法半導體STR710,USB範例程式,模擬U盤
💻 H
📖 第 1 页 / 共 2 页
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name          : can.h
* Author             : MCD Application Team
* Date First Issued  : 27/10/2003
* Description        : This file contains all the functions prototypes for the
*                      CAN bus software library.
********************************************************************************
* History:
*  27/10/2003 : Created
*******************************************************************************/
#ifndef __can_H
#define __can_H

#include "71x_lib.h"

// Standard bitrates available
enum
{
  CAN_BITRATE_100K,
  CAN_BITRATE_125K,
  CAN_BITRATE_250K,
  CAN_BITRATE_500K,
  CAN_BITRATE_1M
};

// Control register
#define CAN_CTL_TEST		0x0080
#define CAN_CTL_CCE			0x0040
#define CAN_CTL_DAR			0x0020
#define CAN_CTL_EIE			0x0008
#define CAN_CTL_SIE			0x0004
#define CAN_CTL_IE			0x0002
#define CAN_CTL_INIT		0x0001

// NewState register
#define CAN_STS_LEC			0x0007
#define CAN_STS_TXOK		0x0008
#define CAN_STS_RXOK		0x0010
#define CAN_STS_EPASS		0x0020
#define CAN_STS_EWARN		0x0040
#define CAN_STS_BOFF		0x0080

// Test register
#define CAN_TST_RX			0x0080
#define CAN_TST_TX1			0x0040
#define CAN_TST_TX0			0x0020
#define CAN_TST_LBACK		0x0010
#define CAN_TST_SILENT		0x0008
#define CAN_TST_BASIC		0x0004

// IFx / Command Request register
#define CAN_CRQ_BUSY		0x8000

// IFx / Command Mask register
#define CAN_COM_WRITE		0x0080
#define CAN_COM_MASK		0x0040
#define CAN_COM_ARB			0x0020
#define CAN_COM_CTRL		0x0010
#define CAN_COM_CLRINT		0x0008
#define CAN_COM_TXRQST		0x0004
#define CAN_COM_DATAA		0x0002
#define CAN_COM_DATAB		0x0001

// IFx / Mask1,2 register
#define CAN_MSK_MXTD		0x8000
#define CAN_MSK_MDIR		0x4000

// IFx / Arbitration1,2 register
#define CAN_ARB_MSGVAL		0x8000
#define CAN_ARB_XTD			0x4000
#define CAN_ARB_DIR			0x2000

// IFx / Message Control register
#define CAN_CTL_NEWDAT		0x8000
#define CAN_CTL_MSGLST		0x4000
#define CAN_CTL_INTPND		0x2000
#define CAN_CTL_UMASK		0x1000
#define CAN_CTL_TXIE		0x0800
#define CAN_CTL_RXIE		0x0400
#define CAN_CTL_RMTEN		0x0200
#define CAN_CTL_TXRQST		0x0100
#define CAN_CTL_EOB			0x0080


// Wake-up modes
enum
{
  CAN_WAKEUP_ON_EXT,
  CAN_WAKEUP_ON_CAN
};


// CAN message structure
typedef struct
{
  int IdType;
  vu32 Id;
  vu8 Dlc;
  vu8 Data[8];
} canmsg;

// message ID types
enum
{
  CAN_STD_ID,
  CAN_EXT_ID
};

// message ID limits
#define CAN_LAST_STD_ID	((1<<11) - 1)
#define CAN_LAST_EXT_ID	((1L<<29) - 1)

/*******************************************************************************
* Function Name  : CAN_EnterInitMode
* Description    : Switch the CAN into initialization mode
* Input 1        : any binary value formed from the CAN_CTL_xxx defines
* Output         : None
* Return         : None
* Note           : CAN_LeaveInitMode must be called when all is done
*******************************************************************************/
inline void CAN_EnterInitMode(u8 mask)
{
	CAN->CR = mask | CAN_CTL_INIT;
	CAN->SR = 0;					// reset the status
}

/*******************************************************************************
* Function Name  : CAN_LeaveInitMode
* Description    : Leave the initialization mode (switch into normal mode)
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
inline void CAN_LeaveInitMode(void)
{
	CAN->CR &= ~(CAN_CTL_INIT | CAN_CTL_CCE);
}

/*******************************************************************************
* Function Name  : CAN_EnterTestMode
* Description    : Switch the CAN into test mode
* Input 1        : any binary value formed from the CAN_TST_xxx defines
* Output         : None
* Return         : None
* Note           : CAN_LeaveTestMode must be called when all is done
*******************************************************************************/
inline void CAN_EnterTestMode(u8 mask)
{
	CAN->CR |= CAN_CTL_TEST;
	CAN->TESTR |= mask;
}

/*******************************************************************************
* Function Name  : CAN_LeaveTestMode
* Description    : Leave the current test mode (switch into normal mode)
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
inline void CAN_LeaveTestMode(void)
{
	CAN->CR |= CAN_CTL_TEST;
	CAN->TESTR &= ~(CAN_TST_LBACK | CAN_TST_SILENT | CAN_TST_BASIC);
	CAN->CR &= ~CAN_CTL_TEST;
}

/*******************************************************************************
* Function Name  : CAN_SetBitrate
* Description    : Setup a standard CAN bitrate
* Input 1        : one of the CAN_BITRATE_xxx defines
* Output         : None
* Return         : None
* Note           : CAN must be in initialization mode
*******************************************************************************/
void CAN_SetBitrate(int bitrate);

/*******************************************************************************
* Function Name  : CAN_SetTiming
* Description    : Setup the CAN timing with specific parameters
* Input 1        : Time Segment before the sample point position, from 1 to 16
* Input 2        : Time Segment after the sample point position, from 1 to 8
* Input 3        : Synchronisation Jump Width, from 1 to 4
* Input 4        : Baud Rate Prescaler, from 1 to 1024
* Output         : None
* Return         : None
* Note           : CAN must be in initialization mode
*******************************************************************************/
void CAN_SetTiming(int tseg1, int tseg2, int sjw, int brp);

/*******************************************************************************
* Function Name  : CAN_SleepRequest
* Description    : Request the CAN cell to enter sleep mode
* Input 1        : CAN_WAKEUP_ON_EXT or CAN_WAKEUP_ON_CAN
* Output         : None
* Return         : None
*******************************************************************************/
void CAN_SleepRequest(int WakeupMode);

⌨️ 快捷键说明

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