Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement core1 #112

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
190cba8
Implement TBMAN
mingpepe Nov 28, 2022
de3601f
Implement REF/SYS CTRL & SELECT for clock
mingpepe Nov 28, 2022
e7a222c
Define enum for cores
mingpepe Dec 12, 2022
dfbeaf0
Add API for peripheral to read from core
mingpepe Dec 12, 2022
aca3a9c
Define onSEV event to wakeup another core
mingpepe Dec 12, 2022
1b660e3
Define onBreak event for GDB
mingpepe Dec 12, 2022
c64c141
Implement read/write via core for ppb
mingpepe Dec 12, 2022
d5a1074
Implement FIFO registers in SIO
mingpepe Dec 12, 2022
a31e8fc
Define 2 cores in rp2040
mingpepe Dec 12, 2022
dc29d0c
Register onSEV event for each core
mingpepe Dec 12, 2022
efb7820
Implement NMI_MASK for syscfg
mingpepe Dec 12, 2022
dcc32ab
Modify debugger to debug only on core0
mingpepe Dec 12, 2022
26fb63f
Update unit test
mingpepe Dec 12, 2022
9b54d9d
Update test-utils
mingpepe Dec 12, 2022
b1b4560
Update demo code
mingpepe Dec 12, 2022
d12a4b5
Merge branch 'master' into core1
mingpepe Dec 12, 2022
4a0cf99
Let each core has its divider
mingpepe Dec 13, 2022
10ec3e6
Let each core has its interpolator
mingpepe Dec 13, 2022
fd563cd
Move fifo related logic to each core
mingpepe Dec 13, 2022
c9ab5ea
Do no need to pass core info to each core
mingpepe Dec 13, 2022
6f2da85
Add core info to warning message
mingpepe Dec 13, 2022
278bda7
Execute core0 and core1 interleaving
mingpepe Jan 30, 2023
26f77aa
Merge branch 'master' into core1
mingpepe Feb 6, 2023
1290137
Fix wrong merge
mingpepe Feb 6, 2023
9b55ad5
Run lint
mingpepe Feb 6, 2023
9bb7e7a
Fix error by lint
mingpepe Feb 6, 2023
23bf9d3
Rename variable
mingpepe Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Let each core has its divider
  • Loading branch information
mingpepe committed Dec 13, 2022
commit 4a0cf99bb3b65ec8ff53e573fcf47e4ba2e0d15f
104 changes: 104 additions & 0 deletions src/sio-core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { RP2040 } from './rp2040';
import { Core } from './core';

//HARDWARE DIVIDER
const DIV_UDIVIDEND = 0x060; // Divider unsigned dividend
const DIV_UDIVISOR = 0x064; // Divider unsigned divisor
const DIV_SDIVIDEND = 0x068; // Divider signed dividend
const DIV_SDIVISOR = 0x06c; // Divider signed divisor
const DIV_QUOTIENT = 0x070; // Divider result quotient
const DIV_REMAINDER = 0x074; //Divider result remainder
const DIV_CSR = 0x078;

export class RPSIOCore {
divDividend = 0;
divDivisor = 1;
divQuotient = 0;
divRemainder = 0;
divCSR = 0;

constructor(private readonly rp2040: RP2040) {

}

readUint32(offset: number) {
switch (offset) {
case DIV_UDIVIDEND:
return this.divDividend;
case DIV_SDIVIDEND:
return this.divDividend;
case DIV_UDIVISOR:
return this.divDivisor;
case DIV_SDIVISOR:
return this.divDivisor;
case DIV_QUOTIENT:
this.divCSR &= ~0b10;
return this.divQuotient;
case DIV_REMAINDER:
return this.divRemainder;
case DIV_CSR:
return this.divCSR;
default:
console.warn(`Read from invalid SIO address: ${offset.toString(16)}`);
return 0xffffffff;
}
}

writeUint32(offset: number, value: number, core: Core) {
switch (offset) {
case DIV_UDIVIDEND:
this.divDividend = value;
this.updateHardwareDivider(false, core);
break;
case DIV_SDIVIDEND:
this.divDividend = value;
this.updateHardwareDivider(true, core);
break;
case DIV_UDIVISOR:
this.divDivisor = value;
this.updateHardwareDivider(false, core);
break;
case DIV_SDIVISOR:
this.divDivisor = value;
this.updateHardwareDivider(true, core);
break;
case DIV_QUOTIENT:
this.divQuotient = value;
this.divCSR = 0b11;
break;
case DIV_REMAINDER:
this.divRemainder = value;
this.divCSR = 0b11;
break;
default:
console.warn(
`Write to invalid SIO address: ${offset.toString(16)}, value=${value.toString(16)}`
);
break;
}
}

private updateHardwareDivider(signed: boolean, core: Core) {
if (this.divDivisor == 0) {
this.divQuotient = this.divDividend > 0 ? -1 : 1;
this.divRemainder = this.divDividend;
} else {
if (signed) {
this.divQuotient = (this.divDividend | 0) / (this.divDivisor | 0);
this.divRemainder = (this.divDividend | 0) % (this.divDivisor | 0);
} else {
this.divQuotient = (this.divDividend >>> 0) / (this.divDivisor >>> 0);
this.divRemainder = (this.divDividend >>> 0) % (this.divDivisor >>> 0);
}
}
this.divCSR = 0b11;
switch (core) {
case Core.Core0:
this.rp2040.core0.cycles += 8;
break;
case Core.Core1:
this.rp2040.core1.cycles += 8;
break;
}
}
}
102 changes: 19 additions & 83 deletions src/sio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Interpolator } from './interpolator';
import { FIFO } from './utils/fifo';
import { Core } from './core';
import { IRQ } from './irq';
import { RPSIOCore } from './sio-core';

const CPUID = 0x000;
const FIFO_ST = 0x50;
Expand Down Expand Up @@ -31,15 +32,6 @@ const GPIO_HI_OE_XOR = 0x04c; // QSPI output enable XOR

const GPIO_MASK = 0x3fffffff;

//HARDWARE DIVIDER
const DIV_UDIVIDEND = 0x060; // Divider unsigned dividend
const DIV_UDIVISOR = 0x064; // Divider unsigned divisor
const DIV_SDIVIDEND = 0x068; // Divider signed dividend
const DIV_SDIVISOR = 0x06c; // Divider signed divisor
const DIV_QUOTIENT = 0x070; // Divider result quotient
const DIV_REMAINDER = 0x074; //Divider result remainder
const DIV_CSR = 0x078;

//INTERPOLATOR
const INTERP0_ACCUM0 = 0x080; // Read/write access to accumulator 0
const INTERP0_ACCUM1 = 0x084; // Read/write access to accumulator 1
Expand Down Expand Up @@ -89,11 +81,6 @@ export class RPSIO {
gpioOutputEnable = 0;
qspiGpioValue = 0;
qspiGpioOutputEnable = 0;
divDividend = 0;
divDivisor = 1;
divQuotient = 0;
divRemainder = 0;
divCSR = 0;
spinLock = 0;
interp0 = new Interpolator(0);
interp1 = new Interpolator(1);
Expand All @@ -106,35 +93,14 @@ export class RPSIO {
core0WOF = false;
core1ROE = false;
core1WOF = false;
readonly core0;
readonly core1;

constructor(private readonly rp2040: RP2040) {
this.core1TxFIFO = this.core0RxFIFO;
this.core1RxFIFO = this.core0TxFIFO;
}

updateHardwareDivider(signed: boolean, core: Core) {
if (this.divDivisor == 0) {
this.divQuotient = this.divDividend > 0 ? -1 : 1;
this.divRemainder = this.divDividend;
} else {
if (signed) {
this.divQuotient = (this.divDividend | 0) / (this.divDivisor | 0);
this.divRemainder = (this.divDividend | 0) % (this.divDivisor | 0);
} else {
this.divQuotient = (this.divDividend >>> 0) / (this.divDivisor >>> 0);
this.divRemainder = (this.divDividend >>> 0) % (this.divDivisor >>> 0);
}
}
this.divCSR = 0b11;
switch (core)
{
case Core.Core0:
this.rp2040.core0.cycles += 8;
break;
case Core.Core1:
this.rp2040.core1.cycles += 8;
break;
}
this.core0 = new RPSIOCore(rp2040);
this.core1 = new RPSIOCore(rp2040);
}

readUint32(offset: number, core: Core) {
Expand Down Expand Up @@ -238,21 +204,6 @@ export class RPSIO {
}
case SPINLOCK_ST:
return this.spinLock;
case DIV_UDIVIDEND:
return this.divDividend;
case DIV_SDIVIDEND:
return this.divDividend;
case DIV_UDIVISOR:
return this.divDivisor;
case DIV_SDIVISOR:
return this.divDivisor;
case DIV_QUOTIENT:
this.divCSR &= ~0b10;
return this.divQuotient;
case DIV_REMAINDER:
return this.divRemainder;
case DIV_CSR:
return this.divCSR;
case INTERP0_ACCUM0:
return this.interp0.accum0;
case INTERP0_ACCUM1:
Expand Down Expand Up @@ -332,8 +283,12 @@ export class RPSIO {
case INTERP1_ACCUM1_ADD:
return this.interp1.smresult1;
}
console.warn(`Read from invalid SIO address: ${offset.toString(16)}`);
return 0xffffffff;
switch (core) {
case Core.Core0:
return this.core0.readUint32(offset);
case Core.Core1:
return this.core1.readUint32(offset);
}
}

writeUint32(offset: number, value: number, core: Core) {
Expand Down Expand Up @@ -393,30 +348,6 @@ export class RPSIO {
case GPIO_HI_OE_XOR:
this.qspiGpioOutputEnable ^= value & GPIO_MASK;
break;
case DIV_UDIVIDEND:
this.divDividend = value;
this.updateHardwareDivider(false, core);
break;
case DIV_SDIVIDEND:
this.divDividend = value;
this.updateHardwareDivider(true, core);
break;
case DIV_UDIVISOR:
this.divDivisor = value;
this.updateHardwareDivider(false, core);
break;
case DIV_SDIVISOR:
this.divDivisor = value;
this.updateHardwareDivider(true, core);
break;
case DIV_QUOTIENT:
this.divQuotient = value;
this.divCSR = 0b11;
break;
case DIV_REMAINDER:
this.divRemainder = value;
this.divCSR = 0b11;
break;
case INTERP0_ACCUM0:
this.interp0.accum0 = value;
this.interp0.update();
Expand Down Expand Up @@ -544,9 +475,14 @@ export class RPSIO {
}
break;
default:
console.warn(
`Write to invalid SIO address: ${offset.toString(16)}, value=${value.toString(16)}`
);
switch (core) {
case Core.Core0:
this.core0.writeUint32(offset, value, core)
break;
case Core.Core1:
this.core1.writeUint32(offset, value, core);
break;
}
}
const pinsToUpdate =
(this.gpioValue ^ prevGpioValue) | (this.gpioOutputEnable ^ prevGpioOutputEnable);
Expand Down