From 4dc9b15829321e29b82c5f0317d2a0811aee6482 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 13 May 2022 14:15:13 +0200 Subject: implement dummy simulation functions --- robot/hypervisor.c | 3 +-- robot/makefile | 20 ++++++++++++++------ robot/orangutan_shim.h | 7 +++++++ robot/setup.c | 2 +- robot/sim.c | 38 ++++++++++++++++++++++++++++++++++++++ robot/sim.h | 13 +++++++++++++ 6 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 robot/orangutan_shim.h create mode 100644 robot/sim.c create mode 100644 robot/sim.h diff --git a/robot/hypervisor.c b/robot/hypervisor.c index 381d9af..8c22316 100644 --- a/robot/hypervisor.c +++ b/robot/hypervisor.c @@ -1,11 +1,10 @@ -#include - #include "consts.h" #include "errcatch.h" #include "hypervisor.h" #include "io.h" #include "modes.h" #include "sercomm.h" +#include "orangutan_shim.h" void w2_hypervisor_main() { w2_sercomm_main(); diff --git a/robot/makefile b/robot/makefile index 598e0fa..fb30b7e 100644 --- a/robot/makefile +++ b/robot/makefile @@ -4,24 +4,30 @@ AVRDUDE_DEVICE = m328p DEVICE ?= atmega168 MCU ?= atmega168 AVRDUDE_DEVICE ?= m168 - -CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) $(DEVICE_SPECIFIC_CFLAGS) -Os -LDFLAGS=-Wl,-gc-sections -lpololu_$(DEVICE) -Wl,-relax +SIM = PORT ?= /dev/ttyACM0 +CFLAGS=-g -Wall $(DEVICE_SPECIFIC_CFLAGS) -Os +LDFLAGS=-Wl,-gc-sections -Wl,-relax + +CFLAGS += $(if $(SIM), -DW2_SIM, -mcall-prologues -mmcu=$(MCU)) +LDFLAGS += $(if $(SIM), , -lpololu_$(DEVICE)) + SOURCES := $(wildcard *.c) HEADERS := $(wildcard *.h) OBJECTS := $(patsubst %.c,%.o, $(SOURCES)) +PREFIX := $(if $(SIM), , avr-) + AVRDUDE=avrdude -CC=avr-gcc -OBJ2HEX=avr-objcopy +CC=$(PREFIX)gcc +OBJ2HEX=$(PREFIX)objcopy BUILD_STR=$(shell git update-index -q --refresh; git describe --tags --dirty='*' --broken='x' | cut -c1-20) CFLAGS += -DW2_BUILD_STR="$(BUILD_STR)" -all: out.hex +all: $(if $(SIM), a.out, out.hex) clean: rm -f *.o out.hex a.out compile_commands.json @@ -40,6 +46,8 @@ flash: out.hex $(AVRDUDE) -p $(AVRDUDE_DEVICE) -c avrisp2 -P $(PORT) -U flash:w:out.hex format: + SOURCES := $(filter-out sim.c, $(SOURCES)) + HEADERS := $(filter-out sim.h, $(HEADERS)) clang-format -i $(SOURCES) $(HEADERS) clang-tidy --fix-errors $(SOURCES) $(HEADERS) diff --git a/robot/orangutan_shim.h b/robot/orangutan_shim.h new file mode 100644 index 0000000..de57c98 --- /dev/null +++ b/robot/orangutan_shim.h @@ -0,0 +1,7 @@ +#pragma once + +#ifdef W2_SIM +#include "sim.h" +#else +#include +#endif diff --git a/robot/setup.c b/robot/setup.c index 10001c7..1174570 100644 --- a/robot/setup.c +++ b/robot/setup.c @@ -1,6 +1,6 @@ -#include #include +#include "orangutan_shim.h" #include "consts.h" #include "halt.h" #include "modes.h" diff --git a/robot/sim.c b/robot/sim.c new file mode 100644 index 0000000..8fc8d00 --- /dev/null +++ b/robot/sim.c @@ -0,0 +1,38 @@ +#include + +#include "sim.h" + +void time_reset() { + return; + printf("SIM: time_reset()\n"); +} + +unsigned long get_ms() { + printf("SIM: get_ms()\n"); + return 0; +} + +void red_led(unsigned char on) { + printf("SIM: red_led(%i)\n", on); + return; +} + +void green_led(unsigned char on) { + printf("SIM: green_led(%i)\n", on); + return; +} + +void clear() { + printf("SIM: clear()\n"); + return; +} + +void play(const char* melody) { + printf("SIM: play(\"%s\")\n", melody); + return; +} + +void serial_set_baud_rate(unsigned int rate) { + printf("SIM: serial_set_baud_rate(%u)\n", rate); + return; +} diff --git a/robot/sim.h b/robot/sim.h new file mode 100644 index 0000000..a408bc6 --- /dev/null +++ b/robot/sim.h @@ -0,0 +1,13 @@ +#pragma once + +/** + * simulates pololu library functions for local testing + */ + +void time_reset(); // NOLINT +unsigned long get_ms(); // NOLINT +void red_led(unsigned char on); // NOLINT +void green_led(unsigned char on); // NOLINT +void clear(); // NOLINT +void play(const char* melody); // NOLINT +void serial_set_baud_rate(unsigned int rate); // NOLINT -- cgit v1.2.3