aboutsummaryrefslogtreecommitdiff
path: root/blink.c
blob: c9213488e2c05e2b5fb232eb46c82a3bb917ac8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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 );
}