Permalink
Browse files

try to implement dma

  • Loading branch information...
wwylele committed Aug 7, 2018
1 parent 661a352 commit d22c2d99d3b0858eb190bf9298815fcac237793a
Showing with 44 additions and 2 deletions.
  1. +4 −0 include/teakra/teakra.h
  2. +16 −0 src/dma.cpp
  3. +17 −0 src/dma.h
  4. +6 −1 src/teakra.cpp
  5. +1 −1 src/test_verifier/main.cpp
@@ -4,6 +4,7 @@
#include <cstdint>
#include <functional>
#include <memory>
#include <vector>

namespace Teakra {
class Teakra {
@@ -28,6 +29,9 @@ class Teakra {
// core
void Run(unsigned cycle);

void SetDmaReadCallback(
std::function<std::vector<uint8_t>(std::uint32_t address, std::uint32_t size)> callback);

private:
struct Impl;
std::unique_ptr<Impl> impl;
@@ -0,0 +1,16 @@
#include <cstring>
#include "dma.h"
#include "shared_memory.h"

namespace Teakra {

void Dma::DoDma() {
u32 src =
channels[active_channel].addr_src_low | ((u32)channels[active_channel].addr_src_high << 16);
u32 dst =
channels[active_channel].addr_dst_low | ((u32)channels[active_channel].addr_dst_high << 16);
auto data = read_callback(src, channels[active_channel].length * 2);
std::memcpy(shared_memory.raw.data() + dst * 2, data.data(), data.size());
}

} // namespace Teakra
@@ -1,12 +1,16 @@
#pragma once
#include <array>
#include <cstdio>
#include <functional>
#include "common_types.h"

namespace Teakra {

struct SharedMemory;

class Dma {
public:
Dma(SharedMemory& shared_memory) : shared_memory(shared_memory) {}
void EnableChannel(u16 value) {
std::printf("DMA: enable channel %04X\n", value);
enable_channel = value;
@@ -154,12 +158,22 @@ class Dma {
void SetZ(u16 value) {
std::printf("DMA: SetZ %04X\n", value);
channels[active_channel].z = value;

if (value == 0x40C0) {
DoDma();
}
}
u16 GetZ() {
std::printf("DMA: GetZ\n");
return channels[active_channel].z;
}

void SetReadCallback(std::function<std::vector<u8>(u32 address, u32 size)> callback) {
read_callback = std::move(callback);
}

void DoDma();

private:
u16 enable_channel = 0;
u16 active_channel = 0;
@@ -176,6 +190,9 @@ class Dma {
};

std::array<Channel, 8> channels;

std::function<std::vector<u8>(u32 address, u32 size)> read_callback;
SharedMemory& shared_memory;
};

} // namespace Teakra
@@ -20,7 +20,7 @@ struct Teakra::Impl {
ICU icu;
Apbp apbp_from_cpu{"cpu->dsp"}, apbp_from_dsp{"dsp->cpu"};
std::array<Timer, 2> timer;
Dma dma;
Dma dma{shared_memory};
Ahbm ahbm;
std::array<Btdmp, 2> btdmp{{{"0"}, {"1"}}};
MMIORegion mmio{miu, icu, apbp_from_cpu, apbp_from_dsp, timer, dma, ahbm, btdmp};
@@ -91,4 +91,9 @@ std::uint16_t Teakra::GetSemaphore() {
return impl->apbp_from_dsp.GetSemaphore();
}

void Teakra::SetDmaReadCallback(
std::function<std::vector<uint8_t>(std::uint32_t address, std::uint32_t size)> callback) {
impl->dma.SetReadCallback(std::move(callback));
}

} // namespace Teakra
@@ -40,7 +40,7 @@ int main(int argc, char** argv) {
Teakra::ICU icu;
Teakra::Apbp apbp_from_cpu{"cpu->dsp"}, apbp_from_dsp{"dsp->cpu"};
std::array<Teakra::Timer, 2> timer;
Teakra::Dma dma;
Teakra::Dma dma{shared_memory};
Teakra::Ahbm ahbm;
std::array<Teakra::Btdmp, 2> btdmp{{{"0"}, {"1"}}};
Teakra::MMIORegion mmio{miu, icu, apbp_from_cpu, apbp_from_dsp, timer, dma, ahbm, btdmp};

1 comment on commit d22c2d9

@Mantinefan022

This comment has been minimized.

Copy link

Mantinefan022 commented on d22c2d9 Aug 23, 2018

Have you stopped with this project? It has been 16 days without update ..

Please sign in to comment.