|
14 | 14 |
|
15 | 15 | #include <pbdrv/block_device.h> |
16 | 16 |
|
| 17 | +#include <pbio/version.h> |
| 18 | + |
| 19 | +#include <pbsys/storage.h> |
| 20 | + |
17 | 21 | /** |
18 | 22 | * The following script is compiled using pybricksdev compile hello.py |
19 | 23 | * in MULTI_MPY_V6. |
@@ -46,22 +50,17 @@ const uint8_t script[] = { |
46 | 50 | 0x34, 0x01, 0x59, 0x11, 0x07, 0x65, 0x51, 0x63, |
47 | 51 | }; |
48 | 52 |
|
49 | | -#define MAX_PROGRAM_SIZE ((PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE)-(PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE_USER)-sizeof(uint32_t) * 2) |
50 | | - |
51 | | -/** |
52 | | - * Mimics data structure expected by pbsys. |
53 | | - */ |
54 | | -static struct { |
55 | | - uint32_t write_size; |
56 | | - uint8_t user_data[PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE_USER]; |
57 | | - uint32_t program_size; |
58 | | - uint8_t program_data[MAX_PROGRAM_SIZE] __attribute__((aligned(sizeof(void *)))); |
| 53 | +static union { |
| 54 | + pbsys_storage_data_map_t data_map; |
| 55 | + uint8_t blockdev[PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE]; |
59 | 56 | } blockdev = { 0 }; |
60 | 57 |
|
61 | 58 | void pbdrv_block_device_init(void) { |
62 | | - blockdev.program_size = sizeof(script); |
63 | | - memcpy(blockdev.program_data, script, sizeof(script)); |
64 | | - blockdev.write_size = sizeof(blockdev) - sizeof(blockdev.program_data) + blockdev.program_size; |
| 59 | + pbsys_storage_data_map_t *map = &blockdev.data_map; |
| 60 | + map->program_size = sizeof(script); |
| 61 | + map->stored_firmware_version = PBIO_HEXVERSION; |
| 62 | + memcpy(&map->program_data, script, sizeof(script)); |
| 63 | + map->write_size = sizeof(pbsys_storage_data_map_t) + map->program_size; |
65 | 64 | } |
66 | 65 |
|
67 | 66 | PT_THREAD(pbdrv_block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffer, uint32_t size, pbio_error_t *err)) { |
|
0 commit comments