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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [can/] [loop/] [current/] [tests/] [can_txevent.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        can_txevent.c
4
//
5
//        Test CAN device driver timeouts
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-07
45
// Description:   Timeout test of CAN device driver
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
// tx event support required
72
#if defined(CYGOPT_IO_CAN_TX_EVENT_SUPPORT)
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
 
93
//===========================================================================
94
//                          LOCAL FUNCTIONS
95
//===========================================================================
96
#include "can_test_aux.inl" // include CAN test auxiliary functions
97
 
98
 
99
//===========================================================================
100
//                             WRITER THREAD 
101
//===========================================================================
102
void can0_thread(cyg_addrword_t data)
103
{
104
    cyg_io_handle_t    hCAN0;
105
    cyg_uint32         len;
106
    cyg_can_buf_info_t buf_info;
107
    cyg_uint16         i;
108
    cyg_can_event      rx_event;
109
    cyg_can_message    tx_msg =
110
    {
111
        0x000,                                               // CAN identifier
112
        data :
113
        {
114
            {0x00, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }// 8 data bytes
115
        },
116
        CYGNUM_CAN_ID_STD,                                   // standard frame
117
        CYGNUM_CAN_FRAME_DATA,                               // data frame
118
        4,                                                   // data length code
119
    };
120
 
121
 
122
    if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0))
123
    {
124
        CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
125
    }
126
 
127
    //
128
    // first we read the buffer info
129
    //
130
    len = sizeof(buf_info);
131
    if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len))
132
    {
133
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
134
    }
135
 
136
    //
137
    // check if buffer is really empty
138
    //
139
    if (buf_info.rx_count != 0)
140
    {
141
        CYG_TEST_FAIL_FINISH("Receive buffer of /dev/can0 is not empty.");
142
    }
143
 
144
    //
145
    // now send messages - because TX events are supported each transmitted CAN message
146
    // will cause a TX event that is filled into receive queue
147
    //
148
    diag_printf("Sending %d CAN messages to /dev/can0 \n", buf_info.rx_bufsize);
149
    for (i = 0; i < buf_info.rx_bufsize; ++i)
150
    {
151
        CYG_CAN_MSG_SET_STD_ID(tx_msg, 0x000 + i);
152
        CYG_CAN_MSG_SET_DATA(tx_msg, 0, i);
153
        len = sizeof(tx_msg);
154
 
155
        if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len))
156
        {
157
            CYG_TEST_FAIL_FINISH("Error writing to /dev/can0");
158
        }
159
        else
160
        {
161
            print_can_msg(&tx_msg, "");
162
        }
163
    }
164
 
165
    //
166
    // Give the loop back driver time to process all those messages.
167
    //
168
    cyg_thread_delay(10);
169
 
170
    //
171
    // now we read the buffer info - we expect a completely filled recieve queue
172
    //
173
    len = sizeof(buf_info);
174
    if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len))
175
    {
176
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
177
    }
178
 
179
    //
180
    // if receive queue is not completely filled, then we have an error here
181
    //
182
    if (buf_info.rx_bufsize != buf_info.rx_count)
183
    {
184
        diag_printf("RX bufsize: %d    events in RX buffer: %d\n", buf_info.rx_bufsize, buf_info.rx_count);
185
        CYG_TEST_FAIL_FINISH("Receive queue of /dev/can0 not completely filled.");
186
    }
187
 
188
    //
189
    // now we read the receive queue
190
    //
191
    diag_printf("Receiving %d TX events from /dev/can0 \n", buf_info.rx_count);
192
    for (i = 0; i < buf_info.rx_count; ++i)
193
    {
194
        len = sizeof(rx_event);
195
 
196
        if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len))
197
        {
198
            CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
199
        }
200
 
201
        //
202
        // we expect only a set TX flag because no other events may arrive for the
203
        // loopback driver
204
        //
205
        if (!(rx_event.flags & CYGNUM_CAN_EVENT_TX) || (rx_event.flags & !CYGNUM_CAN_EVENT_TX))
206
        {
207
            CYG_TEST_FAIL_FINISH("Unexpected receive event flags.");
208
        }
209
 
210
        //
211
        // Now check if TX events contain valid data - we know that the ID and the first
212
        // data byte contain the message number
213
        //
214
        if ((rx_event.msg.id != i) || (rx_event.msg.data.bytes[0] != i))
215
        {
216
            CYG_TEST_FAIL_FINISH("Received invalid data in TX event");
217
        }
218
        else
219
        {
220
            print_can_msg(&rx_event.msg, "");
221
        }
222
    } // for (i = 0; i < buf_info.rx_count; ++i)
223
 
224
    CYG_TEST_PASS_FINISH("can_txevent test OK");
225
}
226
 
227
 
228
 
229
void
230
cyg_start(void)
231
{
232
    CYG_TEST_INIT();
233
 
234
    //
235
    // create the thread which access the CAN device driver
236
    //
237
    cyg_thread_create(4, can0_thread,
238
                        (cyg_addrword_t) 0,
239
                                "can0_thread",
240
                                (void *) can0_thread_data.stack,
241
                                1024 * sizeof(long),
242
                                &can0_thread_data.hdl,
243
                                &can0_thread_data.obj);
244
 
245
    cyg_thread_resume(can0_thread_data.hdl);
246
 
247
    cyg_scheduler_start();
248
}
249
 
250
#else // CYGOPT_IO_CAN_TX_EVENT_SUPPORT
251
#define N_A_MSG "TX event support required for IO/CAN"
252
#endif
253
 
254
#else // CYGFUN_KERNEL_API_C
255
#define N_A_MSG "Needs kernel C API"
256
#endif
257
 
258
#else // CYGPKG_IO_CAN && CYGPKG_KERNEL
259
#define N_A_MSG "Needs IO/CAN and Kernel"
260
#endif
261
 
262
#ifdef N_A_MSG
263
void
264
cyg_start( void )
265
{
266
    CYG_TEST_INIT();
267
    CYG_TEST_NA( N_A_MSG);
268
}
269
#endif // N_A_MSG
270
 
271
// EOF serial4.c

powered by: WebSVN 2.1.0

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