示例#1
0
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
0
文件: efbUart.c 项目: ORiGiNe/asserv
/* -----------------------------------------------------------------------------
 * 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
0
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
0
  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
0
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;
}
/*--------------------------------------------
| 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
0
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
0
sys_sem_t sys_sem_new(u8_t count)
{
   xSemaphoreHandle handle = xSemaphoreCreateCounting(255, count);

   if (handle == NULL)
      return SYS_SEM_NULL;
   
   return handle;
}
示例#9
0
void AnalyzerControl::StartTask()
{
	_semaphore = xSemaphoreCreateCounting(1, 1);
	_needconfiguration = false;
	_needanalysis = 0;
	_analysiscomplete = false;

	xTaskCreate(vAnalyzerControlTask, "analyzercontrol", 512, NULL, 2 /* priority */, NULL);
}
示例#10
0
void Lock_Initialize( Lock *m )
{
    /*
     * sm = new Semaphore( );
     * sm.count = 1;
     * sm.limit = 1;
     */
    m->sm = xSemaphoreCreateCounting( 1, 1 );
}
/*! \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
0
/**
 * 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();
}
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;
}
/*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
0
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;
}
示例#16
0
/**
* @brief Create and Initialize a Semaphore object used for managing resources
* @param semaphore_def semaphore definition referenced with \ref osSemaphore.
* @param count         number of available resources.
* @retval  semaphore ID for reference by other functions or NULL in case of error.
* @note   MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
*/
osSemaphoreId osSemaphoreCreate (osSemaphoreDef_t *semaphore_def, int32_t count)
{
  (void) semaphore_def;
  osSemaphoreId sema;
  
  if (count == 1) {
    vSemaphoreCreateBinary(sema);
    return sema;
  }
  
  return xSemaphoreCreateCounting(count, count);
}
示例#17
0
/**
 * create the semaphore for signallizing wake-up source
 * @param  semaphore pointer which should be pointed to the new semaphore
 * @return           status flag
 */
static osa_status_t power_CreateBinSema(semaphore_t* semaphore )
{
    assert( semaphore );

    *semaphore = xSemaphoreCreateCounting( 0x1, 0 );

    if ( NULL == *semaphore )
    {
        return kStatus_OSA_Error;
    }
    return kStatus_OSA_Success;
}
示例#18
0
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_SemaphoreCreate
 * Description   : This function is used to create a semaphore. 
 * Return         : Semaphore handle of the new semaphore, or NULL if failed. 
  *
 *END**************************************************************************/
osaSemaphoreId_t OSA_SemaphoreCreate(uint32_t initValue)
{
#if osNumberOfSemaphores
    semaphore_t sem;
    sem = xSemaphoreCreateCounting(0xFF, initValue);
    return (osaSemaphoreId_t)sem;
#else 
    (void)initValue;
    return NULL;
#endif
    
}
示例#19
0
bool CCountingSemaphore::Create(UBaseType_t uxMaxCount, UBaseType_t uxInitialCount) {

#if (configUSE_COUNTING_SEMAPHORES == 1)
    SemaphoreHandle_t handle = NULL;
    handle = xSemaphoreCreateCounting(uxMaxCount, uxInitialCount);

    if (handle != NULL)
        Attach(handle);
#endif

    return IsValid();
}
示例#20
0
void Condition_Initialize( Condition *c )
{
    if ( c->m == NULL )
    {
        /* this.m = m; */
        Lock *m = (Lock*) malloc ( sizeof( Lock ) );
        FAIL( m == NULL, ( "Unable to allocate memory for Lock m.\r\n" ), NULL );
        IPERF_MEMALLOC_DEBUG_MSG( m, sizeof( Lock ) );
        Lock_Initialize( m );
        c->m = m;

        /* int waiters = 0; */
        c->waiters = 0;

        /*
         * s = new Semaphore( );
         * s.count = 0;
         * s.limit = 999999;
         */
        c->s = xSemaphoreCreateCounting( portMAX_DELAY, 0 );

        /*
         * x = new Semaphore( );
         * x.count = 1;
         * x.limit = 1;
         */
        c->x = xSemaphoreCreateCounting( 1, 1 );

        /*
         * h = new Semaphore( );
         * h.count = 0;
         * h.limit = 999999;
         */
        c->h = xSemaphoreCreateCounting( portMAX_DELAY, 0 );
    }
    else
    {
        fprintf( stderr, "Condition already has a lock. Unable to initialize a new lock.\r\n" );
    }
}
示例#21
0
int main()
{
    pm_enable_osc0_crystal (&AVR32_PM, FOSC0);
    pm_enable_clk0 (&AVR32_PM, OSC0_STARTUP);
    pm_switch_to_clock (&AVR32_PM, AVR32_PM_MCSEL_OSC0);

    USART_Initialize ();

    usart_write_line (&AVR32_USART0, "USART initialized\n");
    usart_write_line (&AVR32_USART0, "DIP204 initialized\n");


    Item_Available_Count = xSemaphoreCreateCounting (Item_Buffer_Count, 0);
    Space_Available_Count = xSemaphoreCreateCounting (Item_Buffer_Count, Item_Buffer_Count - 1);

    xTaskCreate (Producer_Task_Function, "Producer", 512, NULL, tskIDLE_PRIORITY + 4, &Producer_Task_Handle);
    xTaskCreate (Consumer_Task_Function, "Consumer", 512, NULL, tskIDLE_PRIORITY + 4, &Consumer_Task_Handle);
    xTaskCreate (Blinker_Task_Function, "Blinker", 512, NULL, tskIDLE_PRIORITY + 4, NULL);


    vTaskStartScheduler ();
}
示例#22
0
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 )
	{
		/* In case alternative locking is used, the mutexes can be initialised here */
		ipconfigBUFFER_ALLOC_INIT( );
/*
 * HT: The use of counting semaphores is perfect, good invention
 * It is just that I didn't find the time yet to adopt the newer FreeRTOS kernel
 * which supports it. I tried it and it crashed. Must dive into it some day
 */
		xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
		configASSERT( xNetworkBufferSemaphore );

		if( xNetworkBufferSemaphore != NULL )
		{
			vListInitialise( &xFreeBuffersList );

			/* Initialise all the network buffers.  The buffer storage comes
			from the network interface, and different hardware has different
			requirements. */
			vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers );
			for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
			{
				/* Initialise and set the owner of the buffer list items. */
				vListInitialiseItem( &( xNetworkBuffers[ x ].xBufferListItem ) );
				listSET_LIST_ITEM_OWNER( &( xNetworkBuffers[ x ].xBufferListItem ), &xNetworkBuffers[ x ] );

				/* Currently, all buffers are available for use. */
				vListInsert( &xFreeBuffersList, &( xNetworkBuffers[ x ].xBufferListItem ) );
			}
			
			uxMinimumFreeNetworkBuffers = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
		}
	}

	if( xNetworkBufferSemaphore == NULL )
	{
		xReturn = pdFAIL;
	}
	else
	{
		xReturn = pdPASS;
	}

	return xReturn;
}
示例#23
0
unsigned char Application_Init(void)
{
	unsigned int PWM_Max_Value = 0;
	PIDCoff Coff_MOTOR = {0, 0, 0};

	TSVN_FOSC_Init();
	TSVN_Led_Init(ALL);
	TSVN_ACS712_Init();
	
	TSVN_QEI_TIM1_Init(400);
	TSVN_QEI_TIM3_Init(400);
	TSVN_QEI_TIM4_Init(400);
	
	TSVN_CAN_Init();
	TSVN_USART_Init();
	TSVN_TIM6_Init(2000);
	
	FIR_Init();
	
	PWM_Max_Value = TSVN_PWM_TIM5_Init(5000);
	
	TSVN_PWM_TIM5_Set_Duty(0, MOTOR1_PWM);
	TSVN_PWM_TIM5_Set_Duty(0, MOTOR2_PWM);
	TSVN_PWM_TIM5_Set_Duty(0, MOTOR3_PWM);
	TSVN_PWM_TIM5_Start();
	
	DIR_Init();
	
	PID_Mem_Create(3);
	PID_WindUp_Init(MOTOR1, PWM_Max_Value);
	PID_WindUp_Init(MOTOR2, PWM_Max_Value);
	PID_WindUp_Init(MOTOR3, PWM_Max_Value);
	Coff_MOTOR.Kp = 4;
	Coff_MOTOR.Ki = 0.01;
	Coff_MOTOR.Kd = 0.0;
	PID_Init(MOTOR1, Coff_MOTOR);
	PID_Init(MOTOR2, Coff_MOTOR);
	PID_Init(MOTOR3, Coff_MOTOR);
	Pos_Queue = xQueueCreate(200, sizeof(Pos_TypeDef));
	CanRxQueue = xQueueCreate(200, sizeof(CanRxMsg));
	Moment_Queue = xQueueCreate(200, sizeof(Moment_Typedef));
	RxQueue = xQueueCreate(200, sizeof(xData));
	
	UART_xCountingSemaphore = xSemaphoreCreateCounting(200, 0);
	
	if (Pos_Queue != NULL && CanRxQueue != NULL  &&
			Moment_Queue != NULL && UART_xCountingSemaphore != NULL && RxQueue != NULL)
		return SUCCESS;
	return ERROR;
}
示例#24
0
// This function simply creates a message queue and a semaphore
int initOSDataStructs(void)
{
	thres_freq = 49.00;
	thres_delta = 25.00;
	load_stability_flag = 0;

	x_sem_loads = xSemaphoreCreateBinary();
	Q_freq_data = xQueueCreate( 100, sizeof( struct freq_struct) );
	stability_queue = xQueueCreate( MSG_QUEUE_SIZE, sizeof( int) );
	load_mngmnt_queue = xQueueCreate( MSG_QUEUE_SIZE, sizeof( int) );
	msgqueue = xQueueCreate( MSG_QUEUE_SIZE, sizeof( void* ) );
	shared_resource_sem = xSemaphoreCreateCounting( 9999, 1 );
	return 0;
}
示例#25
0
static void prvExerciseSemaphoreAPI( void )
{
SemaphoreHandle_t xSemaphore;
const UBaseType_t uxMaxCount = 5, uxInitialCount = 0;

	/* Most of the semaphore API is common to the queue API and is already being
	used.  This function uses a few semaphore functions that are unique to the
	RTOS objects, rather than generic and used by queues also.

	First create and use a counting semaphore. */
	xSemaphore = xSemaphoreCreateCounting( uxMaxCount, uxInitialCount );
	configASSERT( xSemaphore );

	/* Give the semaphore a couple of times and ensure the count is returned
	correctly. */
	xSemaphoreGive( xSemaphore );
	xSemaphoreGive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 2 );
	vSemaphoreDelete( xSemaphore );

	/* Create a recursive mutex, and ensure the mutex holder and count are
	returned returned correctly. */
	xSemaphore = xSemaphoreCreateRecursiveMutex();
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphore );
	xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
	xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetHandle( mainTASK_TO_DELETE_NAME ) );
	xSemaphoreGiveRecursive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
	xSemaphoreGiveRecursive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
	vSemaphoreDelete( xSemaphore );

	/* Create a normal mutex, and sure the mutex holder and count are returned
	returned correctly. */
	xSemaphore = xSemaphoreCreateMutex();
	configASSERT( xSemaphore );
	xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
	xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); /* Not recursive so can only be 1. */
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
	xSemaphoreGive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
	vSemaphoreDelete( xSemaphore );
}
示例#26
0
/*
  Counting semaphore functions
*/
feabhOS_error feabhOS_counting_semaphore_create(feabhOS_COUNTING_SEMAPHORE * const pSemaphore, 
                                                num_elements_t max_count, 
                                                num_elements_t init_count)
{
  feabhOS_COUNTING_SEMAPHORE self;

  self = getCountingInstance();
  if(self == NULL) return ERROR_MEMORY;
  
  self->semaphore = xSemaphoreCreateCounting((portBASE_TYPE)max_count, (portBASE_TYPE)init_count);
  if(self->semaphore == 0) return ERROR_MEMORY;

  *pSemaphore = self;
  return ERROR_OK;
}
示例#27
0
void start_web_server()
{
    	printf("\r\nWEB:Enter start web server!\n");
	webs_terminate = 0;
	if(webs_task == NULL)
	{
		if(xTaskCreate(vBasicWEBServer, (const char *)"web_server", STACKSIZE, NULL, tskIDLE_PRIORITY + 1, &webs_task) != pdPASS)
			printf("\n\rWEB: Create webserver task failed!\n");
	}
	if(webs_sema == NULL)
	{
		webs_sema = xSemaphoreCreateCounting(0xffffffff, 0);	//Set max count 0xffffffff
	}
    	//printf("\r\nWEB:Exit start web server!\n");
}
示例#28
0
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 )
	{
		/* In case alternative locking is used, the mutexes can be initialised
		here */
		ipconfigBUFFER_ALLOC_INIT();

		xNetworkBufferSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
		configASSERT( xNetworkBufferSemaphore );

		if( xNetworkBufferSemaphore != NULL )
		{
			vListInitialise( &xFreeBuffersList );

			/* Initialise all the network buffers.  The buffer storage comes
			from the network interface, and different hardware has different
			requirements. */
			vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers );
			for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
			{
				/* Initialise and set the owner of the buffer list items. */
				vListInitialiseItem( &( xNetworkBuffers[ x ].xBufferListItem ) );
				listSET_LIST_ITEM_OWNER( &( xNetworkBuffers[ x ].xBufferListItem ), &xNetworkBuffers[ x ] );

				/* Currently, all buffers are available for use. */
				vListInsert( &xFreeBuffersList, &( xNetworkBuffers[ x ].xBufferListItem ) );
			}

			uxMinimumFreeNetworkBuffers = ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
		}
	}

	if( xNetworkBufferSemaphore == NULL )
	{
		xReturn = pdFAIL;
	}
	else
	{
		xReturn = pdPASS;
	}

	return xReturn;
}
/**
* @brief Create and Initialize a Semaphore object used for managing resources
* @param semaphore_def semaphore definition referenced with \ref osSemaphore.
* @param count         number of available resources.
* @retval  semaphore ID for reference by other functions or NULL in case of error.
* @note   MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
*/
osSemaphoreId osUserDefinedSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count)
{
  (void) semaphore_def;
  osSemaphoreId sema;
  
  if (count == 1) {
    vSemaphoreCreateBinary(sema);
    return sema;
  }

#if (configUSE_COUNTING_SEMAPHORES == 1 )	
  return xSemaphoreCreateCounting(count, count);
#else
  return NULL;
#endif
}
示例#30
0
static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void )
{
SemaphoreHandle_t xSemaphore;
const UBaseType_t uxMaxCount = ( UBaseType_t ) 10;

/* StaticSemaphore_t is a publicly accessible structure that has the same size
and alignment requirements as the real semaphore structure.  It is provided as a
mechanism for applications to know the size of the semaphore (which is dependent
on the architecture and configuration file settings) without breaking the strict
data hiding policy by exposing the real semaphore internals.  This
StaticSemaphore_t variable is passed into the xSemaphoreCreateCountingStatic()
function calls within this function.  NOTE: In most usage scenarios now it is
faster and more memory efficient to use a direct to task notification instead of
a counting semaphore.  http://www.freertos.org/RTOS-task-notifications.html */
StaticSemaphore_t xSemaphoreBuffer;

	/* Create the semaphore.  xSemaphoreCreateCountingStatic() has one more
	parameter than the usual xSemaphoreCreateCounting() function.  The parameter
	is a pointer to the pre-allocated StaticSemaphore_t structure, which will
	hold information on the semaphore in an anonymous way.  If the pointer is
	passed as NULL then the structure will be allocated dynamically, just as
	when xSemaphoreCreateCounting() is called. */
	xSemaphore = xSemaphoreCreateCountingStatic( uxMaxCount, 0, &xSemaphoreBuffer );

	/* The semaphore handle should equal the static semaphore structure passed
	into the xSemaphoreCreateBinaryStatic() function. */
	configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );

	/* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
	prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );

	/* Delete the semaphore again so the buffers can be reused. */
	vSemaphoreDelete( xSemaphore );

	#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
	{
		/* Now do the same but using dynamically allocated buffers to ensure the
		delete functions are working correctly in both the static and dynamic
		allocation cases. */
		xSemaphore = xSemaphoreCreateCounting( uxMaxCount, 0 );
		configASSERT( xSemaphore != NULL );
		prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );
		vSemaphoreDelete( xSemaphore );
	}
	#endif
}