/**
  * @brief  Pause Audio stream
  * @param  None.
  * @retval Audio state.
  */
AUDIO_RECORDER_ErrorTypdef  AUDIO_RECORDER_PauseResume(void)
{
  if(haudio.in.state == AUDIO_RECORDER_PLAYING)
  {  
    osThreadSuspend(AudioThreadId);     
    BSP_AUDIO_OUT_Pause();
    haudio.in.state = AUDIO_RECORDER_PLAY_PAUSE;
  }
  else if(haudio.in.state == AUDIO_RECORDER_RECORDING)
  {
    osThreadSuspend(AudioThreadId);     
    BSP_AUDIO_IN_Pause();
    haudio.in.state = AUDIO_RECORDER_RECORD_PAUSE;    
  }
  
  else if(haudio.in.state == AUDIO_RECORDER_PLAY_PAUSE)
  { 
    osThreadResume(AudioThreadId);  
    BSP_AUDIO_OUT_Resume();
    haudio.in.state = AUDIO_RECORDER_PLAYING;
  }
  else if(haudio.in.state == AUDIO_RECORDER_RECORD_PAUSE)
  {
    osThreadResume(AudioThreadId);  
    BSP_AUDIO_IN_Resume();
    haudio.in.state = AUDIO_RECORDER_RECORDING;    
  }  
  return AUDIO_RECORDER_ERROR_NONE;
}
示例#2
0
/**
  * @brief  Toggle LED2 thread
  * @param  argument not used
  * @retval None
  */
static void LED_Thread2(void const *argument)
{
  uint32_t count;
  (void) argument;

  for(;;)
  {
    count = osKernelSysTick() + 10000;

    /* Toggle LED2 every 500 ms for 10 s */
    while (count >= osKernelSysTick())
    {
      BSP_LED_Toggle(LED2);

      osDelay(500);
    }

    /* Turn off LED2 */
    BSP_LED_Off(LED2);

    /* Resume Thread 1 */
    osThreadResume(LEDThread1Handle);

    /* Suspend Thread 2 */
    osThreadSuspend(NULL);
  }
}
示例#3
0
/**
  * @brief  Semaphore Thread 1 function
  * @param  argument: shared semaphore
  * @retval None
  */
static void SemaphoreThread1 (void const *argument)
{  
  uint32_t count = 0;
  osSemaphoreId semaphore = (osSemaphoreId) argument;
  
  for(;;)
  {
    if (semaphore != NULL)
    {
      /* Try to obtain the semaphore. */
      if(osSemaphoreWait(semaphore , 100) == osOK)
      {
        count = osKernelSysTick() + 5000;
        
        while (count >= osKernelSysTick())
        {
          /* Toggle LED1 */
          BSP_LED_Toggle(LED1);
          
          /* Delay 200 ms */
          osDelay(200);
        }
        
        /* Turn off LED1 */
        BSP_LED_Off(LED1);

        /* Release the semaphore */
        osSemaphoreRelease(semaphore);

        /* Suspend ourseleves to execute thread 2 (lower priority)  */
        osThreadSuspend(NULL); 
      }
    }
  }
}
/**
  * @brief  Stop audio stream.
  * @param  None.
  * @retval Audio state.
  */
AUDIO_RECORDER_ErrorTypdef  AUDIO_RECORDER_StopRec(void)
{
  uint32_t byteswritten = 0;
  AUDIO_RECORDER_ErrorTypdef audio_error = AUDIO_RECORDER_ERROR_IO;
  

  BSP_AUDIO_IN_Stop();  
  haudio.in.state = AUDIO_RECORDER_IDLE;      
  if(f_lseek(&wav_file, 0) == FR_OK)
  {
    /* Update the wav file header save it into wav file */
    WavProcess_HeaderUpdate(pHeaderBuff, &AudioInfo);
    
    if(f_write(&wav_file, pHeaderBuff, sizeof(WAV_InfoTypedef), (void*)&byteswritten) == FR_OK)
    {   
      audio_error = AUDIO_RECORDER_ERROR_NONE;
    }
  }

  haudio.in.state = AUDIO_RECORDER_SUSPENDED;
  f_close(&wav_file);

  _cbNotifyStateChange();
  
  if(AudioThreadId != 0)
  {  
    osThreadSuspend(AudioThreadId); 
  }
  return audio_error;
}
示例#5
0
/**
  * @brief  Toggle LED3 thread
  * @param  argument not used
  * @retval None
  */
static void LED_Thread2(void const *argument)
{
  uint32_t count;
  (void) argument;

  for (;;)
  {
    count = osKernelSysTick() + 10000;

    while (count >= osKernelSysTick())
    {
      BSP_LED_On(LED3);
      osDelay(100);
      BSP_LED_Off(LED3);
      osDelay(100);
      BSP_LED_On(LED3);
      osDelay(100);
      BSP_LED_Off(LED3);
      HAL_Delay(1000); 
    }

    /* Turn off LED3 */
    BSP_LED_Off(LED3);

    /* Resume Thread 1 */
    osThreadResume(LEDThread1Handle);

    /* Suspend Thread 2 */
    osThreadSuspend(NULL);
  }
}
示例#6
0
/**
  * @brief  Pause Audio stream
  * @param  None.
  * @retval Audio state.
  */
AUDIOPLAYER_ErrorTypdef  AUDIOPLAYER_Pause(void)
{
  if(AudioThreadId != 0)
  {
    osThreadSuspend(AudioThreadId); 
  }
  BSP_AUDIO_OUT_Pause();
  return AUDIOPLAYER_ERROR_NONE;
}
示例#7
0
/**
  * @brief  Mutex Medium Priority Thread.
  * @param  argument: Not used
  * @retval None
  */
static void MutexMeduimPriorityThread(void const *argument)
{
  /* Just to remove compiler warning */
  (void) argument;
  
  for(;;)
  {
    /* This thread will run while the high-priority thread is blocked, and the
    high-priority thread will block only once it has the mutex - therefore
    this call should block until the high-priority thread has given up the 
    mutex, and not actually execute past this call until the high-priority 
    thread is suspended. */
    if(osMutexWait(osMutex, osWaitForever) == osOK)
    {
      if(osThreadGetState(osHighPriorityThreadHandle) != osThreadSuspended)
      {
        /* Did not expect to execute until the high priority thread was
        suspended.
        Toggle LED 3 to indicate error */
        BSP_LED_Toggle(LED3);
      }
      else
      {
        /* Give the mutex back before suspending ourselves to allow
        the low priority thread to obtain the mutex. */
        if(osMutexRelease(osMutex) != osOK)
        {
          /* Toggle LED 3 to indicate error */
          BSP_LED_Toggle(LED3);
        } 
        osThreadSuspend(NULL);
      }
    }
    else
    {
      /* We should not leave the osMutexWait() function
      until the mutex was obtained. 
      Toggle LED 3 to indicate error */
      BSP_LED_Toggle(LED3);
    }
    
    /* The High and Medium priority threads should be in lock step. */
    if(HighPriorityThreadCycles != (MediumPriorityThreadCycles + 1))
    {
      /* Toggle LED 3 to indicate error */
      BSP_LED_Toggle(LED3);
    }
    
    /* Keep count of the number of cycles this task has performed so a 
    stall can be detected. */
    MediumPriorityThreadCycles++;
    BSP_LED_Toggle(LED2);
  }
}
/**
  * @brief  Stop audio stream.
  * @param  None.
  * @retval Audio state.
  */
AUDIOPLAYER_ErrorTypdef  AUDIOPLAYER_Stop(void)
{    
  AUDIOPLAYER_Mute(1); 
  BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);    
  f_close(&wav_file);  
  osThreadSuspend(AudioThreadId); 

  haudio.state = AUDIOPLAYER_STOP;      

  return AUDIOPLAYER_ERROR_NONE;
}
示例#9
0
/**
  * @brief  Stop audio stream.
  * @param  None.
  * @retval Audio state.
  */
AUDIOPLAYER_ErrorTypdef  AUDIOPLAYER_Stop(void)
{

  BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);  
  haudio.out.state = AUDIOPLAYER_STOP;
  f_close(&wav_file);
  if(AudioThreadId != 0)
  {  
    osThreadSuspend(AudioThreadId); 
  }
  return AUDIOPLAYER_ERROR_NONE;
}
/**
  * @brief  Stop audio stream.
  * @param  None.
  * @retval Audio state.
  */
AUDIO_RECORDER_ErrorTypdef  AUDIO_RECORDER_StopPlayer(void)
{
  BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW);
  BSP_AUDIO_OUT_DeInit();  
  haudio.in.state = AUDIO_RECORDER_SUSPENDED;      
  f_close(&wav_file);
  _cbNotifyStateChange(); 
  
  if(AudioThreadId != 0)
  {  
    osThreadSuspend(AudioThreadId); 
  } 
  return AUDIO_RECORDER_ERROR_NONE;
}
/**
  * @brief  Toggle LED1
  * @param  thread not used
  * @retval None
  */
static void LED_Thread1(void const *argument)
{
	(void) argument;
  
	for (;;)
	{
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
		osDelay(2000);
		
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
		osThreadSuspend(LEDThread2Handle);
		osDelay(1900);
		
		osThreadResume(LEDThread2Handle);
	}
}
示例#12
0
/**
  * @brief  Mutex High Priority Thread.
  * @param  argument: Not used
  * @retval None
  */
static void MutexHighPriorityThread(void const *argument)
{
  /* Just to remove compiler warning. */
  (void) argument;

  for (;;)
  {

    /* The first time through the mutex will be immediately available, on
    subsequent times through the mutex will be held by the low priority thread
    at this point and this Take will cause the low priority thread to inherit
    the priority of this tadhr.  In this case the block time must be
    long enough to ensure the low priority thread will execute again before the
    block time expires.  If the block time does expire then the error
    flag will be set here. */
    if (osMutexWait(osMutex, mutexTWO_TICK_DELAY) != osOK)
    {
      /* Toggle LED3 to indicate error */
      BSP_LED_Toggle(LED3);
    }

    /* Ensure the other thread attempting to access the mutex
    are able to execute to ensure they either block (where a block
    time is specified) or return an error (where no block time is
    specified) as the mutex is held by this task. */
    osDelay(mutexSHORT_DELAY);


    /* We should now be able to release the mutex .
    When the mutex is available again the medium priority thread
    should be unblocked but not run because it has a lower priority
    than this thread.  The low priority thread should also not run
    at this point as it too has a lower priority than this thread. */
    if (osMutexRelease(osMutex) != osOK)
    {
      /* Toggle LED3 to indicate error */
      BSP_LED_Toggle(LED3);
    }

    /* Keep count of the number of cycles this thread has performed. */
    HighPriorityThreadCycles++;
    BSP_LED_Toggle(LED1);

    /* Suspend ourselves to the medium priority thread can execute. */
    osThreadSuspend(NULL);
  }
}
示例#13
0
/**
  * @brief  Toggle LED3 and LED4 thread
  * @param  thread not used
  * @retval None
  */
static void LED_Thread1(void const *argument)
{
  uint32_t count = 0;
  (void) argument;

  for (;;)
  {
    count = osKernelSysTick() + 5000;

    /* Toggle LED3 every 200 ms for 5 s */
    while (count >= osKernelSysTick())
    {
      BSP_LED_Toggle(LED3);

      osDelay(200);
    }

    /* Turn off LED3 */
    BSP_LED_Off(LED3);

    /* Suspend Thread 1 */
    osThreadSuspend(NULL);

    count = osKernelSysTick() + 5000;

    /* Toggle LED3 every 400 ms for 5 s */
    while (count >= osKernelSysTick())
    {
      BSP_LED_Toggle(LED3);

      osDelay(400);
    }

    /* Resume Thread 2*/
    osThreadResume(LEDThread2Handle);

  }
}