aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Mattik <otto@mattik.org>2021-07-08 18:20:26 +0200
committerOtto Mattik <otto@mattik.org>2021-07-08 18:20:26 +0200
commit49b9e6e6548bf621e321ff66825fb2e1579db063 (patch)
tree0ff23a35f11b6bd84fc39359f819401adfdae536
downloadblink-49b9e6e6548bf621e321ff66825fb2e1579db063.tar.gz
blink-49b9e6e6548bf621e321ff66825fb2e1579db063.zip
git: update to v1.0HEADv1.0master
-rw-r--r--blink.c95
-rw-r--r--makefile80
-rw-r--r--options.mak32
3 files changed, 207 insertions, 0 deletions
diff --git a/blink.c b/blink.c
new file mode 100644
index 0000000..c921348
--- /dev/null
+++ b/blink.c
@@ -0,0 +1,95 @@
+/************************************************************************/
+/* */
+/* File: blink.c */
+/* Description: the "hello world" for armen OS */
+/* Version: 1.0 */
+/* Author: Otto Mattik */
+/* */
+/* (C)Copyright Otto Mattik 2021. */
+/* */
+/* This file is distributed under the CeCILL-V2.1 licence. */
+/* For more details, please visit the website cecill.info */
+/* */
+/************************************************************************/
+
+#include "armen.h"
+
+#ifndef ARDUINO
+ #error "no or unaivalable mcu defined"
+#endif
+
+/*
+ * schematic:
+ * +---+
+ * P12 >----|220|----+
+ * +---+ |
+ * ---
+ * LED2 \ /
+ * -----
+ * |
+ * ---
+ * GND
+*/
+
+#if defined(__AVR_ATmega2560__)
+ #define PIN_LED1 GPIO15 /* mega P13 (onboard led) */
+ #define PIN_LED2 GPIO14 /* mega P12 */
+#else
+ #define PIN_LED1 GPIO5 /* uno P13 (onboard led) */
+ #define PIN_LED2 GPIO4 /* uno P12 */
+#endif
+
+#ifdef DEBUG
+extern void uart_printf( uint8_t, char*, ... );
+#endif
+
+/*
+ * 1st thread
+*/
+void* led1( void* param )
+{
+ for( ;; )
+ {
+ sleep( 1000 );
+ gpio_pin_set( PIN_LED1, 1 - gpio_pin_get( PIN_LED1 ) );
+ }
+}
+
+/*
+ * 2nd thread
+*/
+void* led2( void* param )
+{
+ for( ;; )
+ {
+ sleep( 1400 );
+ gpio_pin_set( PIN_LED2, 1 - gpio_pin_get( PIN_LED2 ) );
+ }
+}
+
+/*
+ * initialization
+*/
+void setup( void )
+{
+#ifdef DEBUG
+ uart_open( 0, B115200 );
+#endif
+ gpio_pin_mode( PIN_LED1, GPIO_OUTPUT, GPIO_LOW );
+ gpio_pin_mode( PIN_LED2, GPIO_OUTPUT, GPIO_LOW );
+}
+
+/*
+ * program entry point
+*/
+void main( void )
+{
+ armen_start( );
+ setup( );
+
+ /* run 2nd thread */
+ thread_create( led2, (void*)0 );
+
+ /* run 1st thread */
+ led1( (void*)0 );
+}
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..79217cc
--- /dev/null
+++ b/makefile
@@ -0,0 +1,80 @@
+$(eval MAK_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
+$(eval SRC_DIR = $(shell dir=$(MAK_DIR);while [ `basename $$dir` != src ];do dir=`dirname $$dir`;done;echo $$dir))
+
+ifeq ($(shell test -f $(SRC_DIR)/options.mak && echo exists), exists)
+ include $(SRC_DIR)/options.mak
+endif
+include options.mak
+
+APP_NAME = blink
+APP_OBJS = $(BUILD_DIR)/$(APP_NAME).o
+ARMEN_DIR = $(SRC_DIR)/armen/armen
+ifdef BUILD_PREFIX
+ BUILD_DIR = $(BUILD_PREFIX)/armen/$(APP_NAME)/$(MODEL)/$(T_CPU)
+else
+ BUILD_DIR = build/$(MODEL)/$(T_CPU)
+endif
+
+ifeq ($(MODEL), arduino)
+ F_CPU = 16000000UL
+ PRGFLAGS += -b 115200 -P /dev/ttyACM0
+ ifeq ($(T_CPU), atmega2560)
+ PRGFLAGS += -c wiring
+ else
+ T_CPU = atmega328p
+ PRGFLAGS += -c arduino
+ endif
+else
+ PRGFLAGS += -P /dev/usbasp -c usbasp
+endif
+
+.PHONY: all clean cleanall install list size
+.DEFAULT_GOAL := all
+
+ARMEN_FLAGS += -DCHECK_PARAM
+include $(ARMEN_DIR)/armen.mak
+
+CFLAGS += -DF_CPU=$(F_CPU)
+ASFLAGS += -DF_CPU=$(F_CPU)
+INCFLAGS = -I. -I$(ARMEN_DIR)
+PRGFLAGS += -c $(PRGTYPE)
+ifeq ($(MODEL), simu)
+ CFLAGS += -Wa,-gstabs
+ ASFLAGS += -g3 -gdwarf-2
+endif
+
+all: $(BUILD_DIR)/$(APP_NAME).elf $(BUILD_DIR)/$(APP_NAME).hex
+
+$(BUILD_DIR)/$(APP_NAME).elf: $(ARMEN_OBJS) $(APP_OBJS)
+ @if [ ! -d $(BUILD_DIR) ]; then mkdir -p $(BUILD_DIR); fi
+ $(CC) $(CFLAGS) -o $@ $^
+
+$(BUILD_DIR)/$(APP_NAME).o: $(MAK_DIR)/$(APP_NAME).c $(ARMEN_DIR)/armen.h
+ @if [ ! -d $(BUILD_DIR) ]; then mkdir -p $(BUILD_DIR); fi
+ $(CC) $(CFLAGS) $(OPTFLAGS) $(ARMEN_FLAGS) $(INCFLAGS) -c -o $@ $<
+
+clean:
+ @rm -f $(BUILD_DIR)/*.o $(BUILD_DIR)/*.lst
+
+cleanall:
+ @rm -fr $(BUILD_DIR)
+
+install: $(BUILD_DIR)/$(APP_NAME).hex
+ @$(PRG) $(PRGFLAGS) -U flash:w:$<
+
+list: $(BUILD_DIR)/$(APP_NAME).lst
+
+size: $(BUILD_DIR)/$(APP_NAME).elf
+ @text=`$(FS) $< | tail -1 | awk '{print $$1}'`;\
+ data=`$(FS) $< | tail -1 | awk '{print $$2}'`;\
+ bss=`$(FS) $< | tail -1 | awk '{print $$3}'`;\
+ total=`expr $$text + $$data + $$bss`;\
+ echo `basename $<`" --> text:$$text + data:$$data + bss:$$bss = $$total bytes"
+
+ifeq ($(MODEL), simu)
+simu: $(BUILD_DIR)/$(APP_NAME).hex
+ @$(SIM) -g -m $(T_CPU) -f `echo $(F_CPU)|cut -d'U' -f1` $< & SIMPID=$$!;\
+ echo "target remote localhost:1234" >.gdbinit; sleep 1;\
+ $(DBG) -q -d . -d ./avr $(BUILD_DIR)/$(APP_NAME).elf;\
+ kill -9 $$SIMPID; rm -f .gdbinit
+endif
diff --git a/options.mak b/options.mak
new file mode 100644
index 0000000..d01c3b8
--- /dev/null
+++ b/options.mak
@@ -0,0 +1,32 @@
+# prod, simu or arduino
+MODEL := arduino
+
+#T_CPU = atmega328p
+#F_CPU = 16000000UL
+
+# thread functions, 0: reduced or 1: all [0 by default]
+#FULL_THREAD = 1
+
+# max count of thread(s), 1 to 6 [1 by default]
+#THREAD = 2
+
+# size of timer(s), 0 = 16bits or 1 = 32bits [0 by default]
+#BIG_TIMER = 1
+
+# count of timer(s), 1 or 2 [1 by default]
+#TIMER = 2
+
+# semaphore functions, 0 or 1 [0 by default]
+#SEM = 1
+
+# number of uart(s), 0 to 4 [0 by default]
+#UART = 1
+
+# use analog conversion, 0 or 1 [0 by default]
+#ADC = 1
+
+# use pulse width modulation, 0 or 1 [0 by default]
+#PWM = 1
+
+# use pin change interruption, 0 or 1 [0 by default]
+#PCINT = 1