can.h File Reference

#include "t89c51cc02.h"
#include "datatypes.h"

Go to the source code of this file.

Defines

#define BRP_500k   0x00
#define SJW_500k   0x00
#define PRS_500k   0x00
#define PHS2_500k   0x07
#define PHS1_500k   0x05
#define BRP_250k   0x01
#define PRS_250k   0x00
#define PHS1_250k   0x05
#define PHS2_250k   0x07
#define SJW_250k   0x00
#define MSK_CANGCON_ENA   0x02
#define MSK_CANGCON_GRES   0x01
#define DLC_MAX   8
#define CH_DISABLE   0x00
#define CH_RxENA   0x80
#define CH_TxENA   0x40
#define MSK_CANGIE_ENRX   0x20
#define MSK_CANGIE_ENTX   0x10
#define CAN_ACK   0x06
#define CAN_NAK   0x15
#define CAN_RECVID   0x400
#define CAN_SENDID   0x401
#define CAN_setchannel(ch)   CANPAGE = (ch << 4)
#define CAN_enablechannel(ch)   CANEN |= (1 << ch)

Functions

void CAN_init (void)
 initialize CAN Bus to receive and send packages
void CAN_interrupt (void) interrupt 7 using 1
 ISR for handling incoming CAN Bus messages.
void CAN_SendACK (BYTE)
 acknowledge last recieved command via CAN Bus
void CAN_SendMsg (BYTE)
 transmits a message over the CAN Bus
void CAN_SendNAK (BYTE)
 reply when last command was accepted but could not be completed

Variables

volatile BYTE idata can_data [8]
 data buffer to construct CAN messages to be send


Detailed Description

Definition in file can.h.


Define Documentation

#define CAN_ACK   0x06
 

ASCII code for 'Acknowledge'

Definition at line 32 of file can.h.

Referenced by CAN_SendACK().

#define CAN_enablechannel ch   )     CANEN |= (1 << ch)
 

macro to activate one of the CAN channels

Definition at line 44 of file can.h.

Referenced by CAN_SendACK(), CAN_SendMsg(), CAN_SendNAK(), and main().

#define CAN_NAK   0x15
 

ASCII code for 'Negative acknowledge'

Definition at line 34 of file can.h.

Referenced by CAN_SendNAK().

#define CAN_RECVID   0x400
 

we listen on this CAN ID

Definition at line 37 of file can.h.

#define CAN_SENDID   0x401
 

we recieve data on this ID

Definition at line 39 of file can.h.

#define CAN_setchannel ch   )     CANPAGE = (ch << 4)
 

macro to select internal CAN channel

Definition at line 42 of file can.h.

Referenced by CAN_init(), CAN_interrupt(), CAN_SendACK(), CAN_SendMsg(), CAN_SendNAK(), and main().

#define DLC_MAX   8
 

maximum length of messages

Definition at line 24 of file can.h.


Function Documentation

void CAN_init void   ) 
 

initialize CAN Bus to receive and send packages

CAN packets are recieved on CAN ID 0x400 (hardcoded into can.h)
CAN packets are transmitted on CAN ID 0x401
The bus is put into 250kbps mode.

Definition at line 29 of file can.c.

References CAN_setchannel, CH_DISABLE, and MSK_CANGCON_GRES.

Referenced by main().

void CAN_interrupt void   ) 
 

ISR for handling incoming CAN Bus messages.

A small implicit state machine is used to decode valid CAN messages.

Definition at line 119 of file can.c.

References can_data, CAN_SendACK(), CAN_SendMsg(), CAN_SendNAK(), CAN_setchannel, Command_CheckTime, Command_ClearMonitor, Command_ClearRead, Command_DisableMonitor(), Command_DisableReport, COMMAND_EEPROM_CLEAR, COMMAND_EEPROM_SAVEMONITOR, Command_EnableMonitor(), Command_EnableReport(), COMMAND_MONITOR, COMMAND_MONITORSTATUS, COMMAND_READ, COMMAND_RECALLMONITOR, COMMAND_REPORT, COMMAND_RESET, Command_SetRead(), COMMAND_STOPALLMONITORS, COMMAND_STOPMONITOR, COMMAND_STOPREPORT, COMMAND_TIMECHECK_DISABLE, COMMAND_TIMECHECK_ENABLE, Command_TimecheckDisable, Command_TimecheckEnable, COMMAND_TIMECHECKSTATUS, monitor, read_eeprom_config, and write_eeprom_config.

void CAN_SendACK BYTE  cmd  ) 
 

acknowledge last recieved command via CAN Bus

The ACK message consists of the command byte to be acknowledged and an ASCII ACK

Parameters:
cmd numerical representation of last CAN command to be acknowledged

Definition at line 296 of file can.c.

References CAN_ACK, CAN_enablechannel, CAN_setchannel, CH_DISABLE, and CH_TxENA.

Referenced by CAN_interrupt().

void CAN_SendMsg BYTE  length  ) 
 

transmits a message over the CAN Bus

The message content has to be specified in can_data and the data length code has to be given.
Transmission of the message is suspended as long as there is a message transmission in progress.
During transfer of the buffer contents to the CAN controller the CAN interrupt is disabled.

Parameters:
length length of data package

Definition at line 344 of file can.c.

References can_data, CAN_enablechannel, CAN_setchannel, CH_DISABLE, and CH_TxENA.

Referenced by CAN_interrupt(), and main().

void CAN_SendNAK BYTE  cmd  ) 
 

reply when last command was accepted but could not be completed

The function works similar to CAN_SendACK but a NAK is send instead of the ACK to signal an imcomplete command or wrong data format.

Parameters:
cmd numerical representation of last CAN command for which the NAK answer is valid

Definition at line 319 of file can.c.

References CAN_enablechannel, CAN_NAK, CAN_setchannel, CH_DISABLE, and CH_TxENA.

Referenced by CAN_interrupt().


Variable Documentation

volatile BYTE idata can_data[8]
 

data buffer to construct CAN messages to be send

The buffer resides in indirect addressable IRAM space of the T89C51CC02.
The buffer is shared for both recieving and sending therefor disabling the CAN interrupt is advisable before sending.

Definition at line 19 of file can.c.

Referenced by CAN_interrupt(), CAN_SendMsg(), and main().


Generated on Wed Oct 24 12:57:24 2007 for SensorControl by  doxygen 1.4.6