From 31eb0df5085c63a9aadeaf6840137aa83ed83e50 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sat, 3 Feb 2024 10:15:39 +0800 Subject: [PATCH] maple: remove all remaining uses of the two-argument "dma_start" After thinking about this more, I realized it is probably never useful, and certainly completely incorrect in all of the cases it was still being used in the examples. --- example/clipping.cpp | 12 +++++---- example/clipping2.cpp | 16 ++++++++---- example/clipping_textured.cpp | 7 +++-- example/maple_analog.cpp | 12 +++++---- example/maple_controller.cpp | 27 ++++++++++++-------- example/maple_device_request.cpp | 11 +++++--- example/modifier_volume_with_two_volumes.cpp | 14 +++++----- maple/maple.cpp | 20 --------------- maple/maple.hpp | 4 --- 9 files changed, 61 insertions(+), 62 deletions(-) diff --git a/example/clipping.cpp b/example/clipping.cpp index 7005ed5..2114941 100644 --- a/example/clipping.cpp +++ b/example/clipping.cpp @@ -44,14 +44,16 @@ void do_get_condition(uint32_t * command_buf, .function_type = std::byteswap(function_type::controller) }; - const uint32_t size = maple::init_host_command_all_ports(command_buf, receive_buf, + const uint32_t command_size = maple::init_host_command_all_ports(command_buf, receive_buf, data_fields); - maple::dma_start(command_buf, size); + using host_response_type = struct maple::command_response; + auto host_response = reinterpret_cast(receive_buf); + + maple::dma_start(command_buf, command_size, + receive_buf, maple::sizeof_command(host_response)); - using command_response_type = struct maple::command_response; for (uint8_t port = 0; port < 4; port++) { - auto response = reinterpret_cast(receive_buf); - auto& bus_data = response[port].bus_data; + auto& bus_data = host_response[port].bus_data; if (bus_data.command_code != response_type::command_code) { return; } diff --git a/example/clipping2.cpp b/example/clipping2.cpp index e648e38..1b65f72 100644 --- a/example/clipping2.cpp +++ b/example/clipping2.cpp @@ -30,6 +30,8 @@ #include "maple/maple_bus_commands.hpp" #include "maple/maple_bus_ft0.hpp" +#include "sh7091/serial.hpp" + uint32_t _command_buf[(1024 + 32) / 4]; uint32_t _receive_buf[(1024 + 32) / 4]; @@ -45,14 +47,15 @@ void do_get_condition(uint32_t * command_buf, .function_type = std::byteswap(function_type::controller) }; - const uint32_t size = maple::init_host_command_all_ports(command_buf, receive_buf, + const uint32_t command_size = maple::init_host_command_all_ports(command_buf, receive_buf, data_fields); - maple::dma_start(command_buf, size); + using host_response_type = struct maple::command_response; + auto host_response = reinterpret_cast(receive_buf); + maple::dma_start(command_buf, command_size, + receive_buf, maple::sizeof_command(host_response)); - using command_response_type = struct maple::command_response; for (uint8_t port = 0; port < 4; port++) { - auto response = reinterpret_cast(receive_buf); - auto& bus_data = response[port].bus_data; + auto& bus_data = host_response[port].bus_data; if (bus_data.command_code != response_type::command_code) { return; } @@ -249,6 +252,9 @@ void main() while (1) { do_get_condition(command_buf, receive_buf); + if (frame_ix % 120 == 0) { + serial::integer(data[0].analog_axis_3); + } ta_polygon_converter_init(opb_size.total(), ta_alloc, diff --git a/example/clipping_textured.cpp b/example/clipping_textured.cpp index 25b44a4..7027986 100644 --- a/example/clipping_textured.cpp +++ b/example/clipping_textured.cpp @@ -49,9 +49,12 @@ void do_get_condition(uint32_t * command_buf, .function_type = std::byteswap(function_type::controller) }; - const uint32_t size = maple::init_host_command_all_ports(command_buf, receive_buf, + const uint32_t command_size = maple::init_host_command_all_ports(command_buf, receive_buf, data_fields); - maple::dma_start(command_buf, size); + using host_response_type = struct maple::command_response; + auto host_response = reinterpret_cast(receive_buf); + maple::dma_start(command_buf, command_size, + receive_buf, maple::sizeof_command(host_response)); using command_response_type = struct maple::command_response; for (uint8_t port = 0; port < 4; port++) { diff --git a/example/maple_analog.cpp b/example/maple_analog.cpp index fac7ce2..fda34b0 100644 --- a/example/maple_analog.cpp +++ b/example/maple_analog.cpp @@ -44,14 +44,16 @@ void do_get_condition(uint32_t * command_buf, .function_type = std::byteswap(function_type::controller) }; - const uint32_t size = maple::init_host_command_all_ports(command_buf, receive_buf, + const uint32_t command_size = maple::init_host_command_all_ports(command_buf, receive_buf, data_fields); - maple::dma_start(command_buf, size); + using host_response_type = struct maple::command_response; + auto host_response = reinterpret_cast(receive_buf); + + maple::dma_start(command_buf, command_size, + receive_buf, maple::sizeof_command(host_response)); - using command_response_type = struct maple::command_response; for (uint8_t port = 0; port < 4; port++) { - auto response = reinterpret_cast(receive_buf); - auto& bus_data = response[port].bus_data; + auto& bus_data = host_response[port].bus_data; if (bus_data.command_code != response_type::command_code) { return; } diff --git a/example/maple_controller.cpp b/example/maple_controller.cpp index 774f605..7337c4f 100644 --- a/example/maple_controller.cpp +++ b/example/maple_controller.cpp @@ -42,16 +42,19 @@ void do_get_condition(uint32_t port) return; } - const uint32_t size = maple::init_get_condition(command_buf, receive_buf, - destination_port, - destination_ap, - std::byteswap(function_type::controller)); - maple::dma_start(command_buf, size); + const uint32_t command_size = maple::init_get_condition(command_buf, receive_buf, + destination_port, + destination_ap, + std::byteswap(function_type::controller)); using response_type = data_transfer; using command_response_type = struct maple::command_response; - auto response = reinterpret_cast(receive_buf); - auto& bus_data = response->bus_data; + auto host_response = reinterpret_cast(receive_buf); + + maple::dma_start(command_buf, command_size, + receive_buf, maple::sizeof_command(host_response)); + + auto& bus_data = host_response->bus_data; if (bus_data.command_code != response_type::command_code) { return; } @@ -74,11 +77,13 @@ void do_device_request() using command_type = device_request; using response_type = device_status; - const uint32_t size = maple::init_host_command_all_ports(command_buf, receive_buf); - maple::dma_start(command_buf, size * 10); + const uint32_t command_size = maple::init_host_command_all_ports(command_buf, receive_buf); + using host_response_type = struct maple::command_response; + auto host_response = reinterpret_cast(receive_buf); + + maple::dma_start(command_buf, command_size, + receive_buf, maple::sizeof_command(host_response)); - using command_response_type = struct maple::command_response; - auto response = reinterpret_cast(receive_buf); for (uint8_t port = 0; port < 4; port++) { auto& bus_data = response[port].bus_data; auto& data_fields = response[port].bus_data.data_fields; diff --git a/example/maple_device_request.cpp b/example/maple_device_request.cpp index c5394eb..15826c2 100644 --- a/example/maple_device_request.cpp +++ b/example/maple_device_request.cpp @@ -16,16 +16,19 @@ void main() using command_type = device_request; using response_type = device_status; - uint32_t size = maple::init_host_command_all_ports(command_buf, receive_buf); - maple::dma_start(command_buf, size); + uint32_t command_size = maple::init_host_command_all_ports(command_buf, receive_buf); + + constexpr uint32_t host_response_size = (sizeof (maple::command_response)); + + maple::dma_start(command_buf, command_size, + receive_buf, host_response_size); uint8_t * buf = reinterpret_cast(receive_buf); for (uint8_t port = 0; port < 4; port++) { serial::string("port "); serial::integer(port); - constexpr uint32_t command_response_size = (sizeof (maple::command_response)); - for (uint32_t i = 0; i < command_response_size; i++) { + for (uint32_t i = 0; i < host_response_size; i++) { serial::integer(buf[port * command_response_size + i]); } serial::character('\n'); diff --git a/example/modifier_volume_with_two_volumes.cpp b/example/modifier_volume_with_two_volumes.cpp index ef710ae..ce402e8 100644 --- a/example/modifier_volume_with_two_volumes.cpp +++ b/example/modifier_volume_with_two_volumes.cpp @@ -45,14 +45,16 @@ void do_get_condition(uint32_t * command_buf, .function_type = std::byteswap(function_type::controller) }; - const uint32_t size = maple::init_host_command_all_ports(command_buf, receive_buf, - data_fields); - maple::dma_start(command_buf, size); + const uint32_t command_size = maple::init_host_command_all_ports(command_buf, receive_buf, + data_fields); + using host_response_type = struct maple::command_response; + auto host_response = reinterpret_cast(receive_buf); + + maple::dma_start(command_buf, command_size, + receive_buf, maple::sizeof_command(host_response)); - using command_response_type = struct maple::command_response; for (uint8_t port = 0; port < 4; port++) { - auto response = reinterpret_cast(receive_buf); - auto& bus_data = response[port].bus_data; + auto& bus_data = host_response[port].bus_data; if (bus_data.command_code != response_type::command_code) { return; } diff --git a/maple/maple.cpp b/maple/maple.cpp index 787ba91..b9d48e8 100644 --- a/maple/maple.cpp +++ b/maple/maple.cpp @@ -173,26 +173,6 @@ void dma_start(const uint32_t * command_buf, system.ISTNRM = ISTNRM__END_OF_DMA_MAPLE_DMA; } -void dma_start(const uint32_t * command_buf, - const uint32_t command_size - ) -{ - // write back operand cache blocks for command buffer prior to starting DMA - for (uint32_t i = 0; i < align_32byte(command_size) / 32; i++) { - asm volatile ("ocbwb @%0" - : // output - : "r" (reinterpret_cast(&command_buf[(32 * i) / 4])) // input - ); - } - - // start maple DMA - _dma_start(command_buf); - - // wait for maple DMA completion - while ((system.ISTNRM & ISTNRM__END_OF_DMA_MAPLE_DMA) == 0); - system.ISTNRM = ISTNRM__END_OF_DMA_MAPLE_DMA; -} - // wait for completion //while (mdst::start_status::status(maple_if.MDST) != 0); /* diff --git a/maple/maple.hpp b/maple/maple.hpp index ff8658b..2ae140e 100644 --- a/maple/maple.hpp +++ b/maple/maple.hpp @@ -60,10 +60,6 @@ void dma_start(const uint32_t * command_buf, const uint32_t receive_size ); -void dma_start(const uint32_t * command_buf, - const uint32_t command_size - ); - template constexpr uint32_t sizeof_command(T * c) {