VCOM Linux Driver
Advantech Inc.
Loading...
Searching...
No Matches
advvcom.h
Go to the documentation of this file.
1#include "advtype.h"
2
3#ifndef _ADVVCOM_H
4#define _ADVVCOM_H
5
6#define ADV_RING_BUF_ENABLED 1
7#define ADV_RING_BUF_CLEAN 2
8
9#define ADV_ATTRBUF_NUM 2
10
11#ifdef __USER_SPACE_IF
12
13struct ring_buf{
14 int head;
15 int tail;
16 int begin;
17 int size;
18 char * mbase;
19};
20#else
21
22#include "advconf.h"
23//#define VCOM_PORTS 10
24
25struct ring_buf{
26 spinlock_t lock;
27 int head;
28 int tail;
29 int begin;
30 int size;
31 unsigned int status;
32 wait_queue_head_t wait;
33 void * data;
34};
35
36
37
39 spinlock_t lock;
41 unsigned int mctrl; /*for input pins only*/
43 wait_queue_head_t wait;
44 int index;
46 int size;
47 int begin;
49 void * data;
50};
51
52struct adv_vcom{
53 struct uart_port * adv_uart;
55 struct ring_buf tx;
56 struct ring_buf rx;
57 struct proc_dir_entry * entry;
59};
60
61static inline int flush_attr_info(struct adv_port_att * attr)
62{
63 struct adv_port_info * usr_base = attr->data;
64
65 if(attr->_newbie){
66 attr->_newbie = 0;
67 }else{
68 attr->usr_ptr = (attr->usr_ptr + 1) % ADV_ATTRBUF_NUM;
69 }
70
71 memcpy(&usr_base[attr->usr_ptr], &attr->_attr, sizeof(struct adv_port_info));
72
73 return (attr->usr_ptr);
74}
75
76static inline int move_rb_head(struct ring_buf * buf, int length)
77{
78 if(buf->status & ADV_RING_BUF_CLEAN){
79 buf->status &= (~ADV_RING_BUF_CLEAN);
80 buf->head = buf->tail;
81 }else{
82 buf->head += length;
83 buf->head %= (buf->size);
84 }
85
86 return 0;
87}
88
89static inline int move_rb_tail(struct ring_buf * buf, int length)
90{
91 buf->tail += length;
92 buf->tail %= (buf->size);
93
94 return 0;
95}
96
97#endif
98
99static inline int is_rb_empty(struct ring_buf buf)
100{
101 return (buf.tail == buf.head);
102}
103
104static inline int get_rb_length(struct ring_buf buf)
105{
106 return (buf.tail >= buf.head)?(buf.tail - buf.head ):(buf.size - buf.head + buf.tail);
107}
108
109static inline int get_rb_llength(struct ring_buf buf)
110{
111 int a = buf.size - buf.head;
112 int b = get_rb_length(buf);
113
114 return (a < b)?a:b;
115}
116
117static inline int get_rb_room(struct ring_buf buf)
118{
119 return buf.size - get_rb_length(buf) - 1;
120}
121
122static inline int get_rb_lroom(struct ring_buf buf)
123{
124 int a = (buf.size - buf.tail);
125 int b = get_rb_room(buf);
126 return a < b?a:b;
127}
128
129static inline int get_rb_tail(struct ring_buf buf)
130{
131 return buf.tail;
132}
133
134static inline int get_rb_head(struct ring_buf buf)
135{
136 return buf.head;
137}
138
139#endif
140
#define ADV_RING_BUF_CLEAN
Definition advvcom.h:7
#define ADV_ATTRBUF_NUM
Definition advvcom.h:9
Definition advvcom.h:38
struct adv_port_info _attr
Definition advvcom.h:40
int size
Definition advvcom.h:46
void * data
Definition advvcom.h:49
int index
Definition advvcom.h:44
spinlock_t lock
Definition advvcom.h:39
int _newbie
Definition advvcom.h:42
int begin
Definition advvcom.h:47
wait_queue_head_t wait
Definition advvcom.h:43
int usr_ptr
Definition advvcom.h:48
int throttled
Definition advvcom.h:45
unsigned int mctrl
Definition advvcom.h:41
Definition advtype.h:31
Definition advvcom.h:52
struct list_head list
Definition advvcom.h:58
struct proc_dir_entry * entry
Definition advvcom.h:57
struct uart_port * adv_uart
Definition advvcom.h:53
struct adv_port_att attr
Definition advvcom.h:54
struct ring_buf rx
Definition advvcom.h:56
struct ring_buf tx
Definition advvcom.h:55
Definition advlist.h:4
Definition advvcom.h:25
int head
Definition advvcom.h:27
int size
Definition advvcom.h:30
void * data
Definition advvcom.h:33
spinlock_t lock
Definition advvcom.h:26
int begin
Definition advvcom.h:29
wait_queue_head_t wait
Definition advvcom.h:32
unsigned int status
Definition advvcom.h:31
int tail
Definition advvcom.h:28