/*
|
/*
|
* Written 1999-03-19 by Jonathan Larmour, Cygnus Solutions
|
* Written 1999-03-19 by Jonathan Larmour, Cygnus Solutions
|
* Modifed for touchscreen testing by Richard Panton 13-09-00
|
* Modifed for touchscreen testing by Richard Panton 13-09-00
|
* This file is in the public domain and may be used for any purpose
|
* This file is in the public domain and may be used for any purpose
|
*/
|
*/
|
|
|
/* CONFIGURATION CHECKS */
|
/* CONFIGURATION CHECKS */
|
|
|
#include <pkgconf/system.h> /* which packages are enabled/disabled */
|
#include <pkgconf/system.h> /* which packages are enabled/disabled */
|
#ifdef CYGPKG_KERNEL
|
#ifdef CYGPKG_KERNEL
|
# include <pkgconf/kernel.h>
|
# include <pkgconf/kernel.h>
|
#endif
|
#endif
|
#ifdef CYGPKG_LIBC
|
#ifdef CYGPKG_LIBC
|
# include <pkgconf/libc.h>
|
# include <pkgconf/libc.h>
|
#endif
|
#endif
|
#ifdef CYGPKG_IO_SERIAL
|
#ifdef CYGPKG_IO_SERIAL
|
# include <pkgconf/io_serial.h>
|
# include <pkgconf/io_serial.h>
|
#endif
|
#endif
|
#ifdef CYGPKG_FS_ROM
|
#ifdef CYGPKG_FS_ROM
|
#define USE_ROMDISK
|
#define USE_ROMDISK
|
#endif
|
#endif
|
#ifdef CYGPKG_FS_JFFS2
|
#ifdef CYGPKG_FS_JFFS2
|
# include <pkgconf/io_flash.h>
|
# include <pkgconf/io_flash.h>
|
#define USE_JFFS2
|
#define USE_JFFS2
|
#undef USE_ROMDISK
|
#undef USE_ROMDISK
|
#endif
|
#endif
|
|
|
#ifndef CYGFUN_KERNEL_API_C
|
#ifndef CYGFUN_KERNEL_API_C
|
# error Kernel API must be enabled to build this application
|
# error Kernel API must be enabled to build this application
|
#endif
|
#endif
|
|
|
#ifndef CYGPKG_LIBC_STDIO
|
#ifndef CYGPKG_LIBC_STDIO
|
# error C library standard I/O must be enabled to build this application
|
# error C library standard I/O must be enabled to build this application
|
#endif
|
#endif
|
|
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG
|
# error I/O HALDIAG pseudo-device driver must be enabled to build this application
|
# error I/O HALDIAG pseudo-device driver must be enabled to build this application
|
#endif
|
#endif
|
|
|
/* INCLUDES */
|
/* INCLUDES */
|
|
|
#include <stdio.h> /* printf */
|
#include <stdio.h> /* printf */
|
#include <stdlib.h> /* printf */
|
#include <stdlib.h> /* printf */
|
#include <string.h> /* strlen */
|
#include <string.h> /* strlen */
|
#include <ctype.h> /* tolower */
|
#include <ctype.h> /* tolower */
|
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */
|
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */
|
#include <cyg/hal/hal_arch.h> /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
|
#include <cyg/hal/hal_arch.h> /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
|
#include <sys/time.h>
|
#include <sys/time.h>
|
#include <network.h> /* init_all_network_interfaces() */
|
#include <network.h> /* init_all_network_interfaces() */
|
|
|
#define STACKSIZE ( 65536 )
|
#define STACKSIZE ( 65536 )
|
|
|
extern void ecos_nx_init(CYG_ADDRWORD data);
|
extern void ecos_nx_init(CYG_ADDRWORD data);
|
extern void nanowm_thread(CYG_ADDRWORD data);
|
extern void nanowm_thread(CYG_ADDRWORD data);
|
extern void nanox_thread(CYG_ADDRWORD data);
|
extern void nanox_thread(CYG_ADDRWORD data);
|
#ifdef USE_NXKBD
|
#ifdef USE_NXKBD
|
extern void nxkbd_thread(CYG_ADDRWORD data);
|
extern void nxkbd_thread(CYG_ADDRWORD data);
|
#endif
|
#endif
|
#ifdef USE_NXSCRIBBLE
|
#ifdef USE_NXSCRIBBLE
|
extern void nxscribble_thread(CYG_ADDRWORD data);
|
extern void nxscribble_thread(CYG_ADDRWORD data);
|
#endif
|
#endif
|
#ifdef USE_LANDMINE
|
#ifdef USE_LANDMINE
|
extern void landmine_thread(CYG_ADDRWORD data);
|
extern void landmine_thread(CYG_ADDRWORD data);
|
#endif
|
#endif
|
#ifdef USE_NTETRIS
|
#ifdef USE_NTETRIS
|
extern void ntetris_thread(CYG_ADDRWORD data);
|
extern void ntetris_thread(CYG_ADDRWORD data);
|
#endif
|
#endif
|
#ifdef USE_WORLD
|
#ifdef USE_WORLD
|
extern void world_thread(CYG_ADDRWORD data);
|
extern void world_thread(CYG_ADDRWORD data);
|
#endif
|
#endif
|
#ifdef USE_IMG_DEMO
|
#ifdef USE_IMG_DEMO
|
extern void img_demo_thread(CYG_ADDRWORD data);
|
extern void img_demo_thread(CYG_ADDRWORD data);
|
#endif
|
#endif
|
static void startup_thread(CYG_ADDRWORD data);
|
static void startup_thread(CYG_ADDRWORD data);
|
|
|
typedef void fun(CYG_ADDRWORD);
|
typedef void fun(CYG_ADDRWORD);
|
struct nx_thread {
|
struct nx_thread {
|
char *name;
|
char *name;
|
fun *entry;
|
fun *entry;
|
int prio;
|
int prio;
|
cyg_handle_t t;
|
cyg_handle_t t;
|
cyg_thread t_obj;
|
cyg_thread t_obj;
|
char stack[STACKSIZE];
|
char stack[STACKSIZE];
|
};
|
};
|
|
|
struct nx_thread _threads[] = {
|
struct nx_thread _threads[] = {
|
{ "System startup", startup_thread, 11 },
|
{ "System startup", startup_thread, 11 },
|
{ "Nano-X server", nanox_thread, 12 },
|
{ "Nano-X server", nanox_thread, 12 },
|
{ "Nano-WM", nanowm_thread, 14 },
|
{ "Nano-WM", nanowm_thread, 14 },
|
#ifdef USE_NXKBD
|
#ifdef USE_NXKBD
|
{ "Nano-KBD", nxkbd_thread, 13 },
|
{ "Nano-KBD", nxkbd_thread, 13 },
|
#endif
|
#endif
|
#ifdef USE_IMG_DEMO
|
#ifdef USE_IMG_DEMO
|
{ "Image demo", img_demo_thread, 20 },
|
{ "Image demo", img_demo_thread, 20 },
|
#endif
|
#endif
|
#ifdef USE_NXSCRIBBLE
|
#ifdef USE_NXSCRIBBLE
|
{ "Scribble", nxscribble_thread, 20 },
|
{ "Scribble", nxscribble_thread, 20 },
|
#endif
|
#endif
|
#ifdef USE_LANDMINE
|
#ifdef USE_LANDMINE
|
{ "Landmine", landmine_thread, 19 },
|
{ "Landmine", landmine_thread, 19 },
|
#endif
|
#endif
|
#ifdef USE_NTETRIS
|
#ifdef USE_NTETRIS
|
{ "Nano-Tetris", ntetris_thread, 18 },
|
{ "Nano-Tetris", ntetris_thread, 18 },
|
#endif
|
#endif
|
#ifdef USE_WORLD
|
#ifdef USE_WORLD
|
{ "World Map", world_thread, 21 },
|
{ "World Map", world_thread, 21 },
|
#endif
|
#endif
|
};
|
};
|
#define NUM(x) (sizeof(x)/sizeof(x[0]))
|
#define NUM(x) (sizeof(x)/sizeof(x[0]))
|
|
|
// Functions not provided in eCos by standard...
|
// Functions not provided in eCos by standard...
|
char *
|
char *
|
strdup(char *string) {
|
strdup(char *string) {
|
char *newbit = malloc(strlen(string)+1);
|
char *newbit = malloc(strlen(string)+1);
|
strcpy(newbit,string);
|
strcpy(newbit,string);
|
return newbit;
|
return newbit;
|
}
|
}
|
|
|
int
|
int
|
gettimeofday(struct timeval *tv,
|
gettimeofday(struct timeval *tv,
|
struct timezone *tz)
|
struct timezone *tz)
|
{
|
{
|
tv->tv_usec = 0;
|
tv->tv_usec = 0;
|
tv->tv_sec = time(NULL);
|
tv->tv_sec = time(NULL);
|
return(0);
|
return(0);
|
}
|
}
|
|
|
int
|
int
|
strcasecmp(const char *s1, const char *s2)
|
strcasecmp(const char *s1, const char *s2)
|
{
|
{
|
char c1, c2;
|
char c1, c2;
|
|
|
while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
|
while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
|
if (c1 == 0)
|
if (c1 == 0)
|
return (0);
|
return (0);
|
return ((unsigned char)c1 - (unsigned char)c2);
|
return ((unsigned char)c1 - (unsigned char)c2);
|
}
|
}
|
|
|
static void
|
static void
|
startup_thread(CYG_ADDRESS data)
|
startup_thread(CYG_ADDRESS data)
|
{
|
{
|
cyg_ucount32 nanox_data_index;
|
cyg_ucount32 nanox_data_index;
|
int i;
|
int i;
|
struct nx_thread *nx;
|
struct nx_thread *nx;
|
|
|
printf("SYSTEM INITIALIZATION in progress\n");
|
printf("SYSTEM INITIALIZATION in progress\n");
|
printf("NETWORK:\n");
|
printf("NETWORK:\n");
|
init_all_network_interfaces();
|
init_all_network_interfaces();
|
|
|
#ifdef USE_ROMDISK
|
#ifdef USE_ROMDISK
|
{
|
{
|
char ROM_fs[32];
|
char ROM_fs[32];
|
int res;
|
int res;
|
|
|
printf("Mount ROM file system\n");
|
printf("Mount ROM file system\n");
|
#ifdef CYGPKG_HAL_ARM_SA11X0_IPAQ
|
#ifdef CYGPKG_HAL_ARM_SA11X0_IPAQ
|
// Work around hardware anomaly which causes major screen flicker
|
// Work around hardware anomaly which causes major screen flicker
|
{
|
{
|
char *hold_rom_fs;
|
char *hold_rom_fs;
|
if ((hold_rom_fs = malloc(0x80080)) != 0) {
|
if ((hold_rom_fs = malloc(0x80080)) != 0) {
|
// Note: ROM fs requires 32 byte alignment
|
// Note: ROM fs requires 32 byte alignment
|
hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31);
|
hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31);
|
memcpy(hold_rom_fs, 0x50F00000, 0x80000);
|
memcpy(hold_rom_fs, 0x50F00000, 0x80000);
|
sprintf(ROM_fs, "0x%08x", hold_rom_fs);
|
sprintf(ROM_fs, "0x%08x", hold_rom_fs);
|
} else {
|
} else {
|
printf("Can't allocate memory to hold ROM fs!\n");
|
printf("Can't allocate memory to hold ROM fs!\n");
|
}
|
}
|
}
|
}
|
#else
|
#else
|
sprintf(ROM_fs, "0x%08x", 0x50F00000);
|
sprintf(ROM_fs, "0x%08x", 0x50F00000);
|
sprintf(ROM_fs, "0x%08x", 0x61F00000);
|
sprintf(ROM_fs, "0x%08x", 0x61F00000);
|
#endif
|
#endif
|
printf("ROM fs at %s\n", ROM_fs);
|
printf("ROM fs at %s\n", ROM_fs);
|
if ((res = mount(ROM_fs, "/", "romfs")) < 0) {
|
if ((res = mount(ROM_fs, "/", "romfs")) < 0) {
|
printf("... failed\n");
|
printf("... failed\n");
|
}
|
}
|
chdir("/");
|
chdir("/");
|
}
|
}
|
#endif
|
#endif
|
|
|
#ifdef USE_JFFS2
|
#ifdef USE_JFFS2
|
{
|
{
|
int res;
|
int res;
|
printf("... Mounting JFFS2 on \"/\"\n");
|
printf("... Mounting JFFS2 on \"/\"\n");
|
res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
|
res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
|
if (res < 0) {
|
if (res < 0) {
|
printf("Mount \"/\" failed - res: %d\n", res);
|
printf("Mount \"/\" failed - res: %d\n", res);
|
}
|
}
|
chdir("/");
|
chdir("/");
|
}
|
}
|
#endif
|
#endif
|
|
|
// Allocate a free thread data slot
|
// Allocate a free thread data slot
|
// Note: all MicroWindows/NanoX threads use this slot for NanoX-private
|
// Note: all MicroWindows/NanoX threads use this slot for NanoX-private
|
// data. That's why there is only one call here.
|
// data. That's why there is only one call here.
|
nanox_data_index = cyg_thread_new_data_index();
|
nanox_data_index = cyg_thread_new_data_index();
|
printf("data index = %d\n", nanox_data_index);
|
printf("data index = %d\n", nanox_data_index);
|
|
|
printf("Creating system threads\n");
|
printf("Creating system threads\n");
|
nx = &_threads[1];
|
nx = &_threads[1];
|
for (i = 1; i < NUM(_threads); i++, nx++) {
|
for (i = 1; i < NUM(_threads); i++, nx++) {
|
cyg_thread_create(nx->prio,
|
cyg_thread_create(nx->prio,
|
nx->entry,
|
nx->entry,
|
(cyg_addrword_t) nanox_data_index,
|
(cyg_addrword_t) nanox_data_index,
|
nx->name,
|
nx->name,
|
(void *)nx->stack, STACKSIZE,
|
(void *)nx->stack, STACKSIZE,
|
&nx->t,
|
&nx->t,
|
&nx->t_obj);
|
&nx->t_obj);
|
}
|
}
|
|
|
printf("Starting threads\n");
|
printf("Starting threads\n");
|
nx = &_threads[1];
|
nx = &_threads[1];
|
for (i = 1; i < NUM(_threads); i++, nx++) {
|
for (i = 1; i < NUM(_threads); i++, nx++) {
|
printf("Starting %s\n", nx->name);
|
printf("Starting %s\n", nx->name);
|
cyg_thread_resume(nx->t);
|
cyg_thread_resume(nx->t);
|
// Special case - run additional code, specific to this environment
|
// Special case - run additional code, specific to this environment
|
// only after the server has had a chance to startup
|
// only after the server has had a chance to startup
|
if (i == 2) {
|
if (i == 2) {
|
ecos_nx_init(nanox_data_index);
|
ecos_nx_init(nanox_data_index);
|
}
|
}
|
}
|
}
|
|
|
printf("SYSTEM THREADS STARTED!\n");
|
printf("SYSTEM THREADS STARTED!\n");
|
}
|
}
|
|
|
void cyg_user_start(void)
|
void cyg_user_start(void)
|
{
|
{
|
struct nx_thread *nx;
|
struct nx_thread *nx;
|
|
|
nx = &_threads[0];
|
nx = &_threads[0];
|
cyg_thread_create(nx->prio,
|
cyg_thread_create(nx->prio,
|
nx->entry,
|
nx->entry,
|
(cyg_addrword_t) 0,
|
(cyg_addrword_t) 0,
|
nx->name,
|
nx->name,
|
(void *)nx->stack, STACKSIZE,
|
(void *)nx->stack, STACKSIZE,
|
&nx->t,
|
&nx->t,
|
&nx->t_obj);
|
&nx->t_obj);
|
cyg_thread_resume(nx->t);
|
cyg_thread_resume(nx->t);
|
}
|
}
|
|
|