Example #1
0
// Module initialization function called internally
// Requires a pwm signal to use
static void InitializePWMModule(tPWMModule *mod, tPWM *pwm) {
    // Use either timer A (shift 0) or timer B (shift 8)
    int tshift = (mod->TIMER == TIMER_A) ? 0 : 8;

    // We take the period from the pwm signal
    mod->period = pwm->period;

    // Then we setup the initial cycle
    pwm->up.target = 0;
    pwm->up.timing = pwm->period / 2;
    pwm->down.target = pwm->period / 2;
    pwm->down.timing = pwm->period / 2;

    // Connect the linked list
    pwm->up.prev = pwm->up.next = &pwm->down;
    pwm->down.next = pwm->down.prev = &pwm->up;

    // And we set the start of the cycle
    mod->event = &pwm->up;
    
    
    // Enable the timer
    SysCtlPeripheralEnable(mod->PERIPH);
    
    // We only need half a timer, so keep the configuration of the second half
    // Configure the timer for one shot usage
    TimerConfigure(mod->BASE, TIMER_CFG_SPLIT_PAIR |
                              *mod->CFG_R |
                              (TIMER_TIMA_TIMEOUT << tshift));
    
    // Setup the timer
    TimerLoadSet(mod->BASE, mod->TIMER, pwm->up.timing);
    // This is a bit hacky and assumes the order of pwm modules
    // By editing the config register both timers are disabled
    TimerEnable(mod->BASE, mod->TIMER | TIMER_A);
    
    // Enable the interrupt
    IntEnable(mod->INT);
    TimerIntEnable(mod->BASE, TIMER_TIMA_TIMEOUT << tshift);
}
Example #2
0
int main(void) {

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
    //Set up the general purpose I/Os
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);    
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//1024hz = 15625

    //Set up the input/output pins
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1);
    GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);
    
    //Set up the interrupt pins
    GPIOIntEnable(GPIO_PORTC_BASE, GPIO_INT_PIN_5 | GPIO_INT_PIN_6);
    GPIOIntRegister(GPIO_PORTC_BASE, interrupt_handler);
    GPIOIntTypeSet(GPIO_PORTC_BASE, (GPIO_PIN_5 | GPIO_PIN_6), GPIO_RISING_EDGE);

    //Just a quick toggle to make sure code is working
    toggle();
  
    //Timer Configuration
    TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    TimerLoadSet(TIMER0_BASE, TIMER_A, frequency);
    TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
    TimerEnable(TIMER0_BASE, TIMER_A);

    //Timer Interrupt Enable
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    TimerIntRegister(TIMER0_BASE, TIMER_A, timer_interrupt);

    //Loop forever
    while(1){
          
      // if(TimerValueGet(TIMER0_BASE, TIMER_A) == 0){
      //           GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, pin_data);
      //           pin_data^=0x04;
      //     }
         }
}
Example #3
0
int main(void)
{
	//Do setup
	setup();
	ledPinConfig();
	switchPinConfig();
	//Enable timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

	uint32_t ui32Period;

	ui32Period = (SysCtlClockGet() / 100) / 2;
	TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);

	IntEnable(INT_TIMER0A);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	IntMasterEnable();

	TimerEnable(TIMER0_BASE, TIMER_A);
	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, led);

	while(1)
	{
		//vode for automode
		if(mode)
		{
			SysCtlDelay(autoDelay*200000);
			if(led == 2) led = 10;
			else if(led == 10) led = 8;
			else if(led == 8) led = 12;
			else if(led == 12) led = 4;
			else if (led == 4) led = 6;
			else if(led == 6) led = 2;
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 , led);
		}
	}


}
Example #4
0
////////////////////////////////TIMER////////////////////////////////
//Configures Timer4A as a 32-bit periodic timer [HW Dependent]
static void RF22_TimerInit()
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);

    TimerConfigure(TIMER4_BASE, TIMER_CFG_32_BIT_PER_UP);
    // Set the Timer4A load value to 1ms.
    TimerLoadSet(TIMER4_BASE, TIMER_A, SysCtlClockGet() / 1000); //1 [ms]

    // Configure the Timer interrupt for timer timeout.
    TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT);

    // Set Low interrupt priority for Timer
    IntPrioritySet(INT_TIMER4A, 3);

    // Enable the Timer interrupt on the processor (NVIC).
    IntEnable(INT_TIMER4A);

    _time_counter = 0;

    // Enable Timer.
    TimerEnable(TIMER4_BASE, TIMER_A);
}
void Timer1_Init(unsigned int frequency)
{
	uint32_t ui32Period; //desired clock period

	// before calling any peripheral specific driverLib function we must enable the clock to that peripheral!!!
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

	/*
	 * Timer 1 as a 32-bit timer in periodic mode.
	 * TIMER1_BASE is the start of the timer registers for Timer0 in the peripheral section of the memory map.
	 */
	TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

	/*
	 * desired frequency = x Hz
	 * duty cycle = 50% (interrupt at 1/2 of the desired period)
	 */
	ui32Period = (SysCtlClockGet() / frequency) / 2;

	/*
	 * load calculated period into the Timer’s Interval Load register using the TimerLoadSet
	 * you have to subtract one from the timer period since the interrupt fires at the zero count
	 */
	TimerLoadSet(TIMER1_BASE, TIMER_A, ui32Period -1);

	// Enable triggering
	TimerControlTrigger(TIMER1_BASE, TIMER_A, true);


	/*** INTERRUPT ENABLE ***/

	IntEnable(INT_TIMER1A); // enables the specific vector associated with Timer0A
	TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); //enables a specific event within the timer to generate an interrupt.(timeout of Timer 0A)
//	IntMasterEnable(); //master interrupt enable API for all interrupts.

	/* TIMER ENABLE */
	TimerEnable(TIMER1_BASE, TIMER_A);

}
Example #6
0
int OS_AddPeriodicThread(void (*task)(void) , unsigned long period, unsigned long priority){
    // Save 
    func = task;
    
    // Reconfigure Timer1
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
    TimerConfigure(TIMER2_BASE, TIMER_CFG_A_PERIODIC);
    //TimerControlTrigger(TIMER2_BASE, TIMER_A, true);
    TimerLoadSet(TIMER2_BASE, TIMER_A, period);
    TimerEnable(TIMER2_BASE, TIMER_A);
    TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
    IntEnable(INT_TIMER2A);
    
    // Priority?
    
    // Debugging IO
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 1);
    
    return 1;
} 
Example #7
0
/************ FUNCTION DEFINITIONS ****************/
void modeselect(void)
{
	if(GPIOIntStatus(GPIO_PORTF_BASE,false) & GPIO_INT_PIN_0)
	{
		GPIOIntClear(GPIO_PORTF_BASE,GPIO_PIN_0);
		for(i=0;i<2000;i++);
		if (GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0)
		{
			mode++;
			if (mode==6)
				mode = 1;
			switch(mode)	//According to mode, initialize peripherals and disable other peripherals
			{
			case 1:	mode2unset(); mode3unset();	mode4unset();	mode5unset();	mode1set();	break;
			case 2: mode1unset(); mode3unset();	mode4unset();	mode5unset();	mode2set();	break;
			case 3: mode2unset(); mode1unset();	mode4unset();	mode5unset();	mode3set();	break;
			case 4: mode2unset(); mode1unset();	mode3unset();	mode5unset();	mode4set();	break;
			case 5: mode2unset(); mode1unset();	mode4unset();	mode3unset();	mode5set();	break;
			}
		}
	}
	if((GPIOIntStatus(GPIO_PORTF_BASE,false)&GPIO_INT_PIN_4)&& (mode==2||mode==5))
	{
		GPIOIntClear(GPIO_PORTF_BASE,GPIO_PIN_4);
		if(!GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4))
		{
			mode2();
			TimerLoadSet(TIMER1_BASE, TIMER_A,SysCtlClockGet()/3);	//Set the Max Value of the timer
			TimerEnable(TIMER1_BASE,TIMER_A);	//Start the timer
		}
		else
		{
			TimerDisable(TIMER1_BASE,TIMER_A);
			fast_flag=0;
		}

	}
}
Example #8
0
int main(void)
{

    uint32_t ui32Period;
	setup();
	ledPinConfig();
    switchPinConfig();
	/*---------------------

		* Write your code here
		* You can create additional functions

	---------------------*/
    // Timer Configuration
    ui32Period = (SysCtlClockGet() / FREQUENCY);
    TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period - 1);
    IntEnable(INT_TIMER0A);
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    IntMasterEnable();
    TimerEnable(TIMER0_BASE, TIMER_A);
    while(1) {
    }
}
Example #9
0
void SonarInterrupt(void)
{
  GPIOPinIntClear(GPIO_PORTD_BASE, GPIO_PIN_7);
  count++;

  if (Status==1)
  {
    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0xFF);
    TimerLoadSet(TIMER2_BASE, TIMER_A,6000000);
    TimerEnable(TIMER2_BASE, TIMER_A);
    Status=2;
  }

 else if (Status==2)
 {
    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0);
    //Distance=((5995500-TimerValueGet(TIMER2_BASE, TIMER_A))*17)/600000;
    Distance=TimerValueGet(TIMER2_BASE, TIMER_A);
    TimerDisable(TIMER2_BASE, TIMER_A);
    Status=3;
 }

}
Example #10
0
/**
* \brief Initialize the systick module, i.e. the hardware timer of the SoC
* 
* This function will register the corresponding ISR, enable the timer interrupt and configure interrupt channel 2 (normal interrupt) for the hardware timer.
*
* \return none
**/
void systick_init(void) {
    /* Set up the ARM Interrupt Controller for generating timer interrupt */
    
    /* Set up the timer */
    TimerConfigure(SOC_TMR_0_REGS, TMR_CFG_32BIT_UNCH_CLK_BOTH_INT);
    TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER34, TMR_PERIOD_LSB32);
    TimerReloadSet(SOC_TMR_0_REGS, TMR_TIMER34, TMR_PERIOD_LSB32);
    
    /* Register the Timer ISR */
    IntRegister(SYS_INT_TINT34_0, systick_isr_C);
  
    /* Set the channel number for Timer interrupt, it will map to IRQ */
    IntChannelSet(SYS_INT_TINT34_0, 2);
    
    /* Enable timer interrupts in AINTC */
    IntSystemEnable(SYS_INT_TINT34_0);
    
    /* Enable the timer interrupt */
    TimerIntEnable(SOC_TMR_0_REGS, TMR_INT_TMR34_NON_CAPT_MODE); 
    
    /* Start the timer */
    TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONTRELOAD);
}
int main(void)
{
	//uint32_t ui32Period;
	//uint32_t ui32Period = 40000000;			// 1s
	//uint32_t ui32Period = 10000000;			// 1/4 s
	uint32_t ui32Period = 40000;			// 1/4 s
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);	// count down
	//ui32Period = (SysCtlClockGet() / 20) / 2;
	//ui32Period = (SysCtlClockGet() / 40000);
	TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
	IntEnable(INT_TIMER0A);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	IntMasterEnable();
	TimerEnable(TIMER0_BASE, TIMER_A);

	while(1)
	{
	}
}
Example #12
0
static void backup_key_info_handler ()
{
	bk_nano.binfo = 1;
	
	NhelperTitleBarSetContent(_("Information"));
	TimerDisable(bk_nano.timer);	

	/* Create Info id */
	bk_nano.info_id = info_create();
	int* is_running = backup_get_ttsstate();

	/* Fill info item */
	char* backup_info[1];
	char present_info[128];
	snprintf(present_info, 128, "%s %f%% %s", _("Backup"), bk_nano.thiz->prog_val, _("completed."));	
	backup_info[0] = present_info;
	
	info_start (bk_nano.info_id, backup_info, 1, is_running);
	info_destroy (bk_nano.info_id);

	TimerEnable(bk_nano.timer);
	NhelperTitleBarSetContent(_("Backup"));
	NhelperStatusBarSetIcon(SRQST_SET_CATEGORY_ICON, SBAR_CATEGORY_ICON_BACKUP);
	switch(bk_nano.media)
	{
	case 0:
		NhelperStatusBarSetIcon(SRQST_SET_MEDIA_ICON, SBAR_MEDIA_ICON_INTERNAL_MEM);
		break;
	case 1:
		NhelperStatusBarSetIcon(SRQST_SET_MEDIA_ICON, SBAR_MEDIA_ICON_SD_CARD);
		break;
	case 2:
		NhelperStatusBarSetIcon(SRQST_SET_MEDIA_ICON, SBAR_MEDIA_ICON_USB_MEM);
		break;
	}
	bk_nano.binfo = 0;
}
Example #13
0
void adc_init(void)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

	TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

	//Set what the timer runs to
	TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / FREQ );

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);

	ADCSequenceDisable(ADC0_BASE, 1);
	ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_TIMER, 0);

	ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_CH0);
	ADCSequenceStepConfigure(ADC_BASE, 1, 1, ADC_CTL_CH1);
	ADCSequenceStepConfigure(ADC_BASE, 1, 2, ADC_CTL_CH2);
	ADCSequenceStepConfigure(ADC_BASE, 1, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 1);
	ADCIntEnable(ADC0_BASE, 1);

	TimerEnable(TIMER1_BASE, TIMER_A);

	//Set timer 1A to trigger the ADC
	TimerControlTrigger(TIMER1_BASE, TIMER_A, 1);

	//May be useful:
	//SysCtlADCSpeedGet();

	ADCIntClear(ADC0_BASE, 1);
	ADCIntEnable(ADC0_BASE, 1);
	IntEnable(INT_ADC0SS1);
}
Example #14
0
void confTimer(){

	//Inicializamos el TIMER2 para el ADC como Trigger a una frecuencia de 10Hz
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER2);
	TimerControlStall(TIMER2_BASE,TIMER_A,true);
	TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC);
	uint32_t ui32Period = SysCtlClockGet() *0.1;
	TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period -1);
	TimerControlTrigger(TIMER2_BASE,TIMER_A,true);
	TimerEnable(TIMER2_BASE, TIMER_A);

	//Inicializamos el TIMER4 para la pulsación larga con un periodo de 2 segundos
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
  SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER4);
  TimerConfigure(TIMER4_BASE, TIMER_CFG_ONE_SHOT);
  ui32Period = (SysCtlClockGet() *2) ;
  TimerLoadSet(TIMER4_BASE, TIMER_A, ui32Period -1);
  IntEnable(INT_TIMER4A);
  TimerIntRegister(TIMER4_BASE,TIMER_A,timerBotonHandler);
  IntPrioritySet(INT_TIMER4A,5<<5);
  TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT);

}
/**
 * Performs one-time setup of peripherals
 */
static void vInit(void)
{
    /* Sets Clock Speed to 50MHz */
    ROM_SysCtlClockSet(
            SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
            | SYSCTL_XTAL_16MHZ);

    /* Initializes Bumpers with Interrupt */
    BumpSensorsInit();
    GPIOPinIntEnable(GPIO_PORTE_BASE, (1 << 0) | (1 << 1));
    GPIOIntTypeSet(GPIO_PORTE_BASE, (1 << 0) | (1 << 1), GPIO_FALLING_EDGE);
    IntEnable(20);

    /* Initializes timer, required for scheduler */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER_UP);
    TimerEnable(TIMER0_BASE, TIMER_A);

    SoundInit();
    SoundVolumeSet(95);

    IntMasterEnable();

    /* Hardware initialization for Bouncy related peripherals */
    vBouncyInit();

    /* Hardware initialization for Gamepad related peripherals */
    vGamepadInit();

    initDriveControl();

    // Init the rangefinder
    initRangeFinder();

    return;
}
Example #16
0
// ================= CONFIGURE AND QUERY FASTER TIMER FOR STATS ===============
void vConfigureTimerForRunTimeStats( void ){
    unsigned long ulFrequency;

    // we will use Timer 2
    SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER2 );
    TimerConfigure( TIMER2_BASE, TIMER_CFG_32_BIT_PER );

    // set timer interrupt to be above the kernel
    IntPrioritySet( INT_TIMER2A, configMAX_SYSCALL_INTERRUPT_PRIORITY + (1 << 5) );

    // set timer interrupt period (freq. appears to be sysclk/2 for now)
    // we just set timer to maximum period and count overflows
    ulFrequency = configCPU_CLOCK_HZ / tmrTIMER_2_FREQUENCY;
    TimerLoadSet( TIMER2_BASE, TIMER_A, MAX_32_BIT_VALUE );
    IntEnable( INT_TIMER2A );
    TimerIntEnable( TIMER2_BASE, TIMER_TIMA_TIMEOUT );

    // disable until schedule runs and enables the interrupts
    portDISABLE_INTERRUPTS();

    // enable Timer 2
    TimerEnable( TIMER2_BASE, TIMER_A );

}
Example #17
0
sht1x_error_t sht1x_status_write(uint8_t status)
{
	sht1x_error_t result = SHT1X_ERROR_BUSY;

	if (xSemaphoreTake(device.lock, portMAX_DELAY) == pdTRUE) {
		sht1x_command_prepare(sreg_write_pattern, sizeof(sreg_write_pattern));
		sht1x_command_payload_prepare(device.cmd_payload, status & SHT1X_SREG_bm);
		sht1x_device_state_prepare(SHT1X_SIDX_SREGW_FIN);

		sht1x_udma_set_buffer(device.cmd, sizeof(trans_start_pattern) + sizeof(sreg_write_pattern));

		TimerLoadSet(SHT1X_TIMER_BASE, SHT1X_TIMER, SHT1X_CLK_NR);
		TimerIntClear(SHT1X_TIMER_BASE, TIMER_TIMA_TIMEOUT);
		TimerEnable(SHT1X_TIMER_BASE, SHT1X_TIMER);

		if (xSemaphoreTake(device.interrupt_semaphore, portMAX_DELAY) == pdTRUE) {
			result = device.error;
			device.status = status;
			device.crc_init = sht1x_reverse_bits(status);
		}
		xSemaphoreGive(device.lock);
	}
	return result;
}
Example #18
0
sht1x_error_t sht1x_status_read(uint8_t * status)
{
	sht1x_error_t result = SHT1X_ERROR_BUSY;

	if (xSemaphoreTake(device.lock, portMAX_DELAY) == pdTRUE) {
		sht1x_command_prepare(sreg_read_pattern, sizeof(sreg_read_pattern));
		sht1x_device_state_prepare(SHT1X_SIDX_SREGR_FIN);

		sht1x_udma_set_buffer((void *) device.cmd, sizeof(trans_start_pattern) + sizeof(sreg_read_pattern));

		TimerLoadSet(SHT1X_TIMER_BASE, SHT1X_TIMER, SHT1X_CLK_NR);
		TimerIntClear(SHT1X_TIMER_BASE, TIMER_TIMA_TIMEOUT);
		TimerEnable(SHT1X_TIMER_BASE, SHT1X_TIMER);

		if (xSemaphoreTake(device.interrupt_semaphore, portMAX_DELAY) == pdTRUE) {
			result = device.error;
			if (result == SHT1X_ERROR_OK) {
				uint8_t data[] = {SHT1X_SREG_READ_CMD, device.data & 0xff, sht1x_reverse_bits(device.crc)};
				uint8_t crc = sht1x_crc(data, sizeof(data), device.crc_init);

				if (crc == 0) {
					device.status = device.data & 0xff;
					device.crc_init = sht1x_reverse_bits(device.status);
					if (status != NULL) {
						*status = device.status;
					}
				} else {
					result = SHT1X_ERROR_INVALID_CRC;
				}
			}
		}
		xSemaphoreGive(device.lock);
	}

	return result;
}
Example #19
0
sht1x_error_t sht1x_software_reset(void)
{
	sht1x_error_t result = SHT1X_ERROR_BUSY;

	if (xSemaphoreTake(device.lock, portMAX_DELAY) == pdTRUE) {
		sht1x_command_prepare(soft_reset_pattern, sizeof(soft_reset_pattern));
		sht1x_device_state_prepare(SHT1X_SIDX_SOFT_RESET_FIN);

		sht1x_udma_set_buffer((void *) device.cmd, sizeof(trans_start_pattern) + sizeof(sreg_read_pattern));

		TimerLoadSet(SHT1X_TIMER_BASE, SHT1X_TIMER, SHT1X_CLK_NR);
		TimerIntClear(SHT1X_TIMER_BASE, TIMER_TIMA_TIMEOUT);
		TimerEnable(SHT1X_TIMER_BASE, SHT1X_TIMER);

		if (xSemaphoreTake(device.interrupt_semaphore, portMAX_DELAY) == pdTRUE) {
			result = device.error;
			device.status = SHT1X_DEFAULT_STATUS;
			device.crc_init = SHT1X_DEFAULT_CRC_INIT;
		}
		xSemaphoreGive(device.lock);
	}

	return result;
}
Example #20
0
int main (void) 
{ 
  // Set the clock  
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	// Set output
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1);
	
	// Configure PF1 as T0CCP1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	
	GPIOPinConfigure(GPIO_PB6_T0CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE,GPIO_PIN_6);
	
	// Configure Timer
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	
	TimerConfigure(TIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER0_BASE,TIMER_A,SysCtlClockGet());
	TimerMatchSet(TIMER0_BASE,TIMER_A,SysCtlClockGet()/2);
	TimerControlLevel(TIMER0_BASE,TIMER_A,false);
	TimerEnable(TIMER0_BASE,TIMER_A);
	
} 
Example #21
0
// * imu_init *****************************************************************
// * Setup pins and I2C interface to communicate with IMU (Pololu MinIMU-9).  *
// *                                                                          *
// * NOTE: Also called internally by imu_i2c_abort_transaction during reset   *
// *       to recover from NAK/error.                                         *
// *                                                                          *
// * Portions for initialization of softi2c library copied/modified from      *
// * "soft_i2c_atmel.c" example code.                                         *
// ****************************************************************************
void imu_init(void)
{
                                                          // setup pins for I2C--------------------
    SysCtlPeripheralEnable(IMU_PORT);                     // enable GPIO port for IMU
    SysCtlPeripheralEnable(IMU_TIM);                      // enable timer to use for I2C bit timing
    SysCtlPeripheralReset(IMU_TIM);                       // reset timer to clear any previous configuration
    GPIOPinTypeI2C(IMU_PORT_BASE, IMU_PINS);              // configure pins for I2C
    memset(&g_sI2C, 0, sizeof(g_sI2C));                   // clear record
    SoftI2CCallbackSet(&g_sI2C, imu_SoftI2CCallback);     // set callback function
    SoftI2CSCLGPIOSet(&g_sI2C, IMU_PORT_BASE, IMU_SCL);   // set SCL pin
    SoftI2CSDAGPIOSet(&g_sI2C, IMU_PORT_BASE, IMU_SDA);   // set SDA pin
    SoftI2CInit(&g_sI2C);                                 // initialize software I2C driver
    SoftI2CIntEnable(&g_sI2C);                            // enable callback from softi2c
    
                                                          // configure timer interrupt
                                                          // Note, (interrupt rate)/4 = SCL frequency
    TimerConfigure(IMU_TIM_BASE, TIMER_CFG_32_BIT_PER);   // configure timer for 32b operation
    TimerLoadSet(IMU_TIM_BASE, TIMER_A, SysCtlClockGet() / IMU_TIM_INTRATE);
                                                          // configure divider to yield desired interrupt rate
    TimerIntEnable(IMU_TIM_BASE, TIMER_TIMA_TIMEOUT);     // enable timer wrap interrupt
    TimerEnable(IMU_TIM_BASE, TIMER_A);                   // enable timer to start counting
    IntEnable(IMU_TIM_INT_VECT);                          // enable interrupt vector in NVIC
  
}
//*****************************************************************************
//
//! Enables the sound output.
//!
//! This function enables the sound output, preparing it to play music or sound
//! effects.
//!
//! \return None.
//
//*****************************************************************************
void
SoundEnable(void)
{
    //
    // Set the timer to produce 40 kHz, which is well beyond the limits of
    // human hearing.
    //
    TimerLoadSet(TIMER2_BASE, TIMER_A, (g_ulSystemClock / 40000) - 1);

    //
    // Restore the output volume.
    //
    SoundVolumeSet(g_ucVolume);

    //
    // Enable the PWM output timer.
    //
    TimerEnable(TIMER2_BASE, TIMER_A);

    //
    // Configure the speaker GPIO pin as a timer PWM pin.
    //
    GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_7);
}
Example #23
0
File: main.c Project: Teider/QuIES
//*****************************************************************************
//
// This example application demonstrates the use of the timers to generate
// periodic interrupts.
//
//*****************************************************************************
int
main(void)
{
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
		FPUEnable();
		FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
	
		//
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Initialize the UART and write status.
    //
    ConfigureUART();
		ConfigureXBeeUART();
		ConfigureUARTSensores();
		ButtonsInit();
		inicializa_motores();

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Configure the two 32-bit periodic timers.
    //
    TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
    TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet()/200000);
		
		
    //
    // Setup the interrupts for the timer timeouts.
    //
    IntEnable(INT_TIMER1A);
   
    TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    //
    // Enable the timers.
    //
		
    TimerEnable(TIMER1_BASE, TIMER_A);


		// Configure a wide timer for timing purposes
		
		SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);
		TimerConfigure(WTIMER0_BASE, TIMER_CFG_PERIODIC_UP);
		TimerLoadSet64(WTIMER0_BASE, (((long long)1) << 60));
		TimerEnable(WTIMER0_BASE, TIMER_A);
	
	int counter_verify_no_ar = 0;
	
	while(1) {
		SysCtlDelay(SysCtlClockGet() / 1000);
		checkButtons();
		
		readPackage();
		
		counter_verify_no_ar++;
		
		if (counter_verify_no_ar == 1000) {
			counter_verify_no_ar = 0;
			if (no_ar) {
				enviaNoAr();
				no_ar = false;
			}
			if (no_chao) {
				enviaNoChao();
				no_chao = false;
			}
		}
	}
}
Example #24
0
int main(void) {
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);	//Configure System Clock
//SSD
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);	//Enable Port D
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	//Enable Port B
	GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,0x0F);
	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,0xFF);
//S1 and S2
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);	//Enable Port F
//Mode 1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);		//Enable ADC0 Module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);	//Enable Port E
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);	//Select ADC Function of PE 1
	ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);	//Configure ADC0 Sequencer
	ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);	//Configure the step of the sequencer
//Mode 2
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);	//Enable TIMER1 Module
	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4);	//Set PF4 as Input
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);		//Configuring the PF4
	GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_BOTH_EDGES);		//Setting Interrupt to trigger on both edges
	TimerConfigure(TIMER1_BASE,TIMER_CFG_PERIODIC);	//Configure TIMER1 into a Continuous Mode
	TimerIntRegister(TIMER1_BASE, TIMER_A, fast);	//Register interrupt if PF4 pressed for more than 1s
//Mode 3
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);	//Enable TIMER4 Module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);	//Enable WTIMER0 Module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);	//Enable Port C
	GPIOPinConfigure(GPIO_PC4_WT0CCP0);
	GPIOPinTypeTimer(GPIO_PORTC_BASE,GPIO_PIN_4);	//Set PC4 as a Timer Capture pin
	TimerIntRegister(TIMER4_BASE,TIMER_A,freqfind);	//Register a timer interrupt for TIMER4
	TimerConfigure(TIMER4_BASE,TIMER_CFG_PERIODIC);	//Configure Timer4 in continuous mode
	TimerConfigure(WTIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_CAP_COUNT);
	TimerControlEvent(WTIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);	//Configure WTIMER0 for Positive Edge Capture

	IntMasterEnable();
	GPIOPinWrite(GPIO_PORTB_BASE,0xFF,0x00);	//Initialize SSD to 0x00
	GPIOPinWrite(GPIO_PORTD_BASE, 0x0F, 0x00);	//Turn off all the digits of the SSD
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);	//Enable TIMER0 Module
	TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);	//Configure TIMER0 into a Continuous Mode
	TimerIntRegister(TIMER0_BASE, TIMER_A, ssdmux);	//Register ISR for TIMER0 Interrupt to update SSD
	TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet()/3000);	//Set the refresh rate of the SSD
	IntEnable(INT_TIMER0A);
	TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);	//Enable the timer interrupt
	TimerEnable(TIMER0_BASE,TIMER_A);	//Start the timer

	HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE|GPIO_O_CR) = GPIO_PIN_0;	//Unlock PF0 from the NMI mode
	HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = 0;

	ssdset(0);
	mode1set();

	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);	//Setting PF0 to Input
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);		//Configuring the pins
	GPIOIntRegister(GPIO_PORTF_BASE, modeselect);		//Register Interrupt for Port F with ISR modeselect()
	GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0);		//Clear any existing interrupts
	GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE);		//Setting Interrupt to trigger on falling edges
	GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0);		//Enable the GPIO Interrupts on Port F
	IntEnable(INT_GPIOF);	//Enable Interrupts on Port F

	while(1){
		switch(mode)	//Select operation according to mode
		{
		case 1: mode1();
				break;
		case 2: ssdsetHex(hex_count);
				if(fast_flag)
				{
					mode2();
					SysCtlDelay(SysCtlClockGet()/300);
				}
				break;
		case 3: mode3(); break;
		case 4: mode1(); break;
		case 5: ssdsetHex(hex_count);
				if(fast_flag)
				{
					mode2();
					SysCtlDelay(SysCtlClockGet()/300);
				} break;
				}
		SysCtlDelay(SysCtlClockGet()/3000);
	}
	return 0;
}
void ISL29023AppCallback(void *pvCallbackData, unsigned     int ui8Status)
{
	
		float fAmbient;
    
		unsigned char tempString[30]={0};
		
		float tempfAmbient;
		uint8_t ui8NewRange;
		
		if(ui8Status == I2CM_STATUS_SUCCESS&&sensorTurn==2)
		{
				//
				// Get a local floating point copy of the latest light data
				//
				ISL29023DataLightVisibleGetFloat(&g_sISL29023Inst, &fAmbient);
			
				//
				// Perform the conversion from float to a printable set of integers
				//
				ISL290_i32IntegerPart = (int32_t)fAmbient;
				ISL290_i32FractionPart = (int32_t)(fAmbient * 1000.0f);
				ISL290_i32FractionPart = ISL290_i32FractionPart - (ISL290_i32IntegerPart * 1000);
				if(ISL290_i32FractionPart < 0)
				{
						ISL290_i32FractionPart *= -1;
				}

				//
				// Print the temperature as integer and fraction parts.
				//
				//sprintf(tempString,"Visible Lux: %3d.%03d\n\r", ISL290_i32IntegerPart,ISL290_i32FractionPart);
				//CLI_Write(tempString);

				if(g_vui8IntensityFlag)
				{
					IntPriorityMaskSet(0x40);
					//
					// Reset the intensity trigger flag.
					//
					g_vui8IntensityFlag = 0;

					//
					// Adjust the lux range.
					//
					
					ui8NewRange = g_sISL29023Inst.ui8Range;

					//
					// Get a local floating point copy of the latest light data
					//
					ISL29023DataLightVisibleGetFloat(&g_sISL29023Inst, &tempfAmbient);

					//
					// Check if we crossed the upper threshold.
					//
					if(tempfAmbient > g_fThresholdHigh[g_sISL29023Inst.ui8Range])
					{
							//
							// The current intensity is over our threshold so adjsut the range
							// accordingly
							//
							if(g_sISL29023Inst.ui8Range < ISL29023_CMD_II_RANGE_64K)
							{
									ui8NewRange = g_sISL29023Inst.ui8Range + 1;
							}
					}

					//
					// Check if we crossed the lower threshold
					//
					if(tempfAmbient < g_fThresholdLow[g_sISL29023Inst.ui8Range])
					{
							//
							// If possible go to the next lower range setting and reconfig the
							// thresholds.
							//
							if(g_sISL29023Inst.ui8Range > ISL29023_CMD_II_RANGE_1K)
							{
									ui8NewRange = g_sISL29023Inst.ui8Range - 1;
							}
					}
					
					//
					// If the desired range value changed then send the new range to the sensor
					//
					if(ui8NewRange != g_sISL29023Inst.ui8Range)
					{
							ISL29023ReadModifyWrite(&g_sISL29023Inst, ISL29023_O_CMD_II,
																			~ISL29023_CMD_II_RANGE_M, ui8NewRange,
																			ISL29023AppCallback, &g_sISL29023Inst);
					}
					
					SysCtlDelay(g_SysClock / (100 * 3));
					//
					// Now we must manually clear the flag in the ISL29023
					// register.
					//
					ISL29023Read(&g_sISL29023Inst, ISL29023_O_CMD_I,
											 g_sISL29023Inst.pui8Data, 1, ISL29023AppCallback,
											 &g_sISL29023Inst);

					//
					// Wait for transaction to complete
					//
					SysCtlDelay(g_SysClock / (100 * 3));
					
					//
					// Disable priority masking so all interrupts are enabled.
					//
					
					IntPriorityMaskSet(0);
				}
				sensorTurn=(sensorTurn+1)%NumberOfSensor;
				TimerEnable(TIMER1_BASE, TIMER_A);
		}
		
}
void BMP180AppCallback(void* pvCallbackData, unsigned     int ui8Status)
{
	
		float fTemperature, fPressure, fAltitude;
    
		unsigned char tempString[30]={0};
		
		if(ui8Status == I2CM_STATUS_SUCCESS&&sensorTurn==1)
    {
				//
        // Get a local copy of the latest temperature and pressure data in
        // float format.
        //
        BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature);
        BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure);

        //
        // Convert the temperature to an integer part and fraction part for
        // easy print.
        //
        BMP180_i32IntegerPart1 = (int32_t) fTemperature;
        BMP180_i32FractionPart1 =(int32_t) (fTemperature * 1000.0f);
        BMP180_i32FractionPart1 = BMP180_i32FractionPart1 - (BMP180_i32IntegerPart1 * 1000);
        if(BMP180_i32FractionPart1 < 0)
        {
            BMP180_i32FractionPart1 *= -1;
        }

        //
        // Print temperature with three digits of decimal precision.
        //
        //sprintf(tempString,"Temperature %3d.%03d\t", BMP180_i32IntegerPart1,
         //          BMP180_i32FractionPart1);
				//CLI_Write(tempString);
				

        //
        // Convert the pressure to an integer part and fraction part for
        // easy print.
        //
        BMP180_i32IntegerPart2 = (int32_t) fPressure;
        BMP180_i32FractionPart2 =(int32_t) (fPressure * 1000.0f);
        BMP180_i32FractionPart2 = BMP180_i32FractionPart2 - (BMP180_i32IntegerPart2 * 1000);
        if(BMP180_i32FractionPart2 < 0)
        {
            BMP180_i32FractionPart2 *= -1;
        }
				
				 //
        // Print Pressure with three digits of decimal precision.
        //
        //sprintf(tempString,"Pressure %3d.%03d\t", BMP180_i32IntegerPart2, BMP180_i32FractionPart2);
				//CLI_Write(tempString);

        //
        // Calculate the altitude.
        //
        fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f,
                                            1.0f / 5.255f));

        //
        // Convert the altitude to an integer part and fraction part for easy
        // print.
        //
        BMP180_i32IntegerPart3 = (int32_t) fAltitude;
        BMP180_i32FractionPart3 =(int32_t) (fAltitude * 1000.0f);
        BMP180_i32FractionPart3 = BMP180_i32FractionPart3 - (BMP180_i32IntegerPart3 * 1000);
        if(BMP180_i32FractionPart3 < 0)
        {
            BMP180_i32FractionPart3 *= -1;
        }

        //
        // Print altitude with three digits of decimal precision.
        //
        //sprintf(tempString,"Altitude %3d.%03d", BMP180_i32IntegerPart3, BMP180_i32FractionPart3);
				//CLI_Write(tempString);

        //
        // Print new line.
        //
        //CLI_Write("\n\r");
				//sensorTurn=3;
				sensorTurn=(sensorTurn+1)%NumberOfSensor;
				TimerEnable(TIMER1_BASE, TIMER_A);
			}
}
//*****************************************************************************
//
// This example application demonstrates the use of a periodic timer to
// request DMA transfers.
//
// Timer0 is used as the periodic timer that requests DMA transfers.
// Timer1 is a free running counter that is used as the source data for
// DMA transfers.  The captured counter values from Timer1 are copied by
// uDMA into a buffer.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulIdx;
    unsigned long ulThisTimerVal;
    unsigned long ulPrevTimerVal;
    unsigned long ulTimerElapsed;
    unsigned long ulTimerErr;

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the UART and write status.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);
    UARTprintf("\033[2JuDMA periodic timer example\n\n");

    //
    // Enable the timers used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Enable the uDMA peripheral
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);

    //
    // Enable the uDMA controller error interrupt.  This interrupt will occur
    // if there is a bus error during a transfer.
    //
    ROM_IntEnable(INT_UDMAERR);

    //
    // Enable the uDMA controller.
    //
    ROM_uDMAEnable();

    //
    // Point at the control table to use for channel control structures.
    //
    ROM_uDMAControlBaseSet(ucControlTable);

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Configure one of the timers as free running 32-bit counter.  Its
    // value will be used as a time reference.
    //
    ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
    ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ~0);
    ROM_TimerEnable(TIMER1_BASE, TIMER_A);

    //
    // Configure the 32-bit periodic timer.
    //
    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, TIMEOUT_VAL - 1);

    //
    // Enable the timer master interrupt.  The timer interrupt will actually
    // be generated by the uDMA controller when the timer channel transfer is
    // complete.  The interrupts on the timer (TimerIntEnable) do not need
    // to be configured.
    //
    ROM_IntEnable(INT_TIMER0A);

    //
    // Put the attributes in a known state for the uDMA Timer0A channel.  These
    // should already be disabled by default.
    //
    ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_TMR0A,
                                    UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST |
                                    UDMA_ATTR_HIGH_PRIORITY |
                                    UDMA_ATTR_REQMASK);

    //
    // Set up the DMA channel for Timer 0A.  Set it up to transfer single
    // 32-bit words at a time.  The source is non-incrementing, the
    // destination is incrementing.
    //
    ROM_uDMAChannelControlSet(UDMA_CHANNEL_TMR0A | UDMA_PRI_SELECT,
                              UDMA_SIZE_32 |
                              UDMA_SRC_INC_NONE | UDMA_DST_INC_32 |
                              UDMA_ARB_1);

    //
    // Set up the transfer for Timer 0A DMA channel.  Basic mode is used,
    // which means that one transfer will occur per timer request (timeout).
    // The amount transferred per timeout is determined by the arbitration
    // size (see function above).  The source will be the value of free running
    // Timer1, and the destination is a memory buffer.  Thus, the value of the
    // free running Timer1 will be stored in a buffer every time the periodic
    // Timer0 times out.
    //
    ROM_uDMAChannelTransferSet(UDMA_CHANNEL_TMR0A | UDMA_PRI_SELECT,
                               UDMA_MODE_BASIC,
                               (void *)(TIMER1_BASE + TIMER_O_TAV),
                               g_ulTimerBuf, MAX_TIMER_EVENTS);

    //
    // Enable the timers and the DMA channel.
    //
    UARTprintf("Using timeout value of %u\n", TIMEOUT_VAL);
    UARTprintf("Starting timer and uDMA\n");
    TimerEnable(TIMER0_BASE, TIMER_A);
    uDMAChannelEnable(UDMA_CHANNEL_TMR0A);

    //
    // Wait for the transfer to complete.
    //
    UARTprintf("Waiting for transfers to complete\n");
    while(!g_bDoneFlag)
    {
    }

    //
    // Check for the expected number of occurrences of the interrupt handler,
    // and that there are no DMA errors
    //
    if(g_uluDMAErrCount != 0)
    {
        UARTprintf("\nuDMA errors were detected!!!\n\n");
    }
    if(g_ulTimer0AIntCount != 1)
    {
        UARTprintf("\nUnexpected number of interrupts occurrred (%d)!!!\n\n",
                   g_ulTimer0AIntCount);
    }

    //
    // Display the timer values that were transferred using timer triggered
    // uDMA.  Compare the difference between stored values to the timer
    // period and make sure they match.  This verifies that the periodic
    // DMA transfers were occuring with the correct timing.
    //
    UARTprintf("\n       Captured\n");
    UARTprintf("Event    Value    Difference  Status\n");
    UARTprintf("----- ----------  ----------  ------\n");
    for(ulIdx = 1; ulIdx < MAX_TIMER_EVENTS; ulIdx++)
    {
        //
        // Compute the difference between adjacent captured values, and then
        // compare that to the expected timeout period.
        //
        ulThisTimerVal = g_ulTimerBuf[ulIdx];
        ulPrevTimerVal = g_ulTimerBuf[ulIdx - 1];
        ulTimerElapsed = ulThisTimerVal > ulPrevTimerVal ?
                         ulThisTimerVal - ulPrevTimerVal :
                         ulPrevTimerVal - ulThisTimerVal;
        ulTimerErr = ulTimerElapsed > TIMEOUT_VAL ?
                     ulTimerElapsed - TIMEOUT_VAL :
                     TIMEOUT_VAL - ulTimerElapsed;

        //
        // Print the captured value and the difference from the previous
        //
        UARTprintf(" %2u   0x%08X  %8u   ", ulIdx, ulThisTimerVal,
                   ulTimerElapsed);

        //
        // Print error status based on the deviation from expected difference
        // between samples (calculated above).  Allow for a difference of up
        // to 1 cycle.  Any more than that is considered an error.
        //
        if(ulTimerErr >  1)
        {
            UARTprintf(" ERROR\n");
        }
        else
        {
            UARTprintf(" OK\n");
        }
    }

    //
    // End of application
    //
    while(1)
    {
    }
}
Example #28
0
//*****************************************************************************
//
// Configure Timer1B as a 16-bit PWM with a duty cycle of 66%.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // The Timer1 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // For this example CCP3 is used with port E pin 4.
    // The actual port and pins used may be different on your part, consult
    // the data sheet for more information.
    // GPIO port E needs to be enabled so these pins can be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    //
    // Configure the GPIO pin muxing for the Timer/CCP function.
    // This is only necessary if your part supports GPIO pin function muxing.
    // Study the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using
    //
    GPIOPinConfigure(GPIO_PE4_CCP3);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for Timer/PWM operation.
    //
    InitConsole();

    //
    // Configure the ccp settings for CCP pin.  This function also gives
    // control of these pins to the SSI hardware.  Consult the data sheet to
    // see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeTimer(GPIO_PORTE_BASE, GPIO_PIN_4);

    //
    // Display the example setup on the console.
    //
    UARTprintf("16-Bit Timer PWM ->");
    UARTprintf("\n   Timer = Timer1B");
    UARTprintf("\n   Mode = PWM");
    UARTprintf("\n   Duty Cycle = 66%%\n");
    UARTprintf("\nGenerating PWM on CCP3 (PE4) -> ");

    //
    // Configure Timer1B as a 16-bit periodic timer.
    //
    TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR |
                   TIMER_CFG_B_PWM);

    //
    // Set the Timer1B load value to 50000.  For this example a 66% duty
    // cycle PWM signal will be generated.  From the load value (i.e. 50000)
    // down to match value (set below) the signal will be high.  From the
    // match value to 0 the timer will be low.
    //
    TimerLoadSet(TIMER1_BASE, TIMER_B, 50000);

    //
    // Set the Timer1B match value to load value / 3.
    //
    TimerMatchSet(TIMER1_BASE, TIMER_B, TimerLoadGet(TIMER1_BASE, TIMER_B) / 3);

    //
    // Enable Timer1B.
    //
    TimerEnable(TIMER1_BASE, TIMER_B);

    //
    // Loop forever while the Timer1B PWM runs.
    //
    while(1)
    {
        //
        // Print out indication on the console that the program is running.
        //
        PrintRunningDots();
    }
}
Example #29
0
/*****************************************************
 * 	Function: main
 *	Description: Runs initialization of all modules
 *				and main state loop
 *	Input: NONE
 *	Output: NONE
 *****************************************************/
int main(void)
{
	init_Clock();				// Initialize clock
    init_LED();					// Initialize LEDs
    init_Zones();				// Initialize zones
    init_genTimer1();			// Initialize general timer 1
    init_BtnHandler();			// Initialize button interrupt handler
    init_Hibernation();			// Initialize hibernation module
    UART_SetupUART0();			// Initialize UART0
    I2C_SetupI2C3();			// Initialize I2C3
    init_IntTempSensor();		// Initialize internal temperature sensor
    AMS_InitSensor();			// Initialize analog moisture sensor

	// Enable master interrupts
	IntMasterEnable();

    //
    // Main loop
    //

	while(true)
	{
		switch(mode)
		{
			case RUN:
				statusLed = LED_GREEN_PIN;
				dateTime = DS1307_GetTime();			// Get the current time
				//HIH6130_UpdateData();					// Get HIH6130 Data
				checkZoneStatus();						// Check if status of each zone
				break;
			case OVERRIDE:
				statusLed = LED_RED_PIN;
				if(oneSecondCounter >= SECONDS_IN_24_HOURS)
				{
					// If 24 hours have passed, switch back to run mode
					clearAllZoneOverrides();
					oneSecondCounter = 0;
					mode = RUN;
				}
				else
				{
					setAllZoneOverrides();
				}
				break;
			case SYSTEM_SHUTDOWN:
				GPIOPinWrite(LED_REG, LED_RED_PIN, LED_ALL_OFF);				// Turn off all other leds
				GPIOPinWrite(LED_REG, LED_RED_PIN, LED_RED_PIN);				// Turn on red led to signal temperature shutdown
				int zoneNumber;
				for(zoneNumber=0; zoneNumber<NUMBER_OF_ZONES; zoneNumber++)		// Shutoff each zone
				{
					Zone* currentZone = Zones[zoneNumber];
					GPIOPinWrite(currentZone->Port, currentZone->Pin, currentZone->Pin);
				}
				IntMasterDisable();												// Disable all interrupts
				TimerEnable(BTN_OVERRIDE_TIM_BASE, TIMER_A);					// Turn off timer for button press
				TimerEnable(TIMER1_BASE, TIMER_A);								// Turn off general timer
				HibernateRequest();												// Go into hibernation until wake button is pressed
				break;
			default:

				break;
		}

		processZones();							// Process any changes to zones

	}


}
Example #30
0
// ******** OS_Init ************
// initialize operating system, disable interrupts until OS_Launch
// initialize OS controlled I/O: serial, ADC, systick, select switch and timer2 
// input:  none
// output: none
void OS_Init(void){
	DisableInterrupts();
	RUNPT=0;
	JitterInit();
	deleteme=0;

// Enable processor interrupts.
    //
    //IntMasterEnable();
	TIMELORD=0; //initialize the system counter for use with thingies (no shit)
	NUMBLOCKEDTHREADS=0;
	TOTALNUMTHREADS=0;
    SDEBOUNCEPREV = 0;
    btndown_time = 0;
    

	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);	//Init System Clock

	//Systick Init (Thread Scheduler)
	//taken care of in OS_Launch
     
	// Timers galore!
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(TIMER0_BASE, (TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC));
	//TimerControlTrigger(TIMER0_BASE, TIMER_A, false);  // TIMELORD Updater
	//TimerControlTrigger(TIMER0_BASE, TIMER_B, true);  // ADC_Collect Timer
	TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
	TimerEnable(TIMER0_BASE, TIMER_BOTH);
	IntEnable(INT_TIMER0A);
	  
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
	TimerControlTrigger(TIMER1_BASE, TIMER_A, true);  // Periodic Timer 1
	TimerControlTrigger(TIMER1_BASE, TIMER_B, true);  // Periodic Timer 2
	TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
	TimerIntEnable(TIMER1_BASE, TIMER_TIMB_TIMEOUT);
	  
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
	TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
	TimerControlTrigger(TIMER2_BASE, TIMER_A, true);  // Periodic Timer 3
	TimerControlTrigger(TIMER2_BASE, TIMER_B, true);  // Periodic Timer 4
	TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
	TimerIntEnable(TIMER2_BASE, TIMER_TIMB_TIMEOUT);
	
	// Init ADC Stuff
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS);  
	  
	// Init Debugging LED
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);

	//Semaphores, OS Stuff
    OS_InitSemaphore(&oled_free,1);
	OS_InitSemaphore(&OSMailBoxSema4,0);
	OS_MailBox_Init();
	
	//UART & OLED 
	UARTInit();
	RIT128x96x4Init(1000000); //Init OLED
	//RIT128x96x4StringDraw("Hello World", 0, 12, 15);
	
	//ADC
    ADC_Init(); // Init ADC to run @ 1KHz

	//Select Switch (button press) Init	(select switch is PF1) (pulled from page 67 of the book and modified for PF1...i think)
	//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  /*GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
  IntEnable(INT_GPIOF);  
  //IntPrioritySet(INT_GPIOF, 0x00);
  GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_BOTH_EDGES);
  GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1);*/
  //NVIC_EN0_R |= 0x40000000;     // (h) enable interrupt 2 in NVIC (Not sure what Stellarisware function replaces this)
  
  
  /* This works for now, but Stellarisware Function owuld be nice */
  SYSCTL_RCGC2_R |= 0x00000020; // (a) activate port F
//	delay = SYSCTL_RCGC2_R;		    //delay, cause i said so
	GPIO_PORTF_DIR_R &= ~0x02;    // (c) make PF1 in
	GPIO_PORTF_DEN_R |= 0x02;     //     enable digital I/O on PF1
	GPIO_PORTF_IS_R &= ~0x02;     // (d) PF1 is edge-sensitive
	GPIO_PORTF_IBE_R &= ~0x02;    //     PF1 is not both edges
	GPIO_PORTF_IEV_R &= ~0x02;    //     PF1 falling edge event
	GPIO_PORTF_ICR_R = 0x02;      // (e) clear flag4
	GPIO_PORTF_IM_R |= 0x02;      // (f) arm interrupt on PF1
	NVIC_PRI7_R = (NVIC_PRI7_R&0xFF00FFFF)|(0<<21); // (g) priority (shifted into place) (will get set in OS_AddButtonTask)
	NVIC_EN0_R |= 0x40000000;     // (h) enable interrupt 2 in NVIC
	//dont enable interrupts 
	GPIO_PORTF_PUR_R |= 0x02;	    //add pull up resistor, just for shits and giggles
  
/*	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);	  	// Enable GPIOF
  	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);	// make Pin 1 an Input
  	GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1);			//
*/

//TODO: i have no f*****g clue what to do here...

return;
}