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_baudrates.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_baudrates.c
4
//
5
//        CAN test of all supported baudrates
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:          2007-06-26
45
// Description:   CAN LPC2xxx baudrate 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
 
73
#include "can_test_aux.inl" // include CAN test auxiliary functions
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
cyg_io_handle_t    hCAN;
91
 
92
 
93
//
94
// The table of baudrates to test
95
//
96
static cyg_can_baud_rate_t baudrate_tbl[9] =
97
{
98
    CYGNUM_CAN_KBAUD_10,
99
    CYGNUM_CAN_KBAUD_20,
100
    CYGNUM_CAN_KBAUD_50,
101
    CYGNUM_CAN_KBAUD_100,
102
    CYGNUM_CAN_KBAUD_125,
103
    CYGNUM_CAN_KBAUD_250,
104
    CYGNUM_CAN_KBAUD_500,
105
    CYGNUM_CAN_KBAUD_800,
106
    CYGNUM_CAN_KBAUD_1000,
107
};
108
 
109
//
110
// String table forprinting supported baudrates
111
//
112
static char* baudrate_strings_tbl[9] =
113
{
114
    "10",
115
    "20",
116
    "50",
117
    "100",
118
    "125",
119
    "250",
120
    "500",
121
    "800",
122
    "1000",
123
};
124
 
125
 
126
//===========================================================================
127
// Thread 0
128
//===========================================================================
129
void can0_thread(cyg_addrword_t data)
130
{
131
    cyg_uint32          len;
132
    cyg_can_event       rx_event;
133
    cyg_uint32          i;
134
    cyg_can_info_t      can_info;
135
 
136
    diag_printf("\n\nWhen the LPC2xxx driver selects a new baudrate then you need\n"
137
                "to setup your hardware to the new baudrate and send one CAN\n"
138
                "single CAN standard message.\n");
139
    //
140
    // Test all supported baudrates
141
    //
142
    for (i = 0; i < 9; ++i)
143
    {
144
        diag_printf("\n\nBaudrate: %s Kbaud\n", baudrate_strings_tbl[i]);
145
        can_info.baud = baudrate_tbl[i];
146
        len = sizeof(can_info);
147
        if (ENOERR != cyg_io_set_config(hCAN, CYG_IO_SET_CONFIG_CAN_INFO, &can_info, &len))
148
        {
149
            diag_printf("not supported\n");
150
            continue;
151
        }
152
        else
153
        {
154
            diag_printf("waiting for CAN message...\n");
155
        }
156
 
157
        len = sizeof(rx_event);
158
        //
159
        // First receive CAN event from real CAN hardware
160
        //
161
        len = sizeof(rx_event);
162
        if (ENOERR != cyg_io_read(hCAN, &rx_event, &len))
163
        {
164
            CYG_TEST_FAIL_FINISH("Error reading from channel 0");
165
        }
166
 
167
        if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
168
        {
169
            print_can_msg(&rx_event.msg, "RX chan 1:");
170
        } // if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
171
        else
172
        {
173
            print_can_flags(rx_event.flags, "");
174
            CYG_TEST_FAIL_FINISH("Rx message expected");
175
        }
176
    } // for (i = 0; i < 9; ++i)
177
 
178
    CYG_TEST_PASS_FINISH("CAN baudrate test OK");
179
}
180
 
181
 
182
//===========================================================================
183
// Entry point
184
//===========================================================================
185
void cyg_start(void)
186
{
187
    CYG_TEST_INIT();
188
 
189
    //
190
    // open CAN device driver channel 1
191
    //
192
    if (ENOERR != cyg_io_lookup(CYGPKG_DEVS_CAN_LPC2XXX_CAN0_NAME, &hCAN))
193
    {
194
        CYG_TEST_FAIL_FINISH("Error opening CAN channel 0");
195
    }
196
 
197
    //
198
    // create the main thread
199
    //
200
    cyg_thread_create(5, can0_thread,
201
                        (cyg_addrword_t) 0,
202
                        "can_tx_thread",
203
                        (void *) can0_thread_data.stack,
204
                        1024 * sizeof(long),
205
                        &can0_thread_data.hdl,
206
                        &can0_thread_data.obj);
207
 
208
    cyg_thread_resume(can0_thread_data.hdl);
209
 
210
    cyg_scheduler_start();
211
}
212
#else // CYGFUN_KERNEL_API_C
213
#define N_A_MSG "Needs kernel C API"
214
#endif
215
 
216
#else // CYGPKG_IO_CAN && CYGPKG_KERNEL
217
#define N_A_MSG "Needs Kernel"
218
#endif
219
 
220
#ifdef N_A_MSG
221
void
222
cyg_start( void )
223
{
224
    CYG_TEST_INIT();
225
    CYG_TEST_NA(N_A_MSG);
226
}
227
#endif // N_A_MSG
228
 
229
//---------------------------------------------------------------------------
230
// EOF can_busload.c

powered by: WebSVN 2.1.0

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