コード例 #1
0
ファイル: timer.c プロジェクト: JamesHinnant/osp
/**
 * @brief	main routine for timer example
 * @return	Function should not exit.
 */
int main(void)
{
	uint32_t timerBaseClock;

	SystemCoreClockUpdate();
	Board_Init();
	Board_LED_Set(0, false);
	Board_LED_Set(1, false);

	/* Initialize Timer 0 and Timer 1 */
	Chip_TIMER_Init(LPC_TIMER0);
	Chip_TIMER_Init(LPC_TIMER1);

	/* Setup prescale value on Timer 0 to PCLK */
	Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);
	/* Setup prescale value on Timer 1 for lower resolution */
	Chip_TIMER_PrescaleSet(LPC_TIMER1, PRESCALE_HZ2);

	/* Reset timers */
	Chip_TIMER_Reset(LPC_TIMER0);
	Chip_TIMER_Reset(LPC_TIMER1);

	/* Enable both timers to generate interrupts when time matches */
	Chip_TIMER_MatchEnableInt(LPC_TIMER0, 1);
	Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1);

	/* Get rate of timer base clock */
	timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();

	/* Setup Timer 0 for a match every 1s */
	Chip_TIMER_SetMatch(LPC_TIMER0, 1, (timerBaseClock / TICKRATE_HZ1));

	/* Setup Timer 1 for a match twice in a second */
	Chip_TIMER_SetMatch(LPC_TIMER1, 1, (timerBaseClock / ((PRESCALE_HZ2 + 1) * TICKRATE_HZ2)) );

	/* Setup both timers to restart when match occurs */
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1);

	/* Start both timers */
	Chip_TIMER_Enable(LPC_TIMER0);
	Chip_TIMER_Enable(LPC_TIMER1);

	/* Clear both timers of any pending interrupts */
	NVIC_ClearPendingIRQ(CT32B0_IRQn);
	NVIC_ClearPendingIRQ(CT32B1_IRQn);

	/* Enable both timer interrupts */
	NVIC_EnableIRQ(CT32B0_IRQn);
	NVIC_EnableIRQ(CT32B1_IRQn);

	/* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */
	while (1) {
		__WFI();
	}

	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: Maxim-DE/W5500_EVB
/**
 * @brief	Initialization 32-bit Timer 0
 * @return	Nothing
 */
void Timer32_0_Init(uint32_t tickrate)
{
	uint32_t timerFreq;

	/* Initialize 32-bit timer 0 clock */
	Chip_TIMER_Init(LPC_TIMER32_0);

	/* Timer rate is system clock rate */
	timerFreq = Chip_Clock_GetSystemClockRate();

	/* Timer setup for match and interrupt at TICKRATE_HZ */
	Chip_TIMER_Reset(LPC_TIMER32_0);
	/* Enable timer to generate interrupts when time matches */
	Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 1);
	/* Setup 32-bit timer's duration (32-bit match time) */
	Chip_TIMER_SetMatch(LPC_TIMER32_0, 1, (timerFreq / tickrate));
	/* Setup timer to restart when match occurs */
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 1);
	/* Start timer */
	Chip_TIMER_Enable(LPC_TIMER32_0);

	/* Clear timer of any pending interrupts */
	NVIC_ClearPendingIRQ(TIMER_32_0_IRQn);
	/* Enable timer interrupt */
	NVIC_EnableIRQ(TIMER_32_0_IRQn);
}
コード例 #3
0
void InicTimers(void){

	uint32_t timerFreq;

	//inicializo los timers para la maquina de estado
		Chip_TIMER_Init(LPC_TIMER2);

	//tomo la frecuencia del clok
		timerFreq = Chip_Clock_GetSystemClockRate();


	//confinfiguro el timer 2 y el match 1

		Chip_TIMER_Reset(LPC_TIMER2);
		Chip_TIMER_MatchEnableInt(LPC_TIMER2, 1);
		Chip_TIMER_SetMatch(LPC_TIMER2, 1, 250);
		Chip_TIMER_ResetOnMatchEnable(LPC_TIMER2, 1);

		Chip_TIMER_Enable(LPC_TIMER2);

		//habilito interrupciones

		NVIC_ClearPendingIRQ(TIMER2_IRQn);
		NVIC_EnableIRQ(TIMER2_IRQn);


}
コード例 #4
0
/**
 * @details Initiizes timers for timer based interrupts
 */
void Init_Timers(void) {
	// ------------------------------------------------
	// Timer 32_0 Init
	Chip_TIMER_Init(LPC_TIMER32_0);
	Chip_TIMER_Reset(LPC_TIMER32_0);
	Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 0);
	Chip_TIMER_SetMatch(LPC_TIMER32_0, 0, Hertz2Ticks(10));
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 0);

	// Chip_TIMER_Enable(LPC_TIMER32_0);

	/* Enable timer interrupt */
	NVIC_ClearPendingIRQ(TIMER_32_0_IRQn);
	NVIC_EnableIRQ(TIMER_32_0_IRQn);

	// ------------------------------------------------
	// Timer 32_0 Init
	Chip_TIMER_Init(LPC_TIMER32_1);
	Chip_TIMER_Reset(LPC_TIMER32_1);
	Chip_TIMER_MatchEnableInt(LPC_TIMER32_1, 0);
	Chip_TIMER_SetMatch(LPC_TIMER32_1, 0, Hertz2Ticks(BCM_POLL_IDLE_FREQ));
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_1, 0);

	/* Enable timer_32_1 interrupt */
	NVIC_ClearPendingIRQ(TIMER_32_1_IRQn);
	NVIC_EnableIRQ(TIMER_32_1_IRQn);

	Chip_TIMER_Enable(LPC_TIMER32_1);
}
コード例 #5
0
ファイル: main.c プロジェクト: pridolfi/workspace
static void initHardware(void)
{
    SystemCoreClockUpdate();
    SysTick_Config(SystemCoreClock/1000);
    Board_Init();
    Board_LED_Set(0, false);

    /* Timer */
    Chip_TIMER_Init(LPC_TIMER1);
    Chip_TIMER_PrescaleSet(LPC_TIMER1,
#ifdef lpc1769
                           Chip_Clock_GetPeripheralClockRate(SYSCTL_PCLK_TIMER1) / 1000000 - 1
#else
                           Chip_Clock_GetRate(CLK_MX_TIMER1) / 1000000 - 1
#endif
                          );

    /* Match 0 (period) */
    Chip_TIMER_MatchEnableInt(LPC_TIMER1, 0);
    Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 0);
    Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 0);
    Chip_TIMER_SetMatch(LPC_TIMER1, 0, 1000);

    /* Match 1 (duty) */
    Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1);
    Chip_TIMER_ResetOnMatchDisable(LPC_TIMER1, 1);
    Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 1);
    Chip_TIMER_SetMatch(LPC_TIMER1, 1, 100);

    Chip_TIMER_Reset(LPC_TIMER1);
    Chip_TIMER_Enable(LPC_TIMER1);

    NVIC_EnableIRQ(TIMER1_IRQn);
}
コード例 #6
0
void AVALON_PWM_Init(void)
{
	/* System CLK 48MHz */
	Chip_TIMER_Init(LPC_TIMER16_0);
	Chip_TIMER_Disable(LPC_TIMER16_0);

	/* CT16B0_MAT0/CT16B0_MAT1/CT16B0_MAT2 Init */
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, IOCON_FUNC2 | IOCON_MODE_INACT);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, IOCON_FUNC2 | IOCON_MODE_INACT);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 15, IOCON_FUNC2 | IOCON_MODE_INACT);

	/* CT16B0_MAT0 duty:50% */
	Chip_TIMER_ExtMatchControlSet(LPC_TIMER16_0, 1, TIMER_EXTMATCH_TOGGLE, 0);
	Chip_TIMER_SetMatch(LPC_TIMER16_0, 0, DUTY_50);

	/* CT16B0_MAT1 duty:25% */
	Chip_TIMER_ExtMatchControlSet(LPC_TIMER16_0, 1, TIMER_EXTMATCH_TOGGLE, 1);
	Chip_TIMER_SetMatch(LPC_TIMER16_0, 1, DUTY_25);

	/* CT16B0_MAT2 duty:10% */
	Chip_TIMER_ExtMatchControlSet(LPC_TIMER16_0, 1, TIMER_EXTMATCH_TOGGLE, 2);
	Chip_TIMER_SetMatch(LPC_TIMER16_0, 2, DUTY_10);

	/* Prescale 0 */
	Chip_TIMER_PrescaleSet(LPC_TIMER16_0, 0);

	/* PWM Period 800Hz */
	Chip_TIMER_SetMatch(LPC_TIMER16_0, 3, DUTY_100);
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 3);

	/* CT16B0_MAT0/CT16B0_MAT1/CT16B0_MAT2 Enable */
	LPC_TIMER16_0->PWMC = 0x7;//pwm

	Chip_TIMER_Enable(LPC_TIMER16_0);
}
コード例 #7
0
ファイル: sapi_timer.c プロジェクト: jlnbotello/plantilla
/*
 * @Brief   Initialize Timer peripheral
 * @param   timerNumber:   Timer number, 0 to 3
 * @param   ticks:   Number of ticks required to finish the cycle.
 * @param   voidFunctionPointer:   function to be executed at the end of the timer cycle
 * @return   nothing
 * @note   For the 'ticks' parameter, see function Timer_microsecondsToTicks
 */
void Timer_Init( uint8_t timerNumber, uint32_t ticks,
                 voidFunctionPointer_t voidFunctionPointer){
   /* Source:
   http://docs.lpcware.com/lpcopen/v1.03/lpc18xx__43xx_2examples_2periph_2periph__blinky_2blinky_8c_source.html */

   /*If timer period = CompareMatch0 Period = 0 => ERROR*/
   if (ticks==0){
      errorOcurred();
   }

   /* Enable timer clock and reset it */
   Chip_TIMER_Init(timer_sd[timerNumber].name);
   Chip_RGU_TriggerReset(timer_sd[timerNumber].RGU);
   while (Chip_RGU_InReset(timer_sd[timerNumber].RGU)) {}
   Chip_TIMER_Reset(timer_sd[timerNumber].name);

   /* Update the defalut function pointer name of the Compare match 0*/
   timer_dd[timerNumber].timerCompareMatchFunctionPointer[TIMERCOMPAREMATCH0] = voidFunctionPointer;

   /* Initialize compare match with the specified ticks (number of counts needed to clear the match counter) */
   Chip_TIMER_MatchEnableInt(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0);
   Chip_TIMER_SetMatch(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0, ticks);

   /* Makes Timer Match 0 period the timer period*/
   Chip_TIMER_ResetOnMatchEnable(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0);

   /*Enable timer*/
   Chip_TIMER_Enable(timer_sd[timerNumber].name);

   /* Enable timer interrupt */
   NVIC_SetPriority(timer_sd[timerNumber].IRQn, MAX_SYSCALL_INTERRUPT_PRIORITY+1);
   NVIC_EnableIRQ(timer_sd[timerNumber].IRQn);
   NVIC_ClearPendingIRQ(timer_sd[timerNumber].IRQn);
}
コード例 #8
0
ファイル: timer.c プロジェクト: MFDM/SE2-SV1314
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void)
{
	uint32_t timerFreq;

	/* Generic Initialization */
	SystemCoreClockUpdate();
	Board_Init();

	/* Enable timer 1 clock */
	Chip_TIMER_Init(LPC_TIMER0);

	/* Timer rate is system clock rate */
	timerFreq = Chip_Clock_GetSystemClockRate();

	/* Timer setup for match and interrupt at TICKRATE_HZ */
	Chip_TIMER_Reset(LPC_TIMER0);
	Chip_TIMER_MatchEnableInt(LPC_TIMER0, 1);
	Chip_TIMER_SetMatch(LPC_TIMER0, 1, (timerFreq / TICKRATE_HZ1));
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
	Chip_TIMER_Enable(LPC_TIMER0);

	/* Enable timer interrupt */
	NVIC_ClearPendingIRQ(TIMER0_IRQn);
	NVIC_EnableIRQ(TIMER0_IRQn);

	/* LEDs toggle in interrupt handlers */
	while (1) {
		__WFI();
	}

	return 0;
}
コード例 #9
0
	void init_runtime_stats_timer( void )
	{
		Chip_TIMER_Init(LPC_TIMER3);
		Chip_TIMER_Reset(LPC_TIMER3);
		Chip_Clock_SetPCLKDiv(SYSCTL_PCLK_TIMER3, SYSCTL_CLKDIV_1);
		Chip_TIMER_PrescaleSet(LPC_TIMER3, 3200);
		Chip_TIMER_Enable(LPC_TIMER3);
	}
コード例 #10
0
ファイル: pwm.c プロジェクト: gary9555/pushbot
uint32_t PWMSetPeriod(uint8_t channel, uint32_t period) {
	if (channel > CHANNEL_C_TIMER_INDEX) {
		return 1;
	}
	if (eDVSMode != EDVS_MODE_INTERNAL && channel == 0) {
		return 1; // channel 0 taken for master/slave mode
	}
	LPC_TIMER_T * timer = halTimers[channel].timer;
	halTimers[channel].period = period;
	/**
	 * If the period equal 0, the timer is disable and its outputs are set as GPIO and driven low.
	 */
	if (period == 0) {
		Chip_TIMER_DeInit(timer); //Stop the timer
		Chip_TIMER_SetMatch(timer, 2, 0);
		halTimers[channel].enabled[0] = DISABLE;
		halTimers[channel].enabled[1] = DISABLE;
		Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]);
		Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]);
		Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]);
		Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]);
		Chip_SCU_PinMuxSet(halTimers[channel].port[0], halTimers[channel].pin[0], halTimers[channel].gpioMode[0]);
		Chip_SCU_PinMuxSet(halTimers[channel].port[1], halTimers[channel].pin[1], halTimers[channel].gpioMode[1]);
	} else {
		/**
		 * The channel match 2 is used as the controller of the base frequency.
		 * When there is a match on this channel, the timer is reset and the external match bit
		 * is set to 1.
		 * The M0 core is looking for this change and it sets the output of the channels to high.
		 */
		Chip_TIMER_Init(timer);
		Chip_TIMER_Disable(timer);
		Chip_TIMER_Reset(timer);
		/**
		 * The Main clock is running at 192Mhz so set the Prescaler in order to have
		 * a 1 Mhz timer. Timer_CLK = Main_CLK/ (PR+1)
		 */
		Chip_TIMER_PrescaleSet(timer, 191);
		Chip_TIMER_ResetOnMatchEnable(timer, 2);
		Chip_TIMER_StopOnMatchDisable(timer, 2);
		Chip_TIMER_MatchDisableInt(timer, 2);
		Chip_TIMER_SetMatch(timer, 2, period);
		//Reconfigure match channels!
		if (halTimers[channel].enabled[0]) {
			PWMSetWidth(channel, 0, halTimers[channel].witdh[0]);
		}
		if (halTimers[channel].enabled[1]) {
			PWMSetWidth(channel, 1, halTimers[channel].witdh[1]);
		}
		Chip_TIMER_ExtMatchControlSet(timer, 0, TIMER_EXTMATCH_SET, 2);
		// Clear interrupt pending
		timer->IR = 0xFFFFFFFF;
		Chip_TIMER_Enable(timer);
	}
	return 0;
}
	void initialize_timer() {
		Chip_TIMER_Init(LPC_TIMER1);
		Chip_TIMER_Reset(LPC_TIMER1);
		Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1);
		Chip_TIMER_SetMatch(LPC_TIMER1, 1, 240000);//1200000
		Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1);
		Chip_TIMER_Enable(LPC_TIMER1);
		NVIC_ClearPendingIRQ(TIMER1_IRQn);
		NVIC_EnableIRQ(TIMER1_IRQn);
	}
コード例 #12
0
void Mb1240::init_capture_timer() {
	Chip_TIMER_Init(this->timer);
	Chip_TIMER_Reset(this->timer);

	Chip_TIMER_CaptureRisingEdgeEnable(this->timer, this->timer_cap_ch);
	Chip_TIMER_CaptureEnableInt(this->timer, this->timer_cap_ch);

	Chip_TIMER_Enable(this->timer);
	NVIC_ClearPendingIRQ(get_timer_nvic_irq(this->timer));
	NVIC_EnableIRQ(get_timer_nvic_irq(this->timer));
}
コード例 #13
0
ファイル: stopwatch_540xx.c プロジェクト: 70year/MICO
/* Initialize stopwatch */
void StopWatch_Init(void)
{
	/* Use timer 1. Set prescaler to divide by 8 */
	const uint32_t prescaleDivisor = 8;
	Chip_TIMER_Init(LPC_TIMER32_1);
	Chip_TIMER_PrescaleSet(LPC_TIMER32_1, prescaleDivisor - 1);
	Chip_TIMER_Enable(LPC_TIMER32_1);

	/* Pre-compute tick rate. */
	ticksPerSecond = Chip_Clock_GetAsyncSysconClockRate() / prescaleDivisor;
	ticksPerMs = ticksPerSecond / 1000;
	ticksPerUs = ticksPerSecond / 1000000;
}
コード例 #14
0
void AVALON_PWM_Test(void)
{
	static Bool bPwmInit = FALSE;

	if(!bPwmInit)
	{
		bPwmInit = TRUE;
		AVALON_PWM_Init();
	}
	Chip_TIMER_Enable(LPC_TIMER16_0);
	AVALON_Delay(9000000);
	Chip_TIMER_Disable(LPC_TIMER16_0);
}
コード例 #15
0
ファイル: system_time.cpp プロジェクト: Xenon-Photon/arm-1
void setup() {
  const uint32 system_clock_hz = Chip_Clock_GetSystemClockRate();
  const uint32 prescale = system_clock_hz / 1000000;

  Chip_TIMER_Init(SYS_CLOCK_TIMER32);

    // Set prescaler for 1 usec/count.
  Chip_TIMER_PrescaleSet(SYS_CLOCK_TIMER32, prescale - 1);
  // Reset count
  Chip_TIMER_Reset(SYS_CLOCK_TIMER32);
  // Start counting.
  Chip_TIMER_Enable(SYS_CLOCK_TIMER32);
}
コード例 #16
0
void AVALON_PWM_Enable(void)
{
	/* Prescale 0 */
	Chip_TIMER_PrescaleSet(LPC_TIMER16_0, 0);

	/* PWM Period 800Hz */
	Chip_TIMER_SetMatch(LPC_TIMER16_0, 3, DUTY_100);
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 3);

	/* CT16B0_MAT0/CT16B0_MAT1/CT16B0_MAT2 Enable */
	LPC_TIMER16_0->PWMC = 0x7;

	Chip_TIMER_Enable(LPC_TIMER16_0);
}
/* Initialize stopwatch */
void StopWatch_Init(void)
{
	/* Use timer 1. Set prescaler to divide by 8, should give ticks at 3.75 MHz.
	   That gives a useable stopwatch measurement range of about 19 minutes
	   (if system clock is running at 120 MHz). */
	const uint32_t prescaleDivisor = 8;
	Chip_TIMER_Init(LPC_TIMER1);
	Chip_TIMER_PrescaleSet(LPC_TIMER1, prescaleDivisor - 1);
	Chip_TIMER_Enable(LPC_TIMER1);

	/* Pre-compute tick rate. Note that peripheral clock supplied to the
	   timer includes a fixed divide by 4. */
	ticksPerSecond = Chip_Clock_GetSystemClockRate() / prescaleDivisor / 4;
	ticksPerMs = ticksPerSecond / 1000;
	ticksPerUs = ticksPerSecond / 1000000;
}
コード例 #18
0
ファイル: timer.c プロジェクト: drobe011/periftest_LPC1769
void setupTimer(void)
{
	Chip_IOCON_PinMux(LPC_IOCON, 1, 28, 2, 3);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO, 1, 28);

	Chip_TIMER_Init(LPC_TIMER0);
	Chip_TIMER_Reset(LPC_TIMER0);
	Chip_TIMER_PrescaleSet(LPC_TIMER0, 500);
	Chip_TIMER_SetMatch(LPC_TIMER0, 0, 16000);
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 0);
	//	Chip_TIMER_MatchEnableInt(LPC_TIMER0, 0);
	Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, RESET, TIMER_EXTMATCH_TOGGLE, 0);
	Chip_TIMER_Enable(LPC_TIMER0);
	//	NVIC_ClearPendingIRQ(TIMER0_IRQn);
	//	NVIC_EnableIRQ(TIMER0_IRQn);
}
コード例 #19
0
void vConfigureTimerForRunTimeStats( void )
{
	uint32_t timerFreq;

	/* Enable timer 1 clock and reset it */
	Chip_TIMER_Init(LPC_TIMER1);
	Chip_RGU_TriggerReset(RGU_TIMER1_RST);
	while (Chip_RGU_InReset(RGU_TIMER1_RST)) {}

	/* Get timer 1 peripheral clock rate */
	timerFreq = Chip_Clock_GetRate(CLK_MX_TIMER1);

	/* Timer setup for match and interrupt at TICKRATE_HZ */
	Chip_TIMER_Reset(LPC_TIMER1);
	Chip_TIMER_SetMatch(LPC_TIMER1, 1, (timerFreq / TICKRATE_HZ));
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1);
	Chip_TIMER_Enable(LPC_TIMER1);
}
コード例 #20
0
ファイル: call.c プロジェクト: p0llux/ham-relay
void
call_init (void)
{
  transmit_call = false;

  Chip_TIMER_Init (LPC_TIMER32_0);
  Chip_TIMER_Reset (LPC_TIMER32_0);
  Chip_TIMER_MatchEnableInt (LPC_TIMER32_0, 0);

  Chip_TIMER_PrescaleSet (LPC_TIMER32_0, Chip_Clock_GetSystemClockRate ());

  Chip_TIMER_SetMatch (LPC_TIMER32_0, 0, CALL_INTERVAL_SEC);
  Chip_TIMER_ResetOnMatchEnable (LPC_TIMER32_0, 0);
  Chip_TIMER_Enable (LPC_TIMER32_0);

  NVIC_ClearPendingIRQ (TIMER_32_0_IRQn);
  NVIC_EnableIRQ (TIMER_32_0_IRQn);
}
コード例 #21
0
ファイル: board.c プロジェクト: ernesto-g/micropython
void Board_TIMER_EnableTimerAsTimer(uint8_t timerNum, uint32_t presc,uint32_t matchValue,bool flagOnce)
{
	// always using match0
	int8_t match=0;
	LPC_TIMER_T* t = getTimerFomIndex(timerNum);

        Chip_TIMER_PrescaleSet(t, presc);
        Chip_TIMER_SetMatch(t, match, matchValue);
        Chip_TIMER_MatchEnableInt(t, match); // enable int for match 0
        if(flagOnce==1)
        { 
			Board_TIMER_DisableTimer(timerNum);
			Board_TIMER_SetTimerCounter(timerNum,0);
			Chip_TIMER_ResetOnMatchDisable(t, match); // reset count on match0
		}
		else 
		{
			Chip_TIMER_ResetOnMatchEnable(t, match); // reset count on match0
		}
	Chip_TIMER_Enable(t);
}
コード例 #22
0
ファイル: windspeed.c プロジェクト: i7sid/SkyNet-Dongle
/*
 * Wind Speed translation : V = p*(2,25/t)
 * V: speed in mph
 * p: pulses per sampelperiod
 * t: sample period in sec
 */
void setupirq(){
	DBG("Initialize Wind Cups...\n");

	Chip_GPIOINT_Init(LPC_GPIOINT);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO,2,13);
	Chip_GPIO_SetPinState(LPC_GPIO, 2, 13, true);

	Chip_IOCON_PinMux(LPC_IOCON, 2, 13, IOCON_MODE_PULLUP, IOCON_FUNC0);

	const uint32_t prescaleDivisor = 8;
	Chip_TIMER_Init(LPC_TIMER2);
	Chip_TIMER_PrescaleSet(LPC_TIMER2, prescaleDivisor - 1);
	Chip_TIMER_Enable(LPC_TIMER2);
	ticksPerSecond = Chip_Clock_GetSystemClockRate() / prescaleDivisor / 4;

	Chip_GPIOINT_SetIntFalling(LPC_GPIOINT, GPIOINT_PORT2, (1 << 13));
	Chip_GPIOINT_ClearIntStatus(LPC_GPIOINT, GPIOINT_PORT2, (1 << 13));

	NVIC_ClearPendingIRQ(EINT3_IRQn);
	NVIC_EnableIRQ(EINT3_IRQn);
	DBG("Initialize Wind Cups complete...\n");


}
コード例 #23
0
ファイル: blink.c プロジェクト: p0llux/ham-relay
void
main (void)
{
  SystemInit ();

  Chip_IOCON_PinMuxSet (LPC_IOCON, LED_STATUS_PIO, IOCON_MODE_INACT | IOCON_FUNC0);
  Chip_GPIO_SetPinDIROutput (LPC_GPIO, LED_STATUS_PORT, LED_STATUS_PIN);
  Chip_GPIO_SetPinState (LPC_GPIO, LED_STATUS_PORT, LED_STATUS_PIN, false);

  Chip_TIMER_Init (LPC_TIMER32_0);
  Chip_TIMER_Reset (LPC_TIMER32_0);
  Chip_TIMER_MatchEnableInt (LPC_TIMER32_0, 1);
  Chip_TIMER_SetMatch (LPC_TIMER32_0, 1, (Chip_Clock_GetSystemClockRate () / (1 * 32)));
  Chip_TIMER_ResetOnMatchEnable (LPC_TIMER32_0, 1);
  Chip_TIMER_Enable (LPC_TIMER32_0);

  /* Enable timer interrupt */
  NVIC_ClearPendingIRQ (TIMER_32_0_IRQn);
  NVIC_EnableIRQ (TIMER_32_0_IRQn);

  while (1) {
    __WFI ();
  }
}
コード例 #24
0
/**
 * @details Where all the magic happens
 * @return Shouldn't return
 */
int main(void) {

	Init_Core();
	Init_SM();
	Init_Board();
	Init_Globals();
	Init_CAN();
	Init_Timers();

	// ------------------------------------------------
	// Begin

	DEBUG_Print("Started Up\r\n");

	while(1) {

		uint8_t count;
		if ((count = Chip_UART_Read(LPC_USART, Rx_Buf, UART_RX_BUF_SIZE)) != 0) {
			switch (Rx_Buf[0]) {
				case 'a': // Print out Brusa Mains Info
					DEBUG_Print("Actual Mains Voltage: ");
					itoa(brusa_actual_1.mains_mVolts, str, 10);
					DEBUG_Print(str);
					DEBUG_Print("\r\n");

					DEBUG_Print("Mains type: ");
					itoa(brusa_actual_1.mains_cAmps, str, 10);
					DEBUG_Print(str);
					DEBUG_Print("\r\n");

					DEBUG_Print("Temp: ");
					itoa((brusa_temp.power_temp / 10) - 40 , str, 10);
					DEBUG_Print(str);
					DEBUG_Print("\r\n");

					DEBUG_Print("Temp: 0x");
					itoa(brusa_temp.power_temp , str, 16);
					DEBUG_Print(str);
					DEBUG_Print("\r\n");
					break;
				case 'b': // Print out Actual Brusa Output
					DEBUG_Print("Actual Out Voltage: ");
					itoa(brusa_actual_1.output_mVolts, str, 10);
					DEBUG_Println(str);

					DEBUG_Print("Actual Out Current: ");
					itoa(brusa_actual_1.output_cAmps, str, 10);
					DEBUG_Println(str);
					break;
				case 'f': // Print out Pack State
					itoa(pack_state.pack_min_mVolts, str, 10);
					DEBUG_Print("Pack Min Voltage: ");
					DEBUG_Print(str);
					DEBUG_Print("\r\n");
					itoa(pack_state.pack_max_mVolts, str, 10);
					DEBUG_Print("Pack Max Voltage: ");
					DEBUG_Print(str);
					DEBUG_Print("\r\n");

					break;
				case 'y': // Print out Module Balance State
					itoa(PackManager_GetExtModId(0), str, 16);
					DEBUG_Print("Mod 0x");
					DEBUG_Print(str);
					itoa(PackManager_GetExtBal(0), str, 2);
					DEBUG_Print(": 0b");
					DEBUG_Println(str);
					itoa(PackManager_GetExtModId(1), str, 16);
					DEBUG_Print("Mod 0x");
					DEBUG_Print(str);
					itoa(PackManager_GetExtBal(1), str, 2);
					DEBUG_Print(": 0b");
					DEBUG_Println(str);
					break;
				case 'e': 
					itoa(brusa_error,str, 2);
					DEBUG_Println(str);
					break;
				case 'm': // Print out charge mode and brusa error
					DEBUG_Print("Charge Mode: ");
					itoa(Charge_GetMode(), str, 10);
					DEBUG_Println(str);
					DEBUG_Print("Error Messages: ");
					itoa((uint64_t)brusa_error, str, 2);
					DEBUG_Println(str);
					break;
				default:
					DEBUG_Print("Unknown Command\r\n");
			}
		}

		//-----------------------------
		// Detect Input Changes (Default to IDLE)

		MODE_INPUT_T inp = INP_IDLE;
		if (!Board_Switch_Read()) {
			inp = INP_CHRG;
		} else {
			inp = INP_IDLE;
		}

		//-----------------------------
		// Update pack_state
		pack_state.contactors_closed = Board_Contactors_Closed();
		pack_state.msTicks = msTicks;
		pack_state.brusa_error = brusa_error;
		pack_state.pack_cAmps_in = brusa_actual_1.output_cAmps;

		//-----------------------------
		// SSM Step
		ERROR_T result = SSM_Step(&pack_state, inp, &out_state);
		if (result != ERROR_NONE) {
			_error(result, true, false);
		}

		//-----------------------------
		// Check if SSM has Changed State
		// Currently only changes Poll Frequency
		// [TODO] Set a status LED!!
		if (SSM_GetMode() != mode) {
			mode = SSM_GetMode();
			switch (SSM_GetMode()) {
				case IDLE:
					Chip_TIMER_SetMatch(LPC_TIMER32_1, 0, Hertz2Ticks(BCM_POLL_IDLE_FREQ));
					Chip_TIMER_Reset(LPC_TIMER32_1); // Otherwise shit gets F****D
					break;
				case CHARGING:
					Chip_TIMER_SetMatch(LPC_TIMER32_1, 0, Hertz2Ticks(BCM_POLL_CHARGING_FREQ));
					Chip_TIMER_Reset(LPC_TIMER32_1);
					break;
				case DRAINING:
					Chip_TIMER_SetMatch(LPC_TIMER32_1, 0, Hertz2Ticks(BCM_POLL_DRAINING_FREQ));
					Chip_TIMER_Reset(LPC_TIMER32_1);
					break;
			}
		}

		//-----------------------------
		// Carry out out_state
		if (out_state.close_contactors && !Board_Contactors_Closed()) {
			Board_Close_Contactors(true);
		} else if (!out_state.close_contactors && Board_Contactors_Closed()) {
			Board_Close_Contactors(false);
		}

		if (out_state.brusa_output) {
			brusa_control.clear_error = out_state.brusa_clear_latch;
			brusa_control.output_mVolts = out_state.brusa_mVolts;
			brusa_control.output_cAmps = out_state.brusa_cAmps;
			Chip_TIMER_Enable(LPC_TIMER32_0);
		} else {
			brusa_control.output_mVolts = 0;
			brusa_control.output_cAmps = 0;
			Chip_TIMER_Disable(LPC_TIMER32_0);
		}

		//-----------------------------
		// Retrieve available brusa messages
		int8_t tmp = MCP2515_GetFullReceiveBuffer();
		int8_t res = 0;
		if (tmp == 2) {
			MCP2515_ReadBuffer(&mcp_msg_obj, 0);
			res = Brusa_Decode(&brusa_messages, &mcp_msg_obj);
			if (res == -1) {
				DEBUG_Println("Brusa Decode Error");
				res = 0;
			}
			MCP2515_ReadBuffer(&mcp_msg_obj, 1);
			res = Brusa_Decode(&brusa_messages, &mcp_msg_obj);
		} else if (tmp == 0) { // Receive Buffer 0 Full
			MCP2515_ReadBuffer(&mcp_msg_obj, tmp);
			res = Brusa_Decode(&brusa_messages, &mcp_msg_obj);
		} else if (tmp == 1) { //Receive buffer 1 full
			MCP2515_ReadBuffer(&mcp_msg_obj, tmp);
			res = Brusa_Decode(&brusa_messages, &mcp_msg_obj);
		} 

		if (res == -1) {
			DEBUG_Println("Brusa Decode Error");
			res = 0;
		}

		//-----------------------------
		// Send brusa message if its time
		if (brusa_message_send) {
			brusa_message_send = false;
			Brusa_MakeCTL(&brusa_control, &mcp_msg_obj);
			MCP2515_LoadBuffer(0, &mcp_msg_obj);
			MCP2515_SendBuffer(0);
		}
		
		//-----------------------------
		// Check for and decode A123 Messages
		if (!RingBuffer_IsEmpty(&rx_buffer)) {

			CCAN_MSG_OBJ_T temp_msg;
			RingBuffer_Pop(&rx_buffer, &temp_msg);
			res = PackManager_Update(&temp_msg);

			if (new_std_msg_sent) {
				PackManager_Commit(&pack_state);
				new_std_msg_sent = false;
			}
			
		}

		if (res == -1) {
			DEBUG_Println("A123 Decode Error");
		}

		//-----------------------------
		// Timed output
		if (msTicks - last_debug_message > TIMED_MESSAGE_DELAY) {
			message_count++;
			last_debug_message = msTicks;
			switch (message_count % 7) {
				case 0:
					if (out_state.balance) {
						itoa(mbb_cmd.balance_target_mVolts, str, 10);
						DEBUG_Print("Balancing to: ");
						DEBUG_Println(str);
					} else {
						DEBUG_Println("Not balancing");
					}
					
					break;
				case 1:
					itoa(brusa_control.output_mVolts, str, 10);
					DEBUG_Print("Brusa out V: ");
					DEBUG_Println(str);
					break;
				case 2:
					itoa(brusa_control.output_cAmps, str, 10);
					DEBUG_Print("Brusa out C: ");
					DEBUG_Println(str);
					break;
				case 3:
					DEBUG_Print("Actual Out Voltage: ");
					itoa(brusa_actual_1.output_mVolts, str, 10);
					DEBUG_Println(str);
					break;
				case 4:
					DEBUG_Print("Actual Out Current: ");
					itoa(brusa_actual_1.output_cAmps, str, 10);
					DEBUG_Println(str);
					break;
				case 5:
					DEBUG_Print("Mode: ");
					DEBUG_Println((SSM_GetMode() == CHARGING) ? "Chrg":"Idle");
					break;
				case 6:
					DEBUG_Print("Brusa Output: ");
					itoa(out_state.brusa_output, str, 2);
					DEBUG_Println(str);

					DEBUG_Print("\r\n");
					break;

			}
		}
	}

	return 0;
}
コード例 #25
0
ファイル: main.c プロジェクト: nopodige/bike_tire_video
/* Function to do the read/write to USB Disk */
static void throughputTest(void)
{
	FRESULT rc;		/* Result code */
	UINT br;



	f_mount(0, &fatFS);		/* Register volume work area (never fails) */

	rc = f_open(&fileObj, "test.bin", FA_READ);
	if (rc) {
		DEBUGOUT("Unable to open big_file.bin from USB Disk\r\n");
		die(rc);
	}

	int frameReads;
	uint32_t readTimes[MAX_FRAME_READS];

	Chip_TIMER_Enable(RUNTIME_TIMER);

	for(frameReads = 0; frameReads < MAX_FRAME_READS; ++frameReads)
	{
		RUNTIME_TIMER->TC = 0;
		/* Read a chunk of file */
		rc = f_read(&fileObj, frameBuffer, FRAME_SIZE, &br);
		if(rc != FR_OK)
		{
			DEBUGOUT("Error reading from file\r\n");
			die(rc);
		}
		else if(br != FRAME_SIZE)
		{
			break;
		}
		readTimes[frameReads] = RUNTIME_TIMER->TC;
		Board_UARTPutChar('.');
	}

	f_close(&fileObj);

	uint64_t sum = 0;
	uint32_t min = UINT32_MAX;
	uint32_t max = 0;
	float ave;

	for(int i = 0; i < frameReads; ++i)
	{
		sum += readTimes[i];
		if(readTimes[i] < min)
			min = readTimes[i];
		if(readTimes[i] > max)
			max = readTimes[i];
	}
	ave = (float)sum / (float)frameReads;

	printf("\n----------------------------\n");
	printf("Test Results\n");
	printf("----------------------------\n");
	printf("\tFrames read: %d\n", frameReads);
	printf("\tFrame size: %.3fkB\n", (float)FRAME_SIZE / 1000.0);
	printf("\tMin time: %.3fus\n", (float)min * PCLK_US);
	printf("\tMax time: %.3fus\n", (float)max * PCLK_US);
	printf("\tAve time: %.3fus\n", (float)ave * PCLK_US);
	printf("\n----------------------------\n");
	printf("All times\n");
	printf("----------------------------\n");
	for(int i = 0; i < frameReads; ++i)
	{
		printf("\t%02d: %.3fus\n", i,  (float)readTimes[i] * PCLK_US);
	}
	printf("----------------------------\n\n");

	DEBUGOUT("\r\nTest completed.\r\n");
	USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0);
}