Commit 0c24f193e260d428283f284672c66be189876727
authorMichel Pollet <buserror@gmail.com>
Sat, 25 Feb 2012 14:40:40 +0000 (14:40 +0000)
committerMichel Pollet <buserror@gmail.com>
Sat, 25 Feb 2012 14:47:38 +0000 (14:47 +0000)
Split the cycle/usec conversion code from the cycle_timer
heacers into it's new sim_time.h

Also removed the simple types out of sim_avr.h to create
new header sim_avr_types.h

Adapted other modules to use avr_time.h

Signed-off-by: Michel Pollet <buserror@gmail.com>
7 files changed:
examples/parts/ac_input.c
examples/parts/hd44780.c
simavr/sim/avr_adc.c
simavr/sim/sim_avr.c
simavr/sim/sim_avr_types.h [new file with mode: 0644]
simavr/sim/sim_time.h [new file with mode: 0644]
simavr/sim/sim_vcd_file.c

index ef30b82f29182464e3a3b2ebd9f02b47ec5022b8..d6db0adfceb46bf930343b2b837b1bd61ae9c27f 100644 (file)
        along with simavr.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <stdio.h>
 #include "sim_avr.h"
+#include "sim_time.h"
 #include "ac_input.h"
-#include "stdio.h"
 
 static avr_cycle_count_t
 switch_auto(struct avr_t * avr,
index 39550508311aaebec4e97ed4a7d338a3b76cedab..1c972358af3284f7eb121f76d8fd98d7eaf797d7 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "sim_cycle_timers.h"
+#include "sim_time.h"
 
 #include "hd44780.h"
 
index 77e1d8037b40e90da0671459c639a170516460f0..dd98a832e0e20d66f0b422db12f0422e10d5fee1 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "sim_time.h"
 #include "avr_adc.h"
 
 static avr_cycle_count_t avr_adc_int_raise(struct avr_t * avr, avr_cycle_count_t when, void * param)
index 884ed29111fef8a8b5acc7d03a1815a35ef11bcc..657131b3b490da84e521210a70f386154813eb01 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include "sim_avr.h"
 #include "sim_core.h"
+#include "sim_time.h"
 #include "sim_gdb.h"
 #include "avr_uart.h"
 #include "sim_vcd_file.h"
diff --git a/simavr/sim/sim_avr_types.h b/simavr/sim/sim_avr_types.h
new file mode 100644 (file)
index 0000000..b8e0902
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+       sim_avr_types.h
+
+       Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
+
+       This file is part of simavr.
+
+       simavr 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 3 of the License, or
+       (at your option) any later version.
+
+       simavr 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 simavr.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __SIM_AVR_TYPES_H___
+#define __SIM_AVR_TYPES_H___
+
+#include <stdint.h>
+#include <inttypes.h>
+
+typedef uint64_t       avr_cycle_count_t;
+typedef uint16_t       avr_io_addr_t;
+
+// printf() conversion specifier for avr_cycle_count_t
+#define PRI_avr_cycle_count PRIu64
+
+struct avr_t;
+
+#endif /* __SIM_AVR_TYPES_H___ */
diff --git a/simavr/sim/sim_time.h b/simavr/sim/sim_time.h
new file mode 100644 (file)
index 0000000..fa1106f
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+       sim_time.h
+
+       Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
+
+       This file is part of simavr.
+
+       simavr 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 3 of the License, or
+       (at your option) any later version.
+
+       simavr 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 simavr.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __SIM_TIME_H___
+#define __SIM_TIME_H___
+
+#include "sim_avr.h"
+
+// converts a number of usec to a number of machine cycles, at current speed
+static inline avr_cycle_count_t avr_usec_to_cycles(struct avr_t * avr, uint32_t usec)
+{
+       return avr->frequency * (avr_cycle_count_t)usec / 1000000;
+}
+
+// converts back a number of cycles to usecs (for usleep)
+static inline uint32_t avr_cycles_to_usec(struct avr_t * avr, avr_cycle_count_t cycles)
+{
+       return 1000000L * cycles / avr->frequency;
+}
+
+// converts back a number of cycles to nsecs
+static inline uint64_t avr_cycles_to_nsec(struct avr_t * avr, avr_cycle_count_t cycles)
+{
+       return (uint64_t)1E6 * (uint64_t)cycles / (avr->frequency/1000);
+}
+
+// converts a number of hz (to megahertz etc) to a number of cycle
+static inline avr_cycle_count_t avr_hz_to_cycles(avr_t * avr, uint32_t hz)
+{
+       return avr->frequency / hz;
+}
+
+#endif /* __SIM_TIME_H___ */
index 18aa5abbc15954e61f0d887707025ae585676a01..2584643264a772e691423c5d12fa8bfb6c560768 100644 (file)
@@ -26,6 +26,7 @@
 #include <string.h>
 #include "sim_vcd_file.h"
 #include "sim_avr.h"
+#include "sim_time.h"
 
 void _avr_vcd_notify(struct avr_irq_t * irq, uint32_t value, void * param);