1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00
myhdl/example/rs232/rs232_rx.py
2003-01-30 22:17:15 +00:00

32 lines
677 B
Python

from __future__ import generators
from myhdl import delay, posedge, intbv, downrange
from rs232_util import sec, parity, ParityError, StopBitError
def rs232_rx(rx, actual, cfg):
data = intbv(0)
period = int(1*sec / cfg.baud_rate)
yield posedge(rx)
yield delay(period / 2)
data[7] = 0
for i in downrange(cfg.n_bits):
yield delay(period)
data[i] = rx.val
if cfg.parity is not None:
yield delay(period)
if rx.val != parity(data, cfg.parity):
raise ParityError
yield delay(period)
if rx.val != 0:
raise StopBitError
actual[8:] = data