Example #1
0
/**
  * @brief  Rx Transfer completed callback
  * @param  None
  * @retval None
  */
void rs232RxCpltCallback()
{
	if (prvRxBuffer1State != BUFFERState_Reading && prvRxBuffer1Count < RX_BUFFER_SIZE)
	{
		prvRxBuffer1State = BUFFERState_Writing;
		prvRxBuffer1[prvRxBuffer1CurrentIndex++] = prvReceivedByte;
		prvRxBuffer1Count++;
		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer1ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer1ClearTimer, NULL);
	}
	else if (prvRxBuffer2State != BUFFERState_Reading && prvRxBuffer2Count < RX_BUFFER_SIZE)
	{
		prvRxBuffer2State = BUFFERState_Writing;
		prvRxBuffer2[prvRxBuffer2CurrentIndex++] = prvReceivedByte;
		prvRxBuffer2Count++;
		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer2ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer2ClearTimer, NULL);
	}
	else
	{
		/* No buffer available, something has gone wrong */
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
	}

	/* Continue receiving data */
	HAL_UART_Receive_IT(&UART_Handle, &prvReceivedByte, 1);
	/* Give back the semaphore now that we are done */
	xSemaphoreGiveFromISR(xSemaphore, NULL);
}
Example #2
0
/**
  * @brief  Rx Transfer completed callback
  * @param  None
  * @retval None
  */
void can2RxCpltCallback()
{
//	if ((CAN_Handle.pRxMsg->StdId == 0x321) && (CAN_Handle.pRxMsg->IDE == CAN_ID_STD) && (CAN_Handle.pRxMsg->DLC == 2))
//	{
//		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
//		volatile uint8_t test1 = CAN_Handle.pRxMsg->Data[0];
//		volatile uint8_t test2 = CAN_Handle.pRxMsg->Data[1];
//	}

	if (prvRxBuffer1State != CANBufferState_Reading && prvRxBuffer1Count < RX_BUFFER_SIZE)
	{
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
		prvRxBuffer1State = CANBufferState_Writing;
		/* Save the message */
		prvRxBuffer1[prvRxBuffer1CurrentIndex].id = CAN_Handle.pRxMsg->StdId;
		prvRxBuffer1[prvRxBuffer1CurrentIndex].dlc = CAN_Handle.pRxMsg->DLC;
		for (uint32_t i = 0; i < CAN_Handle.pRxMsg->DLC; i++)
			prvRxBuffer1[prvRxBuffer1CurrentIndex].data[i] = CAN_Handle.pRxMsg->Data[i];

		/* Increment the counters */
		prvRxBuffer1CurrentIndex++;
		prvRxBuffer1Count++;

		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer1ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer1ClearTimer, NULL);
	}
	else if (prvRxBuffer2State != CANBufferState_Reading && prvRxBuffer2Count < RX_BUFFER_SIZE)
	{
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
		prvRxBuffer2State = CANBufferState_Writing;
		/* Save the message */
		prvRxBuffer2[prvRxBuffer1CurrentIndex].id = CAN_Handle.pRxMsg->StdId;
		prvRxBuffer2[prvRxBuffer1CurrentIndex].dlc = CAN_Handle.pRxMsg->DLC;
		for (uint32_t i = 0; i < CAN_Handle.pRxMsg->DLC; i++)
			prvRxBuffer2[prvRxBuffer1CurrentIndex].data[i] = CAN_Handle.pRxMsg->Data[i];

		/* Increment the counters */
		prvRxBuffer2CurrentIndex++;
		prvRxBuffer2Count++;

		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer2ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer2ClearTimer, NULL);
	}
	else
	{
		/* No buffer available, something has gone wrong */
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
	}


	/* Receive */
	if (HAL_CAN_Receive_IT(&CAN_Handle, CAN_FIFO1) != HAL_OK)
	{
		/* Reception Error */
//		Error_Handler();
	}
}
Example #3
0
/**
 * @brief   Beep the buzzer a specified number of times
 * @param   NumOfBeeps: Number of beeps
 * @retval  None
 */
void BUZZER_BeepNumOfTimes(uint32_t NumOfBeeps)
{
  if (NumOfBeeps != 0)
  {
    prvCurrentSettings.numOfBeeps = 2*NumOfBeeps;
    /* Start the timer if it's not already started */
    if (xTimerIsTimerActive(prvBuzzerBeepTimer) == pdFALSE)
      xTimerStart(prvBuzzerBeepTimer, 100);
  }
}
Example #4
0
	BaseType_t MPU_xTimerIsTimerActive( TimerHandle_t xTimer )
	{
	BaseType_t xReturn;
	BaseType_t xRunningPrivileged = xPortRaisePrivilege();

		xReturn = xTimerIsTimerActive( xTimer );
		vPortResetPrivilege( xRunningPrivileged );

		return xReturn;
	}
uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context)
{
    app_timer_info_t * pinfo = (app_timer_info_t*)(timer_id);
    TimerHandle_t hTimer = pinfo->osHandle;
    uint32_t rtc_prescaler = portNRF_RTC_REG->PRESCALER  + 1;
    /* Get back the microseconds to wait */
    uint32_t timeout_corrected = ROUNDED_DIV(timeout_ticks * m_prescaler, rtc_prescaler);

    if (hTimer == NULL)
    {
        return NRF_ERROR_INVALID_STATE;
    }
    if (pinfo->active && (xTimerIsTimerActive(hTimer) != pdFALSE))
    {
        // Timer already running - exit silently
        return NRF_SUCCESS;
    }

    pinfo->argument = p_context;

    if (__get_IPSR() != 0)
    {
        BaseType_t yieldReq = pdFALSE;
        if (xTimerChangePeriodFromISR(hTimer, timeout_corrected, &yieldReq) != pdPASS)
        {
            return NRF_ERROR_NO_MEM;
        }

        if ( xTimerStartFromISR(hTimer, &yieldReq) != pdPASS )
        {
            return NRF_ERROR_NO_MEM;
        }

        portYIELD_FROM_ISR(yieldReq);
    }
    else
    {
        if (xTimerChangePeriod(hTimer, timeout_corrected, APP_TIMER_WAIT_FOR_QUEUE) != pdPASS)
        {
            return NRF_ERROR_NO_MEM;
        }

        if (xTimerStart(hTimer, APP_TIMER_WAIT_FOR_QUEUE) != pdPASS)
        {
            return NRF_ERROR_NO_MEM;
        }
    }

    pinfo->active = true;
    return NRF_SUCCESS;
}
/**
 * @brief Check if a timer is expired
 *
 * Call this function passing in a timer to check if that timer has expired.
 *
 * @param Timer - pointer to the timer to be checked for expiration
 * @return character - 1 = timer expired, 0 = timer not expired
 */
char expired(Timer* timer)
{

	//printf("expired: %d\r\n", pvTimerGetTimerID(((pst_TimerHandle_t)*timer)->xTimer) );
	if( xTimerIsTimerActive(((pst_TimerHandle_t)*timer)->xTimer) != pdFALSE )// active means not expired
	{
//		printf("Timer NOT expired TimerId: %d\r\n", pvTimerGetTimerID(((pst_TimerHandle_t)*timer)->xTimer));
		return pdFALSE; //0 = timer not expired
	}
	else
	{
		((pst_TimerHandle_t)*timer)->TimeToExpire = 0;
//		printf("Timer expired TimerId: %d\r\n", pvTimerGetTimerID(((pst_TimerHandle_t)*timer)->xTimer));

		return !pdFALSE;//1 = timer expired
	}
}
/**
 * @brief Check the time remaining on a give timer
 *
 * Checks the input timer and returns the number of milliseconds remaining on the timer.
 *
 * @param Timer - pointer to the timer to be set to checked
 * @return int - milliseconds left on the countdown timer
 */
int left_ms(Timer* timer)
{
	unsigned int time_s = 0; 
	if( xTimerIsTimerActive(((pst_TimerHandle_t)*timer)->xTimer ) != pdFALSE )
	{
		//Active
		time_s = xTimerLeftMs(((pst_TimerHandle_t)*timer)->xTimer);
		time_s = time_s - ((xTaskGetTickCount()) - ((pst_TimerHandle_t)*timer)->TimeToExpire);
//		printf("left_ms:%d of TimerID %d\r\n", time_s, pvTimerGetTimerID(((pst_TimerHandle_t)*timer)->xTimer));
	}
	else
	{
		//Not active
		time_s = 0;
//		printf("left_ms:%d of TimerID %d\r\n", time_s, pvTimerGetTimerID(((pst_TimerHandle_t)*timer)->xTimer));
	}
  	
	return time_s;
//	return 2000;
}
Example #8
0
bool bModeSmsIsPaused(void)
{
    if (state == MODE_SMS_STATE_STOP) return false;
    
    return xTimerIsTimerActive(xModeSmsControlTimer) == pdFALSE;
}
Example #9
0
int os_timer_is_active(os_timer_t timer, void* reserved)
{
    return xTimerIsTimerActive(timer) != pdFALSE;
}
Example #10
0
/**
 * \brief	Data acquisition Task. Implementation of the Data acquisition task with his own loop.
 * \param[in]	pvParameters task parameters. Not used.
 */
void taskDataAcquisition(void* pvParameters) {
	dataacquisition_t settings;
	speed_t engine_speed;

	event_t event;

	uint8_t laser_flag;
	uint8_t laser_flag_last = 1;
	uint8_t engine_flag;
	uint8_t engine_flag_last = 1;

	/* Loop forever */
	for (;;) {
		/* Wait for new configuration settings. */
		if (xQueueReceive(queueDataAcquisition, &settings, 100) == pdTRUE) {
			/* Check the new state */
			if (settings.state == DATA_ACQUISITION_ENABLE) {
				/* Starts the data acquisition */
				engine_speed = settings.param.scan.rate * (BSP_QUADENC_INC_PER_TURN+1) / (1000*ENGINE_CONTROLER_TA);

				/* Starts the engine */
				xTimerStop(timerEngineSleep, portMAX_DELAY);
				xQueueSend(queueSpeed, &engine_speed, portMAX_DELAY);

				/* Calculate the settings */
				g_configs.azimuth_left = tenthdegree2increments(settings.param.scan.bndry_left);
				g_configs.azimuth_right = tenthdegree2increments(settings.param.scan.bndry_right);
				g_configs.azimuth_res = tenthdegree2increments_Relative(settings.param.scan.step);
				g_configs.laser_pulses =  DA_LASERPULSE / settings.param.scan.rate;

				/* Check if the engine is running */
				if (xTimerIsTimerActive(timerEngineSleep) != pdFALSE) {
					/* Stops the engine delay sleep timer */
					xTimerStop(timerEngineSleep, portMAX_DELAY);
					/* Starts the data acquisition direct */
					DataAcquisitionStartCallback(NULL);
				}
				else {
					/* Starts after a small time delay */
					xTimerStart(timerDataAcquisitionStart, portMAX_DELAY);
				}
			}
			else {
				/* Stops the data acquisition */
				xTimerStop(timerDataAcquisitionStart, portMAX_DELAY);
				g_configs.enable = 0;

				/* Stop the engine after a given time delay */
				if (settings.param.engine_sleep > 0) {
					xTimerChangePeriod(timerEngineSleep, settings.param.engine_sleep, portMAX_DELAY);
					xTimerStart(timerEngineSleep, portMAX_DELAY);
				}
				else {
					/* Stop the engine now */
					engine_speed = 0;
					xQueueSend(queueSpeed, &engine_speed, portMAX_DELAY);
				}
			}
		}

		/* Make the system check of the data acquisition module */

		/* --- Laser driver error flag ------------------------ */
		laser_flag = bsp_LaserOvercurrent();

		/* Check if a overcurrent is ocured */
		if (!laser_flag && laser_flag_last) {
			event.event = Malf_LaserDriver;
			if (xQueueSend(queueEvent, &event, 0) == pdTRUE) {
				laser_flag_last = laser_flag;
			}
			/* If queue is full, wait for an other check cycle */
		}
		else {
			laser_flag_last = laser_flag;
		}

		/* --- Engine driver error flag ----------------------- */
		engine_flag = bsp_EngineAlert();

		/* Check if a overcurrent is ocured */
		if (!engine_flag && engine_flag_last) {
			event.event = Malf_EngineDriver;
			if (xQueueSend(queueEvent, &event, 0) == pdTRUE) {
				engine_flag_last = engine_flag;
			}
			/* If queue is full, wait for an other check cycle */
		}
		else {
			engine_flag_last = engine_flag;
		}
	}

	/* Never reach this point */
}
Example #11
0
bool SoftTimer::isActive()
{
	return xTimerIsTimerActive(_hnd) != pdFALSE;
}
Example #12
0
/**
* @brief  Start or restart a timer.
* @param  timer_id      timer ID obtained by \ref osTimerCreate.
* @param  millisec      time delay value of the timer.
* @retval  status code that indicates the execution status of the function
* @note   MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
*/
osStatus osTimerStart (osTimerId timer_id, uint32_t millisec)
{
  osStatus result = osOK;
#if (configUSE_TIMERS == 1)  
	portBASE_TYPE taskWoken = pdFALSE;
  TickType_t ticks = millisec / portTICK_PERIOD_MS;
  
  if (xTimerIsTimerActive(timer_id) != pdFALSE)
  {
    if (inHandlerMode()) 
    {
      if(xTimerResetFromISR(timer_id, &taskWoken) != pdPASS)
      {
        result = osErrorOS;
      }
      else
      {
        portEND_SWITCHING_ISR(taskWoken);
        result = osOK;
      }
    }
    else
    {
      if (xTimerReset(timer_id, 0) != pdPASS)
        result = osErrorOS;
      else   
        result = osOK;
    }
  }
  else
  {
    if (ticks == 0)
      ticks = 1;
    
    if (inHandlerMode()) 
    {
      if (xTimerChangePeriodFromISR(timer_id, ticks, &taskWoken) != pdPASS) 
        result = osErrorOS;
      else
      {
        xTimerStartFromISR(timer_id, &taskWoken);
        portEND_SWITCHING_ISR(taskWoken);
        result = osOK; 
      }
    }
    else 
    {
      if (xTimerChangePeriod(timer_id, ticks, 0) != pdPASS)
        result = osErrorOS;
      else
      {
        if (xTimerStart(timer_id, 0) != pdPASS)
          result = osErrorOS;
      }
    }
  }
#else 
  result = osErrorOS;
#endif
  return result;
}
Example #13
0
wiced_result_t wiced_rtos_is_timer_running( wiced_timer_t* timer )
{
    return ( xTimerIsTimerActive( timer->handle ) != 0 ) ? WICED_SUCCESS : WICED_ERROR;
}
Example #14
0
bool bModeVideoIsPaused(void)
{
    if (state == MODE_VIDEO_STATE_STOP) return false;
    
    return xTimerIsTimerActive(xModeVideoControlTimer) == pdFALSE;
}
bool FreeRTOSTimer::isRunning()
{
	return (pdFALSE != xTimerIsTimerActive(mTimerHandle) ? true : false);
}