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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [ecos/] [ecos_init.c] - Blame information for rev 673

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

Line No. Rev Author Line
1 673 markom
//
2
// Micro-Windows/Nano-X additional setup fo eCos
3
//
4
 
5
#include <pkgconf/kernel.h>
6
#include <pkgconf/hal.h>
7
#include <cyg/kernel/kapi.h>
8
 
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <fcntl.h>
12
#include <unistd.h>
13
#include <time.h>
14
#include <ctype.h>
15
#include <errno.h>
16
#include <sys/time.h>
17
 
18
#define MWINCLUDECOLORS
19
#include <nano-X.h>
20
#include <nwidgets.h>
21
 
22
static bool closed = false;
23
 
24
static void
25
do_close(NBUTTON * w, int b)
26
{
27
   printf("Button %d was clicked in widget %p\n",b,w);
28
   closed = true;
29
}
30
 
31
// Display a number of ticks as microseconds
32
// Note: for improved calculation significance, values are kept in ticks*1000
33
static void
34
show_ns(long long ns)
35
{
36
    diag_printf("%5d.%02d", (int)(ns/1000), (int)((ns%1000)/10));
37
}
38
 
39
static long rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION;
40
static long ns_per_system_clock;
41
 
42
static long long
43
ns_time(void)
44
{
45
    unsigned long off;
46
    long long ns, clocks;
47
 
48
    ns_per_system_clock = 1000000/rtc_resolution[1];
49
    HAL_CLOCK_READ(&off);
50
    ns = (ns_per_system_clock * (long long)off) / CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
51
    ns += 5;  // for rounding to .01us
52
    clocks = (cyg_current_time() * 10000000) + ns;
53
    return clocks;
54
}
55
 
56
static void
57
test_file_io(void)
58
{
59
    long long start_time, end_time;
60
    FILE *fp;
61
    unsigned char buf[256];
62
    int len, n, fd;
63
 
64
    start_time = ns_time();
65
    if ((fp = fopen("/bin/letters.cl", "r")) != (FILE *)NULL) {
66
        len = 0;
67
        while (fgets(buf, sizeof(buf), fp)) {
68
            len += strlen(buf);
69
        }
70
        fclose(fp);
71
    }
72
    end_time = ns_time();
73
    diag_printf("'fgets': %d bytes in ", len); show_ns(end_time-start_time);  diag_printf("ns\n");
74
 
75
    start_time = ns_time();
76
    if ((fp = fopen("/bin/letters.cl", "r")) != (FILE *)NULL) {
77
        len = 0;
78
        while (n = fread(buf, 1, sizeof(buf), fp)) {
79
            len += n;
80
        }
81
        fclose(fp);
82
    }
83
    end_time = ns_time();
84
    diag_printf("'fread': %d bytes in ", len); show_ns(end_time-start_time);  diag_printf("ns\n");
85
 
86
    start_time = ns_time();
87
    if ((fd = open("/bin/letters.cl", O_RDONLY)) >= 0) {
88
        len = 0;
89
        while (n = read(fd, buf, sizeof(buf))) {
90
            len += n;
91
        }
92
        close(fd);
93
    }
94
    end_time = ns_time();
95
    diag_printf("'read': %d bytes in ", len); show_ns(end_time-start_time);  diag_printf("ns\n");
96
}
97
 
98
void
99
ecos_nx_init(CYG_ADDRWORD data)
100
{
101
    GR_SCREEN_INFO      si;             /* window information */
102
    GR_FONT_INFO        fi;             /* font information */
103
    GR_WINDOW_ID        mainwid;        /* main window id */
104
    GR_WM_PROPERTIES    props;
105
    GR_GC_ID            gct = 0;
106
    NWIDGET             *w;
107
    NBUTTON             *b;
108
    NTEXTFIELD          *t;
109
 
110
    cyg_thread_delay(50);
111
    INIT_PER_THREAD_DATA();
112
 
113
    test_file_io();
114
 
115
    if(GrOpen() < 0) {
116
        fprintf(stderr, "Couldn't connect to Nano-X server\n");
117
        exit(1);
118
    }
119
 
120
    GrGetScreenInfo(&si);
121
    GrGetFontInfo(0, &fi);
122
 
123
#if 0
124
    mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, si.cols, si.rows,
125
                          0, RED, WHITE);
126
 
127
    props.flags = GR_WM_FLAGS_PROPS;
128
    props.props = GR_WM_PROPS_BORDER;
129
    GrSetWMProperties(mainwid, &props);
130
 
131
    GrMapWindow(mainwid);
132
    GrFlush();
133
    cyg_thread_delay(50);
134
 
135
    gct = GrNewGC();
136
    GrSetGCForeground(gct, WHITE);
137
    GrSetGCFont(gct, GrCreateFont(GR_FONT_GUI_VAR, 0, NULL));
138
    GrDrawImageFromFile(mainwid, gct, 0, 0, si.cols, si.rows, "/redhat.logo", 0);
139
    GrText(mainwid, gct, 80, 350, "Tap all 4 corners", 17, GR_TFTOP);
140
    GrFlush();
141
#endif
142
 
143
    n_init_button_class();
144
    n_init_textfield_class();
145
 
146
    w = NEW_NOBJECT(widget);
147
    n_widget_init(w, 0);
148
    n_widget_resize(w, si.cols - 10, si.rows - 30);
149
    n_widget_background(w, "/redhat.logo");
150
    n_widget_show(w);
151
 
152
    b = NEW_NOBJECT(button);
153
    n_button_init(b, w, "Close");
154
    n_button_onclick(b, do_close);
155
    n_widget_resize(b, 40, 20);
156
    n_widget_move(b,180,260);
157
    n_widget_show(b);
158
 
159
    t = NEW_NOBJECT(textfield);
160
    n_textfield_init(t,w,"Tap all 4 corners");
161
    n_widget_move(t,45,220);
162
    n_widget_resize(t,120,20);
163
    n_widget_show(t);
164
 
165
    t = NEW_NOBJECT(textfield);
166
    n_textfield_init(t,w,"Then press close");
167
    n_widget_move(t,45,250);
168
    n_widget_resize(t,120,20);
169
    n_widget_show(t);
170
 
171
    while (!closed) {
172
        n_handle_event();
173
    }
174
 
175
    n_widget_hide(w);
176
    n_object_cleanup(w);
177
 
178
//    printf("Tap all four corners\n");
179
//    cyg_thread_delay(10*100);
180
 
181
    GrClose();
182
}

powered by: WebSVN 2.1.0

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