void _serial_fini(void) { int delay = _clkfreq/2; int waitcycles = _CNT + delay; /* sleep a bit to let things drain */ waitcycles = __builtin_propeller_waitcnt(waitcycles, delay); /* send a break */ _OUTA = 0; __builtin_propeller_waitcnt(waitcycles, delay); }
int _serial_tx(int c, unsigned int txmask, unsigned int bitcycles) { unsigned int waitcycles; int i, value; /* set output */ _OUTA |= txmask; _DIRA |= txmask; value = (c | 256) << 1; waitcycles = getcnt() + bitcycles; for (i = 0; i < 10; i++) { waitcycles = __builtin_propeller_waitcnt(waitcycles, bitcycles); if (value & 1) _OUTA |= txmask; else _OUTA &= ~txmask; value >>= 1; } // if we turn off DIRA, then some boards (like QuickStart) are left with // floating pins and garbage output; if we leave it on, we're left with // a high pin and other cogs cannot produce output on it // the solution is to use FullDuplexSerialDriver instead on applications // with multiple cogs //_DIRA &= ~txmask; return c; }
int __attribute__((section(".hubtext"))) _serial_tx(int value) { int i; int txpin = _txpin; int bitcycles = _bitcycles; int waitcycles = _CNT + bitcycles; value = (value | 256) << 1; for (i = 0; i < 10; i++) { waitcycles = __builtin_propeller_waitcnt(waitcycles, bitcycles); _OUTA = (value & 1) << txpin; value >>= 1; } return 1; }