-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pbdrv/block_device: Implement async program load and save.
This replaces the polling SPI implementation (deactivated in the previous commit) with asynchronous DMA driven SPI transfers. This fixes motors going out of sync when starting programs. Fixes pybricks/support#679 This also avoids touching file systems used by other known firmwares, so that Pybricks can operate entirely stand alone. This reduces the complexity of firmware installation and troubleshooting, because there are no dependencies on prior firmwares or hub state. It also lays the groundwork for saving and storing program data on Powered Up hubs, which can be implemented in a future commit.
- Loading branch information
1 parent
37e6969
commit dbe4791
Showing
25 changed files
with
1,148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2022 The Pybricks Authors | ||
|
||
#ifndef _INTERNAL_PBDRV_BLOCK_DEVICE_H_ | ||
#define _INTERNAL_PBDRV_BLOCK_DEVICE_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <pbdrv/config.h> | ||
#include <pbio/error.h> | ||
|
||
#if PBDRV_CONFIG_BLOCK_DEVICE | ||
|
||
void pbdrv_block_device_init(void); | ||
|
||
#else // PBDRV_CONFIG_BLOCK_DEVICE | ||
|
||
static inline void pbdrv_block_device_init(void) { | ||
} | ||
|
||
#endif // PBDRV_CONFIG_BLOCK_DEVICE | ||
|
||
#endif // _INTERNAL_PBDRV_BLOCK_DEVICE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2022 The Pybricks Authors | ||
|
||
// Block device driver for Internal_flash. | ||
|
||
#include <pbdrv/config.h> | ||
|
||
#if PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32 | ||
|
||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include <contiki.h> | ||
|
||
#include "../core.h" | ||
|
||
#include <pbdrv/block_device.h> | ||
|
||
#include <pbio/error.h> | ||
#include <pbio/util.h> | ||
|
||
uint32_t pbdrv_block_device_get_size(void) { | ||
// Defined in linker script. | ||
extern uint32_t _pbdrv_block_device_storage_size; | ||
return (uint32_t)(&_pbdrv_block_device_storage_size); | ||
} | ||
|
||
void pbdrv_block_device_init(void) { | ||
} | ||
|
||
void pbdrv_block_device_set_callback(void (*callback)(void)) { | ||
} | ||
|
||
PT_THREAD(pbdrv_block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffer, uint32_t size, pbio_error_t *err)) { | ||
|
||
PT_BEGIN(pt); | ||
|
||
// TODO: Read from user flash. For now this just loads | ||
// the mpy file appended to the firmware to keep Pybricks Code working. | ||
extern uint32_t _pb_user_mpy_size; | ||
if (_pb_user_mpy_size + 8 > pbdrv_block_device_get_size()) { | ||
*err = PBIO_ERROR_FAILED; | ||
PT_EXIT(pt); | ||
} | ||
extern uint8_t _pb_user_mpy_data[]; | ||
pbio_set_uint32_le(buffer, _pb_user_mpy_size + 8); | ||
pbio_set_uint32_le(&buffer[4], _pb_user_mpy_size); | ||
memcpy(&buffer[8], _pb_user_mpy_data, _pb_user_mpy_size); | ||
*err = PBIO_SUCCESS; | ||
|
||
PT_END(pt); | ||
} | ||
|
||
PT_THREAD(pbdrv_block_device_store(struct pt *pt, uint8_t *buffer, uint32_t size, pbio_error_t *err)) { | ||
|
||
PT_BEGIN(pt); | ||
// TODO: Implement saving to user flash. | ||
*err = PBIO_ERROR_NOT_IMPLEMENTED; | ||
PT_END(pt); | ||
} | ||
|
||
#endif // PBDRV_CONFIG_BLOCK_DEVICE_FLASH_STM32 |
Oops, something went wrong.