Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/misoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fb22edc
Choose a base ref
...
head repository: m-labs/misoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ef0667d
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Feb 7, 2012

  1. uart: RX support

    Sebastien Bourdeauducq committed Feb 7, 2012
    Copy the full SHA
    506ffab View commit details
  2. software: UART RX demo

    Sebastien Bourdeauducq committed Feb 7, 2012
    Copy the full SHA
    ef0667d View commit details
Showing with 57 additions and 4 deletions.
  1. +51 −3 milkymist/uart/__init__.py
  2. +6 −1 software/bios/main.c
54 changes: 51 additions & 3 deletions milkymist/uart/__init__.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,8 @@ def __init__(self, address, clk_freq, baud=115200):
self._divisor = RegisterField("divisor", 16, reset=int(clk_freq/baud/16))

self._tx_event = EventSourceLevel()
self.events = EventManager(self._tx_event)
self._rx_event = EventSourcePulse()
self.events = EventManager(self._tx_event, self._rx_event)
self.bank = csrgen.Bank([self._rxtx, self._divisor] + self.events.get_registers(),
address=address)

@@ -28,10 +29,11 @@ def get_fragment(self):
enable16_counter.eq(self._divisor.field.r - 1))
]

# TX
tx_reg = Signal(BV(8))
tx_bitcount = Signal(BV(4))
tx_count16 = Signal(BV(4))
tx_busy = Signal()
tx_busy = self._tx_event.trigger
sync += [
If(self._rxtx.re,
tx_reg.eq(self._rxtx.r),
@@ -55,7 +57,53 @@ def get_fragment(self):
)
)
]
comb.append(self._tx_event.trigger.eq(tx_busy))

# RX
rx0 = Signal() # sychronize
rx = Signal()
sync += [
rx0.eq(self.rx),
rx.eq(rx0)
]
rx_r = Signal()
rx_reg = Signal(BV(8))
rx_bitcount = Signal(BV(4))
rx_count16 = Signal(BV(4))
rx_busy = Signal()
rx_done = self._rx_event.trigger
rx_data = self._rxtx.w
sync += [
rx_done.eq(0),
If(enable16,
rx_r.eq(rx),
If(~rx_busy,
If(~rx & rx_r, # look for start bit
rx_busy.eq(1),
rx_count16.eq(7),
rx_bitcount.eq(0)
)
).Else(
rx_count16.eq(rx_count16 + 1),
If(rx_count16 == 0,
rx_bitcount.eq(rx_bitcount + 1),

If(rx_bitcount == 0,
If(rx, # verify start bit
rx_busy.eq(0)
)
).Elif(rx_bitcount == 9,
rx_busy.eq(0),
If(rx, # verify stop bit
rx_data.eq(rx_reg),
rx_done.eq(1)
)
).Else(
rx_reg.eq(Cat(rx_reg[1:], rx))
)
)
)
)
]

return self.bank.get_fragment() \
+ self.events.get_fragment() \
7 changes: 6 additions & 1 deletion software/bios/main.c
Original file line number Diff line number Diff line change
@@ -4,11 +4,16 @@

int main(void)
{
char c;

irq_setmask(0);
irq_setie(1);
uart_init();

printf("Hello World with IRQs\n");

while(1);
while(1) {
c = uart_read();
printf("You typed: %c\n", c);
}
}