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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [can/] [current/] [tests/] [can_load.c] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        can_load.c
4
//
5
//        CAN load test
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     Uwe Kindler
43
// Contributors:  Uwe Kindler
44
// Date:          2005-08-14
45
// Description:  CAN load test
46
//####DESCRIPTIONEND####
47
 
48
 
49
//===========================================================================
50
//                                INCLUDES
51
//===========================================================================
52
#include <pkgconf/system.h>
53
 
54
#include <cyg/infra/testcase.h>         // test macros
55
#include <cyg/infra/cyg_ass.h>          // assertion macros
56
#include <cyg/infra/diag.h>
57
 
58
// Package requirements
59
#if defined(CYGPKG_IO_CAN) && defined(CYGPKG_KERNEL)
60
 
61
#include <pkgconf/kernel.h>
62
#include <cyg/io/io.h>
63
#include <cyg/io/canio.h>
64
 
65
// Package option requirements
66
#if defined(CYGFUN_KERNEL_API_C)
67
 
68
#include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
69
#include <cyg/kernel/kapi.h>
70
 
71
// Package option requirements
72
#if defined(CYGOPT_IO_CAN_STD_CAN_ID) && defined(CYGOPT_IO_CAN_EXT_CAN_ID)
73
 
74
 
75
//===========================================================================
76
//                               DATA TYPES
77
//===========================================================================
78
typedef struct st_thread_data
79
{
80
    cyg_thread   obj;
81
    long         stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
82
    cyg_handle_t hdl;
83
} thread_data_t;
84
 
85
 
86
//===========================================================================
87
//                              LOCAL DATA
88
//===========================================================================
89
cyg_thread_entry_t can0_thread;
90
thread_data_t      can0_thread_data;
91
 
92
cyg_thread_entry_t can1_thread;
93
thread_data_t      can1_thread_data;
94
 
95
cyg_io_handle_t    hCAN0;
96
 
97
 
98
//===========================================================================
99
//                          LOCAL FUNCTIONS
100
//===========================================================================
101
#include "can_test_aux.inl" // include CAN test auxiliary functions
102
 
103
 
104
//===========================================================================
105
// Main thread
106
//===========================================================================
107
void can0_thread(cyg_addrword_t data)
108
{
109
    cyg_uint32             len;
110
    cyg_can_event          rx_event;
111
    cyg_can_timeout_info_t timeouts;
112
 
113
#if defined(CYGOPT_IO_CAN_SUPPORT_TIMEOUTS)   
114
    //
115
    // setup large timeout values because we do not need timeouts here
116
    //
117
    timeouts.rx_timeout = 100000;
118
    timeouts.tx_timeout = 100000;
119
 
120
    len = sizeof(timeouts);
121
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_CAN_TIMEOUT ,&timeouts, &len))
122
    {
123
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
124
    }
125
#endif // defined(CYGOPT_IO_CAN_SUPPORT_TIMEOUTS)  
126
 
127
    //
128
    // This thread simply receives all CAN events and prints the event flags and the
129
    // CAN message if it was a TX or RX event. You can use this test in order to check
130
    // when a RX overrun occurs
131
    //
132
    while (1)
133
    {
134
        len = sizeof(rx_event);
135
 
136
        if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len))
137
        {
138
            CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
139
        }
140
        else
141
        {
142
            print_can_flags(rx_event.flags, "");
143
 
144
            if ((rx_event.flags & CYGNUM_CAN_EVENT_RX) || (rx_event.flags & CYGNUM_CAN_EVENT_TX))
145
            {
146
                print_can_msg(&rx_event.msg, "");
147
            }
148
        }
149
    }
150
}
151
 
152
 
153
//===========================================================================
154
//                            WRITER THREAD
155
//===========================================================================
156
void can1_thread(cyg_addrword_t data)
157
{
158
    cyg_uint16      i = 0;
159
    cyg_uint32      len;
160
    cyg_can_message tx_msg =
161
    {
162
        0x000,                                               // CAN identifier
163
        data :
164
        {
165
            {0x00, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }   // 8 data bytes
166
        },
167
        CYGNUM_CAN_ID_STD,                                   // standard frame
168
        CYGNUM_CAN_FRAME_DATA,                               // data frame
169
        8,                                                   // data length code
170
    };
171
 
172
    //
173
    // This thread simply sends CAN messages. It increments the ID for each new CAN messsage
174
    // and sends a remote frame after seven data frames. In the first byte of each data frame
175
    // the number (0 - 7) of the data frame is stored and the length of the data frame grows
176
    // from 1 - 8 data bytes.
177
    //
178
    // The received pattern should look like this way:
179
    // ID    Length    Data
180
    // ----------------------------------------------
181
    // 000   1         00
182
    // 001   2         01 F1
183
    // 002   3         02 F1 F2
184
    // 003   4         03 F1 F2 F3
185
    // 004   5         04 F1 F2 F3 F4
186
    // 005   6         05 F1 F2 F3 F4 F5
187
    // 006   7         06 F1 F2 F3 F4 F5 F6
188
    // 007   8         Remote Request
189
    // 008   1         00
190
    // 009   2         01 F1
191
    // 00A   3         02 F1 F2
192
    // ...
193
    //
194
    while (1)
195
    {
196
        tx_msg.id            = i;
197
        tx_msg.dlc           = (i % 8) + 1;
198
        tx_msg.data.bytes[0] = (i % 8);
199
        i = (i + 1) % 0x7FF;
200
 
201
        //
202
        // the 6th frame is a remote frame
203
        //
204
        if ((i % 8) == 6)
205
        {
206
            tx_msg.rtr =  CYGNUM_CAN_FRAME_RTR;
207
            tx_msg.ext =  CYGNUM_CAN_ID_STD;
208
        }
209
        //
210
        // the 7th frame is a extended frame
211
        //
212
        else if ((i % 8) == 7)
213
        {
214
            tx_msg.ext =  CYGNUM_CAN_ID_EXT;
215
            tx_msg.rtr = CYGNUM_CAN_FRAME_DATA;
216
        }
217
        //
218
        // the 8th frame is a extended remote frame
219
        //
220
        else if (!(i % 8))
221
        {
222
            tx_msg.ext =  CYGNUM_CAN_ID_EXT;
223
            tx_msg.rtr = CYGNUM_CAN_FRAME_RTR;
224
        }
225
        //
226
        // all other frames are standard data frames
227
        //
228
        else
229
        {
230
            tx_msg.ext =  CYGNUM_CAN_ID_STD;
231
            tx_msg.rtr =  CYGNUM_CAN_FRAME_DATA;
232
        }
233
 
234
        len = sizeof(tx_msg);
235
        if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len))
236
        {
237
            CYG_TEST_FAIL_FINISH("Error writing to /dev/can0");
238
        }
239
 
240
        cyg_thread_delay(50);
241
    } // while (1)
242
}
243
 
244
 
245
 
246
void
247
cyg_start(void)
248
{
249
    CYG_TEST_INIT();
250
 
251
    //
252
    // open CAN device driver
253
    //
254
    if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0))
255
    {
256
        CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
257
    }
258
 
259
    //
260
    // create the two threads which access the CAN device driver
261
    // a reader thread with a higher priority and a writer thread
262
    // with a lower priority
263
    //
264
    cyg_thread_create(4, can0_thread,
265
                        (cyg_addrword_t) 0,
266
                                "can0_thread",
267
                                (void *) can0_thread_data.stack,
268
                                1024 * sizeof(long),
269
                                &can0_thread_data.hdl,
270
                                &can0_thread_data.obj);
271
 
272
    cyg_thread_create(5, can1_thread,
273
                        (cyg_addrword_t) can0_thread_data.hdl,
274
                                "can1_thread",
275
                                (void *) can1_thread_data.stack,
276
                                1024 * sizeof(long),
277
                                &can1_thread_data.hdl,
278
                                &can1_thread_data.obj);
279
 
280
    cyg_thread_resume(can0_thread_data.hdl);
281
    cyg_thread_resume(can1_thread_data.hdl);
282
 
283
    cyg_scheduler_start();
284
}
285
 
286
#else // defined(CYGOPT_IO_CAN_STD_CAN_ID) && defined(CYGOPT_IO_CAN_EXT_CAN_ID)
287
#define N_A_MSG "Needs support for standard and extended CAN identifiers"
288
#endif
289
 
290
#else // CYGFUN_KERNEL_API_C
291
#define N_A_MSG "Needs kernel C API"
292
#endif
293
 
294
#else // CYGPKG_IO_CAN && CYGPKG_KERNEL
295
#define N_A_MSG "Needs IO/CAN and Kernel"
296
#endif
297
 
298
#ifdef N_A_MSG
299
void
300
cyg_start( void )
301
{
302
    CYG_TEST_INIT();
303
    CYG_TEST_NA( N_A_MSG);
304
}
305
#endif // N_A_MSG
306
 
307
// EOF can_load.c

powered by: WebSVN 2.1.0

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