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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [kclock1.c] - Blame information for rev 228

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

Line No. Rev Author Line
1 27 unneback
/*=================================================================
2
//
3
//        kclock1.c
4
//
5
//        Kernel C API Clock test 1 - Real Time Clock
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 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     dsm
44
// Contributors:    dsm
45
// Date:          1998-03-20
46
// Description:   Tests the Kernel Real Time Clock
47
//                This test creates a thread, starts the scheduler and
48
//                delays for a time of about 5 seconds.  This test should
49
//                be expected to run for about this length of time.
50
// Omissions:
51
//     Doesn't test alarms attached to RTC.
52
// Assumptions:
53
//     CYGVAR_KERNEL_COUNTERS_CLOCK must be set.
54
//     Resolution of clock small compared with 5s.
55
//     Overhead small compared with 5s.
56
// Options:
57
//     CYGIMP_KERNEL_COUNTERS_SINGLE_LIST
58
//     CYGIMP_KERNEL_COUNTERS_MULTI_LIST
59
//     CYGVAR_KERNEL_COUNTERS_CLOCK
60
//     CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE
61
//####DESCRIPTIONEND####
62
*/
63
 
64
#include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
65
 
66
#include <cyg/kernel/kapi.h>
67
 
68
#include <cyg/infra/testcase.h>
69
 
70
 
71
static cyg_uint64 TEST_DELAY;
72
 
73
#ifdef CYGFUN_KERNEL_THREADS_TIMER
74
 
75
#ifdef CYGFUN_KERNEL_API_C
76
 
77
#include "testaux.h"
78
 
79
#define NTHREADS 1
80
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
81
 
82
static cyg_handle_t thread[NTHREADS];
83
 
84
static cyg_thread thread_obj[NTHREADS];
85
static char stack[NTHREADS][STACKSIZE];
86
 
87
static void entry0( cyg_addrword_t data )
88
{
89
    cyg_resolution_t res;
90
    cyg_uint32 ticks;
91
    cyg_tick_count_t count0, count1;
92
    cyg_handle_t rtclock, rtcounter;
93
 
94
    rtclock = cyg_real_time_clock();
95
    cyg_clock_to_counter(rtclock, &rtcounter);
96
 
97
    res = cyg_clock_get_resolution (rtclock);
98
 
99
    /* RTC takes res.dividend/res.divisor ns/tick */
100
    ticks = ((cyg_uint64)TEST_DELAY * res.divisor) / res.dividend;
101
 
102
    count0 = cyg_counter_current_value(rtcounter);
103
    cyg_thread_delay(ticks);
104
    count1 = cyg_counter_current_value(rtcounter);
105
 
106
    CYG_TEST_CHECK(count0+ticks <= count1,
107
                   "real time clock's counter not counting");
108
 
109
    CYG_TEST_CHECK(count1 <= cyg_current_time(),"cyg_current_time()");
110
 
111
    CYG_TEST_PASS_FINISH("Kernel C API Clock 1 OK");
112
}
113
 
114
void kclock1_main( void )
115
{
116
    CYG_TEST_INIT();
117
 
118
    if (cyg_test_is_simulator) {
119
        TEST_DELAY = 100000000ll;
120
    } else {
121
        TEST_DELAY = 3000000000ll;
122
    }
123
 
124
    cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kclock1",
125
        (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
126
    cyg_thread_resume(thread[0]);
127
 
128
    cyg_scheduler_start();
129
}
130
 
131
externC void
132
cyg_start( void )
133
{
134
    kclock1_main();
135
}
136
 
137
#else  // def CYGFUN_KERNEL_API_C
138
#define N_A_MSG "Kernel C API layer disabled"
139
#endif // def CYGFUN_KERNEL_API_C
140
#else  // def CYGFUN_KERNEL_THREADS_TIMER
141
#define N_A_MSG "Kernel threads timer disabled"
142
#endif // def CYGFUN_KERNEL_THREADS_TIMER
143
 
144
#ifdef N_A_MSG
145
externC void
146
cyg_start( void )
147
{
148
    CYG_TEST_INIT();
149
    CYG_TEST_NA( N_A_MSG );
150
}
151
#endif // N_A_MSG
152
 
153
// EOF kclock1.c

powered by: WebSVN 2.1.0

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