Skip to content

Commit

Permalink
dma/otc-test DMA Channel 6
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Dec 25, 2019
1 parent a86ba5f commit ff1144c
Show file tree
Hide file tree
Showing 11 changed files with 521 additions and 14 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ TOPTARGETS = build clean

IMAGES = common \
cpu/code-in-scratchpad \
dma/otc-test \
gpu/bandwidth \
gpu/benchmark \
gpu/quad \
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Name | Description
-------------------------|------------
code-in-scratchpad | **(Not finished)** Check whether code execution from Scratchpad is possible

### DMA

Name | Description
-------------------------|------------
otc-test | DMA Channel 6 (OTC aka Ordering Table clear) unit tests

### GPU

Name | Description
Expand Down
4 changes: 2 additions & 2 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LIBDIRS := -L$(PSN00BSDK)/libpsn00b
GCC_VERSION = 7.4.0
GCC_BASE = /usr/local/mipsel-unknown-elf

CFLAGS ?= -g -msoft-float -O2 -fno-builtin -fdata-sections -ffunction-sections -Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare
CPPFLAGS ?= $(CFLAGS) -fno-exceptions -std=c++17
CFLAGS ?= -g -msoft-float -O3 -fno-builtin -fdata-sections -ffunction-sections -Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare
CPPFLAGS ?= $(CFLAGS) -fno-exceptions -std=c++1z
AFLAGS ?= -g -msoft-float
LDFLAGS ?= -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x

Expand Down
86 changes: 86 additions & 0 deletions common/dma.hpp
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;
}
};
};
3 changes: 3 additions & 0 deletions common/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "test.h"

struct TEST __test = {0};
63 changes: 51 additions & 12 deletions common/test.h
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__)
3 changes: 3 additions & 0 deletions dma/otc-test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TARGET = otc-test.elf

include ../../common-test.mk
Loading

0 comments on commit ff1144c

Please sign in to comment.