Beispiel #1
0
/*!
 * @Brief enable the trigger source
 *
 * @param instance The ADC instance number
 */
void adc16InitPitTriggerSource(uint32_t adcInstance)
{
    /* Change the timer period here in unit of microseconds.*/
    uint32_t timerPeriod = 500;
    uint32_t pitInstance = BOARD_PIT_INSTANCE;
    uint32_t pitChannel = 0;

    if(sPdbInitialized)
    {
        return;
    }
    sPdbInitialized = 1;

    pitUserConf.isInterruptEnabled = false;
    pitUserConf.periodUs = timerPeriod;

    /* Init pit module and enable run in debug */
    PIT_DRV_Init(pitInstance, false);

    /* Initialize PIT timer 0 */
    PIT_DRV_InitChannel(pitInstance, pitChannel, &pitUserConf);

    /* Set timer0 period and start it.*/
    PIT_DRV_SetTimerPeriodByUs(pitInstance, pitChannel, timerPeriod * 1000);

    // Configure SIM for ADC hw trigger source PIT
    SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, true);

    SIM_HAL_SetAdcTriggerMode(gSimBase[0], adcInstance, kSimAdcTrgSelPit0);

    PIT_DRV_StartTimer(pitInstance, pitChannel);
}
Beispiel #2
0
int main (void)
{
   OSA_Init();

   /* Initialize clocks, debug console interface and configure required pins */
   hardware_init();

   /* Disable Memory Protection Unit */
   MPU_HAL_Disable(MPU);

	testPin.pinName = test_pin_name;
	testPin.config.outputLogic = 0;
	testPin.config.slewRate = kPortFastSlewRate;
	testPin.config.driveStrength = kPortHighDriveStrength;
	testPin.config.isOpenDrainEnabled = false;
	GPIO_DRV_OutputPinInit(&testPin);

	// Structure of initialize PIT channel No.0
   pit_user_config_t chn0Confg;
   chn0Confg.isInterruptEnabled = true;
   chn0Confg.periodUs = 1000000u;

   // Init pit module and enable run in debug
   PIT_DRV_Init(BOARD_PIT_INSTANCE, false);

   // Initialize PIT timer instance for channel 0 and 1
   PIT_DRV_InitChannel(BOARD_PIT_INSTANCE, 0, &chn0Confg);

   // Start channel 0
   PRINTF("\n\rStarting channel No.0 ...");
   PIT_DRV_StartTimer(BOARD_PIT_INSTANCE, 0);

//	drv_Mpu9250.Init();
	sdCard.Init(1);

   OSA_TaskCreate((task_t)MainTask,   (uint8_t*)"Main Task",    4096, NULL, 2, NULL, true, NULL);
   //OSA_TaskCreate((task_t)FnetTask,   (uint8_t*)"FNET Task",    2048, NULL, 3, NULL, true, NULL);

   OSA_Start(); // This function will not return

   while(1);

   return(0);
}
Beispiel #3
0
/*!
 * @brief Main function
 */
int main (void)
{
    /* enable clock for PORTs */
    CLOCK_SYS_EnablePortClock(PORTA_IDX);
    //CLOCK_SYS_EnablePortClock(PORTB_IDX);
    CLOCK_SYS_EnablePortClock(PORTC_IDX);
    CLOCK_SYS_EnablePortClock(PORTD_IDX);
    CLOCK_SYS_EnablePortClock(PORTE_IDX);

    /* Set allowed power mode, allow all. */
    SMC_HAL_SetProtection(SMC, kAllowPowerModeAll);

    /* Set system clock configuration. */
    CLOCK_SYS_SetConfiguration(&g_defaultClockConfigVlpr);

    /* Initialize LPTMR */
    lptmr_state_t lptmrState;
    LPTMR_DRV_Init(LPTMR0_IDX, &lptmrState, &g_lptmrConfig);
    LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, 100000);
    LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back);

    /* Initialize DMA */
    dma_state_t dma_state;
    DMA_DRV_Init(&dma_state);

    /* Initialize PIT */
    PIT_DRV_Init(0, false);
    PIT_DRV_InitChannel(0, 0, &g_pitChan0);

    /* Initialize CMP */
    CMP_DRV_Init(0, &g_cmpState, &g_cmpConf);
    CMP_DRV_ConfigDacChn(0, &g_cmpDacConf);
    PORT_HAL_SetMuxMode(g_portBase[GPIOC_IDX], 0, kPortMuxAlt5);
    CMP_DRV_Start(0);

    /* Buttons */
    GPIO_DRV_InputPinInit(&g_switch1);
    GPIO_DRV_InputPinInit(&g_switch2);
    GPIO_DRV_InputPinInit(&g_switchUp);
    GPIO_DRV_InputPinInit(&g_switchDown);
    GPIO_DRV_InputPinInit(&g_switchLeft);
    GPIO_DRV_InputPinInit(&g_switchRight);
    GPIO_DRV_InputPinInit(&g_switchSelect);

    /* Start LPTMR */
    LPTMR_DRV_Start(LPTMR0_IDX);

    /* Setup LPUART1 */
    LPUART_DRV_Init(1, &g_lpuartState, &g_lpuartConfig);
    LPUART_DRV_InstallRxCallback(1, lpuartRxCallback, rxBuff, NULL, true);
    LPUART_DRV_InstallTxCallback(1, lpuartTxCallback, NULL, NULL);
    LPUART_BWR_CTRL_TXINV(g_lpuartBase[1], 1);
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 0, kPortMuxAlt3);
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 1, kPortMuxAlt3);

    /* Setup FlexIO for the WS2812B */
    FLEXIO_Type *fiobase = g_flexioBase[0];
    CLOCK_SYS_SetFlexioSrc(0, kClockFlexioSrcMcgIrClk);
    FLEXIO_DRV_Init(0, &g_flexioConfig);
    FLEXIO_HAL_ConfigureTimer(fiobase, 0, &g_timerConfig);
    FLEXIO_HAL_ConfigureShifter(fiobase, 0, &g_shifterConfig);
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 20, kPortMuxAlt6);
    FLEXIO_DRV_Start(0);

    FLEXIO_HAL_SetShifterStatusDmaCmd(fiobase, 1, true);
    DMA_DRV_RequestChannel(kDmaAnyChannel, kDmaRequestMux0FlexIOChannel0,
            &g_fioChan);
    DMA_DRV_RegisterCallback(&g_fioChan, fioDmaCallback, NULL);

    /* Connect buzzer to TPM0_CH3 */
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 30, kPortMuxAlt3);
    tpm_general_config_t tmpConfig = {
        .isDBGMode = false,
        .isGlobalTimeBase = false,
        .isTriggerMode = false,
        .isStopCountOnOveflow = false,
        .isCountReloadOnTrig = false,
        .triggerSource = kTpmTrigSel0,
    };
    TPM_DRV_Init(0, &tmpConfig);
    TPM_DRV_SetClock(0, kTpmClockSourceModuleMCGIRCLK, kTpmDividedBy1);

    /* Blank LED just in case, saves power */
    led(0x00, 0x00, 0x00);

    /* Init e-paper display */
    EPD_Init();

    /* Throw up first image */
    int ret = EPD_Draw(NULL, images[current_image]);
    if (-1 == ret) {
        led(0xff, 0x00, 0x00);
    } else if (-2 == ret) {
        led(0xff, 0xff, 0x00);
    } else if (-3 == ret) {
        led(0x00, 0x00, 0xff);
    } else {
        led(0x00, 0xff, 0x00);
    }
    blank_led = 30;

    /* Deinit so we can mess around on the bus pirate */
    //EPD_Deinit();

    /* We're done, everything else is triggered through interrupts */
    for(;;) {
        if (cue_next_image) {
            int old_image = current_image;
            current_image = (current_image + 1) % image_count;
            EPD_Draw(images[old_image], images[current_image]);
            cue_next_image = 0;
        }
#ifndef DEBUG
        SMC_HAL_SetMode(SMC, &g_idlePowerMode);
#endif
    }
}
//PTD2_UART_rx, PTD3_UART_tx
//PTC1,2,3,4
int main (void)
{
    memcpy(packet_upper_PC.trans_header, trans_header_table, sizeof(trans_header_table));
    // RX buffers
    //! @param receiveBuff Buffer used to hold received data
    uint8_t receiveBuff;

    // Initialize standard SDK demo application pins
    hardware_init();
    OSA_Init();
    // Call this function to initialize the console UART. This function
    // enables the use of STDIO functions (printf, scanf, etc.)
    dbg_uart_init();

/*Start***FTM Init*************************************************************/
    memset(&ftmInfo, 0, sizeof(ftmInfo));
    ftmInfo.syncMethod = kFtmUseSoftwareTrig;
    FTM_DRV_Init(0, &ftmInfo);
/*End*****FTM Init*************************************************************/

    // Print the initial banner
    PRINTF("\r\nHello World!\n\n\r");

    LED2_EN;    LED3_EN;    LED4_EN;    LED5_EN;
    LED2_OFF;   LED3_OFF;   LED4_OFF;   LED5_OFF;

    I2C_fxos8700Init();
    I2C_l3g4200dInit();

    FTM_DRV_PwmStart(0, &ftmParam0, 0);
    FTM_DRV_PwmStart(0, &ftmParam1, 1);
    FTM_DRV_PwmStart(0, &ftmParam2, 2);
    FTM_DRV_PwmStart(0, &ftmParam3, 3);
    FTM_HAL_SetSoftwareTriggerCmd(g_ftmBaseAddr[0], true);

        // Hwtimer initialization
    if (kHwtimerSuccess != HWTIMER_SYS_Init(&hwtimer, &HWTIMER_LL_DEVIF, HWTIMER_LL_ID, 5, NULL))
    {
        PRINTF("\r\nError: hwtimer initialization.\r\n");
    }
    if (kHwtimerSuccess != HWTIMER_SYS_SetPeriod(&hwtimer, HWTIMER_LL_SRCCLK, HWTIMER_PERIOD))
    {
        PRINTF("\r\nError: hwtimer set period.\r\n");
    }
//    if (kHwtimerSuccess != HWTIMER_SYS_RegisterCallback(&hwtimer, hwtimer_callback, NULL))
//    {
//        PRINTF("\r\nError: hwtimer callback registration.\r\n");
//    }
//    if (kHwtimerSuccess != HWTIMER_SYS_Start(&hwtimer))
//    {
//        PRINTF("\r\nError: hwtimer start.\r\n");
//    }
    
    /* A write of any value to current value register clears the field to 0, and also clears the SYST_CSR COUNTFLAG bit to 0. */
    SysTick->VAL = 0U;
    /* Run timer and disable interrupt */
    SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk ;//| SysTick_CTRL_TICKINT_Msk;

    GPIO_DRV_Init(remoteControlPins,NULL);
//    GPIO_DRV_Init(fxos8700IntPins,NULL);
//    I2C_fxos8700AutoCalibration(); //cannot work , shit!
    
/*Start PIT init***************/    
    // Structure of initialize PIT channel No.0
    pit_user_config_t chn0Confg = {
      .isInterruptEnabled = true,
      .isTimerChained = false,
      .periodUs = 20000u //1000000 us
    };
    
    // Structure of initialize PIT channel No.1
    pit_user_config_t chn1Confg = {
      .isInterruptEnabled = true,
      .isTimerChained = false,
      .periodUs = 2000000u
    };  
    
    // Init pit module and enable run in debug
    PIT_DRV_Init(BOARD_PIT_INSTANCE, false);
    
    // Initialize PIT timer instance for channel 0 and 1
    PIT_DRV_InitChannel(BOARD_PIT_INSTANCE, 0, &chn0Confg);
//    PIT_DRV_InitChannel(BOARD_PIT_INSTANCE, 1, &chn1Confg);
    
    // Start channel 0
//    printf ("\n\rStarting channel No.0 ...");
    PIT_DRV_StartTimer(BOARD_PIT_INSTANCE, 0);
    
    // Start channel 1
//    printf ("\n\rStarting channel No.1 ...");
//    PIT_DRV_StartTimer(BOARD_PIT_INSTANCE, 1);
    
/*End PIT init***************/   

//    NVIC_SetPriority(SysTick_IRQn, 3);
//    NVIC_SetPriority(PORTB_IRQn,0);
    while(1)
    {
///*Start************Remote Controller Unlock *************/      
//      if(isRCunlock == true)
//      {    
//        LED3_ON;
//      }
//      else
//      {    
//        LED3_OFF;
//      }
//      static uint32_t unlock_times = 0;
//      static uint32_t lock_times = 0;
//      PRINTF("ThrottleValue = %6d ,YawValue = %6d \r\n" ,remoteControlValue[kThrottle],remoteControlValue[kYaw]);
//      if(isRCunlock == false)
//      {
//        if((remoteControlValue[kThrottle] < RC_THRESHOLD_L) && (remoteControlValue[kYaw] > RC_THRESHOLD_H))
//        {
//          unlock_times++;
//        }
//        else
//        {
//          unlock_times = 0;
//        }
//        if(unlock_times > 6)
//        {
//          isRCunlock = true; 
//        }
//      }
//      else
//      {
//        if((remoteControlValue[kThrottle] < RC_THRESHOLD_L) && (remoteControlValue[kYaw] < RC_THRESHOLD_L))
//        {
//          lock_times++;
//        }
//        else
//        {
//          lock_times = 0;
//        }
//        if(lock_times > 4)
//        {
//          isRCunlock = false;
//        }
//      }
///*End************Remote Controller Unlock *************/          

//      LED2_ON;
//      OSA_TimeDelay(200);
//      LED3_ON;
//      OSA_TimeDelay(200);
//      LED4_ON;
//      OSA_TimeDelay(200);
      LED5_ON;
      OSA_TimeDelay(100);

//      LED2_OFF;
//      OSA_TimeDelay(200);
//      LED3_OFF;
//      OSA_TimeDelay(200);
//      LED4_OFF;
//      OSA_TimeDelay(200);
      LED5_OFF;
      OSA_TimeDelay(100);
    }
}

volatile bool isRCunlock = false;
//below define value is in quad_common.h
//#define RC_THRESHOLD_H (220000U)
//#define RC_THRESHOLD_L (140000U)
//#define RC_THRESHOLD_ERROR (300000U)//由于IO采两个边沿中断,有可能算成低电平的时间,所以做一个剔除算法。
//#define HW_DIVIDER (2400000U) 
////120M core clock , 2400000 / 120 000 000 = 0.02 s , 50Hz , 
////遥控器信号 50Hz , 范围1~2ms,周期20ms,1.5ms中值.对应 120 000 - 240 000
void PORTB_IRQHandler(void)
{
  uint32_t intFlag = PORT_HAL_GetPortIntFlag(PORTB_BASE);
  uint32_t i =  0;
  uint32_t value = 0;
  static  uint32_t remoteControlValue1st[8] = {0};
  static  uint32_t remoteControlValue2nd[8] = {0};
  static  uint32_t remoteControlValueFlag[8] = {0};
  for(i=0 ; i<8;i++)
  {
    if (intFlag & (1 << remoteControlPinNum[i]))
    {
      if (remoteControlValueFlag[i] == 0)
      {
        remoteControlValue1st[i] = (SysTick->VAL);
        remoteControlValueFlag[i] = 1;
      }
      else
      {
        remoteControlValueFlag[i] = 0;
        remoteControlValue2nd[i] = (SysTick->VAL);
        if ( remoteControlValue1st[i] > remoteControlValue2nd[i] )
        { 
          value = remoteControlValue1st[i] - remoteControlValue2nd[i];
        }
        else
        {
          value = remoteControlValue1st[i] + HW_DIVIDER - remoteControlValue2nd[i];//hwtimer.divider
        }
        if( value > RC_THRESHOLD_ERROR)
        {
          remoteControlValueFlag[i] = 1;
          remoteControlValue1st[i] = (SysTick->VAL);
        }
        else
        {
          remoteControlValue[i] = value;
//          if(((remoteControlValue[3] <180000) ||(remoteControlValue[3] > 190000))&&remoteControlValue[3]> 100)
//            LED4_ON;
        }
      }
    }
    PORT_HAL_ClearPinIntFlag(PORTB_BASE,remoteControlPinNum[i]);
  }
  /* Clear interrupt flag.*/
 //   PORT_HAL_ClearPortIntFlag(PORTB_BASE);
}


void PORTE_IRQHandler(void)
{
  uint32_t intFlag = PORT_HAL_GetPortIntFlag(PORTE_BASE);
  if (intFlag & (1 << 11))
  {
    isFXOS8700Int1Trigger = true;
      PRINTF("\r\n PTE11 irq");
  }

  /* Clear interrupt flag.*/
  PORT_HAL_ClearPortIntFlag(PORTE_BASE);
}