]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/ecos/ecos_app.c
unified MX27, MX25, MX37 trees
[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 int
63 strcasecmp(const char *s1, const char *s2)
64 {
65     char c1, c2;
66
67     while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
68         if (c1 == 0)
69             return (0);
70     return ((unsigned char)c1 - (unsigned char)c2);
71 }
72
73 static void 
74 startup(CYG_ADDRESS data)
75 {
76     cyg_ucount32 nanox_data_index;
77     struct _mw_app_entry *nx;
78
79     printf("SYSTEM INITIALIZATION in progress\n");
80     printf("NETWORK:\n");
81     init_all_network_interfaces();
82
83 #ifdef USE_ROMDISK
84     {
85         char ROM_fs[32];
86         int res;
87
88         printf("Mount ROM file system\n");
89 #if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS)
90         // Work around hardware anomaly which causes major screen flicker
91         {
92             char *hold_rom_fs;
93             if ((hold_rom_fs = malloc(0x80080)) != 0) {
94                 // Note: ROM fs requires 32 byte alignment
95                 hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31);
96                 memcpy(hold_rom_fs, 0x50F00000, 0x80000);
97                 sprintf(ROM_fs, "0x%08x", hold_rom_fs);
98             } else {
99                 printf("Can't allocate memory to hold ROM fs!\n");
100             }
101         }
102 #else
103         sprintf(ROM_fs, "0x%08x", 0x50F00000);
104         sprintf(ROM_fs, "0x%08x", 0x61F00000);
105 #endif
106         printf("ROM fs at %s\n", ROM_fs);
107         if ((res = mount(ROM_fs, "/", "romfs")) < 0) {
108             printf("... failed\n");
109         }
110         chdir("/");
111     }
112 #endif
113
114 #ifdef USE_JFFS2
115     {
116         int res;
117         printf("... Mounting JFFS2 on \"/\"\n");
118         res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
119         if (res < 0) {
120             printf("Mount \"/\" failed - res: %d\n", res);
121         }
122         chdir("/");
123     }   
124 #endif
125
126     // Allocate a free thread data slot
127     // Note: all MicroWindows/NanoX threads use this slot for NanoX-private
128     // data.  That's why there is only one call here.
129     nanox_data_index = cyg_thread_new_data_index();
130     printf("data index = %d\n", nanox_data_index);
131
132     printf("Creating system threads\n");
133     for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__;  nx++) {
134         printf("Creating %s thread\n", nx->name);
135         cyg_thread_create(nx->prio,
136                           nx->entry,
137                           (cyg_addrword_t) nanox_data_index,
138                           nx->name,
139                           (void *)nx->stack, STACKSIZE,
140                           &nx->t,
141                           &nx->t_obj);
142     }
143     printf("Starting threads\n");
144     for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__;  nx++) {
145         printf("Starting %s\n", nx->name);
146         cyg_thread_resume(nx->t);
147         if (nx->init) {
148             (nx->init)(nanox_data_index);
149         }
150     }
151
152     printf("SYSTEM THREADS STARTED!\n");
153 }
154
155 void cyg_user_start(void)
156 {
157     // Create the initial thread and start it up
158     cyg_thread_create(ECOS_MW_STARTUP_PRIORITY,
159                       startup,
160                       (cyg_addrword_t) 0,
161                       "System startup",
162                       (void *)startup_stack, STACKSIZE,
163                       &startup_thread,
164                       &startup_thread_obj);
165     cyg_thread_resume(startup_thread);
166 }