1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// can_nonblock.c
|
4 |
|
|
//
|
5 |
|
|
// CAN driver test of nonblocking calls
|
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 driver test of nonblocking callst
|
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_SUPPORT_NONBLOCKING)
|
73 |
|
|
|
74 |
|
|
//===========================================================================
|
75 |
|
|
// DATA TYPES
|
76 |
|
|
//===========================================================================
|
77 |
|
|
typedef struct st_thread_data
|
78 |
|
|
{
|
79 |
|
|
cyg_thread obj;
|
80 |
|
|
long stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
|
81 |
|
|
cyg_handle_t hdl;
|
82 |
|
|
} thread_data_t;
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
//===========================================================================
|
86 |
|
|
// LOCAL DATA
|
87 |
|
|
//===========================================================================
|
88 |
|
|
cyg_thread_entry_t can0_thread;
|
89 |
|
|
thread_data_t can0_thread_data;
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
cyg_io_handle_t hDrvFlexCAN;
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
//===========================================================================
|
96 |
|
|
// LOCAL FUNCTIONS
|
97 |
|
|
//===========================================================================
|
98 |
|
|
#include "can_test_aux.inl" // include CAN test auxiliary functions
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
//===========================================================================
|
102 |
|
|
// READER THREAD
|
103 |
|
|
//===========================================================================
|
104 |
|
|
void can0_thread(cyg_addrword_t data)
|
105 |
|
|
{
|
106 |
|
|
cyg_uint32 len;
|
107 |
|
|
cyg_uint32 blocking;
|
108 |
|
|
cyg_can_event rx_event;
|
109 |
|
|
Cyg_ErrNo res;
|
110 |
|
|
|
111 |
|
|
blocking = 0;
|
112 |
|
|
len = sizeof(blocking);
|
113 |
|
|
if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_READ_BLOCKING ,&blocking, &len))
|
114 |
|
|
{
|
115 |
|
|
CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
len = sizeof(rx_event);
|
119 |
|
|
res = cyg_io_read(hDrvFlexCAN, &rx_event, &len);
|
120 |
|
|
|
121 |
|
|
if (-EAGAIN == res)
|
122 |
|
|
{
|
123 |
|
|
CYG_TEST_PASS_FINISH("can_test1 test OK");
|
124 |
|
|
}
|
125 |
|
|
else if (-EINTR == res)
|
126 |
|
|
{
|
127 |
|
|
CYG_TEST_PASS_FINISH("can_test1 test OK");
|
128 |
|
|
}
|
129 |
|
|
else
|
130 |
|
|
{
|
131 |
|
|
CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
void
|
137 |
|
|
cyg_start(void)
|
138 |
|
|
{
|
139 |
|
|
cyg_uint32 len;
|
140 |
|
|
cyg_can_info_t can_cfg;
|
141 |
|
|
|
142 |
|
|
CYG_TEST_INIT();
|
143 |
|
|
|
144 |
|
|
//
|
145 |
|
|
// open flexcan device driver
|
146 |
|
|
//
|
147 |
|
|
if (ENOERR != cyg_io_lookup("/dev/can0", &hDrvFlexCAN))
|
148 |
|
|
{
|
149 |
|
|
CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
//
|
153 |
|
|
// setup CAN baudrate 250 KBaud
|
154 |
|
|
//
|
155 |
|
|
can_cfg.baud = CYGNUM_CAN_KBAUD_250;
|
156 |
|
|
len = sizeof(can_cfg);
|
157 |
|
|
if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_CAN_INFO ,&can_cfg, &len))
|
158 |
|
|
{
|
159 |
|
|
CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
//
|
163 |
|
|
// create the main thread
|
164 |
|
|
//
|
165 |
|
|
cyg_thread_create(4, can0_thread,
|
166 |
|
|
(cyg_addrword_t) 0,
|
167 |
|
|
"can0_thread",
|
168 |
|
|
(void *) can0_thread_data.stack,
|
169 |
|
|
1024 * sizeof(long),
|
170 |
|
|
&can0_thread_data.hdl,
|
171 |
|
|
&can0_thread_data.obj);
|
172 |
|
|
|
173 |
|
|
cyg_thread_resume(can0_thread_data.hdl);
|
174 |
|
|
|
175 |
|
|
cyg_scheduler_start();
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
#else // #if defined(CYGOPT_IO_CAN_SUPPORT_NONBLOCKING)
|
179 |
|
|
#define N_A_MSG "Needs nonblocking calls"
|
180 |
|
|
#endif
|
181 |
|
|
|
182 |
|
|
#else // CYGFUN_KERNEL_API_C
|
183 |
|
|
#define N_A_MSG "Needs kernel C API"
|
184 |
|
|
#endif
|
185 |
|
|
|
186 |
|
|
#else // CYGPKG_IO_CAN && CYGPKG_KERNEL
|
187 |
|
|
#define N_A_MSG "Needs IO/CAN and Kernel"
|
188 |
|
|
#endif
|
189 |
|
|
|
190 |
|
|
#ifdef N_A_MSG
|
191 |
|
|
void
|
192 |
|
|
cyg_start( void )
|
193 |
|
|
{
|
194 |
|
|
CYG_TEST_INIT();
|
195 |
|
|
CYG_TEST_NA( N_A_MSG);
|
196 |
|
|
}
|
197 |
|
|
#endif // N_A_MSG
|
198 |
|
|
|
199 |
|
|
// EOF can_nonblock.c
|