Does anyone use the main() function in rtems programs?

brian brian at bpeas.org
Thu Jul 1 18:56:42 UTC 2004


Joe,

I have been using the POSIX  API of  RTEMS and so please see the code
extract below:-

/* Library Header files */
/* ============== */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <rtems.h>

#include <semaphore.h>
#include <pthread.h>
#include <fcntl.h>

void POSIX_Init (void *args)
{

  /* local variables */

  /* ================*/

  /* Initialise POSIX system */
  /* ================ */
  printf ("\n");
  printf ("RTEMS POSIX Started\n");  /* initialise variables */

 add your code here

}

I expect that you are having some problems with the configuration
definitions, since I was going to be changing these I started by defining
most of them as the defaults and then changing as needed

#if !defined (__CONFIG__)
#define __CONFIG__

/* ask the system to generate a configuration table */
#define CONFIGURE_INIT

/* define the posix configuration */

#define CONFIGURE_POSIX_INIT_THREAD_TABLE

#define CONFIGURE_MAXIMUM_POSIX_THREADS              10
#define CONFIGURE_MAXIMUM_POSIX_MUTEXES              5
#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES  5
#define CONFIGURE_MAXIMUM_POSIX_KEYS                 5
#define CONFIGURE_MAXIMUM_POSIX_TIMERS               5
#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS       2000
#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES       5
#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES           10

#include <confdefs.h>

#endif /* if defined CONFIG */

Remeber that the default initialisation routines are
    POSIX_INIT for the POSIX API
    Init for RTEMS API

I hope that this helps, if not let me know.




----- Original Message ----- 
From: "Joe OS" <joe_os2001 at yahoo.com>
To: <rtems-users at rtems.com>
Sent: Thursday, July 01, 2004 4:33 PM
Subject: Does anyone use the main() function in rtems programs?


>
>
> Hi,
> I am sorry about this beginner question, but I cant
> solute this problem:
>
> I am a beginner concerning rtems. I already made some
> simple programs and they workek.
> In these programs I used configuration information
> like
>
> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
> #define CONFIGURE_MICROSECONDS_PER_TICK 1000
> #define CONFIGURE_TICKS_PER_TIMESLICE   1
> #define CONFIGURE_MAXIMUM_TASKS 1
> #define CONFIGURE_MICROSECONDS_INIT
> #define CONFIGURE_INIT
> #include <confdefs.h>
>
> So everything worked fine.
>
> Now, I want to write rtems programs with the
> portability in mind,
> like, use the main() function and posic api. So I
> wrote one simple
> program using the main() instruction, instead of the
> rtems macro
>  representing the main. I
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/time.h>
>
> int main()
> {
>   puts( "\n\n*** POSIX PROGRAM ***" );
>   return 0;
> }
>
> I used the make file of the rtmes program version to
> build this c posix
> like program and everuthing worked fine. Remember that
> I didn't define
> any symbols and didn't include the confdefs.h either!!
> But it worked!
>
>
> Now I want to launch one extra thread and the problem
> arises:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <pthread.h>
> #include <sys/time.h>
>
> void task2()
> {
>    int counter=0;
>    int i;
>
>    for(i=0;i<100000;i++)
>    {
>     counter++;
>     if((counter % 10000) == 0)
>  {
>   puts( " P " );
>  }
>    }
> }
>
> int main()
> {
>   pthread_t count;
>   int taskparameter = 0;
>
>   puts( "\n\n*** POSIX PROGRAM ***" );
>
>   //Start task 2
>   int task_ret;
>   task_ret = pthread_create(&count, NULL, (void *)
> task2, (void *) &taskparameter);
>   if (task_ret)
>   {
>     perror("error creating task2");
>     return 0;
>   }
>   pthread_join(count,NULL);
>   return 0;
> }
>
> Every time the program is executed, the
> pthread_create() function
> always fails! Once more again, I didn't define any
> symbols nor confdefs.h, because if I define for
> example
>
> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
> #define CONFIGURE_MICROSECONDS_PER_TICK 1000
> #define CONFIGURE_TICKS_PER_TIMESLICE   1
> #define CONFIGURE_MAXIMUM_TASKS 1
> #define CONFIGURE_MICROSECONDS_INIT
> #define CONFIGURE_INIT
> #include <confdefs.h>
>
> many errors appear during execution of the original
> make file.
>
> My question is:
> When using the c posix fashion, using the pure main()
> function,
> is it needed to define the symbols and use confdefs,
> or there is
>  other way to compile a program.
>
> I searched in the rtems samples and didn't find any
> programs using
> the main() function, so any c posix fashion sample
> program and make
> file would be appreciated.
>
> Any comments?
>
> Thanks to everybody,
>
> Joe
>
>
>
> __________________________________
> Do you Yahoo!?
> New and Improved Yahoo! Mail - Send 10MB messages!
> http://promotions.yahoo.com/new_mail




More information about the users mailing list