Skip to content

Commit 3477ccb

Browse files
committed
ports: analog: Improve supervisor portability in GPIO init
- Add gpio_init function to normalize disparate GPIO_Init usage of port parameter - Modify ticks usage in interrupt_after_ticks to fix possible zero result from integer division Signed-off-by: Brandon-Hurst <brandon.hurst97@gmail.com>
1 parent 5e94915 commit 3477ccb

8 files changed

Lines changed: 31 additions & 4 deletions

File tree

ports/analog/max32_port.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "system_max32690.h"
2323
#include "max32690.h"
2424

25+
// GPIO ports & initialization
26+
#include "peripherals/max32690/gpios.h"
27+
2528
// UART Ports & pins
2629
#include "peripherals/max32690/max32_uart.h"
2730
#include "peripherals/max32690/max32_i2c.h"
@@ -66,7 +69,10 @@
6669
// 12-bit ssec register, ticks @ 4096 Hz
6770
#define SUBSEC_PER_TICK 4
6871

69-
// UART Ports & pins
72+
// GPIO ports & initialization
73+
#include "peripherals/max32650/gpios.h"
74+
75+
// BUSIO Ports & pins
7076
#include "peripherals/max32650/max32_uart.h"
7177
#include "peripherals/max32650/max32_i2c.h"
7278
#include "peripherals/max32650/max32_spi.h"
@@ -79,7 +85,10 @@
7985
// 12-bit ssec register, ticks @ 4096 Hz
8086
#define SUBSEC_PER_TICK 4
8187

82-
// UART Ports & pins
88+
// GPIO ports & initialization
89+
#include "peripherals/max32665/gpios.h"
90+
91+
// BUSIO Ports & pins
8392
#include "peripherals/max32665/max32_uart.h"
8493
#include "peripherals/max32665/max32_i2c.h"
8594
#include "peripherals/max32665/max32_spi.h"

ports/analog/peripherals/max32650/gpios.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88

99
volatile mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] =
1010
{MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3};
11+
12+
int32_t gpio_init(uint32_t port) {
13+
return MXC_GPIO_Init(port);
14+
}

ports/analog/peripherals/max32650/gpios.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
#include "gpio.h"
1414
#include "gpio_regs.h"
1515
#include "max32650.h"
16+
17+
int32_t gpio_init(uint32_t port);

ports/analog/peripherals/max32665/gpios.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88

99
volatile mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] =
1010
{MXC_GPIO0, MXC_GPIO1};
11+
12+
int32_t gpio_init(uint32_t port) {
13+
return MXC_GPIO_Init(1 << port);
14+
}

ports/analog/peripherals/max32665/gpios.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
#include "gpio.h"
1414
#include "gpio_regs.h"
1515
#include "max32665.h"
16+
17+
int32_t gpio_init(uint32_t portmask);

ports/analog/peripherals/max32690/gpios.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88

99
volatile mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] =
1010
{MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4};
11+
12+
int32_t gpio_init(uint32_t port) {
13+
return MXC_GPIO_Init(1 << port);
14+
}

ports/analog/peripherals/max32690/gpios.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
#include "gpio.h"
1414
#include "gpio_regs.h"
1515
#include "max32690.h"
16+
17+
int32_t gpio_init(uint32_t portmask);

ports/analog/supervisor/port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ safe_mode_t port_init(void) {
124124

125125
// Enable GPIO (enables clocks + common init for ports)
126126
for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) {
127-
err = MXC_GPIO_Init(0x1 << i);
127+
err = gpio_init(i);
128128
if (err) {
129129
return SAFE_MODE_PROGRAMMATIC;
130130
}
@@ -282,7 +282,7 @@ void port_disable_tick(void) {
282282
void port_interrupt_after_ticks(uint32_t ticks) {
283283
uint32_t ticks_msec = 0;
284284

285-
ticks_msec = (ticks / TICKS_PER_SEC) * 1000;
285+
ticks_msec = ((ticks * 1000) / TICKS_PER_SEC);
286286

287287
// Disable RTC interrupts
288288
MXC_RTC_DisableInt(SSEC_ENABLE | TOD_ENABLE | RDY_ENABLE);

0 commit comments

Comments
 (0)