aboutsummaryrefslogtreecommitdiff
path: root/armen.h
blob: 404d05aafa73867262e075d4890321ecc519023d (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/************************************************************************/
/*                                                                      */
/*                  - armen a tiny operating system -                   */
/*                                                                      */
/*  File:           armen.h                                             */
/*  Description:    armen api                                           */
/*  Version:        1.0                                                 */
/*  Author:         Otto Mattik                                         */
/*                                                                      */
/*  (C)Copyright Otto Mattik 2014-2021.                                 */
/*                                                                      */
/*  This file is a part of 'armen' (a tiny operating system).           */
/*  'armen" is distributed under the CeCILL-V2.1 licence. For more      */
/*  details about this licence, please visit the website cecill.info    */
/*                                                                      */
/************************************************************************/

#ifndef _ARMEN_H_
#define _ARMEN_H_

#include <stdint.h>

#define FALSE               0
#define TRUE                1

/*
 * events
*/
#define EVENT_UART0         0x0001
#define EVENT_UART1         0x0002
#define EVENT_UART2         0x0004
#define EVENT_UART3         0x0008
#define EVENT_TIMER1        0x0010
#define EVENT_TIMER2        0x0020
#define EVENT_INT0          0x0040
#define EVENT_INT1          0x0080
#define EVENT_INT2          0x0100
#define EVENT_PCINT0        0x0200
#define EVENT_PCINT1        0x0400
#define EVENT_PCINT2        0x0800
#define EVENT_USER          0x2000

#define EVENT_PCINT         EVENT_PCINT0

/*
 * gpio
*/
#define GPIO_INPUT          0
#define GPIO_OUTPUT         1

#define GPIO_LOW            0
#define GPIO_HIGH           1

#define GPIO0               0
#define GPIO1               1
#define GPIO2               2
#define GPIO3               3
#define GPIO4               4
#define GPIO5               5
#define GPIO6               6
#define GPIO7               7
#define GPIO8               8
#define GPIO9               9
#define GPIO10              10
#define GPIO11              11
#define GPIO12              12
#define GPIO13              13
#define GPIO14              14
#define GPIO15              15
#define GPIO16              16
#define GPIO17              17
#define GPIO18              18
#define GPIO19              19
#define GPIO20              20
#define GPIO21              21
#define GPIO22              22
#define GPIO23              23

/*
 * uart features
*/
#if defined(UART) && (UART != 0)
  #define B1200             0
  #define B2400             1
  #define B4800             2
  #define B9600             3
  #define B19200            4
  #define B38400            5
  #define B57600            6
  #define B115200           7
  #define BAUDRATE          7
  #define ECHOO             8           /* echo on output */
#endif

/*
 * analog conversion
*/
#ifdef USE_ADC
  #define ADC_REF_VCC       0
  #define ADC_REF_EXT       1
  #define ADC_REF_INT1V1    2
  #define ADC_REF_INT2V2    3
  #define ADC_REF_INT2V56   3
  #define ADC_REF_INT4V096  4
#endif

/*
 * pulse witdth modulation
*/
#ifdef USE_PWM
  #define PWM_SCALE_1       1
  #define PWM_SCALE_8       2
  #define PWM_SCALE_64      3
  #define PWM_SCALE_256     4
  #define PWM_SCALE_1024    5
#endif

/*
 * pin change interruptions
*/
#ifdef USE_PCINT
  #define INT_LOW           0
  #define INT_CHANGE        1
  #define INT_RISING        2
  #define INT_FALLING       3
  #define INT_DISABLE       4
#endif

typedef int8_t thread_t;
typedef uint32_t sem_t;
#ifdef USE_BIG_TIMER
typedef uint32_t timer_t;
#else
typedef uint16_t timer_t;
#endif

#ifdef __cplusplus
extern "C" {
#endif

extern void armen_start( void );

extern uint16_t wait_event( uint16_t events );
extern void send_user_event( void );
extern timer_t get_timer( uint8_t timer );
extern int8_t set_timer( uint8_t timer, timer_t msecs );
extern void sleep( timer_t msecs );
extern void delay( uint16_t usecs );
extern uint32_t get_time( void );

extern thread_t thread_self( void );
extern thread_t thread_create( void* (*start)(void*), void* arg );
extern void thread_exit( void* retval );
#ifdef USE_FULL_THREAD
extern void thread_cancel( thread_t thread );
extern void thread_join( thread_t thread, void** retval );
extern uint8_t thread_nice( thread_t thread, uint8_t priority );
#endif

extern uint8_t test_and_set( void* lock );
#ifdef USE_SEM
extern void sem_init( sem_t* sem, uint8_t value );
extern void sem_wait( sem_t* sem );
extern void sem_post( sem_t* sem );
#endif

extern void gpio_pin_mode( uint8_t gpio, uint8_t mode, ... );
extern int8_t gpio_pin_get( uint8_t gpio );
extern void gpio_pin_set( uint8_t gpio, uint8_t value );
#ifdef USE_ADC
extern void gpio_adc_ref( uint8_t ref );
extern int16_t gpio_adc_get( uint8_t gpio );
#endif
#ifdef USE_PWM
extern void gpio_pwm_freq( uint8_t scale );
extern void gpio_pwm_set( uint8_t gpio, uint8_t percent );
#endif
#ifdef USE_PCINT
extern void gpio_int_enable( uint8_t interrupt, uint8_t mode );
extern void gpio_pcint_enable( uint8_t gpio, uint8_t enable );
#endif

#if defined(UART) && (UART != 0)
extern int8_t uart_open( uint8_t device, uint8_t config );
extern int8_t uart_close( uint8_t device );
extern int8_t uart_read( uint8_t device, uint8_t* byte );
extern int8_t uart_write( uint8_t device, uint8_t byte );
extern char uart_getchar( uint8_t device );
extern void uart_putchar( uint8_t device, char c );
extern void uart_putstr( uint8_t device, char* s );
#endif

#ifdef __cplusplus
}
#endif

#endif