Skip to content

Commit

Permalink
Assertion to incorrect initial values, Fix #37
Browse files Browse the repository at this point in the history
  • Loading branch information
oyama committed Jun 13, 2024
1 parent f0dc42e commit 14e64fd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/blockdevice/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {

/** Create Raspberry Pi Pico On-board Flash block device
*
* Create a block device object that uses the Raspberry Pi Pico onboard flash memory. The start position of the flash memory to be allocated to the block device is specified by start and the length by length.
* Create a block device object that uses the Raspberry Pi Pico onboard flash memory. The start position of the flash memory to be allocated to the block device is specified by start and the length by length. start and length must be aligned to a flash sector of 4096 bytes.
*
* @param start Specifies the starting position of the flash memory to be allocated to the block device in bytes.
* @param length Size in bytes to be allocated to the block device. If zero is specified, all remaining space is used.
Expand Down
10 changes: 5 additions & 5 deletions include/filesystem/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool fs_init(void);
* @param fs File system object. Format the block device according to the specified file system.
* @param device Block device used in the file system.
* @retval 0 Format succeeded.
* @retval <0 Format failed. Negative integer value indicates an error code.
* @retval -1 Format failed. Error codes are indicated by errno.
*/
int fs_format(filesystem_t *fs, blockdevice_t *device);

Expand All @@ -47,7 +47,7 @@ int fs_format(filesystem_t *fs, blockdevice_t *device);
* @param fs File system object.
* @param device Block device used in the file system. Block devices must be formatted with a file system.
* @retval 0 Mount succeeded.
* @retval <0 Mount failed. Negative integer value indicates an error code.
* @retval -1 Mount failed. Error codes are indicated by errno.
*/
int fs_mount(const char *path, filesystem_t *fs, blockdevice_t *device);

Expand All @@ -57,7 +57,7 @@ int fs_mount(const char *path, filesystem_t *fs, blockdevice_t *device);
*
* @param path Directory path of the mount point. Must be the same as the path specified for the mount.
* @retval 0 Dismount succeeded.
* @retval <0 Dismount failed. Negative integer value indicates an error code.
* @retval -1 Dismount failed. Error codes are indicated by errno.
*/
int fs_unmount(const char *path);

Expand All @@ -67,7 +67,7 @@ int fs_unmount(const char *path);
*
* @param path Directory path of the mount point. Must be the same as the path specified for the mount.
* @retval 0 Reformat suceeded.
* @retval <0 Reformat failed. Negative integer value indicates an error code.
* @retval -1 Reformat failed. Error codes are indicated by errno.
*/
int fs_reformat(const char *path);

Expand All @@ -77,7 +77,7 @@ int fs_reformat(const char *path);
* @param fs Pointer references to filesystem objects
* @param device Pinter references to blockdevice objects
* @retval 0 Lookup succeeded
* @retval <0 Lookup failed. Negative integer value indicates an error code.
* @retval -1 Lookup failed. Error codes are indicated by errno.
*/
int fs_info(const char *path, filesystem_t **fs, blockdevice_t **device);

Expand Down
4 changes: 4 additions & 0 deletions src/blockdevice/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright 2024, Hiroyuki OYAMA. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <hardware/flash.h>
#include <hardware/regs/addressmap.h>
#include <hardware/sync.h>
Expand Down Expand Up @@ -87,6 +88,9 @@ static size_t size(blockdevice_t *device) {
}

blockdevice_t *blockdevice_flash_create(uint32_t start, size_t length) {
assert(start % FLASH_SECTOR_SIZE == 0);
assert(length % FLASH_SECTOR_SIZE == 0);

blockdevice_t *device = calloc(1, sizeof(blockdevice_t));
if (device == NULL) {
fprintf(stderr, "blockdevice_flash_create: Out of memory\n");
Expand Down
15 changes: 15 additions & 0 deletions src/blockdevice/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [ARM Mbed OS](https://github.com/ARMmbed/mbed-os/blob/master/storage/blockdevice/COMPONENT_SD/source/SDBlockDevice.cpp);
* ARM Embed OS is licensed under the Apache 2.0 licence.
*/
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
Expand Down Expand Up @@ -1036,6 +1037,20 @@ blockdevice_t *blockdevice_sd_create(spi_inst_t *spi_inst,
uint32_t hz,
bool enable_crc)
{
if (spi_inst == spi0) {
assert(mosi == 3 || mosi == 7 || mosi == 19 || mosi == 23);
assert(miso == 0 || miso == 4 || miso == 16 || miso == 20);
assert(sclk == 2 || sclk == 6 || sclk == 18 || sclk == 22);
// assert(cs == 1 || cs == 5 || cs == 17 || cs == 21);
} else if (spi_inst == spi1) {
assert(mosi == 11 || mosi == 15 || mosi == 27);
assert(miso == 8 || miso == 12 || mosi == 24 || mosi == 28);
assert(sclk == 10 || sclk == 14 || sclk == 26);
// assert(cs == 9 || cs == 13 || cs == 25 || cs == 29);
} else {
assert(spi_inst == spi0 || spi_inst == spi1);
}

blockdevice_t *device = calloc(1, sizeof(blockdevice_t));
if (device == NULL) {
fprintf(stderr, "blockdevice_sd_create: Out of memory\n");
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

#define PICO_SPI1_TX_PIN 15
#define PICO_SPI1_RX_PIN 12
#define PICO_SPI1_SCK_PIN 19
#define PICO_SPI1_CSN_PIN 17
#define PICO_SPI1_SCK_PIN 14
#define PICO_SPI1_CSN_PIN 13

static void test_printf(const char *format, ...) {
va_list args;
Expand Down

0 comments on commit 14e64fd

Please sign in to comment.