]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/ecos/ecos_app.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / ecos / ecos_app.c
1 /* 
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 #include <pkgconf/microwindows.h>
28
29 #ifndef CYGFUN_KERNEL_API_C
30 # error Kernel API must be enabled to build this application
31 #endif
32
33 #ifndef CYGPKG_LIBC_STDIO
34 # error C library standard I/O must be enabled to build this application
35 #endif
36
37 #ifndef CYGPKG_IO_SERIAL_HALDIAG
38 # error I/O HALDIAG pseudo-device driver must be enabled to build this application
39 #endif
40
41 /* INCLUDES */
42
43 #include <stdio.h>                      /* printf */
44 #include <stdlib.h>                      /* printf */
45 #include <string.h>                     /* strlen */
46 #include <ctype.h>                      /* tolower */
47 #include <cyg/kernel/kapi.h>            /* All the kernel specific stuff */
48 #include <cyg/hal/hal_arch.h>           /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
49 #include <sys/time.h>
50 #include <network.h>                    /* init_all_network_interfaces() */
51 #include <microwin/ecos_mw_app.h>
52
53 // Define table boundaries
54 CYG_HAL_TABLE_BEGIN( __MW_APP_TAB__, _mw_apps );
55 CYG_HAL_TABLE_END( __MW_APP_TAB_END__, _mw_apps );
56 extern struct _mw_app_entry __MW_APP_TAB__[], __MW_APP_TAB_END__;
57
58 static char startup_stack[STACKSIZE];
59 cyg_handle_t startup_thread;
60 cyg_thread   startup_thread_obj;
61
62
63 int 
64 gettimeofday(struct timeval *tv,
65              struct timezone *tz)
66 {
67     tv->tv_usec = 0;
68     tv->tv_sec = time(NULL);
69     return(0);
70 }
71
72 int
73 strcasecmp(const char *s1, const char *s2)
74 {
75     char c1, c2;
76
77     while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
78         if (c1 == 0)
79             return (0);
80     return ((unsigned char)c1 - (unsigned char)c2);
81 }
82
83 static void 
84 startup(CYG_ADDRESS data)
85 {
86     cyg_ucount32 nanox_data_index;
87     struct _mw_app_entry *nx;
88
89     printf("SYSTEM INITIALIZATION in progress\n");
90     printf("NETWORK:\n");
91     init_all_network_interfaces();
92
93 #ifdef USE_ROMDISK
94     {
95         char ROM_fs[32];
96         int res;
97
98         printf("Mount ROM file system\n");
99 #if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS)
100         // Work around hardware anomaly which causes major screen flicker
101         {
102             char *hold_rom_fs;
103             if ((hold_rom_fs = malloc(0x80080)) != 0) {
104                 // Note: ROM fs requires 32 byte alignment
105                 hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31);
106                 memcpy(hold_rom_fs, 0x50F00000, 0x80000);
107                 sprintf(ROM_fs, "0x%08x", hold_rom_fs);
108             } else {
109                 printf("Can't allocate memory to hold ROM fs!\n");
110             }
111         }
112 #else
113         sprintf(ROM_fs, "0x%08x", 0x50F00000);
114         sprintf(ROM_fs, "0x%08x", 0x61F00000);
115 #endif
116         printf("ROM fs at %s\n", ROM_fs);
117         if ((res = mount(ROM_fs, "/", "romfs")) < 0) {
118             printf("... failed\n");
119         }
120         chdir("/");
121     }
122 #endif
123
124 #ifdef USE_JFFS2
125     {
126         int res;
127         printf("... Mounting JFFS2 on \"/\"\n");
128         res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
129         if (res < 0) {
130             printf("Mount \"/\" failed - res: %d\n", res);
131         }
132         chdir("/");
133     }   
134 #endif
135
136     // Allocate a free thread data slot
137     // Note: all MicroWindows/NanoX threads use this slot for NanoX-private
138     // data.  That's why there is only one call here.
139     nanox_data_index = cyg_thread_new_data_index();
140     printf("data index = %d\n", nanox_data_index);
141
142     printf("Creating system threads\n");
143     for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__;  nx++) {
144         printf("Creating %s thread\n", nx->name);
145         cyg_thread_create(nx->prio,
146                           nx->entry,
147                           (cyg_addrword_t) nanox_data_index,
148                           nx->name,
149                           (void *)nx->stack, STACKSIZE,
150                           &nx->t,
151                           &nx->t_obj);
152     }
153     printf("Starting threads\n");
154     for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__;  nx++) {
155         printf("Starting %s\n", nx->name);
156         cyg_thread_resume(nx->t);
157         if (nx->init) {
158             (nx->init)(nanox_data_index);
159         }
160     }
161
162     printf("SYSTEM THREADS STARTED!\n");
163 }
164
165 void cyg_user_start(void)
166 {
167     // Create the initial thread and start it up
168     cyg_thread_create(ECOS_MW_STARTUP_PRIORITY,
169                       startup,
170                       (cyg_addrword_t) 0,
171                       "System startup",
172                       (void *)startup_stack, STACKSIZE,
173                       &startup_thread,
174                       &startup_thread_obj);
175     cyg_thread_resume(startup_thread);
176 }