1 #ifndef CYGONCE_CAN_AT91SAM7_H
2 #define CYGONCE_CAN_AT91SAM7_H
3 //==========================================================================
5 // devs/can/arm/at91sam7x/current/include/can_at91sam7.inl
7 // CAN message macros for Atmel AT91SAM7X CAN driver
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 // Copyright (C) 2003 Gary Thomas
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
46 // Author(s): Uwe Kindler
47 // Contributors: Uwe Kindler
49 // Purpose: Support AT91SAM7X on-chip CAN moduls
52 //####DESCRIPTIONEND####
54 //==========================================================================
57 //==========================================================================
59 //==========================================================================
60 #include <pkgconf/devs_can_at91sam7.h>
63 //==========================================================================
65 //==========================================================================
67 //--------------------------------------------------------------------------
68 // We define our own CAN message data type here. This structure needs less
69 // memory than the common CAN message defined by IO layer. This is important
70 // because the AT91SAM7 contains only 64 KBytes RAM memory
72 typedef struct st_at91sam7_can_message
74 cyg_can_msg_data data;// 8 data bytes
75 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID
76 cyg_uint32 id; // also extended identifiers (29 Bit) are supported
77 cyg_uint8 ctrl;// control stores extended flag, rtr flag and dlc
80 // only standard identifiers are supported - we need only 11 bit of
81 // the data word to store the identifier. So we have 5 bit left to store
82 // the the rtr flag and the dlc flag. We do not need the IDE flag because
83 // only standard identifiers are supported
87 } at91sam7_can_message;
90 //--------------------------------------------------------------------------
91 // We also define an own event structure here to store the received events
92 // This event structure uses the device CAN message structure and
93 // 16 Bit value for timestamps
95 typedef struct st_at91sam7_can_event
98 #ifdef CYGOPT_IO_CAN_SUPPORT_TIMESTAMP
101 at91sam7_can_message msg;
102 } at91sam7_can_event;
106 //==========================================================================
108 //==========================================================================
109 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID
111 // If we use extended identifier then we store the message parameters
114 #define AT91SAM7_CAN_SET_DLC(_msg_, _dlc_) ((_msg_).ctrl = (_dlc_)) // this also clears the ctrl
115 #define AT91SAM7_CAN_SET_EXT(_msg_) ((_msg_).ctrl |= 0x01 << 4)
116 #define AT91SAM7_CAN_SET_RTR(_msg_) ((_msg_).ctrl |= 0x01 << 5)
118 #define AT91SAM7_CAN_GET_DLC(_msg_) ((_msg_).ctrl & 0x0F)
119 #define AT91SAM7_CAN_IS_EXT(_msg_) ((((_msg_).ctrl >> 4) & 0x01) != 0)
120 #define AT91SAM7_CAN_IS_RTR(_msg_) ((((_msg_).ctrl >> 5) & 0x01) != 0)
121 #define AT91SAM7_CAN_GET_ID(_msg_) ((_msg_).id & CYG_CAN_EXT_ID_MASK)
122 #else // CYGOPT_IO_CAN_EXT_CAN_ID
124 // We use only standard identifiers and we can store the message parameters
125 // into the upper 5 bits of the 16 bit id field (only 11 bits are required for
128 #define AT91SAM7_CAN_SET_DLC(_msg_, _dlc_) ((_msg_).id |= (_dlc_) << 11)
129 #define AT91SAM7_CAN_SET_EXT(_msg_) // we do not need to support this flag - only std IDs supported
130 #define AT91SAM7_CAN_SET_RTR(_msg_) ((_msg_).id |= 0x01 << 15)
132 #define AT91SAM7_CAN_GET_DLC(_msg_) (((_msg_).id >> 11) & 0x0F)
133 #define AT91SAM7_CAN_IS_EXT(_msg_) 0 // we do not support extended identifiers so this is always false
134 #define AT91SAM7_CAN_IS_RTR(_msg_) ((((_msg_).id >> 15) & 0x01) != 0)
135 #define AT91SAM7_CAN_GET_ID(_msg_) ((_msg_).id & CYG_CAN_STD_ID_MASK)
136 #endif // CYGOPT_IO_CAN_EXT_CAN_ID
139 //---------------------------------------------------------------------------
140 // The foolowing macros are required for CAN devicedriver. We define our own
141 // CAN messaeg and event structures and therefore we also need to define the
142 // two message conversion macros that translate out message/event into the
143 // standard CAN message/event
145 #define CYG_CAN_MSG_T at91sam7_can_message
146 #define CYG_CAN_EVENT_T at91sam7_can_event
149 // We need to copy the timestamp field only if timestamps are supported by
152 #ifdef CYGOPT_IO_CAN_SUPPORT_TIMESTAMP
153 #define CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_) ((_ioevent_ptr_)->timestamp = (_devevent_ptr_)->timestamp)
155 #define CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_)
159 #define CYG_CAN_WRITE_MSG(_devmsg_ptr_, _iomsg_ptr_) \
161 (_devmsg_ptr_)->data = (_iomsg_ptr_)->data; \
162 (_devmsg_ptr_)->id = (_iomsg_ptr_)->id; \
163 AT91SAM7_CAN_SET_DLC(*(_devmsg_ptr_), (_iomsg_ptr_)->dlc); \
164 if (CYGNUM_CAN_ID_EXT == (_iomsg_ptr_)->ext) {AT91SAM7_CAN_SET_EXT(*(_devmsg_ptr_));} \
165 if (CYGNUM_CAN_FRAME_RTR == (_iomsg_ptr_)->rtr) {AT91SAM7_CAN_SET_RTR(*(_devmsg_ptr_));} \
169 #define CYG_CAN_READ_EVENT(_ioevent_ptr_, _devevent_ptr_) \
171 (_ioevent_ptr_)->flags = (_devevent_ptr_)->flags; \
172 (_ioevent_ptr_)->msg.data = (_devevent_ptr_)->msg.data; \
173 (_ioevent_ptr_)->msg.id = AT91SAM7_CAN_GET_ID((_devevent_ptr_)->msg); \
174 (_ioevent_ptr_)->msg.dlc = AT91SAM7_CAN_GET_DLC((_devevent_ptr_)->msg); \
175 if (AT91SAM7_CAN_IS_EXT((_devevent_ptr_)->msg)) { \
176 (_ioevent_ptr_)->msg.ext = CYGNUM_CAN_ID_EXT; } \
178 (_ioevent_ptr_)->msg.ext = CYGNUM_CAN_ID_STD; } \
179 if (AT91SAM7_CAN_IS_RTR((_devevent_ptr_)->msg)) { \
180 (_ioevent_ptr_)->msg.rtr = CYGNUM_CAN_FRAME_RTR; } \
182 (_ioevent_ptr_)->msg.rtr = CYGNUM_CAN_FRAME_DATA; } \
183 CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_); \
186 //---------------------------------------------------------------------------
187 #endif // CYGONCE_CAN_AT91SAM7_H