52 lines
2.1 KiB
C++
52 lines
2.1 KiB
C++
#ifndef __JABYENGINE_CD_INTERNAL_HPP__
|
|
#define __JABYENGINE_CD_INTERNAL_HPP__
|
|
#include "cd_types.hpp"
|
|
|
|
namespace JabyEngine {
|
|
namespace CD {
|
|
namespace internal {
|
|
extern State current_state;
|
|
extern CD_IO::Interrupt::Type last_interrupt;
|
|
extern uint8_t cmd_interrupt_bit;
|
|
|
|
struct Command {
|
|
static void wait_completed() {
|
|
while(const_cast<volatile uint8_t&>(cmd_interrupt_bit) > 0);
|
|
}
|
|
|
|
template<typename...ARGS>
|
|
static void send(IOPort<CD_IO::CommandFifo>& cmd_fifo, IOPort<CD_IO::ParameterFifo>& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) {
|
|
while(CD_IO::IndexStatus.read().is_set2(CD_IO::IndexStatus::IsTransmissionBusy));
|
|
|
|
((parameter_fifo.write(CD_IO::ParameterFifo{args})),...);
|
|
cmd_fifo.write(CD_IO::CommandFifo {cmd.id});
|
|
cmd_interrupt_bit = bit::set(0, cmd.complete_irq);
|
|
}
|
|
|
|
template<typename T, typename...ARGS>
|
|
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
|
|
send(T::CommandFifo, T::ParameterFifo, cmd, args...);
|
|
}
|
|
|
|
template<typename...ARGS>
|
|
static void send_wait(IOPort<CD_IO::CommandFifo>& cmd_fifo, IOPort<CD_IO::ParameterFifo>& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) {
|
|
send(cmd_fifo, parameter_fifo, cmd, args...);
|
|
wait_completed();
|
|
}
|
|
|
|
template<typename T, typename...ARGS>
|
|
static void send_wait(CD_IO::Command::Desc cmd, ARGS...args) {
|
|
send_wait(T::CommandFifo, T::ParameterFifo, cmd, args...);
|
|
}
|
|
};
|
|
|
|
static State read_current_state() {
|
|
return const_cast<volatile State&>(current_state);
|
|
}
|
|
|
|
void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator);
|
|
void continue_reading();
|
|
}
|
|
}
|
|
}
|
|
#endif //!__JABYENGINE_CD_INTERNAL_HPP__
|