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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [ecos/] [ecos_app.c] - Blame information for rev 1765

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

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

powered by: WebSVN 2.1.0

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