aboutsummaryrefslogtreecommitdiff
path: root/mkmif.c
diff options
context:
space:
mode:
Diffstat (limited to 'mkmif.c')
-rw-r--r--mkmif.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/mkmif.c b/mkmif.c
index 06a2c4b..bc852ef 100644
--- a/mkmif.c
+++ b/mkmif.c
@@ -50,9 +50,11 @@ hal_error_t hal_mkmif_init(hal_core_t *core)
cmd.word = htonl(MKMIF_CTRL_CMD_INIT);
- err = hal_core_alloc(MKMIF_NAME, &core) ||
- hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4) ||
- hal_io_wait_ready(core);
+ if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK)
+ return err;
+
+ if ((err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) == HAL_OK)
+ err = hal_io_wait_ready(core);
hal_core_free(core);
return err;
@@ -65,8 +67,10 @@ hal_error_t hal_mkmif_set_clockspeed(hal_core_t *core, const uint32_t divisor)
data.word = htonl(divisor);
- err = hal_core_alloc(MKMIF_NAME, &core) ||
- hal_io_write(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4);
+ if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK)
+ return err;
+
+ err = hal_io_write(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4);
hal_core_free(core);
return err;
@@ -77,10 +81,10 @@ hal_error_t hal_mkmif_get_clockspeed(hal_core_t *core, uint32_t *divisor)
byteword_t data;
hal_error_t err;
- err = hal_core_alloc(MKMIF_NAME, &core) ||
- hal_io_read(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4);
+ if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK)
+ return err;
- if (err == HAL_OK)
+ if ((err = hal_io_read(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4)) == HAL_OK)
*divisor = htonl(data.word);
hal_core_free(core);
@@ -101,11 +105,11 @@ hal_error_t hal_mkmif_write(hal_core_t *core, uint32_t addr, const uint8_t *buf,
for (; len > 0; addr += 4, buf += 4, len -= 4) {
byteword_t write_addr;
write_addr.word = htonl((uint32_t)addr);
- if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, write_addr.byte, 4)) ||
- (err = hal_io_write(core, MKMIF_ADDR_EMEM_DATA, buf, 4)) ||
- (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) ||
- (err = hal_io_wait_ready(core)))
- return err;
+ if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, write_addr.byte, 4)) != HAL_OK ||
+ (err = hal_io_write(core, MKMIF_ADDR_EMEM_DATA, buf, 4)) != HAL_OK ||
+ (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) != HAL_OK ||
+ (err = hal_io_wait_ready(core)) != HAL_OK)
+ break;
}
}
@@ -132,19 +136,19 @@ hal_error_t hal_mkmif_read(hal_core_t *core, uint32_t addr, uint8_t *buf, size_t
cmd.word = htonl(MKMIF_CTRL_CMD_READ);
- if ((err = hal_core_alloc(MKMIF_NAME, &core)) == HAL_OK) {
- for (; len > 0; addr += 4, buf += 4, len -= 4) {
- byteword_t read_addr;
- read_addr.word = htonl((uint32_t)addr);
- if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, read_addr.byte, 4)) ||
- (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) ||
- (err = hal_io_wait_valid(core)) ||
- (err = hal_io_read(core, MKMIF_ADDR_EMEM_DATA, buf, 4)))
- goto out;
- }
+ if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK)
+ return err;
+
+ for (; len > 0; addr += 4, buf += 4, len -= 4) {
+ byteword_t read_addr;
+ read_addr.word = htonl((uint32_t)addr);
+ if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, read_addr.byte, 4)) != HAL_OK ||
+ (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) != HAL_OK ||
+ (err = hal_io_wait_valid(core)) != HAL_OK ||
+ (err = hal_io_read(core, MKMIF_ADDR_EMEM_DATA, buf, 4)) != HAL_OK)
+ break;
}
-out:
hal_core_free(core);
return err;
}