本文整理汇总了C++中xSemaphoreCreateCounting函数的典型用法代码示例。如果您正苦于以下问题:C++ xSemaphoreCreateCounting函数的具体用法?C++ xSemaphoreCreateCounting怎么用?C++ xSemaphoreCreateCounting使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xSemaphoreCreateCounting函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vStartCountingSemaphoreTasks
void vStartCountingSemaphoreTasks( void )
{
/* Create the semaphores that we are going to use for the test/demo. The
first should be created such that it starts at its maximum count value,
the second should be created such that it starts with a count value of zero. */
xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE );
xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT;
xParameters[ 0 ].uxLoopCounter = 0;
xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );
xParameters[ 1 ].uxExpectedStartCount = 0;
xParameters[ 1 ].uxLoopCounter = 0;
/* Were the semaphores created? */
if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) )
{
/* vQueueAddToRegistry() adds the semaphore to the registry, if one is
in use. The registry is provided as a means for kernel aware
debuggers to locate semaphores and has no purpose if a kernel aware
debugger is not being used. The call to vQueueAddToRegistry() will be
removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
defined or is defined to be less than 1. */
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" );
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" );
/* Create the demo tasks, passing in the semaphore to use as the parameter. */
xTaskCreate( prvCountingSemaphoreTask, "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL );
xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL );
}
}
示例2: EFBuart0Init
/* -----------------------------------------------------------------------------
* EFBuart0Init
*
* Initilizes an activates UART0 at given Baud Rate (in BPS).
* Also defines a byte that should be watched during reception
* -----------------------------------------------------------------------------
*/
void EFBuart0Init (uint32_t baudRate, tEFBboolean doubleTransmissionSpeed, uint8_t byteToWatch)
{
EFBInitUartControlStruct (gEFBuartControl0);
sEFBuart0ByteToWatch = byteToWatch;
if (doubleTransmissionSpeed)
{
// Enable double transmission speed
EFBoutPort (UART0_STATUS_CTRL_A, _BV (UART0_BIT_U2X));
// Configure bitRate
EFBoutPort (UBRR0L, (byte)EFBuartConvertDoubleSpeedBaudRate (baudRate, F_CPU));
}
else
{
// Configure bitRate
EFBoutPort (UBRR0L, (byte)EFBuartConvertBaudRate (baudRate, F_CPU));
}
// Enable UART receiver, transmitter, and enable RX Complete Interrupt
EFBoutPort (UART0_STATUS_CTRL_B, _BV (UART0_BIT_RXCIE)
| _BV (UART0_BIT_TXEN)
| _BV (UART0_BIT_RXEN));
/* Set frame format: asynchronous, 8data, no parity, 1stop bit */
// Configure UART frame to asyncronous, 1-bit stop, no parity, 8 bit data
EFBoutPort (UART0_STATUS_CTRL_C, _BV (UART0_BIT_UCSZ0) | _BV (UART0_BIT_UCSZ1));
#if defined (EFBGENE_FREERTOS)
UART0_RxSemaphore = xSemaphoreCreateCounting (UART0_RX_BUFFER_SIZE, 0);
#endif // EFBGENE_FREERTOS
} // EFBuart0Init
示例3: xNetworkInterfaceInitialise
BaseType_t xNetworkInterfaceInitialise( void )
{
const TickType_t x5_Seconds = 5000UL;
if( xEMACTaskHandle == NULL )
{
prvGMACInit();
/* Wait at most 5 seconds for a Link Status in the PHY. */
xGMACWaitLS( pdMS_TO_TICKS( x5_Seconds ) );
/* The handler task is created at the highest possible priority to
ensure the interrupt handler can return directly to it. */
xTaskCreate( prvEMACHandlerTask, "EMAC", configEMAC_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &xEMACTaskHandle );
configASSERT( xEMACTaskHandle );
}
if( xTxBufferQueue == NULL )
{
xTxBufferQueue = xQueueCreate( GMAC_TX_BUFFERS, sizeof( void * ) );
configASSERT( xTxBufferQueue );
}
if( xTXDescriptorSemaphore == NULL )
{
xTXDescriptorSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) GMAC_TX_BUFFERS, ( UBaseType_t ) GMAC_TX_BUFFERS );
configASSERT( xTXDescriptorSemaphore );
}
/* When returning non-zero, the stack will become active and
start DHCP (in configured) */
return ( ulPHYLinkStatus & BMSR_LINK_STATUS ) != 0;
}
示例4: main
int main()
{
PINSEL0 = 0x00000000; // Reset all pins as GPIO
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
Init_Peripherals();
UART0_SendStr("\t\tCounting Semaphore\n");
xSemaphore = xSemaphoreCreateCounting( 5, 5 );
if( xSemaphore != NULL )
{ UART0_SendStr("\tSemaphore Created\n");
xTaskCreate(vfork,"Philospher 1", 300 ,"P1", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 2", 300 ,"P2", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 3", 300 ,"P3", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 4", 300 ,"P4", tskIDLE_PRIORITY + 1, NULL);//Task Creation
xTaskCreate(vfork,"Philospher 5", 300 ,"P5", tskIDLE_PRIORITY + 1, NULL);//Task Creation
vTaskStartScheduler(); //Task Scheduling
}
while(1)//Never reaches this Part of the main
{UART0_SendStr("\t\tSemaphore not Created\n"); }
}
示例5: main
int main( void )
{
/* Before a semaphore is used it must be explicitly created. In this example
a counting semaphore is created. The semaphore is created to have a maximum
count value of 10, and an initial count value of 0. */
xCountingSemaphore = xSemaphoreCreateCounting( 10, 0 );
/* Check the semaphore was created successfully. */
if( xCountingSemaphore != NULL )
{
/* Enable the software interrupt and set its priority. */
prvSetupSoftwareInterrupt();
/* Create the 'handler' task. This is the task that will be synchronized
with the interrupt. The handler task is created with a high priority to
ensure it runs immediately after the interrupt exits. In this case a
priority of 3 is chosen. */
xTaskCreate( vHandlerTask, "Handler", 240, NULL, 3, NULL );
/* Create the task that will periodically generate a software interrupt.
This is created with a priority below the handler task to ensure it will
get preempted each time the handler task exist the Blocked state. */
xTaskCreate( vPeriodicTask, "Periodic", 240, NULL, 1, NULL );
/* Start the scheduler so the created tasks start executing. */
vTaskStartScheduler();
}
/* If all is well we will never reach here as the scheduler will now be
running the tasks. If we do reach here then it is likely that there was
insufficient heap memory available for a resource to be created. */
for( ;; );
return 0;
}
示例6: kernel_sem_init
/*--------------------------------------------
| Name: kernel_sem_init
| Description:
| Parameters: none
| Return Type: none
| Comments:
| See:
----------------------------------------------*/
int kernel_sem_init(kernel_sem_t* kernel_sem, int pshared, unsigned int value){
if(!kernel_sem)
return -1;
#ifdef __KERNEL_UCORE_FREERTOS
kernel_sem->sem = xSemaphoreCreateCounting( (unsigned portBASE_TYPE) (-1), (unsigned portBASE_TYPE) value);
#endif
return 0;
}
示例7: xNetworkBuffersInitialise
BaseType_t xNetworkBuffersInitialise( void )
{
BaseType_t xReturn, x;
/* Only initialise the buffers and their associated kernel objects if they
have not been initialised before. */
if( xNetworkBufferSemaphore == NULL )
{
xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
configASSERT( xNetworkBufferSemaphore );
#if ( configQUEUE_REGISTRY_SIZE > 0 )
{
vQueueAddToRegistry( xNetworkBufferSemaphore, "NetBufSem" );
}
#endif /* configQUEUE_REGISTRY_SIZE */
/* If the trace recorder code is included name the semaphore for viewing
in FreeRTOS+Trace. */
#if( ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 )
{
extern QueueHandle_t xNetworkEventQueue;
vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );
vTraceSetQueueName( xNetworkBufferSemaphore, "NetworkBufferCount" );
}
#endif /* ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */
if( xNetworkBufferSemaphore != NULL )
{
vListInitialise( &xFreeBuffersList );
/* Initialise all the network buffers. No storage is allocated to
the buffers yet. */
for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
{
/* Initialise and set the owner of the buffer list items. */
xNetworkBufferDescriptors[ x ].pucEthernetBuffer = NULL;
vListInitialiseItem( &( xNetworkBufferDescriptors[ x ].xBufferListItem ) );
listSET_LIST_ITEM_OWNER( &( xNetworkBufferDescriptors[ x ].xBufferListItem ), &xNetworkBufferDescriptors[ x ] );
/* Currently, all buffers are available for use. */
vListInsert( &xFreeBuffersList, &( xNetworkBufferDescriptors[ x ].xBufferListItem ) );
}
uxMinimumFreeNetworkBuffers = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
}
}
if( xNetworkBufferSemaphore == NULL )
{
xReturn = pdFAIL;
}
else
{
xReturn = pdPASS;
}
return xReturn;
}
示例8: sys_sem_new
sys_sem_t sys_sem_new(u8_t count)
{
xSemaphoreHandle handle = xSemaphoreCreateCounting(255, count);
if (handle == NULL)
return SYS_SEM_NULL;
return handle;
}
示例9: xSemaphoreCreateCounting
void AnalyzerControl::StartTask()
{
_semaphore = xSemaphoreCreateCounting(1, 1);
_needconfiguration = false;
_needanalysis = 0;
_analysiscomplete = false;
xTaskCreate(vAnalyzerControlTask, "analyzercontrol", 512, NULL, 2 /* priority */, NULL);
}
示例10: Lock_Initialize
void Lock_Initialize( Lock *m )
{
/*
* sm = new Semaphore( );
* sm.count = 1;
* sm.limit = 1;
*/
m->sm = xSemaphoreCreateCounting( 1, 1 );
}
示例11: SEM_Init
/*! \brief Initializes module */
void SEM_Init(void) {
SemaphoreHandle_t xSemaphore = NULL;
MySem = xSemaphoreCreateCounting(AS1_INP_BUF_SIZE/NOF_BYTES_IN_TICKET,0);
//vSemaphoreCreateBinary(MySem);
if (MySem == NULL) {
for(;;); /* creation failed */
}
FRTOS1_vQueueAddToRegistry(MySem,"Semaphore")
}
示例12: low_level_init
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*
* @param netif the already initialized lwip network interface structure
* for this ethernetif
*/
static void
low_level_init(struct netif *netif)
{
portBASE_TYPE result;
// struct ethernetif *ethernetif = netif->state;
/* set MAC hardware address length */
netif->hwaddr_len = ETHARP_HWADDR_LEN;
/* set MAC hardware address */
netif->hwaddr[5] = MYMAC_1;
netif->hwaddr[4] = MYMAC_2;
netif->hwaddr[3] = MYMAC_3;
netif->hwaddr[2] = MYMAC_4;
netif->hwaddr[1] = MYMAC_5;
netif->hwaddr[0] = MYMAC_6;
/* maximum transfer unit */
netif->mtu = ETH_MTU;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
/* Do whatever else is needed to initialize interface. */
semEthTx = xSemaphoreCreateCounting((unsigned portBASE_TYPE) NUM_TX_FRAG,(unsigned portBASE_TYPE) NUM_TX_FRAG);
semEthRx = xSemaphoreCreateCounting((unsigned portBASE_TYPE) NUM_RX_FRAG,(unsigned portBASE_TYPE) 0);
if(semEthTx == NULL) {
LWIP_DEBUGF(NETIF_DEBUG,("Semaphore for ETH transmit created failed !\n\r"));
};
if(semEthRx == NULL) {
LWIP_DEBUGF(NETIF_DEBUG,("Semaphore for ETH recive created failed !\n\r"));
};
result = xTaskCreate( ethernetif_input, ( signed portCHAR * ) "EhtTsk", sizeEthif, (void *)netif, prioEthif, &xETHTsk );
if(result != pdPASS) {
LWIP_DEBUGF(NETIF_DEBUG,("Task for ETH recive created failed !\n\r "));
};
Init_EMAC();
}
示例13: CreatorSemaphore_New
CreatorSemaphore CreatorSemaphore_New(uint tokensTotal, uint tokensTaken)
{
xSemaphoreHandle result;
Creator_Assert(tokensTaken <= tokensTotal, "Bad initial number of tokens");
if (tokensTaken > tokensTotal)
{
tokensTaken = tokensTotal;
}
result = xSemaphoreCreateCounting(tokensTotal, (tokensTotal - tokensTaken));
return result;
}
示例14: OSA_SemaCreate
/*FUNCTION**********************************************************************
*
* Function Name : OSA_SemaCreate
* Description : This function is used to create a semaphore. Return
* kStatus_OSA_Success if create successfully, otherwise return kStatus_OSA_Error.
*
*END**************************************************************************/
osa_status_t OSA_SemaCreate(semaphore_t *pSem, uint8_t initValue)
{
assert(pSem);
*pSem = xSemaphoreCreateCounting(0xFF, initValue);
if (*pSem==NULL)
{
return kStatus_OSA_Error; /* creating semaphore failed */
}
return kStatus_OSA_Success;
}
示例15: osCreateSemaphore
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
{
//Create a semaphore
semaphore->handle = xSemaphoreCreateCounting(count, count);
//Check whether the returned handle is valid
if(semaphore->handle != NULL)
return TRUE;
else
return FALSE;
}