OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [can/] [arm/] [at91/] [at91sam7/] [current/] [include/] [can_at91sam7.inl] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#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, 2003 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later
18
// version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT
21
// ANY 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
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
28
//
29
// As a special exception, if other files instantiate templates or use
30
// macros or inline functions from this file, or you compile this file
31
// and link it with other works to produce a work based on this file,
32
// this file does not by itself cause the resulting work to be covered by
33
// the GNU General Public License. However the source code for this file
34
// must still be made available in accordance with section (3) of the GNU
35
// General Public License v2.
36
//
37
// This exception does not invalidate any other reasons why a work based
38
// on this file might be covered by the GNU General Public License.
39
// -------------------------------------------
40
// ####ECOSGPLCOPYRIGHTEND####
41
//==========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    Uwe Kindler
45
// Contributors: Uwe Kindler
46
// Date:         2007-02-08
47
// Purpose:      Support AT91SAM7X on-chip CAN moduls
48
// Description:
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
 
55
//==========================================================================
56
//                               INCLUDE
57
//==========================================================================
58
#include 
59
 
60
 
61
//==========================================================================
62
//                              DATA TYPES
63
//==========================================================================
64
 
65
//--------------------------------------------------------------------------
66
// We define our own CAN message data type here. This structure needs less
67
// memory than the common CAN message defined by IO layer. This is important
68
// because the AT91SAM7 contains only 64 KBytes RAM memory
69
//
70
typedef struct st_at91sam7_can_message
71
{
72
    cyg_can_msg_data data;// 8 data bytes
73
#ifdef CYGOPT_IO_CAN_EXT_CAN_ID
74
    cyg_uint32       id;  // also extended identifiers (29 Bit) are supported
75
    cyg_uint8        ctrl;// control stores extended flag, rtr flag and dlc
76
#else
77
    //
78
    // only standard identifiers are supported - we need only 11 bit of
79
    // the data word to store the identifier. So we have 5 bit left to store
80
    // the the rtr flag and the dlc flag. We do not need the IDE flag because
81
    // only standard identifiers are supported
82
    //
83
    cyg_uint16       id;
84
#endif
85
} at91sam7_can_message;
86
 
87
 
88
//--------------------------------------------------------------------------
89
// We also define an own event structure here to store the received events
90
// This event structure uses the device CAN message structure and
91
// 16 Bit value for timestamps
92
//
93
typedef struct st_at91sam7_can_event
94
{
95
    cyg_uint16           flags;
96
#ifdef CYGOPT_IO_CAN_SUPPORT_TIMESTAMP
97
    cyg_uint16           timestamp;
98
#endif
99
    at91sam7_can_message msg;
100
} at91sam7_can_event;
101
 
102
 
103
 
104
//==========================================================================
105
//                                DEFINES
106
//==========================================================================
107
#ifdef CYGOPT_IO_CAN_EXT_CAN_ID
108
//
109
// If we use extended identifier then we store the message parameters
110
// into control word
111
//
112
#define AT91SAM7_CAN_SET_DLC(_msg_, _dlc_)  ((_msg_).ctrl = (_dlc_)) // this also clears the ctrl
113
#define AT91SAM7_CAN_SET_EXT(_msg_)         ((_msg_).ctrl |= 0x01 << 4)
114
#define AT91SAM7_CAN_SET_RTR(_msg_)         ((_msg_).ctrl |= 0x01 << 5)
115
 
116
#define AT91SAM7_CAN_GET_DLC(_msg_)         ((_msg_).ctrl & 0x0F)
117
#define AT91SAM7_CAN_IS_EXT(_msg_)          ((((_msg_).ctrl >> 4) & 0x01) != 0)
118
#define AT91SAM7_CAN_IS_RTR(_msg_)          ((((_msg_).ctrl >> 5) & 0x01) != 0)
119
#define AT91SAM7_CAN_GET_ID(_msg_)          ((_msg_).id & CYG_CAN_EXT_ID_MASK)
120
#else // CYGOPT_IO_CAN_EXT_CAN_ID
121
//
122
// We use only standard identifiers and we can store the message parameters
123
// into the upper 5 bits of the 16 bit id field (only 11 bits are required for
124
// standard frames
125
//
126
#define AT91SAM7_CAN_SET_DLC(_msg_, _dlc_)  ((_msg_).id |= (_dlc_) << 11)
127
#define AT91SAM7_CAN_SET_EXT(_msg_)         // we do not need to support this flag - only std IDs supported
128
#define AT91SAM7_CAN_SET_RTR(_msg_)         ((_msg_).id |= 0x01 << 15)
129
 
130
#define AT91SAM7_CAN_GET_DLC(_msg_)         (((_msg_).id >> 11) & 0x0F)
131
#define AT91SAM7_CAN_IS_EXT(_msg_)          0 // we do not support extended identifiers so this is always false
132
#define AT91SAM7_CAN_IS_RTR(_msg_)          ((((_msg_).id >> 15) & 0x01) != 0)
133
#define AT91SAM7_CAN_GET_ID(_msg_)          ((_msg_).id & CYG_CAN_STD_ID_MASK)
134
#endif // CYGOPT_IO_CAN_EXT_CAN_ID
135
 
136
 
137
//---------------------------------------------------------------------------
138
// The foolowing macros are required for CAN devicedriver. We define our own
139
// CAN messaeg and event structures and therefore we also need to define the
140
// two message conversion macros that translate out message/event into the
141
// standard CAN message/event
142
//
143
#define CYG_CAN_MSG_T   at91sam7_can_message
144
#define CYG_CAN_EVENT_T at91sam7_can_event
145
 
146
//
147
// We need to copy the timestamp field only if timestamps are supported by
148
// driver
149
//
150
#ifdef CYGOPT_IO_CAN_SUPPORT_TIMESTAMP
151
#define CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_) ((_ioevent_ptr_)->timestamp = (_devevent_ptr_)->timestamp)
152
#else
153
#define CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_)
154
#endif
155
 
156
 
157
#define CYG_CAN_WRITE_MSG(_devmsg_ptr_, _iomsg_ptr_)                                         \
158
CYG_MACRO_START                                                                              \
159
    (_devmsg_ptr_)->data = (_iomsg_ptr_)->data;                                              \
160
    (_devmsg_ptr_)->id   = (_iomsg_ptr_)->id;                                                \
161
    AT91SAM7_CAN_SET_DLC(*(_devmsg_ptr_), (_iomsg_ptr_)->dlc);                               \
162
    if (CYGNUM_CAN_ID_EXT == (_iomsg_ptr_)->ext) {AT91SAM7_CAN_SET_EXT(*(_devmsg_ptr_));}    \
163
    if (CYGNUM_CAN_FRAME_RTR == (_iomsg_ptr_)->rtr) {AT91SAM7_CAN_SET_RTR(*(_devmsg_ptr_));} \
164
CYG_MACRO_END
165
 
166
 
167
#define CYG_CAN_READ_EVENT(_ioevent_ptr_, _devevent_ptr_)                     \
168
CYG_MACRO_START                                                               \
169
    (_ioevent_ptr_)->flags    = (_devevent_ptr_)->flags;                      \
170
    (_ioevent_ptr_)->msg.data = (_devevent_ptr_)->msg.data;                   \
171
    (_ioevent_ptr_)->msg.id   = AT91SAM7_CAN_GET_ID((_devevent_ptr_)->msg);   \
172
    (_ioevent_ptr_)->msg.dlc  = AT91SAM7_CAN_GET_DLC((_devevent_ptr_)->msg);  \
173
    if (AT91SAM7_CAN_IS_EXT((_devevent_ptr_)->msg))  {                        \
174
        (_ioevent_ptr_)->msg.ext = CYGNUM_CAN_ID_EXT; }                       \
175
    else {                                                                    \
176
        (_ioevent_ptr_)->msg.ext = CYGNUM_CAN_ID_STD; }                       \
177
    if (AT91SAM7_CAN_IS_RTR((_devevent_ptr_)->msg))  {                        \
178
        (_ioevent_ptr_)->msg.rtr = CYGNUM_CAN_FRAME_RTR; }                    \
179
    else {                                                                    \
180
        (_ioevent_ptr_)->msg.rtr = CYGNUM_CAN_FRAME_DATA; }                   \
181
    CYG_CAN_READ_TIMESTAMP(_ioevent_ptr_, _devevent_ptr_);                    \
182
CYG_MACRO_END
183
 
184
//---------------------------------------------------------------------------
185
#endif // CYGONCE_CAN_AT91SAM7_H

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.