Index: trunk/code/projects/i2c_charge_station/i2c_auto.c
===================================================================
--- trunk/code/projects/i2c_charge_station/i2c_auto.c	(nonexistent)
+++ trunk/code/projects/i2c_charge_station/i2c_auto.c	(revision 666)
@@ -0,0 +1,120 @@
+/**
+ * This is the API for i2c_autodetect used on the 
+ * charging station. This block explains the high
+ * level implementation. The functions below explain
+ * the low level.
+ * 
+ ***** High Level *****
+ * Since the charge stations are hooked up
+ * via i2c lines, we must determine one master. We
+ * decide that the one with the XBee is the master.
+ * There should only be one Xbee in an i2c chain, though
+ * in the case that there are two, the second one to detect
+ * that they have an XBee must yeild the the older one.
+ * All others are slaves. At startup, we check if we have an
+ * XBee. If so, we poll for master, if there is none we declare
+ * ourselves master. If you do not have an XBee, poll the line
+ * asking for a master. If there is none, wait for a while and
+ * then try again until the master assigns you an ID.
+ * Once you have an ID, wait until the Master sends you commands.
+ * Periodically check if you have an XBee, just in case.
+ * The master must hand out IDs to the slaves. These IDs are
+ * kept in a table that indicates the status of the station.
+ * Occassionally poll the slaves to make sure they are not there and
+ * update the table as needed. If a packet comes in over XBee,
+ * forward to the correct charging station.
+ * In the event that the master loses the XBee, broadcast a message
+ * indicating that. Then poll for a new master. When one comes on,
+ * pass it the table.
+ **/
+ 
+ /**
+  * Sets up the needed states for i2c_autodetect
+  */
+ void i2c_startup (void) {
+ 
+ }
+ 
+ /**
+  * Checks if an XBee is present.
+  *
+  * @return 0 if false, 1 if true
+  */
+ char i2c_has_xbee(void) {
+ 
+ }
+ 
+ /**
+  * Acting as a temporary master, poll the master for an ID. If there
+  * is a master, he should respond with an ID in which case you should
+  * add that as your ID. Otherwise leave your ID blank.
+  *
+  * @return your ID, otherwise 0x00
+  */
+char i2c_request_id(void) {
+    
+}
+
+/**
+ * This should be called on the reception of an ID request. Since this
+ * will be called during an interrupt, make it as fast as possible.
+ * Check for the next available ID in the allocation table ans assign it.
+ * Send the ID back on the bus.
+ **/
+void i2c_allocate_id(void) {
+    
+}
+
+/**
+ * This is your handler function to be called by the i2c interrupt. You
+ * should get only 1 byte at a time and it will not be buffered. Handle it
+ * fast. You should analyze if the packet is a ID request, a poll, a transfer
+ * ID table, or data and then call the correct function. Basically this is a
+ * giant switch.
+ *
+ * @param data Data byte received from master
+ */
+void i2c_receive_data(char data) {
+
+}
+
+/**
+ * Called if a poll request has been received. Since this is in an interrupt make it
+ * fast. Queues up a poll response message to the master.
+ */
+void i2c_poll_respond(void) {
+
+}
+
+/**
+ * This should be done periodically. The allocation table should have a time since
+ * last poll field which counts down along with a poll send bit. 
+ * If time reaches 0 after a  poll remove it. This function, when
+ * called with a NULL should run through the table and send out request to all 
+ * those who are not currently being polled and check if those who have polls
+ * have reached 0 and remove them. If called with an ID, set the poll status
+ * bit for that ID to 0.
+ * 
+ * @param ID ID of the slave who has responded. If NULL poll all those not being polled
+ */
+void i2c_poll_slaves_send(char ID) {
+
+}
+
+/**
+ * Call this if you have lost the XBee and a new master has arrived. You should 
+ * transfer the entire table over to the new master.
+ */
+void i2c_transfer_table(void) {
+
+}
+
+/**
+ * Call this if you receive a transfer table request. You should accept it and 
+ * merge it into your table.
+ */
+ void i2c_receive_table(void) {
+ 
+ }
+
+
