-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a86ba5f
commit ff1144c
Showing
11 changed files
with
521 additions
and
14 deletions.
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
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
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,86 @@ | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
// Copied from Avocado | ||
namespace DMA { | ||
enum class Channel { MDECin, MDECout, GPU, CDROM, SPU, PIO, OTC }; | ||
|
||
const inline uint32_t CH_BASE_ADDR = 0x1F801080; | ||
const inline uint32_t CH_BLOCK_ADDR = 0x1F801084; | ||
const inline uint32_t CH_CONTROL_ADDR = 0x1F801088; | ||
const inline uint32_t CONTROL_ADDR = 0x1F8010F0; | ||
|
||
// DMA base address | ||
union MADDR { | ||
struct { | ||
uint32_t address : 24; | ||
uint32_t : 8; | ||
}; | ||
uint32_t _reg; | ||
uint8_t _byte[4]; | ||
|
||
MADDR() : _reg(0) {} | ||
}; | ||
|
||
// DMA Block Control | ||
union BCR { | ||
union { | ||
struct { | ||
uint32_t wordCount : 16; | ||
uint32_t : 16; | ||
} syncMode0; | ||
struct { | ||
uint32_t blockSize : 16; | ||
uint32_t blockCount : 16; | ||
} syncMode1; | ||
}; | ||
uint32_t _reg; | ||
uint8_t _byte[4]; | ||
|
||
BCR() : _reg(0) {} | ||
}; | ||
|
||
// DMA Channel Control | ||
union CHCR { | ||
enum class Direction : uint32_t { toRam = 0, fromRam = 1 }; | ||
enum class MemoryAddressStep : uint32_t { forward = 0, backward = 1 }; | ||
enum class SyncMode : uint32_t { startImmediately = 0, syncBlockToDmaRequests = 1, linkedListMode = 2, reserved = 3 }; | ||
enum class ChoppingEnable : uint32_t { normal = 0, chopping = 1 }; | ||
enum class Enabled : uint32_t { completed = 0, stop = 0, start = 1 }; | ||
enum class StartTrigger : uint32_t { clear = 0, automatic = 0, manual = 1 }; | ||
|
||
struct { | ||
Direction direction : 1; | ||
MemoryAddressStep memoryAddressStep : 1; | ||
uint32_t : 6; | ||
uint32_t choppingEnable : 1; | ||
SyncMode syncMode : 2; | ||
uint32_t : 5; | ||
uint32_t choppingDmaWindowSize : 3; // Chopping DMA Window Size (1 SHL N words) | ||
uint32_t : 1; | ||
uint32_t choppingCpuWindowSize : 3; // Chopping CPU Window Size(1 SHL N clks) | ||
uint32_t : 1; | ||
Enabled enabled : 1; // stopped/completed, start/enable/busy | ||
uint32_t : 3; | ||
StartTrigger startTrigger : 1; | ||
uint32_t : 3; | ||
}; | ||
uint32_t _reg; | ||
uint8_t _byte[4]; | ||
|
||
CHCR() : _reg(0) {} | ||
|
||
static CHCR OTC() { | ||
CHCR control; | ||
control.direction = Direction::toRam; | ||
control.memoryAddressStep = MemoryAddressStep::backward; | ||
control.choppingEnable = 0; | ||
control.syncMode = SyncMode::startImmediately; | ||
control.choppingDmaWindowSize = 0; | ||
control.choppingCpuWindowSize = 0; | ||
control.enabled = Enabled::start; | ||
control.startTrigger = StartTrigger::manual; | ||
return control; | ||
} | ||
}; | ||
}; |
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,3 @@ | ||
#include "test.h" | ||
|
||
struct TEST __test = {0}; |
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 |
---|---|---|
@@ -1,14 +1,53 @@ | ||
#pragma once | ||
#include "stdint.h" | ||
|
||
#define assertEquals(given, expected) \ | ||
do { \ | ||
auto GIVEN = (given); \ | ||
auto EXPECTED = (expected); \ | ||
if (GIVEN == EXPECTED) { \ | ||
printf("pass - %s\n", __FUNCTION__); \ | ||
} else { \ | ||
printf("fail - %s:%d `"#given" == "#expected"`," \ | ||
" given: 0x%x, expected: 0x%x\n", \ | ||
__FUNCTION__, __LINE__, GIVEN, EXPECTED); \ | ||
} \ | ||
} while(0) | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct TEST { | ||
bool quiet; | ||
int failedAssertions; | ||
int passedAssertions; | ||
}; | ||
|
||
extern struct TEST __test; | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#define assertEquals(given, expected) \ | ||
[](auto FUNCTION, auto GIVEN, auto EXPECTED) -> bool { \ | ||
if (GIVEN == EXPECTED) { \ | ||
__test.passedAssertions++; \ | ||
if (!__test.quiet) { \ | ||
printf("pass - %s\n", FUNCTION); \ | ||
} \ | ||
return true; \ | ||
} else { \ | ||
__test.failedAssertions++; \ | ||
printf("fail - %s:%d `"#given" == "#expected"`," \ | ||
" given: 0x%x, expected: 0x%x\n", \ | ||
FUNCTION, __LINE__, GIVEN, EXPECTED); \ | ||
return false; \ | ||
} \ | ||
}(__FUNCTION__, given, expected) | ||
|
||
#define TEST_MULTIPLE_BEGIN() \ | ||
[]() { \ | ||
__test.quiet = true; \ | ||
}() | ||
|
||
#define TEST_MULTIPLE_END() \ | ||
[](auto FUNCTION) { \ | ||
bool passed = __test.failedAssertions == 0; \ | ||
__test.quiet = false; \ | ||
__test.failedAssertions = 0; \ | ||
__test.passedAssertions = 0; \ | ||
if (passed) { \ | ||
printf("pass - %s\n", FUNCTION); \ | ||
return true; \ | ||
} else { \ | ||
return false; \ | ||
} \ | ||
}(__FUNCTION__) |
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,3 @@ | ||
TARGET = otc-test.elf | ||
|
||
include ../../common-test.mk |
Oops, something went wrong.