aboutsummaryrefslogtreecommitdiff
path: root/blink.c
diff options
context:
space:
mode:
Diffstat (limited to 'blink.c')
-rw-r--r--blink.c95
1 files changed, 95 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 );
+}