本文整理汇总了C++中rtems_semaphore_create函数的典型用法代码示例。如果您正苦于以下问题:C++ rtems_semaphore_create函数的具体用法?C++ rtems_semaphore_create怎么用?C++ rtems_semaphore_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rtems_semaphore_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doTest
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" );
}
示例2: Init
/**
* 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);
}
示例3: Init
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);
}
示例4: pfpu_initialize
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;
}
示例5: i2c_transfer_wait_sema
/* 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;
}
示例6: test_mrsp_obtain_release
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);
}
示例7: mmap_mappings_lock_create
/**
* 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;
}
示例8: OS_TimerAPIInit
/****************************************************************************************
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);
}
示例9: test_create_initially_locked_prio_inherit_sema
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);
}
示例10: Init
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);
}
示例11: test
/*
* 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 );
}
示例12: Init
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);
}
示例13: Init
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);
}
示例14: grtm_device_init
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;
}
示例15: Init
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 );
}