1
0
mirror of synced 2026-03-10 04:44:58 +00:00

Some more refactor of the Teensy code.

This commit is contained in:
Matthieu Bucchianeri
2025-02-17 14:01:03 -08:00
parent fae52a0057
commit e03594b514

View File

@@ -558,6 +558,7 @@ inline void Internal_RAM_Write() {
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
__attribute__((always_inline))
inline void Mem_Read_Cycle() inline void Mem_Read_Cycle()
{ {
isa_address = ADDRESS_DATA_GPIO6_UNSCRAMBLE; isa_address = ADDRESS_DATA_GPIO6_UNSCRAMBLE;
@@ -653,6 +654,7 @@ inline void Mem_Read_Cycle()
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
__attribute__((always_inline))
inline void Mem_Write_Cycle() inline void Mem_Write_Cycle()
{ {
isa_address = ADDRESS_DATA_GPIO6_UNSCRAMBLE; isa_address = ADDRESS_DATA_GPIO6_UNSCRAMBLE;
@@ -732,11 +734,14 @@ inline void Mem_Write_Cycle()
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
__attribute__((always_inline))
inline void IO_Read_Cycle() inline void IO_Read_Cycle()
{ {
isa_address = 0xFFFF & ADDRESS_DATA_GPIO6_UNSCRAMBLE; isa_address = 0xFFFF & ADDRESS_DATA_GPIO6_UNSCRAMBLE;
if ((isa_address&0x0FF8)==EMS_BASE_IO) { // Location of 16 KB Expanded Memory page frame pointers uint16_t base_address = isa_address&0x0FF8;
switch (base_address) {
case EMS_BASE_IO:
switch (isa_address) { switch (isa_address) {
case EMS_BASE_IO : isa_data_out = ems_frame_pointer[0]; break; case EMS_BASE_IO : isa_data_out = ems_frame_pointer[0]; break;
case EMS_BASE_IO+1: isa_data_out = ems_frame_pointer[0] >> 8; break; case EMS_BASE_IO+1: isa_data_out = ems_frame_pointer[0] >> 8; break;
@@ -754,8 +759,9 @@ inline void IO_Read_Cycle()
while ( (gpio9_int&0xF0) != 0xF0 ) { gpio9_int = GPIO9_DR; } // Wait here until cycle is complete while ( (gpio9_int&0xF0) != 0xF0 ) { gpio9_int = GPIO9_DR; } // Wait here until cycle is complete
GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH;
} break;
else if ((isa_address&0x0FF8)==SD_BASE) { // Location of SD Card registers
case SD_BASE:
switch (isa_address) { switch (isa_address) {
case SD_BASE+0: sd_spi_dataout = 0xff; SD_SPI_Cycle(); isa_data_out = sd_spi_datain; break; case SD_BASE+0: sd_spi_dataout = 0xff; SD_SPI_Cycle(); isa_data_out = sd_spi_datain; break;
case SD_BASE+1: isa_data_out = SD_CONFIG_BYTE; break; case SD_BASE+1: isa_data_out = SD_CONFIG_BYTE; break;
@@ -774,6 +780,7 @@ inline void IO_Read_Cycle()
while ( (gpio9_int&0xF0) != 0xF0 ) { gpio9_int = GPIO9_DR; } // Wait here until cycle is complete while ( (gpio9_int&0xF0) != 0xF0 ) { gpio9_int = GPIO9_DR; } // Wait here until cycle is complete
GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH;
break;
} }
} }
@@ -781,11 +788,14 @@ inline void IO_Read_Cycle()
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
__attribute__((always_inline))
inline void IO_Write_Cycle() inline void IO_Write_Cycle()
{ {
isa_address = 0xFFFF & ADDRESS_DATA_GPIO6_UNSCRAMBLE; isa_address = 0xFFFF & ADDRESS_DATA_GPIO6_UNSCRAMBLE;
if ((isa_address&0x0FF8)==EMS_BASE_IO) { // Location of 16 KB Expanded Memory page frame pointers uint16_t base_address = isa_address&0x0FF8;
switch (base_address) {
case EMS_BASE_IO:
GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_HIGH + CHRDY_OUT_LOW + trigger_out; GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_HIGH + CHRDY_OUT_LOW + trigger_out;
GPIO8_DR = sd_pin_outputs + MUX_DATA_n_LOW + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; GPIO8_DR = sd_pin_outputs + MUX_DATA_n_LOW + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH;
@@ -809,8 +819,9 @@ inline void IO_Write_Cycle()
GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_LOW + CHRDY_OUT_LOW + trigger_out; GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_LOW + CHRDY_OUT_LOW + trigger_out;
GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH;
} break;
else if ((isa_address&0x0FF8)==SD_BASE) { // Location of SD Card registers
case SD_BASE:
GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_HIGH + CHRDY_OUT_LOW + trigger_out; GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_HIGH + CHRDY_OUT_LOW + trigger_out;
GPIO8_DR = sd_pin_outputs + MUX_DATA_n_LOW + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; GPIO8_DR = sd_pin_outputs + MUX_DATA_n_LOW + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH;
@@ -829,7 +840,6 @@ inline void IO_Write_Cycle()
case SD_BASE+7: sd_timeout = 0; sd_requested_timeout = data_in * 10; break; case SD_BASE+7: sd_timeout = 0; sd_requested_timeout = data_in * 10; break;
} }
//gpio9_int = GPIO9_DR;
while ( (gpio9_int&0xF0) != 0xF0 ) { // Wait here until cycle is complete while ( (gpio9_int&0xF0) != 0xF0 ) { // Wait here until cycle is complete
gpio6_int = GPIO6_DR; gpio6_int = GPIO6_DR;
gpio9_int = GPIO9_DR; gpio9_int = GPIO9_DR;
@@ -839,6 +849,7 @@ inline void IO_Write_Cycle()
GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_LOW + CHRDY_OUT_LOW + trigger_out; GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_LOW + CHRDY_OUT_LOW + trigger_out;
GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH;
break;
} }
} }
@@ -849,23 +860,22 @@ inline void IO_Write_Cycle()
// Main loop // Main loop
// //
// ------------------------------------------------- // -------------------------------------------------
void loop() {
// Give Teensy 4.1 a moment
//
//delay (1000);
void loop()
{
PSRAM_Configure(); PSRAM_Configure();
while (1) { while (1) {
gpio6_int = GPIO6_DR; gpio6_int = GPIO6_DR;
gpio9_int = GPIO9_DR; gpio9_int = GPIO9_DR;
if ((gpio9_int&0x80000010)==0) IO_Read_Cycle(); // Isolate and check AEN and IO Rd/Wr switch (gpio9_int&0x800000F0) {
else if ((gpio9_int&0x80000020)==0) IO_Write_Cycle(); case 0x000000E0: IO_Read_Cycle(); break; // ~AEN + ~IORD
else if ((gpio9_int&0x00000040)==0) Mem_Read_Cycle(); case 0x000000D0: IO_Write_Cycle(); break; // ~AEN + ~IOWR
else if ((gpio9_int&0x00000080)==0) Mem_Write_Cycle(); case 0x000000B0:
case 0x800000B0: Mem_Read_Cycle(); break; // ~MEMRD
case 0x00000070:
case 0x80000070: Mem_Write_Cycle(); break; // ~MEMWR
}
} }
} }