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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [can/] [current/] [tests/] [can_hdi.c] - Blame information for rev 825

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        can_hdi.c
4
//
5
//        CAN hardware description information test
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-03-22
45
// Description:   CAN hardware desciption information 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
// 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
 
72
//===========================================================================
73
//                               DATA TYPES
74
//===========================================================================
75
typedef struct st_thread_data
76
{
77
    cyg_thread   obj;
78
    long         stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
79
    cyg_handle_t hdl;
80
} thread_data_t;
81
 
82
 
83
//===========================================================================
84
//                              LOCAL DATA
85
//===========================================================================
86
cyg_thread_entry_t can0_thread;
87
thread_data_t      can0_thread_data;
88
 
89
 
90
cyg_io_handle_t    hCAN0;
91
 
92
 
93
//===========================================================================
94
//                          LOCAL FUNCTIONS
95
//===========================================================================
96
#include "can_test_aux.inl" // include CAN test auxiliary functions
97
 
98
 
99
//===========================================================================
100
// Main thread
101
//===========================================================================
102
void can0_thread(cyg_addrword_t data)
103
{
104
    cyg_uint32             len;
105
    cyg_can_hdi            hdi;
106
    cyg_can_msgbuf_info    msgbox_info;
107
 
108
 
109
    //
110
    // Query information about hardware of CAN controller
111
    //
112
    len = sizeof(hdi);
113
    if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_HDI ,&hdi, &len))
114
    {
115
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
116
    }
117
 
118
    //
119
    // Check type of CAN controller - type of supported CAN frames
120
    //
121
    diag_printf("\n\nSupported message formats:\n");
122
    if (hdi.support_flags & CYGNUM_CAN_HDI_FRAMETYPE_STD)
123
    {
124
        diag_printf("  Standard CAN (2.0A):         yes\n");
125
        diag_printf("  Extended CAN (2.0B):         no\n");
126
    }
127
    else if (hdi.support_flags & CYGNUM_CAN_HDI_FRAMETYPE_EXT_PASSIVE)
128
    {
129
        diag_printf("  Standard CAN (2.0A):         yes\n");
130
        diag_printf("  Extended CAN (2.0B):         passive\n");
131
    }
132
    else if (hdi.support_flags & CYGNUM_CAN_HDI_FRAMETYPE_EXT_ACTIVE)
133
    {
134
        diag_printf("  Standard CAN (2.0A):         yes\n");
135
        diag_printf("  Extended CAN (2.0B):         yes\n");
136
    }
137
 
138
    //
139
    // Check if this is a FullCAN controller
140
    //
141
    diag_printf("\nController type:               ");
142
    if (hdi.support_flags & CYGNUM_CAN_HDI_FULLCAN)
143
    {
144
        diag_printf("FullCAN\n");
145
        //
146
        // FullCAN means the controller supports a number of message buffers.
147
        // Now query number of available and free message buffers
148
        //
149
        len = sizeof(msgbox_info);
150
        if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_MSGBUF_INFO ,&msgbox_info, &len))
151
        {
152
             CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
153
        }
154
 
155
        diag_printf("  Message buffers:             %d\n", msgbox_info.count);
156
        diag_printf("  Message buffers free:        %d\n", msgbox_info.free);
157
    }
158
    else
159
    {
160
        diag_printf("BasicCAN\n");
161
    }
162
 
163
    //
164
    // Check if automatic baudrate detection is supported
165
    //
166
    if (hdi.support_flags & CYGNUM_CAN_HDI_AUTBAUD)
167
    {
168
        diag_printf("\nAutomatic baudrate detection:  supported\n");
169
    }
170
 
171
    //
172
    // Check if driver supports timestamps
173
    //
174
    if (hdi.support_flags & CYGNUM_CAN_HDI_TIMESTAMP)
175
    {
176
        diag_printf("Timestamps:                    supported\n");
177
    }
178
 
179
    diag_printf("\n\n");
180
    CYG_TEST_PASS_FINISH("can_hdi test OK");
181
}
182
 
183
 
184
void
185
cyg_start(void)
186
{
187
    CYG_TEST_INIT();
188
 
189
    //
190
    // open CAN device driver
191
    //
192
    if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0))
193
    {
194
        CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
195
    }
196
 
197
 
198
    //
199
    // create the two threads which access the CAN device driver
200
    // a reader thread with a higher priority and a writer thread
201
    // with a lower priority
202
    //
203
    cyg_thread_create(4, can0_thread,
204
                        (cyg_addrword_t) 0,
205
                                "can0_thread",
206
                                (void *) can0_thread_data.stack,
207
                                1024 * sizeof(long),
208
                                &can0_thread_data.hdl,
209
                                &can0_thread_data.obj);
210
 
211
    cyg_thread_resume(can0_thread_data.hdl);
212
 
213
    cyg_scheduler_start();
214
}
215
 
216
#else // CYGFUN_KERNEL_API_C
217
#define N_A_MSG "Needs kernel C API"
218
#endif
219
 
220
#else // CYGPKG_IO_CAN && CYGPKG_KERNEL
221
#define N_A_MSG "Needs IO/CAN and Kernel"
222
#endif
223
 
224
#ifdef N_A_MSG
225
void
226
cyg_start( void )
227
{
228
    CYG_TEST_INIT();
229
    CYG_TEST_NA( N_A_MSG);
230
}
231
#endif // N_A_MSG
232
 
233
//---------------------------------------------------------------------------
234
// EOF can_hdi.c

powered by: WebSVN 2.1.0

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