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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [can/] [arm/] [lpc2xxx/] [current/] [tests/] [can_extended_cfg.c] - Blame information for rev 867

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        can_extended_cfg.c
4
//
5
//        Test of extended CAN configuration keys for LPC2xxx CAN driver
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:          2006-06-20
45
// Description:   LPC2xxx CAN extended configuration 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
 
66
// Package option requirements
67
#if defined(CYGFUN_KERNEL_API_C)
68
 
69
#include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
70
#include <cyg/kernel/kapi.h>
71
 
72
// Package option requirements
73
#if defined(CYGOPT_IO_CAN_RUNTIME_MBOX_CFG)
74
#include "can_test_aux.inl"
75
 
76
#if defined(CYGOPT_DEVS_CAN_LPC2XXX_EXTENDED_CFG_KEYS)
77
#include <cyg/io/can_lpc2xxx.h>
78
 
79
//===========================================================================
80
//                               DATA TYPES
81
//===========================================================================
82
typedef struct st_thread_data
83
{
84
    cyg_thread   obj;
85
    long         stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
86
    cyg_handle_t hdl;
87
} thread_data_t;
88
 
89
 
90
//===========================================================================
91
//                              LOCAL DATA
92
//===========================================================================
93
cyg_thread_entry_t can0_thread;
94
thread_data_t      can0_thread_data;
95
cyg_io_handle_t    hCAN0;
96
 
97
 
98
//===========================================================================
99
//                             READER THREAD 
100
//===========================================================================
101
void can0_thread(cyg_addrword_t data)
102
{
103
    cyg_uint32              len;
104
    cyg_can_event           rx_event;
105
    cyg_can_filtergroup_cfg acc_filt_grp;
106
    cyg_can_msgbuf_cfg      msgbox_cfg;
107
 
108
    //
109
    // First we reset message buffer configuration - this is mandatory bevore starting
110
    // message buffer runtime configuration. This call clears/frees all message buffers
111
    // The CAN controller cannot receive any further CAN message after this call
112
    //
113
    msgbox_cfg.cfg_id = CYGNUM_CAN_MSGBUF_RESET_ALL;
114
    len = sizeof(msgbox_cfg);
115
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_CAN_MSGBUF ,&msgbox_cfg, &len))
116
    {
117
        CYG_TEST_FAIL_FINISH("Error resetting message buffer configuration of /dev/can0");
118
    }
119
 
120
    //
121
    // Now we setup two different acceptance filter groups. Acceptance filter
122
    // groups are not part of the CAN I/O layer and are a LPC2xxx specific
123
    // feature. You should not use appcetance filter groups if you would like
124
    // to code portable eCos CAN applications
125
    //
126
#ifdef CYGOPT_IO_CAN_STD_CAN_ID    
127
    acc_filt_grp.ext            = CYGNUM_CAN_ID_STD;
128
    acc_filt_grp.lower_id_bound = 0x100;
129
    acc_filt_grp.upper_id_bound = 0x110;
130
    len = sizeof(acc_filt_grp);
131
 
132
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_LPC2XXX_ACCFILT_GROUP ,&acc_filt_grp, &len))
133
    {
134
        CYG_TEST_FAIL_FINISH("Error adding filter group to /dev/can0");
135
    }
136
#endif // CYGOPT_IO_CAN_STD_CAN_ID
137
 
138
#ifdef CYGOPT_IO_CAN_EXT_CAN_ID   
139
    acc_filt_grp.ext            = CYGNUM_CAN_ID_EXT;
140
    acc_filt_grp.lower_id_bound = 0x2000;
141
    acc_filt_grp.upper_id_bound = 0x2200;
142
    len = sizeof(acc_filt_grp);
143
 
144
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_LPC2XXX_ACCFILT_GROUP ,&acc_filt_grp, &len))
145
    {
146
        CYG_TEST_FAIL_FINISH("Error adding filter group to /dev/can0");
147
    }
148
#endif // CYGOPT_IO_CAN_STD_CAN_ID
149
 
150
    diag_printf("\n\nNow try to send CAN messages. The device should only\n"
151
                    "receive standard messages identifiers in the range of 0x100\n"
152
                    "to 0x110 and/or extended identifiers in the range 0x2000 to\n"
153
                    "0x2200. As soon as a standard message with ID 0x110 or an\n"
154
                    "extended message with ID 0x2200 arrives, the test finishes\n\n");
155
 
156
    while (1)
157
    {
158
        len = sizeof(rx_event);
159
 
160
        if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len))
161
        {
162
            CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
163
        }
164
        else
165
        {
166
            print_can_flags(rx_event.flags, "");
167
 
168
            if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
169
            {
170
                print_can_msg(&rx_event.msg, "");
171
#ifdef CYGOPT_IO_CAN_STD_CAN_ID
172
                if (rx_event.msg.id == 0x110)
173
                {
174
                    CYG_TEST_PASS_FINISH("LPC2xxx CAN message filter group test OK");
175
                }
176
#endif // CYGOPT_IO_CAN_STD_CAN_ID
177
 
178
#ifdef CYGOPT_IO_CAN_EXT_CAN_ID          
179
                if (rx_event.msg.id == 0x2200)
180
                {
181
                    CYG_TEST_PASS_FINISH("LPC2xxx CAN message filter group test OK");
182
                }
183
#endif // CYGOPT_IO_CAN_EXT_CAN_ID  
184
 
185
                if (((rx_event.msg.id > 0x110) && (rx_event.msg.id < 0x2000))
186
                   || (rx_event.msg.id > 0x2200))
187
                {
188
                    CYG_TEST_FAIL_FINISH("Received CAN identifier outside filter group bounds");
189
                }
190
            }
191
        }
192
    } // while (1)
193
}
194
 
195
 
196
 
197
void
198
cyg_start(void)
199
{
200
    CYG_TEST_INIT();
201
 
202
    //
203
    // open CAN device driver
204
    //
205
    if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0))
206
    {
207
        CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
208
    }
209
 
210
    //
211
    // create the thread that accesses 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_DEVS_CAN_LPC2XXX_EXTENDED_CFG_KEYS
227
#define N_A_MSG "Needs support for extended LPC2xxx CAN configuration keys" 
228
#endif
229
 
230
#else // CYGOPT_IO_CAN_RUNTIME_MBOX_CFG
231
#define N_A_MSG "Needs CAN message box runtime confuguration support"
232
#endif
233
 
234
#else // CYGFUN_KERNEL_API_C
235
#define N_A_MSG "Needs kernel C API"
236
#endif
237
 
238
#else // CYGPKG_IO_CAN && CYGPKG_KERNEL
239
#define N_A_MSG "Needs Kernel"
240
#endif
241
 
242
#ifdef N_A_MSG
243
void
244
cyg_start( void )
245
{
246
    CYG_TEST_INIT();
247
    CYG_TEST_NA(N_A_MSG);
248
}
249
#endif // N_A_MSG
250
 
251
// EOF flexcan_remote.c

powered by: WebSVN 2.1.0

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