1 #ifndef libpropeller_full_duplex_serial_h_
2 #define libpropeller_full_duplex_serial_h_
8 static inline int Rotl__(
unsigned int a,
unsigned int b) {
9 return (a << b) | (a >> (32 -
b));
12 static inline int Lookup__(
int x,
int b,
int a[],
int n) {
14 return ((
unsigned) i >= n) ? 0 : (a)[i];
21 #define buffersize 256
22 #define buffermask (buffersize - 1)
56 void Start(
int Rxpin,
int Txpin,
int Mode,
int Baudrate) {
57 volatile void * asm_reference = NULL;
58 __asm__
volatile (
"mov %[asm_reference], #FullDuplexSerial_Entry \n\t"
59 : [asm_reference]
"+r" (asm_reference));
73 Bit_ticks = (CLKFREQ / Baudrate);
74 Buffer_ptr = Rx_buffer;
76 Cog = cognew(_load_start_full_duplex_serial_cog, &Rx_head) + 1;
106 while (CheckBuffer() >= 0) {
119 int Get(
const int timeout = -1) {
122 while ((Rxbyte = CheckBuffer()) < 0) {
126 while (!(((Rxbyte = CheckBuffer()) >= 0)
127 || (((CNT - T) / (CLKFREQ / 1000)) > timeout))) {
137 void Put(
const char Txbyte) {
138 while (!(Tx_tail != ((Tx_head + 1) &
buffermask))) {
140 Tx_buffer[Tx_head] = Txbyte;
142 if (Rxtx_mode & 0x8) {
153 void Put(
const char *
string) {
154 const int length = strlen(
string);
155 for (
int i = 0; i < length; i++) {
177 if (Value == (
int) 0x80000000U) {
187 for (_idx__0043 = 1; _idx__0043 <= 10; (_idx__0043 = (_idx__0043 + 1))) {
189 Put((((Value / I) +
'0')));
193 if ((result) || (I == 1)) {
204 void PutHex(
int Value,
int Digits) {
205 static int look__0044[] = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70,};
207 Value = (Value << ((8 - Digits) << 2));
210 int _limit__0046 = Digits;
211 for (_idx__0045 = 1; _idx__0045 <= _limit__0046; (_idx__0045 = (_idx__0045 + 1))) {
212 Put(Lookup__(((Value = (Rotl__(Value, 4))) & 0xf), 0, look__0044, 16));
217 void PutBin(
int Value,
int Digits) {
218 Value = (Value << (32 - Digits));
221 int _limit__0048 = Digits;
222 for (_idx__0047 = 1; _idx__0047 <= _limit__0048; (_idx__0047 = (_idx__0047 + 1))) {
223 Put((((Value = (Rotl__(Value, 1))) & 0x1) +
'0'));
232 volatile int Rx_head;
233 volatile int Rx_tail;
234 volatile int Tx_head;
235 volatile int Tx_tail;
238 volatile int Rxtx_mode;
239 volatile int Bit_ticks;
240 volatile char * Buffer_ptr;
244 int CheckBuffer(
void) {
246 if (Rx_tail != Rx_head) {
247 Rxbyte = Rx_buffer[Rx_tail];
254 #endif // libpropeller_full_duplex_serial_h_