summaryrefslogtreecommitdiff
path: root/n/asserv/src/eeprom.c
blob: 8c98078957ea14784001ff18f3099b7a9c6acad0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* eeprom.c */
/* asserv - Position & speed motor control on a ATmega128. {{{
 *
 * Copyright (C) 2005 Nicolas Schodet
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Contact :
 *        Web: http://perso.efrei.fr/~schodet/
 *      Email: <contact@ni.fr.eu.org>
 * }}} */
#include <avr/eeprom.h>

/* +AutoDec */
/* -AutoDec */

/* Read parameters from eeprom. */
static void
eeprom_read_params (void)
{
    uint8_t *p8 = 0;
    uint16_t *p16;
    if (eeprom_read_byte (p8++) != 0xa5)
	return;
    speed_acc_cpt = speed_acc = eeprom_read_byte (p8++);
    speed_max = eeprom_read_byte (p8++);
    pwm_dir = eeprom_read_byte (p8++);
    p16 = (uint16_t *) p8;
    speed_kp = eeprom_read_word (p16++);
    speed_ki = eeprom_read_word (p16++);
    speed_kd = eeprom_read_word (p16++);
    speed_int_max = eeprom_read_word (p16++);
    postrack_set_footing (eeprom_read_word (p16++));
}

/* Write parameters to eeprom. */
static void
eeprom_write_params (void)
{
    uint8_t *p8 = 0;
    uint16_t *p16;
    eeprom_write_byte (p8++, 0xa5);
    eeprom_write_byte (p8++, speed_acc_cpt);
    eeprom_write_byte (p8++, speed_max);
    eeprom_write_byte (p8++, pwm_dir);
    p16 = (uint16_t *) p8;
    eeprom_write_word (p16++, speed_kp);
    eeprom_write_word (p16++, speed_ki);
    eeprom_write_word (p16++, speed_kd);
    eeprom_write_word (p16++, speed_int_max);
    eeprom_write_word (p16++, postrack_footing);
}

/* Clear eeprom parameters. */
static void
eeprom_clear_params (void)
{
    uint8_t *p = 0;
    eeprom_write_byte (p, 0xff);
}