]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/devs/can/arm/at91/at91sam7/v2_0/include/can_at91sam7.inl
Initial revision
[karo-tx-redboot.git] / packages / devs / can / arm / at91 / at91sam7 / v2_0 / include / can_at91sam7.inl
1 #ifndef CYGONCE_CAN_AT91SAM7_H
2 #define CYGONCE_CAN_AT91SAM7_H
3 //==========================================================================
4 //
5 //      devs/can/arm/at91sam7x/current/include/can_at91sam7.inl
6 //
7 //      CAN message macros for Atmel AT91SAM7X CAN driver
8 //
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
15 //
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.
19 //
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
23 // for more details.
24 //
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.
28 //
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.
35 //
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.
38 //
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####
45 //
46 // Author(s):    Uwe Kindler
47 // Contributors: Uwe Kindler
48 // Date:         2007-02-08
49 // Purpose:      Support AT91SAM7X on-chip CAN moduls
50 // Description: 
51 //
52 //####DESCRIPTIONEND####
53 //
54 //==========================================================================
55
56
57 //==========================================================================
58 //                               INCLUDE
59 //==========================================================================
60 #include <pkgconf/devs_can_at91sam7.h>
61
62
63 //==========================================================================
64 //                              DATA TYPES
65 //==========================================================================
66
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
71 //
72 typedef struct st_at91sam7_can_message
73 {
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  
78 #else
79     //
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
84     //
85     cyg_uint16       id; 
86 #endif
87 } at91sam7_can_message;
88
89
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
94 //
95 typedef struct st_at91sam7_can_event
96 {
97     cyg_uint16           flags;
98 #ifdef CYGOPT_IO_CAN_SUPPORT_TIMESTAMP
99     cyg_uint16           timestamp;
100 #endif
101     at91sam7_can_message msg;
102 } at91sam7_can_event;
103
104
105
106 //==========================================================================
107 //                                DEFINES
108 //==========================================================================
109 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID
110 //
111 // If we use extended identifier then we store the message parameters
112 // into control word
113 //
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)
117
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
123 //
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
126 // standard frames
127 //
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)
131
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
137
138
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
144 //
145 #define CYG_CAN_MSG_T   at91sam7_can_message
146 #define CYG_CAN_EVENT_T at91sam7_can_event
147
148 //
149 // We need to copy the timestamp field only if timestamps are supported by
150 // driver
151 //
152 #ifdef CYGOPT_IO_CAN_SUPPORT_TIMESTAMP
153 #define CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_) ((_ioevent_ptr_)->timestamp = (_devevent_ptr_)->timestamp)
154 #else
155 #define CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_)
156 #endif
157
158
159 #define CYG_CAN_WRITE_MSG(_devmsg_ptr_, _iomsg_ptr_)                                         \
160 CYG_MACRO_START                                                                              \
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_));} \
166 CYG_MACRO_END
167
168
169 #define CYG_CAN_READ_EVENT(_ioevent_ptr_, _devevent_ptr_)                     \
170 CYG_MACRO_START                                                               \
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; }                       \
177     else {                                                                    \
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; }                    \
181     else {                                                                    \
182         (_ioevent_ptr_)->msg.rtr = CYGNUM_CAN_FRAME_DATA; }                   \
183     CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_);                    \
184 CYG_MACRO_END
185
186 //---------------------------------------------------------------------------
187 #endif // CYGONCE_CAN_AT91SAM7_H