23 #define USB_DEV_SN_LEN (32) // 32 hex digit UUID 24 #define USB_DEV_SN_DESC_SIZE (USB_DEV_SN_LEN * 2 + 2) 34 int ascii2usb_string_desc(uint8_t *usb_desc,
const char *str,
size_t n)
36 if (str == NULL || usb_desc == NULL || n < 4) {
44 memset(usb_desc, 0, n);
45 for (s = 0, d = 2; str[s] !=
'\0' && d < n; s++, d += 2) {
51 usb_desc[1] = STRING_DESCRIPTOR;
57 TestUSBMSD(
BlockDevice *bd,
bool connect_blocking =
true, uint16_t vendor_id = 0x0703, uint16_t product_id = 0x0104,
58 uint16_t product_release = 0x0001)
59 :
USBMSD(bd, connect_blocking, vendor_id, product_id, product_release)
69 uint32_t get_read_counter()
74 uint32_t get_program_counter()
76 return program_counter;
81 read_counter = program_counter = erase_counter = 0;
84 static void setup_serial_number()
86 char _key[128] = { 0 };
87 char _value[128] = { 0 };
89 greentea_send_kv(
"get_serial_number", 0);
90 greentea_parse_kv(_key, _value,
sizeof(_key),
sizeof(_value));
91 TEST_ASSERT_EQUAL_STRING(
"serial_number", _key);
92 usb_dev_sn[USB_DEV_SN_LEN] =
'\0';
93 memcpy(usb_dev_sn, _value, USB_DEV_SN_LEN);
94 ascii2usb_string_desc(_serial_num_descriptor, usb_dev_sn, USB_DEV_SN_DESC_SIZE);
97 virtual const uint8_t *string_iserial_desc()
99 return (
const uint8_t *)_serial_num_descriptor;
102 static volatile uint32_t read_counter;
103 static volatile uint32_t program_counter;
104 static volatile uint32_t erase_counter;
107 virtual int disk_read(uint8_t *data, uint64_t block, uint8_t count)
110 return USBMSD::disk_read(data, block, count);
113 virtual int disk_write(
const uint8_t *data, uint64_t block, uint8_t count)
118 return USBMSD::disk_write(data, block, count);
121 static uint8_t _serial_num_descriptor[USB_DEV_SN_DESC_SIZE];
122 static char usb_dev_sn[USB_DEV_SN_LEN + 1];
125 uint8_t TestUSBMSD::_serial_num_descriptor[USB_DEV_SN_DESC_SIZE] = { 0 };
126 char TestUSBMSD::usb_dev_sn[USB_DEV_SN_LEN + 1] = { 0 };
129 volatile uint32_t TestUSBMSD::read_counter = 0;
130 volatile uint32_t TestUSBMSD::program_counter = 0;
131 volatile uint32_t TestUSBMSD::erase_counter = 0;
133 #endif // Test_USBMSD_H
A hardware device capable of writing and reading blocks.
USBMSD class: generic class in order to use all kinds of blocks storage chip.
USBMSD(BlockDevice *bd, bool connect_blocking=true, uint16_t vendor_id=0x0703, uint16_t product_id=0x0104, uint16_t product_release=0x0001)
Constructor.