Esempio n. 1
0
int main(void)
{
  Config32MHzClock(); // configure sysclk=32MHz RC oscillator, turn on 32KHz osc
  Config32KHzRTC();   // configure with 1 tick per second

  CLK.PSCTRL = 0x00;  // no division on peripheral clock

  // make clkout on PORTE:7
  PORTCFG.CLKEVOUT = PORTCFG_CLKOUT_PE7_gc;
  PORTE.DIR = (1<<7); // clkout

  // configure timer/counter0
  TCC0.CTRLA = 0x7;   // clk/1024

  // configure PORTF:0 as output to LED
  PORTF.DIR=(1<<0);

  // setup RTC counter params
  RTC.PER = 0;         // overflow after 1 second
  RTC.INTCTRL |= 0x3;  // set high level interrupt on RTC overflow
  RTC.CNT = 0;         // clear initial count

  PMIC.CTRL = PMIC_HILVLEN_bm; // enable high level interrupts
  sei(); // enable interrupts

  while(1); // forever

return 0;
};
Esempio n. 2
0
void DoOscillator(unsigned int osc)
{
  switch(osc)
  {
    case 0:
	  Config2MHzClock();
	  break;
    case 1:
	  Config32MHzClock();
	  break;
    case 2:
	  Config32KHzClock();
	  break;
    default:
	  Error("Unsupported Selectrion");
	  return;
  };
};
Esempio n. 3
0
/**
 * \brief Initializes all the subsystems for this Droplet. This function MUST be called
 * by the user before using any other functions in the API.
 */ 
static void initAllSystems(void){
	cli();
	Config32MHzClock();
	
	calculateIdNumber();
	
	schedulerInit();			INIT_DEBUG_PRINT("SCHEDULER INIT\r\n");
	pcCommInit();				INIT_DEBUG_PRINT("PC COM INIT\r\n");
	rgbLEDinit();				INIT_DEBUG_PRINT("LED INIT\r\n");
	powerInit();				INIT_DEBUG_PRINT("POWER INIT\r\n");
	i2cInit();					INIT_DEBUG_PRINT("I2C INIT\r\n");
	
	enableInterrupts();	
	
	rangeAlgsInit();			INIT_DEBUG_PRINT("RANGE ALGORITHMS INIT\r\n");
	rgbSensorInit();			INIT_DEBUG_PRINT("RGB SENSE INIT\r\n");
	irLedInit();				INIT_DEBUG_PRINT("IR LED INIT\r\n");
	irSensorInit();			INIT_DEBUG_PRINT("IR SENSE INIT\r\n");
	
	#ifdef AUDIO_DROPLET
		speakerInit();			INIT_DEBUG_PRINT("SPEAKER INIT\r\n");
		micInit();				INIT_DEBUG_PRINT("MIC INIT\r\n"); //Must occur after ir_sensor_init.
	#endif
		
	motorInit();				INIT_DEBUG_PRINT("MOTOR INIT\r\n");
	randomInit();				INIT_DEBUG_PRINT("RAND INIT\r\n"); //This uses adc readings for a random seed, and so requires that the adcs have been initialized.
	localizationInit();		INIT_DEBUG_PRINT("LOCALIZATION INIT\r\n"); 
	
	#ifdef SYNCHRONIZED
		fireflySyncInit();
	#endif

	setAllirPowers(256);
	startupLightSequence();
	
	irCommInit();				INIT_DEBUG_PRINT("IR COM INIT\r\n");
	#ifdef AUDIO_DROPLET
		enableMicInterrupt();
	#endif
}
Esempio n. 4
0
int main (void)
{
	Config32MHzClock();// Set Clock Speed to 32MHz	
	PORTE.DIRSET = _BV(0); // DEBUG: Set pin E0 as OUTPUT
	PORTE.OUTCLR = _BV(0);

	/* Timer for keeping track of milliseconds: 
	 * 
	 * The result of this triggers the interrupt once per millisecond.
	 */
	TCC0.PER = 4000;// Set HIGH to 4000 and LOW to 0
	TCC0.CTRLA = ( TCC0.CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_DIV1024_gc; // Work from CPUCLK/8
	TCC0.INTCTRLA = ( TCC0.INTCTRLA & ~TC0_OVFINTLVL_gm ) | TC_OVFINTLVL_HI_gc; // Enable overflow interrupt.--
	// Enable low interrupt level in PMIC and enable global interrupts.
	PMIC.CTRL |= PMIC_HILVLEN_bm;
	sei();
	
	
	while(1){
		if(millis()>1){
			PORTE.OUTSET = _BV(0);
		}
	}
}
Esempio n. 5
0
int main(void)
{
	int data;
	int index=0;
	char buffer[100];
	Config32MHzClock();

	CLK.PSCTRL = 0x00; // no division on peripheral clock

	UsartInit();
	
	UsartWriteString("\r\n\r\nBOOT: Starting...\r\n");

	//Analog Mux
	PORTF.DIR = 0b11111111; //Output

	PORTF.OUTCLR = PIN6_bm;
	PORTF.OUTCLR = PIN4_bm | PIN7_bm;
	PORTF.OUTSET = PIN5_bm;

	PORTF.OUTCLR = PIN0_bm | PIN1_bm | PIN2_bm | PIN3_bm;
	//PORTF.OUTSET = PIN1_bm;

	PORTF.OUTCLR = PIN6_bm;
	PORTF.OUTSET = PIN4_bm;
	PORTF.OUTCLR = PIN5_bm;
	PORTF.OUTSET = PIN7_bm; //WR

	UsartWriteString("BOOT: Analog Mux configured...\r\n");

	//ADC
	PORTQ.DIR = 0b1111; //Output
	PORTQ.OUTCLR = PIN1_bm | PIN3_bm; //PWRDWN pins

	PORTQ.OUTSET = PIN0_bm | PIN2_bm; //ENCODE pins

	//Reading Values
	PORTD.DIR = 0b00000000; //Input
	PORTE.DIR = 0b00000000; //Input

	UsartWriteString("BOOT: ADC configured...\r\n");

	//TFT LCD
	TFT_init();

	Delay100ms(10);
	Delay100ms(10);
	Delay100ms(10);
	Delay100ms(10);
	Delay100ms(10);
	
	TSLCDFillRect(0,TS_SIZE_X-1,0,TS_SIZE_Y-1,TS_COL_BLUE,TS_MODE_NORMAL);
	/*
	TSLCDFillRect(0,TS_SIZE_X-1,0,70,TS_COL_WHITE,TS_MODE_NORMAL);
	TSLCDSetFontColor(TS_COL_BLUE);
	TSLCDPrintStr(2,6,"Testing ELT240320TP with AVR",TS_MODE_NORMAL);
	TSLCDFillRect(20,80,90,130,TS_COL_BLACK,TS_MODE_NORMAL);
	TSLCDFillRect(30,90,100,140,TS_COL_YELLOW,TS_MODE_NORMAL);
	TSLCDFillRect(20,80,160,200,TS_COL_BLACK,TS_MODE_NORMAL);
	TSLCDFillRect(30,90,170,210,TS_COL_RED,TS_MODE_NORMAL);
	TSLCDFillRect(195,205,71,TS_SIZE_Y-1,TS_COL_WHITE,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,60,TS_COL_WHITE,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,50,TS_COL_BLUE,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,40,TS_COL_BLACK,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,30,TS_COL_RED,TS_MODE_NORMAL);
	*/
	
	UsartWriteString("BOOT: TFT LCD configured...\r\n");

	//Timing Lines

	//INT0: breakoutbar6 / A0 / frame
	//INT1: slicebin0 / A1 / pixel
	PORTA.INTCTRL = (PORTA.INTCTRL & ~PORT_INT0LVL_gm ) | PORT_INT0LVL_LO_gc; 
	PORTA.INTCTRL = (PORTA.INTCTRL & ~PORT_INT1LVL_gm ) | PORT_INT1LVL_LO_gc;

	//Detect rising edge only
	PORTA.PIN0CTRL |= 0x01;
	PORTA.PIN0CTRL &= ~0x06;
	PORTA.PIN1CTRL |= 0x01;
	PORTA.PIN1CTRL &= ~0x06;

    PORTA.INT0MASK = PIN0_bm;
	PORTA.INT1MASK = PIN1_bm;
	
	UsartWriteString("BOOT: Interrupts configured...\r\n");
	
	//EBI/SDRAM
	ebi_setup_port(12, 0, 0, EBI_PORT_3PORT | EBI_PORT_SDRAM);
	/*
	 * Configure the EBI chip select for an 8 MB SDRAM located at
	 * \ref BOARD_EBI_SDRAM_BASE.
	 */
	ebi_cs_set_mode(&cs_config, EBI_CS_MODE_SDRAM_gc);
	ebi_cs_set_address_size(&cs_config, EBI_CS_ASPACE_8MB_gc);
	ebi_cs_set_base_address(&cs_config, BOARD_EBI_SDRAM_BASE);

	/* Configure the EBI chip select to be in SDRAM mode. */
	ebi_sdram_set_mode(&cs_config, EBI_CS_SDMODE_NORMAL_gc);

	/* Setup the number of SDRAM rows and columns. */
	ebi_sdram_set_row_bits(&sdram_config, 12);
	ebi_sdram_set_col_bits(&sdram_config, 10);

	/* Further, setup the SDRAM timing. */
	ebi_sdram_set_cas_latency(&sdram_config, 3);
	ebi_sdram_set_mode_delay(&sdram_config, EBI_MRDLY_2CLK_gc);
	ebi_sdram_set_row_cycle_delay(&sdram_config, EBI_ROWCYCDLY_7CLK_gc);
	ebi_sdram_set_row_to_precharge_delay(&sdram_config, EBI_RPDLY_7CLK_gc);
	ebi_sdram_set_write_recovery_delay(&sdram_config, EBI_WRDLY_1CLK_gc);
	ebi_sdram_set_self_refresh_to_active_delay(&sdram_config,
			EBI_ESRDLY_7CLK_gc);
	ebi_sdram_set_row_to_col_delay(&sdram_config, EBI_ROWCOLDLY_7CLK_gc);
	ebi_sdram_set_refresh_period(&sdram_config, BOARD_EBI_SDRAM_REFRESH);
	ebi_sdram_set_initialization_delay(&sdram_config,
			BOARD_EBI_SDRAM_INITDLY);

	/* Write SDRAM configuration into the EBI registers. */
	ebi_sdram_write_config(&sdram_config);
	/* Write the chip select configuration into the EBI registers. */
	ebi_cs_write_config(EBI_SDRAM_CS, &cs_config);

	ebi_enable_cs(EBI_SDRAM_CS, &cs_config);
	
	UsartWriteString("BOOT: SDRAM configured...\r\n");
	
	do {
		// Wait for SDRAM to initialize.
	} while (!ebi_sdram_is_ready());
	
	UsartWriteString("BOOT: SDRAM ready...\r\n");
	
	status_code_t retval = ebi_test_data_bus((hugemem_ptr_t)BOARD_EBI_SDRAM_BASE);
	if (retval == STATUS_OK) {
		UsartWriteString("BOOT: SDRAM data bus test completed...\r\n");
	} else {
		UsartWriteString("BOOT: WARNING: SDRAM data bus test failed...\r\n");
	}
	
	retval = ebi_test_addr_bus((hugemem_ptr_t)BOARD_EBI_SDRAM_BASE,BOARD_EBI_SDRAM_SIZE);
	if (retval == STATUS_OK) {
		UsartWriteString("BOOT: SDRAM address bus test completed...\r\n");
	} else {
		UsartWriteString("BOOT: WARNING: SDRAM address bus test failed...\r\n");
	}

	//_delay_ms(1);
	
	//SD Card testing
	UsartWriteString("BOOT: SD Card testing...\r\n");
	//_delay_ms(1);
	
	FRESULT f_err_code;
	static FATFS FATFS_Obj;

	UsartWriteString("BOOT: SD Card: initializing disk...\r\n");
	disk_initialize(0);

	UsartWriteString("BOOT: SD Card: mounting disk...\r\n");
	f_err_code = f_mount(0, &FATFS_Obj);

	if (f_err_code == FR_OK) {
	
		FIL fil_obj;
		int test_number = 5;

		UsartWriteString("BOOT: SD Card: opening file...\r\n");
		f_open(&fil_obj, "asplfc.txt", FA_WRITE);
		UsartWriteString("BOOT: SD Card: writing file...\r\n");
		int out = f_printf(&fil_obj, "moo %d", test_number);
		UsartWriteString("BOOT: SD Card: closing file...\r\n");
		f_close(&fil_obj);

	} else {
		UsartWriteLine("BOOT: WARNING: No SD card found...");
	}

	//PORTQ.OUTCLR = PIN2_bm | PIN4_bm;

	UsartWriteString("\n\rASP LFC firmware -- v0.1\r\n");
	UsartWriteString("> ");
	while(1)
	{
		data=UsartReadChar(); // read char
		// check for carriage return and try to match/execute command
		if((data == '\r')||(index==sizeof(buffer)))
		{
			//PORTF.OUT ^= (1<<0);      // switch LED
			buffer[index]=0;          // null terminate
			index=0;                  // reset buffer index
			UsartWriteString("\n\r"); // echo newline
			ParseCommand(buffer);     // attempt to parse command
			  UsartWriteString("> ");
		}
		else if(data==8)              // backspace character
		{
			if(index>0)
				index--;                  // backup one character
			UsartWriteChar(data);
		}
		else
		{
			buffer[index++]=data;
			UsartWriteChar(data);
		};

		//	UsartWriteChar(data); // write char
		//	_delay_ms(100);
		//	PORTF.OUT ^= (1<<0); // toggle LED

	};
};
Esempio n. 6
0
int main(void) {    
    
    Config32MHzClock(); // Setup the 32MHz Clock. Should really be using 2MHz...
    
    // Setup output and input ports.
    LEDPORT.DIRSET = 0xFF; 
    LEDPORT.OUT = 0xFF;
    AD9835_PORT.DIRCLR = 0x40;
    PORTC.DIRSET = 0x04;

    // Start up the timer.
    init_timer();
    
    sensors.begin();
    sensors.requestTemperatures();
    
    // Wait a bit before starting the AD9835.
    // It seems to take a few hundred ms to 'boot up' once power is applied.
    _delay_ms(500); 
    
    // Configure the AD9835, and start in sleep mode.
    AD9835_Setup();
    AD9835_Sleep();
    
    // Setup the AD9835 for our chosen datamode.
    TX_Setup();
    AD9835_Awake();
    
    // Broadcast a bit of carrier.
    _delay_ms(1000);
    
    TXString("Booting up...\n"); // Kind of like debug lines.
    
    // Start up the GPS RX UART.
    init_gps();
    
    // Turn Interrupts on.
    PMIC.CTRL = PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm;
    sei();
    
    sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data.
    
    //TXString("GPS Active, Interrupts On.\n");
    
    int found_sensors = sensors.getDeviceCount();
    
    //sprintf(tx_buffer,"Found %u sensors.\n",found_sensors);
   // TXString(tx_buffer);
    unsigned int counter = 0; // Init out TX counter.
    
 
    while(1){
        // Identify every few minutes
        if ((counter%30 == 0)&&(data_mode != FALLBACK)) TXString("DE VK5VZI Project Horus HAB Launch - projecthorus.org \n");
    
	    // Read ADC PortA pin 0, using differential, signed input mode. Negative input comes from pin 1, which is tied to ground. Use VCC/1.6 as ref.
	    uint16_t temp = readADC(); 
	    float bat_voltage = (float)temp * 0.001007572056668* 8.5;
        floatToString(bat_voltage,1,voltString);
   
    
    
        // Collect GPS data
        
        gps.f_get_position(&lat, &lon);
	    sats = gps.sats();
	    if(sats>2){LEDPORT.OUTCLR = 0x80;}
	    speed = gps.f_speed_kmph();
	    altitude = (long)gps.f_altitude();
	    gps.crack_datetime(0, 0, 0, &time[0], &time[1], &time[2]);
	    
	    floatToString(lat, 5, latString);
	    floatToString(lon, 5, longString);
	    
        sensors.requestTemperatures();
        _intTemp = sensors.getTempC(internal);
        _extTemp = sensors.getTempC(external);
        if (_intTemp!=85 && _intTemp!=127 && _intTemp!=-127 && _intTemp!=999) intTemp = _intTemp;
        if (_extTemp!=85 && _extTemp!=127 && _extTemp!=-127 && _extTemp!=999) extTemp = _extTemp;
	    
	    if(data_mode != FALLBACK){
	    
            // Construct our Data String
            sprintf(tx_buffer,"$$DARKSIDE,%u,%02d:%02d:%02d,%s,%s,%ld,%d,%d,%d,%d,%s",counter++,time[0], time[1], time[2],latString,longString,altitude,speed,sats,intTemp,extTemp,voltString);
            
            
            // Calculate the CRC-16 Checksum
            char checksum[10];
            snprintf(checksum, sizeof(checksum), "*%04X\n", gps_CRC16_checksum(tx_buffer));
         
            // And copy the checksum onto the end of the string.
            memcpy(tx_buffer + strlen(tx_buffer), checksum, strlen(checksum) + 1);
        }else{
            // If our battery is really low, we don't want to transmit much data, so limit what we TX to just an identifier, battery voltage, and our position.
            
            sprintf(tx_buffer, "DE VK5VZI HORUS8 %s %s %s %ld", bat_voltage, latString, longString,altitude);
        }
        
        // Blinky blinky...
        LEDPORT.OUTTGL = 0x20;
        
        // Transmit!
        TXString(tx_buffer);
       
        
        sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data again.
        
        /*
        // Check the battery voltage. If low, switch to a more reliable mode.
        if((bat_voltage < BATT_THRESHOLD) && (data_mode != RELIABLE_MODE)){
            new_mode = RELIABLE_MODE;
            // This string should be changed if the 'reliable' mode is changed.
            TXString("Battery Voltage Below 9V. Switching to DominoEX8.\n");
        }
        */
        // Perform a mode switch, if required. 
        // Done here to allow for mode changes to occur elsewhere.
        if(new_mode != -1){
            data_mode = new_mode;
            TX_Setup();
            new_mode = -1;
        }
        
        // And wait a little while before sending the next string.
        // Don't delay for domino - synch stuffs up otherwise
        if(data_mode != DOMINOEX8){
            _delay_ms(1000);
        }
        
        
    }

    
}
Esempio n. 7
0
/* See Atmel doc8050.pdf : AVR1313: Using the XMEGA IO Pins and External Interrupts
 * 
 * 
 */
void init(void){
		Config32MHzClock(); //Set Clock Speed to 32MHz	
		PORTD.PIN4CTRL = PORT_OPC_PULLUP_gc; //Set pin D4 as INPUT and as a pullup (Detect when pulled LOW)
		PORTE.DIRSET |= _BV(0); //Set pin E0 as OUTPUT
        uart_init(); 
}