diff --git a/Inc/control.h b/Inc/control.h index 12dc543..19b2d8e 100644 --- a/Inc/control.h +++ b/Inc/control.h @@ -3,21 +3,6 @@ #include "stm32f4xx_hal.h" -typedef enum { - CONTROL_STOP = 0, - CONTROL_RESET_BEGIN, - CONTROL_RESET_1, - CONTROL_RESET_2, - CONTROL_RESET_3, - CONTROL_RESET_4, - CONTROL_RESET_5, - CONTROL_RESET_6, - CONTROL_RESET_7, - CONTROL_RESET_END = 9, - CONTROL_CLOCK_LOW, - CONTROL_CLOCK_HIGH -} ControlState; - typedef struct { uint8_t dirty; uint8_t action; @@ -31,7 +16,6 @@ typedef struct { } Storage; typedef struct { - ControlState state; uint8_t memory_config; Storage storage; } Control; @@ -41,7 +25,7 @@ void write_data(uint8_t value); uint8_t read_data(); void control_program_eeprom(uint8_t* data, uint16_t length); -void control_execute_state(); +void control_cycle(); void control_reset(); #endif diff --git a/Src/control.c b/Src/control.c index a4a4519..c6ff0e7 100644 --- a/Src/control.c +++ b/Src/control.c @@ -55,7 +55,7 @@ void control_program_eeprom(uint8_t* data, uint16_t length) { // Take control of the bus send_busrq(1); while (!has_busak()) { - control_execute_state(); + control_cycle(); } enable_address_out(1); @@ -237,7 +237,9 @@ void handle_ioreq() { } } -void cycle() { +void control_cycle() { + set_clock(1); + // We need this not detect IO multiple times static uint8_t had_ioreq = 0; if (!has_ioreq()) { @@ -257,58 +259,20 @@ void cycle() { } else if (has_ioreq() && has_m1()) { printf("Interrupt ackknowledged\n\r"); } -} -void control_execute_state() { - switch (control.state) { - case CONTROL_STOP: - // OK - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET); - // UPDATE - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET); - // OTHER - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_RESET); - return; - - case CONTROL_RESET_BEGIN: - control.state++; - set_reset(1); - - // OK - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_SET); - // UPDATE - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET); - // OTHER - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_RESET); - break; - - case CONTROL_RESET_BEGIN+1 ... CONTROL_RESET_END-1: - control.state++; - set_clock(control.state % 2); - break; - - case CONTROL_RESET_END: - control.state++; - set_reset(0); - break; - - case CONTROL_CLOCK_LOW: - control.state++; - set_clock(1); - break; - - case CONTROL_CLOCK_HIGH: - control.state--; - cycle(); - set_clock(0); - break; - } + set_clock(0); } // @todo Properly reset everything void control_reset() { free(control.storage.buffer); - Control temp = {CONTROL_RESET_BEGIN, 0, {1, 0, 0, 0, 0, 0, 0, 0, NULL}}; + Control temp = {0, {1, 0, 0, 0, 0, 0, 0, 0, NULL}}; control = temp; control.storage.buffer = (uint8_t*)malloc(SD_PAGES*SD_PAGE_SIZE); + + set_reset(1); + for (int i = 0; i <= 10; ++i) { + set_clock(i % 2); + } + set_reset(0); } diff --git a/Src/main.c b/Src/main.c index 24a7d55..77e82cd 100644 --- a/Src/main.c +++ b/Src/main.c @@ -264,7 +264,7 @@ int main(void) printf("Restarting Z80\n\r"); control_reset(); } else if (!temp) { - control_execute_state(); + control_cycle(); } zrst = temp;