From 1a64241f92251f3ed16ae54afd020a416565bf74 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Thu, 30 Jan 2020 20:21:31 +0200 Subject: feat(twi): partial TWI master implementation #10 --- src/twi.spec.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/twi.spec.ts (limited to 'src/twi.spec.ts') diff --git a/src/twi.spec.ts b/src/twi.spec.ts new file mode 100644 index 0000000..dacd958 --- /dev/null +++ b/src/twi.spec.ts @@ -0,0 +1,22 @@ +import { CPU } from './cpu'; +import { AVRTWI, twiConfig } from './twi'; + +const FREQ_16MHZ = 16e6; + +describe('TWI', () => { + it('should correctly calculate the sclFrequency from TWBR', () => { + const cpu = new CPU(new Uint16Array(1024)); + const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); + cpu.writeData(0xb8, 0x48); // TWBR <- 0x48 + cpu.writeData(0xb9, 0); // TWSR <- 0 (prescaler: 1) + expect(twi.sclFrequency).toEqual(100000); + }); + + it('should take the prescaler into consideration when calculating sclFrequency', () => { + const cpu = new CPU(new Uint16Array(1024)); + const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); + cpu.writeData(0xb8, 0x03); // TWBR <- 0x03 + cpu.writeData(0xb9, 0x01); // TWSR <- 1 (prescaler: 4) + expect(twi.sclFrequency).toEqual(400000); + }); +}); -- cgit v1.2.3