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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [ecos/] [ecos_init.c] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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