Project

General

Profile

Revision 1572

Added get_ir_offset to eeprom and changed program_eeprom.c so that it can read and modify them.

View differences:

branches/ir_branch/code/tools/eeprom/program_eeprom.c
1 1
#include <dragonfly_lib.h>
2
#include <stdlib.h>
2 3
#include <eeprom.h>
3 4

  
4 5
int main()
5 6
{
6 7
  char str[5];
7
  int i=0,id;
8
  int i=0,id,ir_offset;
8 9
  char c;
9 10

  
10 11
  dragonfly_init(ALL_ON);
......
12 13
  usb_puts("Here is the current setup:\r\n  ID: ");
13 14
  itoa(get_robotid(), str, 10);
14 15
  usb_puts(str);
16
  
15 17
  usb_puts("\r\n  BOM type: ");
16 18
  itoa(get_bom_type(), str, 10);
17 19
  usb_puts(str);
20
  
21
  usb_puts("\r\n  IR Offset: ");
22
  itoa(get_ir_offset(), str, 10);
23
  usb_puts(str);
24
  
25
  
18 26
  usb_puts("\r\n\r\nEnter new ID:");
19 27

  
20 28
  while((c = usb_getc()) != '\n' && c != '\r')
......
64 72
  eeprom_put_byte(EEPROM_BOM_TYPE_ADDR+2, 'M');
65 73
  eeprom_put_byte(EEPROM_BOM_TYPE_ADDR+3, id);
66 74

  
75
  usb_puts("\r\n\r\nEnter new IR Offset:");
76
  i = 0;
77
  while((c = usb_getc()) != '\n' && c != '\r')
78
    {
79
      usb_putc(c);
80
      if(i>=4)
81
      {
82
        usb_puts("ERROR: filled buffer\n");
83
        while(1);
84
      }
85
      str[i++] = c;
86
    }
87
  while(i<5)
88
    str[i++] = 0;
67 89

  
90
  ir_offset = atoi(str);
68 91

  
92
  usb_puts("\r\nsetting new IR_offset to: ");
93
  usb_puti(ir_offset);
94
  
95
  eeprom_put_byte(EEPROM_IR_OFFSET_ADDR, 'I');
96
  eeprom_put_byte(EEPROM_IR_OFFSET_ADDR+1, 'R');
97
  eeprom_put_byte(EEPROM_IR_OFFSET_ADDR+2, ir_offset);
98

  
69 99
  usb_puts("\r\ndone! have a nice day\r\n");
70 100

  
71 101

  
branches/ir_branch/code/lib/include/libdragonfly/eeprom.h
12 12
 
13 13
 #define EEPROM_ROBOT_ID_ADDR 0x10
14 14
 #define EEPROM_BOM_TYPE_ADDR 0x14
15
 #define EEPROM_IR_OFFSET_ADDR 0x20
15 16
 
16 17
 /** @brief store a byte to eeproem
17 18
  *  @return 0 if success, nonzero on failure
......
44 45
  */
45 46
 unsigned char get_bom_type(void);
46 47
 
48
    /** @brief get stored robot ID
49
  *
50
  * checks that EEPROM has been programed with an BOM type and returns it
51
  *
52
  *  @return the robot bom type as defined in bom.h, if it is stored. If it returns 0xFF it is probably invalid
53
  */
54
 unsigned char get_ir_offset(void);
55
 
56
 
47 57
 #endif
branches/ir_branch/code/projects/libdragonfly/eeprom.c
53 53
    else
54 54
        return 0xFF;
55 55
}
56

  
57
unsigned char get_ir_offset(void) {
58
    unsigned char c0, c1, c2;
59
    
60
    eeprom_get_byte(EEPROM_IR_OFFSET_ADDR, &c0);
61
    eeprom_get_byte(EEPROM_IR_OFFSET_ADDR+1, &c1);
62
    eeprom_get_byte(EEPROM_IR_OFFSET_ADDR+2, &c2);
63
    if(c0 == 'I' && c1 == 'R')
64
        return c2;
65
    else
66
        return 0xFF;
67
}
68

  
branches/ir_branch/code/projects/libdragonfly/eeprom.h
12 12
 
13 13
 #define EEPROM_ROBOT_ID_ADDR 0x10
14 14
 #define EEPROM_BOM_TYPE_ADDR 0x14
15
 #define EEPROM_IR_OFFSET_ADDR 0x20
15 16
 
16 17
 /** @brief store a byte to eeproem
17 18
  *  @return 0 if success, nonzero on failure
......
44 45
  */
45 46
 unsigned char get_bom_type(void);
46 47
 
48
    /** @brief get stored robot ID
49
  *
50
  * checks that EEPROM has been programed with an BOM type and returns it
51
  *
52
  *  @return the robot bom type as defined in bom.h, if it is stored. If it returns 0xFF it is probably invalid
53
  */
54
 unsigned char get_ir_offset(void);
55
 
56
 
47 57
 #endif

Also available in: Unified diff