-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat(sio): fix implemented Hardware Divider #37
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d810256
feat(RP2040): implemented RESET_BASE peripherals
Turro75 1a6550c
feat(sio): fix implemented Hardware Divider
Turro75 e89f2f6
feat(sio): add cycles count for hardware divider
Turro75 79925fa
test(sio): add test for hardware divider
Turro75 40694fb
test(sio): add test for hardware divider
Turro75 6bfe234
wrong test description fixed
Turro75 c968ed8
Merge branch 'Hardware-Divider-fix' of https://github.com/Turro75/rp2…
Turro75 a7e7e6a
fix(sio):fix unsigned/signed hardware divisor
Turro75 b7553f9
feat(test-driver): add readInt32 for signed responses
Turro75 00e2c81
feat(hardware divider): moved case code to dedicate function
Turro75 5583d49
feat(test-driver): align gdb readInt32 to rp2040 implementation
Turro75 88e7904
fix(sio): update cycles and CSR even with div/0
Turro75 5353e80
test(sio): added test -3000/2
Turro75 126c4c0
fix(hardware divider): changed division math to better reflect silico…
Turro75 efae75a
fix(hardware divider): missing break in case forced always signed ope…
Turro75 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,37 @@ | ||
import { BasePeripheral, Peripheral } from './peripheral'; | ||
|
||
const RESET = 0x0; //Reset control. | ||
const WDSEL = 0x4; //Watchdog select. | ||
const RESET_DONE = 0x8; //Reset Done | ||
|
||
export class RPReset extends BasePeripheral implements Peripheral { | ||
private reset: number = 0; | ||
private wdsel: number = 0; | ||
private reset_done: number = 0x1ffffff; | ||
|
||
readUint32(offset: number) { | ||
switch (offset) { | ||
case RESET: | ||
return this.reset; | ||
case WDSEL: | ||
return this.wdsel; | ||
case RESET_DONE: | ||
return this.reset_done; | ||
} | ||
return super.readUint32(offset); | ||
} | ||
|
||
writeUint32(offset: number, value: number) { | ||
switch (offset) { | ||
case RESET: | ||
this.reset = value & 0x1ffffff; | ||
break; | ||
case WDSEL: | ||
this.wdsel = value & 0x1ffffff; | ||
break; | ||
default: | ||
super.writeUint32(offset, value); | ||
break; | ||
} | ||
} | ||
} |
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,64 @@ | ||
import { RP2040, SIO_START_ADDRESS } from './rp2040'; | ||
|
||
//HARDWARE DIVIDER | ||
const _DIV_UDIVIDEND = SIO_START_ADDRESS + 0x060; // Divider unsigned dividend | ||
const _DIV_UDIVISOR = SIO_START_ADDRESS + 0x064; // Divider unsigned divisor | ||
const _DIV_SDIVIDEND = SIO_START_ADDRESS + 0x068; // Divider signed dividend | ||
const _DIV_SDIVISOR = SIO_START_ADDRESS + 0x06c; // Divider signed divisor | ||
const _DIV_QUOTIENT = SIO_START_ADDRESS + 0x070; // Divider result quotient | ||
const _DIV_REMAINDER = SIO_START_ADDRESS + 0x074; //Divider result remainder | ||
const _DIV_CSR = SIO_START_ADDRESS + 0x078; | ||
|
||
describe('RPSIO', () => { | ||
describe('Hardware Divider', () => { | ||
it('should set perform a signed hardware divider 123456 / -321 = -384 R192', () => { | ||
const rp2040 = new RP2040(); | ||
expect(rp2040.readUint32(_DIV_CSR)).toEqual(0); | ||
rp2040.writeUint32(_DIV_SDIVIDEND, 123456); | ||
rp2040.writeUint32(_DIV_SDIVISOR, -321); | ||
expect(rp2040.readUint32(_DIV_CSR)).toEqual(1); | ||
expect(rp2040.readUint32(_DIV_REMAINDER)).toEqual(192); | ||
expect(rp2040.readUint32(_DIV_QUOTIENT)).toEqual(-384); | ||
expect(rp2040.readUint32(_DIV_CSR)).toEqual(0); | ||
}); | ||
|
||
it('should set perform an unsigned hardware divider 123456 / 321 = 384 R192', () => { | ||
const rp2040 = new RP2040(); | ||
expect(rp2040.readUint32(_DIV_CSR)).toEqual(0); | ||
rp2040.writeUint32(_DIV_UDIVIDEND, 123456); | ||
const cycles = rp2040.cycles; | ||
rp2040.writeUint32(_DIV_UDIVISOR, 321); | ||
expect(rp2040.cycles - cycles).toEqual(8); | ||
expect(rp2040.readUint32(_DIV_CSR)).toEqual(1); | ||
expect(rp2040.readUint32(_DIV_REMAINDER)).toEqual(192); | ||
expect(rp2040.readUint32(_DIV_QUOTIENT)).toEqual(384); | ||
expect(rp2040.readUint32(_DIV_CSR)).toEqual(0); | ||
}); | ||
|
||
it('should perform a division, store the result, do another division then restore the previously stored result ', () => { | ||
const rp2040 = new RP2040(); | ||
rp2040.writeUint32(_DIV_SDIVIDEND, 123456); | ||
rp2040.writeUint32(_DIV_SDIVISOR, -321); | ||
const remainder = rp2040.readUint32(_DIV_REMAINDER); | ||
const quotient = rp2040.readUint32(_DIV_QUOTIENT); | ||
expect(remainder).toEqual(192); | ||
expect(quotient).toEqual(-384); | ||
rp2040.writeUint32(_DIV_UDIVIDEND, 123); | ||
rp2040.writeUint32(_DIV_UDIVISOR, 7); | ||
expect(rp2040.readUint32(_DIV_REMAINDER)).toEqual(4); | ||
expect(rp2040.readUint32(_DIV_QUOTIENT)).toEqual(17); | ||
rp2040.writeUint32(_DIV_REMAINDER, remainder); | ||
rp2040.writeUint32(_DIV_QUOTIENT, quotient); | ||
expect(rp2040.readUint32(_DIV_REMAINDER)).toEqual(192); | ||
expect(rp2040.readUint32(_DIV_QUOTIENT)).toEqual(-384); | ||
}); | ||
|
||
it('should set perform an unsigned division by zero 123456 / 0 = Infinity RNaN', () => { | ||
const rp2040 = new RP2040(); | ||
rp2040.writeUint32(_DIV_UDIVIDEND, 123456); | ||
rp2040.writeUint32(_DIV_UDIVISOR, 0); | ||
expect(rp2040.readUint32(_DIV_REMAINDER)).toEqual(NaN); | ||
expect(rp2040.readUint32(_DIV_QUOTIENT)).toEqual(Infinity); | ||
}); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove the _ (underscore) in front of the constant? The idea is to keep this code consistent with the rest of the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'm moving test to be gdbclient ready, I'll do it in the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh great. I was going to suggest that, but you are faster!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok done,
I had to add several "| 0"which are needed when running on silicone and the read value is signed, maybe a readSInt32 implementation could be better? or maybe not as it matters only during test?
copied the silicone behavior when divisor=0 -> quot=-1, rem=dividend
I wasn't able to find any word related to div/0 exceptions in the datasheets, is this possible?
_DIV_XXX has been renamed to SIO_DIV_XXX, I choose this way as SIO_DIV_XXX = SIO_ADDRESS_BASE + DIV_XXX
Even if declared in different files, I wouldn't have the same name to both offset and full address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Good idea to test what happens when dividing by zero.
No idea! Did you see it getting any exception on the silicone?
I think this is a good idea, it will make the tests easier to read / understand. I suggest calling it
readInt32()
(without the S), similar to how they call the signed int array in JavaScript (and also C++ type int32_t vs uint32_t).👍