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_timeout.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        can_timeout.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
// timeout support required
72
#if defined(CYGOPT_IO_CAN_SUPPORT_TIMEOUTS)
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
// Measure timeout time and compare it with RX timeout value
101
//===========================================================================
102
void check_timeout(cyg_io_handle_t hCAN, cyg_uint32 timeout)
103
{
104
    cyg_can_event          rx_event;
105
    cyg_can_timeout_info_t timeout_info;
106
    cyg_uint32             len;
107
    cyg_uint32             current_time_old;
108
    cyg_uint32             current_time_new;
109
    cyg_int32              diff_time;
110
 
111
 
112
 
113
    timeout_info.tx_timeout = timeout;
114
    timeout_info.rx_timeout = timeout;
115
    len = sizeof(timeout_info);
116
    if (ENOERR != cyg_io_set_config(hCAN, CYG_IO_SET_CONFIG_CAN_TIMEOUT ,&timeout_info, &len))
117
    {
118
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
119
    }
120
 
121
    diag_printf("read timeout:  %d\n", timeout);
122
 
123
    //
124
    // if the return code is -EINTR then we know that a timout occured. Normally the
125
    // receive queue should be empty so we can expect a timeout here
126
    //
127
    current_time_old = (cyg_uint32)cyg_current_time();
128
    len = sizeof(rx_event);
129
    if (-EINTR == cyg_io_read(hCAN, &rx_event, &len))
130
    {
131
        current_time_new = (cyg_uint32)cyg_current_time();
132
        diff_time = current_time_new -  current_time_old;
133
        diag_printf("measured time: %d\n\n", diff_time);
134
        diff_time = diff_time - timeout;
135
 
136
        //
137
        // If the measured value is smaller then the timeout value or if
138
        // the difference is > 2 the we treat this as an error
139
        //
140
        if ((diff_time < 0) || (diff_time > 2))
141
        {
142
            CYG_TEST_FAIL_FINISH("Measured timeout time differs from /dev/can0 RX timeout value.");
143
        }
144
    }
145
    else
146
    {
147
        CYG_TEST_FAIL_FINISH("Timeout expected for /dev/can0");
148
    }
149
}
150
 
151
//===========================================================================
152
//                             WRITER THREAD 
153
//===========================================================================
154
void can0_thread(cyg_addrword_t data)
155
{
156
    cyg_io_handle_t        hCAN0;
157
    cyg_uint32             len;
158
    cyg_uint32             blocking;
159
    cyg_can_timeout_info_t timeout_info;
160
 
161
 
162
    if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0))
163
    {
164
        CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
165
    }
166
 
167
    //
168
    // the first thing we need to do is to switch to nonblocking calls because
169
    // function calls with timeout require nonblocking calls
170
    //
171
    blocking = 0;
172
    len = sizeof(blocking);
173
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_READ_BLOCKING ,&blocking, &len))
174
    {
175
        CYG_TEST_FAIL_FINISH("Error changing config of /dev/can0");
176
    }
177
 
178
    //
179
    // first we read the timeout configuration
180
    //
181
    len = sizeof(timeout_info);
182
    if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_TIMEOUT ,&timeout_info, &len))
183
    {
184
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
185
    }
186
 
187
    //
188
    // now we check the default timeout and a number of different timeout values
189
    //
190
    check_timeout(hCAN0, timeout_info.rx_timeout);
191
    check_timeout(hCAN0, 10);
192
    check_timeout(hCAN0, 20);
193
    check_timeout(hCAN0, 50);
194
    check_timeout(hCAN0, 100);
195
    check_timeout(hCAN0, 200);
196
    check_timeout(hCAN0, 500);
197
 
198
 
199
    CYG_TEST_PASS_FINISH("can_timeout test OK");
200
}
201
 
202
 
203
 
204
 
205
void
206
cyg_start(void)
207
{
208
    CYG_TEST_INIT();
209
 
210
    //
211
    // create the thread which access the CAN device driver
212
    //
213
    cyg_thread_create(4, can0_thread,
214
                        (cyg_addrword_t) 0,
215
                                "can0_thread",
216
                                (void *) can0_thread_data.stack,
217
                                1024 * sizeof(long),
218
                                &can0_thread_data.hdl,
219
                                &can0_thread_data.obj);
220
 
221
    cyg_thread_resume(can0_thread_data.hdl);
222
 
223
    cyg_scheduler_start();
224
}
225
 
226
#else // CYGOPT_IO_CAN_SUPPORT_TIMEOUTS
227
#define N_A_MSG "Timeout support required for IO/CAN"
228
#endif
229
 
230
#else // CYGFUN_KERNEL_API_C
231
#define N_A_MSG "Needs kernel C API"
232
#endif
233
 
234
#else // CYGPKG_IO_CAN && CYGPKG_KERNEL
235
#define N_A_MSG "Needs IO/CAN and Kernel"
236
#endif
237
 
238
#ifdef N_A_MSG
239
void
240
cyg_start( void )
241
{
242
    CYG_TEST_INIT();
243
    CYG_TEST_NA( N_A_MSG);
244
}
245
#endif // N_A_MSG
246
 
247
// EOF can_timeout.c

powered by: WebSVN 2.1.0

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