1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #13886 from benpicco/drivers/at25xxx_api_conformity

drivers/at25xxx: return read/written bytes to match MTD API
This commit is contained in:
Marian Buschsieweke 2020-04-17 12:52:16 +02:00 committed by GitHub
commit 32694e0931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 15 deletions

View File

@ -113,7 +113,7 @@ static ssize_t _write_page(const at25xxx_t *dev, uint32_t pos, const void *data,
int at25xxx_write(const at25xxx_t *dev, uint32_t pos, const void *data, size_t len)
{
int res = 0;
int res = len;
const uint8_t *d = data;
if (pos + len > dev->params.size) {
@ -164,7 +164,7 @@ int at25xxx_read(const at25xxx_t *dev, uint32_t pos, void *data, size_t len)
spi_release(dev->params.spi);
return 0;
return len;
}
uint8_t at25xxx_read_byte(const at25xxx_t *dev, uint32_t pos)

View File

@ -82,7 +82,7 @@ uint8_t at25xxx_read_byte(const at25xxx_t *dev, uint32_t pos);
* @param[out] data read buffer
* @param[in] len requested length to be read
*
* @return 0 on success
* @return Number of bytes read
* @return -ERANGE if pos + len > EEPROM size
*/
int at25xxx_read(const at25xxx_t *dev, uint32_t pos, void *data, size_t len);
@ -104,7 +104,7 @@ void at25xxx_write_byte(const at25xxx_t *dev, uint32_t pos, uint8_t data);
* @param[in] data write buffer
* @param[in] len requested length to be written
*
* @return 0 on success
* @return Number of bytes written
* @return -ERANGE if pos + len > EEPROM size
*/
int at25xxx_write(const at25xxx_t *dev, uint32_t pos, const void *data, size_t len);

View File

@ -34,12 +34,12 @@ static void test_normal_write(void)
const char data_in_b[] = "This is a test.";
char data_out[32];
TEST_ASSERT_EQUAL_INT(0, at25xxx_write(&dev, 0, data_in_a, sizeof(data_in_a)));
TEST_ASSERT_EQUAL_INT(0, at25xxx_read(&dev, 0, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(sizeof(data_in_a), at25xxx_write(&dev, 0, data_in_a, sizeof(data_in_a)));
TEST_ASSERT_EQUAL_INT(sizeof(data_out), at25xxx_read(&dev, 0, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_STRING(data_in_a, data_out);
TEST_ASSERT_EQUAL_INT(0, at25xxx_write(&dev, 0, data_in_b, sizeof(data_in_b)));
TEST_ASSERT_EQUAL_INT(0, at25xxx_read(&dev, 0, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(sizeof(data_in_b), at25xxx_write(&dev, 0, data_in_b, sizeof(data_in_b)));
TEST_ASSERT_EQUAL_INT(sizeof(data_out), at25xxx_read(&dev, 0, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_STRING(data_in_b, data_out);
}
@ -49,12 +49,16 @@ static void test_page_write(void)
const char data_in_b[] = "This is a test.";
char data_out[32];
TEST_ASSERT_EQUAL_INT(0, at25xxx_write(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_in_a, sizeof(data_in_a)));
TEST_ASSERT_EQUAL_INT(0, at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(sizeof(data_in_a),
at25xxx_write(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_in_a, sizeof(data_in_a)));
TEST_ASSERT_EQUAL_INT(sizeof(data_out),
at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_STRING(data_in_a, data_out);
TEST_ASSERT_EQUAL_INT(0, at25xxx_write(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_in_b, sizeof(data_in_b)));
TEST_ASSERT_EQUAL_INT(0, at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(sizeof(data_in_b),
at25xxx_write(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_in_b, sizeof(data_in_b)));
TEST_ASSERT_EQUAL_INT(sizeof(data_out),
at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_STRING(data_in_b, data_out);
}
@ -66,12 +70,15 @@ static void test_page_clear(void)
memset(data_clr, 0, sizeof(data_clr));
TEST_ASSERT_EQUAL_INT(0, at25xxx_write(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_in_a, sizeof(data_in_a)));
TEST_ASSERT_EQUAL_INT(0, at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(sizeof(data_in_a),
at25xxx_write(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_in_a, sizeof(data_in_a)));
TEST_ASSERT_EQUAL_INT(sizeof(data_out),
at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_STRING(data_in_a, data_out);
TEST_ASSERT_EQUAL_INT(0, at25xxx_clear(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(0, at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(sizeof(data_out),
at25xxx_read(&dev, AT25XXX_PARAM_PAGE_SIZE - 5, data_out, sizeof(data_out)));
TEST_ASSERT_EQUAL_INT(0, memcmp(data_out, data_clr, sizeof(data_clr)));
}