]> www.fi.muni.cz Git - bike-lights.git/commitdiff
Include date and git revision in the eeprom variable
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 25 Jun 2013 20:26:33 +0000 (22:26 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 25 Jun 2013 20:26:33 +0000 (22:26 +0200)
... in order to be able to find out which firmware version is this MCU
running. This roughly corresponds to the commit
49420b56b31e113f4c40128c530f2e585a9f8061
of project Tinyboard.

firmware/Makefile
firmware/version.pl [new file with mode: 0755]

index 1b0113eab0835166c7648ed1dced01769b1b9228..726558bdcdc170f26d2156397aacfe613359c0d5 100644 (file)
@@ -1,7 +1,7 @@
 
 PROGRAM=lights
-SRC=main.c logging.c adc.c pwm.c tmr.c pwmled.c gpio.c ambient.c pattern.c \
-       buttons.c battery.c control.c
+SRC=version.c main.c logging.c adc.c pwm.c tmr.c pwmled.c gpio.c ambient.c \
+       pattern.c buttons.c battery.c control.c
 OBJ=$(SRC:.c=.o)
 
 
@@ -63,5 +63,10 @@ objdump: $(PROGRAM).elf
 clean:
        rm -f $(PROGRAM).hex $(PROGRAM).eep $(PROGRAM).elf *.o *.s eeprom.raw
 
-.PHONY: all clean dump_eeprom program program_flash program_eeprom objdump
+version.c:
+       ./version.pl > version.c
+
+.PHONY: all clean dump_eeprom program program_flash program_eeprom objdump \
+       version.c
+
 
diff --git a/firmware/version.pl b/firmware/version.pl
new file mode 100755 (executable)
index 0000000..4052844
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+use strict;
+use POSIX qw(strftime);
+
+my $git = `git rev-parse --short HEAD`;
+chomp $git;
+
+my $now = strftime('%Y%m%d', localtime(time));
+
+print <<EOF;
+/* DO NOT EDIT - GENERATED BY $0 */
+
+#include <avr/eeprom.h>
+
+unsigned char version[] EEMEM = {
+EOF
+
+print hex2c($now, "date");
+print hex2c($git, "git revision");
+
+print "};\n\n/* EOF - this file has not been truncated */\n\n";
+
+sub hex2c {
+       my ($data, $comment) = @_;
+
+       my $data1 = $data;
+       $data1 .= '0' if (length($data1) & 1 == 1);
+       $data1 =~ s/(..)/0x$1, /g;
+       return "\t$data1 /* $comment $data */\n";
+}
+