File MM2.h

-

CONTENTS
Home

TECHNOLOGY
Message IDs
Layer-2 Driver
MM2.h
Layer-7 API
MM7.h

 
/**************************************************************************
MODULE:    MM2
CONTAINS:  MicroMessaging Layer 2 Driver Interface Definitions
COPYRIGHT: Embedded Systems Academy, Inc. 2003
           See www.MicroMessaging.com
           This software was written in accordance to the guidelines at
           www.esacademy.com/software/softwarestyleguide.pdf
DISCLAIM:  Read and understand our disclaimer before using this code!
           www.esacademy.com/disclaim.htm
LICENSE:   General Public License as specified by GNU
VERSION:   0.75, Pf 23-SEP-03
---------------------------------------------------------------------------
HISTORY:   0.75, Pf 23-SEP-03, First Published Version
***************************************************************************/ 


/**************************************************************************
DEFINES TO CONTROL THE OPERATION OF THE DRIVER
**************************************************************************/

// This defines the number of bits a message identifier has.
// Possible values are 6 (LIN), 8 (default) or 11 (CANopen)
#define NR_OF_MESSAGE_ID_BITS 8

// The following definition controls the network media arbitration
// method used.
//  1: Multi-Master (as available in CAN and I2C), nodes can access the
//     network at any time.
//  2: Master-Polling, nodes are individually polled with a poll message
//     containing the node ID of the node currently polled.
//     POLL_MSG_ID defines the message ID of the poll message used.
#define NET_ARBITRATION 1
#define POLL_MSG_ID 0x20

// The number of transmit and receive data channels is selectable in order
// to be able to optimize the code
#define NR_OF_TX_CHANNELS 2
#define NR_OF_RX_CHANNELS 2

// Defined Service Responses (CANopen SDO responses)
#define DEVICETYPE 0x00030191L // [1000,00]
#define VENDORID   0x01455341L // [1018,01]
#define PRODUCTID  0x00020012L // [1018,02]
#define REVISION   0x00010005L // [1018,03]


/**************************************************************************
GLOBAL TYPE DEFINITIONS
**************************************************************************/

// Standard data types
#define BIT   bit
#define BYTE  unsigned char
#define WORD  unsigned int
#define DWORD unsigned long

// Boolean expressions
#define BOOLEAN unsigned char
#define TRUE 0xFF
#define FALSE 0


/**************************************************************************
GLOBAL FUNCTIONS
**************************************************************************/

/**************************************************************************
DOES:    Initializes the driver with the desired bit rate.
         For a complete initialization, MM2_SetMessageFilter must be called
         for every message ID that should be received by the driver.
RETURNS: TRUE, if initialization executed OK.
         FALSE, if initialization failed.
**************************************************************************/
BYTE MM2_Init
  (
  WORD BitRate // Bitrate in multiple of 100bps
  );


/**************************************************************************
DOES:    Sets a single receive filter. The driver only accepts messages
         from the network for which a filter was set.
RETURNS: TRUE, if message ID filter was set successfully.
         FALSE, if message ID filter could not be set.
**************************************************************************/
BYTE MM2_SetMessageFilter 
  (
  BYTE MessageID
  );


/**************************************************************************
DOES:    Pushes the next message into the transmit queue.
RETURNS: TRUE, if transmit queue accepted the message.
         FALSE, if transmit queue is full.
**************************************************************************/
BYTE MM2_PushMessage
  (
  BYTE pMM2TxMsg[] // Pointer to MicroMessage
                   // 1: address byte
                   // 2: number of data bytes (max of 8)
                   // 3-10: data bytes
  );


/**************************************************************************
DOES:    Pulls a message from the receive queue.
RETURNS: TRUE, if message was received.
         FALSE, if receive queue is empty.
**************************************************************************/
BYTE MM2_PullMessage
  (
  BYTE pMM2RxMsg[] // Pointer to MicroMessage
                   // Caller must provide a buffer of 10 bytes!!!
                   // 1: address byte
                   // 2: number of data bytes (max of 8)
                   // 3-10: data bytes
  );


/**************************************************************************
DOES:    This function reads a 1 millisecond timer tick. The timer tick
         must be a WORD and must be incremented once per millisecond.
RETURNS: 1 millisecond timer tick
NOTES:   Data consistency must be insured by the driver.
         (On 8-bit systems, disable the timer interrupt incrementing
         the timer tick while executing this function)
         Systems that cannot provide a 1ms tick may consider incrementing
         the timer tick only once every "x" ms, if the increment is by "x".
**************************************************************************/
WORD MM2_GetTime 
  (
  void
  );