Exemplo n.º 1
0
void us_ticker_init(void)
{
    if (us_ticker_inited) {
        return;
    }
    us_ticker_inited = 1;
    //Common for ticker/timer
    uint32_t busClock;
    // Structure to initialize PIT
    pit_config_t pitConfig;

    PIT_GetDefaultConfig(&pitConfig);
    PIT_Init(PIT, &pitConfig);

    busClock = CLOCK_GetFreq(kCLOCK_BusClk);

    //Timer
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, busClock / 1000000 - 1);
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, 0xFFFFFFFF);
    PIT_SetTimerChainMode(PIT, kPIT_Chnl_1, true);
    PIT_StartTimer(PIT, kPIT_Chnl_0);
    PIT_StartTimer(PIT, kPIT_Chnl_1);

    //Ticker
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_2, busClock / 1000000 - 1);
    PIT_SetTimerChainMode(PIT, kPIT_Chnl_3, true);
    NVIC_SetVector(PIT0_IRQn, (uint32_t)pit_isr);
    NVIC_EnableIRQ(PIT0_IRQn);
}
/*
 * The application must provide a function that configures a peripheral to
 * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()
 * in FreeRTOSConfig.h to call the function.  This file contains a function
 * that is suitable for use on the Atmel SAMA5.
 */
void vConfigureTickInterrupt( void )
{
	/* NOTE:  The PIT interrupt is cleared by the configCLEAR_TICK_INTERRUPT()
	macro in FreeRTOSConfig.h. */

	/* Enable the PIT clock. */
	PMC->PMC_PCER0 = 1 << ID_PIT;

	/* Initialize the PIT to the desired frequency - specified in uS. */
	PIT_Init( 1000000UL / configTICK_RATE_HZ, BOARD_MCK / 1000000 );

	/* Configure interrupt on PIT.  Note this is on the system interrupt, which
	is shared with other system peripherals, so System_Handler() must be
	installed in place of FreeRTOS_Tick_Handler() if other system handlers are
	required.  The tick must be given the lowest priority (0 in the SAMA5 AIC) */
	IRQ_ConfigureIT( ID_PIT, AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE, FreeRTOS_Tick_Handler );
	/* See commend directly above IRQ_ConfigureIT( ID_PIT, 0, System_Handler ); */
	IRQ_EnableIT( ID_PIT );
	PIT_EnableIT();

	/* Enable the pit. */
	PIT_Enable();

	/* Prevent compiler warnings in the case where System_Handler() is not used
	as the handler.  See the comments above the System_Handler() function
	prototype at the top of this file. */
	( void ) System_Handler;
}
Exemplo n.º 3
0
/** Initialize the high frequency ticker
 *
 */
void us_ticker_init(void)
{
    /* Common for ticker/timer. */
    uint32_t busClock;
    /* Structure to initialize PIT. */
    pit_config_t pitConfig;

    PIT_GetDefaultConfig(&pitConfig);
    PIT_Init(PIT, &pitConfig);

    busClock = CLOCK_GetFreq(kCLOCK_BusClk);

    /* Let the timer to count if re-init. */
    if (!us_ticker_inited) {

        PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, busClock / 1000000 - 1);
        PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, 0xFFFFFFFF);
        PIT_SetTimerChainMode(PIT, kPIT_Chnl_1, true);
        PIT_StartTimer(PIT, kPIT_Chnl_0);
        PIT_StartTimer(PIT, kPIT_Chnl_1);
    }

    /* Configure interrupt generation counters and disable ticker interrupts. */
    PIT_StopTimer(PIT, kPIT_Chnl_3);
    PIT_StopTimer(PIT, kPIT_Chnl_2);
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_2, busClock / 1000000 - 1);
    PIT_SetTimerChainMode(PIT, kPIT_Chnl_3, true);
    NVIC_SetVector(PIT3_IRQn, (uint32_t) pit_isr);
    NVIC_EnableIRQ(PIT3_IRQn);
    PIT_DisableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);

    us_ticker_inited = true;
}
Exemplo n.º 4
0
/**
 *  \brief Configures the PIT & reset tickCount.
 *  Systick interrupt handler will generates 1ms interrupt and increase a
 *  tickCount.
 *  \note IRQ handler must be configured before invoking this function.
 *  \note PIT is enabled automatically in this function.
 *  \param new_mck  Current master clock.
 */
extern uint32_t TimeTick_Configure( uint32_t new_mck )
{
    _dwTickCount = 0 ;
    PIT_Init( 1000, new_mck / 1000000 );
    PIT_EnableIT();
    PIT_Enable();
    return 0;
}
Exemplo n.º 5
0
void PIT_Configuration (void)
{
	PIT_InitTypeDef PIT_InitStruct1;
	PIT_InitStruct1.PITx = PIT0;          //PIT0通道
	PIT_InitStruct1.PIT_Interval = 200;   //定时周期100MS
	PIT_Init(&PIT_InitStruct1);
	PIT_ITConfig(PIT0,PIT_IT_TIF,ENABLE);
	//NVIC_EnableIRQ(PIT0_IRQn);
}
Exemplo n.º 6
0
static void prvSetupTimerInterrupt( void )
{
const uint32_t ulPeriodIn_uS = ( 1.0 / ( double ) configTICK_RATE_HZ ) * port1SECOND_IN_uS;

	/* Setup the PIT for the required frequency. */
	PIT_Init( ulPeriodIn_uS, BOARD_MCK / port1MHz_IN_Hz );
	
	/* Setup the PIT interrupt. */
	AIC_DisableIT( AT91C_ID_SYS );
	AIC_ConfigureIT( AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, vPortTickISR );
	AIC_EnableIT( AT91C_ID_SYS );
	PIT_EnableIT();
}
Exemplo n.º 7
0
void kw41zAlarmInit(void)
{
    pit_config_t config;
    uint32_t     count = (CLOCK_GetBusClkFreq() / 1000) - 1;

    PIT_GetDefaultConfig(&config);
    PIT_Init(PIT, &config);
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, count);
    PIT_StartTimer(PIT, kPIT_Chnl_0);

    PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);
    NVIC_ClearPendingIRQ(PIT_IRQn);
    NVIC_EnableIRQ(PIT_IRQn);
}
Exemplo n.º 8
0
//--------------------------------------------------------------------------------------------------------
void System_Init(void)
{
  GPIO_Init();
  UART_Init();
  ADC_Init();
  PIT_Init();
  PWM_Init();
  LED_Init();
  InitFlashLed();
  //----------进入按键调参--------
  SetLED();
  
  //---------初始化全局变量-------
  CarControlStop();
  

  
  
  g_nCarCount=0;
  g_nSpeedControlCount=0;
  g_nSpeedControlPeriod=0;
  g_nDirectionControlCount=0;
  g_nDirectionControlPeriod=0;
  
  g_fAngleControlOut=0;
  
  g_nLeftMotorPulse=0;
  g_nRightMotorPulse=0;
  g_fCarSpeed=0;
  g_fSpeedControlOutNew=0;
  g_fSpeedControlOutOld=0;
  g_fSpeedControlIntegral=0;
  g_fSpeedControlOut=0;
  
  VOLTAGE_RIGHT=0;
  VOLTAGE_LEFT=0; 
  DIR_LEFT_OFFSET=0;
  DIR_RIGHT_OFFSET=0;
  g_fDirectionControlOutP=0;
  g_fDirectionControlOutD=0;
  g_fDirectionControlOutOld=0;
  g_fDirectionControlOutNew=0;
  g_fDirection=0;
  g_nDirectionGyro=0;
  g_fDirectionControlOut=0;
  
  g_fLeftMotorOut=0;
  g_fRightMotorOut=0;
}
Exemplo n.º 9
0
unsigned long int SysTick_Config(unsigned long int ticks)
{
  unsigned long int rate = SystemCoreClock/ticks;

/* Configure timer to interrupt specified times per second */

  PIT_Init(1000000/rate, SystemCoreClock/1000000);
  PIT_EnableIT();
  PIT_Enable();

/* Configure timer interrupt */

  AIC_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, TimerISR);
  AIC_EnableIT(AT91C_ID_SYS);

  return 0;
}
Exemplo n.º 10
0
/*!
 * @brief Main function
 */
int main(void)
{
    /* Structure of initialize PIT */
    pit_config_t pitConfig;

    /* Initialize and enable LED */
    LED_INIT();

    /* Board pin, clock, debug console init */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    /*
     * pitConfig.enableRunInDebug = false;
     */
    PIT_GetDefaultConfig(&pitConfig);

    /* Init pit module */
    PIT_Init(PIT, &pitConfig);

    /* Set timer period for channel 0 */
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(1000000U, PIT_SOURCE_CLOCK));

    /* Enable timer interrupts for channel 0 */
    PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);

    /* Enable at the NVIC */
    EnableIRQ(PIT_IRQ_ID);

    /* Start channel 0 */
    PRINTF("\r\nStarting channel No.0 ...");
    PIT_StartTimer(PIT, kPIT_Chnl_0);

    while (true)
    {
        /* Check whether occur interupt and toggle LED */
        if (true == pitIsrFlag)
        {
            PRINTF("\r\n Channel No.0 interrupt is occured !");
            LED_TOGGLE();
            pitIsrFlag = false;
        }
    }
}
Exemplo n.º 11
0
void initStateMachine()
{
    activityDetected();

    /* configure PIT module in chain mode */
    /* PIT clock source is bus clock,24MHz */
    /* PIT channel 0 load value = (600000-1) */
    uint32_t u32LoadValue0   	 = (BUS_CLOCK / 1000) * STEP_TIME_MS - 1; /* 25ms */
    sPITConfig.u32LoadValue      = u32LoadValue0;
    sPITConfig.bFreeze           = FALSE;
    sPITConfig.bModuleDis        = FALSE;    /*!< enable PIT module */
    sPITConfig.bInterruptEn      = TRUE;
    sPITConfig.bChainMode        = FALSE;
    sPITConfig.bTimerEn          = TRUE;

    PIT_Init(PIT_CHANNEL1, &sPITConfig);

    PIT_SetCallback(PIT_CHANNEL1, controlStateMachine);
}
Exemplo n.º 12
0
/*!
 * @brief Initialisation thread. runs once.
 */
void InitThread(void *data)
{
	for (;;)
	{
		OS_SemaphoreWait(InitSemaphore, 0);

		Random_Init();
		//Switches mate
		Switch_Init(S1Callback, (void *) 0, S2Callback, (void *) 0);

		Toggle_Init(ToggleModeFinished);
		Game_Init(GameModeFinished);

		Touch_Init();

//Initialize all the modules
		LEDs_Init();

		I2C_Init(100000, MODULE_CLOCK);
		Accel_Init(&AccelSetup);

		PIT_Init(MODULE_CLOCK, &PitCallback, (void *) 0);
		PIT_Set(500000000, bFALSE);
		PIT_Enable(bTRUE);

		Packet_Init(BAUD_RATE, MODULE_CLOCK);
		Flash_Init();
		CMD_Init();

		//Best to do this one last
		//TODO: disabled for yellow
    RTC_Init((void (*)(void*))OS_SemaphoreSignal, (void *) RtcSemaphore);

		Timer_Init();
		Timer_Set(&PacketTimer);
		Timer_Set(&AccTimer);

		CMD_SpecialGetStartupValues();

		LEDs_On(LED_ORANGE);
	}
}
Exemplo n.º 13
0
//------------------------------------------------------------------------------
/// Configures the PIT to generate 1ms ticks.
//------------------------------------------------------------------------------
static void ConfigurePit(void)
{
    // Initialize and enable the PIT
    PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000);

    // Disable the interrupt on the interrupt controller
    IRQ_DisableIT(AT91C_ID_SYS);

    // Configure the AIC for PIT interrupts
    IRQ_ConfigureIT(AT91C_ID_SYS, 0, ISR_Pit);

    // Enable the interrupt on the interrupt controller
    IRQ_EnableIT(AT91C_ID_SYS);

    // Enable the interrupt on the pit
    PIT_EnableIT();

    // Enable the pit
    PIT_Enable();
}
Exemplo n.º 14
0
void PitInit(unsigned int msperiod)
{
	PIT_DisableIT();
    // Initialize the PIT to the desired frequency
    PIT_Init(0, 0);
	// PIT timer runs at MCK/16 
	// calculates the PIT Value accurate to a Millisecond interrupt
	// msperiod can not be larget than 349 because PIV is at a 20bit limit
	if(msperiod > 349) msperiod = 349;
    PIT_SetPIV((MCK/(16*1000))*msperiod);
	
    // Configure interrupt on PIT
    AIC_DisableIT(AT91C_ID_SYS);
    AIC_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit);
    AIC_EnableIT(AT91C_ID_SYS);
    PIT_EnableIT();
	
    // Enable the pit
    PIT_Enable();
}
Exemplo n.º 15
0
void _start(void)
{
	InterruptManager_Init();
	PWM_Init();
	
	PIT_Init();
	PIT_EnableTimer(0);

	WDOG_Init();

	while(1)
	{
		uint32_t volatile *r = (uint32_t*)0xE000E200;
		if((r[(64 - 16)/32] >> ((64-16) % 32)) & 1)
		{
			r = (uint32_t*)0x400FF04C;
			r[0] |= (1 << 22);
		}
	}
}
Exemplo n.º 16
0
void main(void) 
{ 
    char send_cnt=0;
    SetBusCLK_40M();
    SCI0_Init();     
    PIT_Init();
    AD_Init();
    CCD_IO_Init();
    PWM_Init();
    PAC_Init();
    DDRT_DDRT0=1;
    PTT_PTT0=1;
    delay();
    Motor_forward(26);
    steering(STEER_MID);
    DDRM=0XFF;
    EnableInterrupts;
    for(;;)
    {

        if(TimerFlag20ms == 1) 
        {
            DisableInterrupts;
            TimerFlag20ms = 0;
            ImageCapture(Pixel);
            //CalculateIntegrationTime();
            //mid_val_3(Pixel);
            //send_cnt++;
            /*if(send_cnt>10) 
            {
                send_cnt=0;
                SendImageData(Pixel);
            } */
            find(Pixel,5,3,20);
            //CCD_P2(Pixel,3,18);
           steer_pd();
           EnableInterrupts;    
        }
    }
             
}
Exemplo n.º 17
0
/*******************************************************************************
 * @brief   main routine
 ******************************************************************************/
int main (void)
{  
  SIM_Init (SIM_MODULE_FRDM_SLCD_CONFIG);
  MCG_LITE_Init (MCG_LITE_HIRC_48MHZ);
  
  // OSC module initialization
  OSC_Init(OSC_MODULE_OSCERCLK_ON_STOPMODE_ON_CONFIG(OSC_SC16P));
  MCG_ExtClkType(OSC_REQST);
  MCG_CrystalMode(LOW_POWER_OSC);
  MCG_CrystalFreqRangeSel(LOW_FREQ_RANGE);
  MCG_WaitOscInit();
  
  // VLLx, VCAPx pins disable
  PORT_Init(PORTC, PORT_MODULE_DISABLED_MODE, PIN_20|PIN_21|PIN_22|PIN_23, 0, NULL);
  // SLCD pin configuration
  PORT_Init(PORTE, PORT_MODULE_ALT0_MODE, PIN_20|PIN_21, 0, NULL);
  PORT_Init(PORTB, PORT_MODULE_ALT0_MODE, PIN_18|PIN_19, 0, NULL);
  PORT_Init(PORTC, PORT_MODULE_ALT0_MODE, PIN_0|PIN_4|PIN_6|PIN_7, 0, NULL);
  PORT_Init(PORTD, PORT_MODULE_ALT0_MODE, PIN_0|PIN_2|PIN_3|PIN_4, 0, NULL);
  // SLCD initialization
  LCD_Init (LCD_FRDM_CONFIG,                                                    \
            LCD_FRONT_PLANE_PINS_FRDM_KL43,                                     \
            LCD_BACK_PLANE_PINS_FRDM_KL43,                                      \
            LCD_ASSIGN_BACK_PLANES_FRDM_KL43);
  //LCD_Write_Segments(LCD_ALL_SEGMENTS_OFF_FRDM_KL43);
  LCD_Delete_Char(0);
  LCD_Delete_Char(1);
  LCD_Delete_Char(2);
  LCD_Delete_Char(3);
  // PIT initialization - CH0 for LCD intro text running 
  PIT_Init (PIT0, CH0, PIT_CH_TIMER_EN_CONFIG, 6000000, 1, pit_callback);
  
  __enable_irq();
  
  while (1)
  {
    
  }
}
Exemplo n.º 18
0
/*
 * The application must provide a function that configures a peripheral to
 * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()
 * in FreeRTOSConfig.h to call the function.  This file contains a function
 * that is suitable for use on the Atmel SAMA5.
 */
void vConfigureTickInterrupt( void )
{
	/* NOTE:  The PIT interrupt is cleared by the configCLEAR_TICK_INTERRUPT()
	macro in FreeRTOSConfig.h. */

	/* Enable the PIT clock. */
	PMC->PMC_PCER0 = 1 << ID_PIT;

	/* Initialize the PIT to the desired frequency - specified in uS. */
	PIT_Init( 1000000UL / configTICK_RATE_HZ, ( BOARD_MCK / 2 ) / 1000000 );

	/* Enable IRQ / select PIT interrupt. */
	PMC->PMC_PCER1 = ( 1 << ( ID_IRQ - 32 ) );
	AIC->AIC_SSR  = ID_PIT;

	/* Ensure interrupt is disabled before setting the mode and installing the
	handler.  The priority of the tick interrupt should always be set to the
	lowest possible. */
	AIC->AIC_IDCR = AIC_IDCR_INTD;
	AIC->AIC_SMR  = AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE;
	AIC->AIC_SVR = ( uint32_t ) FreeRTOS_Tick_Handler;

	/* Start with the interrupt clear. */
	AIC->AIC_ICCR = AIC_ICCR_INTCLR;

	/* Enable the interrupt in the AIC and peripheral. */
	AIC_EnableIT( ID_PIT );
	PIT_EnableIT();

	/* Enable the peripheral. */
	PIT_Enable();

	/* Prevent compiler warnings in the case where System_Handler() is not used
	as the handler.  See the comments above the System_Handler() function
	prototype at the top of this file. */
	( void ) System_Handler;
}
Exemplo n.º 19
0
void us_ticker_init(void)
{
    /* Common for ticker/timer. */
    uint32_t busClock;
    /* Structure to initialize PIT. */
    pit_config_t pitConfig;

    if (us_ticker_inited) {
        /* calling init again should cancel current interrupt */
        TPM_DisableInterrupts(TPM2, kTPM_TimeOverflowInterruptEnable);
        return;
    }

    PIT_GetDefaultConfig(&pitConfig);
    PIT_Init(PIT, &pitConfig);

    busClock = CLOCK_GetFreq(kCLOCK_BusClk);

    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, busClock / 1000000 - 1);
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, 0xFFFFFFFF);
    PIT_SetTimerChainMode(PIT, kPIT_Chnl_1, true);
    PIT_StartTimer(PIT, kPIT_Chnl_0);
    PIT_StartTimer(PIT, kPIT_Chnl_1);

    /* Configure interrupt generation counters and disable ticker interrupts. */
    tpm_config_t tpmConfig;

    TPM_GetDefaultConfig(&tpmConfig);
    /* Set to Div 32 to get 1MHz clock source for TPM */
    tpmConfig.prescale = kTPM_Prescale_Divide_32;
    TPM_Init(TPM2, &tpmConfig);
    NVIC_SetVector(TPM2_IRQn, (uint32_t)tpm_isr);
    NVIC_EnableIRQ(TPM2_IRQn);

    us_ticker_inited = true;
}
Exemplo n.º 20
0
void Peripherals_Init(void)
{
#ifdef NVIC_AUTOINIT
  NVIC_Init();
#endif /* NVIC_AUTOINIT */
#ifdef SIM_AUTOINIT
  SIM_Init();
#endif /* SIM_AUTOINIT */

#ifdef MCM_AUTOINIT
  MCM_Init();
#endif /* MCM_AUTOINIT */
#ifdef PMC_AUTOINIT
  PMC_Init();
#endif /* PMC_AUTOINIT */
#ifdef PORTA_AUTOINIT
  PORTA_Init();
#endif /* PORTA_AUTOINIT */
#ifdef PORTB_AUTOINIT
  PORTB_Init();
#endif /* PORTB_AUTOINIT */
#ifdef PORTC_AUTOINIT
  PORTC_Init();
#endif /* PORTC_AUTOINIT */
#ifdef PORTD_AUTOINIT
  PORTD_Init();
#endif /* PORTD_AUTOINIT */
#ifdef PORTE_AUTOINIT
  PORTE_Init();
#endif /* PORTE_AUTOINIT */

#ifdef ADC0_AUTOINIT
  ADC0_Init();
#endif /* ADC0_AUTOINIT */
#ifdef ADC1_AUTOINIT
  ADC1_Init();
#endif /* ADC1_AUTOINIT */
#ifdef AIPS0_AUTOINIT
  AIPS0_Init();
#endif /* AIPS0_AUTOINIT */
#ifdef AIPS1_AUTOINIT
  AIPS1_Init();
#endif /* AIPS1_AUTOINIT */
#ifdef AXBS_AUTOINIT
  AXBS_Init();
#endif /* AXBS_AUTOINIT */
#ifdef CAN0_AUTOINIT
  CAN0_Init();
#endif /* CAN0_AUTOINIT */
#ifdef CMP0_AUTOINIT
  CMP0_Init();
#endif /* CMP0_AUTOINIT */
#ifdef CMP1_AUTOINIT
  CMP1_Init();
#endif /* CMP1_AUTOINIT */
#ifdef CMP2_AUTOINIT
  CMP2_Init();
#endif /* CMP2_AUTOINIT */
#ifdef CMT_AUTOINIT
  CMT_Init();
#endif /* CMT_AUTOINIT */
#ifdef CRC_AUTOINIT
  CRC_Init();
#endif /* CRC_AUTOINIT */
#ifdef DAC0_AUTOINIT
  DAC0_Init();
#endif /* DAC0_AUTOINIT */
#ifdef DMAMUX_AUTOINIT
  DMAMUX_Init();
#endif /* DMAMUX_AUTOINIT */
#ifdef DMA_AUTOINIT
  DMA_Init();
#endif /* DMA_AUTOINIT */
#ifdef ENET_AUTOINIT
  ENET_Init();
#endif /* ENET_AUTOINIT */
#ifdef EWM_AUTOINIT
  EWM_Init();
#endif /* EWM_AUTOINIT */
#ifdef FB_AUTOINIT
  FB_Init();
#endif /* FB_AUTOINIT */
#ifdef FMC_AUTOINIT
  FMC_Init();
#endif /* FMC_AUTOINIT */
#ifdef FTFE_AUTOINIT
  FTFE_Init();
#endif /* FTFE_AUTOINIT */
#ifdef FTM0_AUTOINIT
  FTM0_Init();
#endif /* FTM0_AUTOINIT */
#ifdef FTM1_AUTOINIT
  FTM1_Init();
#endif /* FTM1_AUTOINIT */
#ifdef FTM2_AUTOINIT
  FTM2_Init();
#endif /* FTM2_AUTOINIT */
#ifdef FTM3_AUTOINIT
  FTM3_Init();
#endif /* FTM3_AUTOINIT */
#ifdef I2C0_AUTOINIT
  I2C0_Init();
#endif /* I2C0_AUTOINIT */
#ifdef I2C1_AUTOINIT
  I2C1_Init();
#endif /* I2C1_AUTOINIT */
#ifdef I2C2_AUTOINIT
  I2C2_Init();
#endif /* I2C2_AUTOINIT */
#ifdef I2S0_AUTOINIT
  I2S0_Init();
#endif /* I2S0_AUTOINIT */
#ifdef LLWU_AUTOINIT
  LLWU_Init();
#endif /* LLWU_AUTOINIT */
#ifdef LPTMR0_AUTOINIT
  LPTMR0_Init();
#endif /* LPTMR0_AUTOINIT */
#ifdef MPU_AUTOINIT
  MPU_Init();
#endif /* MPU_AUTOINIT */
#ifdef PDB0_AUTOINIT
  PDB0_Init();
#endif /* PDB0_AUTOINIT */
#ifdef PIT_AUTOINIT
  PIT_Init();
#endif /* PIT_AUTOINIT */
#ifdef PTA_AUTOINIT
  PTA_Init();
#endif /* PTA_AUTOINIT */
#ifdef PTB_AUTOINIT
  PTB_Init();
#endif /* PTB_AUTOINIT */
#ifdef PTC_AUTOINIT
  PTC_Init();
#endif /* PTC_AUTOINIT */
#ifdef PTD_AUTOINIT
  PTD_Init();
#endif /* PTD_AUTOINIT */
#ifdef PTE_AUTOINIT
  PTE_Init();
#endif /* PTE_AUTOINIT */
#ifdef RCM_AUTOINIT
  RCM_Init();
#endif /* RCM_AUTOINIT */
#ifdef RNG_AUTOINIT
  RNG_Init();
#endif /* RNG_AUTOINIT */
#ifdef RTC_AUTOINIT
  RTC_Init();
#endif /* RTC_AUTOINIT */
#ifdef SDHC_AUTOINIT
  SDHC_Init();
#endif /* SDHC_AUTOINIT */
#ifdef SMC_AUTOINIT
  SMC_Init();
#endif /* SMC_AUTOINIT */
#ifdef SPI0_AUTOINIT
  SPI0_Init();
#endif /* SPI0_AUTOINIT */
#ifdef SPI1_AUTOINIT
  SPI1_Init();
#endif /* SPI1_AUTOINIT */
#ifdef SPI2_AUTOINIT
  SPI2_Init();
#endif /* SPI2_AUTOINIT */
#ifdef SystemControl_AUTOINIT
  SystemControl_Init();
#endif /* SystemControl_AUTOINIT */
#ifdef SysTick_AUTOINIT
  SysTick_Init();
#endif /* SysTick_AUTOINIT */
#ifdef UART0_AUTOINIT
  UART0_Init();
#endif /* UART0_AUTOINIT */
#ifdef UART1_AUTOINIT
  UART1_Init();
#endif /* UART1_AUTOINIT */
#ifdef UART2_AUTOINIT
  UART2_Init();
#endif /* UART2_AUTOINIT */
#ifdef UART3_AUTOINIT
  UART3_Init();
#endif /* UART3_AUTOINIT */
#ifdef UART4_AUTOINIT
  UART4_Init();
#endif /* UART4_AUTOINIT */
#ifdef UART5_AUTOINIT
  UART5_Init();
#endif /* UART5_AUTOINIT */
#ifdef USB0_AUTOINIT
  USB0_Init();
#endif /* USB0_AUTOINIT */
#ifdef USBDCD_AUTOINIT
  USBDCD_Init();
#endif /* USBDCD_AUTOINIT */
#ifdef VREF_AUTOINIT
  VREF_Init();
#endif /* VREF_AUTOINIT */
#ifdef WDOG_AUTOINIT
  WDOG_Init();
#endif /* WDOG_AUTOINIT */
}
Exemplo n.º 21
0
Arquivo: main.c Projeto: kfreezen/kos
int kmain(UInt32 initial_stack, MultibootHeader* mboot, UInt32 mboot_magic) {
	initial_esp = initial_stack;
	
	CLI_Init();
	Cls();
	
	UInt32 initrd_end = *(UInt32*)(mboot->mods_addr+4);
	
	placement_address = (Pointer) initrd_end;
	
	// Set up our new stack here.
	//UInt32 stack = (UInt32) kmalloc_a(8192, TRUE);
	MultibootHeader* mboot_hdr = mboot; //kmalloc(sizeof(MultibootHeader));
	//memcpy(mboot_hdr, mboot, sizeof(MultibootHeader));
	
	kprintf("Starting init...\n");

	//new_start(stack, mboot_hdr);
	GDT_Init();
	IDT_Init();
	ISR_Init();
	asm volatile("sti");
	
	kprintf("Basics\t\t\t[OK]\n");

	PIT_Init(PIT_MSTIME);

	kprintf("PIT\t\t\t[OK]\n");

	init_kheap();
	InitPaging((mboot_hdr->mem_lower+mboot_hdr->mem_upper)&~3);
	InitKernelHeap();

	kprintf("Heap\t\t\t[OK]\n");

	VFS_Init();
	DevFS_Init();
	
	kprintf("VFS\t\t\t[OK]\n");

	DriversInit();

	kprintf("Drivers\t\t\t[OK]\n");

	Screen_Init();

	FloppyInit();

	checkAllBuses();
	DumpPCIDeviceData();
	kprintf("PCI\t\t\t[OK]\n");

	/*kprintf("Keyboard Init... ");
	KB_Init(0);
	kprintf("[ok]\n");*/

	FAT12_Init(FAT12_GetContext(FloppyGetDevice()), "/", "sys");
	
	InitTasking();

	KernelSymbolsLoad();

	//Cls();

	kprintf("kOS v0.6.13\n");

	VFS_Node* rd = GetNodeFromFile(GetFileFromPath("/sys"));
	kprintf("rd = %x\n", rd);
	
	ArrayList* list = ListFiles(rd);
	ALIterator* itr = ALGetItr(list);

	while(ALItrHasNext(itr)) {
		VFS_Node* node = ALItrNext(itr);
		kprintf("file: %s\n", node->name);
	}

	ALFreeItr(itr);
	
	ALFreeList(list);

	//kprintf("kprintf symbol = %x\n", getKernelSymbol("kprintf"));
	File* initScript = GetFileFromPath("/sys/init.script");
	FileSeek(0, initScript); // Due to these being global objects, we have to do such ugly things as this.

	#ifdef INIT_DEBUG
	kprintf("initScript=%x\n", initScript);
	#endif

	char* lineBuf = kalloc(256);
	int doBreak = 0;
	while(!doBreak) {
		if(fgetline(initScript, lineBuf, 256, '\n')==-1) {
			if(strlen(lineBuf) > 0) {
				doBreak = 1;
			} else {
				break; // We've processed everything that needs to be processed.
			}
		}

		// Now parse it.
		char* tok = strtok(lineBuf, " ");
		kprintf("%s, %x\n", tok,tok);
		if(!strcmp(tok, "load_driver")) {
			#ifdef INIT_DEBUG
			kprintf("load_driver ");
			#endif

			tok = strtok(NULL, " ");

			// Load the driver specified.
			File* drv = GetFileFromPath(tok);
			if(drv != NULL) {
				int drvLength = FileSeek(SEEK_EOF, drv);
				FileSeek(0, drv);
				void* drvBuf = kalloc(drvLength);

				#ifdef INIT_DEBUG
				kprintf("%s\n", GetNodeFromFile(drv)->name);
				#endif

				ReadFile(drvBuf, drvLength, drv);
				ELF* elf = LoadKernelDriver(drvBuf);

				#ifdef INIT_DEBUG
				kprintf("elf->start=%x\n", elf->start);
				#endif

				if(elf->error == 0) {
					void (*driverInit)() = (void (*)()) elf->start;
					driverInit();
				}

				kfree(drvBuf);
				drvBuf = NULL;

				CloseFile(drv);
			}
		}
	}

	CloseFile(initScript);
	kfree(lineBuf);

	kprintf("Kernel init done...\n");

	File* elf = GetFileFromPath("/sys/helloworld");
	
	FileSeek(SEEK_EOF, elf);
	int length = FileTell(elf);
	FileSeek(0, elf);
	UInt8* elfBuf = kalloc(length);
	ReadFile(elfBuf, length, elf);
	ELF* elfExe = Parse_ELF(elfBuf);
	CreateTaskFromELF(elfExe);

	// Kernel main logic loop
	while(1) {
		asm volatile("hlt");
	}

	return 0;
}
Exemplo n.º 22
0
Arquivo: main.c Projeto: oldjohnh/car
int main(void)
{
	unsigned char i;          
	unsigned char Send_Count; 
	uint32_t DMA_Value0 = 0;
	uint32_t DMA_Value1 = 0;
	PIT_InitTypeDef PIT_InitStruct1;
	GPIO_InitTypeDef GPIO_InitStruct1;
	FTM_InitTypeDef FTM_InitStruct1;
	DMACNT_InitTypeDef DMACNT_InitStruct1;
	SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
	UART_DebugPortInit(UART0_RX_PA14_TX_PA15,115200);
	DisplayCPUInfo();
	DelayInit();
	OLED_Init();
	DMACNT_InitStruct1.DMACNT_Mode = DMACNT_MODE_FALLING;  //ÉÏÉýÑؼÆÊý
	DMACNT_InitStruct1.DMA_Chl = DMA_CH0;                 //ʹÓÃͨµÀ 0
	DMACNT_InitStruct1.GPIOx = PTC;                       //PTC5
	DMACNT_InitStruct1.GPIO_Pin = GPIO_Pin_5; 
	DMACNT_Init(&DMACNT_InitStruct1);

	GPIO_InitStruct1.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStruct1.GPIO_InitState = Bit_RESET;
	GPIO_InitStruct1.GPIO_IRQMode = GPIO_IT_DISABLE;
	GPIO_InitStruct1.GPIO_Mode = GPIO_Mode_OPP;
	GPIO_InitStruct1.GPIOx = PTB;
	GPIO_Init(&GPIO_InitStruct1);
	
	GPIO_InitStruct1.GPIO_Pin = GPIO_Pin_1;
	GPIO_InitStruct1.GPIO_InitState = Bit_SET;
	GPIO_InitStruct1.GPIOx = PTB;
	GPIO_Init(&GPIO_InitStruct1);
	
	PIT_InitStruct1.PITx=PIT2;
	PIT_InitStruct1.PIT_Interval=100;
	PIT_Init(&PIT_InitStruct1);
	NVIC_EnableIRQ(PIT2_IRQn);
	PIT_ITConfig(PIT2,PIT_IT_TIF,ENABLE);
	
	PIT_InitStruct1.PITx=PIT0;
	PIT_InitStruct1.PIT_Interval=20000;
	PIT_Init(&PIT_InitStruct1);
	PIT_ITConfig(PIT0,PIT_IT_TIF,ENABLE);
	NVIC_EnableIRQ(PIT0_IRQn);
	FTM_InitStruct1.Frequency = 800;
	FTM_InitStruct1.FTM_Mode = FTM_Mode_EdgeAligned;
//	FTM_InitStruct1.InitalDuty = 10000;
	FTM_InitStruct1.FTMxMAP = FTM0_CH0_PC1;
	FTM_Init(&FTM_InitStruct1);
	UART_printf("DMACNT_CH0_Value:%d \n",*Pid_Out);


	while(1)
	{
//		if(key_detect1()){
//			Pid_Set += 500;
//		}
//		if(key_detect3()){
//			Pid_Set -= 500;
//		}
		GPIO_ResetBits(PTB,GPIO_Pin_0);
		PidError[2] = Pid_Set - *Pid_Out;
		PidOut =  Kp * (PidError[2] - PidError[1]);
		PidOut += Ki *  PidError[2] * Td;
		PidOut += Kd * (PidError[2] - 2 * PidError[1] + PidError[0]) / Td;
		PidError[0] = PidError[1];
		PidError[1] = PidError[2];
		PID_FinalOut =PidOut*2;
		
		
//		
//		if(key_detect5()){
//			Kd+=0.2;OLED_Clear();
//		}
//		else if(key_detect6()){
//			Kd-=0.2;OLED_Clear();
//		}
//		
//		OLED_Write_String(2,0,"Kp");
//		OLED_Write_String(2,2,"Ki");
//		OLED_Write_String(2,4,"Kd");
//		OLED_Write_Num3(6,0,Kp*10);
//		OLED_Write_Num3(6,2,Ki*10);
//		OLED_Write_Num3(6,4,Kd*10);
//		OLED_Write_Num4(9,6,*Pid_Out-1000);
//		
		
		if(PID_FinalOut>10000) PID_FinalOut=10000;
		else if(PID_FinalOut<0) PID_FinalOut=0;
		
		FTM_PWM_ChangeDuty(FTM0_CH0_PC1,PID_FinalOut);
		
	}
}