mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/sdcard_spi: use of ucrc16 by default
Useless consts removed.
This commit is contained in:
parent
f8070edb05
commit
32ae17256c
@ -271,6 +271,7 @@ endif
|
||||
ifneq (,$(filter sdcard_spi,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_gpio
|
||||
FEATURES_REQUIRED += periph_spi
|
||||
USEMODULE += checksum
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "sdcard_spi_params.h"
|
||||
#include "periph/spi.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "checksum/ucrc16.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -45,9 +46,6 @@ static sd_rw_response_t _write_data_packet(sdcard_spi_t *card, char token, const
|
||||
/* CRC-7 (polynomial: x^7 + x^3 + 1) LSB of CRC-7 in a 8-bit variable is always 1*/
|
||||
static char _crc_7(const char *data, int n);
|
||||
|
||||
/* CRC-16 (CRC-CCITT) (polynomial: x^16 + x^12 + x^5 + x^1) */
|
||||
static uint16_t _crc_16(const char *data, size_t n);
|
||||
|
||||
/* use this transfer method instead of _transfer_bytes to force the use of 0xFF as dummy bytes */
|
||||
static inline int _transfer_bytes(sdcard_spi_t *card, const char *out, char *in, unsigned int length);
|
||||
|
||||
@ -412,20 +410,6 @@ static char _crc_7(const char *data, int n)
|
||||
return (crc << 1) | 1;
|
||||
}
|
||||
|
||||
static uint16_t _crc_16(const char *data, size_t n)
|
||||
{
|
||||
uint16_t crc = 0;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
crc = (uint8_t)(crc >> 8) | (crc << 8);
|
||||
crc ^= data[i];
|
||||
crc ^= (uint8_t)(crc & 0xFF) >> 4;
|
||||
crc ^= crc << 12;
|
||||
crc ^= (crc & 0xFF) << 5;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
char sdcard_spi_send_cmd(sdcard_spi_t *card, char sd_cmd_idx, uint32_t argument, int32_t max_retry)
|
||||
{
|
||||
int try_cnt = 0;
|
||||
@ -622,9 +606,9 @@ static sd_rw_response_t _read_data_packet(sdcard_spi_t *card, char token, char *
|
||||
|
||||
char crc_bytes[2];
|
||||
if (_transfer_bytes(card, 0, crc_bytes, sizeof(crc_bytes)) == sizeof(crc_bytes)) {
|
||||
uint16_t data__crc_16 = (crc_bytes[0] << 8) | crc_bytes[1];
|
||||
uint16_t data_crc16 = (crc_bytes[0] << 8) | crc_bytes[1];
|
||||
|
||||
if (_crc_16(data, size) == data__crc_16) {
|
||||
if (ucrc16_calc_be((uint8_t *)data, size, UCRC16_CCITT_POLY_BE, 0) == data_crc16) {
|
||||
DEBUG("_read_data_packet: [OK]\n");
|
||||
return SD_RW_OK;
|
||||
}
|
||||
@ -712,8 +696,8 @@ static sd_rw_response_t _write_data_packet(sdcard_spi_t *card, char token, const
|
||||
|
||||
if (_transfer_bytes(card, data, 0, size) == size) {
|
||||
|
||||
uint16_t data__crc_16 = _crc_16(data, size);
|
||||
char crc[sizeof(uint16_t)] = { data__crc_16 >> 8, data__crc_16 & 0xFF };
|
||||
uint16_t data_crc16 = ucrc16_calc_be((uint8_t *)data, size, UCRC16_CCITT_POLY_BE, 0);
|
||||
char crc[sizeof(uint16_t)] = { data_crc16 >> 8, data_crc16 & 0xFF };
|
||||
|
||||
if (_transfer_bytes(card, crc, 0, sizeof(crc)) == sizeof(crc)) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user