task creation

D.G.Somerton dgsomerton at hunterwatertech.com.au
Mon Apr 2 03:35:35 UTC 2001


Hello,

  Does anybody know why this output is produced by the included program?

*** CLOCK TICK TEST ***
Error creating task 20, status is 0000000d
Error creating task 21, status is 0000000d
Error creating task 22, status is 0000000d
Error creating task 23, status is 0000000d
TA01 - rtems_clock_get - 10:00:00   04/02/2001
TA02 - rtems_clock_get - 10:00:00   04/02/2001
TA03 - rtems_clock_get - 10:00:00   04/02/2001
TA04 - rtems_clock_get - 10:00:00   04/02/2001
TA05 - rtems_clock_get - 10:00:00   04/02/2001
TA06 - rtems_clock_get - 10:00:00   04/02/2001
TA07 - rtems_clock_get - 10:00:00   04/02/2001
TA08 - rtems_clock_get - 10:00:00   04/02/2001
TA09 - rtems_clock_get - 10:00:00   04/02/2001
TA10 - rtems_clock_get - 10:00:00   04/02/2001
TA11 - rtems_clock_get - 10:00:00   04/02/2001
TA12 - rtems_clock_get - 10:00:00   04/02/2001
TA13 - rtems_clock_get - 10:00:00   04/02/2001
TA14 - rtems_clock_get - 10:00:00   04/02/2001
TA15 - rtems_clock_get - 10:00:00   04/02/2001
TA16 - rtems_clock_get - 10:00:01   04/02/2001
TA17 - rtems_clock_get - 10:00:01   04/02/2001
TA18 - rtems_clock_get - 10:00:01   04/02/2001
TA19 - rtems_clock_get - 10:00:01   04/02/2001



Program:
  System.h

/*  system.h
 *
 *  This include file contains information that is included in every
 *  function in the test set.
 *
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id: system.h,v 1.12.2.4 2000/05/24 17:06:40 joel Exp $
 */

#include <rtems.h>

/* functions */

rtems_task
Init (rtems_task_argument argument);

rtems_task
Test_task (rtems_task_argument argument);

/* global variables */

/*
 *  Keep the names and IDs in global variables so another task can use them.
 */ 

extern rtems_id   Task_id  [32];         /* array of task ids */
extern rtems_name Task_name[32];       /* array of task names */


/* configuration information */

#include <bsp.h> /* for device driver prototypes */

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MAXIMUM_TASKS             32

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)

#include <confdefs.h>

/*
 *  Handy macros and static inline functions
 */

/*
 *  Macro to hide the ugliness of printing the time.
 */

#define print_time(_s1, _tb, _s2) \
  do { \
    printf( "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
    fflush(stdout); \
  } while ( 0 )

/*
 *  Macro to print an task name that is composed of ASCII characters.
 *
 */

#define put_name( _name, _crlf ) \
  do { \
    rtems_unsigned32 c0, c1, c2, c3; \
    \
    c0 = ((_name) >> 24) & 0xff; \
    c1 = ((_name) >> 16) & 0xff; \
    c2 = ((_name) >> 8) & 0xff; \
    c3 = (_name) & 0xff; \
    putchar( (char)c0 ); \
    if ( c1 ) putchar( (char)c1 ); \
    if ( c2 ) putchar( (char)c2 ); \
    if ( c3 ) putchar( (char)c3 ); \
    if ( (_crlf) ) \
      putchar( '\n' ); \
  } while (0)

/*
 *  static inline routine to make obtaining ticks per second easier.
 */

static __inline rtems_unsigned32
get_ticks_per_second (void)
{
  rtems_interval ticks_per_second;
  rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second);
  return ticks_per_second;
}


/*
 *  This allows us to view the "Test_task" instantiations as a set
 *  of numbered tasks by eliminating the number of application
 *  tasks created.
 *
 *  In reality, this is too complex for the purposes of this
 *  example.  It would have been easier to pass a task argument. :)
 *  But it shows how rtems_id's can sometimes be used.
 */

#define task_number(tid)\
 (rtems_get_index(tid)-rtems_configuration_get_rtems_api_configuration ()->number_of_initialization_tasks)

/* end of include file */


Init.c
/*  Init
 *
 *  This routine is the initialization task for this test program.
 *  It is called from init_exec and has the responsibility for creating
 *  and starting the tasks that make up the test.  If the time of day
 *  clock is required for the test, it should also be set to a known
 *  value by this function.
 *
 *  Input parameters:  NONE
 *
 *  Output parameters:  NONE
 *
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id: init.c,v 1.10.2.1 2000/05/05 12:58:06 joel Exp $
 */

#define CONFIGURE_INIT
#include "system.h"
#include <stdio.h>

/*
 *  Keep the names and IDs in global variables so another task can use them.
 */

rtems_id   Task_id  [32];       /* array of task ids */
rtems_name Task_name[32];       /* array of task names */

rtems_task
Init (rtems_task_argument argument)
{
  int  i;
  char name[5];
  char buf [80];
  
  rtems_status_code status;
  rtems_time_of_day time;

  puts ("\n\n*** CLOCK TICK TEST ***");

  time.year   = 2001;
  time.month  = 4;
  time.day    = 2;
  time.hour   = 10;
  time.minute = 0;
  time.second = 0;
  time.ticks  = 0;

  status = rtems_clock_set (&time);

#if 1
  for (i = 1; i < 24; i++)
  {
   sprintf (name, "TA%02d", i);
    Task_name[i] = rtems_build_name (name[0], name[1], name[2], name[3]);
    status = rtems_task_create (Task_name[i], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &Task_id[i]);
    if (status != RTEMS_SUCCESSFUL)
    {
      sprintf (buf, "Error creating task %d, status is %08x", i, status);
      puts (buf);
    }
    else
    {
      status = rtems_task_start (Task_id[i], Test_task, i);
      if (status != RTEMS_SUCCESSFUL)
      {
        sprintf (buf, "Error starting task %d, status is %08x", i, status);
        puts (buf);
      }
    }
  }
#endif

#if 0
  Task_name[1] = rtems_build_name ('T', 'A', '1', ' ');
  Task_name[2] = rtems_build_name ('T', 'A', '2', ' ');
  Task_name[3] = rtems_build_name ('T', 'A', '3', ' ');

  status = rtems_task_create (Task_name[1], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1]);
  status = rtems_task_create (Task_name[2], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &Task_id[2]);
  status = rtems_task_create (Task_name[3], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &Task_id[3]);

  status = rtems_task_start (Task_id[1], Test_task, 1);
  status = rtems_task_start (Task_id[2], Test_task, 2);
  status = rtems_task_start (Task_id[3], Test_task, 3);
#endif

  status = rtems_task_delete (RTEMS_SELF);
}


Tasks.c

/*  Test_task
 *
 *  This routine serves as a test task.  It verifies the basic task
 *  switching capabilities of the executive.
 *
 *  Input parameters:  NONE
 *
 *  Output parameters:  NONE
 *
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id: tasks.c,v 1.7.2.1 2000/05/05 12:58:06 joel Exp $
 */

#include "system.h"
#include <stdio.h>

rtems_task
Test_task (rtems_task_argument unused)
{
  rtems_id          tid;
  rtems_time_of_day time;
  rtems_unsigned32  task_index;
  rtems_status_code status;

  status = rtems_task_ident (RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid);
  task_index = task_number (tid);

  for (;;)
  {
    status = rtems_clock_get (RTEMS_CLOCK_GET_TOD, &time);
    put_name (Task_name[task_index], FALSE);
    print_time (" - rtems_clock_get - ", &time, "\n");
    status = rtems_task_wake_after (task_index * 5 * get_ticks_per_second());
  }
}


D.G.Somerton



More information about the users mailing list