Ejemplo n.º 1
0
/**
\brief Schedule the callback to be called in some specified time.

The delay is expressed relative to the last compare event. It doesn't matter
how long it took to call this function after the last compare, the timer will
expire precisely delayTicks after the last one.

The only possible problem is that it took so long to call this function that
the delay specified is shorter than the time already elapsed since the last
compare. In that case, this function triggers the interrupt to fire right away.

This means that the interrupt may fire a bit off, but this inaccuracy does not
propagate to subsequent timers.

\param delayTicks Number of ticks before the timer expired, relative to the
                  last compare event.
*/
void bsp_timer_scheduleIn(PORT_TIMER_WIDTH delayTicks) {
   PORT_TIMER_WIDTH newCompareValue;
   PORT_TIMER_WIDTH temp_last_compare_value;
   PORT_TIMER_WIDTH current_value;

   temp_last_compare_value = bsp_timer_vars.last_compare_value;

   newCompareValue      =  bsp_timer_vars.last_compare_value+delayTicks;
   bsp_timer_vars.last_compare_value   =  newCompareValue;

   current_value=timer_get_current_value(TIMER_NUM2);
   if (delayTicks<current_value-temp_last_compare_value) {
      // we're already too late, schedule the ISR right now manually

      // setting the interrupt flag triggers an interrupt
      // TODO .. check that this works correctly.

	   timer_set_compare(TIMER_NUM2,TIMER_COMPARE_REG0,delayTicks+current_value);
	   timer_enable(TIMER_NUM2); //in case not enabled
	   //
   } else {
      // this is the normal case, have timer expire at newCompareValue
	  timer_set_compare(TIMER_NUM2,TIMER_COMPARE_REG0,newCompareValue);
	  timer_enable(TIMER_NUM2); //in case not enabled
   }
}
Ejemplo n.º 2
0
void busy_wait(unsigned int ds)
{
    timer_enable(0);
    timer_set_reload(0);
    timer_set_counter(get_system_frequency()/10*ds);
    timer_enable(1);
    while(timer_get());
}
Ejemplo n.º 3
0
void us_ticker_init(void) {
    if (us_ticker_inited) {
        return;
    }
    us_ticker_inited = 1;
	timer_enable(US_TICKER_TIMER);
	timer_start(US_TICKER_TIMER, 10000, FALSE);	
	timer_enable(US_COUNTER_TIMER);
	timer_start(US_COUNTER_TIMER, 1000, TRUE);	
	NVIC_EnableIRQ(TIMER1_IRQn);
	NVIC_EnableIRQ(TIMER2_IRQn);
}
Ejemplo n.º 4
0
/* TimerHandler from fm.c */
static void TimerHandler(int n,int c,int count,double stepTime)
{
	if( count == 0 )
	{	/* Reset FM Timer */
	 	timer_enable (Timer[n][c], 0);
	}
	else
	{	/* Start FM Timer */
		double timeSec = (double)count * stepTime;
		if (!timer_enable(Timer[n][c], 1))
		 	timer_adjust (Timer[n][c], timeSec, (c<<7)|n, 0);
	}
}
Ejemplo n.º 5
0
static void timer_handler(void *param,int c,int count,int clock)
{
	struct ym2203_info *info = param;
	if( count == 0 )
	{	/* Reset FM Timer */
		timer_enable(info->timer[c], 0);
	}
	else
	{	/* Start FM Timer */
		attotime period = attotime_mul(ATTOTIME_IN_HZ(clock), count);
		if (!timer_enable(info->timer[c], 1))
			timer_adjust_oneshot(info->timer[c], period, 0);
	}
}
Ejemplo n.º 6
0
/* TimerHandler from fm.c */
static void TimerHandler(void *param,int c,int count,double stepTime)
{
	struct ym2610_info *info = param;
	if( count == 0 )
	{	/* Reset FM Timer */
		timer_enable(info->timer[c], 0);
	}
	else
	{	/* Start FM Timer */
		double timeSec = (double)count * stepTime;
		if (!timer_enable(info->timer[c], 1))
			timer_adjust_ptr(info->timer[c], timeSec, 0);
	}
}
Ejemplo n.º 7
0
void init_rgb_pwm(uint8_t _gpio_r, uint8_t _gpio_g, uint8_t _gpio_b, uint8_t _gpio_i){
	timer_init();

	MSS_GPIO_config((gpio_r_i = _gpio_r), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);
	MSS_GPIO_config((gpio_g_i = _gpio_g), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);
	MSS_GPIO_config((gpio_b_i = _gpio_b), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);
	MSS_GPIO_config((gpio_i_i = _gpio_i), MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE);

	MSS_GPIO_enable_irq(_gpio_r);
	MSS_GPIO_enable_irq(_gpio_g);
	MSS_GPIO_enable_irq(_gpio_b);
	MSS_GPIO_enable_irq(_gpio_i);

	// add the timer peripherals to the timer module
	red_timer_id   = add_timer(TIMER_RED);
	green_timer_id = add_timer(TIMER_GREEN);
	blue_timer_id  = add_timer(TIMER_BLUE);
	pulse_timer_id = add_timer(TIMER_PULSE);

	// all colors overflow at their max pwm value
	timer_setOverflowVal(red_timer_id, 1000000);
	timer_setOverflowVal(blue_timer_id, 1000000);
	timer_setOverflowVal(green_timer_id, 1000000);

	// pulse uses overflow only
	//timer_enable_allInterrupts(pulse_timer_id);
	timer_enable_overflowInt(pulse_timer_id);
	timer_disable_compareInt(pulse_timer_id);

	// colors require overflow and compare registers
	timer_enable_allInterrupts(red_timer_id);
	timer_enable_allInterrupts(blue_timer_id);
	timer_enable_allInterrupts(green_timer_id);

	timer_enable_compareInt(red_timer_id);
	timer_enable_compareInt(blue_timer_id);
	timer_enable_compareInt(green_timer_id);

	timer_enable_overflowInt(red_timer_id);
	timer_enable_overflowInt(blue_timer_id);
	timer_enable_overflowInt(green_timer_id);

	timer_enable(red_timer_id);
	timer_enable(green_timer_id);
	timer_enable(blue_timer_id);
	//timer_enable(pulse_timer_id);


	// don't start the colors until set_brightness is called
}
Ejemplo n.º 8
0
void radiotimer_setPeriod(PORT_RADIOTIMER_WIDTH period) {
	radiotimer_vars.period=(PORT_RADIOTIMER_WIDTH)period;
	timer_reset(TIMER_NUM3);
	timer_enable(TIMER_NUM3);
	radiotimer_vars.counter_slot_val=radiotimer_getValue(); //it is 0 always. remove that..
	timer_set_compare(TIMER_NUM3, TIMER_COMPARE_REG0,  radiotimer_vars.counter_slot_val+period); //the period timer is controlled by the compare 0 register
}
Ejemplo n.º 9
0
int main(void)
{
	static console_command_t commands[2];
	commands[0].callback = command_callback;
	commands[1].callback = branch_hub_command_callback;
	commands[1].help_callback = branch_hub_help_callback;
	ADCON1 = 0x0F;
	CMCON = 0x07;
	TRISA = 0x00;
	PORTA = 0x00;
	
	interrupt_initialize();
	timer_initialize();

	timer_register(timer_callback, 1000, &timer_id);
	timer_enable(timer_id);
	
	console_initialize();

	console_register_command(commands[0], "main");
	console_register_command(commands[1], "hub");

	hub_init(HUB_ADDRESS);
	
	while(1)
	{
		console_process_tasks();
	}
}
Ejemplo n.º 10
0
static u32
get_hz()
{
	// divided counter by 16
	lapic_write_reg(_LAPIC_DC_OFFSET, 0x3);
	// enable timer interrupt(vector 255)
	lapic_write_reg(_LAPIC_TIMER_OFFSET, 0xff);
	timer_enable();

	// initialize PIT channel 2 in one-shot mode
	// waiting 1/100 sec
	outb(0x61, (inb(0x61)&0xfd)|1);
	outb(0x43, 0xb2);
	// 1193182/100 = 11932 = 0x2e9c
	outb(0x42, 0x9c); // lsb
	inb(0x60); // short delay
	outb(0x42, 0x2e); // msb

	// reload counter
	u8 v = inb(0x61) & 0xfe;
	outb(0x61, v);
	outb(0x61, v|1);

	// reset apic timer init counter to -1
	lapic_write_reg(_LAPIC_IC_OFFSET, 0xffffffff);

	// wait until the PIT counter reaches zero
	while (!(inb(0x61) & 0x20));

	// disable timer interrupt
	timer_disable();

	return (0xffffffff - lapic_read_reg(_LAPIC_CC_OFFSET) + 1) * 100 * 16;
}
Ejemplo n.º 11
0
static void music_playback(int param)
{
	int pattern = 0;

	if ((OKIM6295_status_0_r(0) & 0x08) == 0)
	{
		if (sslam_bar != 0) {
			sslam_bar += 1;
			if (sslam_bar >= (sslam_snd_loop[sslam_melody][0] + 1))
				sslam_bar = 1;
		}
		pattern = sslam_snd_loop[sslam_melody][sslam_bar];

		if (pattern == 0xff) {		/* Restart track from first bar */
			sslam_bar = 1;
			pattern = sslam_snd_loop[sslam_melody][sslam_bar];
		}
		if (pattern == 0x00) {		/* Non-looped track. Stop playing it */
			sslam_track = 0;
			sslam_melody = 0;
			sslam_bar = 0;
			timer_enable(music_timer,0);
		}
		if (pattern) {
			logerror("Changing bar in music track to pattern %02x\n",pattern);
			OKIM6295_data_0_w(0,(0x80 | pattern));
			OKIM6295_data_0_w(0,0x81);
		}
	}
//  {
//      pattern = sslam_snd_loop[sslam_melody][sslam_bar];
//      popmessage("Music track: %02x, Melody: %02x, Pattern: %02x, Bar:%02d",sslam_track,sslam_melody,pattern,sslam_bar);
//  }
}
Ejemplo n.º 12
0
static void
timer_write(void *opaque, hwaddr addr,
            uint64_t val64, unsigned int size)
{
    struct timerblock *t = opaque;
    struct xlx_timer *xt;
    unsigned int timer;
    uint32_t value = val64;

    addr >>= 2;
    timer = timer_from_addr(addr);
    xt = &t->timers[timer];
    D(fprintf(stderr, "%s addr=%x val=%x (timer=%d off=%d)\n",
             __func__, addr * 4, value, timer, addr & 3));
    /* Further decoding to address a specific timers reg.  */
    addr &= 3;
    switch (addr) 
    {
        case R_TCSR:
            if (value & TCSR_TINT)
                value &= ~TCSR_TINT;

            xt->regs[addr] = value & 0x7ff;
            if (value & TCSR_ENT)
                timer_enable(xt);
            break;
 
        default:
            if (addr < ARRAY_SIZE(xt->regs))
                xt->regs[addr] = value;
            break;
    }
    timer_update_irq(t);
}
Ejemplo n.º 13
0
void dm_event_timer_init(dm_event_timer_t* const event_timer,
		dm_event_timer_mode mode, timer_regs_t* const timer_regs,
		compare_regs_t* const compare_regs) {
	datastream_object_init(&event_timer->super);  //call parents init function
	/*
	 * set method pointer(s) of super-"class" to sub-class function(s)
	 */
	event_timer->super.update = dm_event_timer_update;

	event_timer->control_out = &control_port_dummy;

	event_timer->timer = timer_regs;
	event_timer->compare = compare_regs;

	event_timer->mode = mode;

	event_timer->peridic_next = 0;
	event_timer->start_delay = 0;
	event_timer->repetitions = -1;

	dm_event_timer_clear_event_list(event_timer);

	timer_enable(timer_regs);  //TODO enable timer only when needed?
	//timer_set_interval_ms(timer_regs, 1000);

	compare_init_mode_set(compare_regs, 0);
}
Ejemplo n.º 14
0
DXL_COMM_ERR dxl_ping(DXL_ACTUATOR_t *settings, unsigned char id, unsigned char* err) {
	char tx_buff[6];
	tx_buff[0] = 0xFF;
	tx_buff[1] = 0xFF;
	tx_buff[2] = id;
	tx_buff[3] = 2;
	tx_buff[4] = DXL_PING;
	tx_buff[5] = 0x0;
	dxl_insert_checksum(tx_buff);
	gpio.out(settings->TxEnGpio, 1);
	uart.puts(settings->Uart, tx_buff, tx_buff[3] + 4);
	gpio.out(settings->TxEnGpio, 0);
	unsigned char rx_cnt = 0;
	signed short rx_char;
	char rx_buff[150];
	memset(rx_buff, 0, 150);
	bool preamble_ok = false;
	DXL_COMM_ERR errors = DXL_COMM_RXTIMEOUT;
	timer(timeout_timer);
	timer_interval(&timeout_timer, settings->timeout);
	while(1) {
		timer_enable(&timeout_timer);
		while(1) {
			rx_char = uart.getc_no_blocking(settings->Uart);
			if(rx_char != (signed short)-1) {
				if(rx_char == 0xFF && preamble_ok == false && rx_cnt < 2) {
					rx_buff[rx_cnt] = rx_char;
					rx_cnt++;
					break;
				}
				if(rx_char != 0xFF && rx_cnt == 1 && preamble_ok == false)
					rx_cnt = 0;
				if(rx_char != 0xFF && rx_cnt == 2 && preamble_ok == false)
					preamble_ok = true;
				if(preamble_ok == true) break;
			}
			if(timer_tick(&timeout_timer)) {
				return errors;
			}
		}
		if(preamble_ok) {
			if(rx_cnt < 56) rx_buff[rx_cnt++] = rx_char;
			else
				errors = DXL_COMM_OVERFLOW;
			if(rx_buff[LENGTH] > 54) {
				errors = DXL_COMM_RXCORRUPT;
			}
			if(rx_cnt > 3) {
				if(rx_cnt - 3 >= rx_buff[3]) {
					if(dxl_verify_checksum(rx_buff)) {
						*err = rx_buff[4];
						return DXL_COMM_SUCCESS;
					} else {
						errors = DXL_COMM_CHECKSUM;
					}
				}
			}
		}
	}
}
Ejemplo n.º 15
0
/*!
*******************************************************************************
**
** \brief  Close a soft timer.
**
** This function closes an instance of the soft timer.
**
** \param pHandle The pHandle of the soft timer to be closed.
**
** \return One of the following status codes:
**         - #GD_OK if successful
**         - #GD_ERR_BAD_PARAMETER if the given parameter is not correctly
**                                 specified.
**
** \sa GD_TIMER_SoftTimerOpen
******************************************************************************/
GERR GD_TIMER_GpregTimerClose(GD_HANDLE * pHandle)
{
    GD_TIMER_DEVICE_S* device;

    if(pHandle == NULL)
        return GD_ERR_INVALID_HANDLE;

    device = (GD_TIMER_DEVICE_S*)(*pHandle);
    if(device == NULL)
    {
        return GD_ERR_INVALID_HANDLE;
    }

    device->eState = TIME_FREE;
    device->nTimeCount = 0;
    device->bpTimeEnd = NULL;
    device->fpCallBackAddress = NULL;

    /* Disable the slow hard timer interrupt */
    timer_enable(device->timerReg, GD_INT_DISABLED);
    GD_INT_Enable(&device->handle, GD_INT_DISABLED);

    *pHandle = 0;
    return GD_OK;
}
Ejemplo n.º 16
0
void __init time_init(void)
{
	if (setup_baget_irq(BAGET_VIC_TIMER_IRQ, &timer_irq) < 0)
		printk("time_init: unable request irq for system timer\n");
	timer_enable();
	/* We don't call sti() here, because it is too early for baget */
}
void mls_Timing_Init(void)
{
	timer_init(QN_TIMER1, TMR1_Tick);
   timer_config(QN_TIMER1, TIMER_PSCAL_DIV, TIMER_COUNT_US(1000, TIMER_PSCAL_DIV));
   timer_enable(QN_TIMER1, MASK_ENABLE);
	Time_Tick = 0;
}
Ejemplo n.º 18
0
static TIMER_CALLBACK( music_playback )
{
	int pattern = 0;
	const device_config *device = devtag_get_device(machine, "oki");

	if ((okim6295_r(device,0) & 0x08) == 0)
	{
		if (sslam_bar != 0) {
			sslam_bar += 1;
			if (sslam_bar >= (sslam_snd_loop[sslam_melody][0] + 1))
				sslam_bar = 1;
		}
		pattern = sslam_snd_loop[sslam_melody][sslam_bar];

		if (pattern == 0xff) {		/* Restart track from first bar */
			sslam_bar = 1;
			pattern = sslam_snd_loop[sslam_melody][sslam_bar];
		}
		if (pattern == 0x00) {		/* Non-looped track. Stop playing it */
			sslam_track = 0;
			sslam_melody = 0;
			sslam_bar = 0;
			timer_enable(music_timer,0);
		}
		if (pattern) {
			logerror("Changing bar in music track to pattern %02x\n",pattern);
			okim6295_w(device,0,(0x80 | pattern));
			okim6295_w(device,0,0x81);
		}
	}
//  {
//      pattern = sslam_snd_loop[sslam_melody][sslam_bar];
//      popmessage("Music track: %02x, Melody: %02x, Pattern: %02x, Bar:%02d",sslam_track,sslam_melody,pattern,sslam_bar);
//  }
}
Ejemplo n.º 19
0
static void mcr68_common_init(void)
{
	int i;

	/* reset the 6840's */
	m6840_counter_periods[0] = ATTOTIME_IN_HZ(30);			/* clocked by /VBLANK */
	m6840_counter_periods[1] = attotime_never;					/* grounded */
	m6840_counter_periods[2] = ATTOTIME_IN_HZ(512 * 30);	/* clocked by /HSYNC */

	m6840_status = 0x00;
	m6840_status_read_since_int = 0x00;
	m6840_msb_buffer = m6840_lsb_buffer = 0;
	for (i = 0; i < 3; i++)
	{
		struct counter_state *m6840 = &m6840_state[i];

		m6840->control = 0x00;
		m6840->latch = 0xffff;
		m6840->count = 0xffff;
		timer_enable(m6840->timer, FALSE);
		m6840->timer_active = 0;
		m6840->period = m6840_counter_periods[i];
	}

	/* initialize the clock */
	m6840_internal_counter_period = ATTOTIME_IN_HZ(cpunum_get_clock(0) / 10);

	/* reset cocktail flip */
	mcr_cocktail_flip = 0;

	/* initialize the sound */
	mcr_sound_reset();
}
Ejemplo n.º 20
0
static int diag_sd_init(char *argv[], const char *test_name, int verbose)
{
	int rval = 0;
	int slot, type;

	putstr("running SD ");
	putstr(test_name);
	putstr(" test ...\r\n");
	putstr("press any key to terminate!\r\n");

	if (strcmp(argv[0], "sd") == 0) {
		slot = SCARDMGR_SLOT_SD;
	} else if (strcmp(argv[0], "sdio") == 0) {
		slot = SCARDMGR_SLOT_SDIO;
	} else if (strcmp(argv[0], "sd2") == 0) {
		slot = SCARDMGR_SLOT_SD2;
	} else {
		slot = SCARDMGR_SLOT_SD;
	}

	if (strcmp(argv[1], "sd") == 0) {
		type = SDMMC_TYPE_SD;
	} else if (strcmp(argv[1], "sdhc") == 0) {
		type = SDMMC_TYPE_SDHC;
	} else if (strcmp(argv[1], "mmc") == 0) {
		type = SDMMC_TYPE_MMC;
	} else if (strcmp(argv[1], "MoviNAND") == 0) {
		type = SDMMC_TYPE_MOVINAND;
	} else {
		type = SDMMC_TYPE_AUTO;
	}

	timer_reset_count(TIMER2_ID);
	timer_enable(TIMER2_ID);
	rval = sdmmc_init(slot, type);
	timer_disable(TIMER2_ID);
	if (verbose) {
		putstr("\r\nInit takes: ");
		putdec(timer_get_count(TIMER2_ID));
		putstr("mS\r\n");
		putstr("SD clock: ");
		putdec(get_sd_freq_hz());
		putstr("Hz\r\n");
#if (SD_HAS_SDXC_CLOCK == 1)
		putstr("SDXC clock: ");
#if (CHIP_REV == A7S)
		putdec((u32)amb_get_sdio_clock_frequency(HAL_BASE_VP));
#else
		putdec((u32)amb_get_sdxc_clock_frequency(HAL_BASE_VP));
#endif
		putstr("Hz\r\n");
#endif
		putstr("total_secs: ");
		putdec(sdmmc_get_total_sectors());
		putstr("\r\n");
	}

	return rval;
}
Ejemplo n.º 21
0
void timeHnd(void){
	u8 tr,doTimer;
	timer_int(0);
	timer_enable(0);
	timer_clearstat();
	
	for(tr=0; tr<NUM_TRACKS; tr++){
		if(trackTable[tr].play == 0) continue;
		if(trackTable[tr].data[trackTable[tr].currNote].tickPosition == musicTick && 
		   trackTable[tr].data[trackTable[tr].currNote].onoff == 0x09){//Start note
		    while(trackTable[tr].data[trackTable[tr].currNote+1].tickPosition == musicTick && //Look for the last note in a cord and play that one.
			      trackTable[tr].data[trackTable[tr].currNote+1].onoff == 0x09) trackTable[tr].currNote++;
			SND_REGS[tr].SxFQH=(FREQUENCY[trackTable[tr].data[trackTable[tr].currNote].note]>>8) & 0xFF;
			SND_REGS[tr].SxFQL=FREQUENCY[trackTable[tr].data[trackTable[tr].currNote].note] & 0xFF;
			SND_REGS[tr].SxLRV=trackTable[tr].volume;
			SND_REGS[tr].SxRAM = tr;
			trackTable[tr].offNote = 0;
			SND_REGS[tr].SxINT = 0x9F;
		}
		/*some midi's don't have off notes so this sets a max length for a given note*/
		trackTable[tr].offNote++;
		if(trackTable[tr].offNote > MAX_NOTE_LENGTH){
			SND_REGS[tr].SxINT = 0x00;
		}

		while(trackTable[tr].data[trackTable[tr].currNote].tickPosition <= musicTick && 
		      trackTable[tr].data[trackTable[tr].currNote].tickPosition != 0xFFFFFFFF){
			trackTable[tr].currNote++;
		}
		
		if(trackTable[tr].data[trackTable[tr].currNote].tickPosition == 0xFFFFFFFF){
			trackTable[tr].play = 0;
			trackTable[tr].currNote = 0;
			SND_REGS[tr].SxINT=0;
		}
	}
	musicTick++;
	doTimer = 0x00;
	for(tr=0; tr<NUM_TRACKS; tr++){
		if(trackTable[tr].play == 1) doTimer = 0x01;
	}
	if(doTimer){
		timer_int(1);
		timer_enable(1);
	}
}
Ejemplo n.º 22
0
/**
    \brief      configure the TIMER peripheral
    \param[in]  none
    \param[out] none
    \retval     none
  */
void timer_config(void)
{
/* -----------------------------------------------------------------------
    TIMER0 configuration to:
    generate 3 complementary PWM signals with 3 different duty cycles:
    TIMER0CLK is fixed to systemcoreclock, the TIMER0 prescaler is equal to 3600 so the 
    TIMER0 counter clock used is 20KHz.
    the three duty cycles are computed as the following description: 
    the channel 0 duty cycle is set to 25% so channel 1N is set to 75%.
    the channel 1 duty cycle is set to 50% so channel 2N is set to 50%.
    the channel 2 duty cycle is set to 75% so channel 3N is set to 25%.
  ----------------------------------------------------------------------- */
    timer_oc_parameter_struct timer_ocintpara;
    timer_parameter_struct timer_initpara;

    rcu_periph_clock_enable(RCU_TIMER0);

    timer_deinit(TIMER0);

    /* TIMER0 configuration */
    timer_initpara.timer_prescaler         = 3599;
    timer_initpara.timer_alignedmode       = TIMER_COUNTER_EDGE;
    timer_initpara.timer_counterdirection  = TIMER_COUNTER_UP;
    timer_initpara.timer_period            = 15999;
    timer_initpara.timer_clockrivision     = TIMER_CKDIV_DIV1;
    timer_initpara.timer_repetitioncounter = 0;
    timer_init(TIMER0,&timer_initpara);

     /* CH1,CH2 and CH3 configuration in PWM mode */
    timer_ocintpara.timer_outputState  = TIMER_CCX_ENABLE;
    timer_ocintpara.timer_outputnState = TIMER_CCXN_ENABLE;
    timer_ocintpara.timer_ocpolarity   = TIMER_OC_POLARITY_HIGH;
    timer_ocintpara.timer_ocnpolarity  = TIMER_OCN_POLARITY_HIGH;
    timer_ocintpara.timer_ocidleState  = TIMER_OC_IDLE_STATE_LOW;
    timer_ocintpara.timer_ocnidleState = TIMER_OCN_IDLE_STATE_LOW;

    timer_channel_output_config(TIMER0,TIMER_CH_0,&timer_ocintpara);
    timer_channel_output_config(TIMER0,TIMER_CH_1,&timer_ocintpara);
    timer_channel_output_config(TIMER0,TIMER_CH_2,&timer_ocintpara);

    timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_0,3999);
    timer_channel_output_mode_config(TIMER0,TIMER_CH_0,TIMER_OC_MODE_PWM1);
    timer_channel_output_shadow_config(TIMER0,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);

    timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_1,7999);
    timer_channel_output_mode_config(TIMER0,TIMER_CH_1,TIMER_OC_MODE_PWM1);
    timer_channel_output_shadow_config(TIMER0,TIMER_CH_1,TIMER_OC_SHADOW_DISABLE);

    timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_2,11999);
    timer_channel_output_mode_config(TIMER0,TIMER_CH_2,TIMER_OC_MODE_PWM1);
    timer_channel_output_shadow_config(TIMER0,TIMER_CH_2,TIMER_OC_SHADOW_DISABLE);

    timer_primary_output_config(TIMER0,ENABLE);

    /* auto-reload preload enable */
    timer_auto_reload_shadow_enable(TIMER0);
    timer_enable(TIMER0);
}
Ejemplo n.º 23
0
/*!
*******************************************************************************
**
** \brief  Set the soft timer.
**
** This function sets the value to an instance of the soft timer.
**
** \param pHandle The pHandle of the soft timer to be set.
** \param timeValue The timer value in 100 milliseconds.
** \param flag A pointer the timmer flag.
** \param fp Pointer to the callback function.
**
** \return One of the following status codes:
**         - #GD_OK if successful
**         - #GD_ERR_BAD_PARAMETER if the given parameter are not correctly
**                                 specified.
**
******************************************************************************/
GERR GD_TIMER_GpregTimerSet(GD_HANDLE* pHandle,
                                U32 timeValue,
                                GBOOL* flag,
                                void(*fp)()
                               )
{
    GD_TIMER_DEVICE_S* device;

    if(pHandle == NULL)
        return GD_ERR_INVALID_HANDLE;
    if(timeValue > (0xFFFFFFFF / (GD_GET_APB_ClkHz() / 100)))
    {
        return GD_ERR_TIMER_OUTOF_RANG;
    }

    device = (GD_TIMER_DEVICE_S*)(*pHandle);
    if(device == NULL)
    {
        return GD_ERR_INVALID_HANDLE;
    }
    /* Disable the sbusl interrupt until we set the state machine */
    GD_INT_Enable(&device->handle, GD_INT_DISABLED);
    timer_enable(device->timerReg, GD_INT_DISABLED);

    if (fp != NULL)
        device->fpCallBackAddress = fp;

    if (flag != NULL)
        device->bpTimeEnd = flag;

    device->nTimeCount = timeValue * 10;// timeValue (ms)

    GH_TIMER_set_CntnSts(device->timerReg,
        device->nTimeCount * (GD_GET_APB_ClkHz() / 1000) - 1);
    GH_TIMER_set_Reloadn(device->timerReg,
        device->nTimeCount * (GD_GET_APB_ClkHz() / 1000) - 1);

    device->eState = TIME_RUNNING;

    /* Enable the slow hard timer interrupt */
    timer_enable(device->timerReg, GD_INT_ENABLED);
    GD_INT_Enable(&device->handle, GD_INT_ENABLED);

    return GD_OK;
}
Ejemplo n.º 24
0
//#####################################################
void timer_interval(STimer_t *S_Timer_Struct,unsigned long long _Value)
{
#ifdef USE_RTC_100_MS
	S_Timer_Struct->S_Timmer_Interval = (_Value & (unsigned long long)INT64_MAX) / 10;
#else
	S_Timer_Struct->S_Timmer_Interval = _Value & (unsigned long long)INT64_MAX;
#endif
	timer_enable(S_Timer_Struct);
}
Ejemplo n.º 25
0
static int
device_enable_impl (struct device_interface *di, struct sh7780_tmu *device)
{
    device->state = STATE_ENABLED;
    device->remaining_ticks = 0;

    timer_enable(device);

    return DEVICE_ENABLED;
}
Ejemplo n.º 26
0
// pulse rate oscillates the led brightness between max_brightness and min_brightness
// param: rate - the number of cycles to wait before interrupting (which changes master_brightness)
// (0 = no pulse, 1=fast pulse 1-2^32=slower pulse)
void set_pulse_rate(uint32_t ms){
   timer_setOverflowVal(pulse_timer_id, ms*HZ_PER_MILLI_SEC);
   if(ms > 0) {
     timer_enable_allInterrupts(pulse_timer_id);
     timer_enable(pulse_timer_id);
   } else {
	 timer_disable_allInterrupts(pulse_timer_id);
	 timer_disable(pulse_timer_id);
   }
}
Ejemplo n.º 27
0
static void timer_hit(void *opaque)
{
    struct xlx_timer *xt = opaque;
    struct timerblock *t = xt->parent;
    D(fprintf(stderr, "%s %d\n", __func__, xt->nr));
    xt->regs[R_TCSR] |= TCSR_TINT;

    if (xt->regs[R_TCSR] & TCSR_ARHT)
        timer_enable(xt);
    timer_update_irq(t);
}
Ejemplo n.º 28
0
static void TimerHandler_3812(int c,double period)
{
	if( period == 0 )
	{	/* Reset FM Timer */
		timer_enable(Timer_3812[c], 0);
	}
	else
	{	/* Start FM Timer */
		timer_adjust(Timer_3812[c], period, c, 0);
	}
}
Ejemplo n.º 29
0
static int
device_enable_impl (struct device_interface *di, struct imx31_timer *device)
{
    device->state = STATE_ENABLED;
    device->remaining_ticks = 0;

    timer_enable(device);

    DBG("timer is enabled\n");
    return DEVICE_ENABLED;
}
Ejemplo n.º 30
0
/* TimerHandler from fm.c */
static void TimerHandler(int n,int c,int count,double stepTime)
{
	if( count == 0 )
	{	/* Reset FM Timer */
		timer_enable(Timer[n][c], 0);
	}
	else
	{	/* Start FM Timer */
		double timeSec = (double)count * stepTime;
		double slack;

		slack = timer_get_time() - lastfired[n][c];
		/* hackish way to make bstars intro sync without */
		/* breaking sonicwi2 command 0x35 */
		if (slack < 0.000050) slack = 0;

		if (!timer_enable(Timer[n][c], 1))
			timer_adjust(Timer[n][c], timeSec - slack, (c<<7)|n, 0);
	}
}