1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

trezorhal: update sdcard api

This commit is contained in:
Pavol Rusnak 2017-10-20 18:13:17 +02:00
parent 3033762618
commit 4f041e9f3a
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 16 additions and 20 deletions

View File

@ -71,8 +71,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_SDCard_capacity_obj, mod_trezorio_
STATIC mp_obj_t mod_trezorio_SDCard_read(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
mp_uint_t ret = sdcard_read_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE);
return mp_obj_new_bool(ret == 0);
return mp_obj_new_bool(sdcard_read_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_SDCard_read_obj, mod_trezorio_SDCard_read);
@ -85,8 +84,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_SDCard_read_obj, mod_trezorio_SDCa
STATIC mp_obj_t mod_trezorio_SDCard_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
mp_uint_t ret = sdcard_write_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE);
return mp_obj_new_bool(ret == 0);
return mp_obj_new_bool(sdcard_write_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_SDCard_write_obj, mod_trezorio_SDCard_write);

View File

@ -28,10 +28,10 @@ uint64_t sdcard_get_capacity_in_bytes(void) {
return 0;
}
uint32_t sdcard_read_blocks(void *dest, uint32_t block_num, uint32_t num_blocks) {
return SD_ERROR;
bool sdcard_read_blocks(void *dest, uint32_t block_num, uint32_t num_blocks) {
return false;
}
uint32_t sdcard_write_blocks(const void *src, uint32_t block_num, uint32_t num_blocks) {
return SD_ERROR;
bool sdcard_write_blocks(const void *src, uint32_t block_num, uint32_t num_blocks) {
return false;
}

View File

@ -150,15 +150,15 @@ static HAL_StatusTypeDef sdcard_wait_finished(SD_HandleTypeDef *sd, uint32_t tim
return HAL_OK;
}
uint32_t sdcard_read_blocks(void *dest, uint32_t block_num, uint32_t num_blocks) {
bool sdcard_read_blocks(void *dest, uint32_t block_num, uint32_t num_blocks) {
// check that SD card is initialised
if (sd_handle.Instance == NULL) {
return HAL_ERROR;
return false;
}
// check that dest pointer is aligned on a 4-byte boundary
if (((uint32_t)dest & 3) != 0) {
return HAL_ERROR;
return false;
}
HAL_StatusTypeDef err = HAL_OK;
@ -168,18 +168,18 @@ uint32_t sdcard_read_blocks(void *dest, uint32_t block_num, uint32_t num_blocks)
err = sdcard_wait_finished(&sd_handle, 60000);
}
return err;
return err == HAL_OK;
}
uint32_t sdcard_write_blocks(const void *src, uint32_t block_num, uint32_t num_blocks) {
bool sdcard_write_blocks(const void *src, uint32_t block_num, uint32_t num_blocks) {
// check that SD card is initialised
if (sd_handle.Instance == NULL) {
return HAL_ERROR;
return false;
}
// check that src pointer is aligned on a 4-byte boundary
if (((uint32_t)src & 3) != 0) {
return HAL_ERROR;
return false;
}
HAL_StatusTypeDef err = HAL_OK;
@ -189,5 +189,5 @@ uint32_t sdcard_write_blocks(const void *src, uint32_t block_num, uint32_t num_b
err = sdcard_wait_finished(&sd_handle, 60000);
}
return err;
return err == HAL_OK;
}

View File

@ -37,9 +37,7 @@ bool sdcard_is_present(void);
bool sdcard_power_on(void);
bool sdcard_power_off(void);
uint64_t sdcard_get_capacity_in_bytes(void);
// these return 0 on success, non-zero on error
uint32_t sdcard_read_blocks(void *dest, uint32_t block_num, uint32_t num_blocks);
uint32_t sdcard_write_blocks(const void *src, uint32_t block_num, uint32_t num_blocks);
bool sdcard_read_blocks(void *dest, uint32_t block_num, uint32_t num_blocks);
bool sdcard_write_blocks(const void *src, uint32_t block_num, uint32_t num_blocks);
#endif