Revision ba516b61

View differences:

os/amiroos.h
67 67

  
68 68
#include "core/inc/aos_confcheck.h"
69 69
#include "core/inc/aos_debug.h"
70
#include <core/inc/aos_iostream.h>
70 71
#include "core/inc/aos_shell.h"
71
#include "core/inc/aos_ssm.h"
72 72
#include "core/inc/aos_system.h"
73 73
#include "core/inc/aos_thread.h"
74 74
#include "core/inc/aos_time.h"
os/core/core.mk
31 31

  
32 32
# C source files
33 33
AMIROOSCORECSRC = $(AMIROOS_CORE_DIR)src/aos_debug.c \
34
                  $(AMIROOS_CORE_DIR)src/aos_iostream.c \
34 35
                  $(AMIROOS_CORE_DIR)src/aos_shell.c \
35
                  $(AMIROOS_CORE_DIR)src/aos_ssm.c \
36 36
                  $(AMIROOS_CORE_DIR)src/aos_system.c \
37 37
                  $(AMIROOS_CORE_DIR)src/aos_thread.c \
38 38
                  $(AMIROOS_CORE_DIR)src/aos_timer.c \
os/core/inc/aos_iostream.h
1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

  
15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
19
#ifndef _AMIROOS_IOSTREAM_H_
20
#define _AMIROOS_IOSTREAM_H_
21

  
22
#include <hal.h>
23
#include <aos_types.h>
24
#include <stdarg.h>
25

  
26

  
27

  
28
/**
29
 * @brief   Channel flag to indicate whether the channel is attached to a stream.
30
 */
31
#define AOS_IOCHANNEL_ATTACHED                  (1 << 0)
32

  
33
/**
34
 * @brief   Channel flag to indicate whether the channel is set as output.
35
 */
36
#define AOS_IOCHANNEL_OUTPUT_ENABLE             (1 << 1)
37

  
38
/*
39
 * forward definitions
40
 */
41
typedef struct aos_iochannel AosIOChannel;
42
typedef struct aos_ostream AosIOStream;
43

  
44
/**
45
 * @brief   AosI=Channel specific methods.
46
 */
47
#define _aos_iochannel_methods                                              \
48
  _base_asynchronous_channel_methods
49

  
50
/**
51
 * @brief   AosIOChannel specific data.
52
 */
53
#define _aos_iochannel_data                                                 \
54
  /* pointer to a BaseAsynchronousChannel object */                         \
55
  BaseAsynchronousChannel* asyncchannel;                                    \
56
  /* pointer to the next channel in a AosIOStream */                        \
57
  AosIOChannel* next;                                                       \
58
  /* flags related to the channel */                                        \
59
  uint8_t flags;
60

  
61
/**
62
 * @extends BaseAsynchronousChannelVMT
63
 *
64
 * @brief   AosIOChannel virtual methods table.
65
 */
66
struct AosIOChannelVMT {
67
  _aos_iochannel_methods
68
};
69

  
70
/**
71
 * @extends BaseAsynchronousChannel
72
 *
73
 * @brief   I/O Channel class.
74
 * @details This class implements an asynchronous I/O channel.
75
 */
76
struct aos_iochannel {
77
  /** @brief Virtual Methods Table. */
78
  const struct AosIOChannelVMT* vmt;
79
  _aos_iochannel_data
80
};
81

  
82
/**
83
 * @brief   AosIOStream methods.
84
 */
85
#define _aos_iostream_methods                                               \
86
  _base_sequential_stream_methods
87

  
88
/**
89
 * @brief   AosIOStream data.
90
 */
91
#define _aos_iostream_data                                                  \
92
  /* Pointer to the first channel in a list. */                             \
93
  AosIOChannel* channel;
94

  
95
/**
96
 * @extends BaseSequentialStream
97
 *
98
 * @brief   AosIOStream virtual methods table.
99
 */
100
struct AosIOStreamVMT {
101
  _aos_iostream_methods
102
};
103

  
104
/**
105
 * @extends BaseSequentialStream
106
 *
107
 * @brief   I/O Stream class.
108
 * @details This class implements an base sequential stream.
109
 * @todo    So far only output but no input is supported.
110
 */
111
struct aos_ostream {
112
  const struct AosIOStreamVMT* vmt;
113
  _aos_iostream_data
114
};
115

  
116
#ifdef __cplusplus
117
extern "C" {
118
#endif
119
  void aosIOStreamInit(AosIOStream* stream);
120
  void aosIOChannelInit(AosIOChannel* channel, BaseAsynchronousChannel* asyncchannel);
121
  void aosIOStreamAddChannel(AosIOStream* stream, AosIOChannel* channel);
122
  aos_status_t aosIOStreamRemoveChannel(AosIOStream* stream, AosIOChannel* channel);
123
  void aosIOChannelOutputEnable(AosIOChannel* channel);
124
  void aosIOChannelOutputDisable(AosIOChannel* channel);
125
#ifdef __cplusplus
126
}
127
#endif
128

  
129
#endif /* _AMIROOS_IOSTREAM_H_ */
os/core/inc/aos_shell.h
19 19
#ifndef _AMIROOS_SHELL_H_
20 20
#define _AMIROOS_SHELL_H_
21 21

  
22
#include <aosconf.h>
23
#if (AMIROOS_CFG_SHELL_ENABLE == true)
24

  
22 25
#include <hal.h>
23 26
#include <aos_types.h>
27
#include <aos_iostream.h>
24 28

  
25 29
/**
26 30
 * @brief   Shell event flag that is emitted when the thread starts.
27 31
 */
28
#define AOS_SHELL_EVTFLAG_START                 ((eventflags_t)(1 << 0))
32
#define AOS_SHELL_EVTFLAG_START                   ((eventflags_t)(1 << 0))
29 33

  
30 34
/**
31 35
 * @brief   Shell event flag that is emitted when a command is executed.
32 36
 */
33
#define AOS_SHELL_EVTFLAG_EXEC                  ((eventflags_t)(1 << 1))
37
#define AOS_SHELL_EVTFLAG_EXEC                    ((eventflags_t)(1 << 1))
34 38

  
35 39
/**
36 40
 * @brief   Shell event flag that is emitted when a command execution finished.
37 41
 */
38
#define AOS_SHELL_EVTFLAG_DONE                  ((eventflags_t)(1 << 2))
42
#define AOS_SHELL_EVTFLAG_DONE                    ((eventflags_t)(1 << 2))
39 43

  
40 44
/**
41 45
 * @brief   Shell event flag that is emitted when the shread stops.
42 46
 */
43
#define AOS_SHELL_EVTFLAG_EXIT                  ((eventflags_t)(1 << 3))
47
#define AOS_SHELL_EVTFLAG_EXIT                    ((eventflags_t)(1 << 3))
44 48

  
45 49
/**
46 50
 * @brief   Shell event flag that is emitted when an I/O error occurred.
47 51
 */
48
#define AOS_SHELL_EVTFLAG_IOERROR               ((eventflags_t)(1 << 4))
52
#define AOS_SHELL_EVTFLAG_IOERROR                 ((eventflags_t)(1 << 4))
49 53

  
50 54
/**
51 55
 * @brief   Shell input configuration for replacing content by user input.
52 56
 */
53
#define AOS_SHELL_CONFIG_INPUT_OVERWRITE        (1 << 0)
57
#define AOS_SHELL_CONFIG_INPUT_OVERWRITE          (1 << 0)
54 58

  
55 59
/**
56 60
 * @brief   Shell prompt configuration print a minimalistic prompt.
57 61
 */
58
#define AOS_SHELL_CONFIG_PROMPT_MINIMAL         (1 << 1)
62
#define AOS_SHELL_CONFIG_PROMPT_MINIMAL           (1 << 1)
59 63

  
60 64
/**
61 65
 * @brief   Shell prompt configuration to additionally print the system uptime with the prompt.
62 66
 */
63
#define AOS_SHELL_CONFIG_PROMPT_UPTIME          (1 << 2)
67
#define AOS_SHELL_CONFIG_PROMPT_UPTIME            (1 << 2)
64 68

  
65 69
/**
66 70
 * @brief   Shell prompt configuration to additionally print the system uptime with the prompt.
67 71
 */
68
#define AOS_SHELL_CONFIG_MATCH_CASE             (1 << 3)
72
#define AOS_SHELL_CONFIG_MATCH_CASE               (1 << 3)
73

  
74
/**
75
 * @brief   Shell I/O channel flag whether the channel is attached to a list.
76
 */
77
#define AOS_SHELLCHANNEL_ATTACHED                 (1 << 0)
78

  
79
/**
80
 * @brief   Shell I/O channel flag whether the channel is enabled as input.
81
 */
82
#define AOS_SHELLCHANNEL_INPUT_ENABLED            (1 << 1)
83

  
84
/**
85
 * @brief   Shell I/O channel flag whether the channel is enabled as output.
86
 */
87
#define AOS_SHELLCHANNEL_OUTPUT_ENABLED           (1 << 2)
88

  
89
/*
90
 * forward definitions
91
 */
92
typedef struct aos_shellchannel AosShellChannel;
93
typedef struct aos_shellstream AosShellStream;
94

  
95
/**
96
 * @brief   AosShellChannel specific methods.
97
 */
98
#define _aos_shell_channel_methods                                          \
99
  _base_asynchronous_channel_methods
100

  
101
/**
102
 * @brief   AosShellChannel specific data.
103
 */
104
#define _aos_shell_channel_data                                             \
105
  /* pointer to a AosIOChannel object */                                    \
106
  AosIOChannel* iochannel;                                                  \
107
  /* event listener for the associated BaseAsynchronousChannel */           \
108
  event_listener_t listener;                                                \
109
  /* pointer to the next chennal in a AosShellStream */                     \
110
  AosShellChannel* next;                                                    \
111
  /* flags related to the channel */                                        \
112
  uint8_t flags;
113

  
114
/**
115
 * @extends BaseAsynchronousChannelVMT
116
 *
117
 * @brief   AosShellChannel virtual methods table.
118
 */
119
struct AosShellChannelVMT {
120
  _aos_shell_channel_methods
121
};
122

  
123
/**
124
 * @extends BaseAsynchronousChannel
125
 *
126
 * @brief   Shell channel class.
127
 * @details This class implements an asynchronous I/O channel.
128
 */
129
struct aos_shellchannel {
130
  /** @brief Virtual Methods Table. */
131
  const struct AosShellChannelVMT* vmt;
132
  _aos_shell_channel_data
133
};
134

  
135
/**
136
 * @brief   AosShellStream methods.
137
 */
138
#define _aos_shellstream_methods                                            \
139
  _base_sequential_stream_methods
140

  
141
/**
142
 * @brief   AosShellStream data.
143
 */
144
#define _aos_shellstream_data                                               \
145
  /* Pointer to the first channel in a list. */                             \
146
  AosShellChannel* channel;
147

  
148
/**
149
 * @extends BaseSequentialStream
150
 *
151
 * @brief   AosShellStream virtual methods table.
152
 */
153
struct AosShellStreamVMT {
154
  _aos_shellstream_methods
155
};
156

  
157
/**
158
 * @extends BaseSequentialStream
159
 *
160
 * @brief   Shell Stream class.
161
 * @details This class implements an base sequential stream.
162
 * @todo    So far only output but no input is supported.
163
 */
164
struct aos_shellstream {
165
  const struct AosShellStreamVMT* vmt;
166
  _aos_shellstream_data
167
};
69 168

  
70 169
/**
71 170
 * @brief   Shell command calback type.
......
90 189
   * @brief   Pointer to next command in a singly linked list.
91 190
   */
92 191
  struct aos_shellcommand* next;
192

  
93 193
} aos_shellcommand_t;
94 194

  
95 195
/**
96 196
 * @brief   Execution status of a shell command.
97 197
 */
98 198
typedef struct aos_shellexecstatus {
99
  aos_shellcommand_t* command;  /**< Pointer to the command that was executed. */
100
  int retval;                   /**< Return value of the executed command. */
199
  /**
200
   * @brief   Pointer to the command that was executed.
201
   */
202
  aos_shellcommand_t* command;
203

  
204
  /**
205
   * @brief   Return value of the executed command.
206
   */
207
  int retval;
101 208
} aos_shellexecstatus_t;
102 209

  
103 210
/**
211
 * @brief   Enumerator to encode shell actions.
212
 */
213
typedef enum aos_shellaction {
214
  AOS_SHELL_ACTION_READCHAR,
215
  AOS_SHELL_ACTION_AUTOFILL,
216
  AOS_SHELL_ACTION_SUGGEST,
217
  AOS_SHELL_ACTION_INSERTTOGGLE,
218
  AOS_SHELL_ACTION_DELETEFORWARD,
219
  AOS_SHELL_ACTION_DELETEBACKWARD,
220
  AOS_SHELL_ACTION_RECALLLAST,
221
  AOS_SHELL_ACTION_CLEAR,
222
  AOS_SHELL_ACTION_CURSOR2START,
223
  AOS_SHELL_ACTION_CURSOR2END,
224
  AOS_SHELL_ACTION_CURSORLEFT,
225
  AOS_SHELL_ACTION_CURSORRIGHT,
226
  AOS_SHELL_ACTION_EXECUTE,
227
  AOS_SHELL_ACTION_ESCSTART,
228
  AOS_SHELL_ACTION_NONE,
229
} aos_shellaction_t;
230

  
231
/**
104 232
 * @brief   Shell structure.
105 233
 */
106 234
typedef struct aos_shell {
......
115 243
  event_source_t eventSource;
116 244

  
117 245
  /**
118
   * @brief   Stream for user I/O.
246
   * @brief   Struct for OS related events
119 247
   */
120
  BaseSequentialStream* stream;
248
  struct {
249
    /**
250
     * @brief   Pointer to the OS' event source.
251
     */
252
    event_source_t* eventSource;
253

  
254
    /**
255
     * @brief   Listener for OS related events.
256
     */
257
    event_listener_t eventListener;
258
  } os;
259

  
260
  /**
261
     * @brief   Pointer to the first I/O channel.
262
     */
263
  AosShellStream stream;
121 264

  
122 265
  /**
123 266
   * @brief   String to printed as prompt.
......
146 289
  size_t linesize;
147 290

  
148 291
  /**
292
   * @brief   Structure containing data for internal input parsing.
293
   */
294
  struct {
295
    /**
296
     * @brief   The last action executed by the shell.
297
     */
298
    aos_shellaction_t lastaction;
299

  
300
    /**
301
     * @brief   Number of character in the current escape sequence.
302
     */
303
    uint8_t escp;
304

  
305
    /**
306
     * @brief   Buffer to store an escape sequence.
307
     */
308
    char escseq[5];
309

  
310
    /**
311
     * @brief   Current curso position.
312
     */
313
    size_t cursorpos;
314

  
315
    /**
316
     * @brief   Current line width.
317
     */
318
    size_t lineend;
319

  
320
    /**
321
     * @brief   Flag whether there was input since the prompt was printed the last time.
322
     */
323
    bool noinput;
324
  } inputdata;
325

  
326
  /**
149 327
   * @brief   Argument buffer.
150 328
   */
151 329
  char** arglist;
......
164 342
#ifdef __cplusplus
165 343
extern "C" {
166 344
#endif
167
  void aosShellInit(aos_shell_t* shell, BaseSequentialStream* stream, const char* prompt, char* line, size_t linesize, char** arglist, size_t arglistsize);
345
  void aosShellInit(aos_shell_t* shell, event_source_t* oseventsource, const char* prompt, char* line, size_t linesize, char** arglist, size_t arglistsize);
346
  void aosShellStreamInit(AosShellStream* stream);
347
  void aosShellChannelInit(AosShellChannel* channel, AosIOChannel* iochannel);
168 348
  aos_status_t aosShellAddCommand(aos_shell_t* shell, aos_shellcommand_t* cmd);
169 349
  aos_status_t aosShellRemoveCommand(aos_shell_t* shell, char* cmd, aos_shellcommand_t** removed);
350
  void aosShellStreamAddChannel(AosShellStream* stream, AosShellChannel* channel);
351
  aos_status_t aosShellStreamRemoveChannel(AosShellStream* stream, AosShellChannel* channel);
352
  void aosShellChannelInputEnable(AosShellChannel* channel);
353
  void aosShellChannelInputDisable( AosShellChannel* channel);
354
  void aosShellChannelOutputEnable(AosShellChannel* channel);
355
  void aosShellChannelOutputDisable(AosShellChannel* channel);
170 356
  THD_FUNCTION(aosShellThread, shell);
171 357
#ifdef __cplusplus
172 358
}
173 359
#endif
174 360

  
361
#endif /* AMIROOS_CFG_SHELL_ENABLE == true */
362

  
175 363
#endif /* _AMIROOS_SHELL_H_ */
os/core/inc/aos_ssm.h
1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

  
15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
19
#ifndef _AMIROOS_SSM_H_
20
#define _AMIROOS_SSM_H_
21

  
22
#include <hal.h>
23
#include <aos_types.h>
24
#include <aos_debug.h>
25

  
26
/**
27
 * @brief   Sequential Stream Multiplexer output structure.
28
 */
29
typedef struct ssm_output {
30
  /**
31
   * @brief   Pointer to a BaseSequentialStream object.
32
   */