UnwrappedHardwareScheduler::UnwrappedHardwareScheduler() 
  : _lastTimeAtFrame0(0)
  , _lastDmaSyncedTime(std::chrono::seconds(0)) {
    dmaCh = 5;
    SchedulerBase::registerExitHandler(&cleanup, SCHED_IO_EXIT_LEVEL);
    makeMaps();
    initSrcAndControlBlocks();
    initPwm();
    initDma();
}
Example #2
0
void dma_main(void){
#else
void main(void){
#endif
   DMA_DESC dmaChannel;
   char sourceString[56] = "This is a test string used to demonstrate DMA transfer."; //56 bytes
   char destString[56];
   INT8 i;
   INT8 errors = 0;


   initDma();



   //Clearing the destination
   memset(destString,0,sizeof(destString));

     // Setting up the DMA channel.
   SET_WORD(dmaChannel.SRCADDRH, dmaChannel.SRCADDRL,   &sourceString); // The start address of the data to be transmitted
   SET_WORD(dmaChannel.DESTADDRH, dmaChannel.DESTADDRL, &destString);   // The start address of the destination.
   SET_WORD(dmaChannel.LENH, dmaChannel.LENL, sizeof(sourceString));    // Setting the number of bytes to transfer.
   dmaChannel.VLEN      = VLEN_USE_LEN;  // Using the length field to determine how many bytes to transfer.
   dmaChannel.PRIORITY  = PRI_HIGH;      // High priority.
   dmaChannel.M8        = M8_USE_8_BITS; // Irrelevant since length is determined by the LENH and LENL.
   dmaChannel.IRQMASK   = FALSE;         // The DMA shall not issue an IRQ upon completion.
   dmaChannel.DESTINC   = DESTINC_1;     // The destination address is to be incremented by 1 after each transfer.
   dmaChannel.SRCINC    = SRCINC_1;      // The source address inremented by 1 byte after each transfer.
   dmaChannel.TRIG      = DMATRIG_NONE;  // The DMA channel will be started manually.
   dmaChannel.TMODE     = TMODE_BLOCK;   // The number of bytes specified by LENH and LENL is transferred.
   dmaChannel.WORDSIZE  = WORDSIZE_BYTE; // One byte is transferred each time.


   // Using DMA channel 0.
   // Setting where the DMA channel is to read the desciptor and arming the DMA channel.
   DMA_SET_ADDR_DESC0(&dmaChannel);
   DMA_ABORT_CHANNEL(0);
   DMA_ARM_CHANNEL(0);

   //Waiting for the user to start the transfer.
   lcdUpdate((char*)"Press S1",(char*)"to start DMA.");
   while(!buttonPushed());


   // Clearing all DMA complete flags and starting the transfer.
   DMAIRQ = 0x00;
   DMA_START_CHANNEL(0);

   // Waiting for the DMA to finish.
   while(!(DMAIRQ & DMA_CHANNEL_0));




   // Verifying that data is transferred correctly
   for(i=0;i<sizeof(sourceString);i++)
   {
     if(sourceString[i] != destString[i])
         errors++;
   }


   //Displaying the result
   if(errors == 0)
   {lcdUpdate((char*)"Dma transfer",(char*)"correct!");}
   else
   {lcdUpdate((char*)"Error in DMA",(char*)"Transfer");}



   haltApplicationWithLED();
   return;
}
Example #3
0
void main(void)
{
	GPIO_InitTypeDef  GPIO_InitStructure;
	/* GPIOD Periph clock enable */
	  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

	  /* Configures the leds and the read/write pin on D1 */
	  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15 | GPIO_Pin_1;
	  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	  GPIO_Init(GPIOD, &GPIO_InitStructure); 
	
	initDma();
	
	uint32_t period = initialize_timers(525000, 1);
	
	 /* GPIOD Periph clock enable */
	 RCC_AHB1PeriphClockCmd(USER_BUTTON_GPIO_CLK, ENABLE);

	 /* Configure Button in output pushpull mode */
	 GPIO_InitStructure.GPIO_Pin = USER_BUTTON_PIN;
	 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	 GPIO_Init(USER_BUTTON_GPIO_PORT, &GPIO_InitStructure);
	
	uint8_t button = 0;
	uint8_t value = 0;
	uint8_t thousands = 0;
	while(1)
	{
		
	    TIM3->CCR1 = (period + 1) * ADC3ConvertedValue[0] / 4000 / 4.5;
		
		/*if(ADC3ConvertedValue[0] > 1000)
		{
			GPIO_SetBits(GPIOD, GPIO_Pin_13);
			TIM3->CCR1 = (period + 1) * 50.0 / 100;
		}
		else if(ADC3ConvertedValue[1] > 1000)
		{
			GPIO_SetBits(GPIOD, GPIO_Pin_14);
			TIM3->CCR2 = (period + 1) * 50.0 / 100;
		}
		else if(ADC3ConvertedValue[2] > 1000)
		{
			GPIO_SetBits(GPIOD, GPIO_Pin_15);
			TIM3->CCR3 = (period + 1) * 50.0 / 100;
		}
		else if(ADC3ConvertedValue[3] > 1000)
		{
			GPIO_SetBits(GPIOD, GPIO_Pin_12);
			TIM3->CCR4 = (period + 1) * 50.0 / 100;
		}
		else
		{
			TIM3->CCR1 = (period + 1) * 0 / 100;
			TIM3->CCR2 = (period + 1) * 0 / 100;
			TIM3->CCR3 = (period + 1) * 0 / 100;
			TIM3->CCR4 = (period + 1) * 0 / 100;
		}*/
		
		GPIO_ResetBits(GPIOD, GPIO_Pin_12);
		GPIO_ResetBits(GPIOD, GPIO_Pin_13);
		GPIO_ResetBits(GPIOD, GPIO_Pin_14);
		GPIO_ResetBits(GPIOD, GPIO_Pin_15);
			
	}
}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
#ifdef GG_STK
  uint32_t mode = 0;
#else
  /* Initialize DK board register access, necessary if run on DK */
  BSP_Init(BSP_INIT_DEFAULT);
  BSP_PeripheralAccess(BSP_AUDIO_OUT, true);
#endif
  
  /* Initialize peripherals */
  initClock();
  initDma();
  initDac();
  initDacDma();
  initTimer();
#ifdef GG_STK
  initGpio();
#endif

  while(1)
  {
/*** Operation for EFM32GG-DK3750 ***/    
#ifndef GG_STK
    /* Wait key press */
    while(!BSP_PushButtonsGet())
      ;
    if (BSP_PushButtonsGet() == BC_UIF_PB1)
    {
      BSP_LedsSet(0x0001);
      /* Wait key release */
      while(BSP_PushButtonsGet()!=0);
      /* Start play files */      
      playList[0].frameStart = (char *)voice8k;
      playList[1].frameStart = NULL;
      playList[0].frameNum = sizeof(voice8k)/FRAME_SIZE_8K;
      speexPlayBack(0, NARROWBAND, FRAME_SIZE_8K, &playList[0]);
      BSP_LedsSet(0x0000);
    }
    if (BSP_PushButtonsGet() == BC_UIF_PB2)
    {    
      BSP_LedsSet(0x0002);
      /* Wait key release */
      while(BSP_PushButtonsGet()!=0);
      /* Start play files */      
      playList[0].frameStart = (char *)voice11k;
      playList[1].frameStart = NULL;
      playList[0].frameNum = sizeof(voice11k)/FRAME_SIZE_11K;
      speexPlayBack(0, NARROWBAND, FRAME_SIZE_11K, &playList[0]);
      BSP_LedsSet(0x0000);
    }
    if (BSP_PushButtonsGet() == BC_UIF_PB3)
    {
      BSP_LedsSet(0x0004);
      /* Wait key release */
      while(BSP_PushButtonsGet()!=0);
      /* Start play files */      
      playList[0].frameStart = (char *)voice15k;
      playList[1].frameStart = NULL;
      playList[0].frameNum = sizeof(voice15k)/FRAME_SIZE_15K;
      speexPlayBack(0, NARROWBAND, FRAME_SIZE_15K, &playList[0]);
      BSP_LedsSet(0x0000);
    }
    if (BSP_PushButtonsGet() == BC_UIF_PB4)
    {    
      BSP_LedsSet(0x0008);
      /* Wait key release */
      while(BSP_PushButtonsGet()!=0);
      /* Start play files */      
      playList[0].frameStart = (char *)voice18k2;
      playList[1].frameStart = NULL;
      playList[0].frameNum = sizeof(voice18k2)/FRAME_SIZE_18K2;
      speexPlayBack(0, NARROWBAND, FRAME_SIZE_18K2, &playList[0]);
      BSP_LedsSet(0x0000);
    }

/*** Operation for EFM32GG-STK3750 ***/        
#else
    /* Wait key press */
    EMU_EnterEM1();

    switch (keyCheck())
    {
    case 1:
      mode++;
      if (mode == 4)
      {
        mode = 0;
      }
      GPIO_PortOutSetVal(gpioPortE, (mode << 2), 0x000c);
      break;
      
    case 2:
      if (mode == 0x00)
      {
        /* Start play files */      
        playList[0].frameStart = (char *)voice8k;
        playList[1].frameStart = NULL;
        playList[0].frameNum = sizeof(voice8k)/FRAME_SIZE_8K;
        speexPlayBack(0, NARROWBAND, FRAME_SIZE_8K, &playList[0]);
      }
      else if (mode == 0x01)
      {
        /* Start play files */      
        playList[0].frameStart = (char *)voice11k;
        playList[1].frameStart = NULL;
        playList[0].frameNum = sizeof(voice11k)/FRAME_SIZE_11K;
        speexPlayBack(0, NARROWBAND, FRAME_SIZE_11K, &playList[0]);
      }
      else if (mode == 0x02)
      {
        /* Start play files */      
        playList[0].frameStart = (char *)voice15k;
        playList[1].frameStart = NULL;
        playList[0].frameNum = sizeof(voice15k)/FRAME_SIZE_15K;
        speexPlayBack(0, NARROWBAND, FRAME_SIZE_15K, &playList[0]);
      }
      else
      {
        /* Start play files */      
        playList[0].frameStart = (char *)voice18k2;
        playList[1].frameStart = NULL;
        playList[0].frameNum = sizeof(voice18k2)/FRAME_SIZE_18K2;
        speexPlayBack(0, NARROWBAND, FRAME_SIZE_18K2, &playList[0]);
      }
      break;
      
    default:
      break;
    }    
#endif
  }
}