Files @ 6ab6b1fe2314
Branch filter:

Location: seniordesign-firmware/slave/slave/lib/inputOutput.c - annotation

ethanzonca@CL-ENS241-08.cedarville.edu
Added InfoText logger for generic informational messages, GPS fix light now reports 3d location fixes, log is made when fix is acquired/lost. Added maximum retransmission limit.
/*
 * io.c
 *
 * Created: 11/7/2012 7:17:52 PM
 *  Author: kripperger
 */ 

#include <avr/io.h>
#include "../config.h"
#include "inputOutput.h"
#include "led.h"
#include "sensors.h"

int8_t	moduleID;	// Slave Module ID from rotary dip switch (or EEPROM)

 void io_configure()
 {
	// Configure ports/pins
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK to operate)
	
	DDRC &= ~(1 << DDC2);		// Set PC2 to input for rotary dip    //TEMPORARY//
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip    //TEMPORARY//
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip    //TEMPORARY//
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip    //TEMPORARY//
	
	
	DDRA &= ~(1 << DDA7);		// Set PA7 to input for battery voltage divider

	ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);	// Set prescaler for ADC, 128 gives ADC freq of 125 KHz
	ADMUX |= (1 << REFS0);									// Set ADC reference voltage to AVCC
	ADMUX |= (1 << ADLAR);									// Sets 10 bit ADC to 8 bit
	ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0);		// Select ADC7 as the conversion channel
	ADCSRA |= (1 << ADATE);									// Enables auto trigger, determined in ADCSRB bits ADTS
	//ADCSRA |= (1 << ADIF);									// 
//ADCSRA |= (1 << ADIE);									// ADC interrupt enable set
	ADCSRB &= ~(1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0);	// Set ADC auto trigger source to free running mode
	ADCSRA |= (1 << ADEN);									// Enable ADC
	ADCSRA |= (1 << ADSC);									// Start ADC measurements.  ADC should now continuously run conversions, which are stored in ADCH 0x79
	

 }
 
 

   
 
 
 void io_readModuleId()
 {
	// Get ID from rotary dip and return it. 
	moduleID = 0;
	
	// This method is temporary as the next release will read the module ID from EEPROM
	PORTC |= (1 << PC2);	// Pull pins on rotary dip high
	PORTC |= (1 << PC3);	// Pull pins on rotary dip high
	PORTC |= (1 << PC4);	// Pull pins on rotary dip high
	PORTC |= (1 << PC5);	// Pull pins on rotary dip high
	
	moduleID = ((PINC & 0b00011100) >> 2);		// Read Dip Encoder
	moduleID = ~moduleID;						//Invert Dip reading
	moduleID = (moduleID & 0b0111);				//Mask bits


/*
	while(moduleID==0)
	{
		moduleID = i2c_read(EEPROM_ADDR, 0x04);
	}
*/


 }
 
 
 uint8_t io_getModuleId()
 {
	return moduleID;
 }
 
 
 void io_heaterOn()
 {		
	PORTB |= (1 << PB4);	//ON
 }
 
 void io_heaterOff()
 {
	PORTB &= ~(1 << PB4);	//OFF
 }
 
 uint8_t io_heaterStatus()
 {
	 uint8_t state;
	 state = 0;
	 
	 state = ((PORTB & 0b00010000) >> 4);
	 
	 return state;
 }
 
  void io_regulateTemp()
  {
	  // Gets board temperature and enables heater if below threshold
	  if (sensors_getBoardTemp() <= HEATER_THRESHOLD)
	  {
		  io_heaterOn();
		  led_on(1);
	  } 
	  else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 5))
	  {
		  io_heaterOff();
		  led_off(1);
	  }
  }