1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00
myhdl/example/rs232/rs232_tx.py

37 lines
852 B
Python
Raw Normal View History

2003-01-30 12:20:43 +00:00
from __future__ import generators
import operator
from myhdl import Signal, downrange, delay, posedge
2003-01-30 22:17:15 +00:00
from rs232_util import reduceXor, sec, ODD, EVEN, MARK, SPACE
2003-01-30 12:20:43 +00:00
def rs232_tx(tx, data, cfg):
2003-01-30 13:57:30 +00:00
2003-01-30 12:20:43 +00:00
duration = delay(int(1*sec / cfg.baud_rate))
2003-01-30 13:57:30 +00:00
2003-01-30 12:20:43 +00:00
tx.next = 1
yield duration
2003-01-30 13:57:30 +00:00
2003-01-30 12:20:43 +00:00
for i in downrange(cfg.n_bits):
tx.next = data[i]
yield duration
2003-01-30 13:57:30 +00:00
2003-01-30 12:20:43 +00:00
if cfg.parity is not None:
if cfg.n_bits == 7:
data[7] = 0
if cfg.parity == ODD:
2003-01-30 22:17:15 +00:00
tx.next = not reduceXor(data[8:])
2003-01-30 12:20:43 +00:00
elif cfg.parity == EVEN:
2003-01-30 22:17:15 +00:00
tx.next = reduceXor(data[8:])
2003-01-30 12:20:43 +00:00
elif cfg.parity == MARK:
tx.next = 1
elif cfg.parity == SPACE:
tx.next = 0
yield duration
2003-01-30 13:57:30 +00:00
2003-01-30 12:20:43 +00:00
tx.next = 0
for i in range(cfg.n_stops):
yield duration