integrate C/LDFLAGS into LunaBuild flow
[lunaix-os.git] / lunaix-os / includes / hal / term.h
1 #ifndef __LUNAIX_TERM_H
2 #define __LUNAIX_TERM_H
3
4 #include <lunaix/device.h>
5 #include <lunaix/ds/rbuffer.h>
6 #include <lunaix/signal_defs.h>
7
8 #include <usr/lunaix/term.h>
9
10 struct term;
11
12 struct linebuffer
13 {
14     struct rbuffer* next;
15     struct rbuffer* current;
16     short sflags;
17     short sz_hlf;
18 };
19 #define LSTATE_EOL (1)
20 #define LSTATE_EOF (1 << 1)
21 #define LSTATE_SIGRAISE (1 << 2)
22
23 typedef struct rbuffer** lbuf_ref_t;
24 #define ref_current(lbuf) (&(lbuf)->current)
25 #define ref_next(lbuf) (&(lbuf)->next)
26 #define deref(bref) (*(bref))
27
28 struct term_lcntl
29 {
30     struct term* term;
31     int (*process_and_put)(struct term*, struct linebuffer*, char);
32 };
33
34 /**
35  * @brief Communication port capability that a device is supported natively, 
36  *          or able to emulate low level serial transmission behaviour specify 
37  *          by POSIX1-2008, section 11.
38  * 
39  */
40 #define TERMPORT_CAP 0x4d524554U
41
42 /**
43  * @brief A termios capability that a device provide interfaces which is 
44  *          compliant to POSIX1-2008
45  * 
46  */
47 #define TERMIOS_CAP 0x534f4954U
48
49 struct termport_capability
50 {
51     CAPABILITY_META;
52
53     void (*set_speed)(struct device*, speed_t);
54     void (*set_cntrl_mode)(struct device*, tcflag_t);
55 };
56
57 struct term
58 {
59     struct device* dev;
60     struct device* chdev;
61     struct term_lcntl* lcntl;
62     struct linebuffer line_out;
63     struct linebuffer line_in;
64     char* scratch_pad;
65     pid_t fggrp;
66
67     struct termport_capability* tp_cap;
68
69     /* -- POSIX.1-2008 compliant fields -- */
70     tcflag_t iflags;
71     tcflag_t oflags;
72     tcflag_t lflags;
73     tcflag_t cflags;
74     cc_t cc[_NCCS];
75     speed_t iospeed;
76 };
77
78 extern struct device* sysconsole;
79
80 struct term*
81 term_create(struct device* chardev, char* suffix);
82
83 int
84 term_bind(struct term* tdev, struct device* chdev);
85
86 int
87 term_push_lcntl(struct term* tdev, struct term_lcntl* lcntl);
88
89 int
90 term_pop_lcntl(struct term* tdev);
91
92 struct term_lcntl*
93 term_get_lcntl(u32_t lcntl_index);
94
95 static inline void
96 line_flip(struct linebuffer* lbf)
97 {
98     struct rbuffer* tmp = lbf->current;
99     lbf->current = lbf->next;
100     lbf->next = tmp;
101 }
102
103 void
104 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
105
106 void
107 line_free(struct linebuffer* lbf, size_t sz_hlf);
108
109 void
110 term_sendsig(struct term* tdev, int signal);
111
112 int
113 term_flush(struct term* tdev);
114
115 int
116 term_read(struct term* tdev);
117
118 int
119 lcntl_transform_inseq(struct term* tdev);
120
121 int
122 lcntl_transform_outseq(struct term* tdev);
123
124 #endif /* __LUNAIX_TERM_H */