Exemple #1
0
int timer_init(tim_t dev, unsigned long freq, timer_cb_t callback, void *arg)
{
    TIMER_TypeDef *pre, *tim;

    /* test if given timer device is valid */
    if (dev >= TIMER_NUMOF) {
        return -1;
    }

    /* save callback */
    isr_ctx[dev].cb = callback;

    /* get timers */
    pre = timer_config[dev].prescaler.dev;
    tim = timer_config[dev].timer.dev;

    /* enable clocks */
    CMU_ClockEnable(cmuClock_HFPER, true);
    CMU_ClockEnable(timer_config[dev].prescaler.cmu, true);
    CMU_ClockEnable(timer_config[dev].timer.cmu, true);

    /* reset and initialize peripherals */
    EFM32_CREATE_INIT(init_pre, TIMER_Init_TypeDef, TIMER_INIT_DEFAULT,
        .conf.enable = false,
        .conf.prescale = timerPrescale1
    );
    EFM32_CREATE_INIT(init_tim, TIMER_Init_TypeDef, TIMER_INIT_DEFAULT,
        .conf.enable = false,
        .conf.clkSel = timerClkSelCascade
    );

    TIMER_Reset(tim);
    TIMER_Reset(pre);

    TIMER_Init(tim, &init_tim.conf);
    TIMER_Init(pre, &init_pre.conf);

    /* configure the prescaler top value */
    uint32_t freq_timer = CMU_ClockFreqGet(timer_config[dev].prescaler.cmu);
    uint32_t top = (
        freq_timer / TIMER_Prescaler2Div(init_pre.conf.prescale) / freq) - 1;

    TIMER_TopSet(pre, top);
    TIMER_TopSet(tim, 0xffff);

    /* enable interrupts for the channels */
    TIMER_IntClear(tim, TIMER_IFC_CC0 | TIMER_IFC_CC1 | TIMER_IFC_CC2);
    TIMER_IntEnable(tim, TIMER_IEN_CC0 | TIMER_IEN_CC1 | TIMER_IEN_CC2);

    NVIC_ClearPendingIRQ(timer_config[dev].irq);
    NVIC_EnableIRQ(timer_config[dev].irq);

    /* start the timers */
    TIMER_Enable(tim, true);
    TIMER_Enable(pre, true);

    return 0;
}
int main (void)
{
	
	DDRC= 0xff;
	DDRD= 0xff;
	
	//UART_Init(9600);

	TIMER_Init(0,7500);                  /* Configure timer0 to generate 100ms(100000us) delay*/
	TIMER_AttachInterrupt(0,myTimerIsr_0);  /* myTimerIsr_0 will be called by TIMER0_IRQn */
	TIMER_Start(0);                         /* Start the Timers */
	
	TIMER_Init(1,30000);                  /* Configure timer0 to generate 100ms(100000us) delay*/
	TIMER_AttachInterrupt(1,myTimerIsr_1);  /* myTimerIsr_0 will be called by TIMER0_IRQn */
	// TIMER_Start(1);
	
	TIMER_Init(2,15000);                  /* Configure timer0 to generate 100ms(100000us) delay*/
	TIMER_AttachInterrupt(2,myTimerIsr_2);  /* myTimerIsr_0 will be called by TIMER0_IRQn */
	TIMER_Start(2);
	TIMER_Start(1);
	

	sei();


	while(1)
	{
		
		
		PORTC = value;
		
	}
	
	/*
	{
		if(flag == 1)
		{
			flag = 0;
			TIMER_Stop(0);
			TIMER_Stop(1);
			TIMER_Stop(2);
			
			UART_Printf("Timer0=%8U Timer1:%8U \nTimer2:%8U",TIMER_GetTime(0),TIMER_GetTime(1),TIMER_GetTime(2));
			
		}
	}
	*/

}
Exemple #3
0
void setup()
{
	setupSystemClock();
	setup_system_tick(SYSTEM_TICK_FREQ);
	setupUART();
#ifdef GPS
	setupGPS();
#endif
	I2C_Init();
	FlashInit();
	UpdateBoardVersion(false);
#ifdef OPTION_RC
	RC_Init();
	if(IsSSVConnected())
		Battery_Init();
	LED_Init();
	TIMER_Init();
	stabilizerInit();
#endif
#ifdef ABROBOT
  ABRobotMotorInit();
#endif
	nvtAHRSInit();
	SensorsInit();
	ChronographSet(ChronMain);
}
Exemple #4
0
void initTimer()
{
  TIMER_Init_TypeDef initValues = TIMER_INIT_DEFAULT;

  /* Enable clock for TIMER0 */
  CMU_ClockEnable(cmuClock_TIMER0, true);
  CMU_ClockEnable(cmuClock_I2C0, true);

  /* Enable underflow and overflow interrupt for TIMER0*/
  TIMER_IntEnable(TIMER0, TIMER_IF_OF);

  /* Enable TIMER0 interrupt vector in NVIC */
  NVIC_EnableIRQ(TIMER0_IRQn);

  /* Set TIMER0 Top value */
  //TIMER_TopSet(TIMER0, 27342);
  TIMER_TopSet(TIMER0, 7000);

  /* Initialize TIMER0 in Up mode with 1024x prescaling */
  initValues.prescale = timerPrescale1024;
  initValues.mode     = timerModeUp;
  TIMER_Init(TIMER0, &initValues);

  /* Start TIMER0 */
  TIMER0->CMD = TIMER_CMD_START;
}
Exemple #5
0
int main(void) {

	/* SystemInit() called by "startup_stm32f40xx.S" */

    /* Init PWM */
    PWM_Pins_Init();

    /* Init timer */
    TIMER_Init();

    /* Init SVPWM */
    SVPWM_Init();

    /* Init 16kHz Interrupt */
    INT_TIM2_Config();

    /* Init ADC1 Channel 0 & ADC2 Channel1 */
    ADC123_Init();

    /* Configure Encoder with Tim8 on GPIOC 6 & 7 */
    configureEncoder();

    /* Enable USART2 */
    USART2_Init();

    GPIO_SetBits(GPIOB, GPIO_Pin_10);



    while (1) {


    }
}
Exemple #6
0
/*************************************************
* Function: PCT_Sleep
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_Sleep()
{
    u32 u32Index;
    MSG_Init();

    g_struProtocolController.u8keyRecv = PCT_KEY_UNRECVED;
    memcpy(g_struProtocolController.u8SessionKey, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    memcpy(g_struProtocolController.IvSend, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    memcpy(g_struProtocolController.IvRecv, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    for (u32Index = 0; u32Index < ZC_TIMER_MAX_NUM; u32Index++)
    {
        if (g_struTimer[u32Index].u8Status == ZC_TIMER_STATUS_USED)
        {
            TIMER_StopTimer((u8)u32Index);
        }
    }

    TIMER_Init();
    g_struProtocolController.u8ReconnectTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8HeartTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8CloudAckTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8MainState = PCT_STATE_INIT;
    g_struProtocolController.u8RegisterTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u32CloudNotAckNum = 0;
    PCT_SendNotifyMsg(ZC_CODE_WIFI_DISCONNECTED);
    ZC_ClientSleep();
}
Exemple #7
0
/***************************************************************************//**
 * @brief
 *   Activate the hardware timer used to pace the 1 millisecond timer system.
 *
 * @details
 *   Call this function whenever the HFPERCLK frequency is changed.
 *   This function is initially called by HOST and DEVICE stack xxxx_Init()
 *   functions.
 ******************************************************************************/
void USBTIMER_Init( void )
{
  uint32_t freq;
  TIMER_Init_TypeDef timerInit     = TIMER_INIT_DEFAULT;
  TIMER_InitCC_TypeDef timerCCInit = TIMER_INITCC_DEFAULT;

  freq = CMU_ClockFreqGet( cmuClock_HFPER );
  ticksPrMs = ( freq + 500 ) / 1000;
  ticksPr1us = ( freq + 500000 ) / 1000000;
  ticksPr10us = ( freq + 50000 ) / 100000;
  ticksPr100us = ( freq + 5000 ) / 10000;

  timerCCInit.mode = timerCCModeCompare;
  CMU_ClockEnable( TIMER_CLK, true );
  TIMER_TopSet( TIMER, 0xFFFF );
  TIMER_InitCC( TIMER, 0, &timerCCInit );
  TIMER_Init( TIMER, &timerInit );

#if ( NUM_QTIMERS > 0 )
  TIMER_IntClear( TIMER, 0xFFFFFFFF );
  TIMER_IntEnable( TIMER, TIMER_IEN_CC0 );
  TIMER_CompareSet( TIMER, 0, TIMER_CounterGet( TIMER ) + ticksPrMs );
  NVIC_ClearPendingIRQ( TIMER_IRQ );
  NVIC_EnableIRQ( TIMER_IRQ );
#endif /* ( NUM_QTIMERS > 0 ) */
}
/*************************************************
* Function: PCT_Init
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_Init(PTC_ModuleAdapter *pstruAdapter)
{
    g_struProtocolController.pstruMoudleFun = pstruAdapter;

    g_struProtocolController.struCloudConnection.u32Socket = PCT_INVAILD_SOCKET;

    /*config connection type*/
    g_struProtocolController.struCloudConnection.u16Port = ZC_CLOUD_PORT;
    g_struProtocolController.struCloudConnection.u8IpType = ZC_IPTYPE_IPV4;
    g_struProtocolController.struCloudConnection.u8ConnectionType = ZC_CONNECT_TYPE_TCP;

    g_struProtocolController.struClientConnection.u32Socket = PCT_INVAILD_SOCKET;

    /*config connection type*/
    g_struProtocolController.struClientConnection.u16Port = ZC_SERVER_PORT;
    g_struProtocolController.struClientConnection.u8IpType = ZC_IPTYPE_IPV4;
    g_struProtocolController.struClientConnection.u8ConnectionType = ZC_CONNECT_TYPE_TCP;

    ZC_ConfigInitPara();

    MSG_Init();
    TIMER_Init();
    
    g_struProtocolController.u8keyRecv = PCT_KEY_UNRECVED;
    g_struProtocolController.u8ReconnectTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8HeartTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8RegisterTimer = PCT_TIMER_INVAILD;

    g_struProtocolController.u8MainState = PCT_STATE_INIT;

    //ZC_ClientInit();
}
/*************************************************
* Function: PCT_ReconnectCloud
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_ReconnectCloud(PTC_ProtocolCon *pstruContoller, u32 u32ReConnectTimer)
{
    u32 u32Index;
    if (PCT_TIMER_INVAILD != pstruContoller->u8ReconnectTimer)
    {
        ZC_Printf("already reconnected \n");
        return;
    }
    

    MSG_Init();
    g_struProtocolController.u8keyRecv = PCT_KEY_UNRECVED;

    for (u32Index = 0; u32Index < ZC_TIMER_MAX_NUM; u32Index++)
    {
        
        if (g_struTimer[u32Index].u8Status == ZC_TIMER_STATUS_USED)
        {
            TIMER_StopTimer((u8)u32Index);
        }
    }
    
    TIMER_Init();
    g_struProtocolController.u8ReconnectTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8HeartTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8MainState = PCT_STATE_INIT;

    pstruContoller->pstruMoudleFun->pfunSetTimer(PCT_TIMER_RECONNECT, 
        u32ReConnectTimer, &pstruContoller->u8ReconnectTimer);
    pstruContoller->struCloudConnection.u32Socket = PCT_INVAILD_SOCKET;
    pstruContoller->u8keyRecv = PCT_KEY_UNRECVED; 
    pstruContoller->u8MainState = PCT_STATE_INIT;
}
Exemple #10
0
void timerSetup(void){
	  /* Enable clock for TIMER0 module */
	  CMU_ClockEnable(cmuClock_TIMER0, true);

	  /* Select TIMER0 parameters */
	  TIMER_Init_TypeDef timerInit;

	  timerInit.enable = true;
	  timerInit.debugRun = true;
	  timerInit.prescale = timerPrescale1024;
	  timerInit.clkSel = timerClkSelHFPerClk;
	  timerInit.fallAction = timerInputActionNone;
	  timerInit.riseAction = timerInputActionNone;
	  timerInit.mode       = timerModeUp;
	  timerInit.dmaClrAct  = false;
	  timerInit.quadModeX4 = false;
	  timerInit.oneShot    = false;
	  timerInit.sync       = false;




	    /* Enable TIMER0 interrupt vector in NVIC */
	    NVIC_EnableIRQ(TIMER0_IRQn);

	    /* Set TIMER Top value */
	    TIMER_TopSet(TIMER0, TOP);

	    /* Configure TIMER */
	     TIMER_Init(TIMER0, &timerInit);


}
/**
 *    \brief    Initializes SysTick.
 */
static void _hal_tcInit(void)
{
    uint32_t l_ticks;
    TIMER_TypeDef* ps_timer = TIMER1;
    TIMER_Init_TypeDef s_timerInit = TIMER_INIT_DEFAULT;

    s_timerInit.enable = true;
    s_timerInit.prescale = timerPrescale2;
    s_timerInit.riseAction = timerInputActionReloadStart;

    /* caluclate ticks */
    l_ticks = SystemHFClockGet() / 2 / 1000;

    /* configure timer for 1ms */
    TIMER_TopSet( ps_timer, l_ticks );
    /* enable timer interrupts */
    NVIC_DisableIRQ( TIMER1_IRQn );
    NVIC_ClearPendingIRQ( TIMER1_IRQn );
    NVIC_EnableIRQ( TIMER1_IRQn );
    TIMER_IntEnable( ps_timer, TIMER_IEN_OF );

    /* initialize and start timer */
    TIMER_Init( ps_timer, &s_timerInit );

} /* _hal_tcInit() */
void writeWaveform(uint16_t pin, uint16_t * values, uint8_t nrOfSamples, uint32_t period, uint16_t presc, uint8_t repetition)
{
	GPIOWriter.elements = nrOfSamples;
	GPIOWriter.pins = pin;
	GPIOWriter.repeat = repetition;
	GPIOWriter.table = (uint16_t *)&values;
	
	TIMER_Init(TIM2, period, presc, true, TIM2_IRQn);	
}
Exemple #13
0
void initboard()
{
	CSL_init();
	PLL_Init();
	EMIF_Init();
	TIMER_Init();

	IRQ_globalDisable();
}
Exemple #14
0
int main(void) 
{
	
	CHIP_Init();

	if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  BSP_Init(BSP_INIT_DEFAULT);
	BSP_LedsSet(0);

  BSP_PeripheralAccess(BSP_AUDIO_IN, true);
  BSP_PeripheralAccess(BSP_AUDIO_OUT, true);

  RTCDRV_Trigger(1000, NULL);
  EMU_EnterEM2(true);

  initSource();

	setupCMU();
  setupDMA();
  
  //setupADC();
  //setupDAC();

  //setupDMAInput();
  //setupDMAOutput();

	//setupDMASplit();
	//setupDMAMerge();

  ADCConfig();
  DACConfig();

  TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT;
  TIMER_TopSet(TIMER0, CMU_ClockFreqGet(cmuClock_HFPER) / SAMPLE_RATE);
  TIMER_Init(TIMER0, &timerInit);

	Delay(100);
	BSP_LedsSet(3);
	Delay(500);
	BSP_LedsSet(0);
	Delay(100);

	while(1) {
		volatile bool result = test();
		if (result) {
			BSP_LedsSet(0x00FF);
		} else {
			BSP_LedsSet(0xFF00);			
		}
		Delay(1000);
    BSP_LedsSet(0x0);    
    Delay(1000);
	}

}
/***************************************************************************//**
* @brief
*   Configure Timer for this application.
*******************************************************************************/
static void TimerConfig(void)
{
  /* Use default timer settings */
  TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT;

  /* Change prescaler to 64, gives roughly 3 overflows per
   * second at 14MHz with 0xffff as top value */
  timerInit.prescale = timerPrescale64;
  TIMER_Init(TIMER0, &timerInit);
}
Exemple #16
0
void setupTIMER( void )
{
	TIMER_Init_TypeDef init = TIMER_INIT_DEFAULT;

	init.mode = timerModeUpDown;

	TIMER_TopSet( TIMER0, CMU_ClockFreqGet(cmuClock_HFPER) / 22050 );
	TIMER_Init( TIMER0, &init );

}
Exemple #17
0
int main (void) 
{
    SystemInit();

    GPIO_PinDirection(LED1,OUTPUT);        /* Configure the pins as Output to blink the Leds*/
    GPIO_PinDirection(LED2,OUTPUT);

    TIMER_Init(0,100000);                  /* Configure timer0 to generate 100ms(100000us) delay*/
    TIMER_Init(1,500000);                  /* Configure timer1 to generate 500ms(500000us) delay*/

    TIMER_AttachInterrupt(0,myTimerIsr_0);  /* myTimerIsr_0 will be called by TIMER0_IRQn */
    TIMER_AttachInterrupt(1,myTimerIsr_1);  /* myTimerIsr_1 will be called by TIMER1_IRQn */

    TIMER_Start(0);                         /* Start the Timers */
    TIMER_Start(1);

    while(1)
    {
        //do nothing
    }
}
//================================================================================
// TIMER1_enter_DefaultMode_from_RESET
//================================================================================
extern void TIMER1_enter_DefaultMode_from_RESET(void) {

	// $[TIMER1 initialization]
	TIMER_Init_TypeDef init = TIMER_INIT_DEFAULT;

	init.enable = 0;//初始化完成后不使能
	init.debugRun = 0;
	init.dmaClrAct = 0;
	init.sync = 0;
	init.clkSel = timerClkSelHFPerClk;//HFPERCLK时钟
	init.prescale = timerPrescale2;   //2分频
	init.fallAction = timerInputActionNone;
	init.riseAction = timerInputActionNone;
	init.mode = timerModeUp;
	init.quadModeX4 = 0;
	init.oneShot = 0;

	// [TIMER1 initialization]$

	// $[TIMER1 CC0 init]
	TIMER_InitCC_TypeDef initCC0 = TIMER_INITCC_DEFAULT;

	initCC0.prsInput = false;
	initCC0.edge = timerEdgeBoth;
	initCC0.mode = timerCCModePWM;
	initCC0.eventCtrl = timerEventEveryEdge;
	initCC0.filter = 0;
	initCC0.cofoa = timerOutputActionNone;
	initCC0.cufoa = timerOutputActionNone;
	initCC0.cmoa = timerOutputActionToggle;
	initCC0.coist = 0;
	initCC0.outInvert = 0;
	TIMER_InitCC(TIMER1, 0, &initCC0);
	// [TIMER1 CC0 init]$

	/* Route CC0 to location 0 (PC11) and enable pin */
	TIMER1->ROUTE |= (TIMER_ROUTE_CC0PEN | TIMER_ROUTE_LOCATION_LOC0);

	/* Set Top Value */
	TIMER_TopSet(TIMER0, 8000000/PWM_FREQ); //PWM频率设定,此处8M是HFPERCLK频率,待定

	/* Set compare value starting at 0 - it will be incremented in the interrupt handler */
	TIMER_CompareBufSet(TIMER0, 0, 0);

	/* Enable overflow interrupt */
	TIMER_IntEnable(TIMER0, TIMER_IF_OF);

	/* Enable TIMER0 interrupt vector in NVIC */
	NVIC_EnableIRQ(TIMER0_IRQn);

	TIMER_Init(TIMER1, &init);
}
void fd_led_wake(void) {
    fd_lp55231_power_on();
    fd_lp55231_wake();

    CMU_ClockEnable(cmuClock_TIMER0, true);

    TIMER_InitCC_TypeDef timer_initcc = TIMER_INITCC_DEFAULT;
    timer_initcc.cmoa = timerOutputActionToggle;
    timer_initcc.mode = timerCCModePWM;
    TIMER_InitCC(TIMER0, /* channel */ 1, &timer_initcc);
    TIMER_InitCC(TIMER0, /* channel */ 2, &timer_initcc);

    TIMER0->ROUTE = TIMER_ROUTE_CC1PEN | TIMER_ROUTE_CC2PEN | TIMER_ROUTE_LOCATION_LOC4;

    TIMER_TopSet(TIMER0, TOP);
    TIMER_CompareSet(TIMER0, /* channel */ 1, TOP);
    TIMER_CompareSet(TIMER0, /* channel */ 2, TOP);

    TIMER_Init_TypeDef timer_init = TIMER_INIT_DEFAULT;
    TIMER_Init(TIMER0, &timer_init);

    CMU_ClockEnable(cmuClock_TIMER3, true);

    TIMER_InitCC(TIMER3, /* channel */ 1, &timer_initcc);
    TIMER_InitCC(TIMER3, /* channel */ 2, &timer_initcc);

    TIMER3->ROUTE = TIMER_ROUTE_CC2PEN | TIMER_ROUTE_LOCATION_LOC0;

    TIMER_TopSet(TIMER3, TOP);
    TIMER_CompareSet(TIMER3, /* channel */ 1, TOP);
    TIMER_CompareSet(TIMER3, /* channel */ 2, TOP);

    TIMER_IntEnable(TIMER3, TIMER_IF_CC1 | TIMER_IF_OF);

    NVIC_EnableIRQ(TIMER3_IRQn);

    TIMER_Init(TIMER3, &timer_init);
}
Exemple #20
0
void init_timer(void)
{
	/* Enable clock source for timer0 */
	UNLOCKREG();
	CLK->PWRCTL |= CLK_PWRCTL_HIRC_EN;
	while (!(CLK->CLKSTATUS & CLK_CLKSTATUS_PLL_STB));
	CLK->CLKSEL1 = CLK->CLKSEL1
		& ~CLK_CLKSEL1_TMR0_MASK
		| CLK_CLKSEL1_TMR0_HIRC;
	LOCKREG();
	
	/* Set up timer0 and enable it's interrupt */
	TIMER_Init(TIMER0, 10, 1200000, TIMER_CTL_MODESEL_PERIODIC);
	TIMER_EnableInt(TIMER0, TIMER_IER_TMRIE);
	TIMER_Start(TIMER0);
}	
Exemple #21
0
void enc_init(void)
{
  static const TIMER_Init_TypeDef txTimerInit =
  { false,                  /* Don't enable timer when init complete. */
    false,                  /* Stop counter during debug halt. */
    HIJACK_TIMER_RESOLUTION,/* ... */
    timerClkSelHFPerClk,    /* Select HFPER clock. */
    false,                  /* Not 2x count mode. */
    false,                  /* No ATI. */
    timerInputActionNone,   /* No action on falling input edge. */
    timerInputActionNone,   /* No action on rising input edge. */
    timerModeUp,            /* Up-counting. */
    false,                  /* Do not clear DMA requests when DMA channel is active. */
    false,                  /* Select X2 quadrature decode mode (if used). */
    false,                  /* Disable one shot. */
    false                   /* Not started/stopped/reloaded by other timers. */
  };

  /* Ensure core frequency has been updated */
  SystemCoreClockUpdate();

  /* Enable peripheral clocks. */
  CMU_ClockEnable(cmuClock_HFPER, true);
  CMU_ClockEnable(HIJACK_TX_TIMERCLK, true);

  /* Configure Rx timer. */
  TIMER_Init(HIJACK_TX_TIMER, &txTimerInit);

  /* Configure Tx timer output compare channel 0. */
  HIJACK_CompareConfig(hijackOutputModeToggle);
  TIMER_CompareSet(HIJACK_TX_TIMER, 0, HIJACK_NUM_TICKS_PER_HALF_CYCLE);

  /* Route the capture channels to the correct pins, enable CC feature. */
  HIJACK_TX_TIMER->ROUTE = HIJACK_TX_LOCATION | TIMER_ROUTE_CC0PEN;

  /* Tx: Configure the corresponding GPIO pin as an input. */
  GPIO_PinModeSet(HIJACK_TX_GPIO_PORT, HIJACK_TX_GPIO_PIN, gpioModePushPull, 0);

  /* Enable Tx timer CC0 interrupt. */
  NVIC_EnableIRQ(TIMER1_IRQn);
  TIMER_IntEnable(HIJACK_TX_TIMER, TIMER_IF_CC0);

  /* Enable the timer. */
  TIMER_Enable(HIJACK_TX_TIMER, true);
}
Exemple #22
0
int main (void)
{
  u8 returnValue;
  u32 seed;

  interactive = 1;

  halInit();
  ST_RadioGetRandomNumbers((u16 *)&seed, 2);
  halCommonSeedRandom(seed);
  uartInit(115200, 8, PARITY_NONE, 1);
  INTERRUPTS_ON();  

  /* Initialize radio (analog section, digital baseband and MAC).
  Leave radio powered up in non-promiscuous rx mode */
  returnValue = ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);

  assert(returnValue==ST_SUCCESS); 

  TIMER_Init();

  printf("Bootloader demo application\r\n");
  
  responsePrintf("{&N API call... &t2x}\r\n", "halGetResetInfo", "resetInfo", 0);

  txBufferInit(FALSE);
  rxBufferInit();
  blInit(NULL, transmitByte, receiveByte);

  ST_RadioSetPanId(IAP_BOOTLOADER_PAN_ID);
  ST_RadioSetChannel(IAP_BOOTLOADER_DEFAULT_CHANNEL);

  commandReaderInit();

  while(1) {
    // Process input and print prompt if it returns TRUE.
    if (processCmdInput(interactive)) {
      if (interactive) {
	printf(">");
      }
      TIMER_Tick();
    }
  }
}
Exemple #23
0
/**
 * \brief decode initial.
 */
void dec_init(void)
{
   static const TIMER_Init_TypeDef rxTimerInit =
  { false,                  /* Don't enable timer when init complete. */
    false,                  /* Stop counter during debug halt. */
    HIJACK_TIMER_RESOLUTION,/* ... */
    timerClkSelHFPerClk,    /* Select HFPER clock. */
    false,                  /* Not 2x count mode. */
    false,                  /* No ATI. */
    timerInputActionNone,   /* No action on falling input edge. */
    timerInputActionNone,   /* No action on rising input edge. */
    timerModeUp,            /* Up-counting. */
    false,                  /* Do not clear DMA requests when DMA channel is active. */
    false,                  /* Select X2 quadrature decode mode (if used). */
    false,                  /* Disable one shot. */
    false                   /* Not started/stopped/reloaded by other timers. */
  };
  /* Ensure core frequency has been updated */
  SystemCoreClockUpdate();

  /* Enable RX_TIMER clock . */
  CMU_ClockEnable(HIJACK_RX_TIMERCLK, true);

  /* Configure Rx timer. */
  TIMER_Init(HIJACK_RX_TIMER, &rxTimerInit);

  /* Configure Rx timer input capture channel 0. */
  HIJACK_CaptureConfig(hijackEdgeModeBoth);

  /* Route the capture channels to the correct pins, enable CC1. */
  HIJACK_RX_TIMER->ROUTE = TIMER_ROUTE_LOCATION_LOC3 | TIMER_ROUTE_CC1PEN;

  /* Rx: Configure the corresponding GPIO pin (PortD, Ch2) as an input. */
  GPIO_PinModeSet(HIJACK_RX_GPIO_PORT, HIJACK_RX_GPIO_PIN, gpioModeInput, 0);

  /* Enable Rx timer CC1 interrupt. */
  NVIC_EnableIRQ(TIMER0_IRQn);
  TIMER_IntEnable(HIJACK_RX_TIMER, TIMER_IF_CC1);

  /* Enable the timer. */
  TIMER_Enable(HIJACK_RX_TIMER, true);
}
Exemple #24
0
// Private function prototypes -----------------------------------------------
// Private functions ---------------------------------------------------------
// Exported functions --------------------------------------------------------
uint8_t bsp_tick_timer_init(void)
{
    uint8_t ret = EXIT_SUCCESS;
    uint32_t timer_freq;
    uint32_t timer_top_count;

    TIMER_Reset(TIMER0);

    // Configure a system timer for tracking a tick counter.
    CMU_ClockEnable(cmuClock_TIMER0, true);

    // Set the timer configuration
    s_timer_init.enable     = false;                // Enable timer when init complete.
    s_timer_init.debugRun   = true;                 // Stop counter during debug halt.

    s_timer_init.prescale   = timer_prescale;       // Prescale by 16 (2MHz clock)
    s_timer_init.clkSel     = timerClkSelHFPerClk;  // Select HFPER clock.

    s_timer_init.count2x    = false;                // Not 2x count mode.
    s_timer_init.ati        = false;                // No ATI.

    s_timer_init.fallAction = timerInputActionNone; // No action on falling input edge.
    s_timer_init.riseAction = timerInputActionNone; // No action on rising input edge.

    s_timer_init.mode       = timerModeUp;          // Up-counting.
    s_timer_init.dmaClrAct  = false;                // Do not clear DMA requests when DMA channel is active.
    s_timer_init.quadModeX4 = false;                // Select X2 quadrature decode mode (if used).

    s_timer_init.oneShot    = false;                // Disable one shot.
    s_timer_init.sync       = false;                // Not started/stopped/reloaded by other timers.

    // Configure TIMER
    TIMER_Init(TIMER0, &s_timer_init);

    // Set counter top for tick rate
    timer_freq = CMU_ClockFreqGet(cmuClock_TIMER0) / (1 << timer_prescale);
    timer_top_count = (timer_freq / TIMER_TICK_RATE_HZ) - 1;
    TIMER_TopSet(TIMER0, timer_top_count);

    return ret;
}
Exemple #25
0
static void init_analog_switches(void)
{
  CMU_ClockEnable(cmuClock_GPIO, true);
  CMU_ClockEnable(cmuClock_TIMER1, true);

  port_init(analog_switches, sizeof(analog_switches)/sizeof(port_init_t));

  TIMER_Init(T2_TIMER, & t2_timer_init);
  TIMER_InitCC(T2_TIMER, T2_TIMER_CC, & t2_timer_cc_init);
  T2_TIMER->ROUTE = TIMER_ROUTE_CC1PEN | (T2_TIMER_LOC << _TIMER_ROUTE_LOCATION_SHIFT);
  T2_TIMER->CTRL |= TIMER_CTRL_RSSCOIST;

  uint16_t t1_to_t2_delay = ROUND_F_TO_I(T1_TO_T2_DELAY * CMU_ClockFreqGet(cmuClock_TIMER1));
  uint16_t timer_max_count = ROUND_F_TO_I((T1_TO_T2_DELAY + T2_PULSE_TIME) * CMU_ClockFreqGet(cmuClock_TIMER1));
#if 0
  printf("t1_to_t2_delay:  %" PRIu16 "\r\n", t1_to_t2_delay);
  printf("timer_max_count: %" PRIu16 "\r\n", timer_max_count);
#endif
  TIMER_CompareSet(T2_TIMER, T2_TIMER_CC, t1_to_t2_delay);
  TIMER_TopSet(T2_TIMER, timer_max_count);
}
Exemple #26
0
/*************************************************
* Function: PCT_ReconnectCloud
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_ReconnectCloud(PTC_ProtocolCon *pstruContoller, u32 u32ReConnectTimer)
{
    u32 u32Index;
    if (PCT_TIMER_INVAILD != pstruContoller->u8ReconnectTimer)
    {
        ZC_Printf("already reconnected \n");
        return;
    }
    

    MSG_Init();
    g_struProtocolController.u8keyRecv = PCT_KEY_UNRECVED;
    memcpy(g_struProtocolController.u8SessionKey, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    memcpy(g_struProtocolController.IvSend, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    memcpy(g_struProtocolController.IvRecv, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);

    for (u32Index = 0; u32Index < ZC_TIMER_MAX_NUM; u32Index++)
    {
        
        if (g_struTimer[u32Index].u8Status == ZC_TIMER_STATUS_USED)
        {
            TIMER_StopTimer((u8)u32Index);
        }
    }
    
    TIMER_Init();
    g_struProtocolController.u8ReconnectTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8HeartTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8CloudAckTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8MainState = PCT_STATE_INIT;

    g_struProtocolController.u32CloudNotAckNum = 0;

    pstruContoller->pstruMoudleFun->pfunSetTimer(PCT_TIMER_RECONNECT, 
        u32ReConnectTimer, &pstruContoller->u8ReconnectTimer);
    pstruContoller->struCloudConnection.u32Socket = PCT_INVAILD_SOCKET;
    pstruContoller->u8keyRecv = PCT_KEY_UNRECVED; 
    pstruContoller->u8MainState = PCT_STATE_INIT;
}
Exemple #27
0
/***************************************************************************//**
 * @brief
 *  Start the TIMER1 to generate a 50% duty cycle output.
 *
 * @param[in] frequency
 *  The output frequency in Hz.
 ******************************************************************************/
void TD_TIMER_Start(uint32_t frequency)
{
	uint32_t top;

	top = CMU_ClockFreqGet(cmuClock_TIMER1);
	top = top / frequency;

	// Enable clock for TIMER1 module
	CMU_ClockEnable(cmuClock_TIMER1, true);

	// Configure CC channel 0
	TIMER_InitCC(TIMER1, 0, &timerCCInit);

	// Route CC0 to location 0 (PC13) and enable pin
	//TIMER1->ROUTE |= (TIMER_ROUTE_CC0PEN | TIMER_ROUTE_LOCATION_LOC0);

	// Set Top Value
	TIMER_TopSet(TIMER1, top);

	// Set compare value starting at 0 - it will be incremented in the interrupt handler
	TIMER_CompareBufSet(TIMER1, 0, top >> 1);

	// Configure timer
	TIMER_Init(TIMER1, &timerInit);

	// Enable overflow interrupt
	TIMER_IntEnable(TIMER1, TIMER_IF_OF);

	// Disable interrupts
	//TIMER_IntDisable(TIMER1, TIMER_IF_OF);

	// Enable TIMER1 interrupt vector in NVIC
	NVIC_EnableIRQ(TIMER1_IRQn);

	// Enable timer
	TIMER_Enable(TIMER1, true);
	TD_TIMER_Enabled = true;
}
/*************************************************
* Function: PCT_Sleep
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_Sleep()
{
    u32 u32Index;
    MSG_Init();

    g_struProtocolController.u8keyRecv = PCT_KEY_UNRECVED;
    for (u32Index = 0; u32Index < ZC_TIMER_MAX_NUM; u32Index++)
    {
        if (g_struTimer[u32Index].u8Status == ZC_TIMER_STATUS_USED)
        {
            TIMER_StopTimer((u8)u32Index);
        }
    }

    TIMER_Init();
    g_struProtocolController.u8ReconnectTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8HeartTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8MainState = PCT_STATE_INIT;
    g_struProtocolController.u8RegisterTimer = PCT_TIMER_INVAILD;
    PCT_SendNotifyMsg(ZC_CODE_WIFI_DISCONNECTED);
    //ZC_ClientSleep();
}
Exemple #29
0
void vDos_Init(void)
	{
	hideWinTill = GetTickCount()+2500;												// Auto hidden till first keyboard check, parachute at 2.5 secs

	LOG_MSG("vDos version: %s", vDosVersion);

#ifndef WITHIRQ1
	// Wil have been called earlier in starup if WITHIRQ1 is defined
	vDos_LoadConfig();
#endif

	GUI_StartUp();
	IO_Init();
	PAGING_Init();
	MEM_Init();
	CALLBACK_Init();
	PIC_Init();
	PROGRAMS_Init();
	TIMER_Init();
//	CMOS_Init();
	VGA_Init();
	CPU_Init();
	KEYBOARD_Init();
	BIOS_Init();
	INT10_Init();
	MOUSE_Init();
	SERIAL_Init();
	PARALLEL_Init();
	printTimeout = ConfGetBool("timeout");
	DOS_Init();
	XMS_Init();
	EMS_Init();
	if (errorMess[0])
		MessageBox(NULL, errorMess+1, "vDos: CONFIG.TXT has unresolved items", MB_OK|MB_ICONWARNING);
	SHELL_Init();																	// Start up main machine
	}
Exemple #30
-1
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();

  /* Initialize the LCD */
  SegmentLCD_Init(true);

  /* Enable the DMA and TIMER0 clocks */
  CMU_ClockEnable(cmuClock_DMA, true);
  CMU_ClockEnable(cmuClock_TIMER0, true);

  /* Enable overflow interrupt */
  TIMER_IntEnable(TIMER0, TIMER_IF_OF);

  /* Enable TIMER0 interrupt vector in NVIC */
  NVIC_EnableIRQ(TIMER0_IRQn);

  /* Initialize TIMER0 */
  TIMER_Init_TypeDef timerInit =
  {
    .enable     = true,
    .debugRun   = true,
    .prescale   = timerPrescale64,
    .clkSel     = timerClkSelHFPerClk,
    .fallAction = timerInputActionNone,
    .riseAction = timerInputActionNone,
    .mode       = timerModeUp,
    .dmaClrAct  = false,
    .quadModeX4 = false,
    .oneShot    = false,
    .sync       = false,
  };
  TIMER_Init(TIMER0, &timerInit);

  /* Initialize DMA */
  DMA_Init_TypeDef dmaInit;
  dmaInit.hprot        = 0;
  dmaInit.controlBlock = dmaControlBlock;
  DMA_Init(&dmaInit);

  /* Configure the DMA and perform the transfer */
  performFlashTransfer();

  while (1)
  {
    /* The transfer has finished. We wish to display the result on the LCD
     * but use as little power as possible; go to EM2 (the LCD requires EM2). */
    EMU_EnterEM2(true);
  }
}