Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add i2c write request callback #522

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/rtos_drivers/hil/src/individual_tests/i2c/i2c_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ void i2c_slave_rx_byte_check(rtos_i2c_slave_t *ctx, void *app_data, uint8_t data
}
}

RTOS_I2C_SLAVE_WRITE_ADDR_REQUEST_CALLBACK_ATTR
void i2c_slave_write_addr_req(rtos_i2c_slave_t *ctx, void *app_data, i2c_slave_ack_t *cur_status)
{
i2c_test_ctx_t *test_ctx = (i2c_test_ctx_t*)ctx->app_data;
if (test_ctx->slave_write_addr_req[test_ctx->cur_test] != NULL)
{
I2C_SLAVE_WRITE_ADDR_REQ_ATTR i2c_slave_write_addr_req_cb_t fn;
fn = test_ctx->slave_write_addr_req[test_ctx->cur_test];
fn(ctx, app_data, cur_status);
} else {
i2c_printf("SLAVE missing slave_write_addr_req callback on test %d", test_ctx->cur_test);
}
}

#endif /* ON_TILE(1) */

static int run_i2c_tests(i2c_test_ctx_t *test_ctx, chanend_t c)
Expand Down Expand Up @@ -131,6 +145,7 @@ static void start_i2c_devices(i2c_test_ctx_t *test_ctx)
i2c_slave_tx_start,
i2c_slave_tx_done,
i2c_slave_rx_byte_check,
i2c_slave_write_addr_req,
I2C_SLAVE_ISR_CORE,
configMAX_PRIORITIES-1);
#endif
Expand Down
3 changes: 3 additions & 0 deletions test/rtos_drivers/hil/src/individual_tests/i2c/i2c_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define I2C_SLAVE_TX_START_ATTR __attribute__((fptrgroup("rtos_test_i2c_slave_tx_start_fptr_grp")))
#define I2C_SLAVE_TX_DONE_ATTR __attribute__((fptrgroup("rtos_test_i2c_slave_tx_done_fptr_grp")))
#define I2C_SLAVE_RX_BYTE_CHECK_ATTR __attribute__((fptrgroup("rtos_test_i2c_slave_rx_byte_check_fptr_grp")))
#define I2C_SLAVE_WRITE_ADDR_REQ_ATTR __attribute__((fptrgroup("rtos_test_i2c_slave_write_addr_check_fptr_grp")))

typedef struct i2c_test_ctx i2c_test_ctx_t;

Expand All @@ -32,13 +33,15 @@ struct i2c_test_ctx {
I2C_SLAVE_TX_START_ATTR size_t (*slave_tx_start[I2C_MAX_TESTS])(rtos_i2c_slave_t *ctx, void *app_data, uint8_t **data);
I2C_SLAVE_TX_DONE_ATTR void (*slave_tx_done[I2C_MAX_TESTS])(rtos_i2c_slave_t *ctx, void *app_data, uint8_t *data, size_t len);
I2C_SLAVE_RX_BYTE_CHECK_ATTR void (*slave_rx_check_byte[I2C_MAX_TESTS])(rtos_i2c_slave_t *ctx, void *app_data, uint8_t data, i2c_slave_ack_t *cur_status);
I2C_SLAVE_WRITE_ADDR_REQ_ATTR void (*slave_write_addr_req[I2C_MAX_TESTS])(rtos_i2c_slave_t *ctx, void *app_data, i2c_slave_ack_t *cur_status);
};

typedef int (*i2c_main_test_t)(i2c_test_ctx_t *ctx);
typedef void (*i2c_slave_rx_t)(rtos_i2c_slave_t *ctx, void *app_data, uint8_t *data, size_t len);
typedef size_t (*i2c_slave_tx_start_t)(rtos_i2c_slave_t *ctx, void *app_data, uint8_t **data);
typedef void (*i2c_slave_tx_done_t)(rtos_i2c_slave_t *ctx, void *app_data, uint8_t *data, size_t len);
typedef void (*i2c_slave_rx_byte_check_cb_t)(rtos_i2c_slave_t *ctx, void *app_data, uint8_t data, i2c_slave_ack_t *cur_status);
typedef void (*i2c_slave_write_addr_req_cb_t)(rtos_i2c_slave_t *ctx, void *app_data, i2c_slave_ack_t *cur_status);

int i2c_device_tests(rtos_i2c_master_t *i2c_master_ctx, rtos_i2c_slave_t *i2c_slave_ctx, chanend_t c);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void register_master_read_multiple_test(i2c_test_ctx_t *test_ctx)
test_ctx->slave_tx_start[this_test_num] = slave_tx_start;
test_ctx->slave_tx_done[this_test_num] = slave_tx_done;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(I2C_MASTER_TILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void register_master_read_test(i2c_test_ctx_t *test_ctx)
test_ctx->slave_tx_start[this_test_num] = slave_tx_start;
test_ctx->slave_tx_done[this_test_num] = slave_tx_done;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(I2C_MASTER_TILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void register_master_reg_read_test(i2c_test_ctx_t *test_ctx)
test_ctx->slave_tx_start[this_test_num] = slave_tx_start;
test_ctx->slave_tx_done[this_test_num] = slave_tx_done;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(I2C_MASTER_TILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static reg_test_t test_vector[I2C_MASTER_REG_WRITE_TEST_ITER] =

#if ON_TILE(I2C_SLAVE_TILE)
static uint32_t test_slave_iters = 0;
static uint32_t test_slave_requests = 0;
#endif

I2C_MAIN_TEST_ATTR
Expand Down Expand Up @@ -79,6 +80,11 @@ static int main_test(i2c_test_ctx_t *ctx)
local_printf("SLAVE failed");
return -1;
}

if ((test_slave_requests) != test_slave_iters) {
local_printf("SLAVE failed");
return -1;
}
}
#endif

Expand Down Expand Up @@ -117,6 +123,13 @@ static void slave_rx_byte_check(rtos_i2c_slave_t *ctx, void *app_data, uint8_t d
{
local_printf("SLAVE rx byte check 0x%x status %d", data, *cur_status);
}

I2C_SLAVE_WRITE_ADDR_REQ_ATTR
static void slave_write_addr_req(rtos_i2c_slave_t *ctx, void *app_data, i2c_slave_ack_t *cur_status)
{
test_slave_requests++;
local_printf("SLAVE write request %d", test_slave_requests);
}
#endif

void register_master_reg_write_test(i2c_test_ctx_t *test_ctx)
Expand All @@ -131,6 +144,7 @@ void register_master_reg_write_test(i2c_test_ctx_t *test_ctx)
#if ON_TILE(I2C_SLAVE_TILE)
test_ctx->slave_rx[this_test_num] = slave_rx;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = slave_write_addr_req;
#endif

#if ON_TILE(I2C_MASTER_TILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void register_master_write_multiple_test(i2c_test_ctx_t *test_ctx)
#if ON_TILE(I2C_SLAVE_TILE)
test_ctx->slave_rx[this_test_num] = slave_rx;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(I2C_MASTER_TILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void register_master_write_test(i2c_test_ctx_t *test_ctx)
#if ON_TILE(I2C_SLAVE_TILE)
test_ctx->slave_rx[this_test_num] = slave_rx;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(I2C_MASTER_TILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void register_rpc_master_read_multiple_test(i2c_test_ctx_t *test_ctx)
test_ctx->slave_tx_start[this_test_num] = slave_tx_start;
test_ctx->slave_tx_done[this_test_num] = slave_tx_done;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void register_rpc_master_read_test(i2c_test_ctx_t *test_ctx)
test_ctx->slave_tx_start[this_test_num] = slave_tx_start;
test_ctx->slave_tx_done[this_test_num] = slave_tx_done;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void register_rpc_master_reg_read_test(i2c_test_ctx_t *test_ctx)
test_ctx->slave_tx_start[this_test_num] = slave_tx_start;
test_ctx->slave_tx_done[this_test_num] = slave_tx_done;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static reg_test_t test_vector[I2C_MASTER_REG_WRITE_TEST_ITER] =

#if ON_TILE(I2C_SLAVE_TILE)
static uint32_t test_slave_iters = 0;
static uint32_t test_slave_requests = 0;
#endif

I2C_MAIN_TEST_ATTR
Expand Down Expand Up @@ -79,6 +80,11 @@ static int main_test(i2c_test_ctx_t *ctx)
local_printf("SLAVE failed");
return -1;
}

if ((test_slave_requests) != test_slave_iters) {
local_printf("SLAVE failed");
return -1;
}
}
#endif

Expand Down Expand Up @@ -117,6 +123,13 @@ static void slave_rx_byte_check(rtos_i2c_slave_t *ctx, void *app_data, uint8_t d
{
local_printf("SLAVE rx byte check 0x%x status %d", data, *cur_status);
}

I2C_SLAVE_WRITE_ADDR_REQ_ATTR
static void slave_write_addr_req(rtos_i2c_slave_t *ctx, void *app_data, i2c_slave_ack_t *cur_status)
{
test_slave_requests++;
local_printf("SLAVE write request %d", test_slave_requests);
}
#endif

void register_rpc_master_reg_write_test(i2c_test_ctx_t *test_ctx)
Expand All @@ -131,6 +144,7 @@ void register_rpc_master_reg_write_test(i2c_test_ctx_t *test_ctx)
#if ON_TILE(I2C_SLAVE_TILE)
test_ctx->slave_rx[this_test_num] = slave_rx;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = slave_write_addr_req;
#endif

#if ON_TILE(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void register_rpc_master_write_multiple_test(i2c_test_ctx_t *test_ctx)
#if ON_TILE(I2C_SLAVE_TILE)
test_ctx->slave_rx[this_test_num] = slave_rx;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void register_rpc_master_write_test(i2c_test_ctx_t *test_ctx)
#if ON_TILE(I2C_SLAVE_TILE)
test_ctx->slave_rx[this_test_num] = slave_rx;
test_ctx->slave_rx_check_byte[this_test_num] = slave_rx_byte_check;
test_ctx->slave_write_addr_req[this_test_num] = NULL;
#endif

#if ON_TILE(0)
Expand Down