Core rebalance

Fixes stability and dedicates core0 for LPC handlers with core0_poll removed.
This commit is contained in:
markt31
2026-06-26 06:52:27 -04:00
parent bc9cd536d4
commit eb023e81b3
6 changed files with 36 additions and 36 deletions
+4 -7
View File
@@ -33,7 +33,6 @@ Copyright (c) 2024, Shalx <Alejandro L. Huitron shalxmva@gmail.com>
typedef enum {
mxt_fn_init,
mxt_fn_powerup,
mxt_fn_core0_poll,
mxt_fn_core1_poll,
mxt_fn_lpc_reset_on,
mxt_fn_lpc_reset_off,
@@ -43,12 +42,11 @@ typedef enum {
typedef struct {
void (*init)(void);
void (*powerup)(void);
void (*core0_poll)(void);
void (*powerup)(void); // Runs on core0, triggers off LPC_ON
void (*core1_poll)(void);
void (*lpc_reset_on)(void);
void (*lpc_reset_off)(void);
void (*shutdown)(void);
void (*lpc_reset_on)(void); // Runs on core1, triggers off LPC_RESET
void (*lpc_reset_off)(void); // Runs on core1, triggers off LPC_RESET
void (*shutdown)(void); // Runs on core0, triggers off LPC_ON
void (*core1_init)(void);
} MODXO_TASK;
@@ -63,7 +61,6 @@ void modxo_register_handler(MODXO_TASK* handler);
void modxo_reset(void);
void modxo_init(void);
void modxo_poll_core1(void);
void modxo_poll_core0(void);
void modxo_lpc_reset_off(void);
void modxo_lpc_reset_on(void);
void modxo_shutdown(void);
-2
View File
@@ -277,7 +277,6 @@ void lpc_interface_set_callback(LPC_OP_TYPE op, lpc_handler_cback cback)
void lpc_interface_start_sm()
{
pio_set_sm_mask_enabled(_pio, 15, false); // Disable All State Machines
pio_custom_init(_pio, LPC_OP_MEM_READ, offset, _disable_internal_flash);
pio_custom_init(_pio, LPC_OP_MEM_WRITE, offset, _disable_internal_flash);
@@ -300,7 +299,6 @@ void lpc_interface_reset(void)
void lpc_interface_init(void)
{
_pio = pio0;
pio_claim_sm_mask(_pio, 15);
+1 -6
View File
@@ -80,11 +80,6 @@ void modxo_poll_core1()
run_modxo_handlers(mxt_fn_core1_poll);
}
void modxo_poll_core0()
{
run_modxo_handlers(mxt_fn_core0_poll);
}
void modxo_lpc_reset_off()
{
run_modxo_handlers(mxt_fn_lpc_reset_off);
@@ -117,7 +112,7 @@ void modxo_shutdown()
void modxo_reset()
{
run_modxo_handlers(mxt_fn_powerup);//Modxo after LPC 3.3v goes high
run_modxo_handlers(mxt_fn_powerup); // Modxo after LPC 3.3v goes high
}
void modxo_init(void)
+1 -1
View File
@@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <hardware/flash.h>
#define MODXO_BANK_BOOTLOADER 0x01
#define STORAGE_CMD_TOTAL_BYTES 64
#define STORAGE_CMD_TOTAL_BYTES 8
+6 -3
View File
@@ -722,7 +722,7 @@ static void ws2812_set_color(uint8_t color) {
select_command(CMD_UPDATE_STRIPS);
}
static void ws2812_init()
static void ws2812_core1_init()
{
selected_strip = 0;
updating_strips = false;
@@ -760,15 +760,18 @@ static void ws2812_init()
}
}
ws2812_update_pixels();
}
static void ws2812_init() {
lpc_interface_add_io_handler(WS2812_PORT_BASE, WS2812_ADDRESS_MASK, lpc_port_read, lpc_port_write);
lpc_interface_add_io_handler(MODXO_REGISTER_NVM_CONFIG_SEL, 0xFFFE, config_read_hdlr, config_write_hdlr);
ws2812_update_pixels();
}
MODXO_TASK ws2812_hdlr = {
.init = ws2812_init,
.core1_init = ws2812_core1_init,
.powerup = ws2812_update_pixels,
.core1_poll = ws2812_poll,
.lpc_reset_on = lpc_reset_on,
+24 -17
View File
@@ -61,6 +61,8 @@ uint8_t nvm_total_registers = sizeof(nvm_registers) / sizeof(nvm_registers[0]);
bool reset_pin = false;
bool xbox_active = false;
void modxo_init_interrupts_core1();
void core1_main()
{
while (true)
@@ -76,15 +78,13 @@ void core0_main()
{
while (true)
{
if(xbox_active) {
modxo_poll_core0();
}
__wfe();
__wfi();
}
}
void core1_init() {
run_modxo_handlers(mxt_fn_core1_init);
modxo_init_interrupts_core1();
core1_main(); // Infinite loop
}
@@ -122,6 +122,20 @@ void pin_3_3v_high()
}
void core0_irq_handler(uint gpio, uint32_t event)
{
if (gpio == LPC_ON && (event & GPIO_IRQ_EDGE_FALL) != 0)
{
pin_3_3v_falling();
}
// Use LEVEL_HIGH because rising edge has already passed by the time we get here
if (gpio == LPC_ON && (event & GPIO_IRQ_LEVEL_HIGH) != 0)
{
pin_3_3v_high();
}
}
void core1_irq_handler(uint gpio, uint32_t event)
{
if (gpio == LPC_RESET && (event & GPIO_IRQ_EDGE_FALL) != 0)
{
@@ -132,17 +146,6 @@ void core0_irq_handler(uint gpio, uint32_t event)
{
reset_pin_rising();
}
if (gpio == LPC_ON && (event & GPIO_IRQ_EDGE_FALL) != 0)
{
pin_3_3v_falling();
}
// Use LEVEL_HIGH because rising edge triggers too early after power-up (~500us)
if (gpio == LPC_ON && (event & GPIO_IRQ_LEVEL_HIGH) != 0)
{
pin_3_3v_high();
}
}
void modxo_init_pin_irq(uint pin, uint32_t event)
@@ -156,9 +159,13 @@ void modxo_init_pin_irq(uint pin, uint32_t event)
void modxo_init_interrupts()
{
gpio_set_irq_callback(core0_irq_handler);
modxo_init_pin_irq(LPC_RESET, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE);
modxo_init_pin_irq(LPC_ON, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_LEVEL_HIGH);
irq_set_enabled(IO_IRQ_BANK0, true);
}
void modxo_init_interrupts_core1() {
gpio_set_irq_callback(core1_irq_handler);
modxo_init_pin_irq(LPC_RESET, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE);
irq_set_enabled(IO_IRQ_BANK0, true);
}
@@ -197,7 +204,7 @@ uint8_t get_flash_spi_clkdiv() {
break;
}
return 4; // Default to CLKDIV=4, should be compatible with most flash chips
return 4; // Default to CLKDIV=4, should be compatible with most flash chips, should be 66MHz SPI CLK
}
void detect_and_upgrade_flash_speed() {