PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
simple
fdserial_utils.c
1
8
#include <propeller.h>
9
#include "fdserial.h"
10
11
/*
12
* rxflush empties the receive queue
13
*/
14
void
fdserial_rxFlush(
fdserial
*term)
15
{
16
while
(fdserial_rxCheck(term) >= 0)
17
;
// clear out queue by receiving all available
18
}
19
20
/*
21
* Check if a byte is available in the buffer.
22
* Function does not block.
23
* @returns non-zero if a byte is available.
24
*/
25
int
fdserial_rxReady(
fdserial
*term)
26
{
27
volatile
fdserial_st
* fdp = (
fdserial_st
*) term->
devst
;
28
return (fdp->
rx_tail
!= fdp->
rx_head
);
29
}
30
31
/*
32
* Get a byte from the receive queue if available within timeout period.
33
* Function blocks if no recieve for ms timeout.
34
* @param ms is number of milliseconds to wait for a char
35
* @returns receive byte 0 to 0xff or -1 if none available
36
*/
37
int
fdserial_rxTime(
fdserial
*term,
int
ms)
38
{
39
int
rc = -1;
40
int
t1 = 0;
41
int
t0 = CNT;
42
do
{
43
rc = fdserial_rxCheck(term);
44
t1 = CNT;
45
if
((t1 - t0)/(CLKFREQ/1000) > ms)
46
break
;
47
}
while
(rc < 0);
48
return
rc;
49
}
50
51
void
fdserial_txFlush(
fdserial
*term)
52
{
53
while
(!fdserial_txEmpty(term));
54
}
55
56
/*
57
* Get a byte from the receive buffer without changing the pointers.
58
* The function does not block.
59
* returns non-zero if a valid byte is available.
60
*/
61
int
fdserial_rxPeek(
fdserial
*term)
62
{
63
int
rc = 0;
64
volatile
fdserial_st
* fdp = (
fdserial_st
*) term->
devst
;
65
volatile
char
* rxbuf = (
volatile
char
*) fdp->
buffptr
;
// rx buff starts at offset 0
66
67
if
(fdp->
rx_tail
!= fdp->
rx_head
) {
68
rc = rxbuf[fdp->
rx_tail
];
69
}
70
return
rc;
71
}
72
73
/*
74
* Get number of bytes available in the receive buffer.
75
* Queue overflows can not be detected.
76
* The function does not block.
77
* returns less than 1 if no bytes are available.
78
*/
79
int
fdserial_rxCount(
fdserial
*term)
80
{
81
int
rc = 0;
82
volatile
fdserial_st
* fdp = (
fdserial_st
*) term->
devst
;
83
volatile
char
* rxbuf = (
volatile
char
*) fdp->
buffptr
;
// rx buff starts at offset 0
84
85
if
(fdp->
rx_tail
== fdp->
rx_head
) {
86
rc = 0;
87
}
88
else
{
89
if
(fdp->
rx_head
> fdp->
rx_tail
) {
90
rc = fdp->
rx_head
- fdp->
rx_tail
;
91
}
92
else
{
93
// [.....H.........T....]
94
rc = FDSERIAL_BUFF_MASK+1;
95
rc -= fdp->
rx_tail
;
// buffer size - tail mark
96
rc += fdp->
rx_head
;
// plus head mark
97
}
98
}
99
return
rc;
100
}
101
102
/*
103
+--------------------------------------------------------------------
104
| TERMS OF USE: MIT License
105
+--------------------------------------------------------------------
106
Permission is hereby granted, free of charge, to any person obtaining
107
a copy of this software and associated documentation files
108
(the "Software"), to deal in the Software without restriction,
109
including without limitation the rights to use, copy, modify, merge,
110
publish, distribute, sublicense, and/or sell copies of the Software,
111
and to permit persons to whom the Software is furnished to do so,
112
subject to the following conditions:
113
114
The above copyright notice and this permission notice shall be
115
included in all copies or substantial portions of the Software.
116
117
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
118
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
119
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
120
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
121
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
122
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
123
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
124
+--------------------------------------------------------------------
125
*/
126
text_struct::devst
volatile void * devst
Definition:
simpletext.h:79
fdserial_struct
Defines fdserial interface structure of 9 contiguous longs + buffers.
Definition:
fdserial.h:85
fdserial_struct::rx_head
int rx_head
Definition:
fdserial.h:87
fdserial_struct::buffptr
char * buffptr
Definition:
fdserial.h:95
text_struct
Structure that contains data used by simple text device libraries.
Definition:
simpletext.h:70
fdserial_struct::rx_tail
int rx_tail
Definition:
fdserial.h:88
Generated on Sat Aug 27 2016 00:58:09 for PropWare by
1.8.12