From: Michel Pollet Date: Sat, 25 Feb 2012 14:40:40 +0000 (+0000) Subject: general: Introduce two new headers X-Git-Tag: v1.0b1~47 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=0c24f193e260d428283f284672c66be189876727;p=sx%2Fsimavr.git general: Introduce two new headers 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 --- diff --git a/examples/parts/ac_input.c b/examples/parts/ac_input.c index ef30b82..d6db0ad 100644 --- a/examples/parts/ac_input.c +++ b/examples/parts/ac_input.c @@ -20,9 +20,10 @@ along with simavr. If not, see . */ +#include #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, diff --git a/examples/parts/hd44780.c b/examples/parts/hd44780.c index 3955050..1c97235 100644 --- a/examples/parts/hd44780.c +++ b/examples/parts/hd44780.c @@ -23,7 +23,7 @@ #include #include #include -#include "sim_cycle_timers.h" +#include "sim_time.h" #include "hd44780.h" diff --git a/simavr/sim/avr_adc.c b/simavr/sim/avr_adc.c index 77e1d80..dd98a83 100644 --- a/simavr/sim/avr_adc.c +++ b/simavr/sim/avr_adc.c @@ -22,6 +22,7 @@ #include #include #include +#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) diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index 884ed29..657131b 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -25,6 +25,7 @@ #include #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 index 0000000..b8e0902 --- /dev/null +++ b/simavr/sim/sim_avr_types.h @@ -0,0 +1,37 @@ +/* + sim_avr_types.h + + Copyright 2008-2012 Michel Pollet + + 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 . + */ + + +#ifndef __SIM_AVR_TYPES_H___ +#define __SIM_AVR_TYPES_H___ + +#include +#include + +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 index 0000000..fa1106f --- /dev/null +++ b/simavr/sim/sim_time.h @@ -0,0 +1,52 @@ +/* + sim_time.h + + Copyright 2008-2012 Michel Pollet + + 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 . + */ + + +#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___ */ diff --git a/simavr/sim/sim_vcd_file.c b/simavr/sim/sim_vcd_file.c index 18aa5ab..2584643 100644 --- a/simavr/sim/sim_vcd_file.c +++ b/simavr/sim/sim_vcd_file.c @@ -26,6 +26,7 @@ #include #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);