general fixes

This commit is contained in:
Polprzewodnikowy 2022-10-05 02:08:43 +02:00
parent 9dfdcdc631
commit bce2d29cfa
7 changed files with 87 additions and 73 deletions

View File

@ -83,7 +83,7 @@ module n64_cfg (
REG_DATA_0_L: n64_scb.cfg_rdata[0][15:0] <= reg_bus.wdata;
REG_DATA_1_H: n64_scb.cfg_rdata[1][31:16] <= reg_bus.wdata;
REG_DATA_1_L: n64_scb.cfg_rdata[1][15:0] <= reg_bus.wdata;
REG_VERSION_L: irq <= 1'b0;
REG_VERSION_H: irq <= 1'b0;
REG_KEY_H, REG_KEY_L: begin
lock_sequence_counter <= lock_sequence_counter + 1'd1;
if (reg_bus.wdata != 16'hFFFF) begin

View File

@ -5,8 +5,12 @@
#include "usb.h"
#define BUTTON_COUNTER_TRIGGER_ON (64)
#define BUTTON_COUNTER_TRIGGER_OFF (0)
struct process {
uint32_t shift;
uint8_t counter;
bool state;
button_mode_t mode;
bool trigger;
@ -36,7 +40,7 @@ button_mode_t button_get_mode (void) {
}
void button_init (void) {
p.shift = 0x00000000UL;
p.counter = 0;
p.state = false;
p.mode = BUTTON_MODE_NONE;
p.trigger = false;
@ -45,15 +49,20 @@ void button_init (void) {
void button_process (void) {
usb_tx_info_t packet_info;
uint32_t status = fpga_reg_get(REG_CFG_SCR);
p.shift <<= 1;
if (status & CFG_SCR_BUTTON_STATE) {
p.shift |= (1 << 0);
if (p.counter < BUTTON_COUNTER_TRIGGER_ON) {
p.counter += 1;
}
if (!p.state && p.shift == 0xFFFFFFFFUL) {
} else {
if (p.counter > BUTTON_COUNTER_TRIGGER_OFF) {
p.counter -= 1;
}
}
if (!p.state && p.counter == BUTTON_COUNTER_TRIGGER_ON) {
p.state = true;
p.trigger = true;
}
if (p.state && p.shift == 0x00000000UL) {
if (p.state && p.counter == BUTTON_COUNTER_TRIGGER_OFF) {
p.state = false;
}
if (p.trigger) {

View File

@ -312,7 +312,7 @@ void cic_reset_parameters (void) {
}
void cic_set_parameters (uint32_t *args) {
cic_disabled = (args[0 >> 24]) & (1 << 1);
cic_disabled = (args[0] >> 24) & (1 << 1);
cic_dd_mode = (args[0] >> 24) & (1 << 0);
cic_seed = (args[0] >> 16) & 0xFF;
cic_checksum[0] = (args[0] >> 8) & 0xFF;
@ -350,7 +350,7 @@ void cic_task (void) {
cic_write_checksum();
cic_init_ram(region);
while(1) {
while (1) {
uint8_t cmd = 0;
cmd |= (cic_read() << 1);
cmd |= cic_read();

View File

@ -44,8 +44,8 @@ void flashram_process (void) {
uint8_t buffer[FLASHRAM_PAGE_SIZE];
uint32_t address = FLASHRAM_ADDRESS;
uint32_t erase_size = (op == OP_ERASE_SECTOR) ? FLASHRAM_SECTOR_SIZE : FLASHRAM_SIZE;
uint32_t sector = (op != OP_ERASE_ALL) ? ((scr & FLASHRAM_SCR_PAGE_MASK) >> FLASHRAM_SCR_PAGE_BIT) : 0;
address += sector * FLASHRAM_PAGE_SIZE;
uint32_t page = (op != OP_ERASE_ALL) ? ((scr & FLASHRAM_SCR_PAGE_MASK) >> FLASHRAM_SCR_PAGE_BIT) : 0;
address += page * FLASHRAM_PAGE_SIZE;
switch (op) {
case OP_ERASE_ALL:

View File

@ -4,90 +4,86 @@
#include "task.h"
#define LED_TICKRATE_MS (10)
#define LED_CYCLE_TICKS_PERIOD (10)
#define LED_CYCLE_TICKS_ON (3)
#define LED_MS_PER_TICK (10)
#define LED_ERROR_TICKS_PERIOD (50)
#define LED_ERROR_TICKS_ON (25)
#define LED_ACT_TICKS_PERIOD (15)
#define LED_ACT_TICKS_ON (6)
typedef enum {
ON,
OFF
} led_state_e;
typedef struct {
uint32_t timer;
led_state_e state;
} error_cycle_t;
static uint32_t timer = 0;
static uint8_t error_cycle = 0;
static uint32_t current_act_counter = 0;
static volatile uint32_t next_act_counter = 0;
static bool error_mode = false;
static uint32_t error_timer = 0;
static volatile bool cic_error = false;
static volatile bool rtc_error = false;
static const error_cycle_t error_codes[2][8] = {
{ { 50, ON }, { 50, OFF }, { 5, ON }, { 0, OFF }, { 0, OFF }, { 0, OFF }, { 0, OFF }, { 100, OFF } },
{ { 50, ON }, { 50, OFF }, { 5, ON }, { 20, OFF }, { 5, ON }, { 0, OFF }, { 0, OFF }, { 100, OFF } },
};
static uint32_t act_timer = 0;
static uint32_t current_act_counter = 0;
static volatile uint32_t next_act_counter = 0;
static void led_task_resume (void) {
task_set_ready(TASK_ID_LED);
}
static bool led_has_errors (void) {
return (cic_error | rtc_error);
}
static void led_process_act (void) {
if (timer > 0) {
timer -= 1;
uint32_t cycle = ((LED_CYCLE_TICKS_PERIOD - 1) - (timer % LED_CYCLE_TICKS_PERIOD));
if (cycle < LED_CYCLE_TICKS_ON) {
hw_gpio_set(GPIO_ID_LED);
} else {
hw_gpio_reset(GPIO_ID_LED);
static void led_update_error_mode (void) {
if (error_mode) {
if (!(cic_error || rtc_error)) {
error_mode = false;
act_timer = 0;
}
} else {
if (current_act_counter != next_act_counter) {
current_act_counter = next_act_counter;
timer = LED_CYCLE_TICKS_PERIOD;
} else {
hw_gpio_reset(GPIO_ID_LED);
if (cic_error || rtc_error) {
error_mode = true;
error_timer = 0;
}
}
}
static void led_process_errors (void) {
if (timer > 0) {
timer -= 1;
} else {
uint8_t error_code = 0;
if (error_timer == 0) {
error_timer = LED_ERROR_TICKS_PERIOD;
if (cic_error) {
error_code = 0;
error_timer *= 1;
} else if (rtc_error) {
error_code = 1;
error_timer *= 2;
}
error_cycle_t error = error_codes[error_code][error_cycle];
timer = error.timer;
if (error.state == ON) {
error_timer += LED_ERROR_TICKS_PERIOD;
}
if (error_timer > 0) {
error_timer -= 1;
if (error_timer >= LED_ERROR_TICKS_PERIOD) {
uint32_t error_cycle = (error_timer % LED_ERROR_TICKS_PERIOD);
if (error_cycle == LED_ERROR_TICKS_ON) {
hw_gpio_set(GPIO_ID_LED);
} else {
}
if (error_cycle == 0) {
hw_gpio_reset(GPIO_ID_LED);
}
error_cycle += 1;
if (error_cycle >= 8) {
error_cycle = 0;
}
}
}
static void led_process_act (void) {
if (act_timer == 0) {
if (current_act_counter != next_act_counter) {
current_act_counter = next_act_counter;
act_timer = LED_ACT_TICKS_PERIOD;
}
}
void led_blink_act (void) {
next_act_counter += 1;
if (act_timer > 0) {
act_timer -= 1;
if (act_timer == LED_ACT_TICKS_ON) {
hw_gpio_set(GPIO_ID_LED);
}
if (act_timer == 0) {
hw_gpio_reset(GPIO_ID_LED);
}
}
}
void led_blink_error (led_error_t error) {
switch (error) {
case LED_ERROR_CIC:
@ -110,14 +106,19 @@ void led_clear_error (led_error_t error) {
}
}
void led_blink_act (void) {
next_act_counter += 1;
}
void led_task (void) {
while (1) {
hw_tim_setup(TIM_ID_LED, LED_TICKRATE_MS, led_task_resume);
hw_tim_setup(TIM_ID_LED, LED_MS_PER_TICK, led_task_resume);
if (led_has_errors()) {
led_update_error_mode();
if (error_mode) {
led_process_errors();
} else {
error_cycle = 0;
led_process_act();
}

View File

@ -8,9 +8,9 @@ typedef enum {
} led_error_t;
void led_blink_act (void);
void led_blink_error (led_error_t error);
void led_clear_error (led_error_t error);
void led_blink_act (void);
void led_task (void);

View File

@ -315,6 +315,7 @@ class SC64:
HEADER = 3
SCREENSHOT = 4
__isv_line_buffer: bytes = b''
__debug_header: Optional[bytes] = None
def __init__(self) -> None:
@ -558,7 +559,10 @@ class SC64:
self.__dd_set_block_ready(1)
def __handle_isv_packet(self, data: bytes) -> None:
print(data.decode('EUC-JP', errors='backslashreplace'), end='')
self.__isv_line_buffer += data
while (b'\n' in self.__isv_line_buffer):
(line, self.__isv_line_buffer) = self.__isv_line_buffer.split(b'\n', 1)
print(line.decode('EUC-JP', errors='backslashreplace'))
def __handle_usb_packet(self, data: bytes) -> None:
header = self.__get_int(data[0:4])