Public Access
sd card: what the card says it is, from its CID register
Type, size, and the identity register read by our SD driver (CMD10): manufacturer, OEM, product name, revision, serial and date, decoded by a host-tested parser. Needed for the upstream report of #21: nothing else here could read the card's identity. This one is a Samsung 8 GB SDHC from June 2013. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#include <unity.h>
|
||||
|
||||
#include "sd_card_id.h"
|
||||
|
||||
using namespace roro;
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
// A SanDisk 8 GB card's CID: manufacturer 0x03, OEM "SD", product "SU08G", revision 8.0,
|
||||
// serial 0x1234ABCD, made in March 2014.
|
||||
static const uint8_t kSanDisk[16] = {0x03, 'S', 'D', 'S', 'U', '0', '8', 'G', 0x80,
|
||||
0x12, 0x34, 0xAB, 0xCD, 0x00, 0xE3, 0xFF};
|
||||
|
||||
void test_fields() {
|
||||
SdCardId id = parseSdCid(kSanDisk);
|
||||
TEST_ASSERT_EQUAL_HEX8(0x03, id.manufacturer);
|
||||
TEST_ASSERT_EQUAL_STRING("SD", id.oem);
|
||||
TEST_ASSERT_EQUAL_STRING("SU08G", id.product);
|
||||
TEST_ASSERT_EQUAL_UINT8(8, id.revisionMajor);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, id.revisionMinor);
|
||||
TEST_ASSERT_EQUAL_HEX32(0x1234ABCD, id.serial);
|
||||
TEST_ASSERT_EQUAL_INT(2014, id.year);
|
||||
TEST_ASSERT_EQUAL_INT(3, id.month);
|
||||
}
|
||||
|
||||
// Clone cards put anything in the name: unprintable bytes mustn't reach the console.
|
||||
void test_unprintable_names() {
|
||||
uint8_t cid[16] = {0x00, 0x00, 0x01, 'A', 0x00, 0xFF, 'B', ' ', 0x10};
|
||||
SdCardId id = parseSdCid(cid);
|
||||
TEST_ASSERT_EQUAL_STRING("??", id.oem);
|
||||
TEST_ASSERT_EQUAL_STRING("A??B ", id.product);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, id.revisionMajor);
|
||||
}
|
||||
|
||||
void test_manufacturer_names() {
|
||||
TEST_ASSERT_EQUAL_STRING("SanDisk", sdManufacturerName(0x03));
|
||||
TEST_ASSERT_EQUAL_STRING("Samsung", sdManufacturerName(0x1B));
|
||||
TEST_ASSERT_EQUAL_STRING("unknown", sdManufacturerName(0xEE));
|
||||
}
|
||||
|
||||
void test_summary_line() {
|
||||
TEST_ASSERT_EQUAL_STRING("SanDisk (0x03) \"SD\" \"SU08G\" rev 8.0, serial 1234abcd, made 2014-03",
|
||||
sdCardSummary(parseSdCid(kSanDisk)).c_str());
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_fields);
|
||||
RUN_TEST(test_unprintable_names);
|
||||
RUN_TEST(test_manufacturer_names);
|
||||
RUN_TEST(test_summary_line);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user