コード例 #1
0
ファイル: IntSemTest.c プロジェクト: peterliu2/tivaWare
static void vInterruptCountingSemaphoreTask( void *pvParameters )
{
    BaseType_t xCount;
    const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) * ( intsemMAX_COUNT + 1 );

    ( void ) pvParameters;

    for( ;; ) {
        /* Expect to start with the counting semaphore empty. */
        if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 ) {
            xErrorDetected = pdTRUE;
        }

        /* Wait until it is expected that the interrupt will have filled the
        counting semaphore. */
        xOkToGiveCountingSemaphore = pdTRUE;
        vTaskDelay( xDelay );
        xOkToGiveCountingSemaphore = pdFALSE;

        /* Now it is expected that the counting semaphore is full. */
        if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != intsemMAX_COUNT ) {
            xErrorDetected = pdTRUE;
        }

        if( uxQueueSpacesAvailable( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 ) {
            xErrorDetected = pdTRUE;
        }

        ulCountingSemaphoreLoops++;

        /* Expect to be able to take the counting semaphore intsemMAX_COUNT
        times.  A block time of 0 is used as the semaphore should already be
        there. */
        xCount = 0;
        while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS ) {
            xCount++;
        }

        if( xCount != intsemMAX_COUNT ) {
            xErrorDetected = pdTRUE;
        }

        /* Now raise the priority of this task so it runs immediately that the
        semaphore is given from the interrupt. */
        vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );

        /* Block to wait for the semaphore to be given from the interrupt. */
        xOkToGiveCountingSemaphore = pdTRUE;
        xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
        xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
        xOkToGiveCountingSemaphore = pdFALSE;

        /* Reset the priority so as not to disturbe other tests too much. */
        vTaskPrioritySet( NULL, tskIDLE_PRIORITY );

        ulCountingSemaphoreLoops++;
    }
}
コード例 #2
0
ファイル: sendDataTask.c プロジェクト: jeremydu/plugandsee
/*
 * sendDataTask read data from xQueueOutput and send them
 * to the mobile application through the Bluetooth module
 * (UART interface for now is used)
 */
void sendDataTask(void *pvParameters) {

	uint8_t flag = FANION;
	uint8_t buff[MAX_XQUEUEOUTPUT];
	memset(buff, 0, sizeof(buff));

#ifdef DEBUG_MODE
	UART_Send(LPC_UART0, "sendDataTask launched\r\n", strlen("sendDataTask launched\r\n"), NONE_BLOCKING);
#endif

	for(;;) {
		if(xQueueOutput != 0) { // xQueueOutput MUST be valid
			vTaskDelay((PERIOD/portTICK_PERIOD_MS));

			if(uxQueueMessagesWaiting(xQueueOutput) > 0) {
				xQueueReceive(xQueueOutput, buff, (TickType_t) 0);
				UART_Send(LPC_UART0, &flag, 1, NONE_BLOCKING);
				UART_Send(LPC_UART0, buff, sizeof(buff), NONE_BLOCKING);
			}
		}else {
			UART_Send(LPC_UART0, &flag, 1, NONE_BLOCKING);
			UART_Send(LPC_UART0, "Error - xQueueOutput not valid", strlen("Error - xQueueOutput not valid"), NONE_BLOCKING);
		}
	}
}
コード例 #3
0
ファイル: sys_arch.c プロジェクト: samutronics/robohome
/**
 * Destroys a mailbox.
 *
 * @param mbox is the mailbox to be destroyed.
 */
void
sys_mbox_free(sys_mbox_t *mbox)
{
  /* There should not be any messages waiting (if there are it is a bug).  If
     any are waiting, increment the mailbox error count. */
#if RTOS_FREERTOS
  if(uxQueueMessagesWaiting(mbox->queue) != 0) {
#endif /* RTOS_FREERTOS */

#if SYS_STATS
    STATS_INC(sys.mbox.err);
#endif /* SYS_STATS */
  }

	/* Find a semaphore that would be freed. */
	u32_t i;
	for(i = 0; i < SYS_MBOX_MAX; i++) {
		if(mboxes[i].queue == mbox->queue) {
			mboxes[i].queue = SYS_MBOX_NULL;
			vSemaphoreDelete(mbox->queue);
			mbox->queue = 0;
			return;
		}
	}

  /* Clear the queue handle. */
  mbox->queue = 0;

  /* Update the mailbox statistics. */
#if SYS_STATS
   STATS_DEC(sys.mbox.used);
#endif /* SYS_STATS */
}
コード例 #4
0
ファイル: serial2.c プロジェクト: YTakami/makecontroller
/**	
	Returns a single character from the receive queue if available.  This character is returned
  unsigned - i.e. having a value of 0 - 255.  The return value is -1 if there is no character waiting.
  @return character from the queue or -1 if there is no character.
*/
int Serial2_GetChar( int index )
{
  if ( index < 0 || index > 1 )
    return CONTROLLER_ERROR_ILLEGAL_INDEX;

  Serial2_* s2p = &Serial2[ index ];

  if ( s2p->users == 0 )
  {
    int status = Serial2_SetActive( index, 1 );
    if ( status != CONTROLLER_OK )
      return -1;
  }

  if ( uxQueueMessagesWaiting( s2p->receiveQueue ) )
  {
    unsigned char c;
    if( xQueueReceive( s2p->receiveQueue, &c, 0 ) == 0 )
      return -1;
    else
      return (int)c;
  }
  else
    return -1; 
}
コード例 #5
0
ファイル: Sensor.c プロジェクト: yguo89/RTOS
// *************** Sensor_HasMessage *************** 
int Sensor_HasMessage( PORT_T *port )
{
	if(uxQueueMessagesWaiting( (xQueueHandle)port->rx_fifo ) > 0) 
		return SENSOR_TRUE;
	else
		return SENSOR_FALSE;
}	
コード例 #6
0
ファイル: hd44780.c プロジェクト: RomanGrekov/I7_RTOS
void prvLcdShow( void *pvParameters )
{
    uint8_t symb, buffer_cnt=0, el_in_queue=0;
    portBASE_TYPE xStatus;

    while(1){
    	el_in_queue = uxQueueMessagesWaiting(xQueueLCD);
    	if(el_in_queue > 0){
    		if(xSemaphoreTake(xLcdMutex, portMAX_DELAY) == pdPASS){
            	while(el_in_queue > 0){
            		if(xQueueReceive(xQueueLCD, &symb, 0) == pdPASS){
            			if (buffer_cnt == 32){
							lcd_clrscr();
							buffer_cnt = 0;
						}
						if(buffer_cnt == 16){
							lcd_goto(2,0);
						}
						lcd_putc(symb);
						buffer_cnt++;
						el_in_queue--;
            		}
            	}
            	xSemaphoreGive(xLcdMutex);
    		}
    	}
    }
}
コード例 #7
0
ファイル: AC_TX.c プロジェクト: ShaohuiZhu/Haier-1
/***
************************************************
函数名:vTaskFillFrame
参数  :
返回值:
描述  :填写点击屏幕产生的数据帧
************************************************
***/
void vTaskFillFrame( void* pvParam )
{
	TP_DATA buf ;
	static MSG_A1_OUT temp ;
	//static u8 A1[7] = { 0X5A, 0X08, 0XFF, 0XFF, 0XFF, 0XFF, 0XA1 } ; 
	Uart_putstr( "vTaskFillFrame start " ) ;
	while(1)
	{
		
		xQueueReceive( xqh_Tpdata, &buf, portMAX_DELAY ) ;  
		//*
		Buf_A1_OUT.client_ID = Get_clientID() ;
		//屏幕点击产生数据填写
		Buf_A1_OUT.feature_ID = buf.allorsg << 3 ;
		Buf_A1_OUT.feature_ID |= buf.id << 4  ;
		Buf_A1_OUT.btA |= buf.temperature << 4 ;        //A1同报btA的高四位为温度
		Buf_A1_OUT.btA |= buf.runmode << 1 ;						//A1同报btA的D3~D1为模式
		Buf_A1_OUT.btA |= buf.windupdown ;	            //A1同报btA的最低位为上下白凤
		Buf_A1_OUT.btB |= buf.envtemperature << 2 ;	    //A1同报 btB 的7~2位为环境温度
		Buf_A1_OUT.btC |= buf.windspeed << 4 ;
		Buf_A1_OUT.btC |= buf.windleftright << 4 ;			
		
		//特殊设定填写
		Buf_A1_OUT.btB |= Registing[buf.id].speset.eding ;
		Buf_A1_OUT.btD |= Registing[buf.id].speset.adress_allow_set << 3 ;
		Buf_A1_OUT.btD |= Registing[buf.id].speset.jingyadangshu << 1 ;
		Buf_A1_OUT.checksum = CheckingSum( (u8*)&Buf_A1_OUT, 7 ) ;
		//*/
		while( uxQueueMessagesWaiting(xqh_Tpframe) )    
			xQueueReceive( xqh_Tpframe, &temp, portMAX_DELAY ) ;   //覆盖原有邮件
		memcpy( (void*)((u8*)&temp), (void*)((u8*)&Buf_A1_OUT), 7 ) ;  //传递拷贝份,避免在发送数据过程中,buf_a1_out被重写
		xQueueSend( xqh_Tpframe, (void*)&temp, 0 ) ;
	}
}
コード例 #8
0
void get_uart_commands(void)
/*****************************************************************************
*   Function : Parses commands from UART.
*****************************************************************************/
{
	portBASE_TYPE status;
	uart_command c;
	
	// Evenst from UART
	if(uxQueueMessagesWaiting(uart_command_queue) != 0)
	{
		status = xQueueReceive(uart_command_queue, &c, 0);
		
		if(status == pdPASS)
		{
			switch ( c.type )
			{
				case UART_COMMAND_POSITION:
					switch ( c.key )
					{
						case UART_COMMAND_X_AXIS:
						if(c.value >= 0 && c.value <= 1079)
						{
							write_5_char_int_to_buffer (11, 0, c.value ); // Disable on production
							xSemaphoreTake(x_pos_mutex, portMAX_DELAY );
							x_target_pos = c.value;
							xSemaphoreGive(x_pos_mutex );
						}
						break;
					}
				break;
			}
		}
	}
}
コード例 #9
0
ファイル: mailbox.c プロジェクト: silenceuncrio/ameba_ws2812b
/******************************************************************************
 * Function: RtlMailboxMsgWaiting
 * Desc: To get the number of message blocks are storing in a given mailbox.
 * Para:
 *  MboxID: The identifier of the target mailbox.
 *  IsFromISR: Is this function is called from an ISR ?
 * Return: The number of message blocks are storing in this mailbox.
 ******************************************************************************/
u32 RtlMailboxMsgWaiting(
    IN u8 MboxID, 
    IN u8 IsFromISR
)
{
	RTL_MAILBOX *pMbox=NULL;
    u32 msg_num=0;

	pMbox = RtlMBoxIdToHdl(MboxID);

	if (NULL == pMbox) {
		MSG_MBOX_ERR("RtlMailboxMsgWaiting: Didn't find the MBox with ID=%d\n", MboxID);
		return 0;
	}

#ifdef PLATFORM_FREERTOS
    if (IsFromISR) {
        msg_num = uxQueueMessagesWaitingFromISR(pMbox->mbox_hdl);
    }
    else {
        msg_num = uxQueueMessagesWaiting(pMbox->mbox_hdl);
    }
#endif

#ifdef PLATFORM_ECOS
    // TODO: call eCos API to implement this function
#endif

    return msg_num;

}
コード例 #10
0
bool BufferCapacity()
{
	unsigned portBASE_TYPE uxBufLen = uxQueueMessagesWaiting(s_QueueBuff);
	if (uxBufLen < 128)
		return false;
	return true;
}
コード例 #11
0
ファイル: serial.c プロジェクト: YTakami/makecontroller
/**	
	Returns a single character from the receive queue if available.
  This character is returned unsigned - i.e. having a value of 0 - 255.  
  The return value is -1 if there is no character waiting.
  @param index Which serial port - SERIAL_0 or SERIAL_1
  @return character from the queue or -1 if there is no character.
*/
int Serial_GetChar( int index )
{
  if ( index < 0 || index >= SERIAL_PORTS )
    return CONTROLLER_ERROR_ILLEGAL_INDEX;

  Serial_* sp = &Serial[ index ];

  if ( !sp->active )
  {
    int status = Serial_SetActive( index, 1 );
    if ( status != CONTROLLER_OK )
      return -1;
  }

  if ( uxQueueMessagesWaiting( sp->receiveQueue ) )
  {
    unsigned char c;
    if( xQueueReceive( sp->receiveQueue, &c, 0 ) == 0 )
      return -1;
    else
      return (int)c;
  }
  else
    return -1; 
}
コード例 #12
0
ファイル: freertos_ex11.c プロジェクト: hokim72/XIL_EDK
static void vReceiverTask(void* pvParameters)
{
	// Declare the structure that will hold the values received from the queue.
	xData xReceivedStructure;
	portBASE_TYPE xStatus;

	// This task is also defined within an infinite loop.
	for (;;)
	{
		// Because it has the lowest priority this task will only run when the
		// sending tasks are in the Blocked state. The sending tasks will only
		// enter the Blocked state when the queue is full so this task always
		// expects the number of items in the queue to be equal to the queue
		// length - 3 in this case.
		if ( uxQueueMessagesWaiting(xQueue) != 3)
		{
			vTaskSuspendAll();
			xil_printf("Queue should have been full!\n");
		}

		// Receive from the queue.

		// The second parameter is the buffer into which the received data will
		// be placed. In this case the buffer is simply the address of a variable
		// that has the required size to hold the received structure.
		
		// The last parameter is the block time - the maximum amount of time 
		// that the task will remain in the Blocked state to wait for data to
		// be available if the queue is already empty. In this case a block time
		// is not necessary because this task will only run when queue is full.
		xStatus = xQueueReceive(xQueue, &xReceivedStructure, 0);

		if (xStatus == pdPASS)
		{
			// Data was successfully received from the queue, print out the
			// received value and the source of the value.
			if (xReceivedStructure.ucSource == mainSENDER_1)
			{
				vTaskSuspendAll();
				xil_printf("From Sender 1 = %d\n", xReceivedStructure.ucValue);
				xTaskResumeAll();
			}
			else
			{
				vTaskSuspendAll();
				xil_printf("From Sender 2 = %d\n", xReceivedStructure.ucValue);
				xTaskResumeAll();
			}
		}
		else
		{
			// Nothing was received from the queue. This must be an error
			// as this task should only run when the queue is full.
			vTaskSuspendAll();
			xil_printf("Could not receive from the queue.\n");
			xTaskResumeAll();
		}
	}
}
コード例 #13
0
static void updateSpindleSpeed(uint32_t speed){
    while(uxQueueMessagesWaiting( movementQueue )); // Clear Movements
    
    if(speed > 100)
        speed = 100;
    TIM_SetCompare1(TIM3, 2400 * speed / 100);
    return;
}
コード例 #14
0
inline bool frt_text_queue::check_for_char (void)
{
	if (uxQueueMessagesWaiting (the_queue) == 0)
	{
		return (false);
	}
	return (true);
}
コード例 #15
0
/**
 * Destroys a mailbox.
 *
 * @param mbox is the mailbox to be destroyed.
 */
void
sys_mbox_free(sys_mbox_t mbox)
{
  unsigned portBASE_TYPE count;

  /* There should not be any messages waiting (if there are it is a bug).  If
     any are waiting, increment the mailbox error count. */
#if RTOS_SAFERTOS
  if((xQueueMessagesWaiting(mbox->queue, &count) != pdPASS) || (count != 0)) {
#elif RTOS_FREERTOS
  if(uxQueueMessagesWaiting(mbox->queue) != 0) {
#endif /* RTOS_SAFERTOS */

#if SYS_STATS
    STATS_INC(sys.mbox.err);
#endif /* SYS_STATS */
  }

  /* Clear the queue handle. */
  mbox->queue = 0;

  /* Update the mailbox statistics. */
#if SYS_STATS
   STATS_DEC(sys.mbox.used);
#endif /* SYS_STATS */
}

/**
 * The routine for a thread.  This handles some housekeeping around the
 * applications's thread routine.
 *
 * @param arg is the index into the thread structure for this thread
 */
static void
sys_arch_thread(void *arg)
{
  u32_t i;

  /* Get this threads index. */
  i = (u32_t)arg;

  /* Call the application's thread routine. */
  threads[i].thread(threads[i].arg);

  /* Free the memory used by this thread's stack. */
  mem_free(threads[i].stackstart);

  /* Clear the stack from the thread structure. */
  threads[i].stackstart = NULL;
  threads[i].stackend = NULL;

  /* Delete this task. */
#if RTOS_SAFERTOS
  xTaskDelete(NULL);
#elif RTOS_FREERTOS
  vTaskDelete(NULL);
#endif
}
コード例 #16
0
ファイル: serial2.c プロジェクト: YTakami/makecontroller
/**	
	Returns the number of bytes in the queue waiting to be read.
  @return bytes in the receive queue.
*/
int Serial2_GetReadable( int index )
{
  if ( index < 0 || index > 1 )
    return CONTROLLER_ERROR_ILLEGAL_INDEX;

  Serial2_* s2p = &Serial2[ index ];

  return uxQueueMessagesWaiting( s2p->receiveQueue );
}
コード例 #17
0
ファイル: port.c プロジェクト: ADTL/ARMWork
unsigned portBASE_TYPE MPU_uxQueueMessagesWaiting( const xQueueHandle pxQueue )
{
portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
unsigned portBASE_TYPE uxReturn;

	uxReturn = uxQueueMessagesWaiting( pxQueue );
	portRESET_PRIVILEGE( xRunningPrivileged );
	return uxReturn;
}
コード例 #18
0
ファイル: serial.c プロジェクト: YTakami/makecontroller
/**	
	Returns the number of bytes in the queue waiting to be read.
  @param index Which serial port - SERIAL_0 or SERIAL_1
  @return bytes in the receive queue.
*/
int Serial_GetReadable( int index )
{
  if ( index < 0 || index >= SERIAL_PORTS )
    return CONTROLLER_ERROR_ILLEGAL_INDEX;

  Serial_* sp = &Serial[ index ];

  return uxQueueMessagesWaiting( sp->receiveQueue );
}
コード例 #19
0
ファイル: mpu_wrappers.c プロジェクト: sean93park/freertos
UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t pxQueue )
{
BaseType_t xRunningPrivileged = xPortRaisePrivilege();
UBaseType_t uxReturn;

	uxReturn = uxQueueMessagesWaiting( pxQueue );
	vPortResetPrivilege( xRunningPrivileged );
	return uxReturn;
}
コード例 #20
0
/* Function: uint8_t OSAL_SEM_GetCount(OSAL_SEM_HANDLE_TYPE semID)

  Summary:
    Return the current value of a counting semaphore.

  Description:
    Return the current value of a counting semaphore. The value returned is
    assumed to be a single value ranging from 0-255.

  Precondition:
     Semaphore must have been created.

  Parameters:
     semID       - The semID

  Returns:
    0           - Semaphore is unavailable
    1-255       - Current value of the counting semaphore

  Example:
    <code>
     uint8_t semCount;

     semCount = OSAL_SEM_GetCount(semUART);

     if (semCount > 0)
     {
        // obtain the semaphore
         if (OSAL_SEM_Pend(semUART) == OSAL_RESULT_TRUE)
         {
            // perform processing on the comm channel
            ...
         }
     }
     else
     {
        // no comm channels available
        ...
     }
    </code>

  Remarks:
     This version of the OSAL_SEM_Post function should be used if the program
     is, or may be, operating inside and ISR. The OSAL will take the necessary
     steps to ensure correct operation possibly disabling interrupts or entering
     a critical section. The exact requirements will depend upon the particular
     RTOS being used.
 */
uint8_t OSAL_SEM_GetCount(OSAL_SEM_HANDLE_TYPE* semID)
{
   unsigned portBASE_TYPE SemCount;
   SemCount = uxQueueMessagesWaiting(*(xSemaphoreHandle*)semID);
   if(SemCount > 255)
      SemCount = 255;
   return SemCount;

}
コード例 #21
0
ファイル: port.c プロジェクト: RitikaGupta1207/freertos
UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t pxQueue )
{
    BaseType_t xRunningPrivileged = prvRaisePrivilege();
    UBaseType_t uxReturn;

    uxReturn = uxQueueMessagesWaiting( pxQueue );
    portRESET_PRIVILEGE( xRunningPrivileged );
    return uxReturn;
}
コード例 #22
0
ファイル: sys_arch.c プロジェクト: FangDongbin/esp8266-hilink
/*
  Deallocates a mailbox. If there are messages still present in the
  mailbox when the mailbox is deallocated, it is an indication of a
  programming error in lwIP and the developer should be notified.
*/
void
sys_mbox_free(sys_mbox_t *mbox)
{
    if (uxQueueMessagesWaiting(*mbox)) {
        /* Line for breakpoint.  Should never break here! */
//		__asm volatile ( "NOP" );
    }

    vQueueDelete(*mbox);
}
コード例 #23
0
ファイル: uart2_sp5KFRTOS.c プロジェクト: spymovil/sp5K
s08 uartQueueIsEmpty(u08 nUart)
{

	switch(nUart) {
	case 0:
		if ( uxQueueMessagesWaiting(xUart0CharsForTxQueue) == 0)
			return (TRUE);
		else
			return(FALSE);

		break;
	case 1:
		if ( uxQueueMessagesWaiting(xUart1CharsForTxQueue) == 0)
			return (TRUE);
		else
			return(FALSE);

		break;
	}
}
コード例 #24
0
ファイル: xTask.c プロジェクト: NguyenTrongThinh/FindPIDCoff
void MOMENT_TASK(void *pvParameters)
{
	float Theta[3];
	float Cordinate[3];
	float F[3] = {0.0, 0.0, 20.0};
	float Phi[3];
	float Moment[3];
	portBASE_TYPE xStatus;
	CanRxMsg CanReceiveData;
	Moment_Typedef M;
	unsigned char Status;
	while(1)
	{
		if (uxQueueMessagesWaiting(CanRxQueue) != NULL)
		{
			xStatus = xQueueReceive(CanRxQueue, &CanReceiveData, 1);
			if (xStatus == pdPASS)
			{
				F[0] = CanReceiveData.Data[1];
				F[1] = CanReceiveData.Data[3];
				F[2] = CanReceiveData.Data[5];
				if (CanReceiveData.Data[0] == 0)
					F[0] = -F[0];
				if (CanReceiveData.Data[2] == 0)
					F[1] = -F[1];
				if (CanReceiveData.Data[4] == 0)
					F[2] = -F[2];
				F[2] += 18.0;
			}
		}
		Theta[0] = ((float)TSVN_QEI_TIM1_Value()*0.9)/7.0;
		Theta[1] = ((float)TSVN_QEI_TIM4_Value()*0.9)/7.0;
		Theta[2] = ((float)TSVN_QEI_TIM3_Value()*0.9)/7.0;		
		Status = (char)Delta_CalcForward(Theta[0], Theta[1], Theta[2], &Cordinate[0], &Cordinate[1], &Cordinate[2]);
		if (Status == 0)
		{
			if (Cordinate[0] >= -44.165 && Cordinate[0] <= 44.165 && 
					Cordinate[1] >= -44.165 && Cordinate[1] <= 44.165 &&
					Cordinate[2] >= -203.648 && Cordinate[2] <= -115.318)
			{
					Phi[0] = -90.0;
					Phi[1] = 30.0;
					Phi[2] = 150;
					MomentCalculate(Theta, Phi, Cordinate, F, &Moment);
					M.Mx = Moment[0]*1100.0;
					M.My = Moment[1]*1100.0;
					M.Mz = Moment[2]*1100.0;
					xQueueSendToBack(Moment_Queue, &M, 1);
			}
		}
		TSVN_Led_Toggle(LED_D6);
		vTaskDelay(200);
	}
}
コード例 #25
0
ファイル: AltPollQ.c プロジェクト: ya-mouse/freertos-np51x0
static portTASK_FUNCTION( vPolledQueueConsumer, pvParameters )
{
    unsigned portSHORT usData, usExpectedValue = ( unsigned portSHORT ) 0;
    signed portBASE_TYPE xError = pdFALSE;

#ifdef USE_STDIO
    void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );

    const portCHAR * const pcTaskStartMsg = "Alt blocking queue consumer task started.\r\n";

    /* Queue a message for printing to say the task has started. */
    vPrintDisplayMessage( &pcTaskStartMsg );
#endif

    for( ;; )
    {
        /* Loop until the queue is empty. */
        while( uxQueueMessagesWaiting( *( ( xQueueHandle * ) pvParameters ) ) )
        {
            if( xQueueAltReceive( *( ( xQueueHandle * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS )
            {
                if( usData != usExpectedValue )
                {
                    /* This is not what we expected to receive so an error has
                    occurred. */
                    xError = pdTRUE;

                    /* Catch-up to the value we received so our next expected
                    value should again be correct. */
                    usExpectedValue = usData;
                }
                else
                {
                    if( xError == pdFALSE )
                    {
                        /* Only increment the check variable if no errors have
                        occurred. */
                        portENTER_CRITICAL();
                        xPollingConsumerCount++;
                        portEXIT_CRITICAL();
                    }
                }

                /* Next time round we would expect the number to be one higher. */
                usExpectedValue++;
            }
        }

        /* Now the queue is empty we block, allowing the producer to place more
        items in the queue. */
        vTaskDelay( pollqCONSUMER_DELAY );
    }
} /*lint !e818 Function prototype must conform to API. */
コード例 #26
0
static void prvHighPriorityPeekTask( void *pvParameters )
{
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
unsigned portLONG ulValue;

	for( ;; )
	{
		/* Try peeking from the queue.  The queue should be empty so we will
		block, allowing the medium priority task to execute.  Both the high
		and highest priority tasks will then be blocked on the queue. */
		if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
		{
			/* We expected to have received something by the time we unblock. */
			xErrorDetected = pdTRUE;
		}

		/* When we get here the highest priority task should have peeked the data
		(unblocking this task) then suspended (allowing this task to also peek
		the data). */
		if( ulValue != 0x01234567 )
		{
			/* We did not receive the expected value. */
			xErrorDetected = pdTRUE;
		}

		if( uxQueueMessagesWaiting( xQueue ) != 1 )
		{
			/* The message should have been left on the queue. */
			xErrorDetected = pdTRUE;
		}

		/* We only peeked the data, so suspending ourselves now should enable
		the medium priority task to also peek the data.  The medium priority task
		will have been unblocked when we peeked the data as we left the data
		in the queue. */
		vTaskSuspend( NULL );


		/* This time we are going actually receive the value, so the medium
		priority task will never peek the data - we removed it from the queue. */
		if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
		{
			xErrorDetected = pdTRUE;
		}

		if( ulValue != 0xaabbaabb )
		{
			xErrorDetected = pdTRUE;
		}

		vTaskSuspend( NULL );				
	}
}
コード例 #27
0
ファイル: motor.c プロジェクト: bt2016/ece4534_team4
// Read value from local message queue
void receiveFromMotorQ() {
    char readdata[MSG_LENGTH];

    // Read from messages until most recent data (FIFO queue)
    while (uxQueueMessagesWaiting(motorData.motorQ_LR) != 0){
    
        if (xQueueReceive(motorData.motorQ_LR, &readdata, portMAX_DELAY))
        {
            //dbgOutputVal(MOTOR_RECEIVEFROMQ);
        } 
    }
}
コード例 #28
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_free
 *---------------------------------------------------------------------------*
 * Description:
 *      Deallocates a mailbox. If there are messages still present in the
 *      mailbox when the mailbox is deallocated, it is an indication of a
 *      programming error in lwIP and the developer should be notified.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 * Outputs:
 *      sys_mbox_t              -- Handle to new mailbox
 *---------------------------------------------------------------------------*/
void sys_mbox_free(sys_mbox_t *pxMailBox) {
    #if SYS_STATS
    unsigned long ulMessagesWaiting;
    
    ulMessagesWaiting = uxQueueMessagesWaiting( *pxMailBox );
    configASSERT( ( ulMessagesWaiting == 0 ) );

    if (ulMessagesWaiting != 0UL) {    
        SYS_STATS_INC( mbox.err );
    }
    
    SYS_STATS_DEC( mbox.used );
    
    #else
    
    uxQueueMessagesWaiting( *pxMailBox);
    
    #endif

    vQueueDelete( *pxMailBox );
}
コード例 #29
0
static void setStepperState(uint32_t state){
    while(uxQueueMessagesWaiting( movementQueue )); // Clear Movements

    if(state){
        GPIO_ResetBits(EnPinPort, XEnPin | YEnPin | ZEnPin);
    }else{
        GPIO_SetBits(EnPinPort, XEnPin | YEnPin | ZEnPin);
    }
    
    stepperState = state;
    return;
}
コード例 #30
0
ファイル: stack.c プロジェクト: SmartGrains/Murphy
/**
 *  Get buffer from stack.
 *
 *	\param blocktime  time to wait for buffer
 *
 *  \return           pointer to buffer, 0 on failure (all buffers allocated)
 */
buffer_t* stack_buffer_get ( portTickType blocktime )
{
  buffer_t *b;

  if (xQueueReceive( buffers, &( b ), 0) == pdTRUE)
	{
		b->dir = BUFFER_DOWN;
		b->buf_ptr = 0;
		b->buf_end = 0;
		b->size = BUFFER_SIZE;
		buffer_left--;
		if (uxQueueMessagesWaiting(buffers) == 0){b->options.last_buffer_when_pulled = 1;}else{b->options.last_buffer_when_pulled = 0;}

#ifdef CHECK_BUFFERS
		del_from_buffer(b, avail_buffers);
#endif /* CHECK_BUFFERS */
		return b;
	}
    else if (xQueueReceive( buffers, &( b ), blocktime / portTICK_RATE_MS) == pdTRUE)
	{
		b->dir = BUFFER_DOWN;
		b->buf_ptr = 0;
		b->buf_end = 0;
		b->size = BUFFER_SIZE;
		buffer_left--;
		if (uxQueueMessagesWaiting(buffers) == 0){b->options.last_buffer_when_pulled = 1;}else{b->options.last_buffer_when_pulled = 0;}

#ifdef CHECK_BUFFERS
		del_from_buffer(b, avail_buffers);
#endif /* CHECK_BUFFERS */
		return b;
	}
	debug_printf("S: No buffer left (%d)\r\n", mac_tx_wr);

#ifdef HAVE_WDT
	WDTCTL  = 0; // reset chip !
#endif /* HAVE_WDG */
	return 0;
}