Skip to content

Commit

Permalink
Move comm_megawifi tick handler registration to comm_megawifi_init()
Browse files Browse the repository at this point in the history
Another day of being eternally confused by the `s8` conflict without `#include <stdint.h>` in certain places.
  • Loading branch information
rhargreaves committed Mar 30, 2024
1 parent 90ce5d8 commit 4ac3ec6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/applemidi.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <stdint.h>
#include <ext/mw/megawifi.h>

#define ERR_BASE 100
Expand Down
3 changes: 3 additions & 0 deletions src/comm_megawifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "memory.h"
#include "ip_util.h"
#include <task.h>
#include "scheduler.h"

#define UDP_CONTROL_PORT 5006
#define UDP_MIDI_PORT (UDP_CONTROL_PORT + 1)
Expand Down Expand Up @@ -111,6 +112,8 @@ static void tasking_init(void)

void comm_megawifi_init(void)
{
scheduler_addTickHandler(*comm_megawifi_tick);

status = NotDetected;
enum mw_err err = mw_init(cmd_buf, MW_BUFLEN);
if (err != MW_ERR_NONE) {
Expand Down
1 change: 1 addition & 0 deletions src/comm_megawifi.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <stdint.h>
#include <types.h>

void comm_megawifi_init(void);
Expand Down
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

static void registerSchedulerHandlers()
{
scheduler_addTickHandler(*comm_megawifi_tick);
scheduler_addTickHandler(*midi_receiver_read_if_comm_ready);
scheduler_addFrameHandler(*midi_psg_tick);
scheduler_addFrameHandler(*ui_update);
Expand Down
1 change: 0 additions & 1 deletion src/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ void scheduler_vsync(void);
void scheduler_tick(void);
void scheduler_run(void);
u16 scheduler_ticks(void);

void scheduler_addTickHandler(HandlerFunc* onTick);
void scheduler_addFrameHandler(HandlerFunc* onFrame);
2 changes: 2 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ MOCKS=midi_process \
ui_update \
scheduler_init \
scheduler_tick \
scheduler_addTickHandler \
scheduler_addFrameHandler \
comm_megawifi_midiEmitCallback \
comm_megawifi_init \
comm_megawifi_tick \
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_comm_megawifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static void expect_ip_log(void)

static void megawifi_init(void)
{
expect_function_call(__wrap_scheduler_addTickHandler);
expect_mw_init();
expect_mw_detect();
expect_ap_connection();
Expand Down
19 changes: 10 additions & 9 deletions tests/unit/test_scheduler.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "cmocka_inc.h"

#include "scheduler.h"

extern void __real_scheduler_init(void);
extern void __real_scheduler_tick(void);
extern void __real_scheduler_addTickHandler(HandlerFunc* onTick);
extern void __real_scheduler_addFrameHandler(HandlerFunc* onFrame);

static void dummy_frame_handler()
{
Expand Down Expand Up @@ -40,8 +41,8 @@ static void test_scheduler_nothing_called_on_vsync(UNUSED void** state)
static void test_scheduler_processes_frame_events_once_after_vsync(
UNUSED void** state)
{
scheduler_addFrameHandler(*dummy_frame_handler);
scheduler_addTickHandler(*dummy_tick_handler);
__real_scheduler_addFrameHandler(*dummy_frame_handler);
__real_scheduler_addTickHandler(*dummy_tick_handler);

expect_function_call(dummy_tick_handler);
__real_scheduler_tick();
Expand All @@ -58,7 +59,7 @@ static void test_scheduler_registered_frame_handler_called_on_vsync(
{
scheduler_vsync();

scheduler_addFrameHandler(*dummy_frame_handler);
__real_scheduler_addFrameHandler(*dummy_frame_handler);

expect_function_call(dummy_frame_handler);
__real_scheduler_tick();
Expand All @@ -69,8 +70,8 @@ static void test_scheduler_multiple_registered_frame_handlers_called_on_vsync(
{
scheduler_vsync();

scheduler_addFrameHandler(*dummy_frame_handler);
scheduler_addFrameHandler(*dummy_frame_handler_2);
__real_scheduler_addFrameHandler(*dummy_frame_handler);
__real_scheduler_addFrameHandler(*dummy_frame_handler_2);

expect_function_call(dummy_frame_handler);
expect_function_call(dummy_frame_handler_2);
Expand All @@ -79,7 +80,7 @@ static void test_scheduler_multiple_registered_frame_handlers_called_on_vsync(

static void test_scheduler_registered_tick_handler_called(UNUSED void** state)
{
scheduler_addTickHandler(*dummy_tick_handler);
__real_scheduler_addTickHandler(*dummy_tick_handler);

expect_function_call(dummy_tick_handler);
__real_scheduler_tick();
Expand All @@ -90,8 +91,8 @@ static void test_scheduler_multiple_registered_tick_handlers_called(
{
scheduler_vsync();

scheduler_addFrameHandler(*dummy_tick_handler);
scheduler_addFrameHandler(*dummy_tick_handler_2);
__real_scheduler_addFrameHandler(*dummy_tick_handler);
__real_scheduler_addFrameHandler(*dummy_tick_handler_2);

expect_function_call(dummy_tick_handler);
expect_function_call(dummy_tick_handler_2);
Expand Down
10 changes: 10 additions & 0 deletions tests/wraps.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,16 @@ void __wrap_scheduler_tick(void)
function_called();
}

void __wrap_scheduler_addTickHandler(HandlerFunc* onTick)
{
function_called();
}

void __wrap_scheduler_addFrameHandler(HandlerFunc* onFrame)
{
function_called();
}

void __wrap_comm_megawifi_tick(void)
{
function_called();
Expand Down
4 changes: 4 additions & 0 deletions tests/wraps.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ext/mw/megawifi.h>
#include "log.h"
#include "synth.h"
#include "scheduler.h"
#include <vdp_bg.h>

typedef enum mw_err mw_err;
Expand Down Expand Up @@ -167,6 +168,9 @@ mw_err __wrap_mw_sock_conn_wait(uint8_t ch, int tout_frames);

void __wrap_midi_receiver_read_if_comm_ready(void);
void __wrap_scheduler_tick(void);
void __wrap_scheduler_addTickHandler(HandlerFunc* onTick);
void __wrap_scheduler_addFrameHandler(HandlerFunc* onFrame);

void __wrap_comm_megawifi_tick(void);
void __wrap_comm_megawifi_send(u8 ch, char* data, u16 len);

Expand Down

0 comments on commit 4ac3ec6

Please sign in to comment.