summaryrefslogtreecommitdiff
path: root/n/asserv/src/asserv/eeprom.avr.c
diff options
context:
space:
mode:
authorschodet2006-01-20 20:36:48 +0000
committerschodet2006-01-20 20:36:48 +0000
commit23db3d37f57602453d21745810232b204b4ca264 (patch)
treefeec1307f66669e8145b916fab15f85c843239dc /n/asserv/src/asserv/eeprom.avr.c
parent89b93c13405fec0e0b73aaf04aa231fa0865a48b (diff)
PrĂȘt pour la compilation sur host.
Diffstat (limited to 'n/asserv/src/asserv/eeprom.avr.c')
-rw-r--r--n/asserv/src/asserv/eeprom.avr.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/n/asserv/src/asserv/eeprom.avr.c b/n/asserv/src/asserv/eeprom.avr.c
new file mode 100644
index 0000000..34770bb
--- /dev/null
+++ b/n/asserv/src/asserv/eeprom.avr.c
@@ -0,0 +1,78 @@
+/* eeprom.c */
+/* asserv - Position & speed motor control on AVR. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * 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.
+ *
+ * }}} */
+#include <avr/eeprom.h>
+
+#define EEPROM_KEY 0xa5
+
+/* +AutoDec */
+/* -AutoDec */
+
+/* Read parameters from eeprom. */
+static void
+eeprom_read_params (void)
+{
+ uint8_t *p8 = 0;
+ uint16_t *p16;
+ if (eeprom_read_byte (p8++) != EEPROM_KEY)
+ return;
+ pwm_dir = eeprom_read_byte (p8++);
+ p16 = (uint16_t *) p8;
+ pos_theta_kp = eeprom_read_word (p16++);
+ pos_alpha_kp = eeprom_read_word (p16++);
+ pos_theta_ki = eeprom_read_word (p16++);
+ pos_alpha_ki = eeprom_read_word (p16++);
+ pos_theta_kd = eeprom_read_word (p16++);
+ pos_alpha_kd = eeprom_read_word (p16++);
+ pos_e_sat = eeprom_read_word (p16++);
+ pos_int_sat = 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++, EEPROM_KEY);
+ eeprom_write_byte (p8++, pwm_dir);
+ p16 = (uint16_t *) p8;
+ eeprom_write_word (p16++, pos_theta_kp);
+ eeprom_write_word (p16++, pos_alpha_kp);
+ eeprom_write_word (p16++, pos_theta_ki);
+ eeprom_write_word (p16++, pos_alpha_ki);
+ eeprom_write_word (p16++, pos_theta_kd);
+ eeprom_write_word (p16++, pos_alpha_kd);
+ eeprom_write_word (p16++, pos_e_sat);
+ eeprom_write_word (p16++, pos_int_sat);
+}
+
+/* Clear eeprom parameters. */
+static void
+eeprom_clear_params (void)
+{
+ uint8_t *p = 0;
+ eeprom_write_byte (p, 0xff);
+}
+