From: Sebastien Bourdeauducq Date: Thu, 11 Jul 2013 17:00:48 +0000 (+0200) Subject: software: move time.c to libbase X-Git-Tag: 24jan2021_ls180~2873 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e42a42ce401217669561f47832014e3d9163e293;p=litex.git software: move time.c to libbase --- diff --git a/software/include/base/time.h b/software/include/base/time.h new file mode 100644 index 00000000..34083902 --- /dev/null +++ b/software/include/base/time.h @@ -0,0 +1,15 @@ +#ifndef __TIME_H +#define __TIME_H + +#ifdef __cplusplus +extern "C" { +#endif + +void time_init(void); +int elapsed(int *last_event, int period); + +#ifdef __cplusplus +} +#endif + +#endif /* __TIME_H */ diff --git a/software/libbase/Makefile b/software/libbase/Makefile index e58da5ce..b9b9a7ab 100644 --- a/software/libbase/Makefile +++ b/software/libbase/Makefile @@ -1,7 +1,7 @@ M2DIR=../.. include $(M2DIR)/software/common.mak -OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o system.o id.o uart.o qsort.o strtod.o +OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o system.o id.o uart.o time.o qsort.o strtod.o all: crt0.o libbase.a libbase-nofloat.a diff --git a/software/libbase/time.c b/software/libbase/time.c new file mode 100644 index 00000000..c1c2ea8b --- /dev/null +++ b/software/libbase/time.c @@ -0,0 +1,29 @@ +#include +#include + +void time_init(void) +{ + int t; + + timer0_en_write(0); + t = 2*identifier_frequency_read(); + timer0_reload_write(t); + timer0_load_write(t); + timer0_en_write(1); +} + +int elapsed(int *last_event, int period) +{ + int t, dt; + + timer0_update_value_write(1); + t = timer0_reload_read() - timer0_value_read(); + dt = t - *last_event; + if(dt < 0) + dt += timer0_reload_read(); + if((dt > period) || (dt < 0)) { + *last_event = t; + return 1; + } else + return 0; +} diff --git a/software/videomixer/Makefile b/software/videomixer/Makefile index 347dccc7..9742ac9d 100644 --- a/software/videomixer/Makefile +++ b/software/videomixer/Makefile @@ -1,7 +1,7 @@ M2DIR=../.. include $(M2DIR)/software/common.mak -OBJECTS=isr.o time.o fb.o dvisampler0.o dvisampler1.o main.o +OBJECTS=isr.o fb.o dvisampler0.o dvisampler1.o main.o all: videomixer.bin videomixer.fbi diff --git a/software/videomixer/dvisamplerX.c b/software/videomixer/dvisamplerX.c index fbb0b688..e089ed19 100644 --- a/software/videomixer/dvisamplerX.c +++ b/software/videomixer/dvisamplerX.c @@ -3,10 +3,10 @@ #include #include +#include #include #include -#include "time.h" #include "fb.h" #include "dvisamplerX.h" diff --git a/software/videomixer/main.c b/software/videomixer/main.c index 4407d64a..5d6128a4 100644 --- a/software/videomixer/main.c +++ b/software/videomixer/main.c @@ -3,11 +3,11 @@ #include #include +#include #include #include #include -#include "time.h" #include "fb.h" #include "dvisampler0.h" #include "dvisampler1.h" diff --git a/software/videomixer/time.c b/software/videomixer/time.c deleted file mode 100644 index 1f2c3aa9..00000000 --- a/software/videomixer/time.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -#include "time.h" - -void time_init(void) -{ - int t; - - timer0_en_write(0); - t = 2*identifier_frequency_read(); - timer0_reload_write(t); - timer0_load_write(t); - timer0_en_write(1); -} - -int elapsed(int *last_event, int period) -{ - int t, dt; - - timer0_update_value_write(1); - t = timer0_reload_read() - timer0_value_read(); - dt = t - *last_event; - if(dt < 0) - dt += timer0_reload_read(); - if((dt > period) || (dt < 0)) { - *last_event = t; - return 1; - } else - return 0; -} diff --git a/software/videomixer/time.h b/software/videomixer/time.h deleted file mode 100644 index a8ebe23f..00000000 --- a/software/videomixer/time.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __TIME_H -#define __TIME_H - -void time_init(void); -int elapsed(int *last_event, int period); - -#endif /* __TIME_H */