-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this allows us to run the MicroPython REPL! 🐍 We still need to write some more tests, and implement the FIFO level interrupts correctly. Yet it's functional! close #41
- Loading branch information
Showing
5 changed files
with
203 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { RP2040 } from '../rp2040'; | ||
import { RPUART } from './uart'; | ||
|
||
const OFFSET_UARTLCR_H = 0x2c; | ||
|
||
describe('UART', () => { | ||
it('should correctly return wordLength based on UARTLCR_H value', () => { | ||
const rp2040 = new RP2040(); | ||
const uart = new RPUART(rp2040, 'UART', 0); | ||
uart.writeUint32(OFFSET_UARTLCR_H, 0x70); | ||
expect(uart.wordLength).toEqual(8); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FIFO } from './fifo'; | ||
|
||
describe('FIFO', () => { | ||
it('should successfully push and pull 4 items', () => { | ||
const fifo = new FIFO(3); | ||
expect(fifo.empty).toBe(true); | ||
fifo.push(1); | ||
expect(fifo.empty).toBe(false); | ||
fifo.push(2); | ||
expect(fifo.itemCount).toBe(2); | ||
expect(fifo.full).toBe(false); | ||
fifo.push(3); | ||
expect(fifo.full).toBe(true); | ||
expect(fifo.pull()).toBe(1); | ||
expect(fifo.full).toBe(false); | ||
fifo.push(4); | ||
expect(fifo.full).toBe(true); | ||
expect(fifo.pull()).toBe(2); | ||
expect(fifo.pull()).toBe(3); | ||
expect(fifo.empty).toBe(false); | ||
expect(fifo.itemCount).toBe(1); | ||
expect(fifo.pull()).toBe(4); | ||
expect(fifo.full).toBe(false); | ||
expect(fifo.empty).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export class FIFO { | ||
readonly buffer: Uint32Array; | ||
|
||
private start = 0; | ||
private used = 0; | ||
|
||
constructor(size: number) { | ||
this.buffer = new Uint32Array(size); | ||
} | ||
|
||
get size() { | ||
return this.buffer.length; | ||
} | ||
|
||
get itemCount() { | ||
return this.used; | ||
} | ||
|
||
push(value: number) { | ||
const { length } = this.buffer; | ||
const { start, used } = this; | ||
if (this.used < length) { | ||
this.buffer[(start + used) % length] = value; | ||
this.used++; | ||
} | ||
} | ||
|
||
pull() { | ||
const { start, used } = this; | ||
const { length } = this.buffer; | ||
if (used) { | ||
this.start = (start + 1) % length; | ||
this.used--; | ||
return this.buffer[start]; | ||
} | ||
return 0; | ||
} | ||
|
||
reset() { | ||
this.used = 0; | ||
} | ||
|
||
get empty() { | ||
return this.used == 0; | ||
} | ||
|
||
get full() { | ||
return this.used === this.buffer.length; | ||
} | ||
} |