aboutsummaryrefslogtreecommitdiff
path: root/src/twi.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/twi.spec.ts22
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);
+ });
+});