Revision 1461
updated all the library code to have sensible _init behavior.
Almost all of the library components have a global variable which gets set after init and the functions inside will fail with an error code if init has not been called. Also, the init functions themselves check this variable and will bail out without doing any damage if that init has already been called
eeprom.c | ||
---|---|---|
1 |
/** |
|
2 |
* @file eeprom.c |
|
3 |
* @brief handles eeprom storage for persistent data |
|
4 |
* |
|
5 |
* Contains functions and definitions for reading and writing to eeprom |
|
6 |
* |
|
7 |
* @author Colony Project, Brad Neuman |
|
8 |
*/ |
|
9 |
|
|
1 | 10 |
#include <avr/io.h> |
2 | 11 |
#include "eeprom.h" |
3 | 12 |
|
13 |
/** @brief store a byte to eeproem |
|
14 |
* @return 0 if success, nonzero on failure |
|
15 |
*/ |
|
4 | 16 |
int eeprom_put_byte(unsigned int uiAddress, unsigned char ucData) { |
5 | 17 |
/* Wait for completion of previous write */ |
6 | 18 |
while(EECR & (1<<EEWE)); |
... | ... | |
15 | 27 |
return 0; |
16 | 28 |
} |
17 | 29 |
|
30 |
/** @brief reads a byte from eeprom |
|
31 |
* |
|
32 |
* Pass it thge address and a pointer to a byte where the byte at the |
|
33 |
* address will be stored |
|
34 |
* |
|
35 |
* @return 0 if successful (byte is set to the eeprom value at addr), |
|
36 |
* nonzero if there was a problem |
|
37 |
*/ |
|
18 | 38 |
int eeprom_get_byte(unsigned int uiAddress, unsigned char *byte) { |
19 | 39 |
/* Wait for completion of previous write */ |
20 | 40 |
while(EECR & (1<<EEWE)); |
... | ... | |
28 | 48 |
return 0; |
29 | 49 |
} |
30 | 50 |
|
31 |
|
|
51 |
/** @brief get stored robot ID |
|
52 |
* |
|
53 |
* checks that EEPROM has been programed with an ID and returns it |
|
54 |
* |
|
55 |
* @return the robot id, if it is stored. If it returns 0xFF it is probably invalid |
|
56 |
*/ |
|
32 | 57 |
unsigned char get_robotid(void) { |
33 | 58 |
unsigned char c0, c1, c2; |
34 | 59 |
|
... | ... | |
41 | 66 |
return 0xFF; |
42 | 67 |
} |
43 | 68 |
|
69 |
/** @brief get stored robot ID |
|
70 |
* |
|
71 |
* checks that EEPROM has been programed with an BOM type and returns it |
|
72 |
* |
|
73 |
* @return the robot bom type as defined in bom.h, if it is stored. If it returns 0xFF it is probably invalid |
|
74 |
*/ |
|
44 | 75 |
unsigned char get_bom_type(void) { |
45 | 76 |
unsigned char c0, c1, c2, c3; |
46 | 77 |
|
Also available in: Unified diff