This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
twothread example in redboot.
- From: Sai Naidu <naiduk at intotoinc dot com>
- To: ecos-discuss at sources dot redhat dot com
- Date: 29 Apr 2004 20:34:26 +0530
- Subject: [ECOS] twothread example in redboot.
hi!
I have some queries regarding the thread scheduling in redboot.
I require to build a redboot bootloader with a server (http and tftp)
running in the background.
I was not aware how the threads are scheduled so I have made use of the
"twothreads.c" example program which was there in "ecos/examples"
directory of the code checked out from the CVS.
Iam building the image for IXP425 (ecosconfig new grg redboot). I have
included the following packages for the target.
target grg {
alias { "Generic Residential Gateway" grg }
packages { CYGPKG_HAL_ARM
CYGPKG_HAL_ARM_XSCALE_CORE
CYGPKG_HAL_ARM_XSCALE_IXP425
CYGPKG_HAL_ARM_XSCALE_GRG
CYGPKG_IO_PCI
CYGPKG_DEVS_ETH_INTEL_I82559
CYGPKG_DEVS_ETH_ARM_GRG_I82559
CYGPKG_DEVS_FLASH_STRATA
CYGPKG_DEVS_FLASH_GRG
CYGPKG_ERROR
CYGPKG_IO
CYGPKG_MEMALLOC
CYGPKG_KERNEL
CYGPKG_LIBC_STDLIB
CYGPKG_LIBC_STDIO
CYGPKG_LIBC_I18N
CYGPKG_LIBC_TIME
}
In order to run my two threads program, i have included a command in
the "packages/redboot/current/src/main.c". The idea is, when i run this
command from the redboot prompt, the twothread.c program get run.
The code added to the "packages/redboot/current/src/main.c" file is as
follows.
RedBoot_cmd("runThreads",
"Execute tftp server",
"",
do_threadsExpl
);
void do_threadsExpl(int argc, char *argv[])
{
cyg_user_start();
}
the cyg_user_start() is the one which is defined in the "twothreads.c"
file. I am pasting the file below
/******************************************/
#include <cyg/kernel/kapi.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/* now declare (and allocate space for) some kernel objects,
like the two threads we will use */
cyg_thread thread_s[2]; /* space for two thread objects */
char stack[2][4096]; /* space for two 4K stacks */
/* now the handles for the threads */
cyg_handle_t simple_threadA, simple_threadB;
/* and now variables for the procedure which is the thread */
cyg_thread_entry_t simple_program;
/* and now a mutex to protect calls to the C library */
cyg_mutex_t cliblock;
/* we install our own startup routine which sets up threads */
void cyg_user_start(void)
{
diag_printf("Entering twothreads' cyg_user_start() function\n");
cyg_mutex_init(&cliblock);
cyg_thread_create(4, simple_program, (cyg_addrword_t) 0,
"Thread A", (void *) stack[0], 4096,
&simple_threadA, &thread_s[0]);
cyg_thread_create(4, simple_program, (cyg_addrword_t) 1,
"Thread B", (void *) stack[1], 4096,
&simple_threadB, &thread_s[1]);
cyg_thread_resume(simple_threadA);
cyg_thread_resume(simple_threadB);
}
/* this is a simple program which runs in a thread */
void simple_program(cyg_addrword_t data)
{
int message = (int) data;
int delay;
diag_printf("Beginning execution; thread data is %d\n", message);
cyg_thread_delay(200);
for (;;) {
delay = 200 + (rand() % 50);
/* note: printf() must be protected by a
call to cyg_mutex_lock() */
cyg_mutex_lock(&cliblock); {
diag_printf("Thread %d: and now a delay of %d clock ticks\n",
message, delay);
}
cyg_mutex_unlock(&cliblock);
cyg_thread_delay(delay);
}
}
/******************************************************/
I then built and complied the image and burnt it on to the flash.
Now when i run the command runThreads from the redboot prompt , i am
not getting the required output. The threads just do not run.
/*********OUTPUT************************/
RedBoot> runThreads
Entering twothreads' cyg_user_start() function
RedBoot>
Basically i do not have any threads running. i have even tried printing
the state of these threads . It shows the states value as 0. Am I
missing out on some package? Is it possible to spawn more threads from
the redboot prompt if NO how do we have more than one thread running? I
require the redboot prompt and a server running on another thread in the
background. Could any one suggest me the right approach?
thanks and regards
sai naidu
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss