integrating NXFLAT

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1962 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-06-26 17:46:51 +00:00
parent f98ca3f781
commit a1c828c484
5 changed files with 60 additions and 28 deletions

View File

@ -39,6 +39,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <pthread.h> #include <pthread.h>
/**************************************************************************** /****************************************************************************
@ -49,23 +50,29 @@ static pthread_mutex_t mut;
static volatile int my_mutex = 0; static volatile int my_mutex = 0;
static unsigned long nloops[2] = {0, 0}; static unsigned long nloops[2] = {0, 0};
static unsigned long nerrors[2] = {0, 0}; static unsigned long nerrors[2] = {0, 0};
static volatile boolean bendoftest;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/* NOTE: it is necessary for functions that are referred to by function pointers /* NOTE: it is necessary for functions that are referred to by function pointers
* pointer to be declared with global scope (at least for ARM). Otherwise, * pointer to be declared with global scope (at least for ARM). Otherwise,
* a relocation type that is not supported by NXFLAT is generated by GCC. * a relocation type that is not supported by NXFLAT is generated by GCC.
*/ */
void thread_func(void *parameter) void thread_func(void *parameter)
{ {
int my_id = (int)parameter; int my_id = (int)parameter;
int my_ndx = my_id - 1; int my_ndx = my_id - 1;
volatile int i; int i;
for (;;) /* Loop 20 times. There is a 100 MS delay in the loop so this should
* take about 2 seconds. The main thread will stop this thread after
* 2 seconds by setting bendoftest in any event.
*/
for (i = 0; i < 20 && !bendoftest; i++);
{ {
if ((pthread_mutex_lock(&mut)) != 0) if ((pthread_mutex_lock(&mut)) != 0)
{ {
@ -80,8 +87,8 @@ void thread_func(void *parameter)
nerrors[my_ndx]++; nerrors[my_ndx]++;
} }
my_mutex = 1; my_mutex = 1;
for (i = 0; i < 1000; i++); usleep(100000);
my_mutex = 0; my_mutex = 0;
if ((pthread_mutex_unlock(&mut)) != 0) if ((pthread_mutex_unlock(&mut)) != 0)
@ -99,9 +106,8 @@ void thread_func(void *parameter)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
pthread_t thread1, thread2; pthread_t thread1;
pthread_t thread2;
printf("Starting threads\n");
/* Initialize the mutex */ /* Initialize the mutex */
@ -109,20 +115,34 @@ int main(int argc, char **argv)
/* Start two thread instances */ /* Start two thread instances */
if ((pthread_create(&thread1, NULL, (void*)&thread_func, (void*)1)) != 0) printf("Starting thread 1\n");
bendoftest = FALSE;
if ((pthread_create(&thread1, NULL, (void*)thread_func, (void*)1)) != 0)
{ {
fprintf(stderr, "Error in thread#1 creation\n"); fprintf(stderr, "Error in thread#1 creation\n");
} }
if ((pthread_create(&thread2, NULL, (void*)&thread_func, (void*)2)) != 0) printf("Starting thread 2\n");
if ((pthread_create(&thread2, NULL, (void*)thread_func, (void*)2)) != 0)
{ {
fprintf(stderr, "Error in thread#2 creation\n"); fprintf(stderr, "Error in thread#2 creation\n");
} }
printf("Press control-C to terminate the example\n"); /* Wait a bit for the threads to do their thing. */
sleep(2);
/* Then ask them politely to stop running */
printf("Stopping threads\n");
bendoftest = TRUE;
pthread_join(thread1, NULL); pthread_join(thread1, NULL);
pthread_join(thread2, NULL); pthread_join(thread2, NULL);
printf("\tThread1\tThread2\n");
printf("Loops\t%ld\t%ld\n", nloops[0], nloops[1]);
printf("Errors\t%ld\t%ld\n", nerrors[0], nerrors[1]);
return 0; return 0;
} }

View File

@ -76,7 +76,7 @@ enum exit_values_e
****************************************************************************/ ****************************************************************************/
/* NOTE: it is necessary for functions that are referred to by function pointers /* NOTE: it is necessary for functions that are referred to by function pointers
* pointer to be declared with global scope (at least for ARM). Otherwise, * pointer to be declared with global scope (at least for ARM). Otherwise,
* a relocation type that is not supported by NXFLAT is generated by GCC. * a relocation type that is not supported by NXFLAT is generated by GCC.
*/ */

View File

@ -54,12 +54,16 @@ static char child_name[] = "child";
static char child_arg[] = "Hello from your parent!"; static char child_arg[] = "Hello from your parent!";
static sem_t g_sem; static sem_t g_sem;
#if CONFIG_TASK_NAME_SIZE == 0
static char no_name[] = "<noname>";
#endif
/**************************************************************************** /****************************************************************************
* Privite Functions * Privite Functions
****************************************************************************/ ****************************************************************************/
/* NOTE: it is necessary for functions that are referred to by function pointers /* NOTE: it is necessary for functions that are referred to by function pointers
* pointer to be declared with global scope (at least for ARM). Otherwise, * pointer to be declared with global scope (at least for ARM). Otherwise,
* a relocation type that is not supported by NXFLAT is generated by GCC. * a relocation type that is not supported by NXFLAT is generated by GCC.
*/ */
@ -74,15 +78,23 @@ static sem_t g_sem;
printf("Child: Exit-ting with status=2\n"); printf("Child: Exit-ting with status=2\n");
exit(2); exit(2);
} }
printf("Child: argv[0]=\"%s\"\n", argv[0]); printf("Child: argv[0]=\"%s\"\n", argv[0]);
if (strcmp(argv[0], child_name) != 0) #if CONFIG_TASK_NAME_SIZE == 0
if (strcmp(argv[0], no_name) != 0)
{
printf("Child: expected argv[0] to be \"%s\"\n", no_name);
printf("Child: Exit-ting with status=3\n");
exit(3);
}
#else
if (strncmp(argv[0], child_name, CONFIG_TASK_NAME_SIZE) != 0)
{ {
printf("Child: expected argv[0] to be \"%s\"\n", child_name); printf("Child: expected argv[0] to be \"%s\"\n", child_name);
printf("Child: Exit-ting with status=3\n"); printf("Child: Exit-ting with status=3\n");
exit(3); exit(3);
} }
#endif
printf("Child: argv[1]=\"%s\"\n", argv[1]); printf("Child: argv[1]=\"%s\"\n", argv[1]);
@ -106,7 +118,7 @@ int main(int argc, char **argv)
{ {
pid_t parent_pid = getpid(); pid_t parent_pid = getpid();
char *child_argv[2]; char *child_argv[2];
int ret; pid_t child_pid;
printf("Parent: Started, pid=%d\n", parent_pid); printf("Parent: Started, pid=%d\n", parent_pid);
@ -116,15 +128,15 @@ int main(int argc, char **argv)
child_argv[0] = child_arg; child_argv[0] = child_arg;
child_argv[1] = 0; child_argv[1] = 0;
ret = task_create(child_name, 50, 512, child_task, (const char**)child_argv); child_pid = task_create(child_name, 50, 512, child_task, (const char**)child_argv);
if (ret != 0) if (child_pid < 0)
{ {
printf("Parent: task_create failed: %d\n", errno); printf("Parent: task_create failed: %d\n", errno);
} }
printf("Parent: Waiting for child\n"); printf("Parent: Waiting for child (pid=%d)\n", child_pid);
sem_wait(&g_sem); sem_wait(&g_sem);
printf("Parent: Exiting\n"); printf("Parent: Exit-ing\n");
sem_destroy(&g_sem); sem_destroy(&g_sem);
return 0; return 0;
} }

View File

@ -47,8 +47,8 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define NXFLAT_MAX_STRING_SIZE 64 /* Largest size of string (w/zterminator) */ #define NXFLAT_MAX_STRING_SIZE 64 /* Largest size of string (w/zterminator) */
#define NXFLAT_MAGIC "NxFT" /* NXFLAT magic number */ #define NXFLAT_MAGIC "NxFT" /* NXFLAT magic number */
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
@ -69,7 +69,7 @@ struct nxflat_hdr_s
* this magic number. * this magic number.
*/ */
char h_magic[4]; char h_magic[4];
/* The following fields provide the memory map for the nxflat binary. /* The following fields provide the memory map for the nxflat binary.
* *
@ -116,7 +116,7 @@ struct nxflat_hdr_s
/* Imported symbol table (NOTE no symbols are exported): /* Imported symbol table (NOTE no symbols are exported):
* *
* h_importsymbols - Offset to the beginning of an array of imported * h_importsymbols - Offset to the beginning of an array of imported
* symbol structures (struct nxflat_import). The * symbol structures (struct nxflat_import_s). The
* h_importsymbols offset is relative to the * h_importsymbols offset is relative to the
* beginning of the file. Each entry of the * beginning of the file. Each entry of the
* array contains an uint32 offset (again from * array contains an uint32 offset (again from
@ -149,7 +149,7 @@ struct nxflat_reloc_s
/* Pack the type and the offset into one 32-bit value */ /* Pack the type and the offset into one 32-bit value */
#define NXFLAT_RELOC(t,o) (((u_int32_t)((t) & 3) << 30) | ((o) & 0x1fffffff)) #define NXFLAT_RELOC(t,o) (((u_int32_t)((t) & 3) << 30) | ((o) & 0x3fffffff))
/* The top three bits of the relocation info is the relocation type (see the /* The top three bits of the relocation info is the relocation type (see the
* NXFLAT_RELOC_TYPE_* definitions below. This is an unsigned value. * NXFLAT_RELOC_TYPE_* definitions below. This is an unsigned value.

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* task_start.c * task_start.c
* *
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without