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_app.c] - Blame information for rev 27

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

Line No. Rev Author Line
1 27 unneback
/*
2
 * Written 1999-03-19 by Jonathan Larmour, Cygnus Solutions
3
 * Modifed for touchscreen testing by Richard Panton 13-09-00
4
 * This file is in the public domain and may be used for any purpose
5
 */
6
 
7
/* CONFIGURATION CHECKS */
8
 
9
#include <pkgconf/system.h>     /* which packages are enabled/disabled */
10
#ifdef CYGPKG_KERNEL
11
# include <pkgconf/kernel.h>
12
#endif
13
#ifdef CYGPKG_LIBC
14
# include <pkgconf/libc.h>
15
#endif
16
#ifdef CYGPKG_IO_SERIAL
17
# include <pkgconf/io_serial.h>
18
#endif
19
#ifdef CYGPKG_FS_ROM
20
#define USE_ROMDISK
21
#endif
22
#ifdef CYGPKG_FS_JFFS2
23
# include <pkgconf/io_flash.h>
24
#define USE_JFFS2
25
#undef  USE_ROMDISK
26
#endif
27
 
28
#ifndef CYGFUN_KERNEL_API_C
29
# error Kernel API must be enabled to build this application
30
#endif
31
 
32
#ifndef CYGPKG_LIBC_STDIO
33
# error C library standard I/O must be enabled to build this application
34
#endif
35
 
36
#ifndef CYGPKG_IO_SERIAL_HALDIAG
37
# error I/O HALDIAG pseudo-device driver must be enabled to build this application
38
#endif
39
 
40
/* INCLUDES */
41
 
42
#include <stdio.h>                      /* printf */
43
#include <stdlib.h>                      /* printf */
44
#include <string.h>                     /* strlen */
45
#include <ctype.h>                      /* tolower */
46
#include <cyg/kernel/kapi.h>            /* All the kernel specific stuff */
47
#include <cyg/hal/hal_arch.h>           /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
48
#include <sys/time.h>
49
#include <network.h>                    /* init_all_network_interfaces() */
50
 
51
#define STACKSIZE ( 65536 )
52
 
53
extern void ecos_nx_init(CYG_ADDRWORD data);
54
extern void nanowm_thread(CYG_ADDRWORD data);
55
extern void nanox_thread(CYG_ADDRWORD data);
56
#ifdef USE_NXKBD
57
extern void nxkbd_thread(CYG_ADDRWORD data);
58
#endif
59
#ifdef USE_NXSCRIBBLE
60
extern void nxscribble_thread(CYG_ADDRWORD data);
61
#endif
62
#ifdef USE_LANDMINE
63
extern void landmine_thread(CYG_ADDRWORD data);
64
#endif
65
#ifdef USE_NTETRIS
66
extern void ntetris_thread(CYG_ADDRWORD data);
67
#endif
68
#ifdef USE_WORLD
69
extern void world_thread(CYG_ADDRWORD data);
70
#endif
71
#ifdef USE_IMG_DEMO
72
extern void img_demo_thread(CYG_ADDRWORD data);
73
#endif
74
static void startup_thread(CYG_ADDRWORD data);
75
 
76
typedef void fun(CYG_ADDRWORD);
77
struct nx_thread {
78
    char         *name;
79
    fun          *entry;
80
    int          prio;
81
    cyg_handle_t t;
82
    cyg_thread   t_obj;
83
    char         stack[STACKSIZE];
84
};
85
 
86
struct nx_thread _threads[] = {
87
    { "System startup", startup_thread,    11 },
88
    { "Nano-X server",  nanox_thread,      12 },
89
    { "Nano-WM",        nanowm_thread,     14 },
90
#ifdef USE_NXKBD
91
    { "Nano-KBD",       nxkbd_thread,      13 },
92
#endif    
93
#ifdef USE_IMG_DEMO
94
    { "Image demo",     img_demo_thread,   20 },
95
#endif
96
#ifdef USE_NXSCRIBBLE
97
    { "Scribble",       nxscribble_thread, 20 },
98
#endif
99
#ifdef USE_LANDMINE
100
    { "Landmine",       landmine_thread,   19 },
101
#endif
102
#ifdef USE_NTETRIS
103
    { "Nano-Tetris",    ntetris_thread,    18 },
104
#endif
105
#ifdef USE_WORLD
106
    { "World Map",      world_thread,      21 },
107
#endif
108
};
109
#define NUM(x) (sizeof(x)/sizeof(x[0]))
110
 
111
// Functions not provided in eCos by standard...
112
char *
113
strdup(char *string) {
114
    char *newbit = malloc(strlen(string)+1);
115
    strcpy(newbit,string);
116
    return newbit;
117
}
118
 
119
int
120
gettimeofday(struct timeval *tv,
121
             struct timezone *tz)
122
{
123
    tv->tv_usec = 0;
124
    tv->tv_sec = time(NULL);
125
    return(0);
126
}
127
 
128
int
129
strcasecmp(const char *s1, const char *s2)
130
{
131
    char c1, c2;
132
 
133
    while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
134
        if (c1 == 0)
135
            return (0);
136
    return ((unsigned char)c1 - (unsigned char)c2);
137
}
138
 
139
static void
140
startup_thread(CYG_ADDRESS data)
141
{
142
    cyg_ucount32 nanox_data_index;
143
    int i;
144
    struct nx_thread *nx;
145
 
146
    printf("SYSTEM INITIALIZATION in progress\n");
147
    printf("NETWORK:\n");
148
    init_all_network_interfaces();
149
 
150
#ifdef USE_ROMDISK
151
    {
152
        char ROM_fs[32];
153
        int res;
154
 
155
        printf("Mount ROM file system\n");
156
#ifdef CYGPKG_HAL_ARM_SA11X0_IPAQ
157
        // Work around hardware anomaly which causes major screen flicker
158
        {
159
            char *hold_rom_fs;
160
            if ((hold_rom_fs = malloc(0x80080)) != 0) {
161
                // Note: ROM fs requires 32 byte alignment
162
                hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31);
163
                memcpy(hold_rom_fs, 0x50F00000, 0x80000);
164
                sprintf(ROM_fs, "0x%08x", hold_rom_fs);
165
            } else {
166
                printf("Can't allocate memory to hold ROM fs!\n");
167
            }
168
        }
169
#else
170
        sprintf(ROM_fs, "0x%08x", 0x50F00000);
171
        sprintf(ROM_fs, "0x%08x", 0x61F00000);
172
#endif
173
        printf("ROM fs at %s\n", ROM_fs);
174
        if ((res = mount(ROM_fs, "/", "romfs")) < 0) {
175
            printf("... failed\n");
176
        }
177
        chdir("/");
178
    }
179
#endif
180
 
181
#ifdef USE_JFFS2
182
    {
183
        int res;
184
        printf("... Mounting JFFS2 on \"/\"\n");
185
        res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
186
        if (res < 0) {
187
            printf("Mount \"/\" failed - res: %d\n", res);
188
        }
189
        chdir("/");
190
    }
191
#endif
192
 
193
    // Allocate a free thread data slot
194
    // Note: all MicroWindows/NanoX threads use this slot for NanoX-private
195
    // data.  That's why there is only one call here.
196
    nanox_data_index = cyg_thread_new_data_index();
197
    printf("data index = %d\n", nanox_data_index);
198
 
199
    printf("Creating system threads\n");
200
    nx = &_threads[1];
201
    for (i = 1;  i < NUM(_threads);  i++, nx++) {
202
        cyg_thread_create(nx->prio,
203
                          nx->entry,
204
                          (cyg_addrword_t) nanox_data_index,
205
                          nx->name,
206
                          (void *)nx->stack, STACKSIZE,
207
                          &nx->t,
208
                          &nx->t_obj);
209
    }
210
 
211
    printf("Starting threads\n");
212
    nx = &_threads[1];
213
    for (i = 1;  i < NUM(_threads);  i++, nx++) {
214
        printf("Starting %s\n", nx->name);
215
        cyg_thread_resume(nx->t);
216
        // Special case - run additional code, specific to this environment
217
        // only after the server has had a chance to startup
218
        if (i == 2) {
219
            ecos_nx_init(nanox_data_index);
220
        }
221
    }
222
 
223
    printf("SYSTEM THREADS STARTED!\n");
224
}
225
 
226
void cyg_user_start(void)
227
{
228
    struct nx_thread *nx;
229
 
230
    nx = &_threads[0];
231
    cyg_thread_create(nx->prio,
232
                      nx->entry,
233
                      (cyg_addrword_t) 0,
234
                      nx->name,
235
                      (void *)nx->stack, STACKSIZE,
236
                      &nx->t,
237
                      &nx->t_obj);
238
    cyg_thread_resume(nx->t);
239
}

powered by: WebSVN 2.1.0

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