Exemplo n.º 1
0
bool InitDisarmFSM ( uint8_t Priority )
{
  ES_Event ThisEvent;
	
	PortFunctionInit(); //initialize pins PA2-5, PB2-3, PD7, PF0 as GPIO
	initTapeSensors();  //initialize tape sensor
	initPhototransistor(); //initialize phototransisor
	initMotors();				//initialize motors
	initializeServos(); //initialize servo motors
	LEDShiftRegInit();  //initialize LED shift register
	LCDInit();					//initialize LCD display
	InitAdafruitAudioPortLines();	//initialize audio 
	initArmedLine();
	
  MyPriority = Priority;
  CurrentState = Armed;
  ThisEvent.EventType = ES_INIT;
  if (ES_PostToService( MyPriority, ThisEvent) == true)
  {
      return true;
  }else
	// if initialization failed
  {
      return false;
  }
}
Exemplo n.º 2
0
void PlatformInit()
{
	PortFunctionInit();
	//configure SW pins pull-ups
	MAP_GPIOPadConfigSet(SW_BASE, (SW1|SW2), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);



}
Exemplo n.º 3
0
//*****************************************************************************
// Main 'C' Language entry point.
//*****************************************************************************
int main(void)
{

	//
    // Setup the system clock to run at 50 Mhz from PLL with crystal reference
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
                    SYSCTL_OSC_MAIN);

    //Initialize
    PortFunctionInit();
	SPI_Init();
	POV_Init(&currentLine);

	//SD card startup
    iFResult = f_mount(0, &g_sFatFs);
    if(iFResult != FR_OK) while(1);

    iFResult = f_open(&g_sFileObject,"LED.dat", FA_READ);
    if(iFResult != FR_OK) while(1);

    numData = SD_Read_Header();



	/*RPM Timer*/
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT_UP );

    rpmPeriod = SysCtlClockGet();
    TimerLoadSet(TIMER0_BASE, TIMER_A, rpmPeriod -1);

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


	/*Display timer*/
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
    TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

    displayPeriod = (SysCtlClockGet()/2);
    TimerLoadSet(TIMER1_BASE, TIMER_A, displayPeriod -1);

    IntEnable(INT_TIMER1A);
    TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);


    IntMasterEnable();

    //TimerEnable(TIMER0_BASE, TIMER_A);
    TimerEnable(TIMER1_BASE, TIMER_A);

    //Do nothing, timers handle all interaction from here on
	while(1){

	}
}
int main(void)
{
	
		//initialize the GPIO ports	
		PortFunctionInit();
	
	  // turn LED D1 on at the beginning
	  GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x02);
	
	  bool button_first_time_pressed = false;
	  bool button_pressed = false;
	
		float delay = 16000000/3/4;        // half a second delay
	
		int turn_led_on = 1;
	
    //
    // Loop forever.
    //
    while(1)
    {
			if(GPIOPinRead(GPIO_PORTJ_AHB_BASE, GPIO_PIN_1)==0x00)	//SW2 is pressed
			{
					button_first_time_pressed = true;
				  button_pressed = true;
			}
			else
			{
					button_pressed = false;
			}
			// after button is pressed for the first time
			if(button_first_time_pressed)
			{
					if(button_pressed)
					{
							GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x00);  // turn off D1
							SysCtlDelay(delay);      // half a second delay
							turn_led_on = 1 - turn_led_on;           // toggle between 0 and 1
							if (turn_led_on)
									GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x01);  // turn on D2
							else
									GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x00);  // turn off D2
					}
					else    // toggle LED D1
					{					
              GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x00);  // turn off D2
						  SysCtlDelay(delay);      // half a second delay
							turn_led_on = 1 - turn_led_on;           // toggle between 0 and 1
							if (turn_led_on)
									GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x02);  // turn on D1
							else
									GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x00);  // turn off D1
					}
			}
    }
}
Exemplo n.º 5
0
int main(void) {
	PortFunctionInit();
	TERMIO_Init();
	clrScrn();
	
	// When doing testing, it is useful to announce just which program
	// is running.
	puts("\rStarting Test Harness for \r");
	printf("the 2nd Generation Events & Services Framework V2.2\r\n");
	printf("%s %s\n",__TIME__, __DATE__);
	printf("\n\r\n");
	printf("Press any key to post key-stroke events to Service 0\n\r");
	printf("Press 'd' to test event deferral \n\r");
	printf("Press 'r' to test event recall \n\n\r");
	

}
int main(void)
{
	
		//initialize the GPIO ports	
		PortFunctionInit();
		
	//configure the GPIOF interrupt
		Interrupt_Init();
	
    //
    // Loop forever.
    //
    while(1)
    {

    }
}
Exemplo n.º 7
0
int main(void) {  
	// Set the clock to run at 40MhZ using the PLL and 16MHz external crystal
	SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
			| SYSCTL_XTAL_16MHZ);
	TERMIO_Init();
	clrScrn();

	ES_Return_t ErrorType;

	// When doing testing, it is useful to announce just which program
	// is running.
	puts("\rStarting Test Harness for \r");
	printf("ME218D final Gridlinq code\r\n");
	printf("%s %s\n",__TIME__, __DATE__);
	printf("\n\r\n");

	// Your hardware initialization function calls go here
    PortFunctionInit();
        
	// now initialize the Events and Services Framework and start it running
	ErrorType = ES_Initialize(ES_Timer_RATE_1mS);
	if ( ErrorType == Success ) {

	  ErrorType = ES_Run();

	}
	//if we got to here, there was an error
	switch (ErrorType){
	  case FailedPost:
	    printf("Failed on attempt to Post\n");
	    break;
	  case FailedPointer:
	    printf("Failed on NULL pointer\n");
	    break;
	  case FailedInit:
	    printf("Failed Initialization\n");
	    break;
	 default:
	    printf("Other Failure\n");
	    break;
	}
	for(;;)
	  ;

}
Exemplo n.º 8
0
int main(void)
{
	PortFunctionInit();
	TERMIO_Init();
	puts("\r\n In test harness for LEDControl: All LEDs should be flashing, except for pin 31 which is flashing and pin 30 which is on (0)\r\n");
	InitLEDControl(1);

	// setLED(LED_ALL, OFF);

	/*char input = getchar();
	
	while (input != '0') {
		
		//setLED(LED_ALL,ON);
		//setLED(LED_SD_BLUE,OFF);
		setLED(LED_ALL, ON);

		setLED(LED_SACRAMENTO_RED, ON);
		setLED(LED_SACRAMENTO_BLUE, OFF);

		//setLED(LED_LA_RED, ON);
		printf("Blue Off\r\n");
		input = getchar();
		setLED(LED_SACRAMENTO_RED,OFF);
		setLED(LED_SACRAMENTO_BLUE, ON);
		//setLED(LED_LA_RED, OFF);
		printf("Blue On\r\n");
		*/
		/*
		if (input >= 'a' && input <='z') {
			setLED(LED_ALL_INDIV, OFF);
			setLED(LED_ALL_CITIES, CITY_OFF);
			setLED(BIT0HI << (input - 'a'), ON);
			printf("Shift Register value: %u\r\n",LED_SR_GetCurrentRegister());
		}
		input = getchar();
		}
		*/
		setLED(LED_ALL_INDIV, OFF);
		setLED(LED_ALL_CITIES_RED, CITY_OFF);
		setLED(LED_ALL_CITIES_BLUE, CITY_ON);
	
	
	return 0;
}
Exemplo n.º 9
0
//*****************************************************************************
//
// main() -- Execution Starts Here
//
//*****************************************************************************
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.
    ROM_FPULazyStackingEnable ();

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

    // Initialize the I/O Ports (pins)
    PortFunctionInit();

    // Initialize the UART.
    UART_Configure();

    // Initialize the I2C3 port as a slave to the cRIO
    Slave_Configure();

    // Initialize the I2C1 port as master to Gyro
    Gyro_Configure();

    // Say Hello on debug port
    UARTprintf("\nReady.\n");

    int16_t     i16Data = 0;               // holds data read from a gyro register
    uint8_t     ui8Status = 0;             // holds data read from gyro status register
    uint32_t    ui32Iteration = 0;         // iterations counter used to average first N samples
    float       fAvgDrift = 0.0;           // average of 1st N samples, used as an offset to subtract
    int16_t     i16MaxDrift = 0.0;
    int16_t     i16MinDrift = 0.0;
    float       fRate = 0.0;               // rate of change in Z in degs/sec
    float       fAngleDegrees = 0.0;       // running Z orientation in degrees
    uint16_t    ui16AngleScaled = 0.0;     // running Z orientation scaled to LSB = 0.01 degrees (i.e. value = degrees * 100)

    // Configure the L3G4200D Gyro chip
    Gyro_RegWrite(GYRO_CTRL_REG5, 0x80);     //BOOT:1 (reboot memory)
    SysCtlDelay(SysCtlClockGet() / 200);     //delay ~1/200 sec
    Gyro_RegWrite(GYRO_CTRL_REG1, 0x0C);     //DR:00 (100 Hz) PD:1 (enabled) XYZen:100 (Z only enabled)
    SysCtlDelay(SysCtlClockGet() / 200);     //delay ~1/200 sec
    Gyro_RegWrite(GYRO_CTRL_REG4, 0x10);     //FS:01 (500dps)
    SysCtlDelay(SysCtlClockGet() / 200);     //delay ~1/200 sec
    Gyro_RegWrite(GYRO_CTRL_REG5, 0x42);     //FIFO_EN:1 (enable FIFO) OUT_SEL:10 (LPF1+LPF2)
    SysCtlDelay(SysCtlClockGet() / 200);     //delay ~1/200 sec
    Gyro_RegWrite(GYRO_FIFO_CTRL_REG, 0x4F); //FM:010 (Stream Mode), WTM:01111
    SysCtlDelay(SysCtlClockGet() / 200);     //delay ~1/200 sec


    //Main Gyro processing loop
    while (1)
    {
        ui8Status = Gyro_RegRead(GYRO_FIFO_SRC_REG);
        //UARTprintf("FIFO_SRC_REG: 0x%x\n", ui8Status);

        // if Gyro's FIFO is not empty
        if (!(ui8Status & 0x20))
        {
            //report the depth of FIFO:
            //if (DEBUG_MODE) UARTprintf("N:0x%02x : ", ui8Status & 0x1F);

            // Read X,Y, and Z values.
            // NOTE: Found that the FIFo does not empty unless all 3 are read
            // TODO: Create a Gyro_RegRead6() to read all 3 values at once
            // Cast from unsigned16 to signed16
            i16Data = (int16_t) Gyro_RegRead2(GYRO_OUT_X_L);  // read and throw away value
            i16Data = (int16_t) Gyro_RegRead2(GYRO_OUT_Y_L);  // read and throw away value
            i16Data = (int16_t) Gyro_RegRead2(GYRO_OUT_Z_L);  // read and keep value

            //Average the first 100 iterations
            if (ui32Iteration < 500)
            {

                //Note min/max
                if (i16Data < i16MinDrift) i16MinDrift = i16Data;
                if (i16Data > i16MaxDrift) i16MaxDrift = i16Data;

                // compute the running average by taking (average * iteration), which is the sum of all prior iterations,
                // adding this iteration's value, and dividing by (iteration+1).
                fAvgDrift = ( (fAvgDrift * (float)ui32Iteration) + (float)i16Data ) / (float)(ui32Iteration + 1);
                ui32Iteration++;

                if (DEBUG_MODE)
                {
                    UARTprintf("Z: %d :", i16Data);
                    UARTprintf("A: %d :", (int16_t)(fAvgDrift * 100.0));
                    UARTprintf("m: %d :", i16MinDrift);
                    UARTprintf("M: %d\n", i16MaxDrift);
                }
            }
            else
            {
                //remove static drift
                fRate = (float)i16Data - fAvgDrift;

                //threshold filter (ignore samples below a threshold)
                if ( (-THRESHOLD_FILTER < fRate) && (fRate < THRESHOLD_FILTER) )
                {
                    fRate = 0.0;
                }

                // Convert rate to ( degrees / sec), scale by 1/SAMPLE_RATE_HZ, and sum into degrees
                fAngleDegrees += (fRate * GYRO_GAIN / SAMPLE_RATE_HZ) / 2.0;

                // wrap angle to be between 0 and 360
                //TODO: is there a better way to do this??
                while (fAngleDegrees < 0.0) fAngleDegrees += 360.0;
                while (fAngleDegrees >= 360.0) fAngleDegrees -= 360.0;

                // scale value to LSB = 0.01 degrees (i.e. value = degrees * 100)
                ui16AngleScaled = (uint16_t)(fAngleDegrees * 100.0);

                // send scaled value out slave i2c port
                Slave_SetLatestValue( ui16AngleScaled );

                if (DEBUG_MODE)
                {
                    UARTprintf("Z: %d : ", ui16AngleScaled);
                    UARTprintf("D: %d\n", (int16_t)(fAvgDrift * 100.0));
                }

            }

            LED_DoBlink();
        }
    }

}
Exemplo n.º 10
0
int main(void) {
	unsigned long ulPeriod = 0;				//Period for Timer0

	//Enable all required peripherals
	PortFunctionInit();

	//Enable console communication with UART
	UARTStdioInit(0);

	//Set system clock to 40 MHz
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

	/*
	 *
	 * Timer Configuration
	 *
	 */

		//Configure timer to be periodic (counts down and then resets)
		TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

		//Calculate period for a pin toggle freq of 1MHz with 50% duty cycle
		ulPeriod = (SysCtlClockGet() / 10) / 2;
		TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod - 1);

	/*
	 *
	 * ADC0 Configuration
	 *
	 */

		//Set the ADC sample rate to 500 KSPS
		SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);

		//Disable ADC0 sequencer 3 (so that we can configure it)
		ADCSequenceDisable(ADC0_BASE, 3);
		//Disable ADC1 sequencer 3 (so that we can configure it)
		ADCSequenceDisable(ADC1_BASE, 3);

		//Configure ADC0 sequencer 3 to trigger based on TIMER0A
		ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
		//Configure ADC1 sequencer 3 to trigger based on TIMER0A
		ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_TIMER, 0);

		//Configure the ADC0 to flag the interrupt flag when it finishes sampling
		ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0|ADC_CTL_END|ADC_CTL_IE);
		//Configure the ADC1 to flag the interrupt flag when it finishes sampling
		ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_CH1|ADC_CTL_END|ADC_CTL_IE);

		//Enable ADC0 sequencer 3
		ADCSequenceEnable(ADC0_BASE, 3);
		//Enable ADC1 sequencer 3
		ADCSequenceEnable(ADC1_BASE, 3);

		//Enable ADC0 interrupt, it's redundant with line 80 but has to be done
		ADCIntEnable(ADC0_BASE, 3);
		//Enable ADC1 interrupt, it's redundant with line 89 but has to be done
		ADCIntEnable(ADC1_BASE, 3);

		//Enable timer
		TimerEnable(TIMER0_BASE, TIMER_A);

		//Configure TIMER0A to be the ADC sample trigger
		TimerControlTrigger(TIMER0_BASE, TIMER_A, true);

		//Clear any interrupts
		ADCIntClear(ADC0_BASE, 3);
		ADCIntClear(ADC1_BASE, 3);

		//Begin sampling
		ADCIntEnable(ADC0_BASE, 3);
		ADCIntEnable(ADC1_BASE, 3);

		//Turn on ADC0 sequence interrupts for sequence 3
		IntEnable(INT_ADC0SS3);
		//Turn on ADC1 sequence interrupts for sequence 3
		IntEnable(INT_ADC1SS3);

		UARTprintf("ADC0 Configured\n");
		UARTprintf("ADC1 Configured\n");

		//Enable all interrupts
		IntMasterEnable();

	while(1) {

	}

}
Exemplo n.º 11
0
/*
 * main.c
 */
int main(void) {

    volatile uint32_t ui32Loop;

    uint32_t id = 3;

	PortFunctionInit();
	INEEDMD_ADC_Start_Low();
	//power on ADC, disable continuous conversions
	INEEDMD_ADC_Power_On();
	//turn off continuous conversion for register read/writes
	INEEDMD_ADC_Stop_Continuous_Conv();

	id = INEEDMD_ADC_Get_ID();

	INEEDMD_ADC_Start_Internal_Reference();
	INEEDMD_ADC_Enable_Lead_Detect();
	uint32_t val2 = INEEDMD_ADC_Check_RLD_Lead();
	wait_time(1);

	//TODO: setup a continuous data read using interrupt
	//use INEEDMD_ADC_Get_Conversion to store reading into global variable
	INEEDMD_ADC_Register_Write(CH8SET, PD1);
	//start conversions
	INEEDMD_ADC_Start_High();
	char result[INEEDMD_ADC_DATA_SIZE];

	while(1)
	{
		//single shot data read

		//wait for conversion to be ready
		while(GPIOPinRead(GPIO_PORTA_BASE, INEEDMD_PORTA_ADC_INTERUPT_PIN))
		{
		}

		//request data
		INEEDMD_ADC_Request_Data();

		//read result

		INEEDMD_ADC_Receive_Data(result);
		uint32_t lead;

		lead = INEEDMD_ADC_Check_Lead_Off();
	}
	/*
	INEEDMD_ADC_Start_Continuous_Conv();

	while(1)
	{
		//single shot data read

		//wait for conversion to be ready
		while(GPIOPinRead(GPIO_PORTA_BASE, INEEDMD_PORTA_ADC_INTERUPT_PIN))
		{
		}
		//read result

		INEEDMD_ADC_Receive_Data(result);
		uint32_t lead;

		lead = INEEDMD_ADC_Check_Lead_Off();
	}
	 */
	return(0);
}