Index: trunk/cardbox/main.c
===================================================================
--- trunk/cardbox/main.c	(revision 133)
+++ trunk/cardbox/main.c	(nonexistent)
@@ -1,920 +0,0 @@
-/** @file main.c
- *  @brief Contains the main function and cardbox specific helper functions for the cardbox for Tooltron.
- *
- *  @author Suresh Nidhiry (snidhiry), Kevin Woo (kwoo)
- **/
-
-/* Includes */
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-
-//#include "USI_UART_config.h"
-//#include "uart.h"
-//#include "timer.h"
-//#include "io_mine.h"
-
-/***** Pin Defines *****/
-/** @brief Pin that turns the relay on/off */
-#define RELAY 				_BV(PB3)
-/** @brief Red LED Pin*/
-#define LED_RED				_BV(PD6)
-/** @brief Yellow LED Pin*/
-#define LED_YELLOW			_BV(PD5)
-/** @brief Green LED Pin*/
-#define LED_GREEN			_BV(PD4)
-/** @brief Black Button Pin*/
-#define BUTTON_BLACK		_BV(PD2)
-/** @brief How much to shift out of the port that Black button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_BLACK_SHIFT	0x02
-/** @brief Red Button Pin*/
-#define BUTTON_RED			_BV(PD3)
-/** @brief How much to shift out of the port that Red button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_RED_SHIFT	0x03
-/** @brief RX Pin for the UART **/
-#define RX		_BV(PD0)
-/** @brief TX Pin for the UART **/
-#define TX		_BV(PD1)
-/** @brief TX Enable Pin for the UART **/
-#define TX_EN	_BV(PB1)
-
-/***** Keypad definitions ******/
-/** @brief ROW1 of the keypad */
-#define ROW1 _BV(PB0)
-/** @brief ROW2 of the keypad */
-#define ROW2 _BV(PB1)
-/** @brief ROW3 of the keypad */
-#define ROW3 _BV(PB2)
-/** @brief ROW4 of the keypad */
-#define ROW4 _BV(PB3)
-/** @brief COL1 of the keypad */
-#define COL1 _BV(PB4)
-/** @brief COL2 of the keypad */
-#define COL2 _BV(PB5)
-/** @brief COL3 of the keypad */
-#define COL3 _BV(PB6)
-/** @brief COL4 of the keypad */
-#define COL4 _BV(PB7)
-
-/***** Self Identity *****/
-/** @brief This is the ADDRESS. Make sure it conforms to Tooltron specs */
-#define ADDR			253
-
-/***** Transmit Defines *****/
-/** @brief Maximum size that the cardID + tool number can be in bytes */
-#define MAX_DATA_SIZE	10			//9 card digits, 1 byte for tool number
-/** @brief Maximum size that a cardID can be in bytes */
-#define MAX_CARD_SIZE	9			//9 card digits
-/** @brief How long a packet is before the payload section. Used for offsets */
-#define HEADER_OFFSET   2
-/** @brief Maximum size that a packet can be */
-#define MAX_PACKET_SIZE HEADER_OFFSET + MAX_DATA_SIZE
-/** @brief Baud rate for the rs485 network. This must be uniform across card, tool, and server */
-#define BAUD            51          //9600bps
-/** @brief The default server id that we send our requests to */
-#define DEFAULT_SERVER  254
-
-/***** USI_UART Defines *****/
-/** @brief The frequency of the clock in Hz */
-#define SYSTEM_CLOCK        8000000
-/** @brief The baudrate that the USI_UART module runs at */
-#define BAUDRATE            9600
-#define TIMER_PRESCALER           8     
-#define UART_RX_BUFFER_SIZE        4     /* 2,4,8,16,32,64,128 or 256 bytes */
-#define UART_TX_BUFFER_SIZE        4
-
-/***** Time Defines *****/
-/** @brief Max time in seconds to leave a red or green light on */
-#define MAX_LED_ON      5
-/** @brief Max time that we can wait for a full packet from the server before we timeout */
-#define TIME_OUT		5
-
-/***** States for for the main cardbox FSM *****/
-/** @brief Wait until a card is swiped and store the card id */
-#define INIT_CARD_READ		0x01
-/** @brief Wait until a tool is selected and store it */
-#define INIT_TOOL_READ		0x02
-/** @brief Send packet and then monitor line to see if the server accepts or denies the request */
-#define TXRX_DATA		    0x03
-/** @brief Run the fail subroutine if we were denied. Return to INIT_CARD_READ */
-#define FAIL				0x04
-#define COPY_FROM_BUF       0x05
-
-/***** States For Packet Parsing *****/
-/** @brief No state */
-#define NONE				0x00
-/** @brief Waiting for the first byte of the header to be received */
-#define HEAD				0x01
-/** @breif Waiting for the first byte of this addr to be received */
-#define DEST				0x02
-/** @brief Receive data */
-#define DATA				0x03 
-
-/***** Main Function Prototypes *****/
-static inline void success(void);
-static inline void fail(void);
-static void get_packet(char* dest, char* data);
-
-/***** IO Function Prototypes *****/
-/** @brief Sets the direction of the pins */
-static inline void init_pins(void);
-/** @brief Toggles the relay on or off. state == 1 is on, state == 0 is off */
-static inline void power_on(void);
-static inline void power_off(void);
-/** @brief Sets the state of the given LED (which) to state where state == 1 is on, state == 0 is off */
-static inline void led_on(char which);
-static inline void led_off(char which);
-/** @brief Reads the value of the black button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_black(void);
-/** @brief Reads the value of the red button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_red(void);
-/** @brief Waits until a button the keypad is pressed. Uses the timer to time out the loop in case none is selected */
-static char get_button(void);
-
-/***** Timer Function Prototypes *****/
-/** @brief Sets the registers to use the timer for couting in real time */
-static inline void init_timer(void);
-/** @brief Starts the timer from last position */
-static inline void start_timer(void);
-/** @brief Stops the timer from counting */
-static inline void stop_timer(void);
-/** @brief Resets the values of the timer to 0 */
-static inline void reset_timer(void);
-
-/***** UART Function Prototypes *****/
-/** @brief Initializes the UART registers and sets it to the buad rate which msut be the 
- *			value that is defined in the datasheet for any particular speed (ie: 51 -> 9600bps)
- **/
-static inline void init_uart(int baud);
-/** @brief Gets latest byte and returns it in output_byte. If the byte was already read, returns -1 
- *			otherwise it returns 0 
- **/
-static inline void uart_get_byte(char *output_byte);
-/** @brief Send one byte of data. If we are currently transmitting it will block until the
-  * 	the current transmit is done. 
-  **/
-static void uart_send_byte(char data);
-/** @brief Enable the RS485 Converter chip to transmit. Must give it about 1ms-2ms to propogate through */
-static inline void uart_enable_transmit(void);
-/** @brief Disable the RS485 Converter chip to transmit. Must give it about 1ms-2ms to propogate through */
-static inline void uart_disable_transmit(void);
-
-//***** USI_UART Prototypes *****//
-//static unsigned char			RxStream[100];
-
-static unsigned char 			RxIndex;
-static inline unsigned char USI_UART_Receive_Bytes( void );
-static inline unsigned char USI_UART_Data_In_Receive_Buffer( void );
-static inline unsigned char Bit_Reverse( unsigned char );
-static inline void          USI_UART_Initialise_Receiver( void );
-
-/***** Global Variables *****/
-static char received_byte;	        //Byte received
-static volatile char byte_ready;	//New byte has been received
-static char transmit_size;	        //Size of string that we are sending
-static volatile char transmitting;  //Flag to indicate that we are currently sending data
-static volatile char seconds;		//Seconds elapsed
-static volatile char minutes;		//Minutes exlapsed
-static char timeout_flag;           //Indicates that timeout has occured
-static char packet[MAX_PACKET_SIZE];   //Buffer for creating a packet
-
-/***********************************************************/
-
-int main(void) {
-
-	char dest = 0;
-	char data;
-	char position;                  //Tracks the position in data array we will send to the server
-	char i;                         //General purpose counter
-	char state;                     //State for FSM
-
-	/***** Start Start-up Sequence *****/
-	sei();				//Enable interrupts
-
-	init_timer();		//Set registers for timer
-	init_pins();		//Set pin directions
-	init_uart(BAUD);	//Set registers for uart
-	USI_UART_Initialise_Receiver();	//Set registers for Card reader
-
-	
-	position = 0;   	//What card number digit we are on, goes 0 - 8
-	state = INIT_CARD_READ;
-	//start_timer();
-	//reset_timer();
-	/***** End Start-up Sequence *****/
-	
-	/* Pregenerate the first 8 bits of the packet because they will
-	 *  always be the same. If they are overwritten you know there's
-	 *  a bug. 
-	 */
-	packet[0] = '~';
-	packet[1] = DEFAULT_SERVER;
-
-	//Main loop. We should never exit this or bad things will happen.
-	while(1) {
-		switch(state) {
-			//Wait until we get something 
-			case INIT_CARD_READ:
-				timeout_flag = 0;
-
-			    packet[MAX_PACKET_SIZE] = 255;  //Clear so we know when we get a valid tool number later
-			    led_on(LED_RED);
-			    //Wait for the cardreader to send us bytes, fill them into the data array
-
-			    //packet[position + HEADER_OFFSET] = USI_UART_Receive_Bytes(); 
-                led_on(LED_RED);
-
-			    i = USI_UART_Receive_Bytes();
-			    //position = 0;
-			    //for (position = 0; position < i; position++) {
-			    //    packet[position + HEADER_OFFSET] = RxStream[position];
-			    //}
-
-                //memcpy(packet[HEADER_OFFSET], RxStream, i);
-                
-
-
-                for (int a = 0; a < i; a++) {
-                    uart_send_byte(packet[a + HEADER_OFFSET]);
-                    led_on(LED_YELLOW);
-                }
-
-                led_on(LED_GREEN);
-
-				//state = INIT_TOOL_READ;
-				break;
-			
-			
-			//Wait until we get a tool to use
-			case INIT_TOOL_READ:
-			    //Turn on Yellow LED to indicate that we are waiting for the user to press a button
-				led_on(LED_YELLOW);
-				reset_timer();
-			    
-			    /*****This is for the actual keypad *****/
-			    
-				//Wait until we get a button press. Only continue if its valid
-				while((packet[position + HEADER_OFFSET] = get_button()) != 255) {
-				    if (seconds == TIME_OUT) {
-				        timeout_flag = 1;
-				        break;
-				    }
-				}
-				/*
-				//Temporary
-	            while (1) {
-                    reset_timer();
-                    //start_timer();
-
-                    if (seconds == TIME_OUT) {
-                        timeout_flag = 1;
-                        break;
-                    }
-
-			        if (read_button_black()) {
-			            packet[MAX_PACKET_SIZE - 1] = 1;
-			            break;
-			        } else if (read_button_red()) {
-			            packet[MAX_PACKET_SIZE - 1] = 2;
-			            break;
-			        }
-			    }
-
-				//If the use took too long fail
-				if (timeout_flag) {;
-				    timeout_flag = 0;
-				    state = FAIL;
-				}    
-			   */ 
-			   
-				state = TXRX_DATA;
-				break;
-				
-			//Recieve Data
-			case TXRX_DATA:
-			    for (i = 0; i < MAX_PACKET_SIZE; i++) {
-			        uart_send_byte(packet[i]);
-			    }
-				//uart_send_bytes(packet, MAX_PACKET_SIZE); 
-
-			    //Parse the server packet
-				get_packet(&dest, &data);
-				
-				/* We will only succeed if the server sends a turn on packet to the tool we
-				 *  designated. Since we are the master, we should not catch any other 
-				 *  packets on the line. If they happen at the same time we are listening
-				 *  for an ack, we will probably fail on the packet parsing and assume that
-				 *  the tool failed and provide feedback as such.
-				 */
-				if (dest == packet[MAX_PACKET_SIZE] && !timeout_flag) {
-				        success();
-				        state = INIT_CARD_READ;
-				} else {
-				    timeout_flag = 0;
-				    state = FAIL;
-				}
-				break;
-
-			//Failure! Provide visual feedback that you fail
-			case FAIL:
-				fail();
-				state = INIT_CARD_READ;
-				break;
-			
-			//We should never get here. If you do, Tooltron explodes
-			default:
-				state = INIT_CARD_READ;
-				break;
-		}
-	}
-	
-	//If you get here, all the tools are sent the SIGEXPLODE interrupt.
-	return 0;
-}
-
-/** @brief Turns off the yellow led and turns on the green led for MAX_LED_ON seconds.
- *      Requires the timer to initialized and started, though not neccessarily cleared.
- *      Will turn off the green LED when done. Timer will still be running when done.
- */
-static inline void success() {
-    //Clear the timer and count the seconds
-	reset_timer();
-
-	led_off(LED_YELLOW);
-	led_on(LED_GREEN);
-	
-	while (seconds < MAX_LED_ON);
-	
-	led_off(LED_GREEN);
-	return;
-}
-
-/** @brief Turns off the yellow led and turns on the red led for MAX_LED_ON seconds.
- *      Requires the timer to initialized and started, though not neccessarily cleared.
- *      Will turn off the red LED when done. Timer will still be running when done.
- */
-static inline void fail() {
-    //Clear the timer and count the seconds
-	reset_timer();
-
-	led_off(LED_YELLOW);
-    led_on(LED_RED);
-	
-	while (seconds <= MAX_LED_ON);
-	
-	led_off(LED_RED);
-	return;
-}
-
-/** @brief Listens to the data bus and parses the inputs as long as they are valid
- *      Tooltron packets. Fills dest and data with the dest and data respectively.
- *      If the server does not respond in TIME_OUT seconds, it assers the timeout_flag and returns.
- *  @param dest the destination that is sent.
- *  @param data the 1 byte of data transmitted with the packet
- */
-static void get_packet(char* dest, char* data) {
-	char current_char = 0;  //Last byte read in
-	char state = HEAD;      //Our current read state
-	
-	//Get timer ready to calculate if we timeout
-	reset_timer();
-	
-	while(1) {
-	    //It's a race against the clock. Don't let it time out.
-		//if (seconds == TIME_OUT) {
-		//	timeout_flag = 1;
-		//	return;
-		//}
-	    
-	    uart_get_byte(&current_char);
-	    if (timeout_flag) {
-	        return;
-	    } else { 
-		//if (!uart_get_byte(&current_char)) {
-			switch(state) {
-				case HEAD:						//First header byte received?
-					if (current_char == '~') {
-						state = DEST;
-					}	
-					break;
-					
-				case DEST:
-					*dest = current_char;
-					state = DATA;
-					break;
-					
-				case DATA:
-				    *data = current_char;
-				    return;
-				    
-				default:
-					state = HEAD;
-					break;
-			}
-		}
-	}
-	
-	return;
-}
-
-/** @file io.c
- *
- *	@brief Implements IO functionality like turning lights, relays on or off
- *			or reading button values
- *
- *	@author Kevin Woo (kwoo)
- */
-
-
-//Sets directions of pins
-static inline void init_pins() {
-	DDRB |= RELAY;
-
-	DDRD |= LED_RED | LED_YELLOW | LED_GREEN;
-	
-	return;	
-}
-
-//Will turn the relay on or off. 1 will turn it on, 0 will turn it off.
-static inline void power_on() {
-	PORTB |= RELAY;
-}
-
-static inline void power_off() {
-    PORTB &= ~RELAY;
-}
-
-//Turns on an off an LED. which should be the defined pins (1 byte) and
-// state is: 1 -> on, 0 -> off
-static inline void led_on(char which) {
-    PORTD |= which;
-	return;
-}
-
-static inline void led_off(char which) {
-	PORTD &= ~which;
-	return;
-}
-
-static inline char read_button_black() {
-	return ((PINB & BUTTON_BLACK) >> BUTTON_BLACK_SHIFT);
-}
-
-
-static inline char read_button_red() {
-	return ((PINB & BUTTON_RED) >> BUTTON_RED_SHIFT);
-}
-
-static char get_button() {           
-    // Row 1 Strobe
-  PORTB &= ~(ROW2|ROW3|ROW4);
-  PORTB |= ROW1;
-    if(PINB&(COL1))
-	    return 0;
-    if(PINB&(COL2))
-	    return 1;
-    if(PINB&(COL3))
-	    return 2;
-    if(PINB&(COL4))
-	    return 3;
-
-      PORTB&=~ROW1;
-      PORTB|=ROW2;
-    // Row 2 Strobe
-
-    if(PINB&(COL1))
-	    return 4;
-    if(PINB&(COL2))
-	    return 5;
-    if(PINB&(COL3))
-	    return 6;
-    if(PINB&(COL4))
-	    return 7;
-
-    // Row 3 Strobe
-      PORTB&=~ROW2;
-      PORTB|=ROW3;
-
-    if(PINB&(COL1))
-	    return 8;
-    if(PINB&(COL2))
-	    return 9;
-    if(PINB&(COL3))
-	    return 10;
-    if(PINB&(COL4))
-	    return 11;
-
-    // Row 4 Strobe
-
-    PORTD &= ~ROW3;
-    PORTA |= ROW4;
-
-    if(PINB&(COL1))
-	    return 12;
-    if(PINB&(COL2))
-	    return 13;
-    if(PINB&(COL3))
-	    return 14;
-    if(PINB&(COL4))
-	    return 15;
-
-    return 255;
-}
-
-
-/** @file timer.c
- * 
- *  @brief Implements the timer functions. See timer.h for full details
- *
- * 	@author Kevin Woo (kwoo)
- */
- 
-
-
-//Initializes all the timer1 registers
-static inline void init_timer() {
-	//Clears the control registers for timer 1
-	TCCR1A = 0x00;
-	TCCR1B = 0x00;
-	TCCR1C = 0x00;
-	TIMSK = 0x00;
-	
-	/*****
-	 * Output control register A set to clear timer on compare match.
-	 * Output control register B not connected.
-	 * WGM is in normal operation.
-	 * Clock is divided by 256. (This sets it to disconnected, connects
-	 *   in start_timer to above value).
-	 *****/
-	TCCR1A |= _BV(COM1A1);
-	
-	//Compares at 1 second with an 8MHz Clock and a 256 prescale. (31250)
-	OCR1AH = 0x7A;
-	OCR1AL = 0x12;
-	
-	//Enable the output compare register 1A interrupt
-	TIMSK |= _BV(OCIE1A);
-
-    //Initialize the time
-	seconds = 0;
-	minutes = 0;
-	
-	//Enable timer
-	TCCR1B |= _BV(CS12);
-		
-	timeout_flag = 0;
-	return;
-}
-
-static inline void start_timer() {
-	//Enables the timer. Sets prescale to 256.
-	TCCR1B |= _BV(CS12);
-}
-
-static inline void stop_timer() {
-	//Disables timer.
-	TCCR1B &= ~_BV(CS12);
-	//seconds = 0;
-	//minutes = 0;
-}
-
-static inline void reset_timer() {
-	seconds = 0;
-	minutes = 0;
-}
-
-ISR( TIMER1_COMPA_vect) {
-	if (seconds == 59) {
-		minutes++;
-		seconds = 0;
-	} else {
-		seconds++;
-	}
-}
-
-/** @file uart.c
- *	
- *	@brief Implements UART functionality in hardware
- *
- *	@author Kevin Woo (kwoo)
- */
-static inline void init_uart(int baud) {
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-
-	UCSRB = 0;
-	UCSRC = 0;
-
-	/* Enable RX/TX and RX/TX Interrupt */
-	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);
-	
-	/* Asynchronous mode, 1 bit stop, 8bit transmissions */
-	UCSRC = _BV(UCSZ1) | _BV(UCSZ0);
- 
- 	/* Enable RX pin as input */
-	PORTD &= ~RX;
-	
-	/* Enable TX pin as output */
-	DDRD |= TX;
-	
-	/* Enable the TXEN pin as output */
-	DDRB |= TX_EN;
-	
-	/* RX Status Variables */
-	received_byte = 0;	//Initialize first byte
-	byte_ready = 0;		//Byte is not ready to be read	
-	
-	/* TX Status Variables */
-	transmitting = 0;
-	transmit_size = 0;
-}
-
-static inline void uart_get_byte(char *output_byte) {
-	while (!byte_ready) {
-		if (seconds == TIME_OUT) {
-		    timeout_flag = 1;
-		    return;
-	    }
-	}
-	*output_byte = received_byte;
-	return;
-	
-	
-	/*
-	if (byte_ready) {
-		*output_byte = received_byte;
-		byte_ready = 0;
-		return 0;
-	} else {
-		return -1;
-	}
-	*/
-}
-
-static void uart_send_byte (char data) {
-    //Wait for the UART line to not be busy sending
-	while (!(UCSRA & (1 << UDRE)));
-
-    //Enable RS485 Converter, give it time to turn on
-	uart_enable_transmit();
-    _delay_loop_2(8000);    //Approxmiately 2ms
-	//led_on(LED_RED);
-	UDR = data;
-	//led_on(LED_YELLOW);	
-}
-
-
-static inline void uart_enable_transmit() {
-    PINB |= TX_EN;
-}
-
-static inline void uart_disable_transmit() {
-	PINB &= ~TX_EN;
-}
-
-ISR(USART_RX_vect) {	
-	while(1);
-	received_byte = UDR;
-	byte_ready = 1;
-}
-
-ISR(USART_TX_vect) {
-	//static volatile char loc = 1;
-	//if (transmitting) {
-		//if (loc < transmit_size) {
-		//	UDR = transmit_data[loc];
-		//	loc++;
-		//} else {
-		//	loc = 1;
-			//transmitting = 0;
-			_delay_loop_2(8000);    //Approxmiately 2ms
-			uart_disable_transmit();
-			//led_on(LED_GREEN);
-		//}
-	//}
-}
-
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File              : USI_UART.c
-* Compiler          : IAR EWAAVR 2.28a
-* Created           : 18.07.2002 by JLL
-* Modified          : 02-10-2003 by LTA
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : ATtiny26
-*
-* Application Note  : AVR307 - Half duplex UART using the USI Interface
-*
-* Description       : Functions for USI_UART_receiver and USI_UART_transmitter.
-*                     Uses Pin Change Interrupt to detect incomming signals.
-*
-*
-****************************************************************************/
-    
-//#include <avr/io.h>  // Note there is a bug in ioavr.h file that includes iotiny22.h instead of iotiny26.h.
-//#include <iotiny26.h>
-//#include <avr/interrupt.h>
-//#include <avr/signal.h>
-//#include "USI_UART_config.h"
-
-
-//********** USI UART Defines **********//
-#define RXPIN	PB5
-#define CLKPIN	PB7
-
-#define STARTFLAG 		0x45 //100 0101 //0x0B  //01011
-#define NSTARTFLAG		0x3A //011 1010 //0x14  //10100
-#define STOPFLAG      0x1F //001 1111  0x1F  //11111
-#define NSTOPFLAG		  0x60 //110 0000 0x00  //00000
-#define REVSTART      0x51 //101 0001  0x1A  //11010
-#define NREVSTART		  0x2E //010 1110 0x05  //00101
-
-#define DATA_BITS                 7
-#define START_BIT                 7
-#define STOP_BIT                  7
-#define HALF_FRAME                7
-
-
-#define USI_COUNTER_MAX_COUNT     16
-#define INTERRUPT_STARTUP_DELAY   (0x11 / TIMER_PRESCALER)
-
-#define USI_COUNTER_SEED_RECEIVE  ( USI_COUNTER_MAX_COUNT - (DATA_BITS*2) )
-
-/* General defines */
-#define TRUE                      1
-#define FALSE                     0
-
-//********** Static Variables **********//
-
-/*__no_init __regvar static unsigned char USI_UART_TxData[15];   // Tells the compiler to store the byte to be transmitted in registry.
-*/
-//static unsigned char			USI_UART_TxData;
-//static unsigned char          UART_RxByte;  // UART buffers. Size is definable in the header file.
-
-
-static volatile union USI_UART_status                           // Status byte holding flags.
-{
-    unsigned char status;
-    struct
-    {
-        unsigned char wait_Card:1;
-        unsigned char wait_Start:1;
-        unsigned char ongoing_Reception_Of_Package:1;
-        unsigned char reception_Buffer_Overflow:1;
-        unsigned char data_Ready:1;
-        unsigned char flag5:1;
-        unsigned char flag6:1;
-        unsigned char flag7:1;
-    };
-} USI_UART_status = {0};
-
-
-//********** USI_UART functions **********//
-
-// Reverses the order of bits in a byte.
-// I.e. MSB is swapped with LSB, etc.
-static inline unsigned char Bit_Reverse5( unsigned char x )
-{
-	unsigned char c = x&0x04;
-//	x = x<<3;
-    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-    return x;    
-}
-
-static inline unsigned char Bit_Reverse( unsigned char x )
-{
-  unsigned char c=0;
-  
-  c |=0x01&(x>>6);
-  c |=0x02&(x>>4);
-  c |=0x04&(x>>2);
-  c |=0x08&(x>>0);
-  c |=0x10&(x<<2);
-  c |=0x20&(x<<4);
-  c |=0x40&(x<<6);
-
-
-//	unsigned char c = x&0x08;
-//	x = x<<3;
-//    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-//    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-//    return x;    
-
-  return c;
-}
-
-
-
-// Initialise USI for UART reception.
-// Note that this function only enables pinchange interrupt on the USI Data Input pin.
-// The USI is configured to read data within the pinchange interrupt.
-static inline void USI_UART_Initialise_Receiver( void ) {  
-    // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)
-    PORTB |=   _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4);
-    // Set USI DI, DO and SCK pins as inputs.            
-    DDRB  &= ~( _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4));
-    // Disable USI.          
-    USICR = 0;                                            
-    // Clear pin change interrupt flag.
-    EIFR = _BV(PCIF);                                    
-	PCMSK |= _BV(RXPIN);
-	// Enable pin change interrupt for PB7:0.
-    GIMSK |= _BV(PCIE);                   
-                    
-	USI_UART_status.data_Ready=FALSE;
-	USI_UART_status.wait_Card=TRUE;
-	USI_UART_status.wait_Start=FALSE;
-	USI_UART_status.ongoing_Reception_Of_Package = FALSE; 
-	RxIndex=0;
-}
-
-// Returns a byte from the receive buffer. Waits if buffer is empty.
-static inline unsigned char USI_UART_Receive_Bytes(void) {
-    while ( !USI_UART_status.data_Ready );                 // Wait for incomming data 
-	USI_UART_status.data_Ready=FALSE;
-    return RxIndex;              // Reverse the order of the bits in the data byte before it returns data from the buffer.
-}
-
-// Check if there is data in the receive buffer.
-static inline unsigned char USI_UART_Data_In_Receive_Buffer(void) {
-    return (USI_UART_status.data_Ready);
-}
-
-
-// ********** Interrupt Handlers ********** //
-
-// The pin change interrupt is used to detect USI_UART reseption.
-// It is here the USI is configured to sample the UART signal.
-
-ISR(PCINT_vect)    
-{  
-   if ((USI_UART_status.wait_Card)&&(!( PINB & (1<<RXPIN) )))     // If the USI DI pin is low, then it is likely that it
-    {                                                             //  was this pin that generated the pin change interrupt.
-        USICR  = _BV(USISIE) | _BV(USIOIE) |                       // Enable USI Counter OVF interrupt.
-                 _BV(USIWM1) | _BV(USIWM0) |                      // Select Three Wire mode.
-                 _BV(USICS1) | _BV(USICS0) | _BV(USICLK) |        // Select Timer0 OVER as USI Clock source.
-                 _BV(USITC);                                           
-                                                                  // Note that enabling the USI will also disable the pin change interrupt.
-        USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;                 // Clear all USI interrupt flags and preload the USI counter to generate interrupt.
-
-        PCMSK |= _BV(CLKPIN);
-        PCMSK &= ~_BV(RXPIN);
-        
-        //GIMSK &=  ~(1<<PCIE);                                    // Disable pin change interrupt for PB3:0. 
-        USI_UART_status.wait_Start = TRUE;
-        USI_UART_status.wait_Card = FALSE;       
-
-    }
-	else if((USI_UART_status.wait_Start)&&(!(PINB&(1<<CLKPIN))))
-	{
-//	   	PORTD |= (1<<PD4); 
-		if((USIDR&0x7F)==(NREVSTART))  /////////////MAYBE SHOULD BE REVSTART
-		{
-			USI_UART_status.wait_Start = FALSE;
-			USI_UART_status.ongoing_Reception_Of_Package = TRUE;  
-			USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;                 // Clear all USI interrupt flags, preload the USI counter to generate an interrupt
-			GIMSK &= ~(1<<PCIE);
-			PCMSK &=~(1<<CLKPIN);
-		}
-	}
-}
-
-// The USI Counter Overflow interrupt is used for moving data between memmory and the USI data register.
-// The interrupt is used for both transmission and reception.
-ISR(SIG_USI_OVERFLOW) {
-
-    if(USI_UART_status.ongoing_Reception_Of_Package) {          
-		char b;
-
-        //Byte comes in inverted and backwards, invert and reverse it to make it correct
-		b=Bit_Reverse(~USIDR)&0x0F;
-
-        //End character
-		if(b>9) {
-            USICR  =  0;                                // Disable USI.
-            EIFR   =  _BV(PCIF);                        // Clear pin change interrupt flag.
-		    USI_UART_status.data_Ready=TRUE;    
-		} else {
-			//RxStream[RxIndex] = b;                      // Store received data in buffer. Note that the data must be bit reversed before used. 
-			//RxIndex=RxIndex+1;
-			
-			//WARNING: This is potentially dangerous if the card is larger than we expect. We should probably put some checks in here
-			// to prevent buffer 
-			packet[RxIndex + HEADER_OFFSET] = b;
-			RxIndex++;
-			USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;   // Clear all USI interrupt flags and Preload the USI counter to generate interrupt.
-		}
-
-    }
-    
-}
Index: trunk/cardbox/io.c.old
===================================================================
--- trunk/cardbox/io.c.old	(revision 133)
+++ trunk/cardbox/io.c.old	(nonexistent)
@@ -1,95 +0,0 @@
-/** @file io.c
- *
- *	@brief Implements IO functionality like turning lights, relays on or off
- *			or reading button values
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#include "io.h"
-
-//Sets directions of pins
-inline void init_pins() {
-	DDRB |= RELAY;
-	DDRD |= LED_RED | LED_YELLOW | LED_GREEN;
-	
-	return;	
-}
-
-//Will turn the relay on or off. 1 will turn it on, 0 will turn it off.
-void toggle_power(char state) {
-	if (state)
-		PORTB |= RELAY;
-	else
-		PORTB &= ~RELAY;
-		
-	return;
-}
-
-//Turns on an off an LED. which should be the defined pins (1 byte) and
-// state is: 1 -> on, 0 -> off
-void toggle_led(char which, char state) {
-	if (state)
-		PORTD |= _BV(which);
-	else
-		PORTD &= ~_BV(which);
-		
-	return;
-}
-
-char read_button_black() {
-	return ((PINB & BUTTON_BLACK) >> BUTTON_BLACK_SHIFT);
-}
-
-char read_button_red() {
-	return ((PINB & BUTTON_RED) >> BUTTON_RED_SHIFT);
-}
-
-char get_button() {
-    reset_timer();
-    start_timer();
-
-    while (1) {
-        if ((PIND & ROW1) && (PINB & COL1)) {
-            return 1;   //1
-        } else if ((PIND & ROW1) && (PINB & COL2)) {
-            return 2;   //2
-        } else if ((PIND & ROW1) && (PINB & COL3)) {
-            return 3;   //3
-        } else if ((PIND & ROW1) && (PINB & COL4)) {
-            return 10;  //A
-        } else if ((PIND & ROW2) && (PINB & COL1)) {
-            return 4;   //4
-        } else if ((PIND & ROW2) && (PINB & COL2)) {
-            return 5;   //5
-        } else if ((PIND & ROW2) && (PINB & COL3)) {
-            return 6;   //6
-        } else if ((PIND & ROW2) && (PINB & COL4)) {
-            return 11;  //B
-        } else if ((PINA & ROW3) && (PINB & COL1)) {
-            return 7;   //7
-        } else if ((PINA & ROW3) && (PINB & COL2)) {
-            return 8;   //8
-        } else if ((PINA & ROW3) && (PINB & COL3)) {
-            return 9;   //9
-        } else if ((PINA & ROW3) && (PINB & COL4)) {
-            return 12;  //C
-        } else if ((PINA & ROW4) && (PINB & COL1)) {
-            return 14;  //*
-        } else if ((PINA & ROW4) && (PINB & COL2)) {
-            return 0;   //0
-        } else if ((PINA & ROW4) && (PINB & COL3)) {
-            return 15;  //#
-        } else if ((PINA & ROW4) && (PINB & COL4)) {
-            return 13;  //D
-        }
-        
-        if (seconds == TIME_OUT) {
-            timeout_flag = 1;
-            return 255;
-        }
-    }
-    
-    return 255;
-}
-
Index: trunk/cardbox/io_mine.h
===================================================================
--- trunk/cardbox/io_mine.h	(revision 133)
+++ trunk/cardbox/io_mine.h	(nonexistent)
@@ -1,67 +0,0 @@
-/** @file io.h
- *
- *	@brief Implements IO functionality such as turning LEDs on
- *			and off, turning the relays on or off, and returning
- *			button values
- *	
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef IO_H
-#define IO_H
-
-#include <avr/io.h>
-#include "timer.h"
-
-/* Pin Defines */
-/** @brief Pin that turns the relay on/off */
-#define RELAY 				_BV(PB3)
-/** @brief Red LED Pin*/
-#define LED_RED				_BV(PD6)
-/** @brief Yellow LED Pin*/
-#define LED_YELLOW			_BV(PD5)
-/** @brief Green LED Pin*/
-#define LED_GREEN			_BV(PD4)
-/** @brief Black Button Pin*/
-#define BUTTON_BLACK		_BV(PD2)
-/** @brief How much to shift out of the port that Black button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_BLACK_SHIFT	0x02
-/** @brief Red Button Pin*/
-#define BUTTON_RED			_BV(PD3)
-/** @brief How much to shift out of the port that Red button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_RED_SHIFT	0x03
-
-/* Keypad definitions */
-/** @brief ROW1 of the keypad */
-#define ROW1 _BV(PD2)
-/** @brief ROW2 of the keypad */
-#define ROW2 _BV(PD3)
-/** @brief ROW3 of the keypad */
-#define ROW3 _BV(PA1)
-/** @brief ROW4 of the keypad */
-#define ROW4 _BV(PA0)
-/** @brief COL1 of the keypad */
-#define COL1 _BV(PB6)
-/** @brief COL2 of the keypad */
-#define COL2 _BV(PB4)
-/** @brief COL3 of the keypad */
-#define COL3 _BV(PB2)
-/** @brief COL4 of the keypad */
-#define COL4 _BV(PB0)
-
-
-/** @brief Sets the direction of the pins */
-static inline void init_pins(void);
-/** @brief Toggles the relay on or off. state == 1 is on, state == 0 is off */
-static inline void toggle_power_on(void);
-static inline void toggle_power_off(void);
-/** @brief Sets the state of the given LED (which) to state where state == 1 is on, state == 0 is off */
-static inline void toggle_led_on(char which);
-static inline void toggle_led_off(char which);
-/** @brief Reads the value of the black button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_black(void);
-/** @brief Reads the value of the red button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_red(void);
-/** @brief Waits until a button the keypad is pressed. Uses the timer to time out the loop in case none is selected */
-static char get_button(void);
-#endif
Index: trunk/cardbox/timer.h
===================================================================
--- trunk/cardbox/timer.h	(revision 133)
+++ trunk/cardbox/timer.h	(nonexistent)
@@ -1,29 +0,0 @@
-/** @file timer.h
- *	
- * 	@breif Timer functions
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef TIMER_H
-#define TIMER_H
-
-/** @brief Max time that we can wait for a full packet from the server before we timeout */
-#define TIME_OUT		5
-
-/** @brief Seconds that have elapsed since the timer started */
-//extern volatile char seconds;
-/** @brief Minutes that have elapsed since the timer started */
-//extern volatile char minutes;
-//extern char timeout_flag;
-
-/** @brief Sets the registers to use the timer for couting in real time */
-static inline void init_timer(void);
-/** @brief Starts the timer from last position*/
-static inline void start_timer(void);
-/** @brief Stops the timer from counting*/
-static inline void stop_timer(void);
-/** @brief Resets the values of the timer to 0*/
-static inline void reset_timer(void);
-
-#endif
Index: trunk/cardbox/USI_UART_config.h
===================================================================
--- trunk/cardbox/USI_UART_config.h	(revision 133)
+++ trunk/cardbox/USI_UART_config.h	(nonexistent)
@@ -1,61 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File          : USI_UART_config.h
-* Compiler      : IAR EWAAVR 2.28a
-* Created       : 18.07.2002 by JLL
-* Modified      : 02-10-2003 by LTA
-*
-* Support mail  : avr@atmel.com
-*
-* AppNote       : AVR307 - Half duplex UART using the USI Interface
-*
-* Description   : Header file for USI_UART driver
-*
-*
-****************************************************************************/
-
-#ifndef __USI_UART_config_h
-#define __USI_UART_config_h
-
-//********** USI UART Defines **********//
-
-//#define SYSTEM_CLOCK             14745600
-//#define SYSTEM_CLOCK             11059200
-#define SYSTEM_CLOCK              8000000
-//#define SYSTEM_CLOCK              7372800
-//#define SYSTEM_CLOCK              3686400
-//#define SYSTEM_CLOCK              2000000
-//#define SYSTEM_CLOCK              1843200
-//#define SYSTEM_CLOCK              1000000
-
-//#define BAUDRATE                   115200
-//#define BAUDRATE                    57600
-//#define BAUDRATE                    28800
-//#define BAUDRATE                    19200
-//#define BAUDRATE                    14400
-#define BAUDRATE                     9600
-
-//#define TIMER_PRESCALER           1
-#define TIMER_PRESCALER           8     
-
-#define UART_RX_BUFFER_SIZE        4     /* 2,4,8,16,32,64,128 or 256 bytes */
-#define UART_TX_BUFFER_SIZE        4
-
-
-//********** USI_UART Prototypes **********//
-static unsigned char			RxStream[100];
-
-static unsigned char 			RxIndex;
-static unsigned char USI_UART_Receive_Bytes( void );
-static inline unsigned char USI_UART_Data_In_Receive_Buffer( void );
-static inline unsigned char Bit_Reverse( unsigned char );
-static inline void          USI_UART_Initialise_Receiver( void );
-//Don't use these
-void          USI_UART_Initialise_Transmitter( void );
-void          USI_UART_Transmit_Byte( unsigned char );
-void          USI_UART_Flush_Buffers( void );
-//End
-
-#endif
Index: trunk/cardbox/main.hex
===================================================================
--- trunk/cardbox/main.hex	(revision 133)
+++ trunk/cardbox/main.hex	(nonexistent)
@@ -1,45 +0,0 @@
-:1000000012C029C028C027C027C025C024C04BC0AB
-:1000100022C04FC020C060C01EC01DC01CC01BC07D
-:100020009EC019C018C011241FBECFEDCDBF10E077
-:10003000A0E6B0E0ECEBF2E002C005900D92A03635
-:10004000B107D9F710E0A0E6B0E001C01D92A537D6
-:10005000B107E1F7C7C0D4CF1F920F920FB60F922E
-:1000600011248F93809166008B3341F48091670057
-:100070008F5F809367001092660005C080916600D4
-:100080008F5F809366008F910F900FBE0F901F902F
-:100090001895282F5D9BFECFB19A80E49FE10197D0
-:1000A000F1F72CB908951F920F920FB60F921124F9
-:1000B000FFCF1F920F920FB60F9211248F939F9331
-:1000C00080E49FE10197F1F7B1989F918F910F9094
-:1000D0000FBE0F901F9018951F920F920FB60F92A0
-:1000E00011248F938091600080FF17C0B59915C0CF
-:1000F0008FEF8DB982EF8EB980B5806880BD80B5F5
-:100100008F7D80BD809160008260809360008091CF
-:1001100060008E7F809360001CC08091600081FF32
-:1001200018C0B79916C08FB18F778E3291F4809135
-:1001300060008D7F80936000809160008460809378
-:10014000600082EF8EB98BB78F7D8BBF80B58F77C4
-:1001500080BD8F910F900FBE0F901F9018951F922A
-:100160000F920FB60F9211242F938F939F93EF93BB
-:10017000FF938091600082FF2BC08FB18095282F64
-:1001800022952695269523702170982F92959F7021
-:100190009270292B982F9870292B869586958470BC
-:1001A000282B2A3048F01DB880E28ABF8091600079
-:1001B0008061809360000CC080916100E82FFF2770
-:1001C000E759FF4F22838F5F8093610082EF8EB9E2
-:1001D000FF91EF919F918F912F910F900FBE0F90F4
-:1001E0001F901895CFEDD0E0DEBFCDBF78941FBC37
-:1001F0001EBC12BC19BE8FB580688FBD8AE78BBD4F
-:1002000082E18ABD89B7806489BF1092660010922E
-:1002100067008EB584608EBD10926800BB9A81B372
-:10022000806781BB12B883E389B91AB813B888ED27
-:100230008AB986E083B99098899AB99A1092620037
-:1002400010926300109265001092640088B3806F72
-:1002500088BB87B38F7087BB1DB880E28ABF80B52B
-:10026000806280BD8BB780628BBF809160008F7E83
-:100270008093600080916000816080936000809135
-:1002800060008D7F80936000809160008B7F809301
-:100290006000109261008EE7809369008EEF80937A
-:1002A0006A00969A969A8091600084FFFCCF8091B4
-:0C02B00060008F7E80936000949AF3CF72
-:00000001FF
Index: trunk/cardbox/USI_UART.c.old
===================================================================
--- trunk/cardbox/USI_UART.c.old	(revision 133)
+++ trunk/cardbox/USI_UART.c.old	(nonexistent)
@@ -1,238 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File              : USI_UART.c
-* Compiler          : IAR EWAAVR 2.28a
-* Created           : 18.07.2002 by JLL
-* Modified          : 02-10-2003 by LTA
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : ATtiny26
-*
-* Application Note  : AVR307 - Half duplex UART using the USI Interface
-*
-* Description       : Functions for USI_UART_receiver and USI_UART_transmitter.
-*                     Uses Pin Change Interrupt to detect incomming signals.
-*
-*
-****************************************************************************/
-    
-#include <avr/io.h>  // Note there is a bug in ioavr.h file that includes iotiny22.h instead of iotiny26.h.
-//#include <iotiny26.h>
-#include <avr/interrupt.h>
-//#include <avr/signal.h>
-#include "USI_UART_config.h"
-
-
-//********** USI UART Defines **********//
-#define RXPIN	PB5
-#define CLKPIN	PB7
-
-#define STARTFLAG 		0x45 //100 0101 //0x0B  //01011
-#define NSTARTFLAG		0x3A //011 1010 //0x14  //10100
-#define STOPFLAG      0x1F //001 1111  0x1F  //11111
-#define NSTOPFLAG		  0x60 //110 0000 0x00  //00000
-#define REVSTART      0x51 //101 0001  0x1A  //11010
-#define NREVSTART		  0x2E //010 1110 0x05  //00101
-
-#define DATA_BITS                 7
-#define START_BIT                 7
-#define STOP_BIT                  7
-#define HALF_FRAME                7
-
-
-#define USI_COUNTER_MAX_COUNT     16
-#define INTERRUPT_STARTUP_DELAY   (0x11 / TIMER_PRESCALER)
-
-#define USI_COUNTER_SEED_RECEIVE  ( USI_COUNTER_MAX_COUNT - (DATA_BITS*2) )
-
-/* General defines */
-#define TRUE                      1
-#define FALSE                     0
-
-//********** Static Variables **********//
-
-/*__no_init __regvar static unsigned char USI_UART_TxData[15];   // Tells the compiler to store the byte to be transmitted in registry.
-*/
-//static unsigned char			USI_UART_TxData;
-//static unsigned char          UART_RxByte;  // UART buffers. Size is definable in the header file.
-
-
-static volatile union USI_UART_status                           // Status byte holding flags.
-{
-    unsigned char status;
-    struct
-    {
-        unsigned char wait_Card:1;
-        unsigned char wait_Start:1;
-        unsigned char ongoing_Reception_Of_Package:1;
-        unsigned char reception_Buffer_Overflow:1;
-        unsigned char data_Ready:1;
-        unsigned char flag5:1;
-        unsigned char flag6:1;
-        unsigned char flag7:1;
-    };
-} USI_UART_status = {0};
-
-
-//********** USI_UART functions **********//
-
-// Reverses the order of bits in a byte.
-// I.e. MSB is swapped with LSB, etc.
-unsigned char Bit_Reverse5( unsigned char x )
-{
-	unsigned char c = x&0x04;
-//	x = x<<3;
-    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-    return x;    
-}
-
-unsigned char Bit_Reverse( unsigned char x )
-{
-  unsigned char c=0;
-  
-  c |=0x01&(x>>6);
-  c |=0x02&(x>>4);
-  c |=0x04&(x>>2);
-  c |=0x08&(x>>0);
-  c |=0x10&(x<<2);
-  c |=0x20&(x<<4);
-  c |=0x40&(x<<6);
-
-
-//	unsigned char c = x&0x08;
-//	x = x<<3;
-//    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-//    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-//    return x;    
-
-  return c;
-}
-
-
-
-// Initialise USI for UART reception.
-// Note that this function only enables pinchange interrupt on the USI Data Input pin.
-// The USI is configured to read data within the pinchange interrupt.
-void USI_UART_Initialise_Receiver( void )        
-{  
-    PORTB |=   (1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4);         // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)   
-    DDRB  &= ~((1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4));        // Set USI DI, DO and SCK pins as inputs.  
-    USICR  =  0;                                            // Disable USI.
-    EIFR   =  (1<<PCIF);                                    // Clear pin change interrupt flag.
-	PCMSK |= (1<<RXPIN);
-    GIMSK |=  (1<<PCIE);                                   // Enable pin change interrupt for PB7:0.
-	USI_UART_status.data_Ready=FALSE;
-	USI_UART_status.wait_Card=TRUE;
-	USI_UART_status.wait_Start=FALSE;
-	USI_UART_status.ongoing_Reception_Of_Package = FALSE; 
-	RxIndex=0;
-}
-
-// Returns a byte from the receive buffer. Waits if buffer is empty.
-unsigned char USI_UART_Receive_Bytes( void )                
-{
-
-    while ( !USI_UART_status.data_Ready );                 // Wait for incomming data 
-	USI_UART_status.data_Ready=FALSE;
-    return RxIndex;              // Reverse the order of the bits in the data byte before it returns data from the buffer.
-}
-
-// Check if there is data in the receive buffer.
-unsigned char USI_UART_Data_In_Receive_Buffer( void )        
-{
-    return ( USI_UART_status.data_Ready );
-
-}
-
-
-// ********** Interrupt Handlers ********** //
-
-// The pin change interrupt is used to detect USI_UART reseption.
-// It is here the USI is configured to sample the UART signal.
-
-ISR(PCINT_vect)    
-{  
-
-		
-   if ((USI_UART_status.wait_Card)&&(!( PINB & (1<<RXPIN) )))                                     // If the USI DI pin is low, then it is likely that it
-    {                                                             //  was this pin that generated the pin change interrupt.
-        USICR  = (0<<USISIE)|(1<<USIOIE)|                         // Enable USI Counter OVF interrupt.
-                 (0<<USIWM1)|(1<<USIWM0)|                         // Select Three Wire mode.
-                 (1<<USICS1)|(1<<USICS0)|(0<<USICLK)|             // Select Timer0 OVER as USI Clock source.
-                 (0<<USITC);                                           
-                                                                  // Note that enabling the USI will also disable the pin change interrupt.
-        USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-                 USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-        PCMSK |= (1<<CLKPIN);
-        PCMSK &=~(1<<RXPIN);
-        //GIMSK &=  ~(1<<PCIE);                                    // Disable pin change interrupt for PB3:0. 
-        USI_UART_status.wait_Start = TRUE;
-        USI_UART_status.wait_Card = FALSE;       
-        PORTD |= (1<<PD4); 
-
-    }
-	else if((USI_UART_status.wait_Start)&&(!(PINB&(1<<CLKPIN))))
-	{
-//	   	PORTD |= (1<<PD4); 
-		if((USIDR&0x7F)==(NREVSTART))  /////////////MAYBE SHOULD BE REVSTART
-		{
-			
-      //PORTD |= (1<<PD4);
-			USI_UART_status.wait_Start = FALSE;
-			USI_UART_status.ongoing_Reception_Of_Package = TRUE;  
-			USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-					 USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-			GIMSK &= ~(1<<PCIE);
-			PCMSK &=~(1<<CLKPIN);
-		}
-	}
-}
-
-// The USI Counter Overflow interrupt is used for moving data between memmory and the USI data register.
-// The interrupt is used for both transmission and reception.
-SIGNAL(SIG_USI_OVERFLOW)                              
-{
-
-    if(USI_UART_status.ongoing_Reception_Of_Package)
-    {          
-		char b;
-
-   
-		b=Bit_Reverse(~USIDR)&0x0F;
-
-	//	PORTD |= (1<<PD5);
-		if(b>9){
-
-   //   PORTD |= (1<<PD6);
-         /////////Not needed?:
-     //   PORTB |=   (1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4);         // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)   
-       //   DDRB  &= ~((1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4));        // Set USI DI, DO and SCK pins as inputs. 
-  
-        USICR  =  0;                                            // Disable USI.
-        EIFR   =  (1<<PCIF);                                    // Clear pin change interrupt flag.
-      //	GIMSK |=  (1<<PCIE);                                   // Enable pin change interrupt for PB3:0.
-      //	PCMSK |= (1<<RXPIN);		
-        USI_UART_status.data_Ready=TRUE;    
-		}
-		else
-		{
-		//	PORTD |= (1<<PD4);
-			RxStream[RxIndex] = b;                                // Store received data in buffer. Note that the data must be bit reversed before used. 
-			RxIndex=RxIndex+1;
-            ///////REVERSE DATA??
-			USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-					USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-	
-		}
-
-    }
-    
-}
Index: trunk/cardbox/Makefile
===================================================================
--- trunk/cardbox/Makefile	(revision 133)
+++ trunk/cardbox/Makefile	(nonexistent)
@@ -1,507 +0,0 @@
-# Hey Emacs, this is a -*- makefile -*-
-#----------------------------------------------------------------------------
-# WinAVR Makefile Template written by Eric B. Weddington, J�rg Wunsch, et al.
-#
-# Released to the Public Domain
-#
-# Additional material for this makefile was written by:
-# Peter Fleury
-# Tim Henigan
-# Colin O'Flynn
-# Reiner Patommel
-# Markus Pfaff
-# Sander Pool
-# Frederik Rouleau
-#
-#----------------------------------------------------------------------------
-# On command line:
-#
-# make all = Make software.
-#
-# make clean = Clean out built project files.
-#
-# make coff = Convert ELF to AVR COFF.
-#
-# make extcoff = Convert ELF to AVR Extended COFF.
-#
-# make program = Download the hex file to the device, using avrdude.
-#                Please customize the avrdude settings below first!
-#
-# make debug = Start either simulavr or avarice as specified for debugging, 
-#              with avr-gdb or avr-insight as the front end for debugging.
-#
-# make filename.s = Just compile filename.c into the assembler code only.
-#
-# make filename.i = Create a preprocessed source file for use in submitting
-#                   bug reports to the GCC project.
-#
-# To rebuild project do "make clean" then "make all".
-#----------------------------------------------------------------------------
-
-
-# MCU name
-MCU = attiny2313
-
-
-# Processor frequency.
-#     This will define a symbol, F_CPU, in all source code files equal to the 
-#     processor frequency. You can then use this symbol in your source code to 
-#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
-#     automatically to create a 32-bit value in your source code.
-F_CPU = 8000000
-
-
-# Output format. (can be srec, ihex, binary)
-FORMAT = ihex
-
-
-# Target file name (without extension).
-TARGET = main
-
-# List C source files here. (C dependencies are automatically generated.)
-//SRC =  $(wildcard *.c)
-SRC = main.c
-
-# List Assembler source files here.
-#     Make them always end in a capital .S.  Files ending in a lowercase .s
-#     will not be considered source files but generated files (assembler
-#     output from the compiler), and will be deleted upon "make clean"!
-#     Even though the DOS/Win* filesystem matches both .s and .S the same,
-#     it will preserve the spelling of the filenames, and gcc itself does
-#     care about how the name is spelled on its command-line.
-ASRC = 
-
-
-# Optimization level, can be [0, 1, 2, 3, s]. 
-#     0 = turn off optimization. s = optimize for size.
-#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-OPT = s
-
-
-# Debugging format.
-#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
-#     AVR Studio 4.10 requires dwarf-2.
-#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
-DEBUG =
-
-
-# List any extra directories to look for include files here.
-#     Each directory must be seperated by a space.
-#     Use forward slashes for directory separators.
-#     For a directory that has spaces, enclose it in quotes.
-#EXTRAINCDIRS = C:\WinAVR\include\fwr
-
-
-# Compiler flag to set the C Standard level.
-#     c89   = "ANSI" C
-#     gnu89 = c89 plus GCC extensions
-#     c99   = ISO C99 standard (not yet fully implemented)
-#     gnu99 = c99 plus GCC extensions
-CSTANDARD = -std=gnu99
-
-
-# Place -D or -U options here
-CDEFS = -DF_CPU=$(F_CPU)UL
-
-
-# Place -I options here
-CINCS =
-
-
-
-#---------------- Compiler Options ----------------
-#  -g*:          generate debugging information
-#  -O*:          optimization level
-#  -f...:        tuning, see GCC manual and avr-libc documentation
-#  -Wall...:     warning level
-#  -Wa,...:      tell GCC to pass this to the assembler.
-#    -adhlns...: create assembler listing
-#CFLAGS = -g$(DEBUG)
-CFLAGS += $(CDEFS) $(CINCS)
-CFLAGS += -O$(OPT)
-CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-CFLAGS += -Wall -Wstrict-prototypes
-CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
-CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-CFLAGS += $(CSTANDARD)
-
-
-#---------------- Assembler Options ----------------
-#  -Wa,...:   tell GCC to pass this to the assembler.
-#  -ahlms:    create listing
-#  -gstabs:   have the assembler create line number information; note that
-#             for use in COFF files, additional information about filenames
-#             and function names needs to be present in the assembler source
-#             files -- see avr-libc docs [FIXME: not yet described there]
-ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
-
-
-#---------------- Library Options ----------------
-# Minimalistic printf version
-PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
-
-# Floating point printf version (requires MATH_LIB = -lm below)
-PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
-
-# If this is left blank, then it will use the Standard printf version.
-PRINTF_LIB = 
-#PRINTF_LIB = $(PRINTF_LIB_MIN)
-#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
-
-
-# Minimalistic scanf version
-SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
-
-# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
-SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
-
-# If this is left blank, then it will use the Standard scanf version.
-SCANF_LIB = 
-#SCANF_LIB = $(SCANF_LIB_MIN)
-#SCANF_LIB = $(SCANF_LIB_FLOAT)
-
-
-MATH_LIB = -lm
-
-
-
-#---------------- External Memory Options ----------------
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# used for variables (.data/.bss) and heap (malloc()).
-#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# only used for heap (malloc()).
-#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
-
-EXTMEMOPTS =
-
-
-
-#---------------- Linker Options ----------------
-#  -Wl,...:     tell GCC to pass this to linker.
-#    -Map:      create map file
-#    --cref:    add cross reference to  map file
-LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
-LDFLAGS += $(EXTMEMOPTS)
-LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
-
-
-
-#---------------- Programming Options (avrdude) ----------------
-
-# Programming hardware: alf avr910 avrisp bascom bsd 
-# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
-#
-# Type: avrdude -c ?
-# to get a full listing.
-#
-AVRDUDE_PROGRAMMER = avrispmkII
-
-# com1 = serial port. Use lpt1 to connect to parallel port.
-AVRDUDE_PORT = usb
-# programmer connected to serial device
-
-AVRDUDE_WRITE_FLASH = -b 4800 -U flash:w:$(TARGET).hex
-#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
-
-
-# Uncomment the following if you want avrdude's erase cycle counter.
-# Note that this counter needs to be initialized first using -Yn,
-# see avrdude manual.
-#AVRDUDE_ERASE_COUNTER = -y
-
-# Uncomment the following if you do /not/ wish a verification to be
-# performed after programming the device.
-#AVRDUDE_NO_VERIFY = -V
-
-# Increase verbosity level.  Please use this when submitting bug
-# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
-# to submit bug reports.
-#AVRDUDE_VERBOSE = -v -v
-
-AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -F
-AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
-AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
-AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
-
-
-
-#---------------- Debugging Options ----------------
-
-# For simulavr only - target MCU frequency.
-DEBUG_MFREQ = $(F_CPU)
-
-# Set the DEBUG_UI to either gdb or insight.
-# DEBUG_UI = gdb
-DEBUG_UI = insight
-
-# Set the debugging back-end to either avarice, simulavr.
-DEBUG_BACKEND = avarice
-#DEBUG_BACKEND = simulavr
-
-# GDB Init Filename.
-GDBINIT_FILE = __avr_gdbinit
-
-# When using avarice settings for the JTAG
-JTAG_DEV = /dev/com1
-
-# Debugging port used to communicate between GDB / avarice / simulavr.
-DEBUG_PORT = 4242
-
-# Debugging host used to communicate between GDB / avarice / simulavr, normally
-#     just set to localhost unless doing some sort of crazy debugging when 
-#     avarice is running on a different computer.
-DEBUG_HOST = localhost
-
-
-
-#============================================================================
-
-
-# Define programs and commands.
-SHELL = sh
-CC = avr-gcc
-OBJCOPY = avr-objcopy
-OBJDUMP = avr-objdump
-SIZE = avr-size
-NM = avr-nm
-AVRDUDE = avrdude
-REMOVE = rm -f
-COPY = cp
-WINSHELL = cmd
-
-
-# Define Messages
-# English
-MSG_ERRORS_NONE = Errors: none
-MSG_BEGIN = -------- begin --------
-MSG_END = --------  end  --------
-MSG_SIZE_BEFORE = Size before: 
-MSG_SIZE_AFTER = Size after:
-MSG_COFF = Converting to AVR COFF:
-MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
-MSG_FLASH = Creating load file for Flash:
-MSG_EEPROM = Creating load file for EEPROM:
-MSG_EXTENDED_LISTING = Creating Extended Listing:
-MSG_SYMBOL_TABLE = Creating Symbol Table:
-MSG_LINKING = Linking:
-MSG_COMPILING = Compiling:
-MSG_ASSEMBLING = Assembling:
-MSG_CLEANING = Cleaning project:
-
-
-
-
-# Define all object files.
-OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
-
-# Define all listing files.
-LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
-
-
-# Compiler flags to generate dependency files.
-GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
-
-
-# Combine all necessary flags and optional flags.
-# Add target processor to flags.
-ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
-
-
-
-
-
-# Default target.
-all: begin gccversion sizebefore build sizeafter end
-
-build: elf hex eep lss sym
-
-elf: $(TARGET).elf
-hex: $(TARGET).hex
-eep: $(TARGET).eep
-lss: $(TARGET).lss 
-sym: $(TARGET).sym
-
-
-
-# Eye candy.
-# AVR Studio 3.x does not check make's exit code but relies on
-# the following magic strings to be generated by the compile job.
-begin:
-	@echo
-	@echo $(MSG_BEGIN)
-
-end:
-	@echo $(MSG_END)
-	@echo
-
-
-# Display size of file.
-HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
-ELFSIZE = $(SIZE) -A $(TARGET).elf
-AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
-
-sizebefore:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-sizeafter:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-
-
-# Display compiler version information.
-gccversion : 
-	@$(CC) --version
-
-
-
-# Program the device.  
-program: $(TARGET).hex $(TARGET).eep
-	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
-
-# Generate avr-gdb config/init file which does the following:
-#     define the reset signal, load the target file, connect to target, and set 
-#     a breakpoint at main().
-gdb-config: 
-	@$(REMOVE) $(GDBINIT_FILE)
-	@echo define reset >> $(GDBINIT_FILE)
-	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
-	@echo end >> $(GDBINIT_FILE)
-	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
-	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
-ifeq ($(DEBUG_BACKEND),simulavr)
-	@echo load  >> $(GDBINIT_FILE)
-endif	
-	@echo break main >> $(GDBINIT_FILE)
-	
-debug: gdb-config $(TARGET).elf
-ifeq ($(DEBUG_BACKEND), avarice)
-	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
-	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
-	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
-	@$(WINSHELL) /c pause
-	
-else
-	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
-	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
-endif
-	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
-	
-
-
-
-# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
-COFFCONVERT=$(OBJCOPY) --debugging \
---change-section-address .data-0x800000 \
---change-section-address .bss-0x800000 \
---change-section-address .noinit-0x800000 \
---change-section-address .eeprom-0x810000 
-
-
-coff: $(TARGET).elf
-	@echo
-	@echo $(MSG_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
-
-
-extcoff: $(TARGET).elf
-	@echo
-	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
-
-
-
-# Create final output files (.hex, .eep) from ELF output file.
-%.hex: %.elf
-	@echo
-	@echo $(MSG_FLASH) $@
-	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
-
-%.eep: %.elf
-	@echo
-	@echo $(MSG_EEPROM) $@
-	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
-	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
-
-# Create extended listing file from ELF output file.
-%.lss: %.elf
-	@echo
-	@echo $(MSG_EXTENDED_LISTING) $@
-	$(OBJDUMP) -h -S $< > $@
-
-# Create a symbol table from ELF output file.
-%.sym: %.elf
-	@echo
-	@echo $(MSG_SYMBOL_TABLE) $@
-	$(NM) -n $< > $@
-
-
-
-# Link: create ELF output file from object files.
-.SECONDARY : $(TARGET).elf
-.PRECIOUS : $(OBJ)
-%.elf: $(OBJ)
-	@echo
-	@echo $(MSG_LINKING) $@
-	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
-
-
-# Compile: create object files from C source files.
-%.o : %.c
-	@echo
-	@echo $(MSG_COMPILING) $<
-	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
-
-
-# Compile: create assembler files from C source files.
-%.s : %.c
-	$(CC) -S $(ALL_CFLAGS) $< -o $@
-
-
-# Assemble: create object files from assembler source files.
-%.o : %.S
-	@echo
-	@echo $(MSG_ASSEMBLING) $<
-	$(CC) -c $(ALL_ASFLAGS) $< -o $@
-
-# Create preprocessed source for use in sending a bug report.
-%.i : %.c
-	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
-
-
-# Target: clean project.
-clean: begin clean_list end
-
-clean_list :
-	@echo
-	@echo $(MSG_CLEANING)
-	$(REMOVE) $(TARGET).hex
-	$(REMOVE) $(TARGET).eep
-	$(REMOVE) $(TARGET).cof
-	$(REMOVE) $(TARGET).elf
-	$(REMOVE) $(TARGET).map
-	$(REMOVE) $(TARGET).sym
-	$(REMOVE) $(TARGET).lss
-	$(REMOVE) $(OBJ)
-	$(REMOVE) $(LST)
-	$(REMOVE) $(SRC:.c=.s)
-	$(REMOVE) $(SRC:.c=.d)
-	$(REMOVE) .dep/*
-
-
-
-# Include the dependency files.
--include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
-
-
-# Listing of phony targets.
-.PHONY : all begin finish end sizebefore sizeafter gccversion \
-build elf hex eep lss sym coff extcoff \
-clean clean_list program debug gdb-config
-
Index: trunk/cardbox/timer.c.old
===================================================================
--- trunk/cardbox/timer.c.old	(revision 133)
+++ trunk/cardbox/timer.c.old	(nonexistent)
@@ -1,75 +0,0 @@
-/** @file timer.c
- * 
- *  @brief Implements the timer functions. See timer.h for full details
- *
- * 	@author Kevin Woo (kwoo)
- */
- 
-#include "timer.h"
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-
-volatile char seconds;		//Seconds elapsed
-volatile char minutes;		//Minutes exlapsed
-char timeout_flag; //Indicates that timeout has occured
-
-//Initializes all the timer1 registers
-void init_timer() {
-	//Clears the control registers for timer 1
-	TCCR1A = 0x00;
-	TCCR1B = 0x00;
-	TCCR1C = 0x00;
-	TIMSK = 0x00;
-	
-	/*****
-	 * Output control register A set to clear timer on compare match.
-	 * Output control register B not connected.
-	 * WGM is in normal operation.
-	 * Clock is divided by 256. (This sets it to disconnected, connects
-	 *   in start_timer to above value).
-	 *****/
-	TCCR1A |= _BV(COM1A1);
-	
-	//Compares at 1 second with an 8MHz Clock and a 256 prescale. (31250)
-	OCR1AH = 0x7A;
-	OCR1AL = 0x12;
-	
-	//Enable the output compare register 1A interrupt
-	TIMSK |= _BV(OCIE1A);
-	
-	timeout_flag = 0;
-	
-	return;
-}
-
-void start_timer() {
-	//Enables the timer. Sets prescale to 256.
-	TCCR1B |= _BV(CS12);
-	
-	return;
-}
-
-void stop_timer() {
-	//Disables timer.
-	TCCR1B &= ~_BV(CS12);
-	seconds = 0;
-	minutes = 0;
-	
-	return;
-}
-
-void reset_timer() {
-	seconds = 0;
-	minutes = 0;
-	return;
-}
-
-ISR(TIMER1_COMP1_vect) {
-	if (seconds == 59) {
-		minutes++;
-		seconds = 0;
-	} else {
-		seconds++;
-	}
-}
Index: trunk/cardbox/swipebox/timer.c.old
===================================================================
--- trunk/cardbox/swipebox/timer.c.old	(revision 133)
+++ trunk/cardbox/swipebox/timer.c.old	(nonexistent)
@@ -1,75 +0,0 @@
-/** @file timer.c
- * 
- *  @brief Implements the timer functions. See timer.h for full details
- *
- * 	@author Kevin Woo (kwoo)
- */
- 
-#include "timer.h"
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-
-volatile char seconds;		//Seconds elapsed
-volatile char minutes;		//Minutes exlapsed
-char timeout_flag; //Indicates that timeout has occured
-
-//Initializes all the timer1 registers
-void init_timer() {
-	//Clears the control registers for timer 1
-	TCCR1A = 0x00;
-	TCCR1B = 0x00;
-	TCCR1C = 0x00;
-	TIMSK = 0x00;
-	
-	/*****
-	 * Output control register A set to clear timer on compare match.
-	 * Output control register B not connected.
-	 * WGM is in normal operation.
-	 * Clock is divided by 256. (This sets it to disconnected, connects
-	 *   in start_timer to above value).
-	 *****/
-	TCCR1A |= _BV(COM1A1);
-	
-	//Compares at 1 second with an 8MHz Clock and a 256 prescale. (31250)
-	OCR1AH = 0x7A;
-	OCR1AL = 0x12;
-	
-	//Enable the output compare register 1A interrupt
-	TIMSK |= _BV(OCIE1A);
-	
-	timeout_flag = 0;
-	
-	return;
-}
-
-void start_timer() {
-	//Enables the timer. Sets prescale to 256.
-	TCCR1B |= _BV(CS12);
-	
-	return;
-}
-
-void stop_timer() {
-	//Disables timer.
-	TCCR1B &= ~_BV(CS12);
-	seconds = 0;
-	minutes = 0;
-	
-	return;
-}
-
-void reset_timer() {
-	seconds = 0;
-	minutes = 0;
-	return;
-}
-
-ISR(TIMER1_COMP1_vect) {
-	if (seconds == 59) {
-		minutes++;
-		seconds = 0;
-	} else {
-		seconds++;
-	}
-}
Index: trunk/cardbox/swipebox/uartio.c.old
===================================================================
--- trunk/cardbox/swipebox/uartio.c.old	(revision 133)
+++ trunk/cardbox/swipebox/uartio.c.old	(nonexistent)
@@ -1,91 +0,0 @@
-/** @file uart.c
- *	
- *	@brief Implements UART functionality in hardware
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#include "uart.h"
-
-char received_byte;							//Byte received
-char *transmit_data;						//String to send
-char transmit_size;							//Size of string that we are sending
-char byte_ready;								//New byte has been received
-char transmitting;
-
-static void init_uart(int baud) {
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-	
-	/* Enable RX/TX and RX/TX Interrupt */
-	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);
-	
-	/* Asynchronous mode, 1 bit stop, 8bit transmissions */
-	UCSRC = _BV(UCSZ1) | _BV(UCSZ0) | ~_BV(USBS);
- 
- 	/* Enable RX pin as input */
-	PORTD &= ~RX;
-	
-	/* Enable TX pin as output */
-	DDRD |= TX;
-	
-	/* Enable the TXEN pin as output */
-	DDRB |= TX_EN;
-	
-	/* RX Status Variables */
-	received_byte = 0;	//Initialize first byte
-	byte_ready = 0;		//Byte is not ready to be read	
-	
-	/* TX Status Variables */
-	transmitting = 0;
-	transmit_size = 0;
-}
-
-static char uart_get_byte(char *output_byte) {
-	if (byte_ready) {
-		*output_byte = received_byte;
-		byte_ready = 0;
-		return 0;
-	} else {
-		return -1;
-	}
-}
-
-static void uart_send_bytes(char *data, int size) {
-	//Waits until current transmit is done
-	while (transmitting);
-
-	uart_enable_transmit(UART_TX_ON);
-	transmitting = 1;
-	transmit_size = size;
-	transmit_data = data;
-	return;
-}
-
-static void uart_enable_transmit(char state) {
-	if (state == UART_TX_ON) {
-		PINB |= TX_EN;
-	} else {
-		PINB &= ~TX_EN;
-	}
-}
-
-ISR(UART_RX_vect) {
-	received_byte = UDR;
-	byte_ready = 1;
-}
-
-ISR(UART_TX_vect) {
-	static volatile char position = 0;
-	if (transmitting) {
-		if (position < transmit_size) {
-			UDR = transmit_data[position];
-			position++;
-		} else {
-			position = 0;
-			transmitting = 0;
-			uart_enable_transmit(UART_TX_OFF);
-		}
-	}
-}
Index: trunk/cardbox/swipebox/uart.h
===================================================================
--- trunk/cardbox/swipebox/uart.h	(revision 133)
+++ trunk/cardbox/swipebox/uart.h	(nonexistent)
@@ -1,46 +0,0 @@
-/** @file uart.h
- *
- *	@brief Initializes UART functions using the UART hardware module
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef UART_H
-#define UART_H
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-
-/** **/
-#define UART_TX_OFF 0
-#define UART_TX_ON 1
-
-/** @brief RX Pin for the UART **/
-#define RX		_BV(PD0)
-#define TX		_BV(PD1)
-#define TX_EN	_BV(PB1)
-
-
-/** @brief The most recently received byte **/
-//extern char received_byte;
-/** @brief If the value in received_byte has been read or not **/
-//extern char	byte_ready;
-//extern char *transmit_data;
-//extern char transmit_size;
-//extern char transmitting;
-
-/** @brief Initializes the UART registers and sets it to the buad rate which msut be the 
- *			value that is defined in the datasheet for any particular speed (ie: 51 -> 9600bps)
- **/
-static inline void init_uart(int baud);
-/** @brief Gets latest byte and returns it in output_byte. If the byte was already read, returns -1 
- *			otherwise it returns 0 
- **/
-static char uart_get_byte(char *output_byte);
-/** @brief Sends a character array of size size. If we are currently transmitting it will block until the
-  * 	the current transmit is done. 
-  **/
-static void uart_send_byte(char data);
-static inline void uart_enable_transmit(void);
-static inline void uart_disable_transmit(void);
-#endif
Index: trunk/cardbox/swipebox/rewrite/timer.h
===================================================================
--- trunk/cardbox/swipebox/rewrite/timer.h	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/timer.h	(nonexistent)
@@ -1,29 +0,0 @@
-/** @file timer.h
- *	
- * 	@breif Timer functions
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef TIMER_H
-#define TIMER_H
-
-/** @brief Max time that we can wait for a full packet from the server before we timeout */
-#define TIME_OUT		5
-
-/** @brief Seconds that have elapsed since the timer started */
-//extern volatile char seconds;
-/** @brief Minutes that have elapsed since the timer started */
-//extern volatile char minutes;
-//extern char timeout_flag;
-
-/** @brief Sets the registers to use the timer for couting in real time */
-static inline void init_timer(void);
-/** @brief Starts the timer from last position*/
-static inline void start_timer(void);
-/** @brief Stops the timer from counting*/
-static inline void stop_timer(void);
-/** @brief Resets the values of the timer to 0*/
-static inline void reset_timer(void);
-
-#endif
Index: trunk/cardbox/swipebox/rewrite/USI_UART_config.h
===================================================================
--- trunk/cardbox/swipebox/rewrite/USI_UART_config.h	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/USI_UART_config.h	(nonexistent)
@@ -1,61 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File          : USI_UART_config.h
-* Compiler      : IAR EWAAVR 2.28a
-* Created       : 18.07.2002 by JLL
-* Modified      : 02-10-2003 by LTA
-*
-* Support mail  : avr@atmel.com
-*
-* AppNote       : AVR307 - Half duplex UART using the USI Interface
-*
-* Description   : Header file for USI_UART driver
-*
-*
-****************************************************************************/
-
-#ifndef __USI_UART_config_h
-#define __USI_UART_config_h
-
-//********** USI UART Defines **********//
-
-//#define SYSTEM_CLOCK             14745600
-//#define SYSTEM_CLOCK             11059200
-#define SYSTEM_CLOCK              8000000
-//#define SYSTEM_CLOCK              7372800
-//#define SYSTEM_CLOCK              3686400
-//#define SYSTEM_CLOCK              2000000
-//#define SYSTEM_CLOCK              1843200
-//#define SYSTEM_CLOCK              1000000
-
-//#define BAUDRATE                   115200
-//#define BAUDRATE                    57600
-//#define BAUDRATE                    28800
-//#define BAUDRATE                    19200
-//#define BAUDRATE                    14400
-#define BAUDRATE                     9600
-
-//#define TIMER_PRESCALER           1
-#define TIMER_PRESCALER           8     
-
-#define UART_RX_BUFFER_SIZE        4     /* 2,4,8,16,32,64,128 or 256 bytes */
-#define UART_TX_BUFFER_SIZE        4
-
-
-//********** USI_UART Prototypes **********//
-static unsigned char			RxStream[100];
-
-static unsigned char 			RxIndex;
-static unsigned char USI_UART_Receive_Bytes( void );
-static inline unsigned char USI_UART_Data_In_Receive_Buffer( void );
-static inline unsigned char Bit_Reverse( unsigned char );
-static inline void          USI_UART_Initialise_Receiver( void );
-//Don't use these
-void          USI_UART_Initialise_Transmitter( void );
-void          USI_UART_Transmit_Byte( unsigned char );
-void          USI_UART_Flush_Buffers( void );
-//End
-
-#endif
Index: trunk/cardbox/swipebox/rewrite/USI_UART.c
===================================================================
--- trunk/cardbox/swipebox/rewrite/USI_UART.c	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/USI_UART.c	(nonexistent)
@@ -1,227 +0,0 @@
-
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File              : USI_UART.c
-* Compiler          : IAR EWAAVR 2.28a
-* Created           : 18.07.2002 by JLL
-* Modified          : 02-10-2003 by LTA
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : ATtiny26
-*
-* Application Note  : AVR307 - Half duplex UART using the USI Interface
-*
-* Description       : Functions for USI_UART_receiver and USI_UART_transmitter.
-*                     Uses Pin Change Interrupt to detect incomming signals.
-*
-*
-****************************************************************************/
-
-//#include <avr/io.h>  // Note there is a bug in ioavr.h file that includes iotiny22.h instead of iotiny26.h.
-//#include <iotiny26.h>
-//#include <avr/interrupt.h>
-//#include <avr/signal.h>
-//#include "USI_UART_config.h"
-
-
-//********** USI UART Defines **********//
-#define RXPIN	PB5
-#define CLKPIN	PB7
-
-#define STARTFLAG 		0x45 //100 0101 //0x0B  //01011
-#define NSTARTFLAG		0x3A //011 1010 //0x14  //10100
-#define STOPFLAG      0x1F //001 1111  0x1F  //11111
-#define NSTOPFLAG		  0x60 //110 0000 0x00  //00000
-#define REVSTART      0x51 //101 0001  0x1A  //11010
-#define NREVSTART		  0x2E //010 1110 0x05  //00101
-
-#define DATA_BITS                 7
-#define START_BIT                 7
-#define STOP_BIT                  7
-#define HALF_FRAME                7
-
-
-#define USI_COUNTER_MAX_COUNT     16
-#define INTERRUPT_STARTUP_DELAY   (0x11 / TIMER_PRESCALER)
-
-#define USI_COUNTER_SEED_RECEIVE  ( USI_COUNTER_MAX_COUNT - (DATA_BITS*2) )
-
-/* General defines */
-#define TRUE                      1
-#define FALSE                     0
-
-//********** Static Variables **********//
-
-/*__no_init __regvar static unsigned char USI_UART_TxData[15];   // Tells the compiler to store the byte to be transmitted in registry.
-*/
-//static unsigned char			USI_UART_TxData;
-//static unsigned char          UART_RxByte;  // UART buffers. Size is definable in the header file.
-
-
-static volatile union USI_UART_status                           // Status byte holding flags.
-{
-    unsigned char status;
-    struct
-    {
-        unsigned char wait_Card:1;
-        unsigned char wait_Start:1;
-        unsigned char ongoing_Reception_Of_Package:1;
-        unsigned char reception_Buffer_Overflow:1;
-        unsigned char data_Ready:1;
-        unsigned char flag5:1;
-        unsigned char flag6:1;
-        unsigned char flag7:1;
-    };
-} USI_UART_status = {0};
-
-
-//********** USI_UART functions **********//
-
-// Reverses the order of bits in a byte.
-// I.e. MSB is swapped with LSB, etc.
-static inline unsigned char Bit_Reverse5( unsigned char x )
-{
-	unsigned char c = x&0x04;
-//	x = x<<3;
-    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-    return x;
-}
-
-static inline unsigned char Bit_Reverse( unsigned char x )
-{
-  unsigned char c=0;
-
-  c |=0x01&(x>>6);
-  c |=0x02&(x>>4);
-  c |=0x04&(x>>2);
-  c |=0x08&(x>>0);
-  c |=0x10&(x<<2);
-  c |=0x20&(x<<4);
-  c |=0x40&(x<<6);
-
-
-//	unsigned char c = x&0x08;
-//	x = x<<3;
-//    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-//    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-//    return x;
-
-  return c;
-}
-
-
-
-// Initialise USI for UART reception.
-// Note that this function only enables pinchange interrupt on the USI Data Input pin.
-// The USI is configured to read data within the pinchange interrupt.
-static inline void USI_UART_Initialise_Receiver( void ) {
-    // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)
-    PORTB |=   _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4);
-    // Set USI DI, DO and SCK pins as inputs.
-    DDRB  &= ~( _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4));
-    // Disable USI.
-    USICR = 0;
-    // Clear pin change interrupt flag.
-    EIFR = _BV(PCIF);
-	PCMSK |= _BV(RXPIN);
-	// Enable pin change interrupt for PB7:0.
-    GIMSK |= _BV(PCIE);
-
-	USI_UART_status.data_Ready=FALSE;
-	USI_UART_status.wait_Card=TRUE;
-	USI_UART_status.wait_Start=FALSE;
-	USI_UART_status.ongoing_Reception_Of_Package = FALSE;
-	RxIndex=0;
-}
-
-// Returns a byte from the receive buffer. Waits if buffer is empty.
-static inline unsigned char USI_UART_Receive_Bytes(void) {
-
-    while ( !USI_UART_status.data_Ready );                 // Wait for incomming data
-
-	USI_UART_status.data_Ready=FALSE;
-    return RxIndex;              // Reverse the order of the bits in the data byte before it returns data from the buffer.
-}
-
-// Check if there is data in the receive buffer.
-static inline unsigned char USI_UART_Data_In_Receive_Buffer(void) {
-    return (USI_UART_status.data_Ready);
-}
-
-// ********** Interrupt Handlers ********** //
-
-// The pin change interrupt is used to detect USI_UART reseption.
-// It is here the USI is configured to sample the UART signal.
-
-ISR(PCINT_vect)
-{
-   if ((USI_UART_status.wait_Card)&&(!( PINB & (1<<RXPIN) )))     // If the USI DI pin is low, then it is likely that it
-    {                                                             //  was this pin that generated the pin change interrupt.
-        USICR  = (0<<USISIE) | (1<<USIOIE) |                       // Enable USI Counter OVF interrupt.
-                 (0<<USIWM1) | (1<<USIWM0) |                      // Select Three Wire mode.
-                 (0<<USICS1) | (1<<USICS0) | (0<<USICLK) |        // Select Timer0 OVER as USI Clock source.
-                 (0<<USITC);
-                                                                  // Note that enabling the USI will also disable the pin change interrupt.
-        USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;                 // Clear all USI interrupt flags and preload the USI counter to generate interrupt.
-        PCMSK |= _BV(CLKPIN);
-        PCMSK &= ~_BV(RXPIN);
-
-        //GIMSK &=  ~(1<<PCIE);                                    // Disable pin change interrupt for PB3:0.
-        USI_UART_status.wait_Start = TRUE;
-        USI_UART_status.wait_Card = FALSE;
-
-    }
-	else if((USI_UART_status.wait_Start)&&(!(PINB&(1<<CLKPIN))))
-	{
-//	   	PORTD |= (1<<PD4);
-		if((USIDR&0x7F)==(NREVSTART))  /////////////MAYBE SHOULD BE REVSTART
-		{
-			USI_UART_status.wait_Start = FALSE;
-			USI_UART_status.ongoing_Reception_Of_Package = TRUE;
-			USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;                 // Clear all USI interrupt flags, preload the USI counter to generate an interrupt
-			GIMSK &= ~(1<<PCIE);
-			PCMSK &=~(1<<CLKPIN);
-		}
-	}
-}
-
-// The USI Counter Overflow interrupt is used for moving data between memmory and the USI data register.
-// The interrupt is used for both transmission and reception.
-ISR(SIG_USI_OVERFLOW) {
-
-  led_on(LED_YELLOW);
-
-    if(USI_UART_status.ongoing_Reception_Of_Package) {
-		char b;
-
-        //Byte comes in inverted and backwards, invert and reverse it to make it correct
-		b=Bit_Reverse(~USIDR)&0x0F;
-
-        //End character
-		if(b>9) {
-            USICR  =  0;                                // Disable USI.
-            EIFR   =  _BV(PCIF);                        // Clear pin change interrupt flag.
-		    USI_UART_status.data_Ready=TRUE;
-		} else {
-			//RxStream[RxIndex] = b;                      // Store received data in buffer. Note that the data must be bit reversed before used.
-			//RxIndex=RxIndex+1;
-
-			//WARNING: This is potentially dangerous if the card is larger than we expect. We should probably put some checks in here
-			// to prevent buffer
-			packet[RxIndex + HEADER_OFFSET] = b;
-			RxIndex++;
-			USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;   // Clear all USI interrupt flags and Preload the USI counter to generate interrupt.
-		}
-
-    }
-
-      led_on(LED_GREEN);
-}
Index: trunk/cardbox/swipebox/rewrite/uart.c
===================================================================
--- trunk/cardbox/swipebox/rewrite/uart.c	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/uart.c	(nonexistent)
@@ -1,114 +0,0 @@
-#include "uart.h"
-#include <avr/io.h>
-
-/** @file uart.c
- *
- *	@brief Implements UART functionality in hardware
- *
- *	@author Kevin Woo (kwoo)
- */
-static  void init_uart(int baud) {
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-
-	UCSRB = 0;
-	UCSRC = 0;
-
-	/* Enable RX/TX and RX/TX Interrupt */
-	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);
-
-	/* Asynchronous mode, 1 bit stop, 8bit transmissions */
-	UCSRC = _BV(UCSZ1) | _BV(UCSZ0);
-
- 	/* Enable RX pin as input */
-	PORTD &= ~RX;
-
-	/* Enable TX pin as output */
-	DDRD |= TX;
-
-	/* Enable the TXEN pin as output */
-	DDRB |= TX_EN;
-
-	/* RX Status Variables */
-	received_byte = 0;	//Initialize first byte
-	byte_ready = 0;		//Byte is not ready to be read
-
-	/* TX Status Variables */
-	transmitting = 0;
-	transmit_size = 0;
-}
-
-static char uart_get_byte(char *output_byte) {
-	while (!byte_ready) {
-		if (seconds == TIME_OUT) {
-		    timeout_flag = 1;
-		    return;
-	    }
-	}
-	*output_byte = received_byte;
-	return received_byte;
-
-
-	/*
-	if (byte_ready) {
-		*output_byte = received_byte;
-		byte_ready = 0;
-		return 0;
-	} else {
-		return -1;
-	}
-	*/
-}
-
-
-static void uart_puts (char* str, int len){
-  for(int i=0;i<len;i++){
-    uart_send_byte('@');//trash byte //TODO: figure out whats going on here
-    uart_send_byte(str[i]);
-  }
-}
-
-static void uart_send_byte (char data) {
-    //Wait for the UART line to not be busy sending
-	while (!(UCSRA & (1 << UDRE)));
-
-    //Enable RS485 Converter, give it time to turn on
-	uart_enable_transmit();
-    _delay_loop_2(8000);    //Approxmiately 2ms
-	//led_on(LED_RED);
-	UDR = data;
-	//led_on(LED_YELLOW);
-
-}
-
-
-static  void uart_enable_transmit() {
-    PINB |= TX_EN;
-}
-
-static  void uart_disable_transmit() {
-	PINB &= ~TX_EN;
-}
-
-ISR(USART_RX_vect) {
-	while(1);
-	received_byte = UDR;
-	byte_ready = 1;
-}
-
-ISR(USART_TX_vect) {
-	//static volatile char loc = 1;
-	//if (transmitting) {
-		//if (loc < transmit_size) {
-		//	UDR = transmit_data[loc];
-		//	loc++;
-		//} else {
-		//	loc = 1;
-			//transmitting = 0;
-			_delay_loop_2(8000);    //Approxmiately 2ms
-			uart_disable_transmit();
-			//led_on(LED_GREEN);
-		//}
-	//}
-}
Index: trunk/cardbox/swipebox/rewrite/Makefile
===================================================================
--- trunk/cardbox/swipebox/rewrite/Makefile	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/Makefile	(nonexistent)
@@ -1,507 +0,0 @@
-# Hey Emacs, this is a -*- makefile -*-
-#----------------------------------------------------------------------------
-# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
-#
-# Released to the Public Domain
-#
-# Additional material for this makefile was written by:
-# Peter Fleury
-# Tim Henigan
-# Colin O'Flynn
-# Reiner Patommel
-# Markus Pfaff
-# Sander Pool
-# Frederik Rouleau
-#
-#----------------------------------------------------------------------------
-# On command line:
-#
-# make all = Make software.
-#
-# make clean = Clean out built project files.
-#
-# make coff = Convert ELF to AVR COFF.
-#
-# make extcoff = Convert ELF to AVR Extended COFF.
-#
-# make program = Download the hex file to the device, using avrdude.
-#                Please customize the avrdude settings below first!
-#
-# make debug = Start either simulavr or avarice as specified for debugging,
-#              with avr-gdb or avr-insight as the front end for debugging.
-#
-# make filename.s = Just compile filename.c into the assembler code only.
-#
-# make filename.i = Create a preprocessed source file for use in submitting
-#                   bug reports to the GCC project.
-#
-# To rebuild project do "make clean" then "make all".
-#----------------------------------------------------------------------------
-
-
-# MCU name
-MCU = attiny2313
-
-
-# Processor frequency.
-#     This will define a symbol, F_CPU, in all source code files equal to the
-#     processor frequency. You can then use this symbol in your source code to
-#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
-#     automatically to create a 32-bit value in your source code.
-F_CPU = 8000000
-
-
-# Output format. (can be srec, ihex, binary)
-FORMAT = ihex
-
-
-# Target file name (without extension).
-TARGET = main
-
-# List C source files here. (C dependencies are automatically generated.)
-#SRC =  $(wildcard *.c)
-SRC = main.c uart.c USI_UART.c
-
-# List Assembler source files here.
-#     Make them always end in a capital .S.  Files ending in a lowercase .s
-#     will not be considered source files but generated files (assembler
-#     output from the compiler), and will be deleted upon "make clean"!
-#     Even though the DOS/Win* filesystem matches both .s and .S the same,
-#     it will preserve the spelling of the filenames, and gcc itself does
-#     care about how the name is spelled on its command-line.
-ASRC =
-
-
-# Optimization level, can be [0, 1, 2, 3, s].
-#     0 = turn off optimization. s = optimize for size.
-#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-OPT = s
-
-
-# Debugging format.
-#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
-#     AVR Studio 4.10 requires dwarf-2.
-#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
-DEBUG =
-
-
-# List any extra directories to look for include files here.
-#     Each directory must be seperated by a space.
-#     Use forward slashes for directory separators.
-#     For a directory that has spaces, enclose it in quotes.
-#EXTRAINCDIRS = C:\WinAVR\include\fwr
-
-
-# Compiler flag to set the C Standard level.
-#     c89   = "ANSI" C
-#     gnu89 = c89 plus GCC extensions
-#     c99   = ISO C99 standard (not yet fully implemented)
-#     gnu99 = c99 plus GCC extensions
-CSTANDARD = -std=gnu99
-
-
-# Place -D or -U options here
-CDEFS = -DF_CPU=$(F_CPU)UL
-
-
-# Place -I options here
-CINCS =
-
-
-
-#---------------- Compiler Options ----------------
-#  -g*:          generate debugging information
-#  -O*:          optimization level
-#  -f...:        tuning, see GCC manual and avr-libc documentation
-#  -Wall...:     warning level
-#  -Wa,...:      tell GCC to pass this to the assembler.
-#    -adhlns...: create assembler listing
-#CFLAGS = -g$(DEBUG)
-CFLAGS += $(CDEFS) $(CINCS)
-CFLAGS += -O$(OPT)
-CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-CFLAGS += -Wall -Wstrict-prototypes
-CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
-CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-CFLAGS += $(CSTANDARD)
-
-
-#---------------- Assembler Options ----------------
-#  -Wa,...:   tell GCC to pass this to the assembler.
-#  -ahlms:    create listing
-#  -gstabs:   have the assembler create line number information; note that
-#             for use in COFF files, additional information about filenames
-#             and function names needs to be present in the assembler source
-#             files -- see avr-libc docs [FIXME: not yet described there]
-ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
-
-
-#---------------- Library Options ----------------
-# Minimalistic printf version
-PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
-
-# Floating point printf version (requires MATH_LIB = -lm below)
-PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
-
-# If this is left blank, then it will use the Standard printf version.
-PRINTF_LIB =
-#PRINTF_LIB = $(PRINTF_LIB_MIN)
-#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
-
-
-# Minimalistic scanf version
-SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
-
-# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
-SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
-
-# If this is left blank, then it will use the Standard scanf version.
-SCANF_LIB =
-#SCANF_LIB = $(SCANF_LIB_MIN)
-#SCANF_LIB = $(SCANF_LIB_FLOAT)
-
-
-MATH_LIB = -lm
-
-
-
-#---------------- External Memory Options ----------------
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# used for variables (.data/.bss) and heap (malloc()).
-#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# only used for heap (malloc()).
-#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
-
-EXTMEMOPTS =
-
-
-
-#---------------- Linker Options ----------------
-#  -Wl,...:     tell GCC to pass this to linker.
-#    -Map:      create map file
-#    --cref:    add cross reference to  map file
-LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
-LDFLAGS += $(EXTMEMOPTS)
-LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
-
-
-
-#---------------- Programming Options (avrdude) ----------------
-
-# Programming hardware: alf avr910 avrisp bascom bsd
-# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
-#
-# Type: avrdude -c ?
-# to get a full listing.
-#
-AVRDUDE_PROGRAMMER = avrispmkII
-
-# com1 = serial port. Use lpt1 to connect to parallel port.
-AVRDUDE_PORT = usb
-# programmer connected to serial device
-
-AVRDUDE_WRITE_FLASH = -b 19200 -U flash:w:$(TARGET).hex #speed was 4800
-#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
-
-
-# Uncomment the following if you want avrdude's erase cycle counter.
-# Note that this counter needs to be initialized first using -Yn,
-# see avrdude manual.
-#AVRDUDE_ERASE_COUNTER = -y
-
-# Uncomment the following if you do /not/ wish a verification to be
-# performed after programming the device.
-#AVRDUDE_NO_VERIFY = -V
-
-# Increase verbosity level.  Please use this when submitting bug
-# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
-# to submit bug reports.
-#AVRDUDE_VERBOSE = -v -v
-
-AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -F
-AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
-AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
-AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
-
-
-
-#---------------- Debugging Options ----------------
-
-# For simulavr only - target MCU frequency.
-DEBUG_MFREQ = $(F_CPU)
-
-# Set the DEBUG_UI to either gdb or insight.
-# DEBUG_UI = gdb
-DEBUG_UI = insight
-
-# Set the debugging back-end to either avarice, simulavr.
-DEBUG_BACKEND = avarice
-#DEBUG_BACKEND = simulavr
-
-# GDB Init Filename.
-GDBINIT_FILE = __avr_gdbinit
-
-# When using avarice settings for the JTAG
-JTAG_DEV = /dev/com1
-
-# Debugging port used to communicate between GDB / avarice / simulavr.
-DEBUG_PORT = 4242
-
-# Debugging host used to communicate between GDB / avarice / simulavr, normally
-#     just set to localhost unless doing some sort of crazy debugging when
-#     avarice is running on a different computer.
-DEBUG_HOST = localhost
-
-
-
-#============================================================================
-
-
-# Define programs and commands.
-SHELL = sh
-CC = avr-gcc
-OBJCOPY = avr-objcopy
-OBJDUMP = avr-objdump
-SIZE = avr-size
-NM = avr-nm
-AVRDUDE = avrdude
-REMOVE = rm -f
-COPY = cp
-WINSHELL = cmd
-
-
-# Define Messages
-# English
-MSG_ERRORS_NONE = Errors: none
-MSG_BEGIN = -------- begin --------
-MSG_END = --------  end  --------
-MSG_SIZE_BEFORE = Size before:
-MSG_SIZE_AFTER = Size after:
-MSG_COFF = Converting to AVR COFF:
-MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
-MSG_FLASH = Creating load file for Flash:
-MSG_EEPROM = Creating load file for EEPROM:
-MSG_EXTENDED_LISTING = Creating Extended Listing:
-MSG_SYMBOL_TABLE = Creating Symbol Table:
-MSG_LINKING = Linking:
-MSG_COMPILING = Compiling:
-MSG_ASSEMBLING = Assembling:
-MSG_CLEANING = Cleaning project:
-
-
-
-
-# Define all object files.
-OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
-
-# Define all listing files.
-LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
-
-
-# Compiler flags to generate dependency files.
-GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
-
-
-# Combine all necessary flags and optional flags.
-# Add target processor to flags.
-ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
-
-
-
-
-
-# Default target.
-all: begin gccversion sizebefore build sizeafter end
-
-build: elf hex eep lss sym
-
-elf: $(TARGET).elf
-hex: $(TARGET).hex
-eep: $(TARGET).eep
-lss: $(TARGET).lss
-sym: $(TARGET).sym
-
-
-
-# Eye candy.
-# AVR Studio 3.x does not check make's exit code but relies on
-# the following magic strings to be generated by the compile job.
-begin:
-	@echo
-	@echo $(MSG_BEGIN)
-
-end:
-	@echo $(MSG_END)
-	@echo
-
-
-# Display size of file.
-HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
-ELFSIZE = $(SIZE) -A $(TARGET).elf
-AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
-
-sizebefore:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-sizeafter:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-
-
-# Display compiler version information.
-gccversion :
-	@$(CC) --version
-
-
-
-# Program the device.
-program: $(TARGET).hex $(TARGET).eep
-	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
-
-# Generate avr-gdb config/init file which does the following:
-#     define the reset signal, load the target file, connect to target, and set
-#     a breakpoint at main().
-gdb-config:
-	@$(REMOVE) $(GDBINIT_FILE)
-	@echo define reset >> $(GDBINIT_FILE)
-	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
-	@echo end >> $(GDBINIT_FILE)
-	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
-	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
-ifeq ($(DEBUG_BACKEND),simulavr)
-	@echo load  >> $(GDBINIT_FILE)
-endif
-	@echo break main >> $(GDBINIT_FILE)
-
-debug: gdb-config $(TARGET).elf
-ifeq ($(DEBUG_BACKEND), avarice)
-	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
-	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
-	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
-	@$(WINSHELL) /c pause
-
-else
-	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
-	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
-endif
-	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
-
-
-
-
-# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
-COFFCONVERT=$(OBJCOPY) --debugging \
---change-section-address .data-0x800000 \
---change-section-address .bss-0x800000 \
---change-section-address .noinit-0x800000 \
---change-section-address .eeprom-0x810000
-
-
-coff: $(TARGET).elf
-	@echo
-	@echo $(MSG_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
-
-
-extcoff: $(TARGET).elf
-	@echo
-	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
-
-
-
-# Create final output files (.hex, .eep) from ELF output file.
-%.hex: %.elf
-	@echo
-	@echo $(MSG_FLASH) $@
-	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
-
-%.eep: %.elf
-	@echo
-	@echo $(MSG_EEPROM) $@
-	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
-	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
-
-# Create extended listing file from ELF output file.
-%.lss: %.elf
-	@echo
-	@echo $(MSG_EXTENDED_LISTING) $@
-	$(OBJDUMP) -h -S $< > $@
-
-# Create a symbol table from ELF output file.
-%.sym: %.elf
-	@echo
-	@echo $(MSG_SYMBOL_TABLE) $@
-	$(NM) -n $< > $@
-
-
-
-# Link: create ELF output file from object files.
-.SECONDARY : $(TARGET).elf
-.PRECIOUS : $(OBJ)
-%.elf: $(OBJ)
-	@echo
-	@echo $(MSG_LINKING) $@
-	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
-
-
-# Compile: create object files from C source files.
-%.o : %.c
-	@echo
-	@echo $(MSG_COMPILING) $<
-	$(CC) -c $(ALL_CFLAGS) $< -o $@
-
-
-# Compile: create assembler files from C source files.
-%.s : %.c
-	$(CC) -S $(ALL_CFLAGS) $< -o $@
-
-
-# Assemble: create object files from assembler source files.
-%.o : %.S
-	@echo
-	@echo $(MSG_ASSEMBLING) $<
-	$(CC) -c $(ALL_ASFLAGS) $< -o $@
-
-# Create preprocessed source for use in sending a bug report.
-%.i : %.c
-	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
-
-
-# Target: clean project.
-clean: begin clean_list end
-
-clean_list :
-	@echo
-	@echo $(MSG_CLEANING)
-	$(REMOVE) $(TARGET).hex
-	$(REMOVE) $(TARGET).eep
-	$(REMOVE) $(TARGET).cof
-	$(REMOVE) $(TARGET).elf
-	$(REMOVE) $(TARGET).map
-	$(REMOVE) $(TARGET).sym
-	$(REMOVE) $(TARGET).lss
-	$(REMOVE) $(OBJ)
-	$(REMOVE) $(LST)
-	$(REMOVE) $(SRC:.c=.s)
-	$(REMOVE) $(SRC:.c=.d)
-	$(REMOVE) .dep/*
-
-
-
-# Include the dependency files.
--include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
-
-
-# Listing of phony targets.
-.PHONY : all begin finish end sizebefore sizeafter gccversion \
-build elf hex eep lss sym coff extcoff \
-clean clean_list program debug gdb-config
-
Index: trunk/cardbox/swipebox/rewrite/uart.h
===================================================================
--- trunk/cardbox/swipebox/rewrite/uart.h	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/uart.h	(nonexistent)
@@ -1,50 +0,0 @@
-/** @file uart.h
- *
- *	@brief Initializes UART functions using the UART hardware module
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef UART_H
-#define UART_H
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-
-/** **/
-#define UART_TX_OFF 0
-#define UART_TX_ON 1
-
-/** @brief RX Pin for the UART **/
-#define RX		_BV(PD0)
-#define TX		_BV(PD1)
-#define TX_EN	_BV(PB1)
-
-
-/** @brief The most recently received byte **/
-extern char received_byte;
-/** @brief If the value in received_byte has been read or not **/
-extern volatile char	byte_ready;
-//extern static char *transmit_data;
-extern char transmit_size;
-extern volatile char transmitting;
-extern volatile char seconds;		//Seconds elapsed
-extern volatile char minutes;		//Minutes exlapsed
-
-
-/** @brief Initializes the UART registers and sets it to the buad rate which msut be the
- *			value that is defined in the datasheet for any particular speed (ie: 51 -> 9600bps)
- **/
-static void init_uart(int baud);
-/** @brief Gets latest byte and returns it in output_byte. If the byte was already read, returns -1
- *			otherwise it returns 0
- **/
-static char uart_get_byte(char *output_byte);
-/** @brief Sends a character array of size size. If we are currently transmitting it will block until the
-  * 	the current transmit is done.
-  **/
-static void uart_send_byte(char data);
-static void uart_enable_transmit(void);
-static void uart_disable_transmit(void);
-static void uart_puts(char* str, int len);
-#endif
Index: trunk/cardbox/swipebox/rewrite/timer.c
===================================================================
--- trunk/cardbox/swipebox/rewrite/timer.c	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/timer.c	(nonexistent)
@@ -1,75 +0,0 @@
-/** @file timer.c
- * 
- *  @brief Implements the timer functions. See timer.h for full details
- *
- * 	@author Kevin Woo (kwoo)
- */
- 
-#include "timer.h"
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-
-volatile char seconds;		//Seconds elapsed
-volatile char minutes;		//Minutes exlapsed
-char timeout_flag; //Indicates that timeout has occured
-
-//Initializes all the timer1 registers
-void init_timer() {
-	//Clears the control registers for timer 1
-	TCCR1A = 0x00;
-	TCCR1B = 0x00;
-	TCCR1C = 0x00;
-	TIMSK = 0x00;
-	
-	/*****
-	 * Output control register A set to clear timer on compare match.
-	 * Output control register B not connected.
-	 * WGM is in normal operation.
-	 * Clock is divided by 256. (This sets it to disconnected, connects
-	 *   in start_timer to above value).
-	 *****/
-	TCCR1A |= _BV(COM1A1);
-	
-	//Compares at 1 second with an 8MHz Clock and a 256 prescale. (31250)
-	OCR1AH = 0x7A;
-	OCR1AL = 0x12;
-	
-	//Enable the output compare register 1A interrupt
-	TIMSK |= _BV(OCIE1A);
-	
-	timeout_flag = 0;
-	
-	return;
-}
-
-void start_timer() {
-	//Enables the timer. Sets prescale to 256.
-	TCCR1B |= _BV(CS12);
-	
-	return;
-}
-
-void stop_timer() {
-	//Disables timer.
-	TCCR1B &= ~_BV(CS12);
-	seconds = 0;
-	minutes = 0;
-	
-	return;
-}
-
-void reset_timer() {
-	seconds = 0;
-	minutes = 0;
-	return;
-}
-
-ISR(TIMER1_COMP1_vect) {
-	if (seconds == 59) {
-		minutes++;
-		seconds = 0;
-	} else {
-		seconds++;
-	}
-}
Index: trunk/cardbox/swipebox/rewrite/main.c
===================================================================
--- trunk/cardbox/swipebox/rewrite/main.c	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/main.c	(nonexistent)
@@ -1,67 +0,0 @@
-/** @file main.c
- *  @brief Contains the functionality for the cardswipe board
- *
- *  @author Suresh Nidhiry (snidhiry), Kevin Woo (kwoo), Brad Neuman (bneuman)
- **/
-
-/******** Includes **********/
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-
-#include "USI_UART_config.h"
-#include "uart.h"
-#include "io_mine.h"
-
-
-/******** defines **********/
-#define BAUD            51          //9600bps
-
-/***** Transmit Defines *****/
-/** @brief Maximum size that the cardID + tool number can be in bytes */
-#define MAX_DATA_SIZE	10			//9 card digits, 1 byte for tool number
-/** @brief Maximum size that a cardID can be in bytes */
-#define MAX_CARD_SIZE	9			//9 card digits
-/** @brief How long a packet is before the payload section. Used for offsets */
-#define HEADER_OFFSET   2
-/** @brief Maximum size that a packet can be */
-#define MAX_PACKET_SIZE HEADER_OFFSET + MAX_DATA_SIZE
-/** @brief Baud rate for the rs485 network. This must be uniform across card, tool, and server */
-#define BAUD            51          //9600bps
-/** @brief The default server id that we send our requests to */
-#define DEFAULT_SERVER  254
-
-
-/***** Global Variables *****/ //TODO:  figure out where these belong
- char received_byte;	        //Byte received
- volatile char byte_ready;	//New byte has been received
- char transmit_size;	        //Size of string that we are sending
- volatile char transmitting;  //Flag to indicate that we are currently sending data
- volatile char seconds;		//Seconds elapsed
- volatile char minutes;		//Minutes exlapsed
- char timeout_flag;           //Indicates that timeout has occured
- char packet[MAX_PACKET_SIZE];   //Buffer for creating a packet
-
-/********* local functions *********/
-
-// Sets directions of pins for basic output
-static inline void init_pins() {
-	DDRB |= RELAY;
-	DDRD |= LED_RED | LED_YELLOW | LED_GREEN;
-
-	return;
-}
-
-
-int main(void) {
-
-  init_pins();
-  init_uart(BAUD);
-  //USI_UART_Initialise_Receiver();	//Set registers for Card reader;
-
-  uart_puts("hello world\n",11);
-
-  while(1);
-
-  return 0;
-}
Index: trunk/cardbox/swipebox/rewrite/io_mine.h
===================================================================
--- trunk/cardbox/swipebox/rewrite/io_mine.h	(revision 133)
+++ trunk/cardbox/swipebox/rewrite/io_mine.h	(nonexistent)
@@ -1,67 +0,0 @@
-/** @file io.h
- *
- *	@brief Implements IO functionality such as turning LEDs on
- *			and off, turning the relays on or off, and returning
- *			button values
- *	
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef IO_H
-#define IO_H
-
-#include <avr/io.h>
-#include "timer.h"
-
-/* Pin Defines */
-/** @brief Pin that turns the relay on/off */
-#define RELAY 				_BV(PB3)
-/** @brief Red LED Pin*/
-#define LED_RED				_BV(PD6)
-/** @brief Yellow LED Pin*/
-#define LED_YELLOW			_BV(PD5)
-/** @brief Green LED Pin*/
-#define LED_GREEN			_BV(PD4)
-/** @brief Black Button Pin*/
-#define BUTTON_BLACK		_BV(PD2)
-/** @brief How much to shift out of the port that Black button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_BLACK_SHIFT	0x02
-/** @brief Red Button Pin*/
-#define BUTTON_RED			_BV(PD3)
-/** @brief How much to shift out of the port that Red button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_RED_SHIFT	0x03
-
-/* Keypad definitions */
-/** @brief ROW1 of the keypad */
-#define ROW1 _BV(PD2)
-/** @brief ROW2 of the keypad */
-#define ROW2 _BV(PD3)
-/** @brief ROW3 of the keypad */
-#define ROW3 _BV(PA1)
-/** @brief ROW4 of the keypad */
-#define ROW4 _BV(PA0)
-/** @brief COL1 of the keypad */
-#define COL1 _BV(PB6)
-/** @brief COL2 of the keypad */
-#define COL2 _BV(PB4)
-/** @brief COL3 of the keypad */
-#define COL3 _BV(PB2)
-/** @brief COL4 of the keypad */
-#define COL4 _BV(PB0)
-
-
-/** @brief Sets the direction of the pins */
-static inline void init_pins(void);
-/** @brief Toggles the relay on or off. state == 1 is on, state == 0 is off */
-static inline void toggle_power_on(void);
-static inline void toggle_power_off(void);
-/** @brief Sets the state of the given LED (which) to state where state == 1 is on, state == 0 is off */
-static inline void toggle_led_on(char which);
-static inline void toggle_led_off(char which);
-/** @brief Reads the value of the black button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_black(void);
-/** @brief Reads the value of the red button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_red(void);
-/** @brief Waits until a button the keypad is pressed. Uses the timer to time out the loop in case none is selected */
-static char get_button(void);
-#endif
Index: trunk/cardbox/swipebox/main.c
===================================================================
--- trunk/cardbox/swipebox/main.c	(revision 133)
+++ trunk/cardbox/swipebox/main.c	(nonexistent)
@@ -1,927 +0,0 @@
-/** @file main.c
- *  @brief Contains the functionality for the cardswipe board
- *
- *  @author Suresh Nidhiry (snidhiry), Kevin Woo (kwoo), Brad Neuman (bneuman)
- **/
-
-/* Includes */
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-
-//#include "USI_UART_config.h"
-//#include "uart.h"
-//#include "timer.h"
-//#include "io_mine.h"
-
-
-/***** Debug Defines *****/
-#define debug
-
-
-/***** Pin Defines *****/
-/** @brief Pin that turns the relay on/off */
-#define RELAY 				_BV(PB3)
-/** @brief Red LED Pin*/
-#define LED_RED				_BV(PD6)
-/** @brief Yellow LED Pin*/
-#define LED_YELLOW			_BV(PD5)
-/** @brief Green LED Pin*/
-#define LED_GREEN			_BV(PD4)
-/** @brief Black Button Pin*/
-#define BUTTON_BLACK		_BV(PD2)
-/** @brief How much to shift out of the port that Black button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_BLACK_SHIFT	0x02
-/** @brief Red Button Pin*/
-#define BUTTON_RED			_BV(PD3)
-/** @brief How much to shift out of the port that Red button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_RED_SHIFT	0x03
-/** @brief RX Pin for the UART **/
-#define RX		_BV(PD0)
-/** @brief TX Pin for the UART **/
-#define TX		_BV(PD1)
-/** @brief TX Enable Pin for the UART **/
-#define TX_EN	_BV(PB1)
-
-
-/***** Self Identity *****/
-/** @brief This is the ADDRESS. Make sure it conforms to Tooltron specs */
-#define ADDR			253
-
-/***** Transmit Defines *****/
-/** @brief Maximum size that the cardID + tool number can be in bytes */
-#define MAX_DATA_SIZE	10			//9 card digits, 1 byte for tool number
-/** @brief Maximum size that a cardID can be in bytes */
-#define MAX_CARD_SIZE	9			//9 card digits
-/** @brief How long a packet is before the payload section. Used for offsets */
-#define HEADER_OFFSET   2
-/** @brief Maximum size that a packet can be */
-#define MAX_PACKET_SIZE HEADER_OFFSET + MAX_DATA_SIZE
-/** @brief Baud rate for the rs485 network. This must be uniform across card, tool, and server */
-#define BAUD            51          //9600bps
-/** @brief The default server id that we send our requests to */
-#define DEFAULT_SERVER  254
-
-/***** USI_UART Defines *****/
-/** @brief The frequency of the clock in Hz */
-#define SYSTEM_CLOCK        8000000
-/** @brief The baudrate that the USI_UART module runs at */
-#define BAUDRATE            9600
-#define TIMER_PRESCALER           8     
-#define UART_RX_BUFFER_SIZE        4     /* 2,4,8,16,32,64,128 or 256 bytes */
-#define UART_TX_BUFFER_SIZE        4
-
-/***** Time Defines *****/
-/** @brief Max time in seconds to leave a red or green light on */
-#define MAX_LED_ON      5
-/** @brief Max time that we can wait for a full packet from the server before we timeout */
-#define TIME_OUT		5
-
-/***** States for for the main cardbox FSM *****/
-/** @brief Wait until a card is swiped and store the card id */
-#define INIT_CARD_READ		0x01
-/** @brief Wait until a tool is selected and store it */
-#define INIT_TOOL_READ		0x02
-/** @brief Send packet and then monitor line to see if the server accepts or denies the request */
-#define TXRX_DATA		    0x03
-/** @brief Run the fail subroutine if we were denied. Return to INIT_CARD_READ */
-#define FAIL				0x04
-#define COPY_FROM_BUF       0x05
-
-/***** States For Packet Parsing *****/
-/** @brief No state */
-#define NONE				0x00
-/** @brief Waiting for the first byte of the header to be received */
-#define HEAD				0x01
-/** @breif Waiting for the first byte of this addr to be received */
-#define DEST				0x02
-/** @brief Receive data */
-#define DATA				0x03 
-
-/***** Main Function Prototypes *****/
-static inline void success(void);
-static inline void fail(void);
-static void get_packet(char* dest, char* data);
-
-/***** IO Function Prototypes *****/
-/** @brief Sets the direction of the pins */
-static inline void init_pins(void);
-/** @brief Toggles the relay on or off. state == 1 is on, state == 0 is off */
-static inline void power_on(void);
-static inline void power_off(void);
-/** @brief Sets the state of the given LED (which) to state where state == 1 is on, state == 0 is off */
-static inline void led_on(char which);
-static inline void led_off(char which);
-
-//TODO: should red and black buttons go in the keybox?
-
-/** @brief Reads the value of the black button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_black(void);
-/** @brief Reads the value of the red button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_red(void);
-
-
-/***** Timer Function Prototypes *****/
-/** @brief Sets the registers to use the timer for couting in real time */
-static inline void init_timer(void);
-/** @brief Starts the timer from last position */
-static inline void start_timer(void);
-/** @brief Stops the timer from counting */
-static inline void stop_timer(void);
-/** @brief Resets the values of the timer to 0 */
-static inline void reset_timer(void);
-
-/***** UART Function Prototypes *****/
-/** @brief Initializes the UART registers and sets it to the buad rate which msut be the 
- *			value that is defined in the datasheet for any particular speed (ie: 51 -> 9600bps)
- **/
-static inline void init_uart(int baud);
-/** @brief Gets latest byte and returns it in output_byte. If the byte was already read, returns -1 
- *			otherwise it returns 0 
- **/
-static inline void uart_get_byte(char *output_byte);
-/** @brief Send one byte of data. If we are currently transmitting it will block until the
-  * 	the current transmit is done. 
-  **/
-static void uart_send_byte(char data);
-/** @brief send len bytes from str
- **/
-static void uart_puts (char* str, int len);
-/** @brief Enable the RS485 Converter chip to transmit. Must give it about 1ms-2ms to propogate through */
-static inline void uart_enable_transmit(void);
-/** @brief Disable the RS485 Converter chip to transmit. Must give it about 1ms-2ms to propogate through */
-static inline void uart_disable_transmit(void);
-
-//***** USI_UART Prototypes *****//
-//static unsigned char			RxStream[100];
-
-static unsigned char 			RxIndex;
-static inline unsigned char USI_UART_Receive_Bytes( void );
-static inline unsigned char USI_UART_Data_In_Receive_Buffer( void );
-static inline unsigned char Bit_Reverse( unsigned char );
-static inline void          USI_UART_Initialise_Receiver( void );
-
-/***** Global Variables *****/
-static char received_byte;	        //Byte received
-static volatile char byte_ready;	//New byte has been received
-static char transmit_size;	        //Size of string that we are sending
-static volatile char transmitting;  //Flag to indicate that we are currently sending data
-static volatile char seconds;		//Seconds elapsed
-static volatile char minutes;		//Minutes exlapsed
-static char timeout_flag;           //Indicates that timeout has occured
-static char packet[MAX_PACKET_SIZE];   //Buffer for creating a packet
-
-/***********************************************************/
-
-int main(void) {
-
-	char dest = 0;
-	char data;
-	char position;                  //Tracks the position in data array we will send to the server
-	char i;                         //General purpose counter
-	char state;                     //State for FSM
-
-	/***** Start Start-up Sequence *****/
-	sei();				//Enable interrupts
-
-	//init_timer();		//Set registers for timer
-	init_pins();		//Set pin directions //TODO: remove pin setup for the keypad
-	init_uart(BAUD);	//Set registers for uart
-	USI_UART_Initialise_Receiver();	//Set registers for Card reader
-
-	
-	position = 0;   	//What card number digit we are on, goes 0 - 8
-	state = INIT_CARD_READ;
-	//start_timer();
-	//reset_timer();
-	/***** End Start-up Sequence *****/
-	
-	/* Pregenerate the first 8 bits of the packet because they will
-	 *  always be the same. If they are overwritten you know there's
-	 *  a bug. 
-	 */
-	packet[0] = '~';
-	packet[1] = DEFAULT_SERVER;
-
-#ifdef debug
-	uart_puts("\n\nentering loop\n",17);
-#endif
-
-
-	//Main loop. We should never exit this or bad things will happen.
-	while(1) {
-		switch(state) {
-			//Wait until we get something 
-			case INIT_CARD_READ:
-				timeout_flag = 0;
-#ifdef debug
-       uart_puts("INIT_CARD_READ:{",17);
-#endif
-
-			    packet[MAX_PACKET_SIZE] = 255;  //Clear so we know when we get a valid tool number later
-			    led_on(LED_RED);
-			    //Wait for the cardreader to send us bytes, fill them into the data array
-
-			    //packet[position + HEADER_OFFSET] = USI_UART_Receive_Bytes(); 
-                led_on(LED_RED);
-
-		i = USI_UART_Receive_Bytes();
-
-#ifdef debug
-		uart_puts("recvd ",6);
-		uart_send_byte(i+48);
-		uart_send_byte(i+48);
-#endif
-
-			    //position = 0;
-			    //for (position = 0; position < i; position++) {
-			    //    packet[position + HEADER_OFFSET] = RxStream[position];
-			    //}
-
-                //memcpy(packet[HEADER_OFFSET], RxStream, i);
-
-		uart_puts(packet+HEADER_OFFSET,i);
-
-
-		//old code below
-		//                for (int a = 0; a < i; a++) {
-		//                    uart_send_byte(packet[a + HEADER_OFFSET]);
-		//                    led_on(LED_YELLOW);
-		//                }
-
-                led_on(LED_GREEN);
-#ifdef debug
-		uart_puts("}done\n",6);
-#endif
-
-				//state = INIT_TOOL_READ;
-				break;
-			
-			
-			//Wait until we get a tool to use
-		case INIT_TOOL_READ:
-		  //Turn on Yellow LED to indicate that we are waiting for the user to press a button
-		  led_on(LED_YELLOW);
-		  reset_timer();
-		  
-/* 		  /\*****This is for the actual keypad *****\/ */
-		  
-/* 		  //Wait until we get a button press. Only continue if its valid */
-/* 		  while((packet[position + HEADER_OFFSET] = get_button()) != 255) { */
-/* 		    if (seconds == TIME_OUT) { */
-/* 		      timeout_flag = 1; */
-/* 		      break; */
-/* 		    } */
-/* 		  } */
-				/*
-				//Temporary
-	            while (1) {
-                    reset_timer();
-                    //start_timer();
-
-                    if (seconds == TIME_OUT) {
-                        timeout_flag = 1;
-                        break;
-                    }
-
-			        if (read_button_black()) {
-			            packet[MAX_PACKET_SIZE - 1] = 1;
-			            break;
-			        } else if (read_button_red()) {
-			            packet[MAX_PACKET_SIZE - 1] = 2;
-			            break;
-			        }
-			    }
-
-				//If the use took too long fail
-				if (timeout_flag) {;
-				    timeout_flag = 0;
-				    state = FAIL;
-				}    
-			   */ 
-			   
-				state = TXRX_DATA;
-				break;
-				
-			//Recieve Data
-			case TXRX_DATA:
-			    for (i = 0; i < MAX_PACKET_SIZE; i++) {
-			        uart_send_byte(packet[i]);
-			    }
-				//uart_send_bytes(packet, MAX_PACKET_SIZE); 
-
-			    //Parse the server packet
-				get_packet(&dest, &data);
-				
-				/* We will only succeed if the server sends a turn on packet to the tool we
-				 *  designated. Since we are the master, we should not catch any other 
-				 *  packets on the line. If they happen at the same time we are listening
-				 *  for an ack, we will probably fail on the packet parsing and assume that
-				 *  the tool failed and provide feedback as such.
-				 */
-				if (dest == packet[MAX_PACKET_SIZE] && !timeout_flag) {
-				        success();
-				        state = INIT_CARD_READ;
-				} else {
-				    timeout_flag = 0;
-				    state = FAIL;
-				}
-				break;
-
-			//Failure! Provide visual feedback that you fail
-			case FAIL:
-				fail();
-				state = INIT_CARD_READ;
-				break;
-			
-			//We should never get here. If you do, Tooltron explodes
-			default:
-				state = INIT_CARD_READ;
-				break;
-		}
-	}
-	
-	//If you get here, all the tools are sent the SIGEXPLODE interrupt.
-	return 0;
-}
-
-/** @brief Turns off the yellow led and turns on the green led for MAX_LED_ON seconds.
- *      Requires the timer to initialized and started, though not neccessarily cleared.
- *      Will turn off the green LED when done. Timer will still be running when done.
- */
-static inline void success() {
-    //Clear the timer and count the seconds
-	reset_timer();
-
-	led_off(LED_YELLOW);
-	led_on(LED_GREEN);
-	
-	while (seconds < MAX_LED_ON);
-	
-	led_off(LED_GREEN);
-	return;
-}
-
-/** @brief Turns off the yellow led and turns on the red led for MAX_LED_ON seconds.
- *      Requires the timer to initialized and started, though not neccessarily cleared.
- *      Will turn off the red LED when done. Timer will still be running when done.
- */
-static inline void fail() {
-    //Clear the timer and count the seconds
-	reset_timer();
-
-	led_off(LED_YELLOW);
-    led_on(LED_RED);
-	
-	while (seconds <= MAX_LED_ON);
-	
-	led_off(LED_RED);
-	return;
-}
-
-/** @brief Listens to the data bus and parses the inputs as long as they are valid
- *      Tooltron packets. Fills dest and data with the dest and data respectively.
- *      If the server does not respond in TIME_OUT seconds, it assers the timeout_flag and returns.
- *  @param dest the destination that is sent.
- *  @param data the 1 byte of data transmitted with the packet
- */
-static void get_packet(char* dest, char* data) {
-	char current_char = 0;  //Last byte read in
-	char state = HEAD;      //Our current read state
-	
-	//Get timer ready to calculate if we timeout
-	reset_timer();
-	
-	while(1) {
-	    //It's a race against the clock. Don't let it time out.
-		//if (seconds == TIME_OUT) {
-		//	timeout_flag = 1;
-		//	return;
-		//}
-	    
-	    uart_get_byte(&current_char);
-	    if (timeout_flag) {
-	        return;
-	    } else { 
-		//if (!uart_get_byte(&current_char)) {
-			switch(state) {
-				case HEAD:						//First header byte received?
-					if (current_char == '~') {
-						state = DEST;
-					}	
-					break;
-					
-				case DEST:
-					*dest = current_char;
-					state = DATA;
-					break;
-					
-				case DATA:
-				    *data = current_char;
-				    return;
-				    
-				default:
-					state = HEAD;
-					break;
-			}
-		}
-	}
-	
-	return;
-}
-
-/** @file io.c
- *
- *	@brief Implements IO functionality like turning lights, relays on or off
- *			or reading button values
- *
- *	@author Kevin Woo (kwoo)
- */
-
-
-//Sets directions of pins
-static inline void init_pins() {
-	DDRB |= RELAY;
-	DDRD |= LED_RED | LED_YELLOW | LED_GREEN;
-	
-	return;	
-}
-
-//Will turn the relay on or off. 1 will turn it on, 0 will turn it off.
-static inline void power_on() {
-	PORTB |= RELAY;
-}
-
-static inline void power_off() {
-    PORTB &= ~RELAY;
-}
-
-//Turns on an off an LED. which should be the defined pins (1 byte) and
-// state is: 1 -> on, 0 -> off
-static inline void led_on(char which) {
-    PORTD |= which;
-	return;
-}
-
-static inline void led_off(char which) {
-	PORTD &= ~which;
-	return;
-}
-
-static inline char read_button_black() {
-	return ((PINB & BUTTON_BLACK) >> BUTTON_BLACK_SHIFT);
-}
-
-
-static inline char read_button_red() {
-	return ((PINB & BUTTON_RED) >> BUTTON_RED_SHIFT);
-}
-
-
-/** @file timer.c
- * 
- *  @brief Implements the timer functions. See timer.h for full details
- *
- * 	@author Kevin Woo (kwoo)
- */
- 
-
-
-//Initializes all the timer1 registers
-static inline void init_timer() {
-	//Clears the control registers for timer 1
-	TCCR1A = 0x00;
-	TCCR1B = 0x00;
-	TCCR1C = 0x00;
-	TIMSK = 0x00;
-	
-	/*****
-	 * Output control register A set to clear timer on compare match.
-	 * Output control register B not connected.
-	 * WGM is in normal operation.
-	 * Clock is divided by 256. (This sets it to disconnected, connects
-	 *   in start_timer to above value).
-	 *****/
-	TCCR1A |= _BV(COM1A1);
-	
-	//Compares at 1 second with an 8MHz Clock and a 256 prescale. (31250)
-	OCR1AH = 0x7A;
-	OCR1AL = 0x12;
-	
-	//Enable the output compare register 1A interrupt
-	TIMSK |= _BV(OCIE1A);
-
-    //Initialize the time
-	seconds = 0;
-	minutes = 0;
-	
-	//Enable timer
-	TCCR1B |= _BV(CS12);
-		
-	timeout_flag = 0;
-	return;
-}
-
-static inline void start_timer() {
-	//Enables the timer. Sets prescale to 256.
-	TCCR1B |= _BV(CS12);
-}
-
-static inline void stop_timer() {
-	//Disables timer.
-	TCCR1B &= ~_BV(CS12);
-	//seconds = 0;
-	//minutes = 0;
-}
-
-static inline void reset_timer() {
-	seconds = 0;
-	minutes = 0;
-}
-
-ISR( TIMER1_COMPA_vect) {
-	if (seconds == 59) {
-		minutes++;
-		seconds = 0;
-	} else {
-		seconds++;
-	}
-}
-
-/** @file uart.c
- *	
- *	@brief Implements UART functionality in hardware
- *
- *	@author Kevin Woo (kwoo)
- */
-static inline void init_uart(int baud) {
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-
-	UCSRB = 0;
-	UCSRC = 0;
-
-	/* Enable RX/TX and RX/TX Interrupt */
-	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);
-	
-	/* Asynchronous mode, 1 bit stop, 8bit transmissions */
-	UCSRC = _BV(UCSZ1) | _BV(UCSZ0);
- 
- 	/* Enable RX pin as input */
-	PORTD &= ~RX;
-	
-	/* Enable TX pin as output */
-	DDRD |= TX;
-	
-	/* Enable the TXEN pin as output */
-	DDRB |= TX_EN;
-	
-	/* RX Status Variables */
-	received_byte = 0;	//Initialize first byte
-	byte_ready = 0;		//Byte is not ready to be read	
-	
-	/* TX Status Variables */
-	transmitting = 0;
-	transmit_size = 0;
-}
-
-static inline void uart_get_byte(char *output_byte) {
-	while (!byte_ready) {
-		if (seconds == TIME_OUT) {
-		    timeout_flag = 1;
-		    return;
-	    }
-	}
-	*output_byte = received_byte;
-	return;
-	
-	
-	/*
-	if (byte_ready) {
-		*output_byte = received_byte;
-		byte_ready = 0;
-		return 0;
-	} else {
-		return -1;
-	}
-	*/
-}
-
-
-static void uart_puts (char* str, int len){
-  for(int i=0;i<len;i++){
-    uart_send_byte('@');//trash byte //TODO: figure out whats going on here
-    uart_send_byte(str[i]);
-  }
-}
-
-static void uart_send_byte (char data) {
-    //Wait for the UART line to not be busy sending
-	while (!(UCSRA & (1 << UDRE)));
-
-    //Enable RS485 Converter, give it time to turn on
-	uart_enable_transmit();
-    _delay_loop_2(8000);    //Approxmiately 2ms
-	//led_on(LED_RED);
-	UDR = data;
-	//led_on(LED_YELLOW);	
-
-}
-
-
-static inline void uart_enable_transmit() {
-    PINB |= TX_EN;
-}
-
-static inline void uart_disable_transmit() {
-	PINB &= ~TX_EN;
-}
-
-ISR(USART_RX_vect) {	
-	while(1);
-	received_byte = UDR;
-	byte_ready = 1;
-}
-
-ISR(USART_TX_vect) {
-	//static volatile char loc = 1;
-	//if (transmitting) {
-		//if (loc < transmit_size) {
-		//	UDR = transmit_data[loc];
-		//	loc++;
-		//} else {
-		//	loc = 1;
-			//transmitting = 0;
-			_delay_loop_2(8000);    //Approxmiately 2ms
-			uart_disable_transmit();
-			//led_on(LED_GREEN);
-		//}
-	//}
-}
-
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File              : USI_UART.c
-* Compiler          : IAR EWAAVR 2.28a
-* Created           : 18.07.2002 by JLL
-* Modified          : 02-10-2003 by LTA
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : ATtiny26
-*
-* Application Note  : AVR307 - Half duplex UART using the USI Interface
-*
-* Description       : Functions for USI_UART_receiver and USI_UART_transmitter.
-*                     Uses Pin Change Interrupt to detect incomming signals.
-*
-*
-****************************************************************************/
-    
-//#include <avr/io.h>  // Note there is a bug in ioavr.h file that includes iotiny22.h instead of iotiny26.h.
-//#include <iotiny26.h>
-//#include <avr/interrupt.h>
-//#include <avr/signal.h>
-//#include "USI_UART_config.h"
-
-
-//********** USI UART Defines **********//
-#define RXPIN	PB5
-#define CLKPIN	PB7
-
-#define STARTFLAG 		0x45 //100 0101 //0x0B  //01011
-#define NSTARTFLAG		0x3A //011 1010 //0x14  //10100
-#define STOPFLAG      0x1F //001 1111  0x1F  //11111
-#define NSTOPFLAG		  0x60 //110 0000 0x00  //00000
-#define REVSTART      0x51 //101 0001  0x1A  //11010
-#define NREVSTART		  0x2E //010 1110 0x05  //00101
-
-#define DATA_BITS                 7
-#define START_BIT                 7
-#define STOP_BIT                  7
-#define HALF_FRAME                7
-
-
-#define USI_COUNTER_MAX_COUNT     16
-#define INTERRUPT_STARTUP_DELAY   (0x11 / TIMER_PRESCALER)
-
-#define USI_COUNTER_SEED_RECEIVE   ( USI_COUNTER_MAX_COUNT - (DATA_BITS*2) ) //TODO: put the right value here
-
-/* General defines */
-#define TRUE                      1
-#define FALSE                     0
-
-//********** Static Variables **********//
-
-/*__no_init __regvar static unsigned char USI_UART_TxData[15];   // Tells the compiler to store the byte to be transmitted in registry.
-*/
-//static unsigned char			USI_UART_TxData;
-//static unsigned char          UART_RxByte;  // UART buffers. Size is definable in the header file.
-
-
-static volatile union USI_UART_status                           // Status byte holding flags.
-{
-    unsigned char status;
-    struct
-    {
-        unsigned char wait_Card:1;
-        unsigned char wait_Start:1;
-        unsigned char ongoing_Reception_Of_Package:1;
-        unsigned char reception_Buffer_Overflow:1;
-        unsigned char data_Ready:1;
-        unsigned char flag5:1;
-        unsigned char flag6:1;
-        unsigned char flag7:1;
-    };
-} USI_UART_status = {0};
-
-
-//********** USI_UART functions **********//
-
-// Reverses the order of bits in a byte.
-// I.e. MSB is swapped with LSB, etc.
-static inline unsigned char Bit_Reverse5( unsigned char x )
-{
-	unsigned char c = x&0x04;
-//	x = x<<3;
-    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-    return x;    
-}
-
-static inline unsigned char Bit_Reverse( unsigned char x )
-{
-  unsigned char c=0;
-  
-  c |=0x01&(x>>6);
-  c |=0x02&(x>>4);
-  c |=0x04&(x>>2);
-  c |=0x08&(x>>0);
-  c |=0x10&(x<<2);
-  c |=0x20&(x<<4);
-  c |=0x40&(x<<6);
-
-
-//	unsigned char c = x&0x08;
-//	x = x<<3;
-//    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-//    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-//    return x;    
-
-  return c;
-}
-
-
-
-// Initialise USI for UART reception.
-// Note that this function only enables pinchange interrupt on the USI Data Input pin.
-// The USI is configured to read data within the pinchange interrupt.
-static inline void USI_UART_Initialise_Receiver( void ) {  
-    // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)
-    PORTB |=   _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4);
-    // Set USI DI, DO and SCK pins as inputs.            
-    DDRB  &= ~( _BV(PB7) | _BV(PB6) | _BV(PB5) | _BV(PB4));
-    // Disable USI.          
-    USICR = 0;                                            
-    // Clear pin change interrupt flag.
-    EIFR = _BV(PCIF);                                    
-    PCMSK |= _BV(RXPIN);
-    // Enable pin change interrupt for PB7:0.
-    GIMSK |= _BV(PCIE);                   
-                    
-	USI_UART_status.data_Ready=FALSE;
-	USI_UART_status.wait_Card=TRUE;
-	USI_UART_status.wait_Start=FALSE;
-	USI_UART_status.ongoing_Reception_Of_Package = FALSE; 
-	RxIndex=0;
-}
-
-// Returns a byte from the receive buffer. Waits if buffer is empty.
-static inline unsigned char USI_UART_Receive_Bytes(void) {
-    while ( !USI_UART_status.data_Ready );                 // Wait for incomming data 
-	USI_UART_status.data_Ready=FALSE;
-    return RxIndex;              // Reverse the order of the bits in the data byte before it returns data from the buffer.
-}
-
-// Check if there is data in the receive buffer.
-static inline unsigned char USI_UART_Data_In_Receive_Buffer(void) {
-    return (USI_UART_status.data_Ready);
-}
-
-// ********** Interrupt Handlers ********** //
-
-// The pin change interrupt is used to detect USI_UART reseption.
-// It is here the USI is configured to sample the UART signal.
-
-ISR(PCINT_vect)    
-{  
-
-#ifdef DEBUG
-  uart_puts("[PCINT]", 7);
-#endif
-
-   if ((USI_UART_status.wait_Card)&&(!( PINB & (1<<RXPIN) )))     // If the USI DI pin is low, then it is likely that it
-    {                                                             //  was this pin that generated the pin change interrupt.
-      USICR  = /*_BV(USISIE) |*/ _BV(USIOIE) |                       // Enable USI Counter OVF interrupt.
-        /* _BV(USIWM1) |*/ _BV(USIWM0) |                      // Select Three Wire mode.
-	/*_BV(USICS1) |*/ _BV(USICS0) /*|  _BV(USICLK) |       // Select Timer0 OVER as USI Clock source.
-                                         _BV(USITC)*/;                                           
-
-
-                                                                  // Note that enabling the USI will also disable the pin change interrupt.
-        USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;                 // Clear all USI interrupt flags and preload the USI counter to generate interrupt.
-        PCMSK |= _BV(CLKPIN);
-        PCMSK &= ~_BV(RXPIN);
-        
-        //GIMSK &=  ~(1<<PCIE);                                    // Disable pin change interrupt for PB3:0. 
-        USI_UART_status.wait_Start = TRUE;
-        USI_UART_status.wait_Card = FALSE;
-
-        PORTD |= _BV(PD4); //from .c  
-
-    }
-	else if((USI_UART_status.wait_Start)&&(!(PINB&(1<<CLKPIN))))
-	{
-//	   	PORTD |= (1<<PD4); 
-		if((USIDR&0x7F)==(NREVSTART))  /////////////MAYBE SHOULD BE REVSTART
-		{
-			USI_UART_status.wait_Start = FALSE;
-			USI_UART_status.ongoing_Reception_Of_Package = TRUE;  
-			USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;                 // Clear all USI interrupt flags, preload the USI counter to generate an interrupt
-			GIMSK &= ~(1<<PCIE);
-			PCMSK &=~(1<<CLKPIN);
-		}
-
-	}
-
-
-}
-
-// The USI Counter Overflow interrupt is used for moving data between memmory and the USI data register.
-// The interrupt is used for both transmission and reception.
-ISR(SIG_USI_OVERFLOW) {
-  //.c has SIGNAL not ISR
-
-#ifdef debug
-  led_on(LED_YELLOW);
-  uart_puts("<UO:",5);
-#endif
-
-  if(USI_UART_status.ongoing_Reception_Of_Package) {
-    char b;
-
-    //Byte comes in inverted and backwards, invert and reverse it to make it correct
-    b=Bit_Reverse(~USIDR)&0x0F;
-
-    //#ifdef debug
-    uart_puts(&b,1);
-    uart_puts(" ",1);
-    //#endif
-
-        //End character
-		if(1){//b>9) {
-#ifdef debug
-		    uart_puts(":b9",3);
-#endif
-
-            USICR  =  0;                                // Disable USI.
-            EIFR   =  _BV(PCIF);                        // Clear pin change interrupt flag.
-		    USI_UART_status.data_Ready=TRUE;
-
-		} else {
-
-#ifdef debug
-			uart_puts(":rx",3);
-#endif
-
-			//RxStream[RxIndex] = b;                      // Store received data in buffer. Note that the data must be bit reversed before used. 
-			//RxIndex=RxIndex+1;
-			
-			//WARNING: This is potentially dangerous if the card is larger than we expect. We should probably put some checks in here
-			// to prevent buffer overflow
-			packet[RxIndex + HEADER_OFFSET] = b;
-			RxIndex++;
-			USISR  = 0xF0 | USI_COUNTER_SEED_RECEIVE;   // Clear all USI interrupt flags and Preload the USI counter to generate interrupt.
-
-		}
-
-#ifdef debug
-		uart_puts(">>",2);
-#endif
-
-    }
-
-#ifdef debug
-  else{
-    uart_puts("sad>",5);
-  }
-#endif
-    
-}
Index: trunk/cardbox/swipebox/io.c.old
===================================================================
--- trunk/cardbox/swipebox/io.c.old	(revision 133)
+++ trunk/cardbox/swipebox/io.c.old	(nonexistent)
@@ -1,95 +0,0 @@
-/** @file io.c
- *
- *	@brief Implements IO functionality like turning lights, relays on or off
- *			or reading button values
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#include "io.h"
-
-//Sets directions of pins
-inline void init_pins() {
-	DDRB |= RELAY;
-	DDRD |= LED_RED | LED_YELLOW | LED_GREEN;
-	
-	return;	
-}
-
-//Will turn the relay on or off. 1 will turn it on, 0 will turn it off.
-void toggle_power(char state) {
-	if (state)
-		PORTB |= RELAY;
-	else
-		PORTB &= ~RELAY;
-		
-	return;
-}
-
-//Turns on an off an LED. which should be the defined pins (1 byte) and
-// state is: 1 -> on, 0 -> off
-void toggle_led(char which, char state) {
-	if (state)
-		PORTD |= _BV(which);
-	else
-		PORTD &= ~_BV(which);
-		
-	return;
-}
-
-char read_button_black() {
-	return ((PINB & BUTTON_BLACK) >> BUTTON_BLACK_SHIFT);
-}
-
-char read_button_red() {
-	return ((PINB & BUTTON_RED) >> BUTTON_RED_SHIFT);
-}
-
-char get_button() {
-    reset_timer();
-    start_timer();
-
-    while (1) {
-        if ((PIND & ROW1) && (PINB & COL1)) {
-            return 1;   //1
-        } else if ((PIND & ROW1) && (PINB & COL2)) {
-            return 2;   //2
-        } else if ((PIND & ROW1) && (PINB & COL3)) {
-            return 3;   //3
-        } else if ((PIND & ROW1) && (PINB & COL4)) {
-            return 10;  //A
-        } else if ((PIND & ROW2) && (PINB & COL1)) {
-            return 4;   //4
-        } else if ((PIND & ROW2) && (PINB & COL2)) {
-            return 5;   //5
-        } else if ((PIND & ROW2) && (PINB & COL3)) {
-            return 6;   //6
-        } else if ((PIND & ROW2) && (PINB & COL4)) {
-            return 11;  //B
-        } else if ((PINA & ROW3) && (PINB & COL1)) {
-            return 7;   //7
-        } else if ((PINA & ROW3) && (PINB & COL2)) {
-            return 8;   //8
-        } else if ((PINA & ROW3) && (PINB & COL3)) {
-            return 9;   //9
-        } else if ((PINA & ROW3) && (PINB & COL4)) {
-            return 12;  //C
-        } else if ((PINA & ROW4) && (PINB & COL1)) {
-            return 14;  //*
-        } else if ((PINA & ROW4) && (PINB & COL2)) {
-            return 0;   //0
-        } else if ((PINA & ROW4) && (PINB & COL3)) {
-            return 15;  //#
-        } else if ((PINA & ROW4) && (PINB & COL4)) {
-            return 13;  //D
-        }
-        
-        if (seconds == TIME_OUT) {
-            timeout_flag = 1;
-            return 255;
-        }
-    }
-    
-    return 255;
-}
-
Index: trunk/cardbox/swipebox/io_mine.h
===================================================================
--- trunk/cardbox/swipebox/io_mine.h	(revision 133)
+++ trunk/cardbox/swipebox/io_mine.h	(nonexistent)
@@ -1,67 +0,0 @@
-/** @file io.h
- *
- *	@brief Implements IO functionality such as turning LEDs on
- *			and off, turning the relays on or off, and returning
- *			button values
- *	
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef IO_H
-#define IO_H
-
-#include <avr/io.h>
-#include "timer.h"
-
-/* Pin Defines */
-/** @brief Pin that turns the relay on/off */
-#define RELAY 				_BV(PB3)
-/** @brief Red LED Pin*/
-#define LED_RED				_BV(PD6)
-/** @brief Yellow LED Pin*/
-#define LED_YELLOW			_BV(PD5)
-/** @brief Green LED Pin*/
-#define LED_GREEN			_BV(PD4)
-/** @brief Black Button Pin*/
-#define BUTTON_BLACK		_BV(PD2)
-/** @brief How much to shift out of the port that Black button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_BLACK_SHIFT	0x02
-/** @brief Red Button Pin*/
-#define BUTTON_RED			_BV(PD3)
-/** @brief How much to shift out of the port that Red button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_RED_SHIFT	0x03
-
-/* Keypad definitions */
-/** @brief ROW1 of the keypad */
-#define ROW1 _BV(PD2)
-/** @brief ROW2 of the keypad */
-#define ROW2 _BV(PD3)
-/** @brief ROW3 of the keypad */
-#define ROW3 _BV(PA1)
-/** @brief ROW4 of the keypad */
-#define ROW4 _BV(PA0)
-/** @brief COL1 of the keypad */
-#define COL1 _BV(PB6)
-/** @brief COL2 of the keypad */
-#define COL2 _BV(PB4)
-/** @brief COL3 of the keypad */
-#define COL3 _BV(PB2)
-/** @brief COL4 of the keypad */
-#define COL4 _BV(PB0)
-
-
-/** @brief Sets the direction of the pins */
-static inline void init_pins(void);
-/** @brief Toggles the relay on or off. state == 1 is on, state == 0 is off */
-static inline void toggle_power_on(void);
-static inline void toggle_power_off(void);
-/** @brief Sets the state of the given LED (which) to state where state == 1 is on, state == 0 is off */
-static inline void toggle_led_on(char which);
-static inline void toggle_led_off(char which);
-/** @brief Reads the value of the black button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_black(void);
-/** @brief Reads the value of the red button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_red(void);
-/** @brief Waits until a button the keypad is pressed. Uses the timer to time out the loop in case none is selected */
-static char get_button(void);
-#endif
Index: trunk/cardbox/swipebox/timer.h
===================================================================
--- trunk/cardbox/swipebox/timer.h	(revision 133)
+++ trunk/cardbox/swipebox/timer.h	(nonexistent)
@@ -1,29 +0,0 @@
-/** @file timer.h
- *	
- * 	@breif Timer functions
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef TIMER_H
-#define TIMER_H
-
-/** @brief Max time that we can wait for a full packet from the server before we timeout */
-#define TIME_OUT		5
-
-/** @brief Seconds that have elapsed since the timer started */
-//extern volatile char seconds;
-/** @brief Minutes that have elapsed since the timer started */
-//extern volatile char minutes;
-//extern char timeout_flag;
-
-/** @brief Sets the registers to use the timer for couting in real time */
-static inline void init_timer(void);
-/** @brief Starts the timer from last position*/
-static inline void start_timer(void);
-/** @brief Stops the timer from counting*/
-static inline void stop_timer(void);
-/** @brief Resets the values of the timer to 0*/
-static inline void reset_timer(void);
-
-#endif
Index: trunk/cardbox/swipebox/USI_UART_config.h
===================================================================
--- trunk/cardbox/swipebox/USI_UART_config.h	(revision 133)
+++ trunk/cardbox/swipebox/USI_UART_config.h	(nonexistent)
@@ -1,61 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File          : USI_UART_config.h
-* Compiler      : IAR EWAAVR 2.28a
-* Created       : 18.07.2002 by JLL
-* Modified      : 02-10-2003 by LTA
-*
-* Support mail  : avr@atmel.com
-*
-* AppNote       : AVR307 - Half duplex UART using the USI Interface
-*
-* Description   : Header file for USI_UART driver
-*
-*
-****************************************************************************/
-
-#ifndef __USI_UART_config_h
-#define __USI_UART_config_h
-
-//********** USI UART Defines **********//
-
-//#define SYSTEM_CLOCK             14745600
-//#define SYSTEM_CLOCK             11059200
-#define SYSTEM_CLOCK              8000000
-//#define SYSTEM_CLOCK              7372800
-//#define SYSTEM_CLOCK              3686400
-//#define SYSTEM_CLOCK              2000000
-//#define SYSTEM_CLOCK              1843200
-//#define SYSTEM_CLOCK              1000000
-
-//#define BAUDRATE                   115200
-//#define BAUDRATE                    57600
-//#define BAUDRATE                    28800
-//#define BAUDRATE                    19200
-//#define BAUDRATE                    14400
-#define BAUDRATE                     9600
-
-//#define TIMER_PRESCALER           1
-#define TIMER_PRESCALER           8     
-
-#define UART_RX_BUFFER_SIZE        4     /* 2,4,8,16,32,64,128 or 256 bytes */
-#define UART_TX_BUFFER_SIZE        4
-
-
-//********** USI_UART Prototypes **********//
-static unsigned char			RxStream[100];
-
-static unsigned char 			RxIndex;
-static unsigned char USI_UART_Receive_Bytes( void );
-static inline unsigned char USI_UART_Data_In_Receive_Buffer( void );
-static inline unsigned char Bit_Reverse( unsigned char );
-static inline void          USI_UART_Initialise_Receiver( void );
-//Don't use these
-void          USI_UART_Initialise_Transmitter( void );
-void          USI_UART_Transmit_Byte( unsigned char );
-void          USI_UART_Flush_Buffers( void );
-//End
-
-#endif
Index: trunk/cardbox/swipebox/Makefile
===================================================================
--- trunk/cardbox/swipebox/Makefile	(revision 133)
+++ trunk/cardbox/swipebox/Makefile	(nonexistent)
@@ -1,507 +0,0 @@
-# Hey Emacs, this is a -*- makefile -*-
-#----------------------------------------------------------------------------
-# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
-#
-# Released to the Public Domain
-#
-# Additional material for this makefile was written by:
-# Peter Fleury
-# Tim Henigan
-# Colin O'Flynn
-# Reiner Patommel
-# Markus Pfaff
-# Sander Pool
-# Frederik Rouleau
-#
-#----------------------------------------------------------------------------
-# On command line:
-#
-# make all = Make software.
-#
-# make clean = Clean out built project files.
-#
-# make coff = Convert ELF to AVR COFF.
-#
-# make extcoff = Convert ELF to AVR Extended COFF.
-#
-# make program = Download the hex file to the device, using avrdude.
-#                Please customize the avrdude settings below first!
-#
-# make debug = Start either simulavr or avarice as specified for debugging,
-#              with avr-gdb or avr-insight as the front end for debugging.
-#
-# make filename.s = Just compile filename.c into the assembler code only.
-#
-# make filename.i = Create a preprocessed source file for use in submitting
-#                   bug reports to the GCC project.
-#
-# To rebuild project do "make clean" then "make all".
-#----------------------------------------------------------------------------
-
-
-# MCU name
-MCU = attiny2313
-
-
-# Processor frequency.
-#     This will define a symbol, F_CPU, in all source code files equal to the
-#     processor frequency. You can then use this symbol in your source code to
-#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
-#     automatically to create a 32-bit value in your source code.
-F_CPU = 8000000
-
-
-# Output format. (can be srec, ihex, binary)
-FORMAT = ihex
-
-
-# Target file name (without extension).
-TARGET = main
-
-# List C source files here. (C dependencies are automatically generated.)
-//SRC =  $(wildcard *.c)
-SRC = main.c
-
-# List Assembler source files here.
-#     Make them always end in a capital .S.  Files ending in a lowercase .s
-#     will not be considered source files but generated files (assembler
-#     output from the compiler), and will be deleted upon "make clean"!
-#     Even though the DOS/Win* filesystem matches both .s and .S the same,
-#     it will preserve the spelling of the filenames, and gcc itself does
-#     care about how the name is spelled on its command-line.
-ASRC =
-
-
-# Optimization level, can be [0, 1, 2, 3, s].
-#     0 = turn off optimization. s = optimize for size.
-#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-OPT = s
-
-
-# Debugging format.
-#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
-#     AVR Studio 4.10 requires dwarf-2.
-#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
-DEBUG =
-
-
-# List any extra directories to look for include files here.
-#     Each directory must be seperated by a space.
-#     Use forward slashes for directory separators.
-#     For a directory that has spaces, enclose it in quotes.
-#EXTRAINCDIRS = C:\WinAVR\include\fwr
-
-
-# Compiler flag to set the C Standard level.
-#     c89   = "ANSI" C
-#     gnu89 = c89 plus GCC extensions
-#     c99   = ISO C99 standard (not yet fully implemented)
-#     gnu99 = c99 plus GCC extensions
-CSTANDARD = -std=gnu99
-
-
-# Place -D or -U options here
-CDEFS = -DF_CPU=$(F_CPU)UL
-
-
-# Place -I options here
-CINCS =
-
-
-
-#---------------- Compiler Options ----------------
-#  -g*:          generate debugging information
-#  -O*:          optimization level
-#  -f...:        tuning, see GCC manual and avr-libc documentation
-#  -Wall...:     warning level
-#  -Wa,...:      tell GCC to pass this to the assembler.
-#    -adhlns...: create assembler listing
-#CFLAGS = -g$(DEBUG)
-CFLAGS += $(CDEFS) $(CINCS)
-CFLAGS += -O$(OPT)
-CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-CFLAGS += -Wall -Wstrict-prototypes
-CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
-CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-CFLAGS += $(CSTANDARD)
-
-
-#---------------- Assembler Options ----------------
-#  -Wa,...:   tell GCC to pass this to the assembler.
-#  -ahlms:    create listing
-#  -gstabs:   have the assembler create line number information; note that
-#             for use in COFF files, additional information about filenames
-#             and function names needs to be present in the assembler source
-#             files -- see avr-libc docs [FIXME: not yet described there]
-ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
-
-
-#---------------- Library Options ----------------
-# Minimalistic printf version
-PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
-
-# Floating point printf version (requires MATH_LIB = -lm below)
-PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
-
-# If this is left blank, then it will use the Standard printf version.
-PRINTF_LIB =
-#PRINTF_LIB = $(PRINTF_LIB_MIN)
-#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
-
-
-# Minimalistic scanf version
-SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
-
-# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
-SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
-
-# If this is left blank, then it will use the Standard scanf version.
-SCANF_LIB =
-#SCANF_LIB = $(SCANF_LIB_MIN)
-#SCANF_LIB = $(SCANF_LIB_FLOAT)
-
-
-MATH_LIB = -lm
-
-
-
-#---------------- External Memory Options ----------------
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# used for variables (.data/.bss) and heap (malloc()).
-#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# only used for heap (malloc()).
-#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
-
-EXTMEMOPTS =
-
-
-
-#---------------- Linker Options ----------------
-#  -Wl,...:     tell GCC to pass this to linker.
-#    -Map:      create map file
-#    --cref:    add cross reference to  map file
-LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
-LDFLAGS += $(EXTMEMOPTS)
-LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
-
-
-
-#---------------- Programming Options (avrdude) ----------------
-
-# Programming hardware: alf avr910 avrisp bascom bsd
-# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
-#
-# Type: avrdude -c ?
-# to get a full listing.
-#
-AVRDUDE_PROGRAMMER = avrispmkII
-
-# com1 = serial port. Use lpt1 to connect to parallel port.
-AVRDUDE_PORT = usb
-# programmer connected to serial device
-
-AVRDUDE_WRITE_FLASH = -b 19200 -U flash:w:$(TARGET).hex #speed was 4800
-#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
-
-
-# Uncomment the following if you want avrdude's erase cycle counter.
-# Note that this counter needs to be initialized first using -Yn,
-# see avrdude manual.
-#AVRDUDE_ERASE_COUNTER = -y
-
-# Uncomment the following if you do /not/ wish a verification to be
-# performed after programming the device.
-#AVRDUDE_NO_VERIFY = -V
-
-# Increase verbosity level.  Please use this when submitting bug
-# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
-# to submit bug reports.
-#AVRDUDE_VERBOSE = -v -v
-
-AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -F
-AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
-AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
-AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
-
-
-
-#---------------- Debugging Options ----------------
-
-# For simulavr only - target MCU frequency.
-DEBUG_MFREQ = $(F_CPU)
-
-# Set the DEBUG_UI to either gdb or insight.
-# DEBUG_UI = gdb
-DEBUG_UI = insight
-
-# Set the debugging back-end to either avarice, simulavr.
-DEBUG_BACKEND = avarice
-#DEBUG_BACKEND = simulavr
-
-# GDB Init Filename.
-GDBINIT_FILE = __avr_gdbinit
-
-# When using avarice settings for the JTAG
-JTAG_DEV = /dev/com1
-
-# Debugging port used to communicate between GDB / avarice / simulavr.
-DEBUG_PORT = 4242
-
-# Debugging host used to communicate between GDB / avarice / simulavr, normally
-#     just set to localhost unless doing some sort of crazy debugging when
-#     avarice is running on a different computer.
-DEBUG_HOST = localhost
-
-
-
-#============================================================================
-
-
-# Define programs and commands.
-SHELL = sh
-CC = avr-gcc
-OBJCOPY = avr-objcopy
-OBJDUMP = avr-objdump
-SIZE = avr-size
-NM = avr-nm
-AVRDUDE = avrdude
-REMOVE = rm -f
-COPY = cp
-WINSHELL = cmd
-
-
-# Define Messages
-# English
-MSG_ERRORS_NONE = Errors: none
-MSG_BEGIN = -------- begin --------
-MSG_END = --------  end  --------
-MSG_SIZE_BEFORE = Size before:
-MSG_SIZE_AFTER = Size after:
-MSG_COFF = Converting to AVR COFF:
-MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
-MSG_FLASH = Creating load file for Flash:
-MSG_EEPROM = Creating load file for EEPROM:
-MSG_EXTENDED_LISTING = Creating Extended Listing:
-MSG_SYMBOL_TABLE = Creating Symbol Table:
-MSG_LINKING = Linking:
-MSG_COMPILING = Compiling:
-MSG_ASSEMBLING = Assembling:
-MSG_CLEANING = Cleaning project:
-
-
-
-
-# Define all object files.
-OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
-
-# Define all listing files.
-LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
-
-
-# Compiler flags to generate dependency files.
-GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
-
-
-# Combine all necessary flags and optional flags.
-# Add target processor to flags.
-ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
-
-
-
-
-
-# Default target.
-all: begin gccversion sizebefore build sizeafter end
-
-build: elf hex eep lss sym
-
-elf: $(TARGET).elf
-hex: $(TARGET).hex
-eep: $(TARGET).eep
-lss: $(TARGET).lss
-sym: $(TARGET).sym
-
-
-
-# Eye candy.
-# AVR Studio 3.x does not check make's exit code but relies on
-# the following magic strings to be generated by the compile job.
-begin:
-	@echo
-	@echo $(MSG_BEGIN)
-
-end:
-	@echo $(MSG_END)
-	@echo
-
-
-# Display size of file.
-HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
-ELFSIZE = $(SIZE) -A $(TARGET).elf
-AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
-
-sizebefore:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-sizeafter:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-
-
-# Display compiler version information.
-gccversion :
-	@$(CC) --version
-
-
-
-# Program the device.
-program: $(TARGET).hex $(TARGET).eep
-	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
-
-# Generate avr-gdb config/init file which does the following:
-#     define the reset signal, load the target file, connect to target, and set
-#     a breakpoint at main().
-gdb-config:
-	@$(REMOVE) $(GDBINIT_FILE)
-	@echo define reset >> $(GDBINIT_FILE)
-	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
-	@echo end >> $(GDBINIT_FILE)
-	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
-	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
-ifeq ($(DEBUG_BACKEND),simulavr)
-	@echo load  >> $(GDBINIT_FILE)
-endif
-	@echo break main >> $(GDBINIT_FILE)
-
-debug: gdb-config $(TARGET).elf
-ifeq ($(DEBUG_BACKEND), avarice)
-	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
-	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
-	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
-	@$(WINSHELL) /c pause
-
-else
-	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
-	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
-endif
-	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
-
-
-
-
-# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
-COFFCONVERT=$(OBJCOPY) --debugging \
---change-section-address .data-0x800000 \
---change-section-address .bss-0x800000 \
---change-section-address .noinit-0x800000 \
---change-section-address .eeprom-0x810000
-
-
-coff: $(TARGET).elf
-	@echo
-	@echo $(MSG_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
-
-
-extcoff: $(TARGET).elf
-	@echo
-	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
-
-
-
-# Create final output files (.hex, .eep) from ELF output file.
-%.hex: %.elf
-	@echo
-	@echo $(MSG_FLASH) $@
-	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
-
-%.eep: %.elf
-	@echo
-	@echo $(MSG_EEPROM) $@
-	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
-	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
-
-# Create extended listing file from ELF output file.
-%.lss: %.elf
-	@echo
-	@echo $(MSG_EXTENDED_LISTING) $@
-	$(OBJDUMP) -h -S $< > $@
-
-# Create a symbol table from ELF output file.
-%.sym: %.elf
-	@echo
-	@echo $(MSG_SYMBOL_TABLE) $@
-	$(NM) -n $< > $@
-
-
-
-# Link: create ELF output file from object files.
-.SECONDARY : $(TARGET).elf
-.PRECIOUS : $(OBJ)
-%.elf: $(OBJ)
-	@echo
-	@echo $(MSG_LINKING) $@
-	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
-
-
-# Compile: create object files from C source files.
-%.o : %.c
-	@echo
-	@echo $(MSG_COMPILING) $<
-	$(CC) -c $(ALL_CFLAGS) $< -o $@
-
-
-# Compile: create assembler files from C source files.
-%.s : %.c
-	$(CC) -S $(ALL_CFLAGS) $< -o $@
-
-
-# Assemble: create object files from assembler source files.
-%.o : %.S
-	@echo
-	@echo $(MSG_ASSEMBLING) $<
-	$(CC) -c $(ALL_ASFLAGS) $< -o $@
-
-# Create preprocessed source for use in sending a bug report.
-%.i : %.c
-	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
-
-
-# Target: clean project.
-clean: begin clean_list end
-
-clean_list :
-	@echo
-	@echo $(MSG_CLEANING)
-	$(REMOVE) $(TARGET).hex
-	$(REMOVE) $(TARGET).eep
-	$(REMOVE) $(TARGET).cof
-	$(REMOVE) $(TARGET).elf
-	$(REMOVE) $(TARGET).map
-	$(REMOVE) $(TARGET).sym
-	$(REMOVE) $(TARGET).lss
-	$(REMOVE) $(OBJ)
-	$(REMOVE) $(LST)
-	$(REMOVE) $(SRC:.c=.s)
-	$(REMOVE) $(SRC:.c=.d)
-	$(REMOVE) .dep/*
-
-
-
-# Include the dependency files.
--include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
-
-
-# Listing of phony targets.
-.PHONY : all begin finish end sizebefore sizeafter gccversion \
-build elf hex eep lss sym coff extcoff \
-clean clean_list program debug gdb-config
-
Index: trunk/cardbox/uartio.c.old
===================================================================
--- trunk/cardbox/uartio.c.old	(revision 133)
+++ trunk/cardbox/uartio.c.old	(nonexistent)
@@ -1,91 +0,0 @@
-/** @file uart.c
- *	
- *	@brief Implements UART functionality in hardware
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#include "uart.h"
-
-char received_byte;							//Byte received
-char *transmit_data;						//String to send
-char transmit_size;							//Size of string that we are sending
-char byte_ready;								//New byte has been received
-char transmitting;
-
-static void init_uart(int baud) {
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-	
-	/* Enable RX/TX and RX/TX Interrupt */
-	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);
-	
-	/* Asynchronous mode, 1 bit stop, 8bit transmissions */
-	UCSRC = _BV(UCSZ1) | _BV(UCSZ0) | ~_BV(USBS);
- 
- 	/* Enable RX pin as input */
-	PORTD &= ~RX;
-	
-	/* Enable TX pin as output */
-	DDRD |= TX;
-	
-	/* Enable the TXEN pin as output */
-	DDRB |= TX_EN;
-	
-	/* RX Status Variables */
-	received_byte = 0;	//Initialize first byte
-	byte_ready = 0;		//Byte is not ready to be read	
-	
-	/* TX Status Variables */
-	transmitting = 0;
-	transmit_size = 0;
-}
-
-static char uart_get_byte(char *output_byte) {
-	if (byte_ready) {
-		*output_byte = received_byte;
-		byte_ready = 0;
-		return 0;
-	} else {
-		return -1;
-	}
-}
-
-static void uart_send_bytes(char *data, int size) {
-	//Waits until current transmit is done
-	while (transmitting);
-
-	uart_enable_transmit(UART_TX_ON);
-	transmitting = 1;
-	transmit_size = size;
-	transmit_data = data;
-	return;
-}
-
-static void uart_enable_transmit(char state) {
-	if (state == UART_TX_ON) {
-		PINB |= TX_EN;
-	} else {
-		PINB &= ~TX_EN;
-	}
-}
-
-ISR(UART_RX_vect) {
-	received_byte = UDR;
-	byte_ready = 1;
-}
-
-ISR(UART_TX_vect) {
-	static volatile char position = 0;
-	if (transmitting) {
-		if (position < transmit_size) {
-			UDR = transmit_data[position];
-			position++;
-		} else {
-			position = 0;
-			transmitting = 0;
-			uart_enable_transmit(UART_TX_OFF);
-		}
-	}
-}
Index: trunk/cardbox/uart.h
===================================================================
--- trunk/cardbox/uart.h	(revision 133)
+++ trunk/cardbox/uart.h	(nonexistent)
@@ -1,46 +0,0 @@
-/** @file uart.h
- *
- *	@brief Initializes UART functions using the UART hardware module
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef UART_H
-#define UART_H
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-
-/** **/
-#define UART_TX_OFF 0
-#define UART_TX_ON 1
-
-/** @brief RX Pin for the UART **/
-#define RX		_BV(PD0)
-#define TX		_BV(PD1)
-#define TX_EN	_BV(PB1)
-
-
-/** @brief The most recently received byte **/
-//extern char received_byte;
-/** @brief If the value in received_byte has been read or not **/
-//extern char	byte_ready;
-//extern char *transmit_data;
-//extern char transmit_size;
-//extern char transmitting;
-
-/** @brief Initializes the UART registers and sets it to the buad rate which msut be the 
- *			value that is defined in the datasheet for any particular speed (ie: 51 -> 9600bps)
- **/
-static inline void init_uart(int baud);
-/** @brief Gets latest byte and returns it in output_byte. If the byte was already read, returns -1 
- *			otherwise it returns 0 
- **/
-static char uart_get_byte(char *output_byte);
-/** @brief Sends a character array of size size. If we are currently transmitting it will block until the
-  * 	the current transmit is done. 
-  **/
-static void uart_send_byte(char data);
-static inline void uart_enable_transmit(void);
-static inline void uart_disable_transmit(void);
-#endif
Index: trunk/cardbox_test/Makefile
===================================================================
--- trunk/cardbox_test/Makefile	(revision 133)
+++ trunk/cardbox_test/Makefile	(nonexistent)
@@ -1,507 +0,0 @@
-# Hey Emacs, this is a -*- makefile -*-
-#----------------------------------------------------------------------------
-# WinAVR Makefile Template written by Eric B. Weddington, J�rg Wunsch, et al.
-#
-# Released to the Public Domain
-#
-# Additional material for this makefile was written by:
-# Peter Fleury
-# Tim Henigan
-# Colin O'Flynn
-# Reiner Patommel
-# Markus Pfaff
-# Sander Pool
-# Frederik Rouleau
-#
-#----------------------------------------------------------------------------
-# On command line:
-#
-# make all = Make software.
-#
-# make clean = Clean out built project files.
-#
-# make coff = Convert ELF to AVR COFF.
-#
-# make extcoff = Convert ELF to AVR Extended COFF.
-#
-# make program = Download the hex file to the device, using avrdude.
-#                Please customize the avrdude settings below first!
-#
-# make debug = Start either simulavr or avarice as specified for debugging, 
-#              with avr-gdb or avr-insight as the front end for debugging.
-#
-# make filename.s = Just compile filename.c into the assembler code only.
-#
-# make filename.i = Create a preprocessed source file for use in submitting
-#                   bug reports to the GCC project.
-#
-# To rebuild project do "make clean" then "make all".
-#----------------------------------------------------------------------------
-
-
-# MCU name
-MCU = attiny2313
-
-
-# Processor frequency.
-#     This will define a symbol, F_CPU, in all source code files equal to the 
-#     processor frequency. You can then use this symbol in your source code to 
-#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
-#     automatically to create a 32-bit value in your source code.
-F_CPU = 8000000
-
-
-# Output format. (can be srec, ihex, binary)
-FORMAT = ihex
-
-
-# Target file name (without extension).
-TARGET = main
-
-# List C source files here. (C dependencies are automatically generated.)
-//SRC =  $(wildcard *.c)
-SRC = main.c
-
-# List Assembler source files here.
-#     Make them always end in a capital .S.  Files ending in a lowercase .s
-#     will not be considered source files but generated files (assembler
-#     output from the compiler), and will be deleted upon "make clean"!
-#     Even though the DOS/Win* filesystem matches both .s and .S the same,
-#     it will preserve the spelling of the filenames, and gcc itself does
-#     care about how the name is spelled on its command-line.
-ASRC = 
-
-
-# Optimization level, can be [0, 1, 2, 3, s]. 
-#     0 = turn off optimization. s = optimize for size.
-#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-OPT = s
-
-
-# Debugging format.
-#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
-#     AVR Studio 4.10 requires dwarf-2.
-#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
-DEBUG =
-
-
-# List any extra directories to look for include files here.
-#     Each directory must be seperated by a space.
-#     Use forward slashes for directory separators.
-#     For a directory that has spaces, enclose it in quotes.
-#EXTRAINCDIRS = C:\WinAVR\include\fwr
-
-
-# Compiler flag to set the C Standard level.
-#     c89   = "ANSI" C
-#     gnu89 = c89 plus GCC extensions
-#     c99   = ISO C99 standard (not yet fully implemented)
-#     gnu99 = c99 plus GCC extensions
-CSTANDARD = -std=gnu99
-
-
-# Place -D or -U options here
-CDEFS = -DF_CPU=$(F_CPU)UL
-
-
-# Place -I options here
-CINCS =
-
-
-
-#---------------- Compiler Options ----------------
-#  -g*:          generate debugging information
-#  -O*:          optimization level
-#  -f...:        tuning, see GCC manual and avr-libc documentation
-#  -Wall...:     warning level
-#  -Wa,...:      tell GCC to pass this to the assembler.
-#    -adhlns...: create assembler listing
-#CFLAGS = -g$(DEBUG)
-CFLAGS += $(CDEFS) $(CINCS)
-CFLAGS += -O$(OPT)
-CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-CFLAGS += -Wall -Wstrict-prototypes
-CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
-CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-CFLAGS += $(CSTANDARD)
-
-
-#---------------- Assembler Options ----------------
-#  -Wa,...:   tell GCC to pass this to the assembler.
-#  -ahlms:    create listing
-#  -gstabs:   have the assembler create line number information; note that
-#             for use in COFF files, additional information about filenames
-#             and function names needs to be present in the assembler source
-#             files -- see avr-libc docs [FIXME: not yet described there]
-ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
-
-
-#---------------- Library Options ----------------
-# Minimalistic printf version
-PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
-
-# Floating point printf version (requires MATH_LIB = -lm below)
-PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
-
-# If this is left blank, then it will use the Standard printf version.
-PRINTF_LIB = 
-#PRINTF_LIB = $(PRINTF_LIB_MIN)
-#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
-
-
-# Minimalistic scanf version
-SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
-
-# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
-SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
-
-# If this is left blank, then it will use the Standard scanf version.
-SCANF_LIB = 
-#SCANF_LIB = $(SCANF_LIB_MIN)
-#SCANF_LIB = $(SCANF_LIB_FLOAT)
-
-
-MATH_LIB = -lm
-
-
-
-#---------------- External Memory Options ----------------
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# used for variables (.data/.bss) and heap (malloc()).
-#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# only used for heap (malloc()).
-#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
-
-EXTMEMOPTS =
-
-
-
-#---------------- Linker Options ----------------
-#  -Wl,...:     tell GCC to pass this to linker.
-#    -Map:      create map file
-#    --cref:    add cross reference to  map file
-LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
-LDFLAGS += $(EXTMEMOPTS)
-LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
-
-
-
-#---------------- Programming Options (avrdude) ----------------
-
-# Programming hardware: alf avr910 avrisp bascom bsd 
-# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
-#
-# Type: avrdude -c ?
-# to get a full listing.
-#
-AVRDUDE_PROGRAMMER = avrisp
-
-# com1 = serial port. Use lpt1 to connect to parallel port.
-AVRDUDE_PORT = com1
-# programmer connected to serial device
-
-AVRDUDE_WRITE_FLASH = -b 4800 -U flash:w:$(TARGET).hex
-#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
-
-
-# Uncomment the following if you want avrdude's erase cycle counter.
-# Note that this counter needs to be initialized first using -Yn,
-# see avrdude manual.
-#AVRDUDE_ERASE_COUNTER = -y
-
-# Uncomment the following if you do /not/ wish a verification to be
-# performed after programming the device.
-#AVRDUDE_NO_VERIFY = -V
-
-# Increase verbosity level.  Please use this when submitting bug
-# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
-# to submit bug reports.
-#AVRDUDE_VERBOSE = -v -v
-
-AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
-AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
-AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
-AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
-
-
-
-#---------------- Debugging Options ----------------
-
-# For simulavr only - target MCU frequency.
-DEBUG_MFREQ = $(F_CPU)
-
-# Set the DEBUG_UI to either gdb or insight.
-# DEBUG_UI = gdb
-DEBUG_UI = insight
-
-# Set the debugging back-end to either avarice, simulavr.
-DEBUG_BACKEND = avarice
-#DEBUG_BACKEND = simulavr
-
-# GDB Init Filename.
-GDBINIT_FILE = __avr_gdbinit
-
-# When using avarice settings for the JTAG
-JTAG_DEV = /dev/com1
-
-# Debugging port used to communicate between GDB / avarice / simulavr.
-DEBUG_PORT = 4242
-
-# Debugging host used to communicate between GDB / avarice / simulavr, normally
-#     just set to localhost unless doing some sort of crazy debugging when 
-#     avarice is running on a different computer.
-DEBUG_HOST = localhost
-
-
-
-#============================================================================
-
-
-# Define programs and commands.
-SHELL = sh
-CC = avr-gcc
-OBJCOPY = avr-objcopy
-OBJDUMP = avr-objdump
-SIZE = avr-size
-NM = avr-nm
-AVRDUDE = avrdude
-REMOVE = rm -f
-COPY = cp
-WINSHELL = cmd
-
-
-# Define Messages
-# English
-MSG_ERRORS_NONE = Errors: none
-MSG_BEGIN = -------- begin --------
-MSG_END = --------  end  --------
-MSG_SIZE_BEFORE = Size before: 
-MSG_SIZE_AFTER = Size after:
-MSG_COFF = Converting to AVR COFF:
-MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
-MSG_FLASH = Creating load file for Flash:
-MSG_EEPROM = Creating load file for EEPROM:
-MSG_EXTENDED_LISTING = Creating Extended Listing:
-MSG_SYMBOL_TABLE = Creating Symbol Table:
-MSG_LINKING = Linking:
-MSG_COMPILING = Compiling:
-MSG_ASSEMBLING = Assembling:
-MSG_CLEANING = Cleaning project:
-
-
-
-
-# Define all object files.
-OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
-
-# Define all listing files.
-LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
-
-
-# Compiler flags to generate dependency files.
-GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
-
-
-# Combine all necessary flags and optional flags.
-# Add target processor to flags.
-ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
-
-
-
-
-
-# Default target.
-all: begin gccversion sizebefore build sizeafter end
-
-build: elf hex eep lss sym
-
-elf: $(TARGET).elf
-hex: $(TARGET).hex
-eep: $(TARGET).eep
-lss: $(TARGET).lss 
-sym: $(TARGET).sym
-
-
-
-# Eye candy.
-# AVR Studio 3.x does not check make's exit code but relies on
-# the following magic strings to be generated by the compile job.
-begin:
-	@echo
-	@echo $(MSG_BEGIN)
-
-end:
-	@echo $(MSG_END)
-	@echo
-
-
-# Display size of file.
-HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
-ELFSIZE = $(SIZE) -A $(TARGET).elf
-AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
-
-sizebefore:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-sizeafter:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-
-
-# Display compiler version information.
-gccversion : 
-	@$(CC) --version
-
-
-
-# Program the device.  
-program: $(TARGET).hex $(TARGET).eep
-	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
-
-# Generate avr-gdb config/init file which does the following:
-#     define the reset signal, load the target file, connect to target, and set 
-#     a breakpoint at main().
-gdb-config: 
-	@$(REMOVE) $(GDBINIT_FILE)
-	@echo define reset >> $(GDBINIT_FILE)
-	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
-	@echo end >> $(GDBINIT_FILE)
-	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
-	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
-ifeq ($(DEBUG_BACKEND),simulavr)
-	@echo load  >> $(GDBINIT_FILE)
-endif	
-	@echo break main >> $(GDBINIT_FILE)
-	
-debug: gdb-config $(TARGET).elf
-ifeq ($(DEBUG_BACKEND), avarice)
-	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
-	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
-	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
-	@$(WINSHELL) /c pause
-	
-else
-	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
-	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
-endif
-	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
-	
-
-
-
-# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
-COFFCONVERT=$(OBJCOPY) --debugging \
---change-section-address .data-0x800000 \
---change-section-address .bss-0x800000 \
---change-section-address .noinit-0x800000 \
---change-section-address .eeprom-0x810000 
-
-
-coff: $(TARGET).elf
-	@echo
-	@echo $(MSG_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
-
-
-extcoff: $(TARGET).elf
-	@echo
-	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
-
-
-
-# Create final output files (.hex, .eep) from ELF output file.
-%.hex: %.elf
-	@echo
-	@echo $(MSG_FLASH) $@
-	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
-
-%.eep: %.elf
-	@echo
-	@echo $(MSG_EEPROM) $@
-	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
-	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
-
-# Create extended listing file from ELF output file.
-%.lss: %.elf
-	@echo
-	@echo $(MSG_EXTENDED_LISTING) $@
-	$(OBJDUMP) -h -S $< > $@
-
-# Create a symbol table from ELF output file.
-%.sym: %.elf
-	@echo
-	@echo $(MSG_SYMBOL_TABLE) $@
-	$(NM) -n $< > $@
-
-
-
-# Link: create ELF output file from object files.
-.SECONDARY : $(TARGET).elf
-.PRECIOUS : $(OBJ)
-%.elf: $(OBJ)
-	@echo
-	@echo $(MSG_LINKING) $@
-	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
-
-
-# Compile: create object files from C source files.
-%.o : %.c
-	@echo
-	@echo $(MSG_COMPILING) $<
-	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
-
-
-# Compile: create assembler files from C source files.
-%.s : %.c
-	$(CC) -S $(ALL_CFLAGS) $< -o $@
-
-
-# Assemble: create object files from assembler source files.
-%.o : %.S
-	@echo
-	@echo $(MSG_ASSEMBLING) $<
-	$(CC) -c $(ALL_ASFLAGS) $< -o $@
-
-# Create preprocessed source for use in sending a bug report.
-%.i : %.c
-	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
-
-
-# Target: clean project.
-clean: begin clean_list end
-
-clean_list :
-	@echo
-	@echo $(MSG_CLEANING)
-	$(REMOVE) $(TARGET).hex
-	$(REMOVE) $(TARGET).eep
-	$(REMOVE) $(TARGET).cof
-	$(REMOVE) $(TARGET).elf
-	$(REMOVE) $(TARGET).map
-	$(REMOVE) $(TARGET).sym
-	$(REMOVE) $(TARGET).lss
-	$(REMOVE) $(OBJ)
-	$(REMOVE) $(LST)
-	$(REMOVE) $(SRC:.c=.s)
-	$(REMOVE) $(SRC:.c=.d)
-	$(REMOVE) .dep/*
-
-
-
-# Include the dependency files.
--include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
-
-
-# Listing of phony targets.
-.PHONY : all begin finish end sizebefore sizeafter gccversion \
-build elf hex eep lss sym coff extcoff \
-clean clean_list program debug gdb-config
-
Index: trunk/cardbox_test/uart.h
===================================================================
--- trunk/cardbox_test/uart.h	(revision 133)
+++ trunk/cardbox_test/uart.h	(nonexistent)
@@ -1,47 +0,0 @@
-/** @file uart.h
- *
- *	@brief Initializes UART functions using the UART hardware module
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef UART_H
-#define UART_H
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-
-/** **/
-#define UART_TX_OFF 0
-#define UART_TX_ON 1
-
-/** @brief RX Pin for the UART **/
-#define RX		_BV(PD0)
-#define TX		_BV(PD1)
-#define TX_EN	_BV(PB1)
-
-
-/** @brief The most recently received byte **/
-//extern char received_byte;
-/** @brief If the value in received_byte has been read or not **/
-//extern char	byte_ready;
-//extern char *transmit_data;
-//extern char transmit_size;
-//extern char transmitting;
-
-/** @brief Initializes the UART registers and sets it to the buad rate which msut be the 
- *			value that is defined in the datasheet for any particular speed (ie: 51 -> 9600bps)
- **/
-static inline void init_uart(int baud);
-/** @brief Gets latest byte and returns it in output_byte. If the byte was already read, returns -1 
- *			otherwise it returns 0 
- **/
-static char uart_get_byte(char *output_byte);
-/** @brief Sends a character array of size size. If we are currently transmitting it will block until the
-  * 	the current transmit is done. 
-  **/
-static void uart_send_byte(char data);
-static inline void uart_send_bytes(char *data, int size);
-static inline void uart_enable_transmit(void);
-static inline void uart_disable_transmit(void);
-#endif
Index: trunk/cardbox_test/main.c
===================================================================
--- trunk/cardbox_test/main.c	(revision 133)
+++ trunk/cardbox_test/main.c	(nonexistent)
@@ -1,431 +0,0 @@
-/** @file main.c
- *  @brief Contains the main function and cardbox specific helper functions for the cardbox for Tooltron.
- *
- *  @author Suresh Nidhiry (snidhiry), Kevin Woo (kwoo)
- **/
-
-/* Includes */
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include "USI_UART_config.h"
-#include "uart.h"
-#include "timer.h"
-#include "io_mine.h"
-
-
-
-/***** Self Identity *****/
-/** @brief This is the ADDRESS. Make sure it conforms to Tooltron specs */
-#define ADDR			253
-
-/***** Transmit Defines *****/
-/** @brief Maximum size that the cardID + tool number can be in bytes */
-#define MAX_DATA_SIZE	10			//9 card digits, 1 byte for tool number
-/** @brief Maximum size that a cardID can be in bytes */
-#define MAX_CARD_SIZE	9			//9 card digits
-/** @brief How long a packet is before the payload section. Used for offsets */
-#define HEADER_OFFSET   2
-/** @brief Maximum size that a packet can be */
-#define MAX_PACKET_SIZE HEADER_OFFSET + MAX_DATA_SIZE
-/** @brief Baud rate for the rs485 network. This must be uniform across card, tool, and server */
-#define BAUD            51          //9600bps
-/** @brief The default server id that we send our requests to */
-#define DEFAULT_SERVER  254
-
-/***** Time Defines *****/
-/** @brief Max time in seconds to leave a red or green light on */
-#define MAX_LED_ON      5
-
-
-/***** States for for the main cardbox FSM *****/
-/** @brief Wait until a card is swiped and store the card id */
-#define INIT_CARD_READ		0x01
-/** @brief Wait until a tool is selected and store it */
-#define INIT_TOOL_READ		0x02
-/** @brief Package and transmit data to server */
-//#define SEND_DATA			0x03
-/** @brief Monitor line to see if the server accepts or denies the request */
-#define TXRX_DATA		0x03
-/** @brief Run the fail subroutine if we were denied. Return to INIT_CARD_READ */
-#define FAIL				0x04
-
-/***** States For Packet Parsing *****/
-/** @brief No state */
-#define NONE				0x00
-/** @brief Waiting for the first byte of the header to be received */
-#define HEAD				0x01
-/** @breif Waiting for the first byte of this addr to be received */
-#define DEST				0x02
-/** @brief Receive data */
-#define DATA				0x03 
-
-/***** Main Function Prototypes *****/
-static inline void success(void);
-static inline void fail(void);
-static void get_packet(char* dest, char* data);
-
-/***** Global Variables *****/
-static char received_byte;	        //Byte received
-static char byte_ready;		        //New byte has been received
-static char *transmit_data;	        //String to send
-static char transmit_size;	        //Size of string that we are sending
-static volatile char transmitting;           //Flag to indicate that we are currently sending data
-static volatile char seconds;		//Seconds elapsed
-static volatile char minutes;		//Minutes exlapsed
-static char timeout_flag;           //Indicates that timeout has occured
-
-
-/***********************************************************/
-
-
-int main(void){
-    unsigned long i,j;
-    init_pins();
- 
- /***** LED Test - Success *****/
- /*
-    while(1) {
-        toggle_led_on(LED_GREEN);
-        toggle_led_on(LED_YELLOW);
-        toggle_led_on(LED_RED);
-    	for(i = 0; i < 60001; i++)
-            for(j = 0; j < 1000; j++);
-            
-        toggle_led_off(LED_GREEN);        
-        toggle_led_off(LED_YELLOW);  
-        toggle_led_off(LED_RED);    
-    	for(i = 0; i < 60001; i++)
-            for(j = 0; j < 1000; j++);              
-    }
-  */
- 
-   init_uart(BAUD);
-    
-    uart_enable_transmit();
-    
-    _delay_loop_2(4000);    //Approximately 2ms
-    
-    while(1){
-       	while (!(UCSRA & (1 << UDRE)));
-       	toggle_led_on(LED_RED);       	
-    	UDR = 'F';
-       	while (!(UCSRA & (1 << UDRE)));
-    	toggle_led_on(LED_YELLOW);
-
-        _delay_loop_2(4000);    //Approxmiately 2ms
-
-    	toggle_led_off(LED_RED);
-    	toggle_led_off(LED_YELLOW);
-    }
-    
-    return 0;
-}
-
-//Sets directions of pins
-static inline void init_pins() {
-	DDRB |= RELAY;
-	DDRD |= LED_RED | LED_YELLOW | LED_GREEN;
-	
-	return;	
-}
-
-//Turns on an off an LED. which should be the defined pins (1 byte) and
-// state is: 1 -> on, 0 -> off
-static inline void toggle_led_on(char which) {
-    PORTD |= which;
-	return;
-}
-
-static inline void toggle_led_off(char which) {
-	PORTD &= ~which;
-	return;
-}
-
-/** @file uart.c
- *	
- *	@brief Implements UART functionality in hardware
- *
- *	@author Kevin Woo (kwoo)
- */
-
-
-
-static inline void init_uart(int baud) {
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-
-	UCSRB = 0;
-	UCSRC = 0;
-
-	/* Enable RX/TX and RX/TX Interrupt */
-	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);
-	
-	/* Asynchronous mode, 1 bit stop, 8bit transmissions */
-	UCSRC = _BV(UCSZ1) | _BV(UCSZ0);
- 
- 	/* Enable RX pin as input */
-	PORTD &= ~RX;
-	
-	/* Enable TX pin as output */
-	DDRD |= TX;
-	
-	/* Enable the TXEN pin as output */
-	DDRB |= TX_EN;
-	
-	/* RX Status Variables */
-	received_byte = 0;	//Initialize first byte
-	byte_ready = 0;		//Byte is not ready to be read	
-	
-	/* TX Status Variables */
-	transmitting = 0;
-	transmit_size = 0;
-}
-
-static inline void uart_enable_transmit() {
-    PINB |= TX_EN;
-}
-
-static inline void uart_disable_transmit() {
-	PINB &= ~TX_EN;
-}
-
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File              : USI_UART.c
-* Compiler          : IAR EWAAVR 2.28a
-* Created           : 18.07.2002 by JLL
-* Modified          : 02-10-2003 by LTA
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : ATtiny26
-*
-* Application Note  : AVR307 - Half duplex UART using the USI Interface
-*
-* Description       : Functions for USI_UART_receiver and USI_UART_transmitter.
-*                     Uses Pin Change Interrupt to detect incomming signals.
-*
-*
-****************************************************************************/
-    
-//#include <avr/io.h>  // Note there is a bug in ioavr.h file that includes iotiny22.h instead of iotiny26.h.
-//#include <iotiny26.h>
-//#include <avr/interrupt.h>
-//#include <avr/signal.h>
-//#include "USI_UART_config.h"
-
-
-//********** USI UART Defines **********//
-#define RXPIN	PB5
-#define CLKPIN	PB7
-
-#define STARTFLAG 		0x45 //100 0101 //0x0B  //01011
-#define NSTARTFLAG		0x3A //011 1010 //0x14  //10100
-#define STOPFLAG      0x1F //001 1111  0x1F  //11111
-#define NSTOPFLAG		  0x60 //110 0000 0x00  //00000
-#define REVSTART      0x51 //101 0001  0x1A  //11010
-#define NREVSTART		  0x2E //010 1110 0x05  //00101
-
-#define DATA_BITS                 7
-#define START_BIT                 7
-#define STOP_BIT                  7
-#define HALF_FRAME                7
-
-
-#define USI_COUNTER_MAX_COUNT     16
-#define INTERRUPT_STARTUP_DELAY   (0x11 / TIMER_PRESCALER)
-
-#define USI_COUNTER_SEED_RECEIVE  ( USI_COUNTER_MAX_COUNT - (DATA_BITS*2) )
-
-/* General defines */
-#define TRUE                      1
-#define FALSE                     0
-
-//********** Static Variables **********//
-
-/*__no_init __regvar static unsigned char USI_UART_TxData[15];   // Tells the compiler to store the byte to be transmitted in registry.
-*/
-//static unsigned char			USI_UART_TxData;
-//static unsigned char          UART_RxByte;  // UART buffers. Size is definable in the header file.
-
-
-static volatile union USI_UART_status                           // Status byte holding flags.
-{
-    unsigned char status;
-    struct
-    {
-        unsigned char wait_Card:1;
-        unsigned char wait_Start:1;
-        unsigned char ongoing_Reception_Of_Package:1;
-        unsigned char reception_Buffer_Overflow:1;
-        unsigned char data_Ready:1;
-        unsigned char flag5:1;
-        unsigned char flag6:1;
-        unsigned char flag7:1;
-    };
-} USI_UART_status = {0};
-
-
-//********** USI_UART functions **********//
-
-// Reverses the order of bits in a byte.
-// I.e. MSB is swapped with LSB, etc.
-static inline unsigned char Bit_Reverse5( unsigned char x )
-{
-	unsigned char c = x&0x04;
-//	x = x<<3;
-    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-    return x;    
-}
-
-static inline unsigned char Bit_Reverse( unsigned char x )
-{
-  unsigned char c=0;
-  
-  c |=0x01&(x>>6);
-  c |=0x02&(x>>4);
-  c |=0x04&(x>>2);
-  c |=0x08&(x>>0);
-  c |=0x10&(x<<2);
-  c |=0x20&(x<<4);
-  c |=0x40&(x<<6);
-
-
-//	unsigned char c = x&0x08;
-//	x = x<<3;
-//    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-//    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-//    return x;    
-
-  return c;
-}
-
-
-
-// Initialise USI for UART reception.
-// Note that this function only enables pinchange interrupt on the USI Data Input pin.
-// The USI is configured to read data within the pinchange interrupt.
-static inline void USI_UART_Initialise_Receiver( void )        
-{  
-    PORTB |=   (1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4);         // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)   
-    DDRB  &= ~((1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4));        // Set USI DI, DO and SCK pins as inputs.  
-    USICR  =  0;                                            // Disable USI.
-    EIFR   =  (1<<PCIF);                                    // Clear pin change interrupt flag.
-	PCMSK |= (1<<RXPIN);
-    GIMSK |=  (1<<PCIE);                                   // Enable pin change interrupt for PB7:0.
-	USI_UART_status.data_Ready=FALSE;
-	USI_UART_status.wait_Card=TRUE;
-	USI_UART_status.wait_Start=FALSE;
-	USI_UART_status.ongoing_Reception_Of_Package = FALSE; 
-	RxIndex=0;
-}
-
-// Returns a byte from the receive buffer. Waits if buffer is empty.
-static unsigned char USI_UART_Receive_Bytes( void )                
-{
-
-    while ( !USI_UART_status.data_Ready );                 // Wait for incomming data 
-	USI_UART_status.data_Ready=FALSE;
-    return RxIndex;              // Reverse the order of the bits in the data byte before it returns data from the buffer.
-}
-
-// Check if there is data in the receive buffer.
-static inline unsigned char USI_UART_Data_In_Receive_Buffer( void )        
-{
-    return ( USI_UART_status.data_Ready );
-
-}
-
-
-// ********** Interrupt Handlers ********** //
-
-// The pin change interrupt is used to detect USI_UART reseption.
-// It is here the USI is configured to sample the UART signal.
-
-ISR(PCINT_vect)    
-{  
-
-		
-   if ((USI_UART_status.wait_Card)&&(!( PINB & (1<<RXPIN) )))                                     // If the USI DI pin is low, then it is likely that it
-    {                                                             //  was this pin that generated the pin change interrupt.
-        USICR  = (0<<USISIE)|(1<<USIOIE)|                         // Enable USI Counter OVF interrupt.
-                 (0<<USIWM1)|(1<<USIWM0)|                         // Select Three Wire mode.
-                 (1<<USICS1)|(1<<USICS0)|(0<<USICLK)|             // Select Timer0 OVER as USI Clock source.
-                 (0<<USITC);                                           
-                                                                  // Note that enabling the USI will also disable the pin change interrupt.
-        USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-                 USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-        PCMSK |= (1<<CLKPIN);
-        PCMSK &=~(1<<RXPIN);
-        //GIMSK &=  ~(1<<PCIE);                                    // Disable pin change interrupt for PB3:0. 
-        USI_UART_status.wait_Start = TRUE;
-        USI_UART_status.wait_Card = FALSE;       
-        //PORTD |= (1<<PD4); 
-
-    }
-	else if((USI_UART_status.wait_Start)&&(!(PINB&(1<<CLKPIN))))
-	{
-//	   	PORTD |= (1<<PD4); 
-		if((USIDR&0x7F)==(NREVSTART))  /////////////MAYBE SHOULD BE REVSTART
-		{
-			
-      //PORTD |= (1<<PD4);
-			USI_UART_status.wait_Start = FALSE;
-			USI_UART_status.ongoing_Reception_Of_Package = TRUE;  
-			USISR  = 0xF0 |                                            // Clear all USI interrupt flags.
-					 USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-			GIMSK &= ~(1<<PCIE);
-			PCMSK &=~(1<<CLKPIN);
-		}
-	}
-}
-
-// The USI Counter Overflow interrupt is used for moving data between memmory and the USI data register.
-// The interrupt is used for both transmission and reception.
-SIGNAL(SIG_USI_OVERFLOW)                              
-{
-
-    if(USI_UART_status.ongoing_Reception_Of_Package)
-    {          
-		char b;
-
-   
-		b=Bit_Reverse(~USIDR)&0x0F;
-
-	//	PORTD |= (1<<PD5);
-		if(b>9){
-
-   //   PORTD |= (1<<PD6);
-         /////////Not needed?:
-     //   PORTB |=   (1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4);         // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)   
-       //   DDRB  &= ~((1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4));        // Set USI DI, DO and SCK pins as inputs. 
-  
-        USICR  =  0;                                            // Disable USI.
-        EIFR   =  (1<<PCIF);                                    // Clear pin change interrupt flag.
-      //	GIMSK |=  (1<<PCIE);                                   // Enable pin change interrupt for PB3:0.
-      //	PCMSK |= (1<<RXPIN);		
-        USI_UART_status.data_Ready=TRUE;    
-		}
-		else
-		{
-		//	PORTD |= (1<<PD4);
-			RxStream[RxIndex] = b;                                // Store received data in buffer. Note that the data must be bit reversed before used. 
-			RxIndex=RxIndex+1;
-            ///////REVERSE DATA??
-			USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-					USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-	
-		}
-
-    }
-    
-}
Index: trunk/cardbox_test/io_mine.h
===================================================================
--- trunk/cardbox_test/io_mine.h	(revision 133)
+++ trunk/cardbox_test/io_mine.h	(nonexistent)
@@ -1,67 +0,0 @@
-/** @file io.h
- *
- *	@brief Implements IO functionality such as turning LEDs on
- *			and off, turning the relays on or off, and returning
- *			button values
- *	
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef IO_H
-#define IO_H
-
-#include <avr/io.h>
-#include "timer.h"
-
-/* Pin Defines */
-/** @brief Pin that turns the relay on/off */
-#define RELAY 				_BV(PB3)
-/** @brief Red LED Pin*/
-#define LED_RED				_BV(PD6)
-/** @brief Yellow LED Pin*/
-#define LED_YELLOW			_BV(PD5)
-/** @brief Green LED Pin*/
-#define LED_GREEN			_BV(PD4)
-/** @brief Black Button Pin*/
-#define BUTTON_BLACK		_BV(PD2)
-/** @brief How much to shift out of the port that Black button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_BLACK_SHIFT	0x02
-/** @brief Red Button Pin*/
-#define BUTTON_RED			_BV(PD3)
-/** @brief How much to shift out of the port that Red button is on to get a 1 or a 0 in the LSB*/
-#define BUTTON_RED_SHIFT	0x03
-
-/* Keypad definitions */
-/** @brief ROW1 of the keypad */
-#define ROW1 _BV(PD2)
-/** @brief ROW2 of the keypad */
-#define ROW2 _BV(PD3)
-/** @brief ROW3 of the keypad */
-#define ROW3 _BV(PA1)
-/** @brief ROW4 of the keypad */
-#define ROW4 _BV(PA0)
-/** @brief COL1 of the keypad */
-#define COL1 _BV(PB6)
-/** @brief COL2 of the keypad */
-#define COL2 _BV(PB4)
-/** @brief COL3 of the keypad */
-#define COL3 _BV(PB2)
-/** @brief COL4 of the keypad */
-#define COL4 _BV(PB0)
-
-
-/** @brief Sets the direction of the pins */
-static inline void init_pins(void);
-/** @brief Toggles the relay on or off. state == 1 is on, state == 0 is off */
-static inline void toggle_power_on(void);
-static inline void toggle_power_off(void);
-/** @brief Sets the state of the given LED (which) to state where state == 1 is on, state == 0 is off */
-static inline void toggle_led_on(char which);
-static inline void toggle_led_off(char which);
-/** @brief Reads the value of the black button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_black(void);
-/** @brief Reads the value of the red button and returns 1 if it is pressed and 0 otherwise */
-static inline char read_button_red(void);
-/** @brief Waits until a button the keypad is pressed. Uses the timer to time out the loop in case none is selected */
-static char get_button(void);
-#endif
Index: trunk/cardbox_test/timer.h
===================================================================
--- trunk/cardbox_test/timer.h	(revision 133)
+++ trunk/cardbox_test/timer.h	(nonexistent)
@@ -1,29 +0,0 @@
-/** @file timer.h
- *	
- * 	@breif Timer functions
- *
- *	@author Kevin Woo (kwoo)
- */
-
-#ifndef TIMER_H
-#define TIMER_H
-
-/** @brief Max time that we can wait for a full packet from the server before we timeout */
-#define TIME_OUT		5
-
-/** @brief Seconds that have elapsed since the timer started */
-//extern volatile char seconds;
-/** @brief Minutes that have elapsed since the timer started */
-//extern volatile char minutes;
-//extern char timeout_flag;
-
-/** @brief Sets the registers to use the timer for couting in real time */
-static inline void init_timer(void);
-/** @brief Starts the timer from last position*/
-static inline void start_timer(void);
-/** @brief Stops the timer from counting*/
-static inline void stop_timer(void);
-/** @brief Resets the values of the timer to 0*/
-static inline void reset_timer(void);
-
-#endif
Index: trunk/cardbox_test/USI_UART_config.h
===================================================================
--- trunk/cardbox_test/USI_UART_config.h	(revision 133)
+++ trunk/cardbox_test/USI_UART_config.h	(nonexistent)
@@ -1,61 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File          : USI_UART_config.h
-* Compiler      : IAR EWAAVR 2.28a
-* Created       : 18.07.2002 by JLL
-* Modified      : 02-10-2003 by LTA
-*
-* Support mail  : avr@atmel.com
-*
-* AppNote       : AVR307 - Half duplex UART using the USI Interface
-*
-* Description   : Header file for USI_UART driver
-*
-*
-****************************************************************************/
-
-#ifndef __USI_UART_config_h
-#define __USI_UART_config_h
-
-//********** USI UART Defines **********//
-
-//#define SYSTEM_CLOCK             14745600
-//#define SYSTEM_CLOCK             11059200
-#define SYSTEM_CLOCK              8000000
-//#define SYSTEM_CLOCK              7372800
-//#define SYSTEM_CLOCK              3686400
-//#define SYSTEM_CLOCK              2000000
-//#define SYSTEM_CLOCK              1843200
-//#define SYSTEM_CLOCK              1000000
-
-//#define BAUDRATE                   115200
-//#define BAUDRATE                    57600
-//#define BAUDRATE                    28800
-//#define BAUDRATE                    19200
-//#define BAUDRATE                    14400
-#define BAUDRATE                     9600
-
-//#define TIMER_PRESCALER           1
-#define TIMER_PRESCALER           8     
-
-#define UART_RX_BUFFER_SIZE        4     /* 2,4,8,16,32,64,128 or 256 bytes */
-#define UART_TX_BUFFER_SIZE        4
-
-
-//********** USI_UART Prototypes **********//
-static unsigned char			RxStream[100];
-
-static unsigned char 			RxIndex;
-static unsigned char USI_UART_Receive_Bytes( void );
-static inline unsigned char USI_UART_Data_In_Receive_Buffer( void );
-static inline unsigned char Bit_Reverse( unsigned char );
-static inline void          USI_UART_Initialise_Receiver( void );
-//Don't use these
-void          USI_UART_Initialise_Transmitter( void );
-void          USI_UART_Transmit_Byte( unsigned char );
-void          USI_UART_Flush_Buffers( void );
-//End
-
-#endif
Index: trunk/cardbox_test/main.hex
===================================================================
--- trunk/cardbox_test/main.hex	(revision 133)
+++ trunk/cardbox_test/main.hex	(nonexistent)
@@ -1,31 +0,0 @@
-:1000000012C02AC029C028C027C026C025C024C0CD
-:1000100023C022C021C052C01FC01EC01DC01CC0B2
-:1000200094C01AC019C011241FBECFEDCDBF10E07F
-:10003000A0E6B0E0E2EDF1E003C0C89531960D9284
-:10004000A036B107D1F710E0A0E6B0E001C01D92E4
-:10005000AF3CB107E1F701C0D3CFCFEDD0E0DEBFB9
-:10006000CDBFBB9A81B3806781BB12B883E390E0B8
-:1000700089B91AB813B888ED8AB986E083B990981F
-:10008000899AB99A1092C6001092C7001092CB00BC
-:100090001092CA00B19A80EA9FE00197F1F726E436
-:1000A0005D9BFECF969A2CB95D9BFECF959A80EA18
-:1000B0009FE00197F1F796989598F2CF1F920F92D3
-:1000C0000FB60F9211248F939F938091600080FF51
-:1000D00017C0B59915C08CE58DB982EF8EB980B582
-:1000E000806880BD80B58F7D80BD8091600082601A
-:1000F00080936000809160008E7F809360001EC0BE
-:100100008091600081FF1AC0B79918C08FB19927FC
-:100110008F7790708E9791F4809160008D7F80939F
-:1001200060008091600084608093600082EF8EB9EF
-:100130008BB78F7D8BBF80B58F7780BD9F918F915F
-:100140000F900FBE0F901F9018951F920F920FB631
-:100150000F9211242F938F939F93EF93FF9380918E
-:10016000600082FF2CC08FB18095282F22952695A4
-:10017000269523702170982F92959F709270292B4D
-:10018000982F969596959470292B8870282B2F7010
-:100190002A3048F01DB880E28ABF809160008061FB
-:1001A000809360000CC08091C500E82FFF27EF59B5
-:1001B000FF4F20838F5F8093C50082EF8EB9FF9140
-:1001C000EF919F918F912F910F900FBE0F901F90E5
-:0201D000189580
-:00000001FF
Index: trunk/old/cardreader/USI_UART_config.h
===================================================================
--- trunk/old/cardreader/USI_UART_config.h	(revision 133)
+++ trunk/old/cardreader/USI_UART_config.h	(nonexistent)
@@ -1,59 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File          : USI_UART_config.h
-* Compiler      : IAR EWAAVR 2.28a
-* Created       : 18.07.2002 by JLL
-* Modified      : 02-10-2003 by LTA
-*
-* Support mail  : avr@atmel.com
-*
-* AppNote       : AVR307 - Half duplex UART using the USI Interface
-*
-* Description   : Header file for USI_UART driver
-*
-*
-****************************************************************************/
-
-#ifndef __USI_UART_config_h
-#define __USI_UART_config_h
-
-//********** USI UART Defines **********//
-
-//#define SYSTEM_CLOCK             14745600
-//#define SYSTEM_CLOCK             11059200
-#define SYSTEM_CLOCK              8000000
-//#define SYSTEM_CLOCK              7372800
-//#define SYSTEM_CLOCK              3686400
-//#define SYSTEM_CLOCK              2000000
-//#define SYSTEM_CLOCK              1843200
-//#define SYSTEM_CLOCK              1000000
-
-//#define BAUDRATE                   115200
-//#define BAUDRATE                    57600
-//#define BAUDRATE                    28800
-//#define BAUDRATE                    19200
-//#define BAUDRATE                    14400
-#define BAUDRATE                     9600
-
-//#define TIMER_PRESCALER           1
-#define TIMER_PRESCALER           8     
-
-#define UART_RX_BUFFER_SIZE        4     /* 2,4,8,16,32,64,128 or 256 bytes */
-#define UART_TX_BUFFER_SIZE        4
-
-
-//********** USI_UART Prototypes **********//
-static unsigned char			RxStream[100];
-
-static unsigned char 			RxIndex;
-
-unsigned char Bit_Reverse( unsigned char );
-void          USI_UART_Flush_Buffers( void );
-void          USI_UART_Initialise_Receiver( void );
-void          USI_UART_Initialise_Transmitter( void );
-void          USI_UART_Transmit_Byte( unsigned char );
-unsigned char USI_UART_Receive_Bytes( void );
-unsigned char USI_UART_Data_In_Receive_Buffer( void );
-#endif
Index: trunk/old/cardreader/USI_UART.c
===================================================================
--- trunk/old/cardreader/USI_UART.c	(revision 133)
+++ trunk/old/cardreader/USI_UART.c	(nonexistent)
@@ -1,238 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File              : USI_UART.c
-* Compiler          : IAR EWAAVR 2.28a
-* Created           : 18.07.2002 by JLL
-* Modified          : 02-10-2003 by LTA
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : ATtiny26
-*
-* Application Note  : AVR307 - Half duplex UART using the USI Interface
-*
-* Description       : Functions for USI_UART_receiver and USI_UART_transmitter.
-*                     Uses Pin Change Interrupt to detect incomming signals.
-*
-*
-****************************************************************************/
-    
-#include <avr/io.h>  // Note there is a bug in ioavr.h file that includes iotiny22.h instead of iotiny26.h.
-//#include <iotiny26.h>
-#include <avr/interrupt.h>
-//#include <avr/signal.h>
-#include "USI_UART_config.h"
-
-
-//********** USI UART Defines **********//
-#define RXPIN	PB5
-#define CLKPIN	PB7
-
-#define STARTFLAG 		0x45 //100 0101 //0x0B  //01011
-#define NSTARTFLAG		0x3A //011 1010 //0x14  //10100
-#define STOPFLAG      0x1F //001 1111  0x1F  //11111
-#define NSTOPFLAG		  0x60 //110 0000 0x00  //00000
-#define REVSTART      0x51 //101 0001  0x1A  //11010
-#define NREVSTART		  0x2E //010 1110 0x05  //00101
-
-#define DATA_BITS                 7
-#define START_BIT                 7
-#define STOP_BIT                  7
-#define HALF_FRAME                7
-
-
-#define USI_COUNTER_MAX_COUNT     16
-#define INTERRUPT_STARTUP_DELAY   (0x11 / TIMER_PRESCALER)
-
-#define USI_COUNTER_SEED_RECEIVE  ( USI_COUNTER_MAX_COUNT - (DATA_BITS*2) )
-
-/* General defines */
-#define TRUE                      1
-#define FALSE                     0
-
-//********** Static Variables **********//
-
-/*__no_init __regvar static unsigned char USI_UART_TxData[15];   // Tells the compiler to store the byte to be transmitted in registry.
-*/
-//static unsigned char			USI_UART_TxData;
-//static unsigned char          UART_RxByte;  // UART buffers. Size is definable in the header file.
-
-
-static volatile union USI_UART_status                           // Status byte holding flags.
-{
-    unsigned char status;
-    struct
-    {
-        unsigned char wait_Card:1;
-        unsigned char wait_Start:1;
-        unsigned char ongoing_Reception_Of_Package:1;
-        unsigned char reception_Buffer_Overflow:1;
-        unsigned char data_Ready:1;
-        unsigned char flag5:1;
-        unsigned char flag6:1;
-        unsigned char flag7:1;
-    };
-} USI_UART_status = {0};
-
-
-//********** USI_UART functions **********//
-
-// Reverses the order of bits in a byte.
-// I.e. MSB is swapped with LSB, etc.
-unsigned char Bit_Reverse5( unsigned char x )
-{
-	unsigned char c = x&0x04;
-//	x = x<<3;
-    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-    return x;    
-}
-
-unsigned char Bit_Reverse( unsigned char x )
-{
-  unsigned char c=0;
-  
-  c |=0x01&(x>>6);
-  c |=0x02&(x>>4);
-  c |=0x04&(x>>2);
-  c |=0x08&(x>>0);
-  c |=0x10&(x<<2);
-  c |=0x20&(x<<4);
-  c |=0x40&(x<<6);
-
-
-//	unsigned char c = x&0x08;
-//	x = x<<3;
-//    x = ((x >> 1) & 0x09) | ((x << 1) & 0x12);
-//    x = ((x >> 3) & 0x03) | ((x << 3) & 0x18)|c;  
-//    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
-
-//    return x;    
-
-  return c;
-}
-
-
-
-// Initialise USI for UART reception.
-// Note that this function only enables pinchange interrupt on the USI Data Input pin.
-// The USI is configured to read data within the pinchange interrupt.
-void USI_UART_Initialise_Receiver( void )        
-{  
-    PORTB |=   (1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4);         // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)   
-    DDRB  &= ~((1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4));        // Set USI DI, DO and SCK pins as inputs.  
-    USICR  =  0;                                            // Disable USI.
-    EIFR   =  (1<<PCIF);                                    // Clear pin change interrupt flag.
-	PCMSK |= (1<<RXPIN);
-    GIMSK |=  (1<<PCIE);                                   // Enable pin change interrupt for PB7:0.
-	USI_UART_status.data_Ready=FALSE;
-	USI_UART_status.wait_Card=TRUE;
-	USI_UART_status.wait_Start=FALSE;
-	USI_UART_status.ongoing_Reception_Of_Package = FALSE; 
-	RxIndex=0;
-}
-
-// Returns a byte from the receive buffer. Waits if buffer is empty.
-unsigned char USI_UART_Receive_Bytes( void )                
-{
-
-    while ( !USI_UART_status.data_Ready );                 // Wait for incomming data 
-	USI_UART_status.data_Ready=FALSE;
-    return RxIndex;              // Reverse the order of the bits in the data byte before it returns data from the buffer.
-}
-
-// Check if there is data in the receive buffer.
-unsigned char USI_UART_Data_In_Receive_Buffer( void )        
-{
-    return ( USI_UART_status.data_Ready );
-
-}
-
-
-// ********** Interrupt Handlers ********** //
-
-// The pin change interrupt is used to detect USI_UART reseption.
-// It is here the USI is configured to sample the UART signal.
-
-ISR(PCINT_vect)    
-{  
-
-		
-   if ((USI_UART_status.wait_Card)&&(!( PINB & (1<<RXPIN) )))                                     // If the USI DI pin is low, then it is likely that it
-    {                                                             //  was this pin that generated the pin change interrupt.
-        USICR  = (0<<USISIE)|(1<<USIOIE)|                         // Enable USI Counter OVF interrupt.
-                 (0<<USIWM1)|(1<<USIWM0)|                         // Select Three Wire mode.
-                 (1<<USICS1)|(1<<USICS0)|(0<<USICLK)|             // Select Timer0 OVER as USI Clock source.
-                 (0<<USITC);                                           
-                                                                  // Note that enabling the USI will also disable the pin change interrupt.
-        USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-                 USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-        PCMSK |= (1<<CLKPIN);
-        PCMSK &=~(1<<RXPIN);
-        //GIMSK &=  ~(1<<PCIE);                                    // Disable pin change interrupt for PB3:0. 
-        USI_UART_status.wait_Start = TRUE;
-        USI_UART_status.wait_Card = FALSE;       
-        PORTD |= (1<<PD4); 
-
-    }
-	else if((USI_UART_status.wait_Start)&&(!(PINB&(1<<CLKPIN))))
-	{
-//	   	PORTD |= (1<<PD4); 
-		if((USIDR&0x7F)==(NREVSTART))  /////////////MAYBE SHOULD BE REVSTART
-		{
-			
-      //PORTD |= (1<<PD4);
-			USI_UART_status.wait_Start = FALSE;
-			USI_UART_status.ongoing_Reception_Of_Package = TRUE;  
-			USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-					 USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-			GIMSK &= ~(1<<PCIE);
-			PCMSK &=~(1<<CLKPIN);
-		}
-	}
-}
-
-// The USI Counter Overflow interrupt is used for moving data between memmory and the USI data register.
-// The interrupt is used for both transmission and reception.
-SIGNAL(SIG_USI_OVERFLOW)                              
-{
-
-    if(USI_UART_status.ongoing_Reception_Of_Package)
-    {          
-		char b;
-
-   
-		b=Bit_Reverse(~USIDR)&0x0F;
-
-	//	PORTD |= (1<<PD5);
-		if(b>9){
-
-   //   PORTD |= (1<<PD6);
-         /////////Not needed?:
-     //   PORTB |=   (1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4);         // Enable pull up on USI DO, DI and SCK pins. (And PB3 because of pin change interrupt)   
-       //   DDRB  &= ~((1<<PB7)|(1<<PB6)|(1<<PB5)|(1<<PB4));        // Set USI DI, DO and SCK pins as inputs. 
-  
-        USICR  =  0;                                            // Disable USI.
-        EIFR   =  (1<<PCIF);                                    // Clear pin change interrupt flag.
-      //	GIMSK |=  (1<<PCIE);                                   // Enable pin change interrupt for PB3:0.
-      //	PCMSK |= (1<<RXPIN);		
-        USI_UART_status.data_Ready=TRUE;    
-		}
-		else
-		{
-		//	PORTD |= (1<<PD4);
-			RxStream[RxIndex] = b;                                // Store received data in buffer. Note that the data must be bit reversed before used. 
-			RxIndex=RxIndex+1;
-            ///////REVERSE DATA??
-			USISR  = 0xF0 |                                           // Clear all USI interrupt flags.
-					USI_COUNTER_SEED_RECEIVE;                        // Preload the USI counter to generate interrupt.
-	
-		}
-
-    }
-    
-}
Index: trunk/old/cardreader/Makefile
===================================================================
--- trunk/old/cardreader/Makefile	(revision 133)
+++ trunk/old/cardreader/Makefile	(nonexistent)
@@ -1,507 +0,0 @@
-# Hey Emacs, this is a -*- makefile -*-
-#----------------------------------------------------------------------------
-# WinAVR Makefile Template written by Eric B. Weddington, J�rg Wunsch, et al.
-#
-# Released to the Public Domain
-#
-# Additional material for this makefile was written by:
-# Peter Fleury
-# Tim Henigan
-# Colin O'Flynn
-# Reiner Patommel
-# Markus Pfaff
-# Sander Pool
-# Frederik Rouleau
-#
-#----------------------------------------------------------------------------
-# On command line:
-#
-# make all = Make software.
-#
-# make clean = Clean out built project files.
-#
-# make coff = Convert ELF to AVR COFF.
-#
-# make extcoff = Convert ELF to AVR Extended COFF.
-#
-# make program = Download the hex file to the device, using avrdude.
-#                Please customize the avrdude settings below first!
-#
-# make debug = Start either simulavr or avarice as specified for debugging, 
-#              with avr-gdb or avr-insight as the front end for debugging.
-#
-# make filename.s = Just compile filename.c into the assembler code only.
-#
-# make filename.i = Create a preprocessed source file for use in submitting
-#                   bug reports to the GCC project.
-#
-# To rebuild project do "make clean" then "make all".
-#----------------------------------------------------------------------------
-
-
-# MCU name
-MCU = attiny2313
-
-
-# Processor frequency.
-#     This will define a symbol, F_CPU, in all source code files equal to the 
-#     processor frequency. You can then use this symbol in your source code to 
-#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
-#     automatically to create a 32-bit value in your source code.
-F_CPU = 8000000
-
-
-# Output format. (can be srec, ihex, binary)
-FORMAT = ihex
-
-
-# Target file name (without extension).
-TARGET = main_jimbo
-
-# List C source files here. (C dependencies are automatically generated.)
-SRC = $(TARGET).c
-
-
-# List Assembler source files here.
-#     Make them always end in a capital .S.  Files ending in a lowercase .s
-#     will not be considered source files but generated files (assembler
-#     output from the compiler), and will be deleted upon "make clean"!
-#     Even though the DOS/Win* filesystem matches both .s and .S the same,
-#     it will preserve the spelling of the filenames, and gcc itself does
-#     care about how the name is spelled on its command-line.
-ASRC = 
-
-
-# Optimization level, can be [0, 1, 2, 3, s]. 
-#     0 = turn off optimization. s = optimize for size.
-#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-OPT = s
-
-
-# Debugging format.
-#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
-#     AVR Studio 4.10 requires dwarf-2.
-#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
-DEBUG = dwarf-2
-
-
-# List any extra directories to look for include files here.
-#     Each directory must be seperated by a space.
-#     Use forward slashes for directory separators.
-#     For a directory that has spaces, enclose it in quotes.
-#EXTRAINCDIRS = C:\WinAVR\include\fwr
-
-
-# Compiler flag to set the C Standard level.
-#     c89   = "ANSI" C
-#     gnu89 = c89 plus GCC extensions
-#     c99   = ISO C99 standard (not yet fully implemented)
-#     gnu99 = c99 plus GCC extensions
-CSTANDARD = -std=gnu99
-
-
-# Place -D or -U options here
-CDEFS = -DF_CPU=$(F_CPU)UL
-
-
-# Place -I options here
-CINCS =
-
-
-
-#---------------- Compiler Options ----------------
-#  -g*:          generate debugging information
-#  -O*:          optimization level
-#  -f...:        tuning, see GCC manual and avr-libc documentation
-#  -Wall...:     warning level
-#  -Wa,...:      tell GCC to pass this to the assembler.
-#    -adhlns...: create assembler listing
-CFLAGS = -g$(DEBUG)
-CFLAGS += $(CDEFS) $(CINCS)
-CFLAGS += -O$(OPT)
-CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-CFLAGS += -Wall -Wstrict-prototypes
-CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
-CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-CFLAGS += $(CSTANDARD)
-
-
-#---------------- Assembler Options ----------------
-#  -Wa,...:   tell GCC to pass this to the assembler.
-#  -ahlms:    create listing
-#  -gstabs:   have the assembler create line number information; note that
-#             for use in COFF files, additional information about filenames
-#             and function names needs to be present in the assembler source
-#             files -- see avr-libc docs [FIXME: not yet described there]
-ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
-
-
-#---------------- Library Options ----------------
-# Minimalistic printf version
-PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
-
-# Floating point printf version (requires MATH_LIB = -lm below)
-PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
-
-# If this is left blank, then it will use the Standard printf version.
-PRINTF_LIB = 
-#PRINTF_LIB = $(PRINTF_LIB_MIN)
-#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
-
-
-# Minimalistic scanf version
-SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
-
-# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
-SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
-
-# If this is left blank, then it will use the Standard scanf version.
-SCANF_LIB = 
-#SCANF_LIB = $(SCANF_LIB_MIN)
-#SCANF_LIB = $(SCANF_LIB_FLOAT)
-
-
-MATH_LIB = -lm
-
-
-
-#---------------- External Memory Options ----------------
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# used for variables (.data/.bss) and heap (malloc()).
-#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
-
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-# only used for heap (malloc()).
-#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
-
-EXTMEMOPTS =
-
-
-
-#---------------- Linker Options ----------------
-#  -Wl,...:     tell GCC to pass this to linker.
-#    -Map:      create map file
-#    --cref:    add cross reference to  map file
-LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
-LDFLAGS += $(EXTMEMOPTS)
-LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
-
-
-
-#---------------- Programming Options (avrdude) ----------------
-
-# Programming hardware: alf avr910 avrisp bascom bsd 
-# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
-#
-# Type: avrdude -c ?
-# to get a full listing.
-#
-AVRDUDE_PROGRAMMER = avrisp
-
-# com1 = serial port. Use lpt1 to connect to parallel port.
-AVRDUDE_PORT = com1
-# programmer connected to serial device
-
-AVRDUDE_WRITE_FLASH = -b 4800 -U flash:w:$(TARGET).hex
-#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
-
-
-# Uncomment the following if you want avrdude's erase cycle counter.
-# Note that this counter needs to be initialized first using -Yn,
-# see avrdude manual.
-#AVRDUDE_ERASE_COUNTER = -y
-
-# Uncomment the following if you do /not/ wish a verification to be
-# performed after programming the device.
-#AVRDUDE_NO_VERIFY = -V
-
-# Increase verbosity level.  Please use this when submitting bug
-# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
-# to submit bug reports.
-#AVRDUDE_VERBOSE = -v -v
-
-AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
-AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
-AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
-AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
-
-
-
-#---------------- Debugging Options ----------------
-
-# For simulavr only - target MCU frequency.
-DEBUG_MFREQ = $(F_CPU)
-
-# Set the DEBUG_UI to either gdb or insight.
-# DEBUG_UI = gdb
-DEBUG_UI = insight
-
-# Set the debugging back-end to either avarice, simulavr.
-DEBUG_BACKEND = avarice
-#DEBUG_BACKEND = simulavr
-
-# GDB Init Filename.
-GDBINIT_FILE = __avr_gdbinit
-
-# When using avarice settings for the JTAG
-JTAG_DEV = /dev/com1
-
-# Debugging port used to communicate between GDB / avarice / simulavr.
-DEBUG_PORT = 4242
-
-# Debugging host used to communicate between GDB / avarice / simulavr, normally
-#     just set to localhost unless doing some sort of crazy debugging when 
-#     avarice is running on a different computer.
-DEBUG_HOST = localhost
-
-
-
-#============================================================================
-
-
-# Define programs and commands.
-SHELL = sh
-CC = avr-gcc
-OBJCOPY = avr-objcopy
-OBJDUMP = avr-objdump
-SIZE = avr-size
-NM = avr-nm
-AVRDUDE = avrdude
-REMOVE = rm -f
-COPY = cp
-WINSHELL = cmd
-
-
-# Define Messages
-# English
-MSG_ERRORS_NONE = Errors: none
-MSG_BEGIN = -------- begin --------
-MSG_END = --------  end  --------
-MSG_SIZE_BEFORE = Size before: 
-MSG_SIZE_AFTER = Size after:
-MSG_COFF = Converting to AVR COFF:
-MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
-MSG_FLASH = Creating load file for Flash:
-MSG_EEPROM = Creating load file for EEPROM:
-MSG_EXTENDED_LISTING = Creating Extended Listing:
-MSG_SYMBOL_TABLE = Creating Symbol Table:
-MSG_LINKING = Linking:
-MSG_COMPILING = Compiling:
-MSG_ASSEMBLING = Assembling:
-MSG_CLEANING = Cleaning project:
-
-
-
-
-# Define all object files.
-OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
-
-# Define all listing files.
-LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
-
-
-# Compiler flags to generate dependency files.
-GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
-
-
-# Combine all necessary flags and optional flags.
-# Add target processor to flags.
-ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
-
-
-
-
-
-# Default target.
-all: begin gccversion sizebefore build sizeafter end
-
-build: elf hex eep lss sym
-
-elf: $(TARGET).elf
-hex: $(TARGET).hex
-eep: $(TARGET).eep
-lss: $(TARGET).lss 
-sym: $(TARGET).sym
-
-
-
-# Eye candy.
-# AVR Studio 3.x does not check make's exit code but relies on
-# the following magic strings to be generated by the compile job.
-begin:
-	@echo
-	@echo $(MSG_BEGIN)
-
-end:
-	@echo $(MSG_END)
-	@echo
-
-
-# Display size of file.
-HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
-ELFSIZE = $(SIZE) -A $(TARGET).elf
-AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
-
-sizebefore:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-sizeafter:
-	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
-	$(AVRMEM) 2>/dev/null; echo; fi
-
-
-
-# Display compiler version information.
-gccversion : 
-	@$(CC) --version
-
-
-
-# Program the device.  
-program: $(TARGET).hex $(TARGET).eep
-	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
-
-# Generate avr-gdb config/init file which does the following:
-#     define the reset signal, load the target file, connect to target, and set 
-#     a breakpoint at main().
-gdb-config: 
-	@$(REMOVE) $(GDBINIT_FILE)
-	@echo define reset >> $(GDBINIT_FILE)
-	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
-	@echo end >> $(GDBINIT_FILE)
-	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
-	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
-ifeq ($(DEBUG_BACKEND),simulavr)
-	@echo load  >> $(GDBINIT_FILE)
-endif	
-	@echo break main >> $(GDBINIT_FILE)
-	
-debug: gdb-config $(TARGET).elf
-ifeq ($(DEBUG_BACKEND), avarice)
-	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
-	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
-	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
-	@$(WINSHELL) /c pause
-	
-else
-	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
-	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
-endif
-	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
-	
-
-
-
-# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
-COFFCONVERT=$(OBJCOPY) --debugging \
---change-section-address .data-0x800000 \
---change-section-address .bss-0x800000 \
---change-section-address .noinit-0x800000 \
---change-section-address .eeprom-0x810000 
-
-
-coff: $(TARGET).elf
-	@echo
-	@echo $(MSG_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
-
-
-extcoff: $(TARGET).elf
-	@echo
-	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
-	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
-
-
-
-# Create final output files (.hex, .eep) from ELF output file.
-%.hex: %.elf
-	@echo
-	@echo $(MSG_FLASH) $@
-	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
-
-%.eep: %.elf
-	@echo
-	@echo $(MSG_EEPROM) $@
-	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
-	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
-
-# Create extended listing file from ELF output file.
-%.lss: %.elf
-	@echo
-	@echo $(MSG_EXTENDED_LISTING) $@
-	$(OBJDUMP) -h -S $< > $@
-
-# Create a symbol table from ELF output file.
-%.sym: %.elf
-	@echo
-	@echo $(MSG_SYMBOL_TABLE) $@
-	$(NM) -n $< > $@
-
-
-
-# Link: create ELF output file from object files.
-.SECONDARY : $(TARGET).elf
-.PRECIOUS : $(OBJ)
-%.elf: $(OBJ)
-	@echo
-	@echo $(MSG_LINKING) $@
-	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
-
-
-# Compile: create object files from C source files.
-%.o : %.c
-	@echo
-	@echo $(MSG_COMPILING) $<
-	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
-
-
-# Compile: create assembler files from C source files.
-%.s : %.c
-	$(CC) -S $(ALL_CFLAGS) $< -o $@
-
-
-# Assemble: create object files from assembler source files.
-%.o : %.S
-	@echo
-	@echo $(MSG_ASSEMBLING) $<
-	$(CC) -c $(ALL_ASFLAGS) $< -o $@
-
-# Create preprocessed source for use in sending a bug report.
-%.i : %.c
-	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
-
-
-# Target: clean project.
-clean: begin clean_list end
-
-clean_list :
-	@echo
-	@echo $(MSG_CLEANING)
-	$(REMOVE) $(TARGET).hex
-	$(REMOVE) $(TARGET).eep
-	$(REMOVE) $(TARGET).cof
-	$(REMOVE) $(TARGET).elf
-	$(REMOVE) $(TARGET).map
-	$(REMOVE) $(TARGET).sym
-	$(REMOVE) $(TARGET).lss
-	$(REMOVE) $(OBJ)
-	$(REMOVE) $(LST)
-	$(REMOVE) $(SRC:.c=.s)
-	$(REMOVE) $(SRC:.c=.d)
-	$(REMOVE) .dep/*
-
-
-
-# Include the dependency files.
--include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
-
-
-# Listing of phony targets.
-.PHONY : all begin finish end sizebefore sizeafter gccversion \
-build elf hex eep lss sym coff extcoff \
-clean clean_list program debug gdb-config
-
Index: trunk/old/cardreader/main.c
===================================================================
--- trunk/old/cardreader/main.c	(revision 133)
+++ trunk/old/cardreader/main.c	(nonexistent)
@@ -1,702 +0,0 @@
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File          : main.c
-* Compiler      : IAR EWAAVR 2.28a
-* Created       : 18.07.2002 by JLL
-* Modified      : 11-07-2003 by LTA
-*
-* Support mail  : avr@atmel.com
-*
-* AppNote       : AVR307 - Half duplex UART using the USI Interface
-*
-* Description   : Example showing how you could use the USI_UART drivers
-*
-*
-****************************************************************************/
-
-#define CARDBOX
-
-
-#ifndef CARDBOX
-#define TOOLBOX
-#endif
-
-
-#include <avr/io.h>  // Note there is a bug in this file that includes iotiny22.h instead of iotiny26.h
-//#include <iotiny26.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-
-#define GRN     0x10
-#define YEL     0x20
-#define RED     0x40
-
-#ifdef TOOLBOX
-static int ovfcnt0 =0 ;
-static int ovfcnt1 =0 ;
-#endif
-
-void LED(uint8_t color, uint8_t on){
-    if(on)
-      PORTD |= color;
-    else
-      PORTD &= ~(color);
-}
-
-#include "USI_UART_config.h"
-#include "USI_UART.c"
-#define RX      0x01
-#define TX      0x02
-#define TEN     0x02
-#define RELAY   0x08
-
-
-#define BTN0	(1<<PD2)  //row1
-#define BTN1	(1<<PD3)  //row2
-
-#define BTN2    (1<<PB6)  //col1
-#define BTN3    (1<<PB4)  //col2
-#define BTN4    (1<<PB2)  //col3
-#define BTN5    (1<<PB0)  //col4
-
-#define BTN6    (1<<PA1)  //row3
-#define BTN7    (1<<PA0)  //row4
-
-#define ROW1 BTN0 //PORTD
-#define ROW2 BTN1
-#define ROW3 BTN6 //PORTA
-#define ROW4 BTN7
-
-#define COL1 BTN2 //PORTB
-#define COL2 BTN2
-#define COL3 BTN2
-#define COL4 BTN2
-
-
-
-
-#define W_CARD 0
-#define W_CARD_ACK 1
-#define W_BTN 2
-#define W_BTN_ACK 3
-
-#define B_START 0
-#define B_ID	1
-#define B_ACK	2
-
-#define R_START 0
-#define R_ID 1
-#define R_ACK 2
-
-#define T_START 0
-#define T_TIMED 1
-
-#define BOXID   0x01
-#define NUMBUT 	6
-#define READEROFFSET '@'
-#define BOXOFFSET '`'
-#define C_ACK 'a'
-#define C_NCK 'n'
-
-
-void setddr(void)
-{
-	DDRB |= (1<<PB1);
-	DDRD &=~(BTN0);
-	DDRD &=~(BTN1);
-//	PORTB |= (1<<PB1);  //why do we do this?
-	PORTD |=(BTN1)|(BTN0);
-    DDRA = 0;
-    DDRB = TEN | RELAY ;
-    DDRD = TX  | GRN | YEL | RED;
-		//buttons are all inputs for now
-    /*
-#ifdef CARDBOX
-
-	DDRD|=COL2|COL1;
-	DDRA|=COL4|COL3;
-	DDRB&=~(ROW1|ROW2|ROW3|ROW4);
-	PORTB&=~(ROW1|ROW2|ROW3|ROW4);
-
-#endif
-*/
-}
-
-void USART_Init( unsigned int baud )
-{
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-	/* Enable receiver and transmitter */
-	UCSRB = (1<<RXEN)|(1<<TXEN)/*|(1<<RXCIE)*/;
-	/* Set frame format: 8data, 1stop bit */
-	UCSRC = (0<<USBS)|(3<<UCSZ0);
-	PORTB &=~(TEN);
-}
-
-void USART_Transmit( unsigned char data )
-{
-	/* Wait for empty transmit buffer */
-	
-	while ( !( UCSRA & (1<<UDRE)) )
-		;
-	/* Put data into buffer, sends the data */
-	//PORTB |=(TEN);
-	UDR = data;
-}
-
-unsigned char USART_Receive(void)
-{
-	while(!( UCSRA & (1<<RXC)));
-	return UDR;
-}
-
-unsigned char kbhit(void)
-{
-	return (UCSRA & (1<<RXC));
-}
-
-
-#ifdef TOOLBOX
-void reset_timer0(void){
-  int t=TIFR;
-	TCNT0=0;
-  ovfcnt0 =0;
-  ovfcnt1 =0;
-  GTCCR|=(1<<PSR10);
-	TIFR=t|(1<<TOV0);
-}
-
-void init_timer0(void){
-	TCCR0A =0;
-	TCCR0B |= _BV(CS12)|_BV(CS10);  //prescale=64, overflow every ~ .5sec
-	TCCR0B &= ~(_BV(CS11)|_BV(WGM13)|_BV(WGM12));
-	reset_timer0();
-
-}
-
-unsigned char has_timed_out0(void){
-	int e;
-	e= TCNT0;
-	if(e>128){
-	//	PORTD |= YEL;
-   // PORTD &=~GRN;
-    return 1;
-	}else{
-		//PORTD |= GRN;
-    //PORTD &=~YEL;
-    return 0;
-  }
-//	return e;
-	
-}
-unsigned char has_overflowed0(void){
-	int d,e;
-	d= TIFR;//TCNT1;
-	e= (d>>TOV0)&0x1;
-  
-	if(e){
-		//PORTD |= YEL;
-    //PORTD &=~GRN;
-	}else{
-	//	PORTD |= GRN;
-   // PORTD &=~YEL;
-  }
-  if(e){
-    ovfcnt0++;
-    TIFR |=_BV(TOV0);
-    if(ovfcnt0>255){		
-      ovfcnt1++;
-	  ovfcnt0=0;
-    }
-	
-  }
-	return ovfcnt1>2;//SET TIMEOUT SPEED HERE (base unit is ~8 seconds)
-}
-
-#endif
-
-
-void reset_timer(void){
-  int t=TIFR;
-	TCNT1H=0;
-  TCNT1L=0;
-  GTCCR|=(1<<PSR10);
-	TIFR=t|(1<<TOV1);
-	//PORTD |= RED;
-	
-}
-
-void init_timer(void){
-	TCCR1A =0;
-	TCCR1B |= _BV(CS12)|_BV(CS10);  //prescale=64, overflow every ~ .5sec
-	TCCR1B &= ~(_BV(CS11)|_BV(WGM13)|_BV(WGM12));
-	reset_timer();
-
-}
-
-unsigned char has_timed_out(void){
-	int e;
-  //return 0;
-	e= TCNT1;
-	if(e>128){
-	//	PORTD |= YEL;
-   // PORTD &=~GRN;
-    return 1;
-	}else{
-		//PORTD |= GRN;
-    //PORTD &=~YEL;
-    return 0;
-  }
-//	return e;
-	
-}
-
-unsigned char has_overflowed(void){
-	int d,e;
-	d= TIFR;//TCNT1;
-	e= (d>>TOV1)&0x1;
-	if(e){
-		//PORTD |= YEL;
-    //PORTD &=~GRN;
-	}else{
-	//	PORTD |= GRN;
-   // PORTD &=~YEL;
-  }
-	return e;
-}
-
-
-
-uint8_t ispressed(void)
-{
-//#ifdef TOOLBOX
-//	LED(YEL,1);
-//	return 255;
-	if (!(PIND & (BTN0)))
-		return 0;
-	if (!(PIND & (BTN1)))
-		return 1;
-		
-	/*... if (PINx & 0xHH)
-			return #;
-	...*/
-	return 255;
-//#endif
-	
-/*	
-#ifdef CARDBOX
-	
-	PORTD &= ~ROW2;
-	PORTA &= ~(ROW3|ROW4);
-	PORTD |= ROW1;
-	
-	if(PINB&(COL1)){
-		return 0;
-	}
-	if(PINB&(COL2)){
-		return 1;
-	}
-	if(PINB&(COL3)){
-		return 2;
-	}
-	if(PINB&(COL4)){
-		return 3;
-	}
-	
-	PORTD &= ~ROW1;
-	PORTD |= ROW2;
-	
-	if(PINB&(COL1)){
-		return 4;
-	}
-	if(PINB&(COL2)){
-		return 5;
-	}
-	if(PINB&(COL3)){
-		return 6;
-	}
-	if(PINB&(COL4)){
-		return 7;
-	}
-	
-	
-	PORTD &= ~ROW2;
-	PORTA |= ROW3;
-	
-	if(PINB&(COL1)){
-		return 8;
-	}
-	if(PINB&(COL2)){
-		return 9;
-	}
-	if(PINB&(COL3)){
-		return 10;
-	}
-	if(PINB&(COL4)){
-		return 11;
-	}
-	
-	
-	
-	PORTA &= ~(ROW3);
-	PORTA |= ROW4;
-	
-	if(PINB&(COL1)){
-		return 12;
-	}
-	if(PINB&(COL2)){
-		return 13;
-	}
-	if(PINB&(COL3)){
-		return 14;
-	}
-	if(PINB&(COL4)){
-		return 15;
-	}
-	
-	
-	return 255; // fail
-	
-#endif
-*/}
-
-#ifdef CARDBOX
-//unsigned char RxStream[60];
-int cardbox( void )
-{
-//    unsigned char myString[] = "\n\rYou just sent me: ";
-	unsigned char c=0;
-	unsigned int d=0,e=0;
-	uint8_t button;
-	uint8_t waiting = W_CARD;
-	uint8_t state = B_START;
-    
-    unsigned char counter=0;
-//	unsigned char *data;
-    
-	setddr();
-	USART_Init(53);
-  
-//			PORTB |= (TEN);
- // while(1){
-  //  USART_Transmit('c');
-    //            for (d = 0; d < 100; d++)
-      //        for (e = 0; e < 60000; e++); 
- // }
-	init_timer();
-	//DDRD |= (1<<PD6)|(1<<PD5)|(1<<PD4);
-	//PORTD |= (1<<PD6);
-    USI_UART_Initialise_Receiver();                                         // Initialisation for USI_UART receiver
-    sei();                                                   // Enable global interrupts
-    //MCUCR = (1<<SE)|(0<<SM1)|(0<<SM0);                                      // Enable Sleepmode: Idle
-//    USI_UART_Transmit_Byte('w');
-    for( ; ; )                                                              // Run forever
-    {
-        if( USI_UART_Data_In_Receive_Buffer() )
-        {  
-			//PORTD |= (1<<PD6);
-			
-          PORTB |= (TEN);
-          for(d=0;d<40000;d++);
-          USART_Transmit('~');
-          //c=USI_UART_Receive_Bytes();    //UNCOMMENT THIS
-          USART_Transmit(BOXID+'@');
-          USART_Transmit('c');
-          USART_Transmit(RxIndex);
-          for(counter = 0; counter < RxIndex; counter++)                       // Echo myString[]
-                {
-            //for(d=0;d<40000;d++);
-                    USART_Transmit((RxStream[counter] +0x30));   
-    
-                }
-          USART_Transmit(0xAB);
-          for(d=0;d<60000;d++);
-    //			for(d=0;d<60000;d++);
-          //PORTD &=~(1<<PD6);
-          //PORTD &=~(1<<PD5);
-          PORTB &=~(TEN);		//////////////////uncomment for 485
-          
-    //			c=USI_UART_Receive_Byte();
-    //			if(c=='c'){
-    //				PORTD |=(1<<PD5);
-     //           }
-               // USI_UART_Transmit_Byte(c+1 );              // Echo the received character      
-           waiting=W_CARD_ACK;
-           reset_timer();
-           
-          LED(YEL,1);
-          c=USI_UART_Receive_Bytes();
-        }    
-
-    if (waiting == W_CARD)
-		{
-			LED(RED, 0);
-			LED(YEL, 0);
-			LED(GRN, 0);
-//      reset_timer();
-//      has_timed_out();
-		}else if ((waiting==W_BTN))
-    {
-      if (((button = ispressed()) != 255))
-      {
-        //LED(RED,1);
-        
-        PORTB |= (TEN);
-        for(d=0;d<40000;d++);
-        
-        button += ('0'); // watch out for overflow
-        USART_Transmit('~');
-        //c=USI_UART_Receive_Bytes();
-        USART_Transmit(BOXID+READEROFFSET);
-        USART_Transmit('t');
-        USART_Transmit(button);
-        USART_Transmit(0xAB);
-  //			USART_Transmit(0xAB);
-        for(d=0;d<60000;d++);
-        for(d=0;d<60000;d++);
-        PORTB &=~(TEN);		
-        waiting=W_BTN_ACK;
-        reset_timer();
-      }
-      if(has_overflowed())
-      {
-//        PORTD |=RED;
-        LED(RED, 1);
-        for (d = 0; d < 100; d++)
-            for (e = 0; e < 60000; e++); 
-        LED(RED, 0);
-
-				state=B_START;
-				waiting=W_CARD;
-				USI_UART_Initialise_Receiver();
-      }
-    }
-		else
-		{
-    	LED(RED, 0);
-			LED(YEL, 1);
-			LED(GRN, 0);
-			if (kbhit())
-			{
-				reset_timer();
-				//LED(RED,1);
-				c = UDR;
-				if (state == B_START) 
-				{
-			//		LED(GRN,0);
-					if (c == READEROFFSET)
-						state = B_ID;
-					else
-						state = B_START;
-				}
-				else if (state == B_ID)
-				{
-//					LED(RED,1);
-					if (c == BOXID + READEROFFSET)
-						state = B_ACK;
-					else{
-						//LED(YEL,0);
-						state = B_START;
-					}
-				}
-				else if (state == B_ACK)
-				{
- 					//LED(RED,1);
-					if (c == C_ACK)
-					{
-						if (waiting == W_CARD_ACK)
-						{
-							LED(GRN, 1);
-							for (d = 0; d < 100; d++)
-								for (e = 0; e < 60000; e++);
-							LED(GRN, 0);
-							waiting = W_BTN; // indicate that we are now waiting for button?
-              reset_timer();
-						}
-						else if (waiting == W_BTN_ACK)
-						{
-							LED(YEL, 0);
-              LED(RED, 0);
-							LED(GRN, 1);
-							for (d = 0; d < 100; d++)
-								for (e = 0; e < 60000; e++); 
-							LED(GRN, 0);
-							waiting=W_CARD;
-							//send some relay clicking action
-							USI_UART_Initialise_Receiver();
-						}
-					}
-					else 
-					{
-						if (c == C_NCK)
-						{
-							LED(GRN, 0);
-							LED(YEL, 0);
-							LED(RED, 1);
-							for (d = 0; d < 100; d++)
-								for (e = 0; e < 60000; e++); 
-							LED(RED, 0);
-						}
-						waiting = W_CARD;
-						USI_UART_Initialise_Receiver();
-					}
-					state = B_START;
-				}
-			}else if(has_timed_out()&&waiting!=W_BTN){
-      
-        LED(RED, 1);
-        //LED(YEL, 0);
-        for (d = 0; d < 100; d++)
-          for (e = 0; e < 60000; e++); 
-        LED(RED, 0);
-        
-				state=B_START;
-				waiting=W_CARD;
-				USI_UART_Initialise_Receiver();
-			
-			}
-		}
-		
-		// we don't ever sleep, this is CMU.
-        //_delay_ms(1);                                                          // Sleep when waiting for next event
-	}    
-}
-
-#endif
-
-
-#ifdef TOOLBOX
-int toolbox(void){
-  char c,button;
-	setddr();
-  PORTD|=BTN1|BTN0;
-  unsigned int state=R_START,d,e,tool=T_START;
-	USART_Init(51);
-	init_timer0();
-	init_timer();
-  
-  
-      LED(GRN,1);
-      PORTD|=GRN;
-      
-		//	PORTB |= (TEN);
-		//	for(d=0;d<40000;d++);
-		//	USART_Transmit('~');
-		//	USART_Transmit(0xAB);
-			for(d=0;d<60000;d++);
-//			for(d=0;d<60000;d++);
-			//PORTD &=~(1<<PD6);
-			//PORTD &=~(1<<PD5);
-			PORTB &=~(TEN);		//////////////////uncomment for 485
-			PORTD &=~GRN;
-      LED(GRN,0);
-  while(1){
-
-    if(kbhit()){
-
-      reset_timer();
-      c=UDR;
-      if (state == R_START) 
-      {
-        if (c == BOXOFFSET){
-          state = R_ID;
-          LED(YEL,1);
-        }
-        else
-          state = R_START;
-        
-        
-        
-      }
-      else if (state == R_ID)
-      {
-        if (c == BOXID + BOXOFFSET){
-          state = R_ACK;
-        }else{
-          state = R_START;
-          
-          LED(YEL,0);
-        }
-      }
-      else if (state == R_ACK)
-      {
-      
-        LED(YEL, 0);
-        if (c == C_ACK)
-        {
-          LED(GRN, 1);
-          LED(RED, 0);
-          PORTB|=RELAY;
-		  	reset_timer0();
-			tool=T_TIMED;
-        }
-        else 
-        {
-        
-          if (c == C_NCK)
-          {
-          
-            PORTB&=~RELAY;
-            LED(GRN, 0);
-            LED(RED, 1);
-            for (d = 0; d < 100; d++)
-              for (e = 0; e < 60000; e++); 
-            LED(RED, 0);
-          }
-          
-          state = R_START;
-        }
-      }
-    }else if(state!=R_START && has_timed_out()){
-      LED(YEL, 1);
-      LED(RED, 1);
-      for (d = 0; d < 100; d++)
-        for (e = 0; e < 60000; e++); 
-      LED(RED, 0);
-      LED(YEL,0);
-      state = R_START;
-    }
-
-	if (((button = ispressed()) == 0)&&tool==T_TIMED)
-    {
-	    LED(YEL, 1);
-		for (d = 0; d < 100; d++)
-			for (e = 0; e < 60000; e++); 
-		LED(YEL, 0);
-		reset_timer0();
-	}
-    if(tool==T_TIMED&&(has_overflowed0()||((button = ispressed()) == 1))){
-	//    LED(YEL, 1);
-      LED(RED, 1);
-      for (d = 0; d < 100; d++)
-        for (e = 0; e < 60000; e++); 
-      LED(RED, 0);
-      LED(GRN,0);
-       PORTB&=~RELAY;
-	   state=R_START;
-	   reset_timer0();
-	   tool=T_START;
-    }
-    
-  }
-
-
-
-
-}
-#endif
-
-int main(void){
-#ifdef CARDBOX
-  cardbox();
-#endif
-
-#ifdef TOOLBOX
-  toolbox();
-#endif
-
-}
-
Index: trunk/old/cardreader/main_aaron.c
===================================================================
--- trunk/old/cardreader/main_aaron.c	(revision 133)
+++ trunk/old/cardreader/main_aaron.c	(nonexistent)
@@ -1,139 +0,0 @@
-//CARD READER
-
-/*****************************************************************************
-*
-* Copyright (C) 2003 Atmel Corporation
-*
-* File          : main.c
-* Compiler      : IAR EWAAVR 2.28a
-* Created       : 18.07.2002 by JLL
-* Modified      : 11-07-2003 by LTA
-*
-* Support mail  : avr@atmel.com
-*
-* AppNote       : AVR307 - Half duplex UART using the USI Interface
-*
-* Description   : Example showing how you could use the USI_UART drivers
-*
-*
-****************************************************************************/
-
-#include <avr/io.h>  // Note there is a bug in this file that includes iotiny22.h instead of iotiny26.h
-//#include <iotiny26.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include "USI_UART_config.h"
-#include "USI_UART.c"
-#define RX      0x01
-#define TX      0x02
-#define TEN     0x02
-#define GRN     0x10
-#define YEL     0x20
-#define RED     0x40
-#define BOXID   0x01
-
-void setddr(void)
-{
-	DDRB |= (1<<PB1);
-	PORTB |= (1<<PB1);
-        DDRA = 0;
-        DDRB = TEN ;
-        DDRD = TX  | GRN | YEL | RED;
-		
-		//buttons are all inputs for now
-}
-void USART_Init( unsigned int baud )
-{
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-	/* Enable receiver and transmitter */
-	UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE);
-	/* Set frame format: 8data, 1stop bit */
-	UCSRC = (0<<USBS)|(3<<UCSZ0);
-	PORTB &=~(TEN);
-}
-
-void USART_Transmit( unsigned char data )
-{
-	/* Wait for empty transmit buffer */
-	
-	while ( !( UCSRA & (1<<UDRE)) )
-		;
-	/* Put data into buffer, sends the data */
-	//PORTB |=(TEN);
-	UDR = data;
-}
-
-unsigned char USART_Receive(void)
-{
-	while(!( UCSRA & (1<<RXC)));
-	return UDR;
-}
-
-
-
-ISR(USART_RX_vect)
-{
-	PORTD |=(1<<PD6);
-	if(UDR=='a'){
-		PORTD |=(1<<PD5);
-	}
-//	USI_UART_Transmit_Byte(UDR);
-}
-
-
-//unsigned char RxStream[60];
-int main( void )
-{
-//    unsigned char myString[] = "\n\rYou just sent me: ";
-	unsigned char c=0;
-	unsigned int d=0;
-    
-    unsigned char counter=0;
-	unsigned char *data;
-    
-	setddr();
-	USART_Init(51);
-	//DDRD |= (1<<PD6)|(1<<PD5)|(1<<PD4);
-	//PORTD |= (1<<PD6);
-	
-    USI_UART_Initialise_Receiver();                                         // Initialisation for USI_UART receiver
-    sei();                                                   // Enable global interrupts
-    //MCUCR = (1<<SE)|(0<<SM1)|(0<<SM0);                                      // Enable Sleepmode: Idle
-//    USI_UART_Transmit_Byte('w');
-    for( ; ; )                                                              // Run forever
-    {
-        if( USI_UART_Data_In_Receive_Buffer() )
-        {  
-			PORTD |= (1<<PD6);
-			
-			PORTB |= (TEN);
-			for(d=0;d<40000;d++);
-			USART_Transmit('~');
-			c=USI_UART_Receive_Bytes();
-			USART_Transmit(BOXID+'@');
-			USART_Transmit('c');
-			USART_Transmit(RxIndex);
-			for(counter = 0; counter < RxIndex; counter++)                       // Echo myString[]
-            {
-				//for(d=0;d<40000;d++);
-                USART_Transmit((RxStream[counter] +0x30));   
-
-            }
-			USART_Transmit(0xAB);
-			for(d=0;d<60000;d++);
-//			for(d=0;d<60000;d++);
-			PORTD &=~(1<<PD6);
-			PORTD &=~(1<<PD5);
-			PORTB &=~(TEN);
-			USI_UART_Initialise_Receiver();
-//			c=USI_UART_Receive_Byte();
-//			if(c=='c'){
-//				PORTD |=(1<<PD5);
- //           }
-           // USI_UART_Transmit_Byte(c+1 );              // Echo the received character      
-        }    
-        _delay_ms(1);                                                          // Sleep when waiting for next event
-	}    
-}
Index: trunk/old/cardreader/main_jimbo.c
===================================================================
--- trunk/old/cardreader/main_jimbo.c	(revision 133)
+++ trunk/old/cardreader/main_jimbo.c	(nonexistent)
@@ -1,747 +0,0 @@
-/*****************************************************************************
-*
-*Aaron's code is unreadable
-*
-*Kevin Woo and James Kong are making it better
-*
-****************************************************************************/
-
-#define CARDBOX
-
-
-#ifndef CARDBOX
-#define TOOLBOX
-#endif
-
-
-#include <avr/io.h>  // Note there is a bug in this file that includes iotiny22.h instead of iotiny26.h
-//#include <iotiny26.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-
-#define GREEN     0x10
-#define YELLOW    0x20
-#define RED       0x40
-
-#ifdef TOOLBOX
-static int ovfcnt0 =0 ;
-static int ovfcnt1 =0 ;
-#endif
-
-void LED(uint8_t color, uint8_t on){
-    if(on)
-      PORTD |= color;
-    else
-      PORTD &= ~(color);
-}
-
-#include "USI_UART_config.h"
-#include "USI_UART.c"
-#define RX      0x01
-#define TX      0x02
-#define TX_EN     0x02
-#define RELAY   0x08
-
-
-#define BTN0	(1<<PD2)  //row1
-#define BTN1	(1<<PD3)  //row2
-
-#define BTN2    (1<<PB6)  //col1
-#define BTN3    (1<<PB4)  //col2
-#define BTN4    (1<<PB2)  //col3
-#define BTN5    (1<<PB0)  //col4
-
-#define BTN6    (1<<PA1)  //row3
-#define BTN7    (1<<PA0)  //row4
-
-#define ROW1 BTN0 //PORTD
-#define ROW2 BTN1
-#define ROW3 BTN6 //PORTA
-#define ROW4 BTN7
-
-#define COL1 BTN2 //PORTB
-#define COL2 BTN2
-#define COL3 BTN2
-#define COL4 BTN2
-
-
-
-#define W_CARD 0
-#define W_CARD_ACK 1
-#define W_BTN 2
-#define W_BTN_ACK 3
-
-#define B_START 0
-#define B_ID	1
-#define B_ACK	2
-
-#define R_START 0
-#define R_ID 1
-#define R_ACK 2
-
-#define T_START 0
-#define T_TIMED 1
-
-#define NOT_PRESSED 255
-
-#define BOXID   0x01
-#define NUMBUT 	6
-#define READEROFFSET '@'
-#define BOXOFFSET '`'
-#define C_ACK 'a'
-#define C_NCK 'n'
-
-#define DELAY(t) for(i = 0; i < (t); i++)
-
-
-void setddr(void)
-{
-	DDRB |= (1<<PB1);
-	DDRD &=~(BTN0);
-	DDRD &=~(BTN1);
-//	PORTB |= (1<<PB1);  //why do we do this?
-	PORTD |=(BTN1)|(BTN0);
-    DDRA = 0;
-    DDRB = TX_EN | RELAY ;
-    DDRD = TX  | GRN | YEL | RED;
-		//buttons are all inputs for now
-    /*
-#ifdef CARDBOX
-
-	DDRD|=COL2|COL1;
-	DDRA|=COL4|COL3;
-	DDRB&=~(ROW1|ROW2|ROW3|ROW4);
-	PORTB&=~(ROW1|ROW2|ROW3|ROW4);
-
-#endif
-*/
-}
-
-void USART_Init( unsigned int baud )
-{
-	/* Set baud rate */
-	UBRRH = (unsigned char)(baud>>8);
-	UBRRL = (unsigned char)baud;
-	/* Enable receiver and transmitter */
-	UCSRB = (1<<RXEN)|(1<<TXEN)/*|(1<<RXCIE)*/;
-	/* Set frame format: 8data, 1stop bit */
-	UCSRC = (0<<USBS)|(3<<UCSZ0);
-	PORTB &=~(TX_EN);
-}
-
-void USART_Transmit( unsigned char data )
-{
-	/* Wait for empty transmit buffer */
-	
-	while ( !( UCSRA & (1<<UDRE)) )
-		;
-	/* Put data into buffer, sends the data */
-	//PORTB |=(TX_EN);
-	UDR = data;
-}
-
-
-
-unsigned char USART_Byte_Received(void)
-{
-	return (UCSRA & (1<<RXC));
-}
-
-
-#ifdef TOOLBOX
-void reset_timer0(void){
-  int t=TIFR;
-	TCNT0=0;
-  ovfcnt0 =0;
-  ovfcnt1 =0;
-  GTCCR|=(1<<PSR10);
-	TIFR=t|(1<<TOV0);
-}
-
-void init_timer0(void){
-	TCCR0A =0;
-	TCCR0B |= _BV(CS12)|_BV(CS10);  //prescale=64, overflow every ~ .5sec
-	TCCR0B &= ~(_BV(CS11)|_BV(WGM13)|_BV(WGM12));
-	reset_timer0();
-
-}
-
-unsigned char has_timed_out0(void){
-	int e;
-	e= TCNT0;
-	if(e>128){
-	//	PORTD |= YEL;
-   // PORTD &=~GRN;
-    return 1;
-	}else{
-		//PORTD |= GRN;
-    //PORTD &=~YEL;
-    return 0;
-  }
-//	return e;
-	
-}
-unsigned char has_overflowed0(void){
-	int d,e;
-	d= TIFR;//TCNT1;
-	e= (d>>TOV0)&0x1;
-  
-	if(e){
-		//PORTD |= YEL;
-    //PORTD &=~GRN;
-	}else{
-	//	PORTD |= GRN;
-   // PORTD &=~YEL;
-  }
-  if(e){
-    ovfcnt0++;
-    TIFR |=_BV(TOV0);
-    if(ovfcnt0>255){		
-      ovfcnt1++;
-	  ovfcnt0=0;
-    }
-	
-  }
-	return ovfcnt1>2;//SET TIMEOUT SPEED HERE (base unit is ~8 seconds)
-}
-
-#endif
-
-
-void reset_timer(void){
-  int t=TIFR;
-	TCNT1H=0;
-  TCNT1L=0;
-  GTCCR|=(1<<PSR10);
-	TIFR=t|(1<<TOV1);
-	//PORTD |= RED;
-	
-}
-
-void init_timer(void){
-	TCCR1A =0;
-	TCCR1B |= _BV(CS12)|_BV(CS10);  //prescale=64, overflow every ~ .5sec
-	TCCR1B &= ~(_BV(CS11)|_BV(WGM13)|_BV(WGM12));
-	reset_timer();
-
-}
-
-unsigned char has_timed_out(void){
-	int e;
-  //return 0;
-	e= TCNT1;
-	if(e>128){
-	//	PORTD |= YEL;
-   // PORTD &=~GRN;
-    return 1;
-	}else{
-		//PORTD |= GRN;
-    //PORTD &=~YEL;
-    return 0;
-  }
-//	return e;
-	
-}
-
-unsigned char has_overflowed(void){
-	int d,e;
-	d= TIFR;//TCNT1;
-	e= (d>>TOV1)&0x1;
-	if(e){
-		//PORTD |= YEL;
-    //PORTD &=~GRN;
-	}else{
-	//	PORTD |= GRN;
-   // PORTD &=~YEL;
-  }
-	return e;
-}
-
-
-
-uint8_t get_button(void)
-{
-	if (!(PIND & (BTN0)))
-		return 0;
-	if (!(PIND & (BTN1)))
-		return 1;
-
-	return 255;
-
-/*	
-#ifdef CARDBOX
-	
-	PORTD &= ~ROW2;
-	PORTA &= ~(ROW3|ROW4);
-	PORTD |= ROW1;
-	
-	if(PINB&(COL1)){
-		return 0;
-	}
-	if(PINB&(COL2)){
-		return 1;
-	}
-	if(PINB&(COL3)){
-		return 2;
-	}
-	if(PINB&(COL4)){
-		return 3;
-	}
-	
-	PORTD &= ~ROW1;
-	PORTD |= ROW2;
-	
-	if(PINB&(COL1)){
-		return 4;
-	}
-	if(PINB&(COL2)){
-		return 5;
-	}
-	if(PINB&(COL3)){
-		return 6;
-	}
-	if(PINB&(COL4)){
-		return 7;
-	}
-	
-	
-	PORTD &= ~ROW2;
-	PORTA |= ROW3;
-	
-	if(PINB&(COL1)){
-		return 8;
-	}
-	if(PINB&(COL2)){
-		return 9;
-	}
-	if(PINB&(COL3)){
-		return 10;
-	}
-	if(PINB&(COL4)){
-		return 11;
-	}
-	
-	
-	
-	PORTA &= ~(ROW3);
-	PORTA |= ROW4;
-	
-	if(PINB&(COL1)){
-		return 12;
-	}
-	if(PINB&(COL2)){
-		return 13;
-	}
-	if(PINB&(COL3)){
-		return 14;
-	}
-	if(PINB&(COL4)){
-		return 15;
-	}
-	
-	
-	return 255; // fail
-	
-#endif
-*/
-}
-
-#ifdef CARDBOX
-int cardbox( void )
-{
-	unsigned char serv_in=0;
-	unsigned int i=0, j=0;
-	uint8_t button;
-	uint8_t waiting = W_CARD;
-	uint8_t state = B_START;
-    
-  unsigned char counter=0;
-    
-	setddr();
-	USART_Init(53);
-
-	init_timer();
-
-  USI_UART_Initialise_Receiver();                          // Initialisation for USI_UART receiver
-  sei();                                                   // Enable global interrupts
-  
-  while(1)                                                // Run forever
-  {
-    switch(state) {
-      /* Waiting for a card swipe */
-      case AWAITING_CARD_IN:
-        /* Data Received from Card Reader */
-        if( USI_UART_Data_In_Receive_Buffer() ) {     //If someone has swiped a card
-          PORTB |= (TX_EN);
-          DELAY(40000);
-          
-          //Header bits
-          USART_Transmit('~');
-          USART_Transmit(BOXID+'@');
-          USART_Transmit('c');
-          
-          //Card data
-          USART_Transmit(RxIndex);
-          for(counter = 0; counter < RxIndex; counter++) {
-            USART_Transmit((RxStream[counter] +0x30));
-          }
-          
-          //Tail bits
-          USART_Transmit(0xAB);
-          DELAY(60000);
-          
-          PORTB &=~(TX_EN);                         //Give up transmit line
-          
-          reset_timer(); 
-          LED(YELLOW,1);                               //Indicate that we are now waiting for a card
-          
-          state = AWAITING_SERV_CARD_RESP;
-        }
-          
-        break;
-      
-      case AWAITING_SERV_CARD_RESP:
-        if (USART_Byte_Received()) {
-          serv_in = USI_UART_Receive_Bytes();
-          
-          //Card recognized
-          if (serv_in == CARD_ACK) {
-
-            LED(GREEN, 1);
-            LED(YELLOW, 1);
-            DELAY(100) {DELAY(60000);} //Actually a 6000000 delay, ~.15secs
-            LED(GREEN, 0);
-            
-            state = AWAITING_BUTTON_PRESS;
-          }
-          
-          //Card not recognized
-          if (serv_in != CARD_ACK) {
-          
-            LED(RED, 1);
-            LED(YELLOW, 0);
-            DELAY(1000) {DELAY(60000);} //Long delay ~1.5secs
-            LED(RED, 0);
-          
-            state = AWAITING_CARD_IN;
-          }
-          
-          reset_timer();
-        }
-        else {
-          if(has_timed_out()) {
-          
-            LED(RED, 1);
-            LED(YELLOW, 0);
-            DELAY(1000) {DELAY(60000);} //Long delay ~1.5secs
-            LED(RED, 0);
-          
-            state = AWAITING_CARD_IN;
-            reset_timer();
-          }
-        }
-        
-        break;
-        
-    case AWAITING_BUTTON_PRESS:
-              //button is pressed (note the double negative)
-              if (((button = get_button()) != NOT_PRESSED)) {
-                //LED(RED,1);
-                
-                PORTB |= (TX_EN);  //enable transmit
-                DELAY(40000);
-                
-                
-/***************************** CONTINUE EDITING THE CODE HERE *****************************/
-                
-                button += ('0'); // watch out for overflow
-                USART_Transmit('~');
-                //serv_in=USI_UART_Receive_Bytes();
-                USART_Transmit(BOXID+READEROFFSET);
-                USART_Transmit('t');
-                USART_Transmit(button);
-                USART_Transmit(0xAB);
-          //			USART_Transmit(0xAB);
-                for(d=0;d<60000;d++);
-                for(d=0;d<60000;d++);
-                PORTB &=~(TX_EN);		
-                waiting=W_BTN_ACK;
-                reset_timer();
-              }
-              if(has_overflowed())
-              {
-        //        PORTD |=RED;
-                LED(RED, 1);
-                for (d = 0; d < 100; d++)
-                    for (e = 0; e < 60000; e++); 
-                LED(RED, 0);
-        
-                state=B_START;
-                waiting=W_CARD;
-                USI_UART_Initialise_Receiver();
-              }
-          
-          
-          
-          
-          
-          
-          
-          
-          } else if 
-              
-            if (waiting == W_CARD) {
-              LED(RED, 0);
-              LED(YEL, 0);
-              LED(GRN, 0);
-            }
-            else if ((waiting==W_BTN)) {
-              if (((button = get_button()) != 255)) {
-                //LED(RED,1);
-                
-                PORTB |= (TX_EN);
-                for(d=0;d<40000;d++);
-                
-                button += ('0'); // watch out for overflow
-                USART_Transmit('~');
-                //serv_in=USI_UART_Receive_Bytes();
-                USART_Transmit(BOXID+READEROFFSET);
-                USART_Transmit('t');
-                USART_Transmit(button);
-                USART_Transmit(0xAB);
-          //			USART_Transmit(0xAB);
-                for(d=0;d<60000;d++);
-                for(d=0;d<60000;d++);
-                PORTB &=~(TX_EN);		
-                waiting=W_BTN_ACK;
-                reset_timer();
-              }
-              if(has_overflowed())
-              {
-        //        PORTD |=RED;
-                LED(RED, 1);
-                for (d = 0; d < 100; d++)
-                    for (e = 0; e < 60000; e++); 
-                LED(RED, 0);
-        
-                state=B_START;
-                waiting=W_CARD;
-                USI_UART_Initialise_Receiver();
-              }
-            }
-            else
-            {
-              LED(RED, 0);
-              LED(YEL, 1);
-              LED(GRN, 0);
-              if (kbhit())
-              {
-                reset_timer();
-                //LED(RED,1);
-                serv_in = UDR;
-                if (state == B_START) 
-                {
-              //		LED(GRN,0);
-                  if (serv_in == READEROFFSET)
-                    state = B_ID;
-                  else
-                    state = B_START;
-                }
-                else if (state == B_ID)
-                {
-        //					LED(RED,1);
-                  if (serv_in == BOXID + READEROFFSET)
-                    state = B_ACK;
-                  else{
-                    //LED(YEL,0);
-                    state = B_START;
-                  }
-                }
-                else if (state == B_ACK)
-                {
-                  //LED(RED,1);
-                  if (serv_in == C_ACK)
-                  {
-                    if (waiting == W_CARD_ACK)
-                    {
-                      LED(GRN, 1);
-                      for (d = 0; d < 100; d++)
-                        for (e = 0; e < 60000; e++);
-                      LED(GRN, 0);
-                      waiting = W_BTN; // indicate that we are now waiting for button?
-                      reset_timer();
-                    }
-                    else if (waiting == W_BTN_ACK)
-                    {
-                      LED(YEL, 0);
-                      LED(RED, 0);
-                      LED(GRN, 1);
-                      for (d = 0; d < 100; d++)
-                        for (e = 0; e < 60000; e++); 
-                      LED(GRN, 0);
-                      waiting=W_CARD;
-                      //send some relay clicking action
-                      USI_UART_Initialise_Receiver();
-                    }
-                  }
-                  else 
-                  {
-                    if (serv_in == C_NCK)
-                    {
-                      LED(GRN, 0);
-                      LED(YEL, 0);
-                      LED(RED, 1);
-                      for (d = 0; d < 100; d++)
-                        for (e = 0; e < 60000; e++); 
-                      LED(RED, 0);
-                    }
-                    waiting = W_CARD;
-                    USI_UART_Initialise_Receiver();
-                  }
-                  state = B_START;
-                }
-              }else if(has_timed_out()&&waiting!=W_BTN){
-              
-                LED(RED, 1);
-                //LED(YEL, 0);
-                for (d = 0; d < 100; d++)
-                  for (e = 0; e < 60000; e++); 
-                LED(RED, 0);
-                
-                state=B_START;
-                waiting=W_CARD;
-                USI_UART_Initialise_Receiver();
-              
-              }
-            }
-	}    
-}
-
-#endif
-
-
-#ifdef TOOLBOX
-int toolbox(void){
-  char serv_in,button;
-	setddr();
-  PORTD|=BTN1|BTN0;
-  unsigned int state=R_START,d,e,tool=T_START;
-	USART_Init(51);
-	init_timer0();
-	init_timer();
-  
-  
-      LED(GRN,1);
-      PORTD|=GRN;
-      
-			for(d=0;d<60000;d++);
-			PORTB &=~(TX_EN);
-			PORTD &=~GRN;
-      LED(GRN,0);
-  while(1){
-
-    if(kbhit()){
-
-      reset_timer();
-      serv_in=UDR;
-      if (state == R_START) 
-      {
-        if (serv_in == BOXOFFSET){
-          state = R_ID;
-          LED(YEL,1);
-        }
-        else
-          state = R_START;
-        
-        
-        
-      }
-      else if (state == R_ID)
-      {
-        if (serv_in == BOXID + BOXOFFSET){
-          state = R_ACK;
-        }else{
-          state = R_START;
-          
-          LED(YEL,0);
-        }
-      }
-      else if (state == R_ACK)
-      {
-      
-        LED(YEL, 0);
-        if (serv_in == C_ACK)
-        {
-          LED(GRN, 1);
-          LED(RED, 0);
-          PORTB|=RELAY;
-		  	reset_timer0();
-			tool=T_TIMED;
-        }
-        else 
-        {
-        
-          if (serv_in == C_NCK)
-          {
-          
-            PORTB&=~RELAY;
-            LED(GRN, 0);
-            LED(RED, 1);
-            for (d = 0; d < 100; d++)
-              for (e = 0; e < 60000; e++); 
-            LED(RED, 0);
-          }
-          
-          state = R_START;
-        }
-      }
-    }else if(state!=R_START && has_timed_out()){
-      LED(YEL, 1);
-      LED(RED, 1);
-      for (d = 0; d < 100; d++)
-        for (e = 0; e < 60000; e++); 
-      LED(RED, 0);
-      LED(YEL,0);
-      state = R_START;
-    }
-
-	if (((button = get_button()) == 0)&&tool==T_TIMED)
-    {
-	    LED(YEL, 1);
-		for (d = 0; d < 100; d++)
-			for (e = 0; e < 60000; e++); 
-		LED(YEL, 0);
-		reset_timer0();
-	}
-    if(tool==T_TIMED&&(has_overflowed0()||((button = get_button()) == 1))){
-	//    LED(YEL, 1);
-      LED(RED, 1);
-      for (d = 0; d < 100; d++)
-        for (e = 0; e < 60000; e++); 
-      LED(RED, 0);
-      LED(GRN,0);
-       PORTB&=~RELAY;
-	   state=R_START;
-	   reset_timer0();
-	   tool=T_START;
-    }
-    
-  }
-
-
-
-
-}
-#endif
-
-int main(void){
-#ifdef CARDBOX
-  cardbox();
-#endif
-
-#ifdef TOOLBOX
-  toolbox();
-#endif
-
-}
-
Index: trunk/old/server/serial.h
===================================================================
--- trunk/old/server/serial.h	(revision 133)
+++ trunk/old/server/serial.h	(nonexistent)
@@ -1,9 +0,0 @@
-#ifndef __SERIAL_H
-
-int openport(char *portname);
-int putbyte (int fd, char c);
-unsigned char getbyte (int fd);
-void clearbuf(int fd);
-
-#define __SERIAL_H
-#endif
Index: trunk/old/server/compile
===================================================================
--- trunk/old/server/compile	(revision 133)
+++ trunk/old/server/compile	(nonexistent)
@@ -1 +0,0 @@
-gcc -o cardserv cardserv.c serial.c -lmembersql -lmd5hash

Property changes on: trunk/old/server/compile
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: trunk/old/server/cardserv.c
===================================================================
--- trunk/old/server/cardserv.c	(revision 133)
+++ trunk/old/server/cardserv.c	(nonexistent)
@@ -1,203 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <time.h>
-#include "serial.h"
-#include <rc/membersql.h>
-// #include <openssl/md5.h>
-//#include <xcrypt.h>
-#include <rc/md5hash.h>
-
-#define TXTBUFSIZ 80
-#define READEROFFSET '@'
-#define BOXOFFSET '`'
-
-
-int fdi;
-
-/*void HashID(char *id, char *hashbuf){
-	int i;
-//	char hashbuf[33];
-	char idbuf[50];
-	char binbuf[16];
-	strcpy(idbuf,id);
-	idbuf[9] = 0x0a;
-	md5_buffer(idbuf,10,binbuf);
-	for(i=0;i<16;i++){
-		sprintf(hashbuf+(2*i),"%.2hhx",binbuf[i]);
-	}
-}
-*/
-void INThandler(int sig)
-{
-  signal(sig, SIG_IGN); /* disallow recursive calls to ^C */
-  fprintf(stderr, "Received ^C, stopping mysql...\n");
-  stopMysql();
-  fprintf(stderr, "             closing /dev/ttyS15...\n");
-  close(fdi);
-  fprintf(stderr, "Goodbye.\n");
-  printf("Received SIG_INT; shutting down.\n");
-  exit(EXIT_SUCCESS);
-}
-
-void Sleep(int s)
-{
-  usleep(s*1000);
-}
-
-char* curasctime(char* curtime)
-{
-	time_t rawtime;
-	struct tm *timeinfo;
-
-	time(&rawtime);
-	timeinfo = localtime(&rawtime);
-	curtime = asctime(timeinfo);
-	curtime[24] = 0;
-
-	return curtime;
-}
-
-#define C_INVALID 0
-#define C_CARDRCV 'c'
-#define C_TOOLRCV 't'
-#define C_ACK 'a'
-#define C_NCK 'n'
-#define NUMCARD 10  // number of readers
-#define CARDLEN 40  // max number of accepted characters (minus one)
-
-main()
-{
-  int i, fd;
-  FILE *fdlog;
-  char hashed[33];
-  char name[80], group[80], curtime[26];
-  unsigned char dev;
-  ssize_t readerr;
-  char xtype;
-  int msglen, reader;
-  char readerstate[NUMCARD][CARDLEN];
-
-  fdlog = fopen("/var/log/toold","a");
-  printf("y");fflush(stdout);
-
-  for (i = 0; i < NUMCARD; i++) // clear reader states
-    readerstate[i][0] = 0;
-  printf("z");fflush(stdout);
-
-  fprintf(fdlog,"%s: Starting toold...\n", curasctime(curtime));
-  fflush(stdout);
-  fprintf(stderr, "Opening /dev/ttyS15...\n");
-  fflush(stdout);
-  fd = openport("/dev/tool");
-  printf("x");fflush(stdout);
-  fdi = fd;
-
-  fprintf(stderr, "Starting mysql...\n");
-  if (!startMysql())
-  {
-    printMysqlError();
-    exit(EXIT_FAILURE);
-  }
-  
-  signal(SIGINT, INThandler);
-
-  while(1)
-  {
-    fflush(fdlog);
-    fprintf(stderr, "waiting for transmission\n");
-    while(getbyte(fd) != '~'){}
-//      Sleep(1);
-    reader = getbyteblock(fd) - READEROFFSET;
-    printf("Got stuff from %d\n",reader);
-    if (reader < 0)
-    {
-      fprintf(stderr, "Error: Reader < 0!\n");
-      continue;
-    }
-    xtype = getbyteblock(fd);
-    fprintf(stderr, "incoming transmission type %c from %d\n", xtype, reader);
-    switch (xtype)
-    {
-      case C_CARDRCV:
-        msglen = getbyteblock(fd);
-        for (i = 0; i < msglen; i++)
-          readerstate[reader][i] = getbyteblock(fd);
-        readerstate[reader][i] = 0;
-        printf("Got ID# %s\n", readerstate[reader]); // shoudl comment me out
-
-        if(!isMember(readerstate[reader])){
-                HashID(readerstate[reader],hashed);
-                strcpy(readerstate[reader],hashed);
-        }else{
-                strcpy(hashed,readerstate[reader]);
-        }
-
-        fprintf(stderr, "HashID: %s\n",hashed);
-        fflush(stdout);
-//        Sleep(250); //was 100
-        //clearbuf(fd);
-
-        if (!isMember(hashed))
-        {
-          putbyte(fd, '@');
-//	Sleep(25);
-          putbyte(fd, reader+'@');
-//	Sleep(25);
-          putbyte(fd, C_NCK);
-          fprintf(stderr, "Invalid card.\n");
-          fprintf(fdlog,"%s: Unknown card %s denied.\n", curasctime(curtime), hashed);
-	  fflush(stdout);
-	  continue;
-        }
-	Sleep(25);
-	putbyte(fd, '@');
-	Sleep(25);
-	putbyte(fd, reader+'@');
-	Sleep(25);
-        putbyte(fd, C_ACK);
-        getName(hashed, name);
-	printf("%s - Card accepted\n",name);
-	  fflush(stdout);
-
-        break;
- 
-      case C_TOOLRCV:
-        dev = getbyteblock(fd);
-        strcpy(hashed, readerstate[reader]);
-	readerstate[reader][0] = 0; // forget the previously swiped card
-        getName(hashed, name);
-        getGroup(hashed, group);
-        fprintf(fdlog, "%s: %s (%s) wishes to use tool %c... ", curasctime(curtime), name, group, dev);
-//        Sleep(250);
-        if (canTool(hashed, dev-'0'))
-        {
-          putbyte(fd, '@');
-          putbyte(fd, reader + READEROFFSET);
-          putbyte(fd, C_ACK);
-          putbyte(fd, '`');
-          putbyte(fd, dev-'0'+ BOXOFFSET);
-          putbyte(fd, C_ACK);
-          fprintf(stderr, "User may use device %c.\n",dev);
-          fprintf(fdlog,"granted.\n");
-        }
-        else
-        {
-	  Sleep(100);
-          putbyte(fd, '@');
-	  Sleep(100);
-          putbyte(fd, reader + READEROFFSET);
-	  Sleep(100);
-          putbyte(fd, C_NCK);
-          fprintf(stderr, "User is DISALLOWED from device %c.\n",dev);
-          fprintf(fdlog,"denied.\n");
-        }
-        break;
-
-      default:
-        fprintf(stderr, "Invalid message header %X received.\n", xtype);
-	break;
-    }
-  }
-}
Index: trunk/old/server/serial.c
===================================================================
--- trunk/old/server/serial.c	(revision 133)
+++ trunk/old/server/serial.c	(nonexistent)
@@ -1,96 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <termios.h>
-#include <unistd.h>
-#include "serial.h"
-
-/* open and configure the port */
-int openport(char* portname){
-  struct termios oldtio, newtio;
-  char *error = 0;
-  int fd;
-
-  /* open read/write, non-controlling, non-blocking */
-  fd = open(portname, O_RDWR | O_NOCTTY | O_NONBLOCK);
-  if (fd == -1){
-    fprintf(stderr, "Unable to open %s: ", portname);
-    perror(error);
-    exit(-1);
-  }
-
-  tcgetattr(fd, &oldtio);          //save current port settings
-  bzero(&newtio, sizeof(newtio));  //clear struct for new settings
-
-  newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
-  newtio.c_iflag = IGNPAR | ICRNL;
-
-  newtio.c_oflag = 0;
-  newtio.c_lflag = 0;
-
-  newtio.c_cc[VINTR]    = 0;     /* Ctrl-c */
-  newtio.c_cc[VQUIT]    = 0;     /* Ctrl-\ */
-  newtio.c_cc[VERASE]   = 0;     /* del */
-  newtio.c_cc[VKILL]    = 0;     /* @ */
-  newtio.c_cc[VEOF]     = 4;     /* Ctrl-d */
-  newtio.c_cc[VTIME]    = 0;     /* inter-character timer unused */
-  newtio.c_cc[VMIN]     = 1;     /* blocking read until 1 character arrives 
-*/
-  newtio.c_cc[VSWTC]    = 0;     /* '\0' */
-  newtio.c_cc[VSTART]   = 0;     /* Ctrl-q */
-  newtio.c_cc[VSTOP]    = 0;     /* Ctrl-s */
-  newtio.c_cc[VSUSP]    = 0;     /* Ctrl-z */
-  newtio.c_cc[VEOL]     = 0;     /* '\0' */
-  newtio.c_cc[VREPRINT] = 0;     /* Ctrl-r */
-  newtio.c_cc[VDISCARD] = 0;     /* Ctrl-u */
-  newtio.c_cc[VWERASE]  = 0;     /* Ctrl-w */
-  newtio.c_cc[VLNEXT]   = 0;     /* Ctrl-v */
-  newtio.c_cc[VEOL2]    = 0;     /* '\0' */
-
-  /* flush the port, and apply the new settings now */
-  tcflush(fd, TCIFLUSH);
-  tcsetattr(fd, TCSANOW, &newtio);
-
-  return (fd);
-}
-
-int putbyte (int fd, char c)
-{
-   int result;
-   result= write(fd, &c, 1);
-//   Sleep(25);
-   return result;
-}
-
-unsigned char getbyte (int fd)
-{
-  char c;
-  ssize_t retval;
-
-  retval = read(fd, &c, 1); 
-
-  if (retval <= 0)
-    return 255;
-
-  return c;
-}
-
-unsigned char getbyteblock (int fd)
-{
-  char c;
-  ssize_t retval;
-
-  while ((retval = read(fd, &c, 1)) <= 0){}
-//    usleep(5000);
-
-  return c;
-}
-
-void clearbuf(int fd)
-{
-  tcflush(fd, TCIFLUSH);
-}
-
