diff options
| author | Uri Shaked | 2020-01-30 20:21:31 +0200 |
|---|---|---|
| committer | Uri Shaked | 2020-01-30 20:21:31 +0200 |
| commit | 1a64241f92251f3ed16ae54afd020a416565bf74 (patch) | |
| tree | 67c888ef7352d9d257591f642346ad9d3f382006 /src/twi.spec.ts | |
| parent | chore: release 0.5.2 (diff) | |
| download | avr8js-1a64241f92251f3ed16ae54afd020a416565bf74.tar.gz avr8js-1a64241f92251f3ed16ae54afd020a416565bf74.tar.bz2 avr8js-1a64241f92251f3ed16ae54afd020a416565bf74.zip | |
feat(twi): partial TWI master implementation #10
Diffstat (limited to 'src/twi.spec.ts')
| -rw-r--r-- | src/twi.spec.ts | 22 |
1 files changed, 22 insertions, 0 deletions
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); + }); +}); |
