void doTest(void)
{
  rtems_status_code sc;
  int               pass, i;

  sc = rtems_semaphore_create(
    rtems_build_name('S', 'E', 'M', 'F'),
    0,
    TEST_SEMAPHORE_ATTRIBUTES,
    0,
    &semaphore);
  directive_failed( sc, "semaphore create" );

  for (i = 0 ; i < NTASK ; i++)
    flags[i] = 0;

  for (i = 0 ; i < NTASK ; i++)
    starttask(i);

  for (pass = 1 ; pass < 10 ; pass++) {
    rtems_task_wake_after(1);
    for (i = 0 ; i < NTASK ; i++) {
      if (flags[i] != pass)
        printf("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
    }
    sc = rtems_semaphore_flush(semaphore);
    directive_failed( sc, "semaphore flush" );
  }

  printf("Flushed all waiting tasks\n" );
}
Esempio n. 2
0
/**
 * Initial task.
 *
 * Enables interrupts, runs calibration and starts up new tasks.
 *
 * Delete itself after completion.
 */
rtems_task Init(rtems_task_argument ignored) {

	position_isr.x = 0;
	position_isr.y = 0;

	rtems_name name;
	rtems_status_code status;

	name = rtems_build_name('Q','U','E','1');
	status = rtems_message_queue_create(name, 1, sizeof(position_t), RTEMS_LOCAL, &msg_queue);
	assert( status == RTEMS_SUCCESSFUL );

	// setup IRQ handler
	status = rtems_interrupt_handler_install(5, NULL, RTEMS_INTERRUPT_UNIQUE, isr, NULL);
	assert( status == RTEMS_SUCCESSFUL );

	// calibrate
	calibrate();

	// create semaphore
	name = rtems_build_name('S','E','M','1');
	status = rtems_semaphore_create(name,1,RTEMS_SIMPLE_BINARY_SEMAPHORE,0,&state_semaphore_id);
	assert(status == RTEMS_SUCCESSFUL);

	set_status(STATE_READY);
	create_and_start_tasks();

	// all done. delete itself.
	rtems_task_delete(RTEMS_SELF);
}
Esempio n. 3
0
static rtems_task Init(
  rtems_task_argument ignored
)
{
  rtems_status_code     status;

  TEST_BEGIN();

  thread = _Thread_Get_executing();

  puts( "Init - Trying to generate semaphore release from ISR while blocking" );
  puts( "Init - Variation is: " TEST_STRING );
  status = rtems_semaphore_create(
    rtems_build_name( 'S', 'M', '1', ' ' ),
    0,
    SEMAPHORE_ATTRIBUTES,
    RTEMS_NO_PRIORITY,
    &Semaphore
  );
  directive_failed( status, "rtems_semaphore_create of SM1" );

  interrupt_critical_section_test( test_body, NULL, test_release_from_isr );

  if ( case_hit ) {
    puts( "Init - Case hit" );
    TEST_END();
  } else
    puts( "Init - Case not hit - ran too long" );

  rtems_test_exit(0);
}
Esempio n. 4
0
rtems_device_driver pfpu_initialize(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  rtems_status_code sc;
  rtems_isr_entry dummy;

  sc = rtems_io_register_name(DEVICE_NAME, major, 0);
  RTEMS_CHECK_SC(sc, "create PFPU device");

  sc = rtems_semaphore_create(
    rtems_build_name('P', 'F', 'P', 'U'),
    0,
    RTEMS_SIMPLE_BINARY_SEMAPHORE,
    0,
    &done_sem
  );
  RTEMS_CHECK_SC(sc, "create PFPU done semaphore");

  rtems_interrupt_catch(done_handler, MM_IRQ_PFPU, &dummy);
  bsp_interrupt_vector_enable(MM_IRQ_PFPU);

  return RTEMS_SUCCESSFUL;
}
Esempio n. 5
0
/* i2c_transfer_wait_sema --
 *     Initiate I2C bus transfer and block on temporary created semaphore
 *     until this transfer will be finished.
 *
 * PARAMETERS:
 *     bus - I2C bus number
 *     msg - pointer to transfer messages array
 *     nmsg - number of messages in transfer
 *
 * RETURNS:
 *     RTEMS_SUCCESSFUL, if tranfer finished successfully,
 *     or RTEMS status code if semaphore operations has failed.
 */
static i2c_message_status
i2c_transfer_wait_sema(i2c_bus_number bus, i2c_message *msg, int nmsg)
{
    rtems_status_code sc;
    rtems_id sema;
    sc = rtems_semaphore_create(
        rtems_build_name('I', '2', 'C', 'S'),
        0,
        RTEMS_COUNTING_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY |
        RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL,
        0,
        &sema
    );
    if (sc != RTEMS_SUCCESSFUL)
        return I2C_RESOURCE_NOT_AVAILABLE;
    sc = i2c_transfer(bus, nmsg, msg,
		      i2c_transfer_sema_done_func, &sema);
    if (sc != RTEMS_SUCCESSFUL)
    {
        rtems_semaphore_delete(sema);
        return sc;
    }
    rtems_semaphore_obtain(sema, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    sc = rtems_semaphore_delete(sema);
    return sc;
}
Esempio n. 6
0
static void test_mrsp_obtain_release(void)
{
  rtems_status_code sc;
  rtems_id id;

  puts("test MrsP obtain and release");

  sc = rtems_semaphore_create(
    rtems_build_name('M', 'R', 'S', 'P'),
    1,
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_BINARY_SEMAPHORE,
    1,
    &id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  assert_prio(2);

  sc = rtems_semaphore_obtain(id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  assert_prio(1);

  sc = rtems_semaphore_delete(id);
  rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE);

  sc = rtems_semaphore_release(id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  assert_prio(2);

  sc = rtems_semaphore_delete(id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Esempio n. 7
0
static int pipe_lock(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;

  if (pipe_semaphore == RTEMS_ID_NONE) {
    rtems_libio_lock();

    if (pipe_semaphore == RTEMS_ID_NONE) {
      sc = rtems_semaphore_create(
        rtems_build_name('P', 'I', 'P', 'E'),
        1,
        RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
        RTEMS_NO_PRIORITY,
        &pipe_semaphore
      );
    }

    rtems_libio_unlock();
  }

  if (sc == RTEMS_SUCCESSFUL) {
    sc = rtems_semaphore_obtain(pipe_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
  }

  if (sc == RTEMS_SUCCESSFUL) {
    return 0;
  } else {
    return -ENOMEM;
  }
}
Esempio n. 8
0
/**
 * Create the lock.
 */
static
bool mmap_mappings_lock_create(
  void
)
{
  /*
   * Lock the mapping table. We only create a lock if a call is made. First we
   * test if a mapping lock is present. If one is present we lock it. If not
   * the libio lock is locked and we then test the mapping lock again. If not
   * present we create the mapping lock then release libio lock.
   */
  if ( mmap_mappings_lock == 0 ) {
    rtems_status_code sc = RTEMS_SUCCESSFUL;
    rtems_chain_initialize_empty( &mmap_mappings );
    rtems_semaphore_obtain( rtems_libio_semaphore,
                            RTEMS_WAIT, RTEMS_NO_TIMEOUT );
    if ( mmap_mappings_lock == 0 )
      sc = rtems_semaphore_create( rtems_build_name( 'M', 'M', 'A', 'P' ),
                                   1,
                                   RTEMS_MUTEX_ATTRIBS,
                                   RTEMS_NO_PRIORITY,
                                   &mmap_mappings_lock );
    rtems_semaphore_release( rtems_libio_semaphore );
    if ( sc != RTEMS_SUCCESSFUL ) {
      errno = EINVAL;
      return false;
    }
  }
  return true;
}
Esempio n. 9
0
/****************************************************************************************
                                INITIALIZATION FUNCTION
****************************************************************************************/
int32  OS_TimerAPIInit ( void )
{
   int               i;
   int32             return_code = OS_SUCCESS;
   rtems_status_code rtems_sc;
   
   /*
   ** Mark all timers as available
   */
   for ( i = 0; i < OS_MAX_TIMERS; i++ )
   {
      OS_timer_table[i].free      = TRUE;
      OS_timer_table[i].creator   = UNINITIALIZED;
      strcpy(OS_timer_table[i].name,"");
   }
	
   /*
   ** Store the clock accuracy for 1 tick.
   */
   OS_TicksToUsecs(1, &os_clock_accuracy);

   /*
   ** Create the Timer Table semaphore
   */
   rtems_sc = rtems_semaphore_create (rtems_build_name ('M', 'U', 'T', '6'),
                                      1, OSAL_TABLE_MUTEX_ATTRIBS, 0,
                                      &OS_timer_table_sem);
   if ( rtems_sc != RTEMS_SUCCESSFUL )
   {
      return_code = OS_ERROR;
   }
   
   return(return_code);
   
}
Esempio n. 10
0
static void test_create_initially_locked_prio_inherit_sema(void)
{
  rtems_status_code   sc;
  rtems_id            id;
  rtems_task_priority prio_a;
  rtems_task_priority prio_b;
  rtems_task_priority prio_ceiling = 0;

  sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio_a);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(prio_a != prio_ceiling);

  sc = rtems_semaphore_create(
    rtems_build_name( 'S', 'E', 'M', 'A' ),
    0,
    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
    prio_ceiling,
    &id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio_b);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_test_assert(prio_a == prio_b);

  sc = rtems_semaphore_release(id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_semaphore_delete(id);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Esempio n. 11
0
File: init.c Progetto: gedare/rtems
rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code  sc;
  rtems_id           mutex;
  Per_CPU_Control   *cpu_self;

  TEST_BEGIN();

  sc = rtems_semaphore_create(
    rtems_build_name('M', 'U', 'T', 'X'),
    0,
    RTEMS_BINARY_SEMAPHORE,
    0,
    &mutex
  );
  directive_failed(sc, "rtems_semaphore_create");

  /*
   *  Call semaphore obtain with dispatching disabled.  Reenable
   *  dispatching before checking the status returned since
   *  directive_failed() checks for dispatching being enabled.
   */
  puts( "rtems_semaphore_obtain - with dispatching disabled" );
  cpu_self = _Thread_Dispatch_disable();
    sc = rtems_semaphore_obtain(mutex, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT);
  _Thread_Dispatch_enable(cpu_self);
  directive_failed(sc, "rtems_semaphore_obtain");

  TEST_END();
  rtems_test_exit(0);
}
Esempio n. 12
0
/*
 * Test verifies priority,
 * Changes priority by obtaining a higher priority semaphore
 * Releases semaphore to return priority
 */
static void test(void)
{
  rtems_status_code   sc;
  rtems_task_priority priority;
  rtems_id            task_sem;

  sc = rtems_semaphore_create(  
    rtems_build_name('S', 'E', 'M', '0'),
    1,
    RTEMS_BINARY_SEMAPHORE |
    RTEMS_PRIORITY     |
    RTEMS_PRIORITY_CEILING, 
    5,
    &task_sem
  );  
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
  printf("Init: priority %d expected %d\n",(int)priority, TASK_PRIORITY );
  rtems_test_assert( priority == TASK_PRIORITY );

  printf("Init: Obtain Semaphore\n");
  sc = rtems_semaphore_obtain (task_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
  rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
  printf("Init: priority %d expected %d\n",(int)priority, SEM_PRIORITY );
  rtems_test_assert( priority == SEM_PRIORITY );

  printf("Init: Release Semaphore\n");
  rtems_semaphore_release(task_sem);
  rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
  printf("Init: priority %d expected %d\n",(int)priority, TASK_PRIORITY );
  rtems_test_assert( priority == TASK_PRIORITY );
}
Esempio n. 13
0
static void Init(rtems_task_argument ignored)
{
  test_context *ctx = &ctx_instance;
  rtems_status_code sc;

  TEST_BEGIN();

  ctx->main_task_control = _Thread_Get_executing();

  sc = rtems_semaphore_create(
    rtems_build_name('S', 'E', 'M', 'A'),
    1,
    RTEMS_SIMPLE_BINARY_SEMAPHORE,
    0,
    &ctx->semaphore_id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  ctx->semaphore_control = get_semaphore_control(ctx->semaphore_id);

  interrupt_critical_section_test(test_body, ctx, release_semaphore);
  rtems_test_assert(ctx->done);

  TEST_END();

  rtems_test_exit(0);
}
Esempio n. 14
0
static rtems_task Init(
  rtems_task_argument ignored
)
{
  rtems_status_code     sc;

  TEST_BEGIN();

  thread = _Thread_Get_executing();

  puts( "Init - Test may not be able to detect case is hit reliably" );
  puts( "Init - Trying to generate timeout from ISR while blocking" );
  sc = rtems_semaphore_create(
    rtems_build_name( 'S', 'M', '1', ' ' ),
    0,
    RTEMS_DEFAULT_ATTRIBUTES,
    RTEMS_NO_PRIORITY,
    &Semaphore
  );
  directive_failed( sc, "rtems_semaphore_create of SM1" );

  interrupt_critical_section_test( test_body, NULL, test_release_from_isr );

  if ( case_hit ) {
    puts( "Init - It appears the case has been hit" );
    TEST_END();
  } else
    puts( "Init - Case not hit - ran too long" );

  rtems_test_exit(0);
}
Esempio n. 15
0
rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code   status;

  puts( "\n\n*** SIMPLE SCHEDULER 02 TEST ***" );

  /*
   * Create the semaphore. Then obtain and release the
   * semaphore with no other tasks running.
   */
  puts( "INIT - Create priority ceiling semaphore" );
  Semaphore_name[ 1 ] = rtems_build_name( 'S', 'M', '1', ' ' );
  status = rtems_semaphore_create(
    Semaphore_name[ 1 ],
    1,
    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY,
    2,
    &Semaphore_id[ 1 ]
  );
  directive_failed( status, "rtems_semaphore_create of SM1" );
  ObtainRelease( false );

  /*
   * Create test task and obtain release the semaphore with
   * one other task running.
   */
  puts( "INIT - create task 1" );
  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
  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_start( Task_id[ 1 ], Test_task, 1 );
  ObtainRelease( false );

  /*
   * Create a a second test task and obtain release the semaphore
   * with both tasks running.
   */
  puts( "INIT - create task 2" );
  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '2', ' ' );
  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_start( Task_id[ 2 ], Test_task, 1 );
  ObtainRelease( false );

  /*
   * Obtain and release the semaphore with the idle task suspended.
   */
  ObtainRelease( true );

  /*  End the Test */
  puts( "*** END OF SIMPLE SCHEDULER 02 TEST ***" );
  rtems_test_exit(0);
}
Esempio n. 16
0
File: grtm.c Progetto: gedare/rtems
static int grtm_device_init(struct grtm_priv *pDev)
{
	struct amba_dev_info *ambadev;
	struct ambapp_core *pnpinfo;
	union drvmgr_key_value *value;

	/* Get device information from AMBA PnP information */
	ambadev = (struct amba_dev_info *)pDev->dev->businfo;
	if ( ambadev == NULL ) {
		return -1;
	}
	pnpinfo = &ambadev->info;
	pDev->irq = pnpinfo->irq;
	pDev->regs = (struct grtm_regs *)pnpinfo->apb_slv->start;
	pDev->minor = pDev->dev->minor_drv;
	pDev->open = 0;
	pDev->running = 0;

	/* Create Binary RX Semaphore with count = 0 */
	if ( rtems_semaphore_create(rtems_build_name('G', 'R', 'M', '0' + pDev->minor),
		0,
		RTEMS_FIFO|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY|\
		RTEMS_LOCAL|RTEMS_NO_PRIORITY_CEILING, 
		0,
		&pDev->sem_tx) != RTEMS_SUCCESSFUL ) {
		return -1;
	}

	/* Allocate Memory for Buffer Descriptor Table, or let user provide a custom
	 * address.
	 */
	value = drvmgr_dev_key_get(pDev->dev, "bdTabAdr", DRVMGR_KT_POINTER);
	if ( value ) {
		pDev->bds = (struct grtm_bd *)value->ptr;
		pDev->_bds = (void *)value->ptr;	
	} else {
		pDev->bds = (struct grtm_bd *)grtm_memalign(0x400, 0x400, &pDev->_bds);
	}
	if ( !pDev->bds ) {
		DBG("GRTM: Failed to allocate descriptor table\n");
		return -1;
	}
	memset(pDev->bds, 0, 0x400);

	pDev->_ring = malloc(sizeof(struct grtm_ring) * 128);
	if ( !pDev->_ring ) {
		return -1;
	}

	/* Reset Hardware before attaching IRQ handler */
	grtm_hw_reset(pDev);

	/* Read SUB revision number, ignore  */
	pDev->subrev = (READ_REG(&pDev->regs->revision) & GRTM_REV1_REV_SREV)
			>> GRTM_REV1_REV_SREV_BIT;

	return 0;
}
Esempio n. 17
0
rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;
  rtems_time_of_day time;
  int               i;
  char              ch[4];
  rtems_id          id;
 
  locked_print_initialize();
  locked_printf( "\n\n*** SMP08 TEST ***\n" );

  time.year   = 1988;
  time.month  = 12;
  time.day    = 31;
  time.hour   = 9;
  time.minute = 0;
  time.second = 0;
  time.ticks  = 0;

  status = rtems_clock_set( &time );

  /* Create/verify synchronisation semaphore */
  status = rtems_semaphore_create(
    rtems_build_name ('S', 'E', 'M', '1'),
    1,                                             
    RTEMS_LOCAL                   |
    RTEMS_SIMPLE_BINARY_SEMAPHORE |
    RTEMS_PRIORITY,
    1,
    &Semaphore
  );
  directive_failed( status, "rtems_semaphore_create" );

  /* Show that the init task is running on this cpu */
  PrintTaskInfo( "Init", &time );

  for ( i=1; i <= rtems_smp_get_processor_count() *3; i++ ) {

    sprintf(ch, "%02" PRId32, i );
    status = rtems_task_create(
      rtems_build_name( 'T', 'A', ch[0], ch[1] ),
      2,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &id
    );
    directive_failed( status, "task create" );

    status = rtems_task_start( id, Test_task, i+1 );
    directive_failed( status, "task start" );
  }

  /* FIXME: Task deletion currently not supported */
  (void) rtems_task_suspend( RTEMS_SELF );
}
Esempio n. 18
0
rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;
  rtems_id          task_id;
  rtems_name        task_name;

  puts( "\n\n*** LED BLINKER -- semaphore ping/pong ***" );

  LED_INIT();

  status = rtems_semaphore_create(
    rtems_build_name( 'S', 'E', 'M', ' ' ),
    0,  /* created locked */
    RTEMS_DEFAULT_ATTRIBUTES,
    0,
    &Sem_id
  );
  assert( status == RTEMS_SUCCESSFUL );

  task_name = rtems_build_name( 'T', 'A', '1', ' ' );

  status = rtems_task_create(
    task_name, 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES, &task_id
  );
  assert( status == RTEMS_SUCCESSFUL );

  status = rtems_task_start( task_id, Test_task, 1 );
  assert( status == RTEMS_SUCCESSFUL );

  while (1) {

    LED_OFF();
    status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
    assert( status == RTEMS_SUCCESSFUL );

    /* Transfers semaphore to TA1 */
    status = rtems_semaphore_release( Sem_id );
    if ( status != RTEMS_SUCCESSFUL )
      fputs( "init - release did not work\n", stderr );

    /* Semaphore not available, ensured to block */
    status = rtems_semaphore_obtain(
      Sem_id,
      RTEMS_DEFAULT_OPTIONS,
      RTEMS_NO_TIMEOUT
    );
    if ( status != RTEMS_SUCCESSFUL )
      fputs( "init - obtain did not work\n", stderr );

  }

  status = rtems_task_delete( RTEMS_SELF );
  assert( status == RTEMS_SUCCESSFUL );
}
Esempio n. 19
0
rtems_task Init(
  rtems_task_argument ignored
)
{
  rtems_status_code     sc;
  int                   resets;

  puts(
    "\n\n*** TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***\n"
    "Init - Trying to generate timeout of a thread while another is blocking\n"
    "Init -   on the same thread queue\n"
    "Init - There is no way for the test to know if it hits the case"
  );

  puts( "Init - rtems_semaphore_create - OK" );
  sc = rtems_semaphore_create(
    rtems_build_name( 'S', 'M', '1', ' ' ),
    0,
    RTEMS_DEFAULT_ATTRIBUTES,
    RTEMS_NO_PRIORITY,
    &Semaphore
  );
  directive_failed( sc, "rtems_semaphore_create of SM1" );

  puts( "Init - rtems_task_create - OK" );
  sc = rtems_task_create(
    rtems_build_name( 'B', 'L', 'C', 'K' ),
    BLOCKER_PRIORITY,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_NO_PREEMPT,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Secondary_task_id
  );
  directive_failed( sc, "rtems_task_create" );

  sc = rtems_task_start( Secondary_task_id, Secondary_task, 0 );
  directive_failed( sc, "rtems_task_start" );

  Main_task = rtems_task_self();

  interrupt_critical_section_test_support_initialize( NULL );

  for (resets=0 ; resets<10 ;) {
    if ( interrupt_critical_section_test_support_delay() )
      resets++;

    sc = rtems_task_restart( Secondary_task_id, 1 );
    directive_failed( sc, "rtems_task_restart" );

    sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 1 );
    fatal_directive_status( sc, RTEMS_TIMEOUT, "rtems_semaphore_obtain" );
  }

  puts( "*** END OF TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" );
  rtems_test_exit(0);
}
Esempio n. 20
0
/*
 * Alloc pipe control structure, buffer, and resources.
 * Called with pipe_semaphore held.
 */
static int pipe_alloc(
  pipe_control_t **pipep
)
{
  static char c = 'a';
  pipe_control_t *pipe;
  int err = -ENOMEM;

  pipe = malloc(sizeof(pipe_control_t));
  if (pipe == NULL)
    return err;
  memset(pipe, 0, sizeof(pipe_control_t));

  pipe->Size = PIPE_BUF;
  pipe->Buffer = malloc(pipe->Size);
  if (! pipe->Buffer)
    goto err_buf;

  err = -ENOMEM;

  if (rtems_barrier_create(
        rtems_build_name ('P', 'I', 'r', c),
        RTEMS_BARRIER_MANUAL_RELEASE, 0,
        &pipe->readBarrier) != RTEMS_SUCCESSFUL)
    goto err_rbar;
  if (rtems_barrier_create(
        rtems_build_name ('P', 'I', 'w', c),
        RTEMS_BARRIER_MANUAL_RELEASE, 0,
        &pipe->writeBarrier) != RTEMS_SUCCESSFUL)
    goto err_wbar;
  if (rtems_semaphore_create(
        rtems_build_name ('P', 'I', 's', c), 1,
        RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO,
        RTEMS_NO_PRIORITY, &pipe->Semaphore) != RTEMS_SUCCESSFUL)
    goto err_sem;

#ifdef RTEMS_POSIX_API
  pipe_interruptible(pipe);
#endif

  *pipep = pipe;
  if (c ++ == 'z')
    c = 'a';
  return 0;

err_sem:
  rtems_barrier_delete(pipe->writeBarrier);
err_wbar:
  rtems_barrier_delete(pipe->readBarrier);
err_rbar:
  free(pipe->Buffer);
err_buf:
  free(pipe);
  return err;
}
Esempio n. 21
0
rtems_task test_init(
  rtems_task_argument argument
)
{
  rtems_status_code   status;
  int                 index;
  rtems_id            task_id;
  rtems_task_priority priority;

  priority = RTEMS_MAXIMUM_PRIORITY - 2u;

  status = rtems_semaphore_create(
    rtems_build_name( 'S', 'M', '1', '\0'),
    0,
    SEMAPHORE_ATTRIBUTES,
    RTEMS_NO_PRIORITY,
    &Semaphore_id
  );
  directive_failed( status, "rtems_semaphore_create of SM1" );

  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
    operation_count =  (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
  for ( index = 2 ; index < operation_count ; index ++ ) {
    rtems_task_create(
      rtems_build_name( 'M', 'I', 'D', ' ' ),
      priority,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &task_id
    );
    directive_failed( status, "rtems_task_create middle" );

    priority--;

    rtems_task_start( task_id, Middle_tasks, 0 );
    directive_failed( status, "rtems_task_start middle" );
  }

  status = rtems_task_create(
    rtems_build_name( 'H', 'I', 'G', 'H' ),
    priority,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  directive_failed( status, "rtems_task_create of high task" );

  status = rtems_task_start( task_id, High_task, 0 );
  directive_failed( status, "rtems_task_start of high task" );

  benchmark_timer_initialize();                          /* start the timer */
  status = rtems_semaphore_release( Semaphore_id );
}
Esempio n. 22
0
/****************************************************************************************
                                INITIALIZATION FUNCTION
****************************************************************************************/
int32 OS_FS_Init(void)
{
    int               i;
    rtems_status_code rtems_sc;
	
    /* Initialize the file system constructs */
    for (i =0; i < OS_MAX_NUM_OPEN_FILES; i++)
    {
        OS_FDTable[i].OSfd =       -1;
        strcpy(OS_FDTable[i].Path, "\0");
        OS_FDTable[i].User =       0;
        OS_FDTable[i].IsValid =    FALSE;
    }

   /*
   ** Initialize the FS subsystem semaphore
   */
   rtems_sc = rtems_semaphore_create (rtems_build_name ('M', 'U', 'T', 'F'),
                                      1, OSAL_TABLE_MUTEX_ATTRIBS, 0,
                                      &OS_FDTableSem);
   if ( rtems_sc != RTEMS_SUCCESSFUL )
   {
      return(OS_ERROR);
   }

   /*
   ** Initialize the RTEMS system call lock semaphore 
   */
   rtems_sc = rtems_semaphore_create (rtems_build_name ('V', 'O', 'L', 'T'),
                                      1, OSAL_TABLE_MUTEX_ATTRIBS, 0,
                                      &OS_VolumeTableSem);
   if ( rtems_sc != RTEMS_SUCCESSFUL )
   {
      return(OS_ERROR);
   }


   return(OS_SUCCESS);


}
Esempio n. 23
0
/*
 * Initialize sparse disk data
 */
static rtems_status_code sparse_disk_initialize( rtems_sparse_disk *sd,
  const uint32_t                                                    media_block_size,
  const rtems_blkdev_bnum                                           blocks_with_buffer,
  const rtems_sparse_disk_delete_handler                            sparse_disk_delete,
  const uint8_t                                                     fill_pattern )
{
  rtems_status_code sc;
  rtems_blkdev_bnum i;

  if ( NULL == sd )
    return RTEMS_INVALID_ADDRESS;

  uint8_t     *data           = (uint8_t *) sd;
  size_t const key_table_size = blocks_with_buffer
                                * sizeof( rtems_sparse_disk_key );
  size_t const data_size      = blocks_with_buffer * media_block_size;

  memset( data, 0, sizeof( rtems_sparse_disk ) + key_table_size );

  sd->fill_pattern = fill_pattern;
  memset( (uint8_t *) ( data + sizeof( rtems_sparse_disk ) + key_table_size ),
          sd->fill_pattern,
          data_size );

  sd->delete_handler = sparse_disk_delete;

  sc                 = rtems_semaphore_create(
    rtems_build_name( 'S', 'P', 'A', 'R' ),
    1,
    RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY,
    0,
    &sd->mutex
    );

  if ( sc != RTEMS_SUCCESSFUL ) {
    return sc;
  }

  data                  += sizeof( rtems_sparse_disk );

  sd->blocks_with_buffer = blocks_with_buffer;
  sd->key_table          = (rtems_sparse_disk_key *) data;

  data                  += key_table_size;

  for ( i = 0; i < blocks_with_buffer; ++i, data += media_block_size ) {
    sd->key_table[i].data = data;
  }

  sd->media_block_size = media_block_size;
  return RTEMS_SUCCESSFUL;
}
void
openlog (const char *ident, int logstat, int logfac)
{
	rtems_status_code sc;
	struct sockaddr_in myAddress;

	if (ident != NULL)
		LogTag = ident;
	LogStatus = logstat;
	if (logfac != 0 && (logfac & ~LOG_FACMASK) == 0)
		LogFacility = logfac;

	/*
	 * Create the socket
	 */
	if ((LogFd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
		printf ("Can't create syslog socket: %d\n", errno);
		return;
	}

	/*
	 * Bind socket to name
	 */
	myAddress.sin_family = AF_INET;
	myAddress.sin_addr.s_addr = INADDR_ANY;
	myAddress.sin_port = 0;
	memset (myAddress.sin_zero, '\0', sizeof myAddress.sin_zero);
	if (bind (LogFd, (struct sockaddr *)&myAddress, sizeof (myAddress)) < 0) {
		close (LogFd);
		LogFd = -1;
		printf ("Can't bind syslog socket: %d\n", errno);
		return;
	}

	/*
	 * Create the mutex
	 */
	sc = rtems_semaphore_create (rtems_build_name('s', 'L', 'o', 'g'),
					1,
					RTEMS_PRIORITY |
						RTEMS_BINARY_SEMAPHORE |
						RTEMS_INHERIT_PRIORITY |
						RTEMS_NO_PRIORITY_CEILING |
						RTEMS_LOCAL,
					0,
					&LogSemaphore);
	if (sc != RTEMS_SUCCESSFUL) {
		printf ("Can't create syslog semaphore: %d\n", sc);
		close (LogFd);
		LogFd = -1;
	}
}
Esempio n. 25
0
static void test_mrsp_create_errors(void)
{
  rtems_status_code sc;
  rtems_id id;

  puts("test MrsP create errors");

  sc = rtems_semaphore_create(
    rtems_build_name('M', 'R', 'S', 'P'),
    1,
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_BINARY_SEMAPHORE,
    UINT32_MAX,
    &id
  );
  rtems_test_assert(sc == RTEMS_INVALID_PRIORITY);

  create_not_defined(
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_COUNTING_SEMAPHORE
  );

  create_not_defined(
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_SIMPLE_BINARY_SEMAPHORE
  );

  create_not_defined(
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_BINARY_SEMAPHORE
      | RTEMS_PRIORITY
  );

  create_not_defined(
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_INHERIT_PRIORITY
      | RTEMS_BINARY_SEMAPHORE
  );

  create_not_defined(
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_PRIORITY_CEILING
      | RTEMS_BINARY_SEMAPHORE
  );

  create_not_defined(
    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING
      | RTEMS_INHERIT_PRIORITY
      | RTEMS_PRIORITY_CEILING
      | RTEMS_BINARY_SEMAPHORE
  );
}
Esempio n. 26
0
File: i2c.c Progetto: chch1028/rtems
rtems_status_code stm32f4_i2c_init(stm32f4_i2c_bus_entry *e)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  volatile stm32f4_i2c *regs = e->regs;
  stm32f4_rcc_index rcc_index = i2c_get_rcc_index(e);
  uint32_t pclk = i2c_get_pclk(e);
  uint32_t cr1 = 0;
  uint32_t cr2 = 0;

  assert(pclk >= 2000000);

  /* Create mutex */
  sc = rtems_semaphore_create (
    rtems_build_name ('I', '2', 'C', '1' + e->index),
    0,
    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
    0,
    &e->mutex
  );
  RTEMS_CHECK_SC(sc, "create mutex");

  /* Install interrupt handler and disable this vector */
  sc = rtems_interrupt_handler_install(
    e->vector,
    "I2C",
    RTEMS_INTERRUPT_UNIQUE,
    stm32f4_i2c_handler,
    e
  );
  RTEMS_CHECK_SC(sc, "install interrupt handler");
  bsp_interrupt_vector_disable(e->vector);

  /* Enable module clock */
  stm32f4_rcc_set_clock(rcc_index, true);

  /* Setup initial bit rate */
  sc = stm32f4_i2c_set_bitrate(e, STM32F4_I2C_INITIAL_BITRATE);
  RTEMS_CHECK_SC(sc, "set bitrate");

  /* Set config registers */
  cr2 = regs->cr2;
  cr2 = STM32F4_I2C_CR2_FREQ_SET(cr2, pclk / 1000000);
  cr2 |= STM32F4_I2C_CR2_ITEVTEN;
  cr2 |= STM32F4_I2C_CR2_ITBUFEN;
  regs->cr2 = cr2;

  cr1 = regs->cr1;
  cr1 |= STM32F4_I2C_CR1_PE;
  regs->cr1 = cr1;

  return RTEMS_SUCCESSFUL;
}
Esempio n. 27
0
rtems_task Init(
  rtems_task_argument ignored
)
{
  int                  status, ceiling, old_ceiling;
  rtems_id             Mutex_id, Task_id;

  puts( "\n\n*** TEST 66 ***" );

  /*
   *  Create binary semaphore (a.k.a. Mutex) with Priority Ceiling
   *  attribute.
   */

  puts( "Creating semaphore" );
  status = rtems_semaphore_create(
    rtems_build_name( 's','e','m','1' ),
    1,
    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_PRIORITY_CEILING,
    1,
    &Mutex_id
  );
  directive_failed( status, "rtems_semaphore_create" );

  puts( "Calling rtems_semaphore_obtain" );
  status = rtems_semaphore_obtain( Mutex_id, RTEMS_DEFAULT_OPTIONS, 0 );
  directive_failed( status, "rtems_semaphore_obtain" );

  puts( "Calling rtems_task_create" );
  status = rtems_task_create( rtems_build_name( 'T', 'A', 'S', '1' ),
    2,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Task_id
  );
  directive_failed( status, "rtems_task_create" );

  puts( "Calling rtems_task_start" );
  status = rtems_task_start( Task_id, Task_1, (rtems_task_argument)&Mutex_id );
  directive_failed( status, "rtems_task_start" );

  sleep(1);

  puts( "Calling semaphore release" );
  status = rtems_semaphore_release( Mutex_id );
  directive_failed( status, "rtems_semaphore_release" );

  puts( "*** END OF TEST 66 ***" );

  rtems_test_exit(0);
}
Esempio n. 28
0
void init_renderer(void)
{
	rtems_status_code sc;

	sc = rtems_semaphore_create(
		rtems_build_name('P', 'T', 'C', 'H'),
		1,
		RTEMS_SIMPLE_BINARY_SEMAPHORE,
		0,
		&patch_lock
	);
	assert(sc == RTEMS_SUCCESSFUL);
}
Esempio n. 29
0
File: init.c Progetto: gedare/rtems
static void create_sema(rtems_id *id)
{
  rtems_status_code sc;

  sc = rtems_semaphore_create(
    rtems_build_name('S', 'E', 'M', 'A'),
    1,
    RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
    0,
    id
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Esempio n. 30
0
static int graes_device_init(struct graes_priv *pDev)
{
	struct amba_dev_info *ambadev;
	struct ambapp_core *pnpinfo;

	/* Get device information from AMBA PnP information */
	ambadev = (struct amba_dev_info *)pDev->dev->businfo;
	if ( ambadev == NULL ) {
		return -1;
	}
	pnpinfo = &ambadev->info;
	pDev->irq = pnpinfo->irq;
	pDev->regs = (struct graes_regs *)pnpinfo->apb_slv->start;
	pDev->minor = pDev->dev->minor_drv;
	pDev->open = 0;
	pDev->running = 0;

	/* Create Binary RX Semaphore with count = 0 */
	if ( rtems_semaphore_create(rtems_build_name('G', 'P', 'R', '0' + pDev->minor),
		0,
		RTEMS_FIFO|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY|\
		RTEMS_LOCAL|RTEMS_NO_PRIORITY_CEILING, 
		0,
		&pDev->sem_rx) != RTEMS_SUCCESSFUL ) {
		return -1;
	}

	/* Allocate Memory for Descriptors */
#ifdef REMOTE_DESCRIPTORS
	pDev->bds = 0xc0800000;
	pDev->_bds = 0xc0800000;
#else
	pDev->bds = (struct graes_bd *)graes_memalign(GRAES_BDAR_SIZE, GRAES_BDAR_SIZE, &pDev->_bds);
#endif
	if ( !pDev->bds ) {
		DBG("GRAES: Failed to allocate descriptor table\n");
		return -1;
	}
	memset(pDev->bds, 0, GRAES_BDAR_SIZE);

	pDev->_ring = malloc(sizeof(struct graes_ring) * GRAES_BDAR_ENTRIES);
	if ( !pDev->_ring ) {
		DBG("GRAES: Failed to allocate ring\n");
		return -1;
	}

	/* Reset Hardware before attaching IRQ handler */
	graes_hw_reset(pDev);

	return 0;
}