URL
https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk
Subversion Repositories openrisc_me
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/trunk/rtos/ecos-2.0/packages/services/gfx/mw/v2_0/src/ecos
- from Rev 27 to Rev 174
- ↔ Reverse comparison
Rev 27 → Rev 174
/world_thread.c
0,0 → 1,51
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
|
// |
// Component interfaces |
// |
|
externC int world_main(int argc, char *argv[]); |
|
int |
world_thread(CYG_ADDRWORD data) |
{ |
int argc = 1; |
char *argv[] = {"world" }; |
|
cyg_thread_delay(10*100); |
INIT_PER_THREAD_DATA(); |
world_main(argc, argv); |
} |
/landmine_thread.c
0,0 → 1,52
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
|
// |
// Component interfaces |
// |
|
externC int landmine_main(int argc, char *argv[]); |
|
int |
landmine_thread(CYG_ADDRWORD data) |
{ |
int argc = 5; |
char *argv[] = {"landmine", |
"-m", "15", |
"-s", "10"}; |
|
INIT_PER_THREAD_DATA(); |
landmine_main(argc, argv); |
} |
/ntetris_thread.c
0,0 → 1,50
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
|
// |
// Component interfaces |
// |
|
externC int ntetris_main(int argc, char *argv[]); |
|
int |
ntetris_thread(CYG_ADDRWORD data) |
{ |
int argc = 1; |
char *argv[] = {"ntetris" }; |
|
INIT_PER_THREAD_DATA(); |
ntetris_main(argc, argv); |
} |
/img_demo.c
0,0 → 1,596
#include <stdio.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <string.h> |
#include <network.h> |
#include <tftp_support.h> |
#include <dirent.h> |
#include <errno.h> |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
static int show_time = 5; |
|
// |
// Component interfaces |
// |
|
static void |
fdprintf(int fd, char *fmt, ...) |
{ |
char msg[256]; |
int ret; |
va_list ap; |
|
// Ignore if no 'fd' |
va_start(ap, fmt); |
ret = vsprintf(msg, fmt, ap); |
va_end(ap); |
diag_printf(msg); |
if (fd <= 0) return; |
write(fd, msg, strlen(msg)); |
} |
|
void |
show_jpeg(int client, char *file, int show_time) |
{ |
GR_EVENT event; /* current event */ |
GR_IMAGE_ID id = 0; |
GR_SIZE w = -1; |
GR_SIZE h = -1; |
GR_IMAGE_INFO info; |
GR_WINDOW_ID w1; /* id for large window */ |
GR_GC_ID gc1; /* graphics context for text */ |
GR_SCREEN_INFO si; |
|
int time_left; |
bool ever_exposed = false; |
|
#if !defined(HAVE_JPEG_SUPPORT) && !defined(HAVE_BMP_SUPPORT) && !defined(HAVE_GIF_SUPPORT) |
printf("Sorry, no image support compiled in\n"); |
exit(1); |
#endif |
|
GrGetScreenInfo(&si); |
printf("Loading image: %s\n", file); |
if (access(file, F_OK) < 0) { |
fdprintf(client, "Can't access \"%s\": %s\n", file, strerror(errno)); |
return; |
} |
id = GrLoadImageFromFile(file, 0); |
if (id) { |
GrGetImageInfo(id, &info); |
} else { |
// File exists, so why the error? |
int fd, len; |
char buf[64]; |
fdprintf(client, "Can't load %s\n", file); |
if ((fd = open(file, O_RDONLY)) >= 0) { |
len = read(fd, buf, 64); |
if (len != 64) { |
diag_printf("Short read? len = %d\n", len); |
} else { |
diag_dump_buf(buf, len); |
} |
close(fd); |
} else { |
diag_printf("Can't oopen \"%s\": %s\n", file, strerror(errno)); |
} |
return; |
} |
|
w = info.width; |
h = info.height; |
if ((si.rows < info.height) || (si.cols < info.width)) { |
// Preserve aspect ratio |
if (si.cols < info.width) { |
w = si.cols; |
h = (si.cols * info.height) / info.width; |
} |
if (si.rows < h) { |
w = (si.rows * w) / h; |
h = si.rows; |
} |
} |
printf("Create window - orig %dx%d => %dx%d\n", info.width, info.height, w, h); |
fdprintf(client, "<INFO> Display \"%s\" - orig %dx%d => %dx%d\n", file, info.width, info.height, w, h); |
w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, w, h, 4, BLACK, WHITE); |
GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE); |
GrMapWindow(w1); |
gc1 = GrNewGC(); |
GrSetGCForeground(gc1, WHITE); |
|
#define TO_MS 50 |
time_left = show_time * 1000; |
while (time_left > 0) { |
GrGetNextEventTimeout(&event, TO_MS); // milliseconds |
switch(event.type) { |
case GR_EVENT_TYPE_CLOSE_REQ: |
GrDestroyWindow(w1); |
GrFreeImage(id); |
return; |
/* no return*/ |
case GR_EVENT_TYPE_EXPOSURE: |
/*GrDrawImageFromFile(w1, gc1, 0, 0, w, h, argv[1],0);*/ |
GrDrawImageToFit(w1, gc1, 0, 0, w, h, id); |
ever_exposed = true; |
break; |
default: |
case GR_EVENT_TYPE_NONE: |
case GR_EVENT_TYPE_TIMEOUT: |
time_left -= TO_MS; |
if ((time_left < 0) && !ever_exposed) { |
// Things get real cranky if we delete the window too fast! |
time_left = TO_MS; |
} |
break; |
} |
} |
GrUnmapWindow(w1); |
GrDestroyWindow(w1); |
GrDestroyGC(gc1); |
GrFreeImage(id); |
} |
|
static void |
do_ls(int client, char *buf) |
{ |
int err; |
DIR *dirp; |
int num=0; |
char name[256]; |
|
buf += 2; // Skip over command |
while (*buf && (*buf == ' ')) buf++; |
if (*buf) { |
// Name provided |
strcpy(name, buf); |
} else { |
strcpy(name, "."); |
} |
|
fdprintf(client, "<INFO> reading directory %s\n",name); |
dirp = opendir( name ); |
if( dirp == NULL ) { |
fdprintf(client, "Can't open directory \"%s\"\n", name); |
return; |
} |
for(;;) { |
struct dirent *entry = readdir( dirp ); |
struct stat sbuf; |
char fullname[PATH_MAX]; |
|
if( entry == NULL ) |
break; |
num++; |
diag_printf("<INFO> entry %s",entry->d_name); |
fdprintf(client, "<INFO> entry %14s",entry->d_name); |
if( name[0] ) { |
strcpy(fullname, name ); |
if( !(name[0] == '/' && name[1] == 0 ) ) |
strcat(fullname, "/" ); |
} |
else fullname[0] = 0; |
strcat(fullname, entry->d_name ); |
err = stat( fullname, &sbuf ); |
if( err < 0 ) { |
if( errno == ENOSYS ) { |
fdprintf(client, " <no status available>"); |
} else { |
diag_printf(" - error %s\n", strerror(errno)); |
fdprintf(client, " - error %s\n", strerror(errno)); |
} |
} else { |
diag_printf(" [mode %08x ino %08x nlink %d size %d]\n", |
sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); |
fdprintf(client, " [mode %08x ino %08x nlink %d size %d]\n", |
sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); |
} |
} |
err = closedir( dirp ); |
} |
|
static void |
do_show(int client, char *buf) |
{ |
char name[256]; |
|
buf += 4; // Skip over command |
while (*buf && (*buf == ' ')) buf++; |
if (*buf) { |
// Name provided |
strcpy(name, buf); |
} else { |
fdprintf(client, "usage: show <file>\n"); |
return; |
} |
show_jpeg(client, name, show_time); |
} |
|
static void |
do_show_all(int client, char *buf) |
{ |
int err; |
DIR *dirp; |
char *c, name[256]; |
|
buf += 8; // Skip over command |
while (*buf && (*buf == ' ')) buf++; |
if (*buf) { |
// Name provided |
strcpy(name, buf); |
} else { |
strcpy(name, "."); |
} |
|
fdprintf(client, "<INFO> show .jpg files in directory %s\n",name); |
dirp = opendir( name ); |
if( dirp == NULL ) { |
fdprintf(client, "Can't open directory \"%s\"\n", name); |
return; |
} |
for(;;) { |
struct dirent *entry = readdir( dirp ); |
struct stat sbuf; |
char fullname[PATH_MAX]; |
|
if( entry == NULL ) |
break; |
if( name[0] ) { |
strcpy(fullname, name ); |
if( !(name[0] == '/' && name[1] == 0 ) ) |
strcat(fullname, "/" ); |
} |
else fullname[0] = 0; |
strcat(fullname, entry->d_name ); |
err = stat( fullname, &sbuf ); |
if( err < 0 ) { |
fdprintf(client, "<ERROR> Can't access \"%s\":", fullname); |
if( errno == ENOSYS ) { |
fdprintf(client, " <no status available>"); |
} else { |
fdprintf(client, "%s\n", strerror(errno)); |
} |
} else { |
#if 0 |
if (/* hack: !S_ISREG(sbuf.st_mode)*/ (sbuf.st_mode & 0x8000) == 0) { |
continue; |
} |
#endif |
if ((c = rindex(fullname, '.')) != (char *)NULL) { |
if (strcmp(c, ".jpg") == 0) { |
show_jpeg(client, fullname, show_time); |
} |
} |
} |
} |
err = closedir( dirp ); |
} |
|
static void |
do_time(int client, char *buf) |
{ |
char *cp; |
int val; |
|
buf += 4; // Skip over command |
while (*buf && (*buf == ' ')) buf++; |
if (*buf) { |
// value provided |
val = strtol(buf, &cp, 0); |
if (val > 0) { |
show_time = val; |
fdprintf(client, "<INFO> time set to %d seconds\n", val); |
return; |
} |
} |
fdprintf(client, "usage: time <value>\n"); |
} |
|
static void |
do_get(int client, char *buf) |
{ |
char *fn, *sn, *data; |
#ifdef CYGPKG_FS_RAM |
char _fn[PATH_MAX]; |
#endif |
int fd, len, err; |
struct sockaddr_in srvr_addr; |
|
buf += 3; // Skip over command |
fn = strtok(buf, " ,"); |
sn = strtok(NULL, " ,"); |
if ((fn == (char *)NULL) || (sn == (char *)NULL)) { |
fdprintf(client, "usage: get <file> <server>\n"); |
return; |
} |
// For now, only numeric IP addresses |
if (!inet_aton(sn, &srvr_addr.sin_addr)) { |
fdprintf(client, "Can't get host info: %s\n", sn); |
return; |
} |
srvr_addr.sin_port = 0; |
if ((data = (char *)malloc(0x100000)) == (char *)NULL) { |
fdprintf(client, "Can't allocate temp buffer\n"); |
return; |
} |
if ((len = tftp_get(fn, &srvr_addr, data, 0x100000, TFTP_OCTET, &err)) > 0) { |
fdprintf(client, "Read %d bytes\n", len); |
fd = open(fn, O_RDWR|O_CREAT); |
if (fd > 0) { |
err = write(fd, data, len); |
if (err != len) { |
fdprintf(client, "Error writing data\n"); |
} |
close(fd); |
} else { |
fdprintf(client, "Can't create \"%s\"\n", fn); |
} |
#ifdef CYGPKG_FS_RAM |
sprintf(_fn, "/%s", fn); |
fd = open(_fn, O_RDWR|O_CREAT); |
if (fd > 0) { |
err = write(fd, data, len); |
if (err != len) { |
fdprintf(client, "Error writing data\n"); |
} |
close(fd); |
} else { |
fdprintf(client, "Can't create \"%s\"\n", _fn); |
} |
#endif |
} else { |
fdprintf(client, "Error reading data\n"); |
} |
free(data); |
} |
|
static void |
do_rm(int client, char *buf) |
{ |
char *fn; |
|
buf += 2; // Skip over command |
fn = strtok(buf, " ,"); |
if (fn == (char *)NULL) { |
fdprintf(client, "usage: rm <file>\n"); |
return; |
} |
if (unlink(fn) < 0) { |
fdprintf(client, "Can't remove \"%s\": %s\n", fn, strerror(errno)); |
} |
} |
|
static void |
do_cmd(int client, char *buf) |
{ |
char *cp = buf+strlen(buf)-1; |
while ((*cp == '\n') || (*cp == '\r')) { |
*cp-- = '\0'; // Remove trailing terminators |
} |
printf("Command: %s\n", buf); |
if (strncmp(buf, "ls", 2) == 0) { |
do_ls(client, buf); |
} else |
if (strncmp(buf, "show_all", 8) == 0) { |
do_show_all(client, buf); |
} else |
if (strncmp(buf, "show", 4) == 0) { |
do_show(client, buf); |
} else |
if (strncmp(buf, "time", 4) == 0) { |
do_time(client, buf); |
} else |
if (strncmp(buf, "get", 3) == 0) { |
do_get(client, buf); |
} else |
if (strncmp(buf, "rm", 2) == 0) { |
do_rm(client, buf); |
} else |
{ |
fdprintf(client, "Unknown command: %s\n", buf); |
} |
} |
|
static void |
do_copy_file(char *src, char *dst) |
{ |
int err, srcfd, dstfd, len; |
char *buf; |
|
#define COPY_SIZE 0x1000 |
if ((srcfd = open(src, O_RDONLY)) >= 0) { |
if ((dstfd = open(dst, O_RDWR|O_CREAT)) >= 0) { |
if ((buf = (char *)malloc(COPY_SIZE)) != (char *)NULL) { |
while ((len = read(srcfd, buf, COPY_SIZE)) > 0) { |
write(dstfd, buf, len); |
} |
free(buf); |
} else { |
diag_printf("Can't allocate working buffer\n"); |
} |
close(srcfd); |
close(dstfd); |
} else { |
diag_printf("Can't create \"%s\": %s\n", dst, strerror(errno)); |
close(srcfd); |
} |
} else { |
diag_printf("Can't open \"%s\": %s\n", src, strerror(errno)); |
} |
} |
|
static void |
do_copy_all(char *src, char *dst) |
{ |
int err; |
DIR *dirp; |
char *c, *buf; |
|
diag_printf("Copy all files from %s to %s\n", src, dst); |
dirp = opendir(src); |
if(dirp == NULL) { |
diag_printf("Can't open directory \"%s\"\n", src); |
return; |
} |
for(;;) { |
struct dirent *entry = readdir( dirp ); |
char srcname[PATH_MAX]; |
char dstname[PATH_MAX]; |
|
if( entry == NULL ) |
break; |
strcpy(srcname, src); |
strcpy(dstname, dst); |
if( !(src[0] == '/' && src[1] == 0 ) ) |
strcat(srcname, "/" ); |
if( !(dst[0] == '/' && dst[1] == 0 ) ) |
strcat(dstname, "/" ); |
strcat(srcname, entry->d_name ); |
strcat(dstname, entry->d_name ); |
if ((c = rindex(srcname, '.')) != (char *)NULL) { |
if (strcmp(c, ".jpg") == 0) { |
diag_printf("Copy %s => %s\n", srcname, dstname); |
do_copy_file(srcname, dstname); |
} |
} |
} |
closedir(dirp); |
} |
|
static void |
pexit(char *why) |
{ |
printf("Image demo thread exiting - %s\n", why); |
GrClose(); |
cyg_thread_exit(); |
} |
|
int |
img_demo_thread(CYG_ADDRWORD data) |
{ |
int err, s, client, client_len; |
struct sockaddr client_addr; |
struct sockaddr_in my_addr; |
struct addrinfo *ai, *addrs, hints; |
char buf[256], addr_buf[256]; |
int one = 1; |
fd_set in_fds, src_fds; |
int num, len; |
struct timeval tv; |
|
INIT_PER_THREAD_DATA(); |
|
printf("Image demo here\n"); |
#ifdef CYGPKG_FS_RAM |
// Stage files from JFFS2 image into RAM |
err = mount("", "/ramfs", "ramfs"); |
if (err >= 0) { |
do_copy_all("/", "/ramfs"); |
} else { |
pexit("Can't mount RAMfs\n"); |
} |
chdir("/ramfs"); |
#endif |
if(GrOpen() < 0) { |
fprintf(stderr, "Couldn't connect to Nano-X server\n"); |
exit(1); |
} |
// Set up as a generic server, listening on TCP/7734 |
#if 0 |
bzero(&hints, sizeof(hints)); |
hints.ai_family = PF_UNSPEC;b |
hints.ai_socktype = SOCK_STREAM; |
hints.ai_flags = AI_PASSIVE; |
if ((err = getaddrinfo(NULL, "7734", &hints, &addrs)) != EAI_NONE) { |
diag_printf("can't getaddrinfo(): %s\n", gai_strerror(err)); |
pexit("getaddrinfo"); |
} |
s = socket(ai->ai_family, ai->ai_socktype, 0); |
if (s < 0) { |
pexit("stream socket"); |
} |
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { |
pexit("setsockopt SO_REUSEADDR"); |
} |
if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) { |
pexit("setsockopt SO_REUSEPORT"); |
} |
if(bind(s, ai->ai_addr, ai->ai_addr->sa_len) < 0) { |
pexit("bind error"); |
} |
listen(s, SOMAXCONN); |
#else |
s = socket(AF_INET, SOCK_STREAM, 0); |
if (s < 0) { |
pexit("stream socket"); |
} |
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { |
pexit("setsockopt SO_REUSEADDR"); |
} |
if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) { |
pexit("setsockopt SO_REUSEPORT"); |
} |
memset(&my_addr, 0, sizeof(my_addr)); |
my_addr.sin_family = AF_INET; |
my_addr.sin_len = sizeof(my_addr); |
my_addr.sin_port = htons(7734); |
my_addr.sin_addr.s_addr = INADDR_ANY; |
if(bind(s, (struct sockaddr *) &my_addr, sizeof(my_addr)) < 0) { |
pexit("bind error"); |
} |
listen(s, SOMAXCONN); |
#endif |
while (true) { |
// Wait for a connection |
FD_ZERO(&src_fds); |
FD_SET(s, &src_fds); |
tv.tv_sec = 15; |
tv.tv_usec = 0; |
num = select(s+1, &src_fds, 0, 0, &tv); |
if (num > 0) { |
client_len = sizeof(client_addr); |
if ((client = accept(s, (struct sockaddr *)&client_addr, &client_len)) < 0) { |
pexit("accept"); |
} |
client_len = sizeof(client_addr); |
getpeername(client, &client_addr, &client_len); |
_inet_ntop(&client_addr, addr_buf, sizeof(addr_buf)); |
diag_printf("connection from %s(%d)\n", addr_buf, ntohs(_inet_port(&client_addr))); |
fdprintf(client, "Hello %s(%d)\n", addr_buf, ntohs(_inet_port(&client_addr))); |
while (true) { |
fdprintf(client, "// Ready\n"); |
tv.tv_sec = 5; |
tv.tv_usec = 0; |
FD_ZERO(&in_fds); |
FD_SET(client, &in_fds); |
num = select(client+1, &in_fds, 0, 0, &tv); |
if (num > 0) { |
len = read(client, buf, sizeof(buf)-1); |
if (len <= 0) { |
diag_printf("Client read error: %s\n", strerror(errno)); |
break; |
} |
buf[len-1] = '\0'; |
do_cmd(client, buf); |
} else if (num == 0) { |
fdprintf(client, "<IDLE> show_all\n"); |
do_show_all(client, "show_all ."); |
} else { |
perror("select"); |
} |
} |
close(client); |
diag_printf("Connection with %s closed\n", addr_buf); |
} else if (num == 0) { |
// No connection within 15 seconds |
do_show_all(0, "show_all ."); |
} else { |
diag_printf("select returned: %d\n", num); |
pexit("bad select"); |
} |
} |
} |
/nxscribble_thread.c
0,0 → 1,50
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
|
// |
// Component interfaces |
// |
|
externC int nxscribble_main(int argc, char *argv[]); |
|
int |
nxscribble_thread(CYG_ADDRWORD data) |
{ |
int argc = 2; |
char *argv[] = {"nxscribble", "-t"}; |
|
INIT_PER_THREAD_DATA(); |
nxscribble_main(argc, argv); |
} |
/retain.awk
0,0 → 1,2
{print "-L ",$3;} |
|
/nanowm_thread.c
0,0 → 1,50
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
|
// |
// Component interfaces |
// |
|
externC int nanowm_main(int argc, char *argv[]); |
|
int |
nanowm_thread(CYG_ADDRWORD data) |
{ |
int argc = 0; |
char **argv; |
|
INIT_PER_THREAD_DATA(); |
nanowm_main(argc, argv); |
} |
/ecos_app.c
0,0 → 1,239
/* |
* Written 1999-03-19 by Jonathan Larmour, Cygnus Solutions |
* Modifed for touchscreen testing by Richard Panton 13-09-00 |
* This file is in the public domain and may be used for any purpose |
*/ |
|
/* CONFIGURATION CHECKS */ |
|
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
#ifdef CYGPKG_FS_ROM |
#define USE_ROMDISK |
#endif |
#ifdef CYGPKG_FS_JFFS2 |
# include <pkgconf/io_flash.h> |
#define USE_JFFS2 |
#undef USE_ROMDISK |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <ctype.h> /* tolower */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/hal/hal_arch.h> /* CYGNUM_HAL_STACK_SIZE_TYPICAL */ |
#include <sys/time.h> |
#include <network.h> /* init_all_network_interfaces() */ |
|
#define STACKSIZE ( 65536 ) |
|
extern void ecos_nx_init(CYG_ADDRWORD data); |
extern void nanowm_thread(CYG_ADDRWORD data); |
extern void nanox_thread(CYG_ADDRWORD data); |
#ifdef USE_NXKBD |
extern void nxkbd_thread(CYG_ADDRWORD data); |
#endif |
#ifdef USE_NXSCRIBBLE |
extern void nxscribble_thread(CYG_ADDRWORD data); |
#endif |
#ifdef USE_LANDMINE |
extern void landmine_thread(CYG_ADDRWORD data); |
#endif |
#ifdef USE_NTETRIS |
extern void ntetris_thread(CYG_ADDRWORD data); |
#endif |
#ifdef USE_WORLD |
extern void world_thread(CYG_ADDRWORD data); |
#endif |
#ifdef USE_IMG_DEMO |
extern void img_demo_thread(CYG_ADDRWORD data); |
#endif |
static void startup_thread(CYG_ADDRWORD data); |
|
typedef void fun(CYG_ADDRWORD); |
struct nx_thread { |
char *name; |
fun *entry; |
int prio; |
cyg_handle_t t; |
cyg_thread t_obj; |
char stack[STACKSIZE]; |
}; |
|
struct nx_thread _threads[] = { |
{ "System startup", startup_thread, 11 }, |
{ "Nano-X server", nanox_thread, 12 }, |
{ "Nano-WM", nanowm_thread, 14 }, |
#ifdef USE_NXKBD |
{ "Nano-KBD", nxkbd_thread, 13 }, |
#endif |
#ifdef USE_IMG_DEMO |
{ "Image demo", img_demo_thread, 20 }, |
#endif |
#ifdef USE_NXSCRIBBLE |
{ "Scribble", nxscribble_thread, 20 }, |
#endif |
#ifdef USE_LANDMINE |
{ "Landmine", landmine_thread, 19 }, |
#endif |
#ifdef USE_NTETRIS |
{ "Nano-Tetris", ntetris_thread, 18 }, |
#endif |
#ifdef USE_WORLD |
{ "World Map", world_thread, 21 }, |
#endif |
}; |
#define NUM(x) (sizeof(x)/sizeof(x[0])) |
|
// Functions not provided in eCos by standard... |
char * |
strdup(char *string) { |
char *newbit = malloc(strlen(string)+1); |
strcpy(newbit,string); |
return newbit; |
} |
|
int |
gettimeofday(struct timeval *tv, |
struct timezone *tz) |
{ |
tv->tv_usec = 0; |
tv->tv_sec = time(NULL); |
return(0); |
} |
|
int |
strcasecmp(const char *s1, const char *s2) |
{ |
char c1, c2; |
|
while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++))) |
if (c1 == 0) |
return (0); |
return ((unsigned char)c1 - (unsigned char)c2); |
} |
|
static void |
startup_thread(CYG_ADDRESS data) |
{ |
cyg_ucount32 nanox_data_index; |
int i; |
struct nx_thread *nx; |
|
printf("SYSTEM INITIALIZATION in progress\n"); |
printf("NETWORK:\n"); |
init_all_network_interfaces(); |
|
#ifdef USE_ROMDISK |
{ |
char ROM_fs[32]; |
int res; |
|
printf("Mount ROM file system\n"); |
#ifdef CYGPKG_HAL_ARM_SA11X0_IPAQ |
// Work around hardware anomaly which causes major screen flicker |
{ |
char *hold_rom_fs; |
if ((hold_rom_fs = malloc(0x80080)) != 0) { |
// Note: ROM fs requires 32 byte alignment |
hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31); |
memcpy(hold_rom_fs, 0x50F00000, 0x80000); |
sprintf(ROM_fs, "0x%08x", hold_rom_fs); |
} else { |
printf("Can't allocate memory to hold ROM fs!\n"); |
} |
} |
#else |
sprintf(ROM_fs, "0x%08x", 0x50F00000); |
sprintf(ROM_fs, "0x%08x", 0x61F00000); |
#endif |
printf("ROM fs at %s\n", ROM_fs); |
if ((res = mount(ROM_fs, "/", "romfs")) < 0) { |
printf("... failed\n"); |
} |
chdir("/"); |
} |
#endif |
|
#ifdef USE_JFFS2 |
{ |
int res; |
printf("... Mounting JFFS2 on \"/\"\n"); |
res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" ); |
if (res < 0) { |
printf("Mount \"/\" failed - res: %d\n", res); |
} |
chdir("/"); |
} |
#endif |
|
// Allocate a free thread data slot |
// Note: all MicroWindows/NanoX threads use this slot for NanoX-private |
// data. That's why there is only one call here. |
nanox_data_index = cyg_thread_new_data_index(); |
printf("data index = %d\n", nanox_data_index); |
|
printf("Creating system threads\n"); |
nx = &_threads[1]; |
for (i = 1; i < NUM(_threads); i++, nx++) { |
cyg_thread_create(nx->prio, |
nx->entry, |
(cyg_addrword_t) nanox_data_index, |
nx->name, |
(void *)nx->stack, STACKSIZE, |
&nx->t, |
&nx->t_obj); |
} |
|
printf("Starting threads\n"); |
nx = &_threads[1]; |
for (i = 1; i < NUM(_threads); i++, nx++) { |
printf("Starting %s\n", nx->name); |
cyg_thread_resume(nx->t); |
// Special case - run additional code, specific to this environment |
// only after the server has had a chance to startup |
if (i == 2) { |
ecos_nx_init(nanox_data_index); |
} |
} |
|
printf("SYSTEM THREADS STARTED!\n"); |
} |
|
void cyg_user_start(void) |
{ |
struct nx_thread *nx; |
|
nx = &_threads[0]; |
cyg_thread_create(nx->prio, |
nx->entry, |
(cyg_addrword_t) 0, |
nx->name, |
(void *)nx->stack, STACKSIZE, |
&nx->t, |
&nx->t_obj); |
cyg_thread_resume(nx->t); |
} |
/nanox_thread.c
0,0 → 1,49
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
|
// |
// Component interfaces |
// |
|
externC int nanox_main(int argc, char *argv[]); |
|
int |
nanox_thread(CYG_ADDRWORD data) |
{ |
int argc = 0; |
char **argv; |
|
nanox_main(argc, argv); |
} |
/ecos_init.c
0,0 → 1,209
// |
// Micro-Windows/Nano-X additional setup fo eCos |
// |
|
#include <pkgconf/system.h> |
#include <pkgconf/kernel.h> |
#include <pkgconf/hal.h> |
#include <cyg/kernel/kapi.h> |
#include <cyg/infra/diag.h> |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <fcntl.h> |
#include <unistd.h> |
#include <time.h> |
#include <ctype.h> |
#include <errno.h> |
#include <sys/time.h> |
#include <sys/stat.h> |
|
#define MWINCLUDECOLORS |
#include <microwin/nano-X.h> |
#if 0 |
#include <nwidgets.h> |
#endif |
|
#if 0 |
static bool closed = false; |
|
static void |
do_close(NBUTTON * w, int b) |
{ |
printf("Button %d was clicked in widget %p\n",b,w); |
closed = true; |
} |
#endif |
|
// Display a number of ticks as microseconds |
// Note: for improved calculation significance, values are kept in ticks*1000 |
static void |
show_ns(long long ns) |
{ |
diag_printf("%5d.%02d", (int)(ns/1000), (int)((ns%1000)/10)); |
} |
|
static long rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION; |
static long ns_per_system_clock; |
|
static long long |
ns_time(void) |
{ |
cyg_uint32 off; |
long long ns, clocks; |
|
ns_per_system_clock = 1000000/rtc_resolution[1]; |
HAL_CLOCK_READ(&off); |
ns = (ns_per_system_clock * (long long)off) / CYGNUM_KERNEL_COUNTERS_RTC_PERIOD; |
ns += 5; // for rounding to .01us |
clocks = (cyg_current_time() * 10000000) + ns; |
return clocks; |
} |
|
static void |
test_file_io(void) |
{ |
long long start_time, end_time; |
FILE *fp; |
unsigned char buf[256]; |
int len, n, fd; |
|
start_time = ns_time(); |
len = 0; |
if ((fp = fopen("/redhat.logo", "r")) != (FILE *)NULL) { |
while (fgets(buf, sizeof(buf), fp)) { |
len += strlen(buf); |
} |
fclose(fp); |
} |
end_time = ns_time(); |
diag_printf("'fgets': %d bytes in ", len); show_ns(end_time-start_time); diag_printf("ns\n"); |
|
start_time = ns_time(); |
len = 0; |
if ((fp = fopen("/redhat.logo", "r")) != (FILE *)NULL) { |
while ((n = fread(buf, 1, sizeof(buf), fp))) { |
len += n; |
} |
fclose(fp); |
} |
end_time = ns_time(); |
diag_printf("'fread': %d bytes in ", len); show_ns(end_time-start_time); diag_printf("ns\n"); |
|
start_time = ns_time(); |
len = 0; |
if ((fd = open("/redhat.logo", O_RDONLY)) >= 0) { |
while ((n = read(fd, buf, sizeof(buf)))) { |
len += n; |
} |
close(fd); |
} |
end_time = ns_time(); |
diag_printf("'read': %d bytes in ", len); show_ns(end_time-start_time); diag_printf("ns\n"); |
} |
|
void |
ecos_nx_init(CYG_ADDRWORD data) |
{ |
GR_SCREEN_INFO si; /* window information */ |
GR_FONT_INFO fi; /* font information */ |
GR_WINDOW_ID mainwid; /* main window id */ |
GR_WM_PROPERTIES props; |
GR_GC_ID gct = 0; |
#if 0 |
NWIDGET *w; |
NBUTTON *b; |
NTEXTFIELD *t; |
#endif |
|
cyg_thread_delay(50); |
INIT_PER_THREAD_DATA(); |
|
test_file_io(); |
|
if(GrOpen() < 0) { |
fprintf(stderr, "Couldn't connect to Nano-X server\n"); |
exit(1); |
} |
|
#ifdef CYGPKG_HAL_ARM_SA11X0_IPAQ |
GrSetPortraitMode(MWPORTRAIT_RIGHT); |
#endif |
|
GrGetScreenInfo(&si); |
GrGetFontInfo(0, &fi); |
|
#if 1 |
mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, si.cols, si.rows, |
0, RED, WHITE); |
|
props.flags = GR_WM_FLAGS_PROPS; |
props.props = GR_WM_PROPS_BORDER; |
GrSetWMProperties(mainwid, &props); |
|
GrMapWindow(mainwid); |
GrFlush(); |
cyg_thread_delay(50); |
|
gct = GrNewGC(); |
GrSetGCForeground(gct, WHITE); |
|
#ifdef CYGPKG_IO_FILEIO |
{ |
struct stat stat_data; |
if (0 == stat("/redhat.logo", &stat_data)) { |
GrDrawImageFromFile(mainwid, gct, 0, 0, si.cols, si.rows, "/redhat.logo", 0); |
} |
} |
#endif |
|
#ifdef CYGPKG_HAL_ARM |
// Touch sensitive screen calibration, only relevant on some |
// platforms. |
GrSetGCFont(gct, GrCreateFont(GR_FONT_GUI_VAR, 0, NULL)); |
GrText(mainwid, gct, 80, 350, "Tap all 4 corners", 17, GR_TFTOP); |
GrFlush(); |
printf("Tap all four corners\n"); |
cyg_thread_delay(10*100); |
#endif |
|
#else |
n_init_button_class(); |
n_init_textfield_class(); |
|
w = NEW_NOBJECT(widget); |
n_widget_init(w, 0); |
n_widget_resize(w, si.cols - 10, si.rows - 30); |
n_widget_background(w, "/redhat.logo"); |
n_widget_show(w); |
|
b = NEW_NOBJECT(button); |
n_button_init(b, w, "Close"); |
n_button_onclick(b, do_close); |
n_widget_resize(b, 40, 20); |
n_widget_move(b,180,260); |
n_widget_show(b); |
|
t = NEW_NOBJECT(textfield); |
n_textfield_init(t,w,"Tap all 4 corners"); |
n_widget_move(t,45,220); |
n_widget_resize(t,120,20); |
n_widget_show(t); |
|
t = NEW_NOBJECT(textfield); |
n_textfield_init(t,w,"Then press close"); |
n_widget_move(t,45,250); |
n_widget_resize(t,120,20); |
n_widget_show(t); |
|
while (!closed) { |
n_handle_event(); |
} |
|
n_widget_hide(w); |
n_object_cleanup(w); |
|
#endif |
|
GrClose(); |
} |
/Makefile
0,0 → 1,73
############################################################################## |
# Microwindows template Makefile |
# Copyright (c) 2000, 2002 Martin Jolicoeur, Greg Haerr |
############################################################################## |
|
include $(CONFIG) |
|
VPATH := $(TOP)/ecos |
|
######################## Additional Flags section ############################ |
|
# Directories list for header files |
INCLUDEDIRS += |
# Defines for preprocessor |
DEFINES += |
|
# Compilation flags for C files OTHER than include directories |
CFLAGS += |
# Preprocessor flags OTHER than defines |
CPPFLAGS += |
# Linking flags |
LDFLAGS += -Wl,--gc-sections -Wl,-static -g -O2 -nostdlib -L$(ECOS_PREFIX)/lib -Ttarget.ld |
|
############################# targets section ################################ |
|
# If you want to create a library with the objects files, define the name here |
LIBNAME = |
LIBNAMESO = |
|
# List of objects to compile |
OBJS = ecos_app.o ecos_init.o |
NANO_OBJS = |
#DEFINES += -DUSE_ROMDISK |
OBJS += nanox_thread.o |
#NANO_OBJS += $(BUILD)/bin/nano-X.o $(BUILD)/bin/nwidgets.o |
NANO_OBJS += $(BUILD)/bin/nano-X.o |
OBJS += nanowm_thread.o |
NANO_OBJS += $(BUILD)/bin/nanowm.o |
OBJS += nxkbd_thread.o |
NANO_OBJS += $(BUILD)/bin/nxkbd.o |
ifeq ($(DEMO), Y) |
DEFINES += -DUSE_NXSCRIBBLE |
OBJS += nxscribble_thread.o |
NANO_OBJS += $(BUILD)/bin/nxscribble.o |
DEFINES += -DUSE_LANDMINE |
OBJS += landmine_thread.o |
NANO_OBJS += $(BUILD)/bin/landmine.o |
DEFINES += -DUSE_NTETRIS |
OBJS += ntetris_thread.o |
NANO_OBJS += $(BUILD)/bin/ntetris.o |
DEFINES += -DUSE_WORLD |
OBJS += world_thread.o |
NANO_OBJS += $(BUILD)/bin/world.o |
endif |
ifeq ($(AGDEMO), Y) |
DEFINES += -DUSE_IMG_DEMO |
OBJS += img_demo.o |
endif |
|
# demos should be built after the libs ! |
all: ecos_app |
|
######################### Makefile.rules section ############################# |
|
include $(TOP)/Makefile.rules |
|
######################## Tools targets section ############################### |
|
ecos_app: $(OBJS) $(NANO_OBJS) |
|
ecos_app.o: Makefile |
|
|
/nxkbd_thread.c
0,0 → 1,50
#include <pkgconf/system.h> /* which packages are enabled/disabled */ |
#ifdef CYGPKG_KERNEL |
# include <pkgconf/kernel.h> |
#endif |
#ifdef CYGPKG_LIBC |
# include <pkgconf/libc.h> |
#endif |
#ifdef CYGPKG_IO_SERIAL |
# include <pkgconf/io_serial.h> |
#endif |
|
#ifndef CYGFUN_KERNEL_API_C |
# error Kernel API must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_LIBC_STDIO |
# error C library standard I/O must be enabled to build this application |
#endif |
|
#ifndef CYGPKG_IO_SERIAL_HALDIAG |
# error I/O HALDIAG pseudo-device driver must be enabled to build this application |
#endif |
|
/* INCLUDES */ |
|
#include <stdio.h> /* printf */ |
#include <stdlib.h> /* printf */ |
#include <string.h> /* strlen */ |
#include <cyg/kernel/kapi.h> /* All the kernel specific stuff */ |
#include <cyg/infra/diag.h> |
|
#define MWINCLUDECOLORS |
#include "nano-X.h" |
|
|
// |
// Component interfaces |
// |
|
externC int nxkbd_main(int argc, char *argv[]); |
|
int |
nxkbd_thread(CYG_ADDRWORD data) |
{ |
int argc = 0; |
char **argv; |
|
INIT_PER_THREAD_DATA(); |
nxkbd_main(argc, argv); |
} |