ref: 0697bc2f9ff85fa341dc597495413b2160636d59
parent: ae7bd71fbf5253083181c322063c24cedb638cec
parent: 4e5365b36f1626bf784b35e09aaf6ecd47a103b3
author: root <ngkaho1234@gmail.com>
date: Mon Sep 21 18:47:59 EDT 2015
Merge remote-tracking branch 'upstream/master'
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,7 @@
include_directories(blockdev/filedev)
include_directories(blockdev/filedev_win)
+set(BLOCKDEV_TYPE none)
#Examples
if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m0)
@@ -34,10 +35,12 @@
#...
else()
#Generic example target
- add_subdirectory(blockdev)
+ set(BLOCKDEV_TYPE linux)
add_subdirectory(fs_test)
add_subdirectory(demos/generic)
endif()
+
+add_subdirectory(blockdev)
#Library build
add_subdirectory(lwext4)
--- a/blockdev/CMakeLists.txt
+++ b/blockdev/CMakeLists.txt
@@ -1,5 +1,15 @@
#Blockdev library
-aux_source_directory(filedev BLOCKDEV_SRC)
-aux_source_directory(filedev_win BLOCKDEV_SRC)
+
+if (BLOCKDEV_TYPE STREQUAL linux)
+aux_source_directory(linux BLOCKDEV_SRC)
+elseif (BLOCKDEV_TYPE STREQUAL windows)
+aux_source_directory(windows BLOCKDEV_SRC)
+elseif (BLOCKDEV_TYPE STREQUAL chibios)
+aux_source_directory(chibios BLOCKDEV_SRC)
+else()
+endif()
+
+aux_source_directory(. BLOCKDEV_SRC)
+
add_library(blockdev ${BLOCKDEV_SRC})
--- /dev/null
+++ b/blockdev/chibios/sdc_lwext4.c
@@ -1,0 +1,184 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../chibios/sdc_lwext4.h"
+
+#include <config.h>
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include <hal.h>
+#include <sdc.h>
+
+
+/**@brief Block size.*/
+#define SDC_BLOCK_SIZE 512
+
+/**@brief MBR_block ID*/
+#define MBR_BLOCK_ID 0
+#define MBR_PART_TABLE_OFF 446
+
+struct part_tab_entry {
+ uint8_t status;
+ uint8_t chs1[3];
+ uint8_t type;
+ uint8_t chs2[3];
+ uint32_t first_lba;
+ uint32_t sectors;
+} __attribute__((packed));
+
+/**@brief Partition block offset*/
+static uint32_t part_offset;
+
+/**@brief IO timings*/
+struct sdc_io_timings {
+ uint64_t acc_bread;
+ uint64_t acc_bwrite;
+
+ uint32_t cnt_bread;
+ uint32_t cnt_bwrite;
+
+ uint32_t av_bread;
+ uint32_t av_bwrite;
+};
+
+static struct sdc_io_timings io_timings;
+
+void io_timings_clear(void)
+{
+ memset(&io_timings, 0, sizeof(struct sdc_io_timings));
+}
+
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
+{
+ static struct ext4_io_stats s;
+
+ s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);
+ s.io_read /= 1000.0;
+
+ s.io_write = (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);
+ s.io_write /= 1000.0;
+
+ s.cpu = 100.0 - s.io_read - s.io_write;
+
+ return &s;
+}
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int sdc_open(struct ext4_blockdev *bdev);
+static int sdc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt);
+static int sdc_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt);
+static int sdc_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_sdc, SDC_BLOCK_SIZE, 0, sdc_open, sdc_bread,
+ sdc_bwrite, sdc_close);
+
+/******************************************************************************/
+EXT4_BCACHE_STATIC_INSTANCE(_sdc_cache, CONFIG_BLOCK_DEV_CACHE_SIZE,
+ EXT_LOGICAL_BLOCK_SIZE);
+
+/******************************************************************************/
+
+static int sdc_open(struct ext4_blockdev *bdev)
+{
+ (void)bdev;
+
+ static uint8_t mbr[512];
+ struct part_tab_entry *part0;
+
+ sdcStart(&SDCD1, NULL);
+
+ if (sdcConnect(&SDCD1) != HAL_SUCCESS)
+ return EIO;
+
+ if (sdcRead(&SDCD1, 0, mbr, 1) != HAL_SUCCESS)
+ return EIO;
+
+ part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);
+
+ part_offset = part0->first_lba;
+ _sdc.ph_bcnt = SDCD1.capacity * SDC_BLOCK_SIZE;
+
+ return EOK;
+}
+
+static int sdc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt)
+{
+ (void)bdev;
+ bool status;
+ uint64_t v = tim_get_us();
+
+ status = sdcRead(&SDCD1, blk_id, buf, blk_cnt);
+ if (status != HAL_SUCCESS)
+ return EIO;
+
+ io_timings.acc_bread += tim_get_us() - v;
+ io_timings.cnt_bread++;
+ io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;
+
+ return EOK;
+}
+
+static int sdc_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt)
+{
+ (void)bdev;
+ bool status;
+ uint64_t v = tim_get_us();
+
+ status = sdcWrite(&SDCD1, blk_id, buf, blk_cnt);
+ if (status != HAL_SUCCESS)
+ return EIO;
+
+ io_timings.acc_bwrite += tim_get_us() - v;
+ io_timings.cnt_bwrite++;
+ io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;
+
+ return EOK;
+}
+
+static int sdc_close(struct ext4_blockdev *bdev)
+{
+ (void)bdev;
+ return EOK;
+}
+
+/******************************************************************************/
+
+struct ext4_bcache *sdc_cache_get(void) { return &_sdc_cache; }
+
+struct ext4_blockdev *sdc_bdev_get(void) { return &_sdc; }
--- /dev/null
+++ b/blockdev/chibios/sdc_lwext4.h
@@ -1,0 +1,45 @@
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SDC_LWEXT4_H_
+#define SDC_LWEXT4_H_
+
+#include <config.h>
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief SDC cache get.*/
+struct ext4_bcache *sdc_cache_get(void);
+
+/**@brief SDC blockdev get.*/
+struct ext4_blockdev *sdc_bdev_get(void);
+
+
+#endif /* CHIBI_SDC_LWEXT4_H_ */
--- /dev/null
+++ b/blockdev/chibios/spi_lwext4.c
@@ -1,0 +1,211 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../chibios/spi_lwext4.h"
+
+#include <config.h>
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include <hal.h>
+#include <mmc_spi.h>
+
+
+#if HAL_USE_MMC_SPI
+extern MMCDriver MMCD1;
+#endif
+
+/**@brief Block size.*/
+#define SPI_BLOCK_SIZE 512
+
+/**@brief MBR_block ID*/
+#define MBR_BLOCK_ID 0
+#define MBR_PART_TABLE_OFF 446
+
+struct part_tab_entry {
+ uint8_t status;
+ uint8_t chs1[3];
+ uint8_t type;
+ uint8_t chs2[3];
+ uint32_t first_lba;
+ uint32_t sectors;
+} __attribute__((packed));
+
+/**@brief Partition block offset*/
+static uint32_t part_offset;
+
+/**@brief IO timings*/
+struct spi_io_timings {
+ uint64_t acc_bread;
+ uint64_t acc_bwrite;
+
+ uint32_t cnt_bread;
+ uint32_t cnt_bwrite;
+
+ uint32_t av_bread;
+ uint32_t av_bwrite;
+};
+
+static struct spi_io_timings io_timings;
+
+void io_timings_clear(void)
+{
+ memset(&io_timings, 0, sizeof(struct spi_io_timings));
+}
+
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
+{
+ static struct ext4_io_stats s;
+
+ s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);
+ s.io_read /= 1000.0;
+
+ s.io_write = (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);
+ s.io_write /= 1000.0;
+
+ s.cpu = 100.0 - s.io_read - s.io_write;
+
+ return &s;
+}
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int spi_open(struct ext4_blockdev *bdev);
+static int spi_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt);
+static int spi_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt);
+static int spi_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_spi, SPI_BLOCK_SIZE, 0, spi_open, spi_bread,
+ spi_bwrite, spi_close);
+
+/******************************************************************************/
+EXT4_BCACHE_STATIC_INSTANCE(_spi_cache, CONFIG_BLOCK_DEV_CACHE_SIZE,
+ EXT_LOGICAL_BLOCK_SIZE);
+
+/******************************************************************************/
+
+static int spi_open(struct ext4_blockdev *bdev)
+{
+
+ (void)bdev;
+
+ static uint8_t mbr[512];
+ struct part_tab_entry *part0;
+
+ if (mmcConnect(&MMCD1) != HAL_SUCCESS)
+ return EIO;
+
+ if (mmcStartSequentialRead(&MMCD1, 0) != HAL_SUCCESS)
+ return EIO;
+
+ if (mmcSequentialRead(&MMCD1, mbr) != HAL_SUCCESS)
+ return EIO;
+
+ if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS)
+ return EIO;
+
+ part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);
+
+ part_offset = part0->first_lba;
+ _spi.ph_bcnt = MMCD1.capacity * SPI_BLOCK_SIZE;
+
+ return EOK;
+}
+
+static int spi_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt)
+{
+ (void)bdev;
+ uint64_t v = tim_get_us();
+
+ if (mmcStartSequentialRead(&MMCD1, blk_id) != HAL_SUCCESS)
+ return EIO;
+
+ while (blk_cnt) {
+ if (mmcSequentialRead(&MMCD1, buf) != HAL_SUCCESS)
+ return EIO;
+
+ buf += SPI_BLOCK_SIZE;
+ blk_cnt--;
+ }
+
+ if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS)
+ return EIO;
+
+ io_timings.acc_bread += tim_get_us() - v;
+ io_timings.cnt_bread++;
+ io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;
+
+ return EOK;
+}
+
+static int spi_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt)
+{
+ (void)bdev;
+ uint64_t v = tim_get_us();
+
+ if (mmcStartSequentialWrite(&MMCD1, blk_id) != HAL_SUCCESS)
+ return EIO;
+
+ while (blk_cnt) {
+ if (mmcSequentialWrite(&MMCD1, buf) != HAL_SUCCESS)
+ return EIO;
+
+ buf += SPI_BLOCK_SIZE;
+ blk_cnt--;
+ }
+
+ if (mmcStopSequentialWrite(&MMCD1) != HAL_SUCCESS)
+ return EIO;
+
+ io_timings.acc_bwrite += tim_get_us() - v;
+ io_timings.cnt_bwrite++;
+ io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;
+
+ return EOK;
+}
+
+static int spi_close(struct ext4_blockdev *bdev)
+{
+ (void)bdev;
+ return EOK;
+}
+
+/******************************************************************************/
+
+struct ext4_bcache *spi_cache_get(void) { return &_spi_cache; }
+
+struct ext4_blockdev *spi_bdev_get(void) { return &_spi; }
--- /dev/null
+++ b/blockdev/chibios/spi_lwext4.h
@@ -1,0 +1,24 @@
+/*
+ * spi_lwext4.h
+ *
+ * Created on: 21 gru 2014
+ * Author: gko
+ */
+
+#ifndef SPI_LWEXT4_H_
+#define SPI_LWEXT4_H_
+
+#include <config.h>
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief SPI cache get.*/
+struct ext4_bcache *spi_cache_get(void);
+
+/**@brief SPI blockdev get.*/
+struct ext4_blockdev *spi_bdev_get(void);
+
+#endif /* SPI_LWEXT4_H_ */
--- /dev/null
+++ b/blockdev/chibios/timings.c
@@ -1,0 +1,49 @@
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../chibios/timings.h"
+
+#include <config.h>
+
+#include <ch.h>
+#include <chvt.h>
+
+
+void tim_wait_ms(uint32_t v) { chThdSleepMilliseconds(v); }
+
+uint64_t tim_get_us(void)
+{
+ uint64_t v = chVTGetSystemTimeX();
+ return ST2US(v);
+}
+
+uint32_t tim_get_ms(void)
+{
+ uint32_t v = chVTGetSystemTimeX();
+ return ST2MS(v);
+}
--- a/blockdev/filedev/ext4_filedev.c
+++ /dev/null
@@ -1,133 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#define _FILE_OFFSET_BITS 64
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <fcntl.h>
-
-/**@brief Default filename.*/
-static const char *fname = "ext2";
-
-/**@brief Image block size.*/
-#define EXT4_FILEDEV_BSIZE 512
-
-/**@brief Image file descriptor.*/
-static FILE *dev_file;
-
-#define DROP_LINUXCACHE_BUFFERS 0
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int filedev_open(struct ext4_blockdev *bdev);
-static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt);
-static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt);
-static int filedev_close(struct ext4_blockdev *bdev);
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_FILEDEV_BSIZE, 0, filedev_open,
- filedev_bread, filedev_bwrite, filedev_close);
-
-/******************************************************************************/
-static int filedev_open(struct ext4_blockdev *bdev)
-{
- dev_file = fopen(fname, "r+b");
-
- if (!dev_file)
- return EIO;
-
- /*No buffering at file.*/
- setbuf(dev_file, 0);
-
- if (fseek(dev_file, 0, SEEK_END))
- return EFAULT;
-
- _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
-
- return EOK;
-}
-
-/******************************************************************************/
-
-static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
-{
- if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
- return EIO;
-
- if (!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
- return EIO;
-
- return EOK;
-}
-
-static void drop_cache(void)
-{
-#if defined(__linux__) && DROP_LINUXCACHE_BUFFERS
- int fd;
- char *data = "3";
-
- sync();
- fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
- write(fd, data, sizeof(char));
- close(fd);
-#endif
-}
-
-/******************************************************************************/
-static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt)
-{
- if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
- return EIO;
-
- if (!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
- return EIO;
-
- drop_cache();
- return EOK;
-}
-/******************************************************************************/
-static int filedev_close(struct ext4_blockdev *bdev)
-{
- fclose(dev_file);
- return EOK;
-}
-
-/******************************************************************************/
-struct ext4_blockdev *ext4_filedev_get(void) { return &_filedev; }
-/******************************************************************************/
-void ext4_filedev_filename(const char *n) { fname = n; }
-
-/******************************************************************************/
--- a/blockdev/filedev/ext4_filedev.h
+++ /dev/null
@@ -1,43 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef EXT4_FILEDEV_H_
-#define EXT4_FILEDEV_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief File blockdev get.*/
-struct ext4_blockdev *ext4_filedev_get(void);
-
-/**@brief Set filename to open.*/
-void ext4_filedev_filename(const char *n);
-
-#endif /* EXT4_FILEDEV_H_ */
--- a/blockdev/filedev_win/io_raw.c
+++ /dev/null
@@ -1,161 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-
-#ifdef WIN32
-#include <windows.h>
-#include <winioctl.h>
-
-/**@brief Default filename.*/
-static const char *fname = "ext2";
-
-/**@brief IO block size.*/
-#define EXT4_IORAW_BSIZE 512
-
-/**@brief Image file descriptor.*/
-static HANDLE dev_file;
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int io_raw_open(struct ext4_blockdev *bdev);
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt);
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt);
-static int io_raw_close(struct ext4_blockdev *bdev);
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,
- io_raw_bread, io_raw_bwrite, io_raw_close);
-
-/******************************************************************************/
-static int io_raw_open(struct ext4_blockdev *bdev)
-{
- char path[64];
- DISK_GEOMETRY pdg;
- uint64_t disk_size;
- BOOL bResult = FALSE;
- DWORD junk;
-
- sprintf(path, "\\\\.\\%s", fname);
-
- dev_file =
- CreateFile(path, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
- FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
-
- if (dev_file == INVALID_HANDLE_VALUE) {
- return EIO;
- }
-
- bResult =
- DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
- &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);
-
- if (bResult == FALSE) {
- CloseHandle(dev_file);
- return EIO;
- }
-
- disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
- (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
-
- _filedev.ph_bsize = pdg.BytesPerSector;
- _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;
-
- return EOK;
-}
-
-/******************************************************************************/
-
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
-{
- long hipart = blk_id >> (32 - 9);
- long lopart = blk_id << 9;
- long err;
-
- SetLastError(0);
- lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
-
- if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
- return EIO;
- }
-
- DWORD n;
-
- if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
- err = GetLastError();
- return EIO;
- }
- return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt)
-{
- long hipart = blk_id >> (32 - 9);
- long lopart = blk_id << 9;
- long err;
-
- SetLastError(0);
- lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
-
- if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
- return EIO;
- }
-
- DWORD n;
-
- if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
- err = GetLastError();
- return EIO;
- }
- return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_close(struct ext4_blockdev *bdev)
-{
- CloseHandle(dev_file);
- return EOK;
-}
-
-/******************************************************************************/
-struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }
-/******************************************************************************/
-void ext4_io_raw_filename(const char *n) { fname = n; }
-
-/******************************************************************************/
-#endif
--- a/blockdev/filedev_win/io_raw.h
+++ /dev/null
@@ -1,43 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef IO_RAW_H_
-#define IO_RAW_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief IO raw blockdev get.*/
-struct ext4_blockdev *ext4_io_raw_dev_get(void);
-
-/**@brief Set filrname to open.*/
-void ext4_io_raw_filename(const char *n);
-
-#endif /* IO_RAW_H_ */
--- /dev/null
+++ b/blockdev/linux/ext4_filedev.c
@@ -1,0 +1,133 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define _FILE_OFFSET_BITS 64
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+
+/**@brief Default filename.*/
+static const char *fname = "ext2";
+
+/**@brief Image block size.*/
+#define EXT4_FILEDEV_BSIZE 512
+
+/**@brief Image file descriptor.*/
+static FILE *dev_file;
+
+#define DROP_LINUXCACHE_BUFFERS 0
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int filedev_open(struct ext4_blockdev *bdev);
+static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt);
+static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt);
+static int filedev_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_FILEDEV_BSIZE, 0, filedev_open,
+ filedev_bread, filedev_bwrite, filedev_close);
+
+/******************************************************************************/
+static int filedev_open(struct ext4_blockdev *bdev)
+{
+ dev_file = fopen(fname, "r+b");
+
+ if (!dev_file)
+ return EIO;
+
+ /*No buffering at file.*/
+ setbuf(dev_file, 0);
+
+ if (fseek(dev_file, 0, SEEK_END))
+ return EFAULT;
+
+ _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
+
+ return EOK;
+}
+
+/******************************************************************************/
+
+static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt)
+{
+ if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+ return EIO;
+
+ if (!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+ return EIO;
+
+ return EOK;
+}
+
+static void drop_cache(void)
+{
+#if defined(__linux__) && DROP_LINUXCACHE_BUFFERS
+ int fd;
+ char *data = "3";
+
+ sync();
+ fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+ write(fd, data, sizeof(char));
+ close(fd);
+#endif
+}
+
+/******************************************************************************/
+static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt)
+{
+ if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+ return EIO;
+
+ if (!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+ return EIO;
+
+ drop_cache();
+ return EOK;
+}
+/******************************************************************************/
+static int filedev_close(struct ext4_blockdev *bdev)
+{
+ fclose(dev_file);
+ return EOK;
+}
+
+/******************************************************************************/
+struct ext4_blockdev *ext4_filedev_get(void) { return &_filedev; }
+/******************************************************************************/
+void ext4_filedev_filename(const char *n) { fname = n; }
+
+/******************************************************************************/
--- /dev/null
+++ b/blockdev/linux/ext4_filedev.h
@@ -1,0 +1,43 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef EXT4_FILEDEV_H_
+#define EXT4_FILEDEV_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief File blockdev get.*/
+struct ext4_blockdev *ext4_filedev_get(void);
+
+/**@brief Set filename to open.*/
+void ext4_filedev_filename(const char *n);
+
+#endif /* EXT4_FILEDEV_H_ */
--- /dev/null
+++ b/blockdev/test_lwext4.c
@@ -1,0 +1,381 @@
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ext4.h>
+
+#include <stdio.h>
+#include <time.h>
+#include <inttypes.h>
+#include <string.h>
+
+#include "test_lwext4.h"
+
+/**@brief Read-write size*/
+#define READ_MAX_WRITE_SZIZE 1024 * 16
+
+/**@brief File read/write buffer*/
+static uint8_t rw_buff[READ_MAX_WRITE_SZIZE];
+
+/**@brief Block device handle.*/
+static struct ext4_blockdev *bd;
+
+/**@brief Block cache handle.*/
+static struct ext4_bcache *bc;
+
+static char *entry_to_str(uint8_t type)
+{
+ switch (type) {
+ case EXT4_DIRENTRY_UNKNOWN:
+ return "[unk] ";
+ case EXT4_DIRENTRY_REG_FILE:
+ return "[fil] ";
+ case EXT4_DIRENTRY_DIR:
+ return "[dir] ";
+ case EXT4_DIRENTRY_CHRDEV:
+ return "[cha] ";
+ case EXT4_DIRENTRY_BLKDEV:
+ return "[blk] ";
+ case EXT4_DIRENTRY_FIFO:
+ return "[fif] ";
+ case EXT4_DIRENTRY_SOCK:
+ return "[soc] ";
+ case EXT4_DIRENTRY_SYMLINK:
+ return "[sym] ";
+ default:
+ break;
+ }
+ return "[???]";
+}
+
+static clock_t get_ms(void) { return tim_get_ms(); }
+
+static void printf_io_timings(clock_t diff)
+{
+ const struct ext4_io_stats *stats = io_timings_get(diff);
+ if (!stats)
+ return;
+
+ printf("io_timings:\n");
+ printf(" io_read: %.3f%%\n", stats->io_read);
+ printf(" io_write: %.3f%%\n", stats->io_write);
+ printf(" io_cpu: %.3f%%\n", stats->cpu);
+}
+
+void test_lwext4_dir_ls(const char *path)
+{
+ char sss[255];
+ ext4_dir d;
+ const ext4_direntry *de;
+
+ printf("ls %s\n", path);
+
+ ext4_dir_open(&d, path);
+ de = ext4_dir_entry_next(&d);
+
+ while (de) {
+ memcpy(sss, de->name, de->name_length);
+ sss[de->name_length] = 0;
+ printf(" %s%s\n", entry_to_str(de->inode_type), sss);
+ de = ext4_dir_entry_next(&d);
+ }
+ ext4_dir_close(&d);
+}
+
+void test_lwext4_mp_stats(void)
+{
+ struct ext4_mount_stats stats;
+ ext4_mount_point_stats("/mp/", &stats);
+
+ printf("********************\n");
+ printf("ext4_mount_point_stats\n");
+ printf("inodes_count = %" PRIu32 "\n", stats.inodes_count);
+ printf("free_inodes_count = %" PRIu32 "\n", stats.free_inodes_count);
+ printf("blocks_count = %" PRIu32 "\n", (uint32_t)stats.blocks_count);
+ printf("free_blocks_count = %" PRIu32 "\n",
+ (uint32_t)stats.free_blocks_count);
+ printf("block_size = %" PRIu32 "\n", stats.block_size);
+ printf("block_group_count = %" PRIu32 "\n", stats.block_group_count);
+ printf("blocks_per_group= %" PRIu32 "\n", stats.blocks_per_group);
+ printf("inodes_per_group = %" PRIu32 "\n", stats.inodes_per_group);
+ printf("volume_name = %s\n", stats.volume_name);
+ printf("********************\n");
+}
+
+void test_lwext4_block_stats(void)
+{
+ if (!bd)
+ return;
+
+ printf("********************\n");
+ printf("ext4 blockdev stats\n");
+ printf("bdev->bread_ctr = %" PRIu32 "\n", bd->bread_ctr);
+ printf("bdev->bwrite_ctr = %" PRIu32 "\n", bd->bwrite_ctr);
+
+ printf("bcache->ref_blocks = %" PRIu32 "\n", bc->ref_blocks);
+ printf("bcache->max_ref_blocks = %" PRIu32 "\n", bc->max_ref_blocks);
+ printf("bcache->lru_ctr = %" PRIu32 "\n", bc->lru_ctr);
+
+ printf("\n");
+
+ uint32_t i;
+ for (i = 0; i < bc->cnt; ++i) {
+ printf("bcache->refctr[%" PRIu32 "]= %" PRIu32 "\n", i,
+ bc->refctr[i]);
+ }
+
+ printf("\n");
+ for (i = 0; i < bc->cnt; ++i) {
+ printf("bcache->lru_id[%" PRIu32 "] = %" PRIu32 "\n", i,
+ bc->lru_id[i]);
+ }
+
+ printf("\n");
+ for (i = 0; i < bc->cnt; ++i) {
+ printf("bcache->free_delay[%" PRIu32 "] = %d\n", i,
+ bc->free_delay[i]);
+ }
+
+ printf("\n");
+ for (i = 0; i < bc->cnt; ++i) {
+ printf("bcache->lba[%" PRIu32 "] = %" PRIu32 "\n", i,
+ (uint32_t)bc->lba[i]);
+ }
+
+ printf("********************\n");
+}
+
+bool test_lwext4_dir_test(int len)
+{
+ ext4_file f;
+ int r;
+ int i;
+ char path[64];
+ clock_t diff;
+ clock_t stop;
+ clock_t start;
+
+ printf("test_lwext4_dir_test: %d\n", len);
+ io_timings_clear();
+ start = get_ms();
+
+ printf("directory create: /mp/dir1\n");
+ r = ext4_dir_mk("/mp/dir1");
+ if (r != EOK) {
+ printf("ext4_dir_mk: rc = %d\n", r);
+ return false;
+ }
+
+ printf("add files to: /mp/dir1\n");
+ for (i = 0; i < len; ++i) {
+ sprintf(path, "/mp/dir1/f%d", i);
+ r = ext4_fopen(&f, path, "wb");
+ if (r != EOK) {
+ printf("ext4_fopen: rc = %d\n", r);
+ return false;
+ }
+ }
+
+ stop = get_ms();
+ diff = stop - start;
+ test_lwext4_dir_ls("/mp/dir1");
+ printf("test_lwext4_dir_test: time: %d ms\n", (int)diff);
+ printf("test_lwext4_dir_test: av: %d ms/entry\n", (int)diff / (len + 1));
+ printf_io_timings(diff);
+ return true;
+}
+
+static int verify_buf(const unsigned char *b, size_t len, unsigned char c)
+{
+ size_t i;
+ for (i = 0; i < len; ++i) {
+ if (b[i] != c)
+ return c - b[i];
+ }
+
+ return 0;
+}
+
+bool test_lwext4_file_test(uint32_t rw_size, uint32_t rw_count)
+{
+ int r;
+ size_t size;
+ uint32_t i;
+ clock_t start;
+ clock_t stop;
+ clock_t diff;
+ uint32_t kbps;
+ uint64_t size_bytes;
+
+ ext4_file f;
+
+ if (rw_size > READ_MAX_WRITE_SZIZE)
+ return false;
+
+ printf("file_test:\n");
+ printf(" rw size: %" PRIu32 "\n", rw_size);
+ printf(" rw count: %" PRIu32 "\n", rw_count);
+
+ /*Add hello world file.*/
+ r = ext4_fopen(&f, "/mp/hello.txt", "wb");
+ r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);
+ r = ext4_fclose(&f);
+
+ io_timings_clear();
+ start = get_ms();
+ r = ext4_fopen(&f, "/mp/test1", "wb");
+ if (r != EOK) {
+ printf("ext4_fopen ERROR = %d\n", r);
+ return false;
+ }
+
+ printf("ext4_write: %" PRIu32 " * %" PRIu32 " ...\n", rw_size,
+ rw_count);
+ for (i = 0; i < rw_count; ++i) {
+
+ memset(rw_buff, i % 10 + '0', rw_size);
+
+ r = ext4_fwrite(&f, rw_buff, rw_size, &size);
+
+ if ((r != EOK) || (size != rw_size))
+ break;
+ }
+
+ if (i != rw_count) {
+ printf(" file_test: rw_count = %" PRIu32 "\n", i);
+ return false;
+ }
+
+ stop = get_ms();
+ diff = stop - start;
+ size_bytes = rw_size * rw_count;
+ size_bytes = (size_bytes * 1000) / 1024;
+ kbps = (size_bytes) / (diff + 1);
+ printf(" write time: %d ms\n", (int)diff);
+ printf(" write speed: %" PRIu32 " KB/s\n", kbps);
+ printf_io_timings(diff);
+ r = ext4_fclose(&f);
+
+ io_timings_clear();
+ start = get_ms();
+ r = ext4_fopen(&f, "/mp/test1", "r+");
+ if (r != EOK) {
+ printf("ext4_fopen ERROR = %d\n", r);
+ return false;
+ }
+
+ printf("ext4_read: %" PRIu32 " * %" PRIu32 " ...\n", rw_size, rw_count);
+
+ for (i = 0; i < rw_count; ++i) {
+ r = ext4_fread(&f, rw_buff, rw_size, &size);
+
+ if ((r != EOK) || (size != rw_size))
+ break;
+
+ if (verify_buf(rw_buff, rw_size, i % 10 + '0'))
+ break;
+ }
+
+ if (i != rw_count) {
+ printf(" file_test: rw_count = %" PRIu32 "\n", i);
+ return false;
+ }
+
+ stop = get_ms();
+ diff = stop - start;
+ size_bytes = rw_size * rw_count;
+ size_bytes = (size_bytes * 1000) / 1024;
+ kbps = (size_bytes) / (diff + 1);
+ printf(" read time: %d ms\n", (int)diff);
+ printf(" read speed: %d KB/s\n", (int)kbps);
+ printf_io_timings(diff);
+
+ r = ext4_fclose(&f);
+ return true;
+}
+void test_lwext4_cleanup(void)
+{
+ clock_t start;
+ clock_t stop;
+ clock_t diff;
+
+ printf("\ncleanup:\n");
+ ext4_fremove("/mp/hello.txt");
+
+ printf("remove /mp/test1\n");
+ ext4_fremove("/mp/test1");
+
+ printf("remove /mp/dir1\n");
+ io_timings_clear();
+ start = get_ms();
+ ext4_dir_rm("/mp/dir1");
+ stop = get_ms();
+ diff = stop - start;
+ printf("cleanup: time: %d ms\n", (int)diff);
+ printf_io_timings(diff);
+}
+
+bool test_lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache)
+{
+ int r;
+
+ bc = bcache;
+ bd = bdev;
+
+ if (!bd) {
+ printf("test_lwext4_mount: no block device\n");
+ return false;
+ }
+
+ ext4_dmask_set(EXT4_DEBUG_ALL);
+
+ r = ext4_device_register(bd, bc ? bc : 0, "ext4_fs");
+ if (r != EOK) {
+ printf("ext4_device_register: rc = %d\n", r);
+ return false;
+ }
+
+ r = ext4_mount("ext4_fs", "/mp/");
+ if (r != EOK) {
+ printf("ext4_mount: rc = %d\n", r);
+ return false;
+ }
+
+ ext4_cache_write_back("/mp/", 1);
+ return true;
+}
+
+bool test_lwext4_umount(void)
+{
+ ext4_cache_write_back("/mp/", 0);
+ int r = ext4_umount("/mp/");
+ if (r != EOK) {
+ printf("ext4_umount: fail %d", r);
+ return false;
+ }
+ return true;
+}
--- /dev/null
+++ b/blockdev/test_lwext4.h
@@ -1,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEST_LWEXT4_H_
+#define TEST_LWEXT4_H_
+
+#include <stdint.h>
+#include <stdbool.h>
+
+void test_lwext4_dir_ls(const char *path);
+void test_lwext4_mp_stats(void);
+void test_lwext4_block_stats(void);
+bool test_lwext4_dir_test(int len);
+bool test_lwext4_file_test(uint32_t rw_szie, uint32_t rw_count);
+void test_lwext4_cleanup(void);
+
+bool test_lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache);
+bool test_lwext4_umount(void);
+
+void tim_wait_ms(uint32_t v);
+
+uint32_t tim_get_ms(void);
+uint64_t tim_get_us(void);
+
+struct ext4_io_stats {
+ float io_read;
+ float io_write;
+ float cpu;
+};
+
+void io_timings_clear(void);
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms);
+
+#endif /* TEST_LWEXT4_H_ */
--- /dev/null
+++ b/blockdev/windows/io_raw.c
@@ -1,0 +1,161 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#ifdef WIN32
+#include <windows.h>
+#include <winioctl.h>
+
+/**@brief Default filename.*/
+static const char *fname = "ext2";
+
+/**@brief IO block size.*/
+#define EXT4_IORAW_BSIZE 512
+
+/**@brief Image file descriptor.*/
+static HANDLE dev_file;
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int io_raw_open(struct ext4_blockdev *bdev);
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt);
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt);
+static int io_raw_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,
+ io_raw_bread, io_raw_bwrite, io_raw_close);
+
+/******************************************************************************/
+static int io_raw_open(struct ext4_blockdev *bdev)
+{
+ char path[64];
+ DISK_GEOMETRY pdg;
+ uint64_t disk_size;
+ BOOL bResult = FALSE;
+ DWORD junk;
+
+ sprintf(path, "\\\\.\\%s", fname);
+
+ dev_file =
+ CreateFile(path, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
+ FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
+
+ if (dev_file == INVALID_HANDLE_VALUE) {
+ return EIO;
+ }
+
+ bResult =
+ DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
+ &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);
+
+ if (bResult == FALSE) {
+ CloseHandle(dev_file);
+ return EIO;
+ }
+
+ disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
+ (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
+
+ _filedev.ph_bsize = pdg.BytesPerSector;
+ _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;
+
+ return EOK;
+}
+
+/******************************************************************************/
+
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt)
+{
+ long hipart = blk_id >> (32 - 9);
+ long lopart = blk_id << 9;
+ long err;
+
+ SetLastError(0);
+ lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
+
+ if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
+ return EIO;
+ }
+
+ DWORD n;
+
+ if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+ err = GetLastError();
+ return EIO;
+ }
+ return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt)
+{
+ long hipart = blk_id >> (32 - 9);
+ long lopart = blk_id << 9;
+ long err;
+
+ SetLastError(0);
+ lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
+
+ if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
+ return EIO;
+ }
+
+ DWORD n;
+
+ if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+ err = GetLastError();
+ return EIO;
+ }
+ return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_close(struct ext4_blockdev *bdev)
+{
+ CloseHandle(dev_file);
+ return EOK;
+}
+
+/******************************************************************************/
+struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }
+/******************************************************************************/
+void ext4_io_raw_filename(const char *n) { fname = n; }
+
+/******************************************************************************/
+#endif
--- /dev/null
+++ b/blockdev/windows/io_raw.h
@@ -1,0 +1,44 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef IO_RAW_H_
+#define IO_RAW_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief IO raw blockdev get.*/
+struct ext4_blockdev *ext4_io_raw_dev_get(void);
+
+/**@brief Set filrname to open.*/
+void ext4_io_raw_filename(const char *n);
+
+
+#endif /* IO_RAW_H_ */
--- a/demos/chibios/apps/olimex_stm32_lcd_sd/Makefile
+++ /dev/null
@@ -1,223 +1,0 @@
-##############################################################################
-# Build global options
-# NOTE: Can be overridden externally.
-#
-
-# Compiler options here.
-ifeq ($(USE_OPT),)
- USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
-endif
-
-# C specific options here (added to USE_OPT).
-ifeq ($(USE_COPT),)
- USE_COPT =
-endif
-
-# C++ specific options here (added to USE_OPT).
-ifeq ($(USE_CPPOPT),)
- USE_CPPOPT = -fno-rtti
-endif
-
-# Enable this if you want the linker to remove unused code and data
-ifeq ($(USE_LINK_GC),)
- USE_LINK_GC = yes
-endif
-
-# Linker extra options here.
-ifeq ($(USE_LDOPT),)
- USE_LDOPT =
-endif
-
-# Enable this if you want link time optimizations (LTO)
-ifeq ($(USE_LTO),)
- USE_LTO =
-endif
-
-# If enabled, this option allows to compile the application in THUMB mode.
-ifeq ($(USE_THUMB),)
- USE_THUMB = yes
-endif
-
-# Enable this if you want to see the full log while compiling.
-ifeq ($(USE_VERBOSE_COMPILE),)
- USE_VERBOSE_COMPILE = no
-endif
-
-#
-# Build global options
-##############################################################################
-
-##############################################################################
-# Architecture or project specific options
-#
-
-# Stack size to be allocated to the Cortex-M process stack. This stack is
-# the stack used by the main() thread.
-ifeq ($(USE_PROCESS_STACKSIZE),)
- USE_PROCESS_STACKSIZE = 0x800
-endif
-
-# Stack size to the allocated to the Cortex-M main/exceptions stack. This
-# stack is used for processing interrupts and exceptions.
-ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
- USE_EXCEPTIONS_STACKSIZE = 0x400
-endif
-
-# Enables the use of FPU on Cortex-M4.
-ifeq ($(USE_FPU),)
- USE_FPU = no
-endif
-
-#
-# Architecture or project specific options
-##############################################################################
-
-##############################################################################
-# Project, sources and paths
-#
-ifndef CHIBIOS
-CHIBIOS = ../../../../../ChibiOS
-endif
-
-LWEXT4 = ../../../..
-COMMON = ../../common
-
-# Define project name here
-PROJECT = olimex_stm32_lcd_sd
-
-# Imported source files and paths
-include ../../boards/olimex_stm32_lcd/board.mk
-
-# Startup files.
-include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
-# HAL-OSAL files (optional).
-include $(CHIBIOS)/os/hal/hal.mk
-include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform.mk
-include $(CHIBIOS)/os/hal/osal/rt/osal.mk
-# RTOS files (optional).
-include $(CHIBIOS)/os/rt/rt.mk
-include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
-# Other files (optional).
-include $(CHIBIOS)/test/rt/test.mk
-
-# Define linker script file here
-LDSCRIPT= $(STARTUPLD)/STM32F103xD.ld
-
-# C sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CSRC = $(STARTUPSRC) \
- $(KERNSRC) \
- $(PORTSRC) \
- $(OSALSRC) \
- $(HALSRC) \
- $(PLATFORMSRC) \
- $(BOARDSRC) \
- $(TESTSRC) \
- $(CHIBIOS)/os/hal/lib/streams/chprintf.c \
- $(CHIBIOS)/os/various/syscalls.c \
- main.c
-
-CSRC += $(COMMON)/sdc_lwext4.c
-CSRC += $(COMMON)/test_lwext4.c
-CSRC += $(COMMON)/timings.c
-
-# C++ sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CPPSRC =
-
-# C sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACSRC =
-
-# C++ sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACPPSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCPPSRC =
-
-# List ASM source files here
-ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
-
-INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
- $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
- $(CHIBIOS)/os/various $(CHIBIOS)/os/hal/lib/streams
-
-
-#
-# Project, sources and paths
-##############################################################################
-
-##############################################################################
-# Compiler settings
-#
-
-MCU = cortex-m3
-
-#TRGT = arm-elf-
-TRGT = arm-none-eabi-
-CC = $(TRGT)gcc
-CPPC = $(TRGT)g++
-# Enable loading with g++ only if you need C++ runtime support.
-# NOTE: You can use C++ even without C++ support if you are careful. C++
-# runtime support makes code size explode.
-LD = $(TRGT)gcc
-#LD = $(TRGT)g++
-CP = $(TRGT)objcopy
-AS = $(TRGT)gcc -x assembler-with-cpp
-AR = $(TRGT)ar
-OD = $(TRGT)objdump
-SZ = $(TRGT)size
-HEX = $(CP) -O ihex
-BIN = $(CP) -O binary
-
-# ARM-specific options here
-AOPT =
-
-# THUMB-specific options here
-TOPT = -mthumb -DTHUMB
-
-# Define C warning options here
-CWARN = -Wall -Wextra -Wstrict-prototypes
-
-# Define C++ warning options here
-CPPWARN = -Wall -Wextra
-
-#
-# Compiler settings
-##############################################################################
-
-##############################################################################
-# Start of user section
-#
-
-# List all user C define here, like -D_DEBUG=1
-UDEFS = -DSTDOUT_SD=SD1
-
-# Define ASM defines here
-UADEFS =
-
-# List all user directories here
-UINCDIR = $(LWEXT4)/lwext4 $(COMMON)
-
-# List the user directory to look for the libraries here
-ULIBDIR = $(LWEXT4)/build_cortex-m3/lwext4
-
-# List all user libraries here
-ULIBS = -llwext4
-
-#
-# End of user defines
-##############################################################################
-
-RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
-include $(RULESPATH)/rules.mk
--- a/demos/chibios/apps/olimex_stm32_lcd_sd/chconf.h
+++ /dev/null
@@ -1,498 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file templates/chconf.h
- * @brief Configuration file template.
- * @details A copy of this file must be placed in each project directory, it
- * contains the application specific kernel settings.
- *
- * @addtogroup config
- * @details Kernel related settings and hooks.
- * @{
- */
-
-#ifndef _CHCONF_H_
-#define _CHCONF_H_
-
-/*===========================================================================*/
-/**
- * @name System timers settings
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief System time counter resolution.
- * @note Allowed values are 16 or 32 bits.
- */
-#define CH_CFG_ST_RESOLUTION 16
-
-/**
- * @brief System tick frequency.
- * @details Frequency of the system timer that drives the system ticks. This
- * setting also defines the system tick time unit.
- */
-#define CH_CFG_ST_FREQUENCY 2000
-
-/**
- * @brief Time delta constant for the tick-less mode.
- * @note If this value is zero then the system uses the classic
- * periodic tick. This value represents the minimum number
- * of ticks that is safe to specify in a timeout directive.
- * The value one is not valid, timeouts are rounded up to
- * this value.
- */
-#define CH_CFG_ST_TIMEDELTA 2
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Kernel parameters and options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Round robin interval.
- * @details This constant is the number of system ticks allowed for the
- * threads before preemption occurs. Setting this value to zero
- * disables the preemption for threads with equal priority and the
- * round robin becomes cooperative. Note that higher priority
- * threads can still preempt, the kernel is always preemptive.
- * @note Disabling the round robin preemption makes the kernel more compact
- * and generally faster.
- * @note The round robin preemption is not supported in tickless mode and
- * must be set to zero in that case.
- */
-#define CH_CFG_TIME_QUANTUM 0
-
-/**
- * @brief Managed RAM size.
- * @details Size of the RAM area to be managed by the OS. If set to zero
- * then the whole available RAM is used. The core memory is made
- * available to the heap allocator and/or can be used directly through
- * the simplified core memory allocator.
- *
- * @note In order to let the OS manage the whole RAM the linker script must
- * provide the @p __heap_base__ and @p __heap_end__ symbols.
- * @note Requires @p CH_CFG_USE_MEMCORE.
- */
-#define CH_CFG_MEMCORE_SIZE 0
-
-/**
- * @brief Idle thread automatic spawn suppression.
- * @details When this option is activated the function @p chSysInit()
- * does not spawn the idle thread. The application @p main()
- * function becomes the idle thread and must implement an
- * infinite loop. */
-#define CH_CFG_NO_IDLE_THREAD FALSE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Performance options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief OS optimization.
- * @details If enabled then time efficient rather than space efficient code
- * is used when two possible implementations exist.
- *
- * @note This is not related to the compiler optimization options.
- * @note The default is @p TRUE.
- */
-#define CH_CFG_OPTIMIZE_SPEED TRUE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Subsystem options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Time Measurement APIs.
- * @details If enabled then the time measurement APIs are included in
- * the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_TM TRUE
-
-/**
- * @brief Threads registry APIs.
- * @details If enabled then the registry APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_REGISTRY TRUE
-
-/**
- * @brief Threads synchronization APIs.
- * @details If enabled then the @p chThdWait() function is included in
- * the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_WAITEXIT TRUE
-
-/**
- * @brief Semaphores APIs.
- * @details If enabled then the Semaphores APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_SEMAPHORES TRUE
-
-/**
- * @brief Semaphores queuing mode.
- * @details If enabled then the threads are enqueued on semaphores by
- * priority rather than in FIFO order.
- *
- * @note The default is @p FALSE. Enable this if you have special
- * requirements.
- * @note Requires @p CH_CFG_USE_SEMAPHORES.
- */
-#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
-
-/**
- * @brief Mutexes APIs.
- * @details If enabled then the mutexes APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MUTEXES TRUE
-
-/**
- * @brief Enables recursive behavior on mutexes.
- * @note Recursive mutexes are heavier and have an increased
- * memory footprint.
- *
- * @note The default is @p FALSE.
- * @note Requires @p CH_CFG_USE_MUTEXES.
- */
-#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
-
-/**
- * @brief Conditional Variables APIs.
- * @details If enabled then the conditional variables APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_MUTEXES.
- */
-#define CH_CFG_USE_CONDVARS TRUE
-
-/**
- * @brief Conditional Variables APIs with timeout.
- * @details If enabled then the conditional variables APIs with timeout
- * specification are included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_CONDVARS.
- */
-#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
-
-/**
- * @brief Events Flags APIs.
- * @details If enabled then the event flags APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_EVENTS TRUE
-
-/**
- * @brief Events Flags APIs with timeout.
- * @details If enabled then the events APIs with timeout specification
- * are included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_EVENTS.
- */
-#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
-
-/**
- * @brief Synchronous Messages APIs.
- * @details If enabled then the synchronous messages APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MESSAGES TRUE
-
-/**
- * @brief Synchronous Messages queuing mode.
- * @details If enabled then messages are served by priority rather than in
- * FIFO order.
- *
- * @note The default is @p FALSE. Enable this if you have special
- * requirements.
- * @note Requires @p CH_CFG_USE_MESSAGES.
- */
-#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
-
-/**
- * @brief Mailboxes APIs.
- * @details If enabled then the asynchronous messages (mailboxes) APIs are
- * included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_SEMAPHORES.
- */
-#define CH_CFG_USE_MAILBOXES TRUE
-
-/**
- * @brief I/O Queues APIs.
- * @details If enabled then the I/O queues APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_QUEUES TRUE
-
-/**
- * @brief Core Memory Manager APIs.
- * @details If enabled then the core memory manager APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MEMCORE TRUE
-
-/**
- * @brief Heap Allocator APIs.
- * @details If enabled then the memory heap allocator APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
- * @p CH_CFG_USE_SEMAPHORES.
- * @note Mutexes are recommended.
- */
-#define CH_CFG_USE_HEAP TRUE
-
-/**
- * @brief Memory Pools Allocator APIs.
- * @details If enabled then the memory pools allocator APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MEMPOOLS TRUE
-
-/**
- * @brief Dynamic Threads APIs.
- * @details If enabled then the dynamic threads creation APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_WAITEXIT.
- * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
- */
-#define CH_CFG_USE_DYNAMIC TRUE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Debug options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Debug option, kernel statistics.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_STATISTICS FALSE
-
-/**
- * @brief Debug option, system state check.
- * @details If enabled the correct call protocol for system APIs is checked
- * at runtime.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_SYSTEM_STATE_CHECK FALSE
-
-/**
- * @brief Debug option, parameters checks.
- * @details If enabled then the checks on the API functions input
- * parameters are activated.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_CHECKS FALSE
-
-/**
- * @brief Debug option, consistency checks.
- * @details If enabled then all the assertions in the kernel code are
- * activated. This includes consistency checks inside the kernel,
- * runtime anomalies and port-defined checks.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_ASSERTS FALSE
-
-/**
- * @brief Debug option, trace buffer.
- * @details If enabled then the context switch circular trace buffer is
- * activated.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_TRACE FALSE
-
-/**
- * @brief Debug option, stack checks.
- * @details If enabled then a runtime stack check is performed.
- *
- * @note The default is @p FALSE.
- * @note The stack check is performed in a architecture/port dependent way.
- * It may not be implemented or some ports.
- * @note The default failure mode is to halt the system with the global
- * @p panic_msg variable set to @p NULL.
- */
-#define CH_DBG_ENABLE_STACK_CHECK FALSE
-
-/**
- * @brief Debug option, stacks initialization.
- * @details If enabled then the threads working area is filled with a byte
- * value when a thread is created. This can be useful for the
- * runtime measurement of the used stack.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_FILL_THREADS FALSE
-
-/**
- * @brief Debug option, threads profiling.
- * @details If enabled then a field is added to the @p thread_t structure that
- * counts the system ticks occurred while executing the thread.
- *
- * @note The default is @p FALSE.
- * @note This debug option is not currently compatible with the
- * tickless mode.
- */
-#define CH_DBG_THREADS_PROFILING FALSE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Kernel hooks
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Threads descriptor structure extension.
- * @details User fields added to the end of the @p thread_t structure.
- */
-#define CH_CFG_THREAD_EXTRA_FIELDS \
- /* Add threads custom fields here.*/
-
-/**
- * @brief Threads initialization hook.
- * @details User initialization code added to the @p chThdInit() API.
- *
- * @note It is invoked from within @p chThdInit() and implicitly from all
- * the threads creation APIs.
- */
-#define CH_CFG_THREAD_INIT_HOOK(tp) { \
- /* Add threads initialization code here.*/ \
-}
-
-/**
- * @brief Threads finalization hook.
- * @details User finalization code added to the @p chThdExit() API.
- *
- * @note It is inserted into lock zone.
- * @note It is also invoked when the threads simply return in order to
- * terminate.
- */
-#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
- /* Add threads finalization code here.*/ \
-}
-
-/**
- * @brief Context switch hook.
- * @details This hook is invoked just before switching between threads.
- */
-#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
- /* System halt code here.*/ \
-}
-
-/**
- * @brief Idle thread enter hook.
- * @note This hook is invoked within a critical zone, no OS functions
- * should be invoked from here.
- * @note This macro can be used to activate a power saving mode.
- */
-#define CH_CFG_IDLE_ENTER_HOOK() { \
-}
-
-/**
- * @brief Idle thread leave hook.
- * @note This hook is invoked within a critical zone, no OS functions
- * should be invoked from here.
- * @note This macro can be used to deactivate a power saving mode.
- */
-#define CH_CFG_IDLE_LEAVE_HOOK() { \
-}
-
-/**
- * @brief Idle Loop hook.
- * @details This hook is continuously invoked by the idle thread loop.
- */
-#define CH_CFG_IDLE_LOOP_HOOK() { \
- /* Idle loop code here.*/ \
-}
-
-/**
- * @brief System tick event hook.
- * @details This hook is invoked in the system tick handler immediately
- * after processing the virtual timers queue.
- */
-#define CH_CFG_SYSTEM_TICK_HOOK() { \
- /* System tick event code here.*/ \
-}
-
-/**
- * @brief System halt hook.
- * @details This hook is invoked in case to a system halting error before
- * the system is halted.
- */
-#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
- /* System halt code here.*/ \
-}
-
-/** @} */
-
-/*===========================================================================*/
-/* Port-specific settings (override port settings defaulted in chcore.h). */
-/*===========================================================================*/
-
-#endif /* _CHCONF_H_ */
-
-/** @} */
--- a/demos/chibios/apps/olimex_stm32_lcd_sd/config.h
+++ /dev/null
@@ -1,7 +1,0 @@
-
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-#define EXT_LOGICAL_BLOCK_SIZE 4096
-
-#endif /* CONFIG_H_ */
--- a/demos/chibios/apps/olimex_stm32_lcd_sd/halconf.h
+++ /dev/null
@@ -1,327 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file templates/halconf.h
- * @brief HAL configuration header.
- * @details HAL configuration file, this file allows to enable or disable the
- * various device drivers from your application. You may also use
- * this file in order to override the device drivers default settings.
- *
- * @addtogroup HAL_CONF
- * @{
- */
-
-#ifndef _HALCONF_H_
-#define _HALCONF_H_
-
-#include "mcuconf.h"
-
-/**
- * @brief Enables the PAL subsystem.
- */
-#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
-#define HAL_USE_PAL TRUE
-#endif
-
-/**
- * @brief Enables the ADC subsystem.
- */
-#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
-#define HAL_USE_ADC FALSE
-#endif
-
-/**
- * @brief Enables the CAN subsystem.
- */
-#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
-#define HAL_USE_CAN FALSE
-#endif
-
-/**
- * @brief Enables the EXT subsystem.
- */
-#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
-#define HAL_USE_EXT FALSE
-#endif
-
-/**
- * @brief Enables the GPT subsystem.
- */
-#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
-#define HAL_USE_GPT FALSE
-#endif
-
-/**
- * @brief Enables the I2C subsystem.
- */
-#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
-#define HAL_USE_I2C FALSE
-#endif
-
-/**
- * @brief Enables the I2S subsystem.
- */
-#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
-#define HAL_USE_I2S FALSE
-#endif
-
-/**
- * @brief Enables the ICU subsystem.
- */
-#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
-#define HAL_USE_ICU FALSE
-#endif
-
-/**
- * @brief Enables the MAC subsystem.
- */
-#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
-#define HAL_USE_MAC FALSE
-#endif
-
-/**
- * @brief Enables the MMC_SPI subsystem.
- */
-#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_MMC_SPI FALSE
-#endif
-
-/**
- * @brief Enables the PWM subsystem.
- */
-#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
-#define HAL_USE_PWM FALSE
-#endif
-
-/**
- * @brief Enables the RTC subsystem.
- */
-#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
-#define HAL_USE_RTC FALSE
-#endif
-
-/**
- * @brief Enables the SDC subsystem.
- */
-#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
-#define HAL_USE_SDC TRUE
-#endif
-
-/**
- * @brief Enables the SERIAL subsystem.
- */
-#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL TRUE
-#endif
-
-/**
- * @brief Enables the SERIAL over USB subsystem.
- */
-#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
-#endif
-
-/**
- * @brief Enables the SPI subsystem.
- */
-#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_SPI FALSE
-#endif
-
-/**
- * @brief Enables the UART subsystem.
- */
-#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
-#define HAL_USE_UART FALSE
-#endif
-
-/**
- * @brief Enables the USB subsystem.
- */
-#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
-#define HAL_USE_USB FALSE
-#endif
-
-/*===========================================================================*/
-/* ADC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables synchronous APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
-#define ADC_USE_WAIT TRUE
-#endif
-
-/**
- * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define ADC_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-/*===========================================================================*/
-/* CAN driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Sleep mode related APIs inclusion switch.
- */
-#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
-#define CAN_USE_SLEEP_MODE TRUE
-#endif
-
-/*===========================================================================*/
-/* I2C driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables the mutual exclusion APIs on the I2C bus.
- */
-#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define I2C_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-/*===========================================================================*/
-/* MAC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
-#define MAC_USE_ZERO_COPY FALSE
-#endif
-
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
-#define MAC_USE_EVENTS TRUE
-#endif
-
-/*===========================================================================*/
-/* MMC_SPI driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Delays insertions.
- * @details If enabled this options inserts delays into the MMC waiting
- * routines releasing some extra CPU time for the threads with
- * lower priority, this may slow down the driver a bit however.
- * This option is recommended also if the SPI driver does not
- * use a DMA channel and heavily loads the CPU.
- */
-#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
-#define MMC_NICE_WAITING TRUE
-#endif
-
-/*===========================================================================*/
-/* SDC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Number of initialization attempts before rejecting the card.
- * @note Attempts are performed at 10mS intervals.
- */
-#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
-#define SDC_INIT_RETRY 100
-#endif
-
-/**
- * @brief Include support for MMC cards.
- * @note MMC support is not yet implemented so this option must be kept
- * at @p FALSE.
- */
-#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
-#define SDC_MMC_SUPPORT FALSE
-#endif
-
-/**
- * @brief Delays insertions.
- * @details If enabled this options inserts delays into the MMC waiting
- * routines releasing some extra CPU time for the threads with
- * lower priority, this may slow down the driver a bit however.
- */
-#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
-#define SDC_NICE_WAITING TRUE
-#endif
-
-/*===========================================================================*/
-/* SERIAL driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Default bit rate.
- * @details Configuration parameter, this is the baud rate selected for the
- * default configuration.
- */
-#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
-#define SERIAL_DEFAULT_BITRATE 115200
-#endif
-
-/**
- * @brief Serial buffers size.
- * @details Configuration parameter, you can change the depth of the queue
- * buffers depending on the requirements of your application.
- * @note The default is 64 bytes for both the transmission and receive
- * buffers.
- */
-#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_BUFFERS_SIZE 16
-#endif
-
-/*===========================================================================*/
-/* SERIAL_USB driver related setting. */
-/*===========================================================================*/
-
-/**
- * @brief Serial over USB buffers size.
- * @details Configuration parameter, the buffer size must be a multiple of
- * the USB data endpoint maximum packet size.
- * @note The default is 64 bytes for both the transmission and receive
- * buffers.
- */
-#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_USB_BUFFERS_SIZE 256
-#endif
-
-/*===========================================================================*/
-/* SPI driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables synchronous APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
-#define SPI_USE_WAIT TRUE
-#endif
-
-/**
- * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define SPI_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-#endif /* _HALCONF_H_ */
-
-/** @} */
--- a/demos/chibios/apps/olimex_stm32_lcd_sd/main.c
+++ /dev/null
@@ -1,71 +1,0 @@
-
-
-#include "ch.h"
-#include "hal.h"
-#include "chprintf.h"
-#include "sdc.h"
-
-#include <sdc_lwext4.h>
-#include <test_lwext4.h>
-#include <timings.h>
-
-#include <stdio.h>
-#include <inttypes.h>
-#include <string.h>
-
-
-
-#define TEST_DELAY_MS 1000
-
-#define DIR_CNT 1000
-#define FILE_CNT 1000
-#define FILE_SIZE 8192
-
-static void lwext4_tests(void)
-{
- printf("lwext4_tests:\n");
-
- struct ext4_blockdev *bdev = sdc_bdev_get();
- struct ext4_bcache *bcache = sdc_cache_get();
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_mount(bdev, bcache))
- return;
-
- tim_wait_ms(TEST_DELAY_MS);
- test_lwext4_cleanup();
- tim_wait_ms(TEST_DELAY_MS);
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_dir_test(DIR_CNT))
- return;
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_file_test(FILE_SIZE, FILE_CNT))
- return;
-
- //test_lwext4_mp_stats();
- //test_lwext4_block_stats();
- //test_lwext4_cleanup();
-
- if(!test_lwext4_umount())
- return;
-
- printf("test finished\n\n");
-}
-
-
-int main(void)
-{
- halInit();
- chSysInit();
- sdStart(&STDOUT_SD, NULL);
-
- printf("\n\n\n\n\nboard: %s\n", BOARD_NAME);
- lwext4_tests();
-
- while (TRUE) {
- chThdSleepMilliseconds(500);
- }
-}
-
--- a/demos/chibios/apps/olimex_stm32_lcd_sd/mcuconf.h
+++ /dev/null
@@ -1,215 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#define STM32F103_MCUCONF
-
-/*
- * STM32F103 drivers configuration.
- * The following settings override the default settings present in
- * the various device driver implementation headers.
- * Note that the settings for each driver only have effect if the whole
- * driver is enabled in halconf.h.
- *
- * IRQ priorities:
- * 15...0 Lowest...Highest.
- *
- * DMA priorities:
- * 0...3 Lowest...Highest.
- */
-
-/*
- * HAL driver system settings.
- */
-#define STM32_NO_INIT FALSE
-#define STM32_HSI_ENABLED TRUE
-#define STM32_LSI_ENABLED FALSE
-#define STM32_HSE_ENABLED TRUE
-#define STM32_LSE_ENABLED FALSE
-#define STM32_SW STM32_SW_PLL
-#define STM32_PLLSRC STM32_PLLSRC_HSE
-#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
-#define STM32_PLLMUL_VALUE 9
-#define STM32_HPRE STM32_HPRE_DIV1
-#define STM32_PPRE1 STM32_PPRE1_DIV2
-#define STM32_PPRE2 STM32_PPRE2_DIV2
-#define STM32_ADCPRE STM32_ADCPRE_DIV4
-#define STM32_USB_CLOCK_REQUIRED TRUE
-#define STM32_USBPRE STM32_USBPRE_DIV1P5
-#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
-#define STM32_RTCSEL STM32_RTCSEL_HSEDIV
-#define STM32_PVD_ENABLE FALSE
-#define STM32_PLS STM32_PLS_LEV0
-
-/*
- * ADC driver system settings.
- */
-#define STM32_ADC_USE_ADC1 FALSE
-#define STM32_ADC_ADC1_DMA_PRIORITY 2
-#define STM32_ADC_ADC1_IRQ_PRIORITY 6
-
-/*
- * CAN driver system settings.
- */
-#define STM32_CAN_USE_CAN1 FALSE
-#define STM32_CAN_CAN1_IRQ_PRIORITY 11
-
-/*
- * EXT driver system settings.
- */
-#define STM32_EXT_EXTI0_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI1_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI2_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI3_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI4_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI16_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI17_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI18_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI19_IRQ_PRIORITY 6
-
-/*
- * GPT driver system settings.
- */
-#define STM32_GPT_USE_TIM1 FALSE
-#define STM32_GPT_USE_TIM2 FALSE
-#define STM32_GPT_USE_TIM3 FALSE
-#define STM32_GPT_USE_TIM4 FALSE
-#define STM32_GPT_USE_TIM5 FALSE
-#define STM32_GPT_USE_TIM8 FALSE
-#define STM32_GPT_TIM1_IRQ_PRIORITY 7
-#define STM32_GPT_TIM2_IRQ_PRIORITY 7
-#define STM32_GPT_TIM3_IRQ_PRIORITY 7
-#define STM32_GPT_TIM4_IRQ_PRIORITY 7
-#define STM32_GPT_TIM5_IRQ_PRIORITY 7
-#define STM32_GPT_TIM8_IRQ_PRIORITY 7
-
-/*
- * I2C driver system settings.
- */
-#define STM32_I2C_USE_I2C1 FALSE
-#define STM32_I2C_USE_I2C2 FALSE
-#define STM32_I2C_BUSY_TIMEOUT 50
-#define STM32_I2C_I2C1_IRQ_PRIORITY 5
-#define STM32_I2C_I2C2_IRQ_PRIORITY 5
-#define STM32_I2C_I2C1_DMA_PRIORITY 3
-#define STM32_I2C_I2C2_DMA_PRIORITY 3
-#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
-
-/*
- * ICU driver system settings.
- */
-#define STM32_ICU_USE_TIM1 FALSE
-#define STM32_ICU_USE_TIM2 FALSE
-#define STM32_ICU_USE_TIM3 FALSE
-#define STM32_ICU_USE_TIM4 FALSE
-#define STM32_ICU_USE_TIM5 FALSE
-#define STM32_ICU_USE_TIM8 FALSE
-#define STM32_ICU_TIM1_IRQ_PRIORITY 7
-#define STM32_ICU_TIM2_IRQ_PRIORITY 7
-#define STM32_ICU_TIM3_IRQ_PRIORITY 7
-#define STM32_ICU_TIM4_IRQ_PRIORITY 7
-#define STM32_ICU_TIM5_IRQ_PRIORITY 7
-#define STM32_ICU_TIM8_IRQ_PRIORITY 7
-
-/*
- * PWM driver system settings.
- */
-#define STM32_PWM_USE_ADVANCED FALSE
-#define STM32_PWM_USE_TIM1 FALSE
-#define STM32_PWM_USE_TIM2 FALSE
-#define STM32_PWM_USE_TIM3 FALSE
-#define STM32_PWM_USE_TIM4 FALSE
-#define STM32_PWM_USE_TIM5 FALSE
-#define STM32_PWM_USE_TIM8 FALSE
-#define STM32_PWM_TIM1_IRQ_PRIORITY 7
-#define STM32_PWM_TIM2_IRQ_PRIORITY 7
-#define STM32_PWM_TIM3_IRQ_PRIORITY 7
-#define STM32_PWM_TIM4_IRQ_PRIORITY 7
-#define STM32_PWM_TIM5_IRQ_PRIORITY 7
-#define STM32_PWM_TIM8_IRQ_PRIORITY 7
-
-/*
- * RTC driver system settings.
- */
-#define STM32_RTC_IRQ_PRIORITY 15
-
-/*
- * SERIAL driver system settings.
- */
-#define STM32_SERIAL_USE_USART1 TRUE
-#define STM32_SERIAL_USE_USART2 FALSE
-#define STM32_SERIAL_USE_USART3 FALSE
-#define STM32_SERIAL_USE_UART4 FALSE
-#define STM32_SERIAL_USE_UART5 FALSE
-#define STM32_SERIAL_USART1_PRIORITY 12
-#define STM32_SERIAL_USART2_PRIORITY 12
-#define STM32_SERIAL_USART3_PRIORITY 12
-#define STM32_SERIAL_UART4_PRIORITY 12
-#define STM32_SERIAL_UART5_PRIORITY 12
-
-/*
- * SPI driver system settings.
- */
-#define STM32_SPI_USE_SPI1 FALSE
-#define STM32_SPI_USE_SPI2 FALSE
-#define STM32_SPI_USE_SPI3 FALSE
-#define STM32_SPI_SPI1_DMA_PRIORITY 1
-#define STM32_SPI_SPI2_DMA_PRIORITY 1
-#define STM32_SPI_SPI3_DMA_PRIORITY 1
-#define STM32_SPI_SPI1_IRQ_PRIORITY 10
-#define STM32_SPI_SPI2_IRQ_PRIORITY 10
-#define STM32_SPI_SPI3_IRQ_PRIORITY 10
-#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
-
-/*
- * ST driver system settings.
- */
-#define STM32_ST_IRQ_PRIORITY 8
-#define STM32_ST_USE_TIMER 2
-
-/*
- * UART driver system settings.
- */
-#define STM32_UART_USE_USART1 FALSE
-#define STM32_UART_USE_USART2 FALSE
-#define STM32_UART_USE_USART3 FALSE
-#define STM32_UART_USART1_IRQ_PRIORITY 12
-#define STM32_UART_USART2_IRQ_PRIORITY 12
-#define STM32_UART_USART3_IRQ_PRIORITY 12
-#define STM32_UART_USART1_DMA_PRIORITY 0
-#define STM32_UART_USART2_DMA_PRIORITY 0
-#define STM32_UART_USART3_DMA_PRIORITY 0
-#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
-
-/*
- * USB driver system settings.
- */
-#define STM32_USB_USE_USB1 FALSE
-#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
-#define STM32_USB_USB1_HP_IRQ_PRIORITY 13
-#define STM32_USB_USB1_LP_IRQ_PRIORITY 14
-
-/*
- * SDC driver system settings.
- */
-#define STM32_SDC_SDIO_DMA_PRIORITY 3
-#define STM32_SDC_SDIO_IRQ_PRIORITY 9
-#define STM32_SDC_WRITE_TIMEOUT_MS 250
-#define STM32_SDC_READ_TIMEOUT_MS 250
-#define STM32_SDC_CLOCK_ACTIVATION_DELAY 10
-#define STM32_SDC_SDIO_UNALIGNED_SUPPORT TRUE
-#define STM32_SDC_SDIO_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
--- a/demos/chibios/apps/olimex_stm32_p107_sd/Makefile
+++ /dev/null
@@ -1,223 +1,0 @@
-##############################################################################
-# Build global options
-# NOTE: Can be overridden externally.
-#
-
-# Compiler options here.
-ifeq ($(USE_OPT),)
- USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
-endif
-
-# C specific options here (added to USE_OPT).
-ifeq ($(USE_COPT),)
- USE_COPT =
-endif
-
-# C++ specific options here (added to USE_OPT).
-ifeq ($(USE_CPPOPT),)
- USE_CPPOPT = -fno-rtti
-endif
-
-# Enable this if you want the linker to remove unused code and data
-ifeq ($(USE_LINK_GC),)
- USE_LINK_GC = yes
-endif
-
-# Linker extra options here.
-ifeq ($(USE_LDOPT),)
- USE_LDOPT =
-endif
-
-# Enable this if you want link time optimizations (LTO)
-ifeq ($(USE_LTO),)
- USE_LTO =
-endif
-
-# If enabled, this option allows to compile the application in THUMB mode.
-ifeq ($(USE_THUMB),)
- USE_THUMB = yes
-endif
-
-# Enable this if you want to see the full log while compiling.
-ifeq ($(USE_VERBOSE_COMPILE),)
- USE_VERBOSE_COMPILE = no
-endif
-
-#
-# Build global options
-##############################################################################
-
-##############################################################################
-# Architecture or project specific options
-#
-
-# Stack size to be allocated to the Cortex-M process stack. This stack is
-# the stack used by the main() thread.
-ifeq ($(USE_PROCESS_STACKSIZE),)
- USE_PROCESS_STACKSIZE = 0x800
-endif
-
-# Stack size to the allocated to the Cortex-M main/exceptions stack. This
-# stack is used for processing interrupts and exceptions.
-ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
- USE_EXCEPTIONS_STACKSIZE = 0x400
-endif
-
-# Enables the use of FPU on Cortex-M4.
-ifeq ($(USE_FPU),)
- USE_FPU = no
-endif
-
-#
-# Architecture or project specific options
-##############################################################################
-
-##############################################################################
-# Project, sources and paths
-#
-ifndef CHIBIOS
-CHIBIOS = ../../../../../ChibiOS
-endif
-
-LWEXT4 = ../../../..
-COMMON = ../../common
-
-# Define project name here
-PROJECT = olimex_stm32_p107_sd
-
-# Imported source files and paths
-include ../../boards/olimex_stm32_p107/board.mk
-
-# Startup files.
-include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
-# HAL-OSAL files (optional).
-include $(CHIBIOS)/os/hal/hal.mk
-include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform.mk
-include $(CHIBIOS)/os/hal/osal/rt/osal.mk
-# RTOS files (optional).
-include $(CHIBIOS)/os/rt/rt.mk
-include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
-# Other files (optional).
-include $(CHIBIOS)/test/rt/test.mk
-
-# Define linker script file here
-LDSCRIPT= $(STARTUPLD)/STM32F103xD.ld
-
-# C sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CSRC = $(STARTUPSRC) \
- $(KERNSRC) \
- $(PORTSRC) \
- $(OSALSRC) \
- $(HALSRC) \
- $(PLATFORMSRC) \
- $(BOARDSRC) \
- $(TESTSRC) \
- $(CHIBIOS)/os/hal/lib/streams/chprintf.c \
- $(CHIBIOS)/os/various/syscalls.c \
- main.c
-
-CSRC += $(COMMON)/spi_lwext4.c
-CSRC += $(COMMON)/test_lwext4.c
-CSRC += $(COMMON)/timings.c
-
-# C++ sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CPPSRC =
-
-# C sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACSRC =
-
-# C++ sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACPPSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCPPSRC =
-
-# List ASM source files here
-ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
-
-INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
- $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
- $(CHIBIOS)/os/various $(CHIBIOS)/os/hal/lib/streams
-
-
-#
-# Project, sources and paths
-##############################################################################
-
-##############################################################################
-# Compiler settings
-#
-
-MCU = cortex-m3
-
-#TRGT = arm-elf-
-TRGT = arm-none-eabi-
-CC = $(TRGT)gcc
-CPPC = $(TRGT)g++
-# Enable loading with g++ only if you need C++ runtime support.
-# NOTE: You can use C++ even without C++ support if you are careful. C++
-# runtime support makes code size explode.
-LD = $(TRGT)gcc
-#LD = $(TRGT)g++
-CP = $(TRGT)objcopy
-AS = $(TRGT)gcc -x assembler-with-cpp
-AR = $(TRGT)ar
-OD = $(TRGT)objdump
-SZ = $(TRGT)size
-HEX = $(CP) -O ihex
-BIN = $(CP) -O binary
-
-# ARM-specific options here
-AOPT =
-
-# THUMB-specific options here
-TOPT = -mthumb -DTHUMB
-
-# Define C warning options here
-CWARN = -Wall -Wextra -Wstrict-prototypes
-
-# Define C++ warning options here
-CPPWARN = -Wall -Wextra
-
-#
-# Compiler settings
-##############################################################################
-
-##############################################################################
-# Start of user section
-#
-
-# List all user C define here, like -D_DEBUG=1
-UDEFS = -DSTDOUT_SD=SD2
-
-# Define ASM defines here
-UADEFS =
-
-# List all user directories here
-UINCDIR = $(LWEXT4)/lwext4 $(COMMON)
-
-# List the user directory to look for the libraries here
-ULIBDIR = $(LWEXT4)/build_cortex-m3/lwext4
-
-# List all user libraries here
-ULIBS = -llwext4
-
-#
-# End of user defines
-##############################################################################
-
-RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
-include $(RULESPATH)/rules.mk
--- a/demos/chibios/apps/olimex_stm32_p107_sd/chconf.h
+++ /dev/null
@@ -1,498 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file templates/chconf.h
- * @brief Configuration file template.
- * @details A copy of this file must be placed in each project directory, it
- * contains the application specific kernel settings.
- *
- * @addtogroup config
- * @details Kernel related settings and hooks.
- * @{
- */
-
-#ifndef _CHCONF_H_
-#define _CHCONF_H_
-
-/*===========================================================================*/
-/**
- * @name System timers settings
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief System time counter resolution.
- * @note Allowed values are 16 or 32 bits.
- */
-#define CH_CFG_ST_RESOLUTION 16
-
-/**
- * @brief System tick frequency.
- * @details Frequency of the system timer that drives the system ticks. This
- * setting also defines the system tick time unit.
- */
-#define CH_CFG_ST_FREQUENCY 2000
-
-/**
- * @brief Time delta constant for the tick-less mode.
- * @note If this value is zero then the system uses the classic
- * periodic tick. This value represents the minimum number
- * of ticks that is safe to specify in a timeout directive.
- * The value one is not valid, timeouts are rounded up to
- * this value.
- */
-#define CH_CFG_ST_TIMEDELTA 2
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Kernel parameters and options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Round robin interval.
- * @details This constant is the number of system ticks allowed for the
- * threads before preemption occurs. Setting this value to zero
- * disables the preemption for threads with equal priority and the
- * round robin becomes cooperative. Note that higher priority
- * threads can still preempt, the kernel is always preemptive.
- * @note Disabling the round robin preemption makes the kernel more compact
- * and generally faster.
- * @note The round robin preemption is not supported in tickless mode and
- * must be set to zero in that case.
- */
-#define CH_CFG_TIME_QUANTUM 0
-
-/**
- * @brief Managed RAM size.
- * @details Size of the RAM area to be managed by the OS. If set to zero
- * then the whole available RAM is used. The core memory is made
- * available to the heap allocator and/or can be used directly through
- * the simplified core memory allocator.
- *
- * @note In order to let the OS manage the whole RAM the linker script must
- * provide the @p __heap_base__ and @p __heap_end__ symbols.
- * @note Requires @p CH_CFG_USE_MEMCORE.
- */
-#define CH_CFG_MEMCORE_SIZE 0
-
-/**
- * @brief Idle thread automatic spawn suppression.
- * @details When this option is activated the function @p chSysInit()
- * does not spawn the idle thread. The application @p main()
- * function becomes the idle thread and must implement an
- * infinite loop. */
-#define CH_CFG_NO_IDLE_THREAD FALSE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Performance options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief OS optimization.
- * @details If enabled then time efficient rather than space efficient code
- * is used when two possible implementations exist.
- *
- * @note This is not related to the compiler optimization options.
- * @note The default is @p TRUE.
- */
-#define CH_CFG_OPTIMIZE_SPEED TRUE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Subsystem options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Time Measurement APIs.
- * @details If enabled then the time measurement APIs are included in
- * the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_TM TRUE
-
-/**
- * @brief Threads registry APIs.
- * @details If enabled then the registry APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_REGISTRY TRUE
-
-/**
- * @brief Threads synchronization APIs.
- * @details If enabled then the @p chThdWait() function is included in
- * the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_WAITEXIT TRUE
-
-/**
- * @brief Semaphores APIs.
- * @details If enabled then the Semaphores APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_SEMAPHORES TRUE
-
-/**
- * @brief Semaphores queuing mode.
- * @details If enabled then the threads are enqueued on semaphores by
- * priority rather than in FIFO order.
- *
- * @note The default is @p FALSE. Enable this if you have special
- * requirements.
- * @note Requires @p CH_CFG_USE_SEMAPHORES.
- */
-#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
-
-/**
- * @brief Mutexes APIs.
- * @details If enabled then the mutexes APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MUTEXES TRUE
-
-/**
- * @brief Enables recursive behavior on mutexes.
- * @note Recursive mutexes are heavier and have an increased
- * memory footprint.
- *
- * @note The default is @p FALSE.
- * @note Requires @p CH_CFG_USE_MUTEXES.
- */
-#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
-
-/**
- * @brief Conditional Variables APIs.
- * @details If enabled then the conditional variables APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_MUTEXES.
- */
-#define CH_CFG_USE_CONDVARS TRUE
-
-/**
- * @brief Conditional Variables APIs with timeout.
- * @details If enabled then the conditional variables APIs with timeout
- * specification are included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_CONDVARS.
- */
-#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
-
-/**
- * @brief Events Flags APIs.
- * @details If enabled then the event flags APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_EVENTS TRUE
-
-/**
- * @brief Events Flags APIs with timeout.
- * @details If enabled then the events APIs with timeout specification
- * are included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_EVENTS.
- */
-#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
-
-/**
- * @brief Synchronous Messages APIs.
- * @details If enabled then the synchronous messages APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MESSAGES TRUE
-
-/**
- * @brief Synchronous Messages queuing mode.
- * @details If enabled then messages are served by priority rather than in
- * FIFO order.
- *
- * @note The default is @p FALSE. Enable this if you have special
- * requirements.
- * @note Requires @p CH_CFG_USE_MESSAGES.
- */
-#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
-
-/**
- * @brief Mailboxes APIs.
- * @details If enabled then the asynchronous messages (mailboxes) APIs are
- * included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_SEMAPHORES.
- */
-#define CH_CFG_USE_MAILBOXES TRUE
-
-/**
- * @brief I/O Queues APIs.
- * @details If enabled then the I/O queues APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_QUEUES TRUE
-
-/**
- * @brief Core Memory Manager APIs.
- * @details If enabled then the core memory manager APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MEMCORE TRUE
-
-/**
- * @brief Heap Allocator APIs.
- * @details If enabled then the memory heap allocator APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
- * @p CH_CFG_USE_SEMAPHORES.
- * @note Mutexes are recommended.
- */
-#define CH_CFG_USE_HEAP TRUE
-
-/**
- * @brief Memory Pools Allocator APIs.
- * @details If enabled then the memory pools allocator APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MEMPOOLS TRUE
-
-/**
- * @brief Dynamic Threads APIs.
- * @details If enabled then the dynamic threads creation APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_WAITEXIT.
- * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
- */
-#define CH_CFG_USE_DYNAMIC TRUE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Debug options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Debug option, kernel statistics.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_STATISTICS FALSE
-
-/**
- * @brief Debug option, system state check.
- * @details If enabled the correct call protocol for system APIs is checked
- * at runtime.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_SYSTEM_STATE_CHECK FALSE
-
-/**
- * @brief Debug option, parameters checks.
- * @details If enabled then the checks on the API functions input
- * parameters are activated.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_CHECKS FALSE
-
-/**
- * @brief Debug option, consistency checks.
- * @details If enabled then all the assertions in the kernel code are
- * activated. This includes consistency checks inside the kernel,
- * runtime anomalies and port-defined checks.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_ASSERTS FALSE
-
-/**
- * @brief Debug option, trace buffer.
- * @details If enabled then the context switch circular trace buffer is
- * activated.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_TRACE FALSE
-
-/**
- * @brief Debug option, stack checks.
- * @details If enabled then a runtime stack check is performed.
- *
- * @note The default is @p FALSE.
- * @note The stack check is performed in a architecture/port dependent way.
- * It may not be implemented or some ports.
- * @note The default failure mode is to halt the system with the global
- * @p panic_msg variable set to @p NULL.
- */
-#define CH_DBG_ENABLE_STACK_CHECK FALSE
-
-/**
- * @brief Debug option, stacks initialization.
- * @details If enabled then the threads working area is filled with a byte
- * value when a thread is created. This can be useful for the
- * runtime measurement of the used stack.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_FILL_THREADS FALSE
-
-/**
- * @brief Debug option, threads profiling.
- * @details If enabled then a field is added to the @p thread_t structure that
- * counts the system ticks occurred while executing the thread.
- *
- * @note The default is @p FALSE.
- * @note This debug option is not currently compatible with the
- * tickless mode.
- */
-#define CH_DBG_THREADS_PROFILING FALSE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Kernel hooks
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Threads descriptor structure extension.
- * @details User fields added to the end of the @p thread_t structure.
- */
-#define CH_CFG_THREAD_EXTRA_FIELDS \
- /* Add threads custom fields here.*/
-
-/**
- * @brief Threads initialization hook.
- * @details User initialization code added to the @p chThdInit() API.
- *
- * @note It is invoked from within @p chThdInit() and implicitly from all
- * the threads creation APIs.
- */
-#define CH_CFG_THREAD_INIT_HOOK(tp) { \
- /* Add threads initialization code here.*/ \
-}
-
-/**
- * @brief Threads finalization hook.
- * @details User finalization code added to the @p chThdExit() API.
- *
- * @note It is inserted into lock zone.
- * @note It is also invoked when the threads simply return in order to
- * terminate.
- */
-#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
- /* Add threads finalization code here.*/ \
-}
-
-/**
- * @brief Context switch hook.
- * @details This hook is invoked just before switching between threads.
- */
-#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
- /* System halt code here.*/ \
-}
-
-/**
- * @brief Idle thread enter hook.
- * @note This hook is invoked within a critical zone, no OS functions
- * should be invoked from here.
- * @note This macro can be used to activate a power saving mode.
- */
-#define CH_CFG_IDLE_ENTER_HOOK() { \
-}
-
-/**
- * @brief Idle thread leave hook.
- * @note This hook is invoked within a critical zone, no OS functions
- * should be invoked from here.
- * @note This macro can be used to deactivate a power saving mode.
- */
-#define CH_CFG_IDLE_LEAVE_HOOK() { \
-}
-
-/**
- * @brief Idle Loop hook.
- * @details This hook is continuously invoked by the idle thread loop.
- */
-#define CH_CFG_IDLE_LOOP_HOOK() { \
- /* Idle loop code here.*/ \
-}
-
-/**
- * @brief System tick event hook.
- * @details This hook is invoked in the system tick handler immediately
- * after processing the virtual timers queue.
- */
-#define CH_CFG_SYSTEM_TICK_HOOK() { \
- /* System tick event code here.*/ \
-}
-
-/**
- * @brief System halt hook.
- * @details This hook is invoked in case to a system halting error before
- * the system is halted.
- */
-#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
- /* System halt code here.*/ \
-}
-
-/** @} */
-
-/*===========================================================================*/
-/* Port-specific settings (override port settings defaulted in chcore.h). */
-/*===========================================================================*/
-
-#endif /* _CHCONF_H_ */
-
-/** @} */
--- a/demos/chibios/apps/olimex_stm32_p107_sd/config.h
+++ /dev/null
@@ -1,7 +1,0 @@
-
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-#define EXT_LOGICAL_BLOCK_SIZE 4096
-
-#endif /* CONFIG_H_ */
--- a/demos/chibios/apps/olimex_stm32_p107_sd/halconf.h
+++ /dev/null
@@ -1,327 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file templates/halconf.h
- * @brief HAL configuration header.
- * @details HAL configuration file, this file allows to enable or disable the
- * various device drivers from your application. You may also use
- * this file in order to override the device drivers default settings.
- *
- * @addtogroup HAL_CONF
- * @{
- */
-
-#ifndef _HALCONF_H_
-#define _HALCONF_H_
-
-#include "mcuconf.h"
-
-/**
- * @brief Enables the PAL subsystem.
- */
-#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
-#define HAL_USE_PAL TRUE
-#endif
-
-/**
- * @brief Enables the ADC subsystem.
- */
-#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
-#define HAL_USE_ADC FALSE
-#endif
-
-/**
- * @brief Enables the CAN subsystem.
- */
-#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
-#define HAL_USE_CAN FALSE
-#endif
-
-/**
- * @brief Enables the EXT subsystem.
- */
-#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
-#define HAL_USE_EXT FALSE
-#endif
-
-/**
- * @brief Enables the GPT subsystem.
- */
-#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
-#define HAL_USE_GPT FALSE
-#endif
-
-/**
- * @brief Enables the I2C subsystem.
- */
-#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
-#define HAL_USE_I2C FALSE
-#endif
-
-/**
- * @brief Enables the I2S subsystem.
- */
-#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
-#define HAL_USE_I2S FALSE
-#endif
-
-/**
- * @brief Enables the ICU subsystem.
- */
-#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
-#define HAL_USE_ICU FALSE
-#endif
-
-/**
- * @brief Enables the MAC subsystem.
- */
-#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
-#define HAL_USE_MAC FALSE
-#endif
-
-/**
- * @brief Enables the MMC_SPI subsystem.
- */
-#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_MMC_SPI TRUE
-#endif
-
-/**
- * @brief Enables the PWM subsystem.
- */
-#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
-#define HAL_USE_PWM FALSE
-#endif
-
-/**
- * @brief Enables the RTC subsystem.
- */
-#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
-#define HAL_USE_RTC FALSE
-#endif
-
-/**
- * @brief Enables the SDC subsystem.
- */
-#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
-#define HAL_USE_SDC FALSE
-#endif
-
-/**
- * @brief Enables the SERIAL subsystem.
- */
-#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL TRUE
-#endif
-
-/**
- * @brief Enables the SERIAL over USB subsystem.
- */
-#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
-#endif
-
-/**
- * @brief Enables the SPI subsystem.
- */
-#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_SPI TRUE
-#endif
-
-/**
- * @brief Enables the UART subsystem.
- */
-#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
-#define HAL_USE_UART FALSE
-#endif
-
-/**
- * @brief Enables the USB subsystem.
- */
-#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
-#define HAL_USE_USB FALSE
-#endif
-
-/*===========================================================================*/
-/* ADC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables synchronous APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
-#define ADC_USE_WAIT TRUE
-#endif
-
-/**
- * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define ADC_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-/*===========================================================================*/
-/* CAN driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Sleep mode related APIs inclusion switch.
- */
-#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
-#define CAN_USE_SLEEP_MODE TRUE
-#endif
-
-/*===========================================================================*/
-/* I2C driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables the mutual exclusion APIs on the I2C bus.
- */
-#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define I2C_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-/*===========================================================================*/
-/* MAC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
-#define MAC_USE_ZERO_COPY FALSE
-#endif
-
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
-#define MAC_USE_EVENTS TRUE
-#endif
-
-/*===========================================================================*/
-/* MMC_SPI driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Delays insertions.
- * @details If enabled this options inserts delays into the MMC waiting
- * routines releasing some extra CPU time for the threads with
- * lower priority, this may slow down the driver a bit however.
- * This option is recommended also if the SPI driver does not
- * use a DMA channel and heavily loads the CPU.
- */
-#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
-#define MMC_NICE_WAITING TRUE
-#endif
-
-/*===========================================================================*/
-/* SDC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Number of initialization attempts before rejecting the card.
- * @note Attempts are performed at 10mS intervals.
- */
-#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
-#define SDC_INIT_RETRY 100
-#endif
-
-/**
- * @brief Include support for MMC cards.
- * @note MMC support is not yet implemented so this option must be kept
- * at @p FALSE.
- */
-#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
-#define SDC_MMC_SUPPORT FALSE
-#endif
-
-/**
- * @brief Delays insertions.
- * @details If enabled this options inserts delays into the MMC waiting
- * routines releasing some extra CPU time for the threads with
- * lower priority, this may slow down the driver a bit however.
- */
-#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
-#define SDC_NICE_WAITING TRUE
-#endif
-
-/*===========================================================================*/
-/* SERIAL driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Default bit rate.
- * @details Configuration parameter, this is the baud rate selected for the
- * default configuration.
- */
-#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
-#define SERIAL_DEFAULT_BITRATE 115200
-#endif
-
-/**
- * @brief Serial buffers size.
- * @details Configuration parameter, you can change the depth of the queue
- * buffers depending on the requirements of your application.
- * @note The default is 64 bytes for both the transmission and receive
- * buffers.
- */
-#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_BUFFERS_SIZE 16
-#endif
-
-/*===========================================================================*/
-/* SERIAL_USB driver related setting. */
-/*===========================================================================*/
-
-/**
- * @brief Serial over USB buffers size.
- * @details Configuration parameter, the buffer size must be a multiple of
- * the USB data endpoint maximum packet size.
- * @note The default is 64 bytes for both the transmission and receive
- * buffers.
- */
-#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_USB_BUFFERS_SIZE 256
-#endif
-
-/*===========================================================================*/
-/* SPI driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables synchronous APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
-#define SPI_USE_WAIT TRUE
-#endif
-
-/**
- * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define SPI_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-#endif /* _HALCONF_H_ */
-
-/** @} */
--- a/demos/chibios/apps/olimex_stm32_p107_sd/main.c
+++ /dev/null
@@ -1,91 +1,0 @@
-
-
-#include "ch.h"
-#include "hal.h"
-#include "chprintf.h"
-#include "sdc.h"
-
-#include <spi_lwext4.h>
-#include <test_lwext4.h>
-#include <timings.h>
-
-#include <stdio.h>
-#include <inttypes.h>
-#include <string.h>
-
-MMCDriver MMCD1;
-
-static const SPIConfig lscfg = {
- NULL,
- IOPORT1,
- GPIOA_SPI3_CS_MMC,
- SPI_CR1_BR_1 | SPI_CR1_BR_0
-};
-static const SPIConfig hscfg = {
- NULL,
- IOPORT1,
- GPIOA_SPI3_CS_MMC,
- 0
-};
-
-static MMCConfig config = {
- &SPID3, &lscfg, &hscfg
-};
-
-#define TEST_DELAY_MS 1000
-
-#define DIR_CNT 1000
-#define FILE_CNT 1000
-#define FILE_SIZE 8192
-
-static void lwext4_tests(void)
-{
- printf("lwext4_tests:\n");
-
- struct ext4_blockdev *bdev = spi_bdev_get();
- struct ext4_bcache *bcache = spi_cache_get();
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_mount(bdev, bcache))
- return;
-
- tim_wait_ms(TEST_DELAY_MS);
- test_lwext4_cleanup();
- tim_wait_ms(TEST_DELAY_MS);
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_dir_test(DIR_CNT))
- return;
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_file_test(FILE_SIZE, FILE_CNT))
- return;
-
- //test_lwext4_mp_stats();
- //test_lwext4_block_stats();
- //test_lwext4_cleanup();
-
- if(!test_lwext4_umount())
- return;
-
- printf("test finished\n\n");
-}
-
-
-int main(void)
-{
- halInit();
- chSysInit();
- sdStart(&STDOUT_SD, NULL);
-
- mmcObjectInit(&MMCD1);
- mmcStart(&MMCD1, &config);
-
- printf("\n\n\n\n\nboard: %s\n", BOARD_NAME);
- lwext4_tests();
-
- while (TRUE) {
- chThdSleepMilliseconds(500);
- }
-}
-
--- a/demos/chibios/apps/olimex_stm32_p107_sd/mcuconf.h
+++ /dev/null
@@ -1,205 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#define STM32F107_MCUCONF
-
-/*
- * STM32F103 drivers configuration.
- * The following settings override the default settings present in
- * the various device driver implementation headers.
- * Note that the settings for each driver only have effect if the whole
- * driver is enabled in halconf.h.
- *
- * IRQ priorities:
- * 15...0 Lowest...Highest.
- *
- * DMA priorities:
- * 0...3 Lowest...Highest.
- */
-
-/*
- * HAL driver system settings.
- */
-#define STM32_NO_INIT FALSE
-#define STM32_HSI_ENABLED TRUE
-#define STM32_LSI_ENABLED FALSE
-#define STM32_HSE_ENABLED TRUE
-#define STM32_LSE_ENABLED FALSE
-#define STM32_SW STM32_SW_PLL
-#define STM32_PLLSRC STM32_PLLSRC_HSI
-#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
-#define STM32_PLLMUL_VALUE 9
-#define STM32_HPRE STM32_HPRE_DIV1
-#define STM32_PPRE1 STM32_PPRE1_DIV2
-#define STM32_PPRE2 STM32_PPRE2_DIV2
-#define STM32_ADCPRE STM32_ADCPRE_DIV4
-#define STM32_USB_CLOCK_REQUIRED TRUE
-#define STM32_USBPRE STM32_USBPRE_DIV1P5
-#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
-#define STM32_RTCSEL STM32_RTCSEL_HSEDIV
-#define STM32_PVD_ENABLE FALSE
-#define STM32_PLS STM32_PLS_LEV0
-
-/*
- * ADC driver system settings.
- */
-#define STM32_ADC_USE_ADC1 FALSE
-#define STM32_ADC_ADC1_DMA_PRIORITY 2
-#define STM32_ADC_ADC1_IRQ_PRIORITY 6
-
-/*
- * CAN driver system settings.
- */
-#define STM32_CAN_USE_CAN1 FALSE
-#define STM32_CAN_CAN1_IRQ_PRIORITY 11
-
-/*
- * EXT driver system settings.
- */
-#define STM32_EXT_EXTI0_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI1_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI2_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI3_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI4_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI16_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI17_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI18_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI19_IRQ_PRIORITY 6
-
-/*
- * GPT driver system settings.
- */
-#define STM32_GPT_USE_TIM1 FALSE
-#define STM32_GPT_USE_TIM2 FALSE
-#define STM32_GPT_USE_TIM3 FALSE
-#define STM32_GPT_USE_TIM4 FALSE
-#define STM32_GPT_USE_TIM5 FALSE
-#define STM32_GPT_USE_TIM8 FALSE
-#define STM32_GPT_TIM1_IRQ_PRIORITY 7
-#define STM32_GPT_TIM2_IRQ_PRIORITY 7
-#define STM32_GPT_TIM3_IRQ_PRIORITY 7
-#define STM32_GPT_TIM4_IRQ_PRIORITY 7
-#define STM32_GPT_TIM5_IRQ_PRIORITY 7
-#define STM32_GPT_TIM8_IRQ_PRIORITY 7
-
-/*
- * I2C driver system settings.
- */
-#define STM32_I2C_USE_I2C1 FALSE
-#define STM32_I2C_USE_I2C2 FALSE
-#define STM32_I2C_BUSY_TIMEOUT 50
-#define STM32_I2C_I2C1_IRQ_PRIORITY 5
-#define STM32_I2C_I2C2_IRQ_PRIORITY 5
-#define STM32_I2C_I2C1_DMA_PRIORITY 3
-#define STM32_I2C_I2C2_DMA_PRIORITY 3
-#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
-
-/*
- * ICU driver system settings.
- */
-#define STM32_ICU_USE_TIM1 FALSE
-#define STM32_ICU_USE_TIM2 FALSE
-#define STM32_ICU_USE_TIM3 FALSE
-#define STM32_ICU_USE_TIM4 FALSE
-#define STM32_ICU_USE_TIM5 FALSE
-#define STM32_ICU_USE_TIM8 FALSE
-#define STM32_ICU_TIM1_IRQ_PRIORITY 7
-#define STM32_ICU_TIM2_IRQ_PRIORITY 7
-#define STM32_ICU_TIM3_IRQ_PRIORITY 7
-#define STM32_ICU_TIM4_IRQ_PRIORITY 7
-#define STM32_ICU_TIM5_IRQ_PRIORITY 7
-#define STM32_ICU_TIM8_IRQ_PRIORITY 7
-
-/*
- * PWM driver system settings.
- */
-#define STM32_PWM_USE_ADVANCED FALSE
-#define STM32_PWM_USE_TIM1 FALSE
-#define STM32_PWM_USE_TIM2 FALSE
-#define STM32_PWM_USE_TIM3 FALSE
-#define STM32_PWM_USE_TIM4 FALSE
-#define STM32_PWM_USE_TIM5 FALSE
-#define STM32_PWM_USE_TIM8 FALSE
-#define STM32_PWM_TIM1_IRQ_PRIORITY 7
-#define STM32_PWM_TIM2_IRQ_PRIORITY 7
-#define STM32_PWM_TIM3_IRQ_PRIORITY 7
-#define STM32_PWM_TIM4_IRQ_PRIORITY 7
-#define STM32_PWM_TIM5_IRQ_PRIORITY 7
-#define STM32_PWM_TIM8_IRQ_PRIORITY 7
-
-/*
- * RTC driver system settings.
- */
-#define STM32_RTC_IRQ_PRIORITY 15
-
-/*
- * SERIAL driver system settings.
- */
-#define STM32_SERIAL_USE_USART1 FALSE
-#define STM32_SERIAL_USE_USART2 TRUE
-#define STM32_SERIAL_USE_USART3 FALSE
-#define STM32_SERIAL_USE_UART4 FALSE
-#define STM32_SERIAL_USE_UART5 FALSE
-#define STM32_SERIAL_USART1_PRIORITY 12
-#define STM32_SERIAL_USART2_PRIORITY 12
-#define STM32_SERIAL_USART3_PRIORITY 12
-#define STM32_SERIAL_UART4_PRIORITY 12
-#define STM32_SERIAL_UART5_PRIORITY 12
-
-/*
- * SPI driver system settings.
- */
-#define STM32_SPI_USE_SPI1 FALSE
-#define STM32_SPI_USE_SPI2 FALSE
-#define STM32_SPI_USE_SPI3 TRUE
-#define STM32_SPI_SPI1_DMA_PRIORITY 1
-#define STM32_SPI_SPI2_DMA_PRIORITY 1
-#define STM32_SPI_SPI3_DMA_PRIORITY 1
-#define STM32_SPI_SPI1_IRQ_PRIORITY 10
-#define STM32_SPI_SPI2_IRQ_PRIORITY 10
-#define STM32_SPI_SPI3_IRQ_PRIORITY 10
-#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
-
-/*
- * ST driver system settings.
- */
-#define STM32_ST_IRQ_PRIORITY 8
-#define STM32_ST_USE_TIMER 2
-
-/*
- * UART driver system settings.
- */
-#define STM32_UART_USE_USART1 FALSE
-#define STM32_UART_USE_USART2 FALSE
-#define STM32_UART_USE_USART3 FALSE
-#define STM32_UART_USART1_IRQ_PRIORITY 12
-#define STM32_UART_USART2_IRQ_PRIORITY 12
-#define STM32_UART_USART3_IRQ_PRIORITY 12
-#define STM32_UART_USART1_DMA_PRIORITY 0
-#define STM32_UART_USART2_DMA_PRIORITY 0
-#define STM32_UART_USART3_DMA_PRIORITY 0
-#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
-
-/*
- * USB driver system settings.
- */
-#define STM32_USB_USE_USB1 FALSE
-#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
-#define STM32_USB_USB1_HP_IRQ_PRIORITY 13
-#define STM32_USB_USB1_LP_IRQ_PRIORITY 14
-
--- a/demos/chibios/apps/redbull_v1_sd/Makefile
+++ /dev/null
@@ -1,221 +1,0 @@
-##############################################################################
-# Build global options
-# NOTE: Can be overridden externally.
-#
-
-# Compiler options here.
-ifeq ($(USE_OPT),)
- USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
-endif
-
-# C specific options here (added to USE_OPT).
-ifeq ($(USE_COPT),)
- USE_COPT =
-endif
-
-# C++ specific options here (added to USE_OPT).
-ifeq ($(USE_CPPOPT),)
- USE_CPPOPT = -fno-rtti
-endif
-
-# Enable this if you want the linker to remove unused code and data
-ifeq ($(USE_LINK_GC),)
- USE_LINK_GC = yes
-endif
-
-# Linker extra options here.
-ifeq ($(USE_LDOPT),)
- USE_LDOPT =
-endif
-
-# Enable this if you want link time optimizations (LTO)
-ifeq ($(USE_LTO),)
- USE_LTO =
-endif
-
-# If enabled, this option allows to compile the application in THUMB mode.
-ifeq ($(USE_THUMB),)
- USE_THUMB = yes
-endif
-
-# Enable this if you want to see the full log while compiling.
-ifeq ($(USE_VERBOSE_COMPILE),)
- USE_VERBOSE_COMPILE = no
-endif
-
-#
-# Build global options
-##############################################################################
-
-##############################################################################
-# Architecture or project specific options
-#
-
-# Stack size to be allocated to the Cortex-M process stack. This stack is
-# the stack used by the main() thread.
-ifeq ($(USE_PROCESS_STACKSIZE),)
- USE_PROCESS_STACKSIZE = 0x800
-endif
-
-# Stack size to the allocated to the Cortex-M main/exceptions stack. This
-# stack is used for processing interrupts and exceptions.
-ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
- USE_EXCEPTIONS_STACKSIZE = 0x400
-endif
-
-# Enables the use of FPU on Cortex-M4.
-ifeq ($(USE_FPU),)
- USE_FPU = no
-endif
-
-#
-# Architecture or project specific options
-##############################################################################
-
-##############################################################################
-# Project, sources and paths
-#
-ifndef CHIBIOS
-CHIBIOS = ../../../../../ChibiOS
-endif
-
-LWEXT4 = ../../../..
-COMMON = ../../common
-
-# Define project name here
-PROJECT = redbull_v1_sd
-
-# Imported source files and paths
-include ../../boards/redbull_v1/board.mk
-
-# Startup files.
-include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
-# HAL-OSAL files (optional).
-include $(CHIBIOS)/os/hal/hal.mk
-include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform.mk
-include $(CHIBIOS)/os/hal/osal/rt/osal.mk
-# RTOS files (optional).
-include $(CHIBIOS)/os/rt/rt.mk
-include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
-# Other files (optional).
-include $(CHIBIOS)/test/rt/test.mk
-
-# Define linker script file here
-LDSCRIPT= $(STARTUPLD)/STM32F103xD.ld
-
-# C sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CSRC = $(STARTUPSRC) \
- $(KERNSRC) \
- $(PORTSRC) \
- $(OSALSRC) \
- $(HALSRC) \
- $(PLATFORMSRC) \
- $(BOARDSRC) \
- $(TESTSRC) \
- $(CHIBIOS)/os/hal/lib/streams/chprintf.c \
- $(CHIBIOS)/os/various/syscalls.c \
- main.c
-
-CSRC += $(COMMON)/sdc_lwext4.c
-CSRC += $(COMMON)/test_lwext4.c
-CSRC += $(COMMON)/timings.c
-
-# C++ sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CPPSRC =
-
-# C sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACSRC =
-
-# C++ sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACPPSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCPPSRC =
-
-# List ASM source files here
-ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
-
-INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
- $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
- $(CHIBIOS)/os/various $(CHIBIOS)/os/hal/lib/streams
-#
-# Project, sources and paths
-##############################################################################
-
-##############################################################################
-# Compiler settings
-#
-
-MCU = cortex-m3
-
-#TRGT = arm-elf-
-TRGT = arm-none-eabi-
-CC = $(TRGT)gcc
-CPPC = $(TRGT)g++
-# Enable loading with g++ only if you need C++ runtime support.
-# NOTE: You can use C++ even without C++ support if you are careful. C++
-# runtime support makes code size explode.
-LD = $(TRGT)gcc
-#LD = $(TRGT)g++
-CP = $(TRGT)objcopy
-AS = $(TRGT)gcc -x assembler-with-cpp
-AR = $(TRGT)ar
-OD = $(TRGT)objdump
-SZ = $(TRGT)size
-HEX = $(CP) -O ihex
-BIN = $(CP) -O binary
-
-# ARM-specific options here
-AOPT =
-
-# THUMB-specific options here
-TOPT = -mthumb -DTHUMB
-
-# Define C warning options here
-CWARN = -Wall -Wextra -Wstrict-prototypes
-
-# Define C++ warning options here
-CPPWARN = -Wall -Wextra
-
-#
-# Compiler settings
-##############################################################################
-
-##############################################################################
-# Start of user section
-#
-
-# List all user C define here, like -D_DEBUG=1
-UDEFS = -DSTDOUT_SD=SD1
-
-# Define ASM defines here
-UADEFS =
-
-# List all user directories here
-UINCDIR = $(LWEXT4)/lwext4 $(COMMON)
-
-# List the user directory to look for the libraries here
-ULIBDIR = $(LWEXT4)/build_cortex-m3/lwext4
-
-# List all user libraries here
-ULIBS = -llwext4
-
-#
-# End of user defines
-##############################################################################
-
-RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
-include $(RULESPATH)/rules.mk
--- a/demos/chibios/apps/redbull_v1_sd/chconf.h
+++ /dev/null
@@ -1,498 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file templates/chconf.h
- * @brief Configuration file template.
- * @details A copy of this file must be placed in each project directory, it
- * contains the application specific kernel settings.
- *
- * @addtogroup config
- * @details Kernel related settings and hooks.
- * @{
- */
-
-#ifndef _CHCONF_H_
-#define _CHCONF_H_
-
-/*===========================================================================*/
-/**
- * @name System timers settings
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief System time counter resolution.
- * @note Allowed values are 16 or 32 bits.
- */
-#define CH_CFG_ST_RESOLUTION 16
-
-/**
- * @brief System tick frequency.
- * @details Frequency of the system timer that drives the system ticks. This
- * setting also defines the system tick time unit.
- */
-#define CH_CFG_ST_FREQUENCY 2000
-
-/**
- * @brief Time delta constant for the tick-less mode.
- * @note If this value is zero then the system uses the classic
- * periodic tick. This value represents the minimum number
- * of ticks that is safe to specify in a timeout directive.
- * The value one is not valid, timeouts are rounded up to
- * this value.
- */
-#define CH_CFG_ST_TIMEDELTA 2
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Kernel parameters and options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Round robin interval.
- * @details This constant is the number of system ticks allowed for the
- * threads before preemption occurs. Setting this value to zero
- * disables the preemption for threads with equal priority and the
- * round robin becomes cooperative. Note that higher priority
- * threads can still preempt, the kernel is always preemptive.
- * @note Disabling the round robin preemption makes the kernel more compact
- * and generally faster.
- * @note The round robin preemption is not supported in tickless mode and
- * must be set to zero in that case.
- */
-#define CH_CFG_TIME_QUANTUM 0
-
-/**
- * @brief Managed RAM size.
- * @details Size of the RAM area to be managed by the OS. If set to zero
- * then the whole available RAM is used. The core memory is made
- * available to the heap allocator and/or can be used directly through
- * the simplified core memory allocator.
- *
- * @note In order to let the OS manage the whole RAM the linker script must
- * provide the @p __heap_base__ and @p __heap_end__ symbols.
- * @note Requires @p CH_CFG_USE_MEMCORE.
- */
-#define CH_CFG_MEMCORE_SIZE 0
-
-/**
- * @brief Idle thread automatic spawn suppression.
- * @details When this option is activated the function @p chSysInit()
- * does not spawn the idle thread. The application @p main()
- * function becomes the idle thread and must implement an
- * infinite loop. */
-#define CH_CFG_NO_IDLE_THREAD FALSE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Performance options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief OS optimization.
- * @details If enabled then time efficient rather than space efficient code
- * is used when two possible implementations exist.
- *
- * @note This is not related to the compiler optimization options.
- * @note The default is @p TRUE.
- */
-#define CH_CFG_OPTIMIZE_SPEED TRUE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Subsystem options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Time Measurement APIs.
- * @details If enabled then the time measurement APIs are included in
- * the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_TM TRUE
-
-/**
- * @brief Threads registry APIs.
- * @details If enabled then the registry APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_REGISTRY TRUE
-
-/**
- * @brief Threads synchronization APIs.
- * @details If enabled then the @p chThdWait() function is included in
- * the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_WAITEXIT TRUE
-
-/**
- * @brief Semaphores APIs.
- * @details If enabled then the Semaphores APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_SEMAPHORES TRUE
-
-/**
- * @brief Semaphores queuing mode.
- * @details If enabled then the threads are enqueued on semaphores by
- * priority rather than in FIFO order.
- *
- * @note The default is @p FALSE. Enable this if you have special
- * requirements.
- * @note Requires @p CH_CFG_USE_SEMAPHORES.
- */
-#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
-
-/**
- * @brief Mutexes APIs.
- * @details If enabled then the mutexes APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MUTEXES TRUE
-
-/**
- * @brief Enables recursive behavior on mutexes.
- * @note Recursive mutexes are heavier and have an increased
- * memory footprint.
- *
- * @note The default is @p FALSE.
- * @note Requires @p CH_CFG_USE_MUTEXES.
- */
-#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
-
-/**
- * @brief Conditional Variables APIs.
- * @details If enabled then the conditional variables APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_MUTEXES.
- */
-#define CH_CFG_USE_CONDVARS TRUE
-
-/**
- * @brief Conditional Variables APIs with timeout.
- * @details If enabled then the conditional variables APIs with timeout
- * specification are included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_CONDVARS.
- */
-#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
-
-/**
- * @brief Events Flags APIs.
- * @details If enabled then the event flags APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_EVENTS TRUE
-
-/**
- * @brief Events Flags APIs with timeout.
- * @details If enabled then the events APIs with timeout specification
- * are included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_EVENTS.
- */
-#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
-
-/**
- * @brief Synchronous Messages APIs.
- * @details If enabled then the synchronous messages APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MESSAGES TRUE
-
-/**
- * @brief Synchronous Messages queuing mode.
- * @details If enabled then messages are served by priority rather than in
- * FIFO order.
- *
- * @note The default is @p FALSE. Enable this if you have special
- * requirements.
- * @note Requires @p CH_CFG_USE_MESSAGES.
- */
-#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
-
-/**
- * @brief Mailboxes APIs.
- * @details If enabled then the asynchronous messages (mailboxes) APIs are
- * included in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_SEMAPHORES.
- */
-#define CH_CFG_USE_MAILBOXES TRUE
-
-/**
- * @brief I/O Queues APIs.
- * @details If enabled then the I/O queues APIs are included in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_QUEUES TRUE
-
-/**
- * @brief Core Memory Manager APIs.
- * @details If enabled then the core memory manager APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MEMCORE TRUE
-
-/**
- * @brief Heap Allocator APIs.
- * @details If enabled then the memory heap allocator APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
- * @p CH_CFG_USE_SEMAPHORES.
- * @note Mutexes are recommended.
- */
-#define CH_CFG_USE_HEAP TRUE
-
-/**
- * @brief Memory Pools Allocator APIs.
- * @details If enabled then the memory pools allocator APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- */
-#define CH_CFG_USE_MEMPOOLS TRUE
-
-/**
- * @brief Dynamic Threads APIs.
- * @details If enabled then the dynamic threads creation APIs are included
- * in the kernel.
- *
- * @note The default is @p TRUE.
- * @note Requires @p CH_CFG_USE_WAITEXIT.
- * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
- */
-#define CH_CFG_USE_DYNAMIC TRUE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Debug options
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Debug option, kernel statistics.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_STATISTICS FALSE
-
-/**
- * @brief Debug option, system state check.
- * @details If enabled the correct call protocol for system APIs is checked
- * at runtime.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_SYSTEM_STATE_CHECK FALSE
-
-/**
- * @brief Debug option, parameters checks.
- * @details If enabled then the checks on the API functions input
- * parameters are activated.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_CHECKS FALSE
-
-/**
- * @brief Debug option, consistency checks.
- * @details If enabled then all the assertions in the kernel code are
- * activated. This includes consistency checks inside the kernel,
- * runtime anomalies and port-defined checks.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_ASSERTS FALSE
-
-/**
- * @brief Debug option, trace buffer.
- * @details If enabled then the context switch circular trace buffer is
- * activated.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_ENABLE_TRACE FALSE
-
-/**
- * @brief Debug option, stack checks.
- * @details If enabled then a runtime stack check is performed.
- *
- * @note The default is @p FALSE.
- * @note The stack check is performed in a architecture/port dependent way.
- * It may not be implemented or some ports.
- * @note The default failure mode is to halt the system with the global
- * @p panic_msg variable set to @p NULL.
- */
-#define CH_DBG_ENABLE_STACK_CHECK FALSE
-
-/**
- * @brief Debug option, stacks initialization.
- * @details If enabled then the threads working area is filled with a byte
- * value when a thread is created. This can be useful for the
- * runtime measurement of the used stack.
- *
- * @note The default is @p FALSE.
- */
-#define CH_DBG_FILL_THREADS FALSE
-
-/**
- * @brief Debug option, threads profiling.
- * @details If enabled then a field is added to the @p thread_t structure that
- * counts the system ticks occurred while executing the thread.
- *
- * @note The default is @p FALSE.
- * @note This debug option is not currently compatible with the
- * tickless mode.
- */
-#define CH_DBG_THREADS_PROFILING FALSE
-
-/** @} */
-
-/*===========================================================================*/
-/**
- * @name Kernel hooks
- * @{
- */
-/*===========================================================================*/
-
-/**
- * @brief Threads descriptor structure extension.
- * @details User fields added to the end of the @p thread_t structure.
- */
-#define CH_CFG_THREAD_EXTRA_FIELDS \
- /* Add threads custom fields here.*/
-
-/**
- * @brief Threads initialization hook.
- * @details User initialization code added to the @p chThdInit() API.
- *
- * @note It is invoked from within @p chThdInit() and implicitly from all
- * the threads creation APIs.
- */
-#define CH_CFG_THREAD_INIT_HOOK(tp) { \
- /* Add threads initialization code here.*/ \
-}
-
-/**
- * @brief Threads finalization hook.
- * @details User finalization code added to the @p chThdExit() API.
- *
- * @note It is inserted into lock zone.
- * @note It is also invoked when the threads simply return in order to
- * terminate.
- */
-#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
- /* Add threads finalization code here.*/ \
-}
-
-/**
- * @brief Context switch hook.
- * @details This hook is invoked just before switching between threads.
- */
-#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
- /* System halt code here.*/ \
-}
-
-/**
- * @brief Idle thread enter hook.
- * @note This hook is invoked within a critical zone, no OS functions
- * should be invoked from here.
- * @note This macro can be used to activate a power saving mode.
- */
-#define CH_CFG_IDLE_ENTER_HOOK() { \
-}
-
-/**
- * @brief Idle thread leave hook.
- * @note This hook is invoked within a critical zone, no OS functions
- * should be invoked from here.
- * @note This macro can be used to deactivate a power saving mode.
- */
-#define CH_CFG_IDLE_LEAVE_HOOK() { \
-}
-
-/**
- * @brief Idle Loop hook.
- * @details This hook is continuously invoked by the idle thread loop.
- */
-#define CH_CFG_IDLE_LOOP_HOOK() { \
- /* Idle loop code here.*/ \
-}
-
-/**
- * @brief System tick event hook.
- * @details This hook is invoked in the system tick handler immediately
- * after processing the virtual timers queue.
- */
-#define CH_CFG_SYSTEM_TICK_HOOK() { \
- /* System tick event code here.*/ \
-}
-
-/**
- * @brief System halt hook.
- * @details This hook is invoked in case to a system halting error before
- * the system is halted.
- */
-#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
- /* System halt code here.*/ \
-}
-
-/** @} */
-
-/*===========================================================================*/
-/* Port-specific settings (override port settings defaulted in chcore.h). */
-/*===========================================================================*/
-
-#endif /* _CHCONF_H_ */
-
-/** @} */
--- a/demos/chibios/apps/redbull_v1_sd/config.h
+++ /dev/null
@@ -1,7 +1,0 @@
-
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-#define EXT_LOGICAL_BLOCK_SIZE 4096
-
-#endif /* CONFIG_H_ */
--- a/demos/chibios/apps/redbull_v1_sd/halconf.h
+++ /dev/null
@@ -1,327 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file templates/halconf.h
- * @brief HAL configuration header.
- * @details HAL configuration file, this file allows to enable or disable the
- * various device drivers from your application. You may also use
- * this file in order to override the device drivers default settings.
- *
- * @addtogroup HAL_CONF
- * @{
- */
-
-#ifndef _HALCONF_H_
-#define _HALCONF_H_
-
-#include "mcuconf.h"
-
-/**
- * @brief Enables the PAL subsystem.
- */
-#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
-#define HAL_USE_PAL TRUE
-#endif
-
-/**
- * @brief Enables the ADC subsystem.
- */
-#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
-#define HAL_USE_ADC FALSE
-#endif
-
-/**
- * @brief Enables the CAN subsystem.
- */
-#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
-#define HAL_USE_CAN FALSE
-#endif
-
-/**
- * @brief Enables the EXT subsystem.
- */
-#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
-#define HAL_USE_EXT FALSE
-#endif
-
-/**
- * @brief Enables the GPT subsystem.
- */
-#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
-#define HAL_USE_GPT FALSE
-#endif
-
-/**
- * @brief Enables the I2C subsystem.
- */
-#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
-#define HAL_USE_I2C FALSE
-#endif
-
-/**
- * @brief Enables the I2S subsystem.
- */
-#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
-#define HAL_USE_I2S FALSE
-#endif
-
-/**
- * @brief Enables the ICU subsystem.
- */
-#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
-#define HAL_USE_ICU FALSE
-#endif
-
-/**
- * @brief Enables the MAC subsystem.
- */
-#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
-#define HAL_USE_MAC FALSE
-#endif
-
-/**
- * @brief Enables the MMC_SPI subsystem.
- */
-#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_MMC_SPI FALSE
-#endif
-
-/**
- * @brief Enables the PWM subsystem.
- */
-#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
-#define HAL_USE_PWM FALSE
-#endif
-
-/**
- * @brief Enables the RTC subsystem.
- */
-#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
-#define HAL_USE_RTC FALSE
-#endif
-
-/**
- * @brief Enables the SDC subsystem.
- */
-#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
-#define HAL_USE_SDC TRUE
-#endif
-
-/**
- * @brief Enables the SERIAL subsystem.
- */
-#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL TRUE
-#endif
-
-/**
- * @brief Enables the SERIAL over USB subsystem.
- */
-#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
-#endif
-
-/**
- * @brief Enables the SPI subsystem.
- */
-#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
-#define HAL_USE_SPI FALSE
-#endif
-
-/**
- * @brief Enables the UART subsystem.
- */
-#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
-#define HAL_USE_UART FALSE
-#endif
-
-/**
- * @brief Enables the USB subsystem.
- */
-#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
-#define HAL_USE_USB FALSE
-#endif
-
-/*===========================================================================*/
-/* ADC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables synchronous APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
-#define ADC_USE_WAIT TRUE
-#endif
-
-/**
- * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define ADC_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-/*===========================================================================*/
-/* CAN driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Sleep mode related APIs inclusion switch.
- */
-#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
-#define CAN_USE_SLEEP_MODE TRUE
-#endif
-
-/*===========================================================================*/
-/* I2C driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables the mutual exclusion APIs on the I2C bus.
- */
-#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define I2C_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-/*===========================================================================*/
-/* MAC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
-#define MAC_USE_ZERO_COPY FALSE
-#endif
-
-/**
- * @brief Enables an event sources for incoming packets.
- */
-#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
-#define MAC_USE_EVENTS TRUE
-#endif
-
-/*===========================================================================*/
-/* MMC_SPI driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Delays insertions.
- * @details If enabled this options inserts delays into the MMC waiting
- * routines releasing some extra CPU time for the threads with
- * lower priority, this may slow down the driver a bit however.
- * This option is recommended also if the SPI driver does not
- * use a DMA channel and heavily loads the CPU.
- */
-#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
-#define MMC_NICE_WAITING TRUE
-#endif
-
-/*===========================================================================*/
-/* SDC driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Number of initialization attempts before rejecting the card.
- * @note Attempts are performed at 10mS intervals.
- */
-#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
-#define SDC_INIT_RETRY 100
-#endif
-
-/**
- * @brief Include support for MMC cards.
- * @note MMC support is not yet implemented so this option must be kept
- * at @p FALSE.
- */
-#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
-#define SDC_MMC_SUPPORT FALSE
-#endif
-
-/**
- * @brief Delays insertions.
- * @details If enabled this options inserts delays into the MMC waiting
- * routines releasing some extra CPU time for the threads with
- * lower priority, this may slow down the driver a bit however.
- */
-#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
-#define SDC_NICE_WAITING TRUE
-#endif
-
-/*===========================================================================*/
-/* SERIAL driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Default bit rate.
- * @details Configuration parameter, this is the baud rate selected for the
- * default configuration.
- */
-#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
-#define SERIAL_DEFAULT_BITRATE 115200
-#endif
-
-/**
- * @brief Serial buffers size.
- * @details Configuration parameter, you can change the depth of the queue
- * buffers depending on the requirements of your application.
- * @note The default is 64 bytes for both the transmission and receive
- * buffers.
- */
-#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_BUFFERS_SIZE 16
-#endif
-
-/*===========================================================================*/
-/* SERIAL_USB driver related setting. */
-/*===========================================================================*/
-
-/**
- * @brief Serial over USB buffers size.
- * @details Configuration parameter, the buffer size must be a multiple of
- * the USB data endpoint maximum packet size.
- * @note The default is 64 bytes for both the transmission and receive
- * buffers.
- */
-#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_USB_BUFFERS_SIZE 256
-#endif
-
-/*===========================================================================*/
-/* SPI driver related settings. */
-/*===========================================================================*/
-
-/**
- * @brief Enables synchronous APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
-#define SPI_USE_WAIT TRUE
-#endif
-
-/**
- * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
- * @note Disabling this option saves both code and data space.
- */
-#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define SPI_USE_MUTUAL_EXCLUSION TRUE
-#endif
-
-#endif /* _HALCONF_H_ */
-
-/** @} */
--- a/demos/chibios/apps/redbull_v1_sd/main.c
+++ /dev/null
@@ -1,86 +1,0 @@
-
-
-#include "ch.h"
-#include "hal.h"
-#include "chprintf.h"
-#include "sdc.h"
-
-#include <sdc_lwext4.h>
-#include <test_lwext4.h>
-#include <timings.h>
-
-#include <stdio.h>
-#include <inttypes.h>
-#include <string.h>
-
-static THD_WORKING_AREA(led_thread, 128);
-static THD_FUNCTION(led_task, arg)
-{
- (void)arg;
-
- printf("led_task\n");
- while (true) {
- palSetPad(GPIOF, 6);
- chThdSleepMilliseconds(500);
- palClearPad(GPIOF, 6);
- chThdSleepMilliseconds(500);
- }
-}
-
-#define TEST_DELAY_MS 1000
-
-#define DIR_CNT 1000
-#define FILE_CNT 1000
-#define FILE_SIZE 8192
-
-static void lwext4_tests(void)
-{
- printf("lwext4_tests:\n");
-
- struct ext4_blockdev *bdev = sdc_bdev_get();
- struct ext4_bcache *bcache = sdc_cache_get();
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_mount(bdev, bcache))
- return;
-
- tim_wait_ms(TEST_DELAY_MS);
- test_lwext4_cleanup();
- tim_wait_ms(TEST_DELAY_MS);
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_dir_test(DIR_CNT))
- return;
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!test_lwext4_file_test(FILE_SIZE, FILE_CNT))
- return;
-
- //test_lwext4_mp_stats();
- //test_lwext4_block_stats();
- //test_lwext4_cleanup();
-
- if(!test_lwext4_umount())
- return;
-
- printf("test finished\n\n");
-}
-
-
-int main(void)
-{
- halInit();
- chSysInit();
- sdStart(&STDOUT_SD, NULL);
-
- printf("\n\n\n\n\nboard: %s\n", BOARD_NAME);
- lwext4_tests();
-
- chThdCreateStatic(led_thread, sizeof(led_thread), NORMALPRIO + 1,
- led_task, NULL);
-
- while (TRUE) {
- chThdSleepMilliseconds(500);
- }
-}
-
--- a/demos/chibios/apps/redbull_v1_sd/mcuconf.h
+++ /dev/null
@@ -1,215 +1,0 @@
-/*
- ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#define STM32F103_MCUCONF
-
-/*
- * STM32F103 drivers configuration.
- * The following settings override the default settings present in
- * the various device driver implementation headers.
- * Note that the settings for each driver only have effect if the whole
- * driver is enabled in halconf.h.
- *
- * IRQ priorities:
- * 15...0 Lowest...Highest.
- *
- * DMA priorities:
- * 0...3 Lowest...Highest.
- */
-
-/*
- * HAL driver system settings.
- */
-#define STM32_NO_INIT FALSE
-#define STM32_HSI_ENABLED TRUE
-#define STM32_LSI_ENABLED FALSE
-#define STM32_HSE_ENABLED TRUE
-#define STM32_LSE_ENABLED FALSE
-#define STM32_SW STM32_SW_PLL
-#define STM32_PLLSRC STM32_PLLSRC_HSE
-#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
-#define STM32_PLLMUL_VALUE 9
-#define STM32_HPRE STM32_HPRE_DIV1
-#define STM32_PPRE1 STM32_PPRE1_DIV2
-#define STM32_PPRE2 STM32_PPRE2_DIV2
-#define STM32_ADCPRE STM32_ADCPRE_DIV4
-#define STM32_USB_CLOCK_REQUIRED TRUE
-#define STM32_USBPRE STM32_USBPRE_DIV1P5
-#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
-#define STM32_RTCSEL STM32_RTCSEL_HSEDIV
-#define STM32_PVD_ENABLE FALSE
-#define STM32_PLS STM32_PLS_LEV0
-
-/*
- * ADC driver system settings.
- */
-#define STM32_ADC_USE_ADC1 FALSE
-#define STM32_ADC_ADC1_DMA_PRIORITY 2
-#define STM32_ADC_ADC1_IRQ_PRIORITY 6
-
-/*
- * CAN driver system settings.
- */
-#define STM32_CAN_USE_CAN1 FALSE
-#define STM32_CAN_CAN1_IRQ_PRIORITY 11
-
-/*
- * EXT driver system settings.
- */
-#define STM32_EXT_EXTI0_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI1_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI2_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI3_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI4_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI16_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI17_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI18_IRQ_PRIORITY 6
-#define STM32_EXT_EXTI19_IRQ_PRIORITY 6
-
-/*
- * GPT driver system settings.
- */
-#define STM32_GPT_USE_TIM1 FALSE
-#define STM32_GPT_USE_TIM2 FALSE
-#define STM32_GPT_USE_TIM3 FALSE
-#define STM32_GPT_USE_TIM4 FALSE
-#define STM32_GPT_USE_TIM5 FALSE
-#define STM32_GPT_USE_TIM8 FALSE
-#define STM32_GPT_TIM1_IRQ_PRIORITY 7
-#define STM32_GPT_TIM2_IRQ_PRIORITY 7
-#define STM32_GPT_TIM3_IRQ_PRIORITY 7
-#define STM32_GPT_TIM4_IRQ_PRIORITY 7
-#define STM32_GPT_TIM5_IRQ_PRIORITY 7
-#define STM32_GPT_TIM8_IRQ_PRIORITY 7
-
-/*
- * I2C driver system settings.
- */
-#define STM32_I2C_USE_I2C1 FALSE
-#define STM32_I2C_USE_I2C2 FALSE
-#define STM32_I2C_BUSY_TIMEOUT 50
-#define STM32_I2C_I2C1_IRQ_PRIORITY 5
-#define STM32_I2C_I2C2_IRQ_PRIORITY 5
-#define STM32_I2C_I2C1_DMA_PRIORITY 3
-#define STM32_I2C_I2C2_DMA_PRIORITY 3
-#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
-
-/*
- * ICU driver system settings.
- */
-#define STM32_ICU_USE_TIM1 FALSE
-#define STM32_ICU_USE_TIM2 FALSE
-#define STM32_ICU_USE_TIM3 FALSE
-#define STM32_ICU_USE_TIM4 FALSE
-#define STM32_ICU_USE_TIM5 FALSE
-#define STM32_ICU_USE_TIM8 FALSE
-#define STM32_ICU_TIM1_IRQ_PRIORITY 7
-#define STM32_ICU_TIM2_IRQ_PRIORITY 7
-#define STM32_ICU_TIM3_IRQ_PRIORITY 7
-#define STM32_ICU_TIM4_IRQ_PRIORITY 7
-#define STM32_ICU_TIM5_IRQ_PRIORITY 7
-#define STM32_ICU_TIM8_IRQ_PRIORITY 7
-
-/*
- * PWM driver system settings.
- */
-#define STM32_PWM_USE_ADVANCED FALSE
-#define STM32_PWM_USE_TIM1 FALSE
-#define STM32_PWM_USE_TIM2 FALSE
-#define STM32_PWM_USE_TIM3 FALSE
-#define STM32_PWM_USE_TIM4 FALSE
-#define STM32_PWM_USE_TIM5 FALSE
-#define STM32_PWM_USE_TIM8 FALSE
-#define STM32_PWM_TIM1_IRQ_PRIORITY 7
-#define STM32_PWM_TIM2_IRQ_PRIORITY 7
-#define STM32_PWM_TIM3_IRQ_PRIORITY 7
-#define STM32_PWM_TIM4_IRQ_PRIORITY 7
-#define STM32_PWM_TIM5_IRQ_PRIORITY 7
-#define STM32_PWM_TIM8_IRQ_PRIORITY 7
-
-/*
- * RTC driver system settings.
- */
-#define STM32_RTC_IRQ_PRIORITY 15
-
-/*
- * SERIAL driver system settings.
- */
-#define STM32_SERIAL_USE_USART1 TRUE
-#define STM32_SERIAL_USE_USART2 FALSE
-#define STM32_SERIAL_USE_USART3 FALSE
-#define STM32_SERIAL_USE_UART4 FALSE
-#define STM32_SERIAL_USE_UART5 FALSE
-#define STM32_SERIAL_USART1_PRIORITY 12
-#define STM32_SERIAL_USART2_PRIORITY 12
-#define STM32_SERIAL_USART3_PRIORITY 12
-#define STM32_SERIAL_UART4_PRIORITY 12
-#define STM32_SERIAL_UART5_PRIORITY 12
-
-/*
- * SPI driver system settings.
- */
-#define STM32_SPI_USE_SPI1 FALSE
-#define STM32_SPI_USE_SPI2 FALSE
-#define STM32_SPI_USE_SPI3 FALSE
-#define STM32_SPI_SPI1_DMA_PRIORITY 1
-#define STM32_SPI_SPI2_DMA_PRIORITY 1
-#define STM32_SPI_SPI3_DMA_PRIORITY 1
-#define STM32_SPI_SPI1_IRQ_PRIORITY 10
-#define STM32_SPI_SPI2_IRQ_PRIORITY 10
-#define STM32_SPI_SPI3_IRQ_PRIORITY 10
-#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
-
-/*
- * ST driver system settings.
- */
-#define STM32_ST_IRQ_PRIORITY 8
-#define STM32_ST_USE_TIMER 2
-
-/*
- * UART driver system settings.
- */
-#define STM32_UART_USE_USART1 FALSE
-#define STM32_UART_USE_USART2 FALSE
-#define STM32_UART_USE_USART3 FALSE
-#define STM32_UART_USART1_IRQ_PRIORITY 12
-#define STM32_UART_USART2_IRQ_PRIORITY 12
-#define STM32_UART_USART3_IRQ_PRIORITY 12
-#define STM32_UART_USART1_DMA_PRIORITY 0
-#define STM32_UART_USART2_DMA_PRIORITY 0
-#define STM32_UART_USART3_DMA_PRIORITY 0
-#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
-
-/*
- * USB driver system settings.
- */
-#define STM32_USB_USE_USB1 FALSE
-#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
-#define STM32_USB_USB1_HP_IRQ_PRIORITY 13
-#define STM32_USB_USB1_LP_IRQ_PRIORITY 14
-
-/*
- * SDC driver system settings.
- */
-#define STM32_SDC_SDIO_DMA_PRIORITY 3
-#define STM32_SDC_SDIO_IRQ_PRIORITY 9
-#define STM32_SDC_WRITE_TIMEOUT_MS 250
-#define STM32_SDC_READ_TIMEOUT_MS 250
-#define STM32_SDC_CLOCK_ACTIVATION_DELAY 10
-#define STM32_SDC_SDIO_UNALIGNED_SUPPORT TRUE
-#define STM32_SDC_SDIO_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
--- a/demos/chibios/boards/olimex_stm32_lcd/board.c
+++ /dev/null
@@ -1,80 +1,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "hal.h"
-
-/**
- * @brief PAL setup.
- * @details Digital I/O ports static configuration as defined in @p board.h.
- * This variable is used by the HAL when initializing the PAL driver.
- */
-#if HAL_USE_PAL || defined(__DOXYGEN__)
-const PALConfig pal_default_config =
-{
- {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
- {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
- {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
- {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
- {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
- {VAL_GPIOFODR, VAL_GPIOFCRL, VAL_GPIOFCRH},
- {VAL_GPIOGODR, VAL_GPIOGCRL, VAL_GPIOGCRH},
-};
-#endif
-
-/*
- * Early initialization code.
- * This initialization must be performed just after stack setup and before
- * any other initialization.
- */
-void __early_init(void) {
-
- stm32_clock_init();
-}
-
-/*
- * Board-specific initialization code.
- */
-void boardInit(void) {
-}
-
-#if HAL_USE_SDC
-/**
- * @brief Insertion monitor function.
- *
- * @param[in] sdcp pointer to the @p SDCDriver object
- *
- * @notapi
- */
-bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
-
- (void)sdcp;
- return true;
-}
-
-/**
- * @brief Protection detection.
- * @note Not supported, always not protected.
- *
- * @param[in] sdcp pointer to the @p SDCDriver object
- *
- * @notapi
- */
-bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
-
- (void)sdcp;
- return FALSE;
-}
-#endif /* HAL_USE_SDC */
--- a/demos/chibios/boards/olimex_stm32_lcd/board.h
+++ /dev/null
@@ -1,136 +1,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef _BOARD_H_
-#define _BOARD_H_
-
-/*
- * Setup for the Olimex STM33-H103 proto board.
- */
-
-/*
- * Board identifier.
- */
-#define BOARD_OLIMEX_STM32_LCD
-#define BOARD_NAME "olimex_stm32_lcd"
-
-/*
- * Board frequencies.
- */
-#define STM32_LSECLK 32768
-#define STM32_HSECLK 8000000
-
-/*
- * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
- */
-#define STM32F10X_HD
-
-/*
- * I/O ports initial setup, this configuration is established soon after reset
- * in the initialization code.
- *
- * The digits have the following meaning:
- * 0 - Analog input.
- * 1 - Push Pull output 10MHz.
- * 2 - Push Pull output 2MHz.
- * 3 - Push Pull output 50MHz.
- * 4 - Digital input.
- * 5 - Open Drain output 10MHz.
- * 6 - Open Drain output 2MHz.
- * 7 - Open Drain output 50MHz.
- * 8 - Digital input with PullUp or PullDown resistor depending on ODR.
- * 9 - Alternate Push Pull output 10MHz.
- * A - Alternate Push Pull output 2MHz.
- * B - Alternate Push Pull output 50MHz.
- * C - Reserved.
- * D - Alternate Open Drain output 10MHz.
- * E - Alternate Open Drain output 2MHz.
- * F - Alternate Open Drain output 50MHz.
- * Please refer to the STM32 Reference Manual for details.
- */
-
-/*
- * Port A setup.
- * Everything input with pull-up except:
- * PA0 - Normal input (BUTTON).
- * PA9 - Alternate output (USART1 TX).
- * PA10 - Normal input (USART1 RX).
- */
-#define VAL_GPIOACRL 0x88888888 /* PA7...PA0 */
-#define VAL_GPIOACRH 0x888884B8 /* PA15...PA8 */
-#define VAL_GPIOAODR 0xFFFFFFFF
-
-/*
- * Port B setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */
-#define VAL_GPIOBCRH 0x88888888 /* PB15...PB8 */
-#define VAL_GPIOBODR 0xFFFFFFFF
-
-/*
- * Port C setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOCCRL 0x44888888 /* PC7...PC0 */
-#define VAL_GPIOCCRH 0x888BBBBB /* PC15...PC8 */
-#define VAL_GPIOCODR 0xFFFFFFFF
-
-/*
- * Port D setup.
- * Everything input with pull-up except:
- * PD0 - Normal input (XTAL).
- * PD1 - Normal input (XTAL).
- */
-#define VAL_GPIODCRL 0x88888B44 /* PD7...PD0 */
-#define VAL_GPIODCRH 0x88888888 /* PD15...PD8 */
-#define VAL_GPIODODR 0xFFFFFFFF
-
-/*
- * Port E setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
-#define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */
-#define VAL_GPIOEODR 0xFFFFFFFF
-
-/*
- * Port F setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOFCRL 0x83888888 /* PE7...PE0 */
-#define VAL_GPIOFCRH 0x88888888 /* PE15...PE8 */
-#define VAL_GPIOFODR 0xFFFFFFFF
-
-/*
- * Port G setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOGCRL 0x88888888 /* PE7...PE0 */
-#define VAL_GPIOGCRH 0x88888888 /* PE15...PE8 */
-#define VAL_GPIOGODR 0xFFFFFFFF
-
-#if !defined(_FROM_ASM_)
-#ifdef __cplusplus
-extern "C" {
-#endif
- void boardInit(void);
-#ifdef __cplusplus
-}
-#endif
-#endif /* _FROM_ASM_ */
-
-#endif /* _BOARD_H_ */
--- a/demos/chibios/boards/olimex_stm32_lcd/board.mk
+++ /dev/null
@@ -1,5 +1,0 @@
-# List of all the board related files.
-BOARDSRC = ../../boards/olimex_stm32_lcd/board.c
-
-# Required include directories
-BOARDINC = ../../boards/olimex_stm32_lcd
--- a/demos/chibios/boards/olimex_stm32_p107/board.c
+++ /dev/null
@@ -1,84 +1,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "hal.h"
-
-/**
- * @brief PAL setup.
- * @details Digital I/O ports static configuration as defined in @p board.h.
- * This variable is used by the HAL when initializing the PAL driver.
- */
-#if HAL_USE_PAL || defined(__DOXYGEN__)
-const PALConfig pal_default_config =
-{
- {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
- {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
- {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
- {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
- {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
-};
-#endif
-
-/*
- * Early initialization code.
- * This initialization must be performed just after stack setup and before
- * any other initialization.
- */
-void __early_init(void) {
-
- stm32_clock_init();
-}
-
-#if HAL_USE_MMC_SPI
-/*
- * Card detection through the card internal pull-up on D3.
- */
-bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
- static bool last_status = FALSE;
-
- (void)mmcp;
- if ((palReadLatch(GPIOA) & PAL_PORT_BIT(GPIOA_SPI3_CS_MMC)) == 0)
- return last_status;
- return last_status = (bool)palReadPad(GPIOA, GPIOA_SPI3_CS_MMC);
-}
-
-/*
- * Card write protection detection is not possible, the card is always
- * reported as not protected.
- */
-bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
-
- (void)mmcp;
- return FALSE;
-}
-#endif
-
-/*
- * Board-specific initialization code.
- */
-void boardInit(void) {
-
- /*
- * Several I/O pins are re-mapped:
- * USART3 to the PD8/PD9 pins.
- * I2C1 to the PB8/PB9 pins.
- * SPI3 to the PC10/PC11/PC12 pins.
- */
- AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP |
- AFIO_MAPR_USART2_REMAP |
- AFIO_MAPR_I2C1_REMAP |
- AFIO_MAPR_SPI3_REMAP;
-}
--- a/demos/chibios/boards/olimex_stm32_p107/board.h
+++ /dev/null
@@ -1,193 +1,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef _BOARD_H_
-#define _BOARD_H_
-
-/*
- * Setup for the Olimex STM32-P107 Rev.A evaluation board.
- */
-
-/*
- * Board identifier.
- */
-#define BOARD_OLIMEX_STM32_P107_REV_A
-#define BOARD_NAME "olimex_stm32_p107"
-
-/*
- * Board frequencies.
- */
-#define STM32_LSECLK 32768
-#define STM32_HSECLK 25000000
-
-/*
- * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
- */
-#define STM32F10X_CL
-
-/*
- * Ethernet PHY type.
- */
-#define BOARD_PHY_ID MII_STE101P_ID
-#define BOARD_PHY_RMII
-
-/*
- * IO pins assignments.
- */
-#define GPIOA_SWITCH_WKUP 0
-#define GPIOA_SPI3_CS_MMC 4
-#define GPIOC_LED_STATUS1 6
-#define GPIOC_LED_STATUS2 7
-#define GPIOC_SWITCH_TAMPER 13
-
-/*
- * I/O ports initial setup, this configuration is established soon after reset
- * in the initialization code.
- *
- * The digits have the following meaning:
- * 0 - Analog input.
- * 1 - Push Pull output 10MHz.
- * 2 - Push Pull output 2MHz.
- * 3 - Push Pull output 50MHz.
- * 4 - Digital input.
- * 5 - Open Drain output 10MHz.
- * 6 - Open Drain output 2MHz.
- * 7 - Open Drain output 50MHz.
- * 8 - Digital input with PullUp or PullDown resistor depending on ODR.
- * 9 - Alternate Push Pull output 10MHz.
- * A - Alternate Push Pull output 2MHz.
- * B - Alternate Push Pull output 50MHz.
- * C - Reserved.
- * D - Alternate Open Drain output 10MHz.
- * E - Alternate Open Drain output 2MHz.
- * F - Alternate Open Drain output 50MHz.
- * Please refer to the STM32 Reference Manual for details.
- */
-
-/*
- * Port A setup.
- * Everything input with pull-up except:
- * PA0 - Normal input (WKUP BUTTON).
- * PA1 - Normal input (ETH_RMII_REF_CLK).
- * PA2 - Alternate output (ETH_RMII_MDIO).
- * PA3 - Input with PU (unconnected).
- * PA4 - Open Drain output (CS_MMC).
- * PA5 - Input with PU (unconnected).
- * PA6 - Input with PU (unconnected).
- * PA7 - Normal input (ETH_RMII_CRS_DV).
- * PA8 - Alternate output (MCO).
- * PA9 - Normal input (OTG_VBUS).
- * PA10 - Normal input (OTG_ID).
- * PA11 - Normal input (OTG_DM).
- * PA12 - Normal input (OTG_DP).
- * PA13 - Normal input (TMS).
- * PA14 - Normal input (TCK).
- * PA15 - Normal input (TDI).
- */
-#define VAL_GPIOACRL 0x48838B44 /* PA7...PA0 */
-#define VAL_GPIOACRH 0x4444444B /* PA15...PA8 */
-#define VAL_GPIOAODR 0xFFFFFFFF
-
-/*
- * Port B setup:
- * PB0 - Input with PU (unconnected).
- * PB1 - Input with PU (unconnected).
- * PB2 - Normal input (BOOT1).
- * PB3 - Normal input (TDO).
- * PB4 - Normal input (TRST).
- * PB5 - Input with PU (unconnected).
- * PB6 - Input with PU (unconnected).
- * PB7 - Input with PU (unconnected).
- * PB8 - Alternate O.D. (I2C1 SCL, remapped).
- * PB9 - Alternate O.D. (I2C1 SDA, remapped).
- * PB10 - Input with PU (unconnected).
- * PB11 - Alternate output (ETH_RMII_TX_EN).
- * PB12 - Alternate output (ETH_RMII_TXD0).
- * PB13 - Alternate output (ETH_RMII_TXD1).
- * PB14 - Input with PU (unconnected).
- * PB15 - Push Pull output (CS_UEXT).
- */
-#define VAL_GPIOBCRL 0x88844488 /* PB7...PB0 */
-#define VAL_GPIOBCRH 0x38BBB8FF /* PB15...PB8 */
-#define VAL_GPIOBODR 0xFFFFFFFF
-
-/*
- * Port C setup:
- * PC0 - Input with PU (unconnected).
- * PC1 - Alternate output (ETH_MDC).
- * PC2 - Input with PU (unconnected).
- * PC3 - Input with PU (unconnected).
- * PC4 - Normal input (ETH_RMII_RXD0).
- * PC5 - Normal input (ETH_RMII_RXD1).
- * PC6 - Push Pull output (STAT1 green LED).
- * PC7 - Push Pull output (STAT2 yellow LED).
- * PC8 - Input with PU (unconnected).
- * PC9 - Input with PU (unconnected).
- * PC10 - Alternate output (SPI3 SCK).
- * PC11 - Input with PU (SPI3 MISO).
- * PC12 - Alternate output (SPI3 MOSI).
- * PC13 - Normal input (TAMPER).
- * PC14 - Normal input (OSC32 IN).
- * PC15 - Normal input (OSC32 OUT).
- */
-#define VAL_GPIOCCRL 0x334488B8 /* PC7...PC0 */
-#define VAL_GPIOCCRH 0x444B8B88 /* PC15...PC8 */
-#define VAL_GPIOCODR 0xFFFFFF3F
-
-/*
- * Port D setup:
- * PD0 - Input with PU (unconnected).
- * PD1 - Input with PU (unconnected).
- * PD2 - Input with PU (unconnected).
- * PD3 - Input with PU (unconnected).
- * PD4 - Input with PU (unconnected).
- * PD5 - Alternate output (USART2 TX, UEXT).
- * PD6 - Input with PU (USART2 RX, UEXT).
- * PD7 - Push Pull output (USB_VBUSON).
- * PD8 - Alternate output (USART2 TX, remapped).
- * PD9 - Normal input (USART2 RX, remapped).
- * PD10 - Input with PU (unconnected).
- * PD11 - Normal input (USART2 CTS, remapped).
- * PD12 - Alternate output (USART2 RTS, remapped).
- * PD13 - Input with PU (unconnected).
- * PD14 - Input with PU (unconnected).
- * PD15 - Input with PU (unconnected).
- */
-#define VAL_GPIODCRL 0x38B88888 /* PD7...PD0 */
-#define VAL_GPIODCRH 0x888B484B /* PD15...PD8 */
-#define VAL_GPIODODR 0xFFFFFFFF
-
-/*
- * Port E setup.
- * Everything input with pull-up except:
- * PE14 - Normal input (ETH_RMII_MDINT).
- * PE15 - Normal input (USB_FAULT).
- */
-#define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
-#define VAL_GPIOECRH 0x44888888 /* PE15...PE8 */
-#define VAL_GPIOEODR 0xFFFFFFFF
-
-#if !defined(_FROM_ASM_)
-#ifdef __cplusplus
-extern "C" {
-#endif
- void boardInit(void);
-#ifdef __cplusplus
-}
-#endif
-#endif /* _FROM_ASM_ */
-
-#endif /* _BOARD_H_ */
--- a/demos/chibios/boards/olimex_stm32_p107/board.mk
+++ /dev/null
@@ -1,5 +1,0 @@
-# List of all the board related files.
-BOARDSRC = ../../boards/olimex_stm32_p107/board.c
-
-# Required include directories
-BOARDINC = ../../boards/olimex_stm32_p107
--- a/demos/chibios/boards/redbull_v1/board.c
+++ /dev/null
@@ -1,80 +1,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "hal.h"
-
-/**
- * @brief PAL setup.
- * @details Digital I/O ports static configuration as defined in @p board.h.
- * This variable is used by the HAL when initializing the PAL driver.
- */
-#if HAL_USE_PAL || defined(__DOXYGEN__)
-const PALConfig pal_default_config =
-{
- {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
- {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
- {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
- {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
- {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
- {VAL_GPIOFODR, VAL_GPIOFCRL, VAL_GPIOFCRH},
- {VAL_GPIOGODR, VAL_GPIOGCRL, VAL_GPIOGCRH},
-};
-#endif
-
-/*
- * Early initialization code.
- * This initialization must be performed just after stack setup and before
- * any other initialization.
- */
-void __early_init(void) {
-
- stm32_clock_init();
-}
-
-/*
- * Board-specific initialization code.
- */
-void boardInit(void) {
-}
-
-#if HAL_USE_SDC
-/**
- * @brief Insertion monitor function.
- *
- * @param[in] sdcp pointer to the @p SDCDriver object
- *
- * @notapi
- */
-bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
-
- (void)sdcp;
- return true;
-}
-
-/**
- * @brief Protection detection.
- * @note Not supported, always not protected.
- *
- * @param[in] sdcp pointer to the @p SDCDriver object
- *
- * @notapi
- */
-bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
-
- (void)sdcp;
- return FALSE;
-}
-#endif /* HAL_USE_SDC */
--- a/demos/chibios/boards/redbull_v1/board.h
+++ /dev/null
@@ -1,136 +1,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef _BOARD_H_
-#define _BOARD_H_
-
-/*
- * Setup for the Olimex STM33-H103 proto board.
- */
-
-/*
- * Board identifier.
- */
-#define BOARD_REDBULL_V1
-#define BOARD_NAME "redbull_v1"
-
-/*
- * Board frequencies.
- */
-#define STM32_LSECLK 32768
-#define STM32_HSECLK 8000000
-
-/*
- * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
- */
-#define STM32F10X_HD
-
-/*
- * I/O ports initial setup, this configuration is established soon after reset
- * in the initialization code.
- *
- * The digits have the following meaning:
- * 0 - Analog input.
- * 1 - Push Pull output 10MHz.
- * 2 - Push Pull output 2MHz.
- * 3 - Push Pull output 50MHz.
- * 4 - Digital input.
- * 5 - Open Drain output 10MHz.
- * 6 - Open Drain output 2MHz.
- * 7 - Open Drain output 50MHz.
- * 8 - Digital input with PullUp or PullDown resistor depending on ODR.
- * 9 - Alternate Push Pull output 10MHz.
- * A - Alternate Push Pull output 2MHz.
- * B - Alternate Push Pull output 50MHz.
- * C - Reserved.
- * D - Alternate Open Drain output 10MHz.
- * E - Alternate Open Drain output 2MHz.
- * F - Alternate Open Drain output 50MHz.
- * Please refer to the STM32 Reference Manual for details.
- */
-
-/*
- * Port A setup.
- * Everything input with pull-up except:
- * PA0 - Normal input (BUTTON).
- * PA9 - Alternate output (USART1 TX).
- * PA10 - Normal input (USART1 RX).
- */
-#define VAL_GPIOACRL 0x88888888 /* PA7...PA0 */
-#define VAL_GPIOACRH 0x888884B8 /* PA15...PA8 */
-#define VAL_GPIOAODR 0xFFFFFFFF
-
-/*
- * Port B setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */
-#define VAL_GPIOBCRH 0x88888888 /* PB15...PB8 */
-#define VAL_GPIOBODR 0xFFFFFFFF
-
-/*
- * Port C setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOCCRL 0x44888888 /* PC7...PC0 */
-#define VAL_GPIOCCRH 0x888BBBBB /* PC15...PC8 */
-#define VAL_GPIOCODR 0xFFFFFFFF
-
-/*
- * Port D setup.
- * Everything input with pull-up except:
- * PD0 - Normal input (XTAL).
- * PD1 - Normal input (XTAL).
- */
-#define VAL_GPIODCRL 0x88888B44 /* PD7...PD0 */
-#define VAL_GPIODCRH 0x88888888 /* PD15...PD8 */
-#define VAL_GPIODODR 0xFFFFFFFF
-
-/*
- * Port E setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
-#define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */
-#define VAL_GPIOEODR 0xFFFFFFFF
-
-/*
- * Port F setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOFCRL 0x83888888 /* PE7...PE0 */
-#define VAL_GPIOFCRH 0x88888888 /* PE15...PE8 */
-#define VAL_GPIOFODR 0xFFFFFFFF
-
-/*
- * Port G setup.
- * Everything input with pull-up except:
- */
-#define VAL_GPIOGCRL 0x88888888 /* PE7...PE0 */
-#define VAL_GPIOGCRH 0x88888888 /* PE15...PE8 */
-#define VAL_GPIOGODR 0xFFFFFFFF
-
-#if !defined(_FROM_ASM_)
-#ifdef __cplusplus
-extern "C" {
-#endif
- void boardInit(void);
-#ifdef __cplusplus
-}
-#endif
-#endif /* _FROM_ASM_ */
-
-#endif /* _BOARD_H_ */
--- a/demos/chibios/boards/redbull_v1/board.mk
+++ /dev/null
@@ -1,5 +1,0 @@
-# List of all the board related files.
-BOARDSRC = ../../boards/redbull_v1/board.c
-
-# Required include directories
-BOARDINC = ../../boards/redbull_v1
--- a/demos/chibios/common/sdc_lwext4.c
+++ /dev/null
@@ -1,184 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <fcntl.h>
-
-#include <hal.h>
-#include <sdc.h>
-
-#include "sdc_lwext4.h"
-#include "timings.h"
-
-/**@brief Block size.*/
-#define SDC_BLOCK_SIZE 512
-
-/**@brief MBR_block ID*/
-#define MBR_BLOCK_ID 0
-#define MBR_PART_TABLE_OFF 446
-
-struct part_tab_entry {
- uint8_t status;
- uint8_t chs1[3];
- uint8_t type;
- uint8_t chs2[3];
- uint32_t first_lba;
- uint32_t sectors;
-} __attribute__((packed));
-
-/**@brief Partition block offset*/
-static uint32_t part_offset;
-
-/**@brief IO timings*/
-struct sdc_io_timings {
- uint64_t acc_bread;
- uint64_t acc_bwrite;
-
- uint32_t cnt_bread;
- uint32_t cnt_bwrite;
-
- uint32_t av_bread;
- uint32_t av_bwrite;
-};
-
-static struct sdc_io_timings io_timings;
-
-void io_timings_clear(void)
-{
- memset(&io_timings, 0, sizeof(struct sdc_io_timings));
-}
-
-const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
-{
- static struct ext4_io_stats s;
-
- s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);
- s.io_read /= 1000.0;
-
- s.io_write = (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);
- s.io_write /= 1000.0;
-
- s.cpu = 100.0 - s.io_read - s.io_write;
-
- return &s;
-}
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int sdc_open(struct ext4_blockdev *bdev);
-static int sdc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt);
-static int sdc_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt);
-static int sdc_close(struct ext4_blockdev *bdev);
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(_sdc, SDC_BLOCK_SIZE, 0, sdc_open, sdc_bread,
- sdc_bwrite, sdc_close);
-
-/******************************************************************************/
-EXT4_BCACHE_STATIC_INSTANCE(_sdc_cache, CONFIG_BLOCK_DEV_CACHE_SIZE,
- EXT_LOGICAL_BLOCK_SIZE);
-
-/******************************************************************************/
-
-static int sdc_open(struct ext4_blockdev *bdev)
-{
- (void)bdev;
-
- static uint8_t mbr[512];
- struct part_tab_entry *part0;
-
- sdcStart(&SDCD1, NULL);
-
- if (sdcConnect(&SDCD1) != HAL_SUCCESS)
- return EIO;
-
- if (sdcRead(&SDCD1, 0, mbr, 1) != HAL_SUCCESS)
- return EIO;
-
- part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);
-
- part_offset = part0->first_lba;
- _sdc.ph_bcnt = SDCD1.capacity * SDC_BLOCK_SIZE;
-
- return EOK;
-}
-
-static int sdc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
-{
- (void)bdev;
- bool status;
- uint64_t v = tim_get_us();
-
- status = sdcRead(&SDCD1, blk_id, buf, blk_cnt);
- if (status != HAL_SUCCESS)
- return EIO;
-
- io_timings.acc_bread += tim_get_us() - v;
- io_timings.cnt_bread++;
- io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;
-
- return EOK;
-}
-
-static int sdc_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt)
-{
- (void)bdev;
- bool status;
- uint64_t v = tim_get_us();
-
- status = sdcWrite(&SDCD1, blk_id, buf, blk_cnt);
- if (status != HAL_SUCCESS)
- return EIO;
-
- io_timings.acc_bwrite += tim_get_us() - v;
- io_timings.cnt_bwrite++;
- io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;
-
- return EOK;
-}
-
-static int sdc_close(struct ext4_blockdev *bdev)
-{
- (void)bdev;
- return EOK;
-}
-
-/******************************************************************************/
-
-struct ext4_bcache *sdc_cache_get(void) { return &_sdc_cache; }
-
-struct ext4_blockdev *sdc_bdev_get(void) { return &_sdc; }
--- a/demos/chibios/common/sdc_lwext4.h
+++ /dev/null
@@ -1,53 +1,0 @@
-/*
- * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef SDC_LWEXT4_H_
-#define SDC_LWEXT4_H_
-
-#include <config.h>
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief SDC cache get.*/
-struct ext4_bcache *sdc_cache_get(void);
-
-/**@brief SDC blockdev get.*/
-struct ext4_blockdev *sdc_bdev_get(void);
-
-struct ext4_io_stats {
- float io_read;
- float io_write;
- float cpu;
-};
-
-void io_timings_clear(void);
-const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms);
-
-#endif /* CHIBI_SDC_LWEXT4_H_ */
--- a/demos/chibios/common/spi_lwext4.c
+++ /dev/null
@@ -1,211 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <fcntl.h>
-
-#include <hal.h>
-#include <mmc_spi.h>
-
-#include "spi_lwext4.h"
-#include "timings.h"
-
-#if HAL_USE_MMC_SPI
-extern MMCDriver MMCD1;
-#endif
-
-/**@brief Block size.*/
-#define SPI_BLOCK_SIZE 512
-
-/**@brief MBR_block ID*/
-#define MBR_BLOCK_ID 0
-#define MBR_PART_TABLE_OFF 446
-
-struct part_tab_entry {
- uint8_t status;
- uint8_t chs1[3];
- uint8_t type;
- uint8_t chs2[3];
- uint32_t first_lba;
- uint32_t sectors;
-} __attribute__((packed));
-
-/**@brief Partition block offset*/
-static uint32_t part_offset;
-
-/**@brief IO timings*/
-struct spi_io_timings {
- uint64_t acc_bread;
- uint64_t acc_bwrite;
-
- uint32_t cnt_bread;
- uint32_t cnt_bwrite;
-
- uint32_t av_bread;
- uint32_t av_bwrite;
-};
-
-static struct spi_io_timings io_timings;
-
-void io_timings_clear(void)
-{
- memset(&io_timings, 0, sizeof(struct spi_io_timings));
-}
-
-const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
-{
- static struct ext4_io_stats s;
-
- s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);
- s.io_read /= 1000.0;
-
- s.io_write = (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);
- s.io_write /= 1000.0;
-
- s.cpu = 100.0 - s.io_read - s.io_write;
-
- return &s;
-}
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int spi_open(struct ext4_blockdev *bdev);
-static int spi_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt);
-static int spi_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt);
-static int spi_close(struct ext4_blockdev *bdev);
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(_spi, SPI_BLOCK_SIZE, 0, spi_open, spi_bread,
- spi_bwrite, spi_close);
-
-/******************************************************************************/
-EXT4_BCACHE_STATIC_INSTANCE(_spi_cache, CONFIG_BLOCK_DEV_CACHE_SIZE,
- EXT_LOGICAL_BLOCK_SIZE);
-
-/******************************************************************************/
-
-static int spi_open(struct ext4_blockdev *bdev)
-{
-
- (void)bdev;
-
- static uint8_t mbr[512];
- struct part_tab_entry *part0;
-
- if (mmcConnect(&MMCD1) != HAL_SUCCESS)
- return EIO;
-
- if (mmcStartSequentialRead(&MMCD1, 0) != HAL_SUCCESS)
- return EIO;
-
- if (mmcSequentialRead(&MMCD1, mbr) != HAL_SUCCESS)
- return EIO;
-
- if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS)
- return EIO;
-
- part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);
-
- part_offset = part0->first_lba;
- _spi.ph_bcnt = MMCD1.capacity * SPI_BLOCK_SIZE;
-
- return EOK;
-}
-
-static int spi_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
-{
- (void)bdev;
- uint64_t v = tim_get_us();
-
- if (mmcStartSequentialRead(&MMCD1, blk_id) != HAL_SUCCESS)
- return EIO;
-
- while (blk_cnt) {
- if (mmcSequentialRead(&MMCD1, buf) != HAL_SUCCESS)
- return EIO;
-
- buf += SPI_BLOCK_SIZE;
- blk_cnt--;
- }
-
- if (mmcStopSequentialRead(&MMCD1) != HAL_SUCCESS)
- return EIO;
-
- io_timings.acc_bread += tim_get_us() - v;
- io_timings.cnt_bread++;
- io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;
-
- return EOK;
-}
-
-static int spi_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt)
-{
- (void)bdev;
- uint64_t v = tim_get_us();
-
- if (mmcStartSequentialWrite(&MMCD1, blk_id) != HAL_SUCCESS)
- return EIO;
-
- while (blk_cnt) {
- if (mmcSequentialWrite(&MMCD1, buf) != HAL_SUCCESS)
- return EIO;
-
- buf += SPI_BLOCK_SIZE;
- blk_cnt--;
- }
-
- if (mmcStopSequentialWrite(&MMCD1) != HAL_SUCCESS)
- return EIO;
-
- io_timings.acc_bwrite += tim_get_us() - v;
- io_timings.cnt_bwrite++;
- io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;
-
- return EOK;
-}
-
-static int spi_close(struct ext4_blockdev *bdev)
-{
- (void)bdev;
- return EOK;
-}
-
-/******************************************************************************/
-
-struct ext4_bcache *spi_cache_get(void) { return &_spi_cache; }
-
-struct ext4_blockdev *spi_bdev_get(void) { return &_spi; }
--- a/demos/chibios/common/spi_lwext4.h
+++ /dev/null
@@ -1,33 +1,0 @@
-/*
- * spi_lwext4.h
- *
- * Created on: 21 gru 2014
- * Author: gko
- */
-
-#ifndef SPI_LWEXT4_H_
-#define SPI_LWEXT4_H_
-
-#include <config.h>
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief SPI cache get.*/
-struct ext4_bcache *spi_cache_get(void);
-
-/**@brief SPI blockdev get.*/
-struct ext4_blockdev *spi_bdev_get(void);
-
-struct ext4_io_stats {
- float io_read;
- float io_write;
- float cpu;
-};
-
-void io_timings_clear(void);
-const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms);
-
-#endif /* SPI_LWEXT4_H_ */
--- a/demos/chibios/common/test_lwext4.c
+++ /dev/null
@@ -1,377 +1,0 @@
-/*
- * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-#include <ext4.h>
-
-#include <stdio.h>
-#include <inttypes.h>
-#include <string.h>
-
-#include "sdc_lwext4.h"
-#include "timings.h"
-#include "test_lwext4.h"
-
-/**@brief Read-write size*/
-#define READ_MAX_WRITE_SZIZE 1024 * 8
-
-/**@brief File read/write buffer*/
-static uint8_t rw_buff[READ_MAX_WRITE_SZIZE];
-
-/**@brief Block device handle.*/
-static struct ext4_blockdev *bd;
-
-/**@brief Block cache handle.*/
-static struct ext4_bcache *bc;
-
-static char *entry_to_str(uint8_t type)
-{
- switch (type) {
- case EXT4_DIRENTRY_UNKNOWN:
- return "[unk] ";
- case EXT4_DIRENTRY_REG_FILE:
- return "[fil] ";
- case EXT4_DIRENTRY_DIR:
- return "[dir] ";
- case EXT4_DIRENTRY_CHRDEV:
- return "[cha] ";
- case EXT4_DIRENTRY_BLKDEV:
- return "[blk] ";
- case EXT4_DIRENTRY_FIFO:
- return "[fif] ";
- case EXT4_DIRENTRY_SOCK:
- return "[soc] ";
- case EXT4_DIRENTRY_SYMLINK:
- return "[sym] ";
- default:
- break;
- }
- return "[???]";
-}
-
-static clock_t get_ms(void) { return tim_get_ms(); }
-
-static void printf_io_timings(clock_t diff)
-{
- const struct ext4_io_stats *stats = io_timings_get(diff);
- printf("io_timings:\n");
- printf(" io_read: %.3f%%\n", stats->io_read);
- printf(" io_write: %.3f%%\n", stats->io_write);
- printf(" io_cpu: %.3f%%\n", stats->cpu);
-}
-
-void test_lwext4_dir_ls(const char *path)
-{
- char sss[255];
- ext4_dir d;
- const ext4_direntry *de;
-
- printf("ls %s\n", path);
-
- ext4_dir_open(&d, path);
- de = ext4_dir_entry_next(&d);
-
- while (de) {
- memcpy(sss, de->name, de->name_length);
- sss[de->name_length] = 0;
- printf(" %s%s\n", entry_to_str(de->inode_type), sss);
- de = ext4_dir_entry_next(&d);
- }
- ext4_dir_close(&d);
-}
-
-void test_lwext4_mp_stats(void)
-{
- struct ext4_mount_stats stats;
- ext4_mount_point_stats("/mp/", &stats);
-
- printf("********************\n");
- printf("ext4_mount_point_stats\n");
- printf("inodes_count = %" PRIu32 "\n", stats.inodes_count);
- printf("free_inodes_count = %" PRIu32 "\n", stats.free_inodes_count);
- printf("blocks_count = %" PRIu32 "\n", (uint32_t)stats.blocks_count);
- printf("free_blocks_count = %" PRIu32 "\n",
- (uint32_t)stats.free_blocks_count);
- printf("block_size = %" PRIu32 "\n", stats.block_size);
- printf("block_group_count = %" PRIu32 "\n", stats.block_group_count);
- printf("blocks_per_group= %" PRIu32 "\n", stats.blocks_per_group);
- printf("inodes_per_group = %" PRIu32 "\n", stats.inodes_per_group);
- printf("volume_name = %s\n", stats.volume_name);
- printf("********************\n");
-}
-
-void test_lwext4_block_stats(void)
-{
- if (!bd)
- return;
-
- printf("********************\n");
- printf("ext4 blockdev stats\n");
- printf("bdev->bread_ctr = %" PRIu32 "\n", bd->bread_ctr);
- printf("bdev->bwrite_ctr = %" PRIu32 "\n", bd->bwrite_ctr);
-
- printf("bcache->ref_blocks = %" PRIu32 "\n", bc->ref_blocks);
- printf("bcache->max_ref_blocks = %" PRIu32 "\n", bc->max_ref_blocks);
- printf("bcache->lru_ctr = %" PRIu32 "\n", bc->lru_ctr);
-
- printf("\n");
-
- uint32_t i;
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->refctr[%" PRIu32 "]= %" PRIu32 "\n", i,
- bc->refctr[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->lru_id[%" PRIu32 "] = %" PRIu32 "\n", i,
- bc->lru_id[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->free_delay[%" PRIu32 "] = %d\n", i,
- bc->free_delay[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->lba[%" PRIu32 "] = %" PRIu32 "\n", i,
- (uint32_t)bc->lba[i]);
- }
-
- printf("********************\n");
-}
-
-bool test_lwext4_dir_test(int len)
-{
- ext4_file f;
- int r;
- int i;
- char path[64];
- clock_t diff;
- clock_t stop;
- clock_t start;
-
- printf("test_lwext4_dir_test: %d\n", len);
- io_timings_clear();
- start = get_ms();
-
- printf("directory create: /mp/dir1\n");
- r = ext4_dir_mk("/mp/dir1");
- if (r != EOK) {
- printf("ext4_dir_mk: rc = %d\n", r);
- return false;
- }
-
- printf("add files to: /mp/dir1\n");
- for (i = 0; i < len; ++i) {
- sprintf(path, "/mp/dir1/f%d", i);
- r = ext4_fopen(&f, path, "wb");
- if (r != EOK) {
- printf("ext4_fopen: rc = %d\n", r);
- return false;
- }
- }
-
- stop = get_ms();
- diff = stop - start;
- test_lwext4_dir_ls("/mp/dir1");
- printf("test_lwext4_dir_test: time: %d ms\n", (int)diff);
- printf("test_lwext4_dir_test: av: %d ms/entry\n", (int)diff / len);
- printf_io_timings(diff);
- return true;
-}
-
-static int verify_buf(const unsigned char *b, size_t len, unsigned char c)
-{
- size_t i;
- for (i = 0; i < len; ++i) {
- if (b[i] != c)
- return c - b[i];
- }
-
- return 0;
-}
-
-bool test_lwext4_file_test(uint32_t rw_szie, uint32_t rw_count)
-{
- int r;
- size_t size;
- uint32_t i;
- clock_t start;
- clock_t stop;
- clock_t diff;
- uint32_t kbps;
- uint64_t size_bytes;
-
- ext4_file f;
-
- printf("file_test:\n");
- printf(" rw size: %" PRIu32 "\n", rw_szie);
- printf(" rw count: %" PRIu32 "\n", rw_count);
-
- /*Add hello world file.*/
- r = ext4_fopen(&f, "/mp/hello.txt", "wb");
- r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);
- r = ext4_fclose(&f);
-
- io_timings_clear();
- start = get_ms();
- r = ext4_fopen(&f, "/mp/test1", "wb");
- if (r != EOK) {
- printf("ext4_fopen ERROR = %d\n", r);
- return false;
- }
-
- printf("ext4_write: %" PRIu32 " * %" PRIu32 " ...\n", rw_szie,
- rw_count);
- for (i = 0; i < rw_count; ++i) {
-
- memset(rw_buff, i % 10 + '0', rw_szie);
-
- r = ext4_fwrite(&f, rw_buff, rw_szie, &size);
-
- if ((r != EOK) || (size != rw_szie))
- break;
- }
-
- if (i != rw_count) {
- printf(" file_test: rw_count = %" PRIu32 "\n", i);
- return false;
- }
-
- stop = get_ms();
- diff = stop - start;
- size_bytes = rw_szie * rw_count;
- size_bytes = (size_bytes * 1000) / 1024;
- kbps = (size_bytes) / (diff + 1);
- printf(" write time: %d ms\n", (int)diff);
- printf(" write speed: %" PRIu32 " KB/s\n", kbps);
- printf_io_timings(diff);
- r = ext4_fclose(&f);
-
- io_timings_clear();
- start = get_ms();
- r = ext4_fopen(&f, "/mp/test1", "r+");
- if (r != EOK) {
- printf("ext4_fopen ERROR = %d\n", r);
- return false;
- }
-
- printf("ext4_read: %" PRIu32 " * %" PRIu32 " ...\n", rw_szie, rw_count);
-
- for (i = 0; i < rw_count; ++i) {
- r = ext4_fread(&f, rw_buff, rw_szie, &size);
-
- if ((r != EOK) || (size != rw_szie))
- break;
-
- if (verify_buf(rw_buff, rw_szie, i % 10 + '0'))
- break;
- }
-
- if (i != rw_count) {
- printf(" file_test: rw_count = %" PRIu32 "\n", i);
- return false;
- }
-
- stop = get_ms();
- diff = stop - start;
- size_bytes = rw_szie * rw_count;
- size_bytes = (size_bytes * 1000) / 1024;
- kbps = (size_bytes) / (diff + 1);
- printf(" read time: %d ms\n", (int)diff);
- printf(" read speed: %d KB/s\n", (int)kbps);
- printf_io_timings(diff);
-
- r = ext4_fclose(&f);
- return true;
-}
-void test_lwext4_cleanup(void)
-{
- clock_t start;
- clock_t stop;
- clock_t diff;
-
- printf("\ncleanup:\n");
- ext4_fremove("/mp/hello.txt");
-
- printf("remove /mp/test1\n");
- ext4_fremove("/mp/test1");
-
- printf("remove /mp/dir1\n");
- io_timings_clear();
- start = get_ms();
- ext4_dir_rm("/mp/dir1");
- stop = get_ms();
- diff = stop - start;
- printf("cleanup: time: %d ms\n", (int)diff);
- printf_io_timings(diff);
-}
-
-bool test_lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache)
-{
- int r;
-
- bc = bcache;
- bd = bdev;
-
- if (!bd) {
- printf("test_lwext4_mount: no block device\n");
- return false;
- }
-
- ext4_dmask_set(EXT4_DEBUG_ALL);
-
- r = ext4_device_register(bd, bc ? bc : 0, "ext4_fs");
- if (r != EOK) {
- printf("ext4_device_register: rc = %d\n", r);
- return false;
- }
-
- r = ext4_mount("ext4_fs", "/mp/");
- if (r != EOK) {
- printf("ext4_mount: rc = %d\n", r);
- return false;
- }
-
- ext4_cache_write_back("/mp/", 1);
- return true;
-}
-
-bool test_lwext4_umount(void)
-{
- ext4_cache_write_back("/mp/", 0);
- int r = ext4_umount("/mp/");
- if (r != EOK) {
- printf("ext4_umount: fail %d", r);
- return false;
- }
- return true;
-}
--- a/demos/chibios/common/test_lwext4.h
+++ /dev/null
@@ -1,46 +1,0 @@
-/*
- * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef TEST_LWEXT4_H_
-#define TEST_LWEXT4_H_
-
-#include <config.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-void test_lwext4_dir_ls(const char *path);
-void test_lwext4_mp_stats(void);
-void test_lwext4_block_stats(void);
-bool test_lwext4_dir_test(int len);
-bool test_lwext4_file_test(uint32_t rw_szie, uint32_t rw_count);
-void test_lwext4_cleanup(void);
-
-bool test_lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache);
-bool test_lwext4_umount(void);
-
-#endif /* TEST_LWEXT4_H_ */
--- a/demos/chibios/common/timings.c
+++ /dev/null
@@ -1,48 +1,0 @@
-/*
- * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-
-#include <ch.h>
-#include <chvt.h>
-
-#include "timings.h"
-
-void tim_wait_ms(uint32_t v) { chThdSleepMilliseconds(v); }
-
-uint64_t tim_get_us(void)
-{
- uint64_t v = chVTGetSystemTimeX();
- return ST2US(v);
-}
-
-uint32_t tim_get_ms(void)
-{
- uint32_t v = chVTGetSystemTimeX();
- return ST2MS(v);
-}
--- a/demos/chibios/common/timings.h
+++ /dev/null
@@ -1,39 +1,0 @@
-/*
- * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef TIMINGS_H_
-#define TIMINGS_H_
-
-#include <config.h>
-#include <stdint.h>
-
-void tim_wait_ms(uint32_t v);
-
-uint32_t tim_get_ms(void);
-uint64_t tim_get_us(void);
-
-#endif /* TIMINGS_H_ */
--- a/demos/generic/CMakeLists.txt
+++ b/demos/generic/CMakeLists.txt
@@ -1,4 +1,4 @@
-#Generic demo
-add_executable(generic main.c)
-target_link_libraries(generic lwext4)
-target_link_libraries(generic blockdev)
\ No newline at end of file
+#Generic demo
+add_executable(generic generic.c)
+target_link_libraries(generic blockdev)
+target_link_libraries(generic lwext4)
--- /dev/null
+++ b/demos/generic/generic.c
@@ -1,0 +1,268 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <ext4.h>
+#include "../../blockdev/linux/ext4_filedev.h"
+#include "../../blockdev/windows/io_raw.h"
+#include "../../blockdev/test_lwext4.h"
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+/**@brief Input stream name.*/
+char input_name[128] = "ext2";
+
+/**@brief Read-write size*/
+static int rw_szie = 1024 * 1024;
+
+/**@brief Read-write size*/
+static int rw_count = 10;
+
+/**@brief Directory test count*/
+static int dir_cnt = 0;
+
+/**@brief Static or dynamic cache mode*/
+static bool cache_mode = true;
+
+/**@brief Cleanup after test.*/
+static bool cleanup_flag = false;
+
+/**@brief Block device stats.*/
+static bool bstat = false;
+
+/**@brief Superblock stats.*/
+static bool sbstat = false;
+
+/**@brief Indicates that input is windows partition.*/
+static bool winpart = false;
+
+/**@brief File write buffer*/
+static uint8_t *wr_buff;
+
+/**@brief File read buffer.*/
+static uint8_t *rd_buff;
+
+/**@brief Block device handle.*/
+static struct ext4_blockdev *bd;
+
+/**@brief Static cache instance*/
+EXT4_BCACHE_STATIC_INSTANCE(_lwext4_cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
+
+/**@brief Block cache handle.*/
+static struct ext4_bcache *bc = &_lwext4_cache;
+
+static const char *usage = " \n\
+Welcome in ext4 generic demo. \n\
+Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com) \n\
+Usage: \n\
+ --i - input file (default = ext2) \n\
+ --rws - single R/W size (default = 1024 * 1024) \n\
+ --rwc - R/W count (default = 10) \n\
+ --cache - 0 static, 1 dynamic (default = 1) \n\
+ --dirs - directory test count (default = 0) \n\
+ --clean - clean up after test \n\
+ --bstat - block device stats \n\
+ --sbstat - superblock stats \n\
+ --wpart - windows partition mode \n\
+\n";
+
+void io_timings_clear(void)
+{
+}
+
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
+{
+ return NULL;
+}
+
+uint32_t tim_get_ms(void)
+{
+ struct timeval t;
+ gettimeofday(&t, NULL);
+ return (t.tv_sec * 1000) + (t.tv_usec / 1000);
+}
+
+uint64_t tim_get_us(void)
+{
+ struct timeval t;
+ gettimeofday(&t, NULL);
+ return (t.tv_sec * 1000000) + (t.tv_usec);
+}
+
+static bool open_linux(void)
+{
+ ext4_filedev_filename(input_name);
+ bd = ext4_filedev_get();
+ if (!bd) {
+ printf("open_filedev: fail\n");
+ return false;
+ }
+ return true;
+}
+
+static bool open_windows(void)
+{
+#ifdef WIN32
+ ext4_io_raw_filename(input_name);
+ bd = ext4_io_raw_dev_get();
+ if (!bd) {
+ printf("open_winpartition: fail\n");
+ return false;
+ }
+ return true;
+#else
+ printf("open_winpartition: this mode should be used only under windows "
+ "!\n");
+ return false;
+#endif
+}
+
+
+static bool parse_opt(int argc, char **argv)
+{
+ int option_index = 0;
+ int c;
+
+ static struct option long_options[] = {
+ {"in", required_argument, 0, 'a'},
+ {"rws", required_argument, 0, 'b'},
+ {"rwc", required_argument, 0, 'c'},
+ {"cache", required_argument, 0, 'd'},
+ {"dirs", required_argument, 0, 'e'},
+ {"clean", no_argument, 0, 'f'},
+ {"bstat", no_argument, 0, 'g'},
+ {"sbstat", no_argument, 0, 'h'},
+ {"wpart", no_argument, 0, 'i'},
+ {0, 0, 0, 0}};
+
+ while (-1 != (c = getopt_long(argc, argv, "a:b:c:d:e:fghi",
+ long_options, &option_index))) {
+
+ switch (c) {
+ case 'a':
+ strcpy(input_name, optarg);
+ break;
+ case 'b':
+ rw_szie = atoi(optarg);
+ break;
+ case 'c':
+ rw_count = atoi(optarg);
+ break;
+ case 'd':
+ cache_mode = atoi(optarg);
+ break;
+ case 'e':
+ dir_cnt = atoi(optarg);
+ break;
+ case 'f':
+ cleanup_flag = true;
+ break;
+ case 'g':
+ bstat = true;
+ break;
+ case 'h':
+ sbstat = true;
+ break;
+ case 'i':
+ winpart = true;
+ break;
+ default:
+ printf("%s", usage);
+ return false;
+ }
+ }
+ return true;
+}
+
+int main(int argc, char **argv)
+{
+ if (!parse_opt(argc, argv))
+ return EXIT_FAILURE;
+
+ printf("test conditions:\n");
+ printf("\timput name: %s\n", input_name);
+ printf("\trw size: %d\n", rw_szie);
+ printf("\trw count: %d\n", rw_count);
+ printf("\tcache mode: %s\n", cache_mode ? "dynamic" : "static");
+
+ if (winpart) {
+ if (!open_windows())
+ return EXIT_FAILURE;
+ } else {
+ if (!open_linux())
+ return EXIT_FAILURE;
+ }
+
+
+ if (!test_lwext4_mount(bd, bc))
+ return EXIT_FAILURE;
+
+ test_lwext4_cleanup();
+
+ if (sbstat)
+ test_lwext4_mp_stats();
+
+ test_lwext4_dir_ls("/mp/");
+ fflush(stdout);
+ if (!test_lwext4_dir_test(dir_cnt))
+ return EXIT_FAILURE;
+
+ fflush(stdout);
+ if (!test_lwext4_file_test(rw_count, rw_szie))
+ return EXIT_FAILURE;
+
+ fflush(stdout);
+ test_lwext4_dir_ls("/mp/");
+
+ if (sbstat)
+ test_lwext4_mp_stats();
+
+ if (cleanup_flag)
+ test_lwext4_cleanup();
+
+ if (bstat)
+ test_lwext4_block_stats();
+
+ if (!test_lwext4_umount())
+ return EXIT_FAILURE;
+
+ printf("\ntest finished\n");
+ return EXIT_SUCCESS;
+}
--- a/demos/generic/main.c
+++ /dev/null
@@ -1,535 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <stdbool.h>
-#include <inttypes.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include <ext4_filedev.h>
-#include <io_raw.h>
-#include <ext4.h>
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-/**@brief Input stream name.*/
-char input_name[128] = "ext2";
-
-/**@brief Read-write size*/
-static int rw_szie = 1024 * 1024;
-
-/**@brief Read-write size*/
-static int rw_count = 10;
-
-/**@brief Directory test count*/
-static int dir_cnt = 0;
-
-/**@brief Static or dynamic cache mode*/
-static bool cache_mode = true;
-
-/**@brief Cleanup after test.*/
-static bool cleanup_flag = false;
-
-/**@brief Block device stats.*/
-static bool bstat = false;
-
-/**@brief Superblock stats.*/
-static bool sbstat = false;
-
-/**@brief Indicates that input is windows partition.*/
-static bool winpart = false;
-
-/**@brief File write buffer*/
-static uint8_t *wr_buff;
-
-/**@brief File read buffer.*/
-static uint8_t *rd_buff;
-
-/**@brief Block device handle.*/
-static struct ext4_blockdev *bd;
-
-/**@brief Static cache instance*/
-EXT4_BCACHE_STATIC_INSTANCE(_lwext4_cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
-
-/**@brief Block cache handle.*/
-static struct ext4_bcache *bc = &_lwext4_cache;
-
-static const char *usage = " \n\
-Welcome in ext4 generic demo. \n\
-Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com) \n\
-Usage: \n\
- --i - input file (default = ext2) \n\
- --rws - single R/W size (default = 1024 * 1024) \n\
- --rwc - R/W count (default = 10) \n\
- --cache - 0 static, 1 dynamic (default = 1) \n\
- --dirs - directory test count (default = 0) \n\
- --clean - clean up after test \n\
- --bstat - block device stats \n\
- --sbstat - superblock stats \n\
- --wpart - windows partition mode \n\
-\n";
-
-static char *entry_to_str(uint8_t type)
-{
- switch (type) {
- case EXT4_DIRENTRY_UNKNOWN:
- return "[UNK] ";
- case EXT4_DIRENTRY_REG_FILE:
- return "[FIL] ";
- case EXT4_DIRENTRY_DIR:
- return "[DIR] ";
- case EXT4_DIRENTRY_CHRDEV:
- return "[CHA] ";
- case EXT4_DIRENTRY_BLKDEV:
- return "[BLK] ";
- case EXT4_DIRENTRY_FIFO:
- return "[FIF] ";
- case EXT4_DIRENTRY_SOCK:
- return "[SOC] ";
- case EXT4_DIRENTRY_SYMLINK:
- return "[SYM] ";
- default:
- break;
- }
- return "[???]";
-}
-
-static void dir_ls(const char *path)
-{
- char sss[255];
- ext4_dir d;
- const ext4_direntry *de;
-
- printf("ls %s:\n", path);
-
- ext4_dir_open(&d, path);
- de = ext4_dir_entry_next(&d);
-
- while (de) {
- memcpy(sss, de->name, de->name_length);
- sss[de->name_length] = 0;
- printf("\t%s", entry_to_str(de->inode_type));
- printf("%s", sss);
- printf("\n");
- de = ext4_dir_entry_next(&d);
- }
- ext4_dir_close(&d);
-}
-
-static void mp_stats(void)
-{
- struct ext4_mount_stats stats;
- ext4_mount_point_stats("/mp/", &stats);
-
- printf("ext4_mount_point_stats:\n");
- printf("\tinodes_count = %" PRIu32 "\n", stats.inodes_count);
- printf("\tfree_inodes_count = %" PRIu32 "\n",
- stats.free_inodes_count);
- printf("\tblocks_count = %" PRIu32 "\n",
- (uint32_t)stats.blocks_count);
- printf("\tfree_blocks_count = %" PRIu32 "\n",
- (uint32_t)stats.free_blocks_count);
- printf("\tblock_size = %" PRIu32 "\n", stats.block_size);
- printf("\tblock_group_count = %" PRIu32 "\n",
- stats.block_group_count);
- printf("\tblocks_per_group = %" PRIu32 "\n", stats.blocks_per_group);
- printf("\tinodes_per_group = %" PRIu32 "\n", stats.inodes_per_group);
- printf("\tvolume_name = %s\n", stats.volume_name);
-}
-
-static void block_stats(void)
-{
- uint32_t i;
-
- printf("ext4 blockdev stats\n");
- printf("\tbdev->bread_ctr = %" PRIu32 "\n", bd->bread_ctr);
- printf("\tbdev->bwrite_ctr = %" PRIu32 "\n", bd->bwrite_ctr);
-
- printf("\tbcache->ref_blocks = %" PRIu32 "\n", bc->ref_blocks);
- printf("\tbcache->max_ref_blocks = %" PRIu32 "\n",
- bc->max_ref_blocks);
- printf("\tbcache->lru_ctr = %" PRIu32 "\n", bc->lru_ctr);
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("\tbcache->refctr[%" PRIu32 "] = %" PRIu32 "\n", i,
- bc->refctr[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("\tbcache->lru_id[%" PRIu32 "] = %" PRIu32 "\n", i,
- bc->lru_id[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("\tbcache->free_delay[%" PRIu32 "] = %d\n", i,
- bc->free_delay[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("\tbcache->lba[%" PRIu32 "] = %" PRIu32 "\n", i,
- (uint32_t)bc->lba[i]);
- }
-}
-
-static clock_t get_ms(void)
-{
- struct timeval t;
- gettimeofday(&t, NULL);
- return (t.tv_sec * 1000) + (t.tv_usec / 1000);
-}
-
-static bool dir_test(int len)
-{
- ext4_file f;
- int r;
- int i;
- char path[64];
- clock_t diff;
- clock_t stop;
- clock_t start;
-
- printf("\ndir_test: %d\n", len);
- printf("directory create: /mp/dir1\n");
- start = get_ms();
- r = ext4_dir_mk("/mp/dir1");
- if (r != EOK) {
- printf("\text4_dir_mk: rc = %d\n", r);
- return false;
- }
-
- ext4_cache_write_back("/mp/", 1);
- printf("add files to: /mp/dir1\n");
- for (i = 0; i < len; ++i) {
- sprintf(path, "/mp/dir1/f%d", i);
- r = ext4_fopen(&f, path, "wb");
- if (r != EOK) {
- printf("\text4_fopen: rc = %d\n", r);
- return false;
- }
- }
- ext4_cache_write_back("/mp/", 0);
-
- stop = get_ms();
- diff = stop - start;
- dir_ls("/mp/dir1");
- printf("dir_test: time: %d ms\n", (int)diff);
- return true;
-}
-
-static bool file_test(void)
-{
- int r;
- size_t size;
- ext4_file f;
- int i;
- clock_t start;
- clock_t stop;
- clock_t diff;
- uint32_t kbps;
- uint64_t size_bytes;
-
- printf("\nfile_test:\n");
- /*Add hello world file.*/
- r = ext4_fopen(&f, "/mp/hello.txt", "wb");
- r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);
- r = ext4_fclose(&f);
-
- printf("ext4_fopen: write test\n");
- start = get_ms();
- r = ext4_fopen(&f, "/mp/test1", "wb");
- if (r != EOK) {
- printf("\text4_fopen rc = %d\n", r);
- return false;
- }
-
- printf("ext4_write: %d * %d ...\n", rw_szie, rw_count);
- for (i = 0; i < rw_count; ++i) {
-
- memset(wr_buff, i % 10 + '0', rw_szie);
-
- r = ext4_fwrite(&f, wr_buff, rw_szie, &size);
-
- if ((r != EOK) || (size != rw_szie))
- break;
- }
-
- if (i != rw_count) {
- printf("\tfile_test: rw_count = %d\n", i);
- return false;
- }
-
- stop = get_ms();
- diff = stop - start;
- size_bytes = rw_szie * rw_count;
- size_bytes = (size_bytes * 1000) / 1024;
- kbps = (size_bytes) / (diff + 1);
- printf("\twrite time: %d ms\n", (int)diff);
- printf("\twrite speed: %" PRIu32 " KB/s\n", kbps);
- r = ext4_fclose(&f);
-
- printf("ext4_fopen: read test\n");
- start = get_ms();
- r = ext4_fopen(&f, "/mp/test1", "r+");
- if (r != EOK) {
- printf("\text4_fopen rc = %d\n", r);
- return false;
- }
-
- printf("ext4_read: %d * %d ...\n", rw_szie, rw_count);
- for (i = 0; i < rw_count; ++i) {
- memset(wr_buff, i % 10 + '0', rw_szie);
- r = ext4_fread(&f, rd_buff, rw_szie, &size);
-
- if ((r != EOK) || (size != rw_szie))
- break;
-
- if (memcmp(rd_buff, wr_buff, rw_szie)) {
- break;
- }
- }
- if (i != rw_count) {
- printf("\tfile_test: rw_count = %d\n", i);
- return false;
- }
- stop = get_ms();
- diff = stop - start;
- size_bytes = rw_szie * rw_count;
- size_bytes = (size_bytes * 1000) / 1024;
- kbps = (size_bytes) / (diff + 1);
- printf("\tread time: %d ms\n", (int)diff);
- printf("\tread speed: %" PRIu32 " KB/s\n", kbps);
- r = ext4_fclose(&f);
-
- return true;
-}
-static void cleanup(void)
-{
- clock_t start;
- clock_t stop;
- clock_t diff;
-
- printf("\ncleanup:\n");
- ext4_fremove("/mp/hello.txt");
- printf("cleanup: remove /mp/test1\n");
- ext4_fremove("/mp/test1");
-
- printf("cleanup: remove /mp/dir1\n");
- start = get_ms();
- ext4_dir_rm("/mp/dir1");
- stop = get_ms();
- diff = stop - start;
- printf("cleanup: time: %d ms\n", (int)diff);
-}
-
-static bool open_filedev(void)
-{
- ext4_filedev_filename(input_name);
- bd = ext4_filedev_get();
- if (!bd) {
- printf("open_filedev: fail\n");
- return false;
- }
- return true;
-}
-
-static bool open_winpartition(void)
-{
-#ifdef WIN32
- ext4_io_raw_filename(input_name);
- bd = ext4_io_raw_dev_get();
- if (!bd) {
- printf("open_winpartition: fail\n");
- return false;
- }
- return true;
-#else
- printf("open_winpartition: this mode should be used only under windows "
- "!\n");
- return false;
-#endif
-}
-
-static bool mount(void)
-{
- int r;
- if (winpart) {
- if (!open_winpartition())
- return false;
- } else {
- if (!open_filedev())
- return false;
- }
- wr_buff = malloc(rw_szie);
- rd_buff = malloc(rw_szie);
-
- if (!wr_buff || !rd_buff) {
- printf("mount: allocation failed\n");
- return false;
- }
-
- ext4_dmask_set(EXT4_DEBUG_ALL);
-
- r = ext4_device_register(bd, cache_mode ? 0 : bc, "ext4_fs");
- if (r != EOK) {
- printf("ext4_device_register: rc = %d\n", r);
- return false;
- }
-
- r = ext4_mount("ext4_fs", "/mp/");
- if (r != EOK) {
- printf("ext4_mount: rc = %d\n", r);
- return false;
- }
-
- return true;
-}
-
-static bool umount(void)
-{
- int r = ext4_umount("/mp/");
- if (r != EOK) {
- printf("ext4_umount: rc = %d", r);
- return false;
- }
- return true;
-}
-
-static bool parse_opt(int argc, char **argv)
-{
- int option_index = 0;
- int c;
-
- static struct option long_options[] = {
- {"in", required_argument, 0, 'a'},
- {"rws", required_argument, 0, 'b'},
- {"rwc", required_argument, 0, 'c'},
- {"cache", required_argument, 0, 'd'},
- {"dirs", required_argument, 0, 'e'},
- {"clean", no_argument, 0, 'f'},
- {"bstat", no_argument, 0, 'g'},
- {"sbstat", no_argument, 0, 'h'},
- {"wpart", no_argument, 0, 'i'},
- {0, 0, 0, 0}};
-
- while (-1 != (c = getopt_long(argc, argv, "a:b:c:d:e:fghi",
- long_options, &option_index))) {
-
- switch (c) {
- case 'a':
- strcpy(input_name, optarg);
- break;
- case 'b':
- rw_szie = atoi(optarg);
- break;
- case 'c':
- rw_count = atoi(optarg);
- break;
- case 'd':
- cache_mode = atoi(optarg);
- break;
- case 'e':
- dir_cnt = atoi(optarg);
- break;
- case 'f':
- cleanup_flag = true;
- break;
- case 'g':
- bstat = true;
- break;
- case 'h':
- sbstat = true;
- break;
- case 'i':
- winpart = true;
- break;
- default:
- printf("%s", usage);
- return false;
- }
- }
- return true;
-}
-
-int main(int argc, char **argv)
-{
- if (!parse_opt(argc, argv))
- return EXIT_FAILURE;
-
- printf("test conditions:\n");
- printf("\timput name: %s\n", input_name);
- printf("\trw size: %d\n", rw_szie);
- printf("\trw count: %d\n", rw_count);
- printf("\tcache mode: %s\n", cache_mode ? "dynamic" : "static");
-
- if (!mount())
- return EXIT_FAILURE;
-
- cleanup();
-
- if (sbstat)
- mp_stats();
-
- dir_ls("/mp/");
- fflush(stdout);
- if (!dir_test(dir_cnt))
- return EXIT_FAILURE;
-
- fflush(stdout);
- if (!file_test())
- return EXIT_FAILURE;
-
- fflush(stdout);
- dir_ls("/mp/");
-
- if (sbstat)
- mp_stats();
-
- if (cleanup_flag)
- cleanup();
-
- if (bstat)
- block_stats();
-
- if (!umount())
- return EXIT_FAILURE;
-
- printf("\ntest finished\n");
- return EXIT_SUCCESS;
-}
--- a/demos/stm32f429_disco/CMakeLists.txt
+++ b/demos/stm32f429_disco/CMakeLists.txt
@@ -33,6 +33,7 @@
set_target_properties(stm32f429_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")
set_target_properties(stm32f429_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")
+target_link_libraries(stm32f429_demo blockdev)
target_link_libraries(stm32f429_demo lwext4)
add_custom_target(stm32f429_size ALL DEPENDS stm32f429_demo COMMAND ${SIZE} -B stm32f429_demo)
--- a/demos/stm32f429_disco/config.h
+++ b/demos/stm32f429_disco/config.h
@@ -1,42 +1,38 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-
-/**@brief Main clock frequency.*/
-#define CFG_CCLK_FREQ 168000000ul
-
-/**@brief EXT partition block size (only when static cache on)*/
-#define EXT_LOGICAL_BLOCK_SIZE (1024 * 4)
-
-
-#endif /* CONFIG_H_ */
-
-
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+/**@brief Main clock frequency.*/
+#define CFG_CCLK_FREQ 168000000ul
+
+/**@brief EXT partition block size (only when static cache on)*/
+#define EXT_LOGICAL_BLOCK_SIZE (1024 * 4)
+
+#endif /* CONFIG_H_ */
--- a/demos/stm32f429_disco/hw_init.c
+++ b/demos/stm32f429_disco/hw_init.c
@@ -1,191 +1,171 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-#include <stm32f4xx.h>
-#include <stm32f429i_discovery_lcd.h>
-#include <lcd_log.h>
-#include <stdint.h>
-
-#include <usbh_core.h>
-#include <usbh_msc.h>
-
-
-
-#include <hw_init.h>
-#include <stdbool.h>
-
-USBH_HandleTypeDef hUSB_Host;
-
-
-static bool msc_connected = false;
-static bool enum_done = false;
-
-static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
-{
- switch(id)
- {
- case HOST_USER_SELECT_CONFIGURATION:
- break;
-
- case HOST_USER_DISCONNECTION:
- msc_connected = false;
- enum_done = false;
- break;
-
- case HOST_USER_CLASS_ACTIVE:
- enum_done = true;
- break;
-
- case HOST_USER_CONNECTION:
- msc_connected = true;
- break;
- default:
- break;
- }
-}
-
-#define LCD_FRAME_BUFFER_LAYER0 (LCD_FRAME_BUFFER+0x130000)
-#define LCD_FRAME_BUFFER_LAYER1 LCD_FRAME_BUFFER
-#define CONVERTED_FRAME_BUFFER (LCD_FRAME_BUFFER+0x260000)
-
-static void SystemClock_Config(void)
-{
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- RCC_OscInitTypeDef RCC_OscInitStruct;
-
- /* Enable Power Control clock */
- __PWR_CLK_ENABLE();
-
- /* The voltage scaling allows optimizing the power consumption when the device is
- clocked below the maximum system frequency, to update the voltage scaling value
- regarding system frequency refer to product datasheet. */
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
-
- /* Enable HSE Oscillator and activate PLL with HSE as source */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLM = 8;
- RCC_OscInitStruct.PLL.PLLN = 336;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
- RCC_OscInitStruct.PLL.PLLQ = 7;
- HAL_RCC_OscConfig (&RCC_OscInitStruct);
-
- /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
- clocks dividers */
- RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
- HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
-}
-
-
-void hw_init(void)
-{
- SystemInit();
- HAL_Init();
- SystemClock_Config();
-
- /* Initialize the LEDs */
- BSP_LED_Init(LED3);
- BSP_LED_Init(LED4);
-
- SysTick_Config(CFG_CCLK_FREQ / 1000);
-
- USBH_Init(&hUSB_Host, USBH_UserProcess, 0);
- USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);
- USBH_Start(&hUSB_Host);
-
- BSP_LCD_Init();
-
- /* Layer2 Init */
- BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER_LAYER1);
- BSP_LCD_SelectLayer(1);
- BSP_LCD_Clear(LCD_COLOR_WHITE);
- BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE);
- BSP_LCD_SetLayerVisible(1, DISABLE);
-
- /* Layer1 Init */
- BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0);
- BSP_LCD_SelectLayer(0);
- BSP_LCD_DisplayOn();
- BSP_LCD_Clear(LCD_COLOR_BLACK);
-
-
- LCD_LOG_Init();
- LCD_LOG_SetHeader((uint8_t *)"STM32 LWEXT4 DEMO ");
-}
-
-void hw_usb_process(void)
-{
- USBH_Process(&hUSB_Host);
-}
-
-bool hw_usb_connected(void)
-{
- return msc_connected;
-}
-
-bool hw_usb_enum_done(void)
-{
- return enum_done;
-}
-
-void hw_led_red(bool on)
-{
- on ? BSP_LED_On(LED4) : BSP_LED_Off(LED4);
-}
-
-void hw_led_green(bool on)
-{
- on ? BSP_LED_On(LED3) : BSP_LED_Off(LED3);
-}
-
-uint32_t tim_get_ms(void)
-{
- return HAL_GetTick();
-}
-
-uint64_t tim_get_us(void)
-{
- return (uint64_t)HAL_GetTick() * 1000 +
- ((SysTick->LOAD - SysTick->VAL) * 1000) / SysTick->LOAD;
-}
-
-void tim_wait_ms(uint32_t ms)
-{
- volatile uint32_t t = HAL_GetTick();
-
- while((t + ms) > HAL_GetTick())
- ;
-}
-
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+#include <stm32f4xx.h>
+#include <stm32f429i_discovery_lcd.h>
+#include <lcd_log.h>
+#include <stdint.h>
+
+#include <usbh_core.h>
+#include <usbh_msc.h>
+
+#include <hw_init.h>
+#include <stdbool.h>
+
+USBH_HandleTypeDef hUSB_Host;
+
+static bool msc_connected = false;
+static bool enum_done = false;
+
+static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
+{
+ switch (id) {
+ case HOST_USER_SELECT_CONFIGURATION:
+ break;
+
+ case HOST_USER_DISCONNECTION:
+ msc_connected = false;
+ enum_done = false;
+ break;
+
+ case HOST_USER_CLASS_ACTIVE:
+ enum_done = true;
+ break;
+
+ case HOST_USER_CONNECTION:
+ msc_connected = true;
+ break;
+ default:
+ break;
+ }
+}
+
+#define LCD_FRAME_BUFFER_LAYER0 (LCD_FRAME_BUFFER + 0x130000)
+#define LCD_FRAME_BUFFER_LAYER1 LCD_FRAME_BUFFER
+#define CONVERTED_FRAME_BUFFER (LCD_FRAME_BUFFER + 0x260000)
+
+static void SystemClock_Config(void)
+{
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+
+ /* Enable Power Control clock */
+ __PWR_CLK_ENABLE();
+
+ /* The voltage scaling allows optimizing the power consumption when the
+ device is
+ clocked below the maximum system frequency, to update the voltage
+ scaling value
+ regarding system frequency refer to product datasheet. */
+ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+ /* Enable HSE Oscillator and activate PLL with HSE as source */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+ RCC_OscInitStruct.PLL.PLLM = 8;
+ RCC_OscInitStruct.PLL.PLLN = 336;
+ RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
+ RCC_OscInitStruct.PLL.PLLQ = 7;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ /* Select PLL as system clock source and configure the HCLK, PCLK1 and
+ PCLK2
+ clocks dividers */
+ RCC_ClkInitStruct.ClockType =
+ (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 |
+ RCC_CLOCKTYPE_PCLK2);
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
+}
+
+void hw_init(void)
+{
+ SystemInit();
+ HAL_Init();
+ SystemClock_Config();
+
+ /* Initialize the LEDs */
+ BSP_LED_Init(LED3);
+ BSP_LED_Init(LED4);
+
+ SysTick_Config(CFG_CCLK_FREQ / 1000);
+
+ USBH_Init(&hUSB_Host, USBH_UserProcess, 0);
+ USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS);
+ USBH_Start(&hUSB_Host);
+
+ BSP_LCD_Init();
+
+ /* Layer2 Init */
+ BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER_LAYER1);
+ BSP_LCD_SelectLayer(1);
+ BSP_LCD_Clear(LCD_COLOR_WHITE);
+ BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE);
+ BSP_LCD_SetLayerVisible(1, DISABLE);
+
+ /* Layer1 Init */
+ BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0);
+ BSP_LCD_SelectLayer(0);
+ BSP_LCD_DisplayOn();
+ BSP_LCD_Clear(LCD_COLOR_BLACK);
+
+ LCD_LOG_Init();
+ LCD_LOG_SetHeader((uint8_t *)"STM32 LWEXT4 DEMO ");
+}
+
+void hw_usb_process(void) { USBH_Process(&hUSB_Host); }
+
+bool hw_usb_connected(void) { return msc_connected; }
+
+bool hw_usb_enum_done(void) { return enum_done; }
+
+void hw_led_red(bool on) { on ? BSP_LED_On(LED4) : BSP_LED_Off(LED4); }
+
+void hw_led_green(bool on) { on ? BSP_LED_On(LED3) : BSP_LED_Off(LED3); }
+
+uint32_t tim_get_ms(void) { return HAL_GetTick(); }
+
+uint64_t tim_get_us(void)
+{
+ return (uint64_t)HAL_GetTick() * 1000 +
+ ((SysTick->LOAD - SysTick->VAL) * 1000) / SysTick->LOAD;
+}
+
+void tim_wait_ms(uint32_t ms)
+{
+ volatile uint32_t t = HAL_GetTick();
+
+ while ((t + ms) > HAL_GetTick())
+ ;
+}
--- a/demos/stm32f429_disco/hw_init.h
+++ b/demos/stm32f429_disco/hw_init.h
@@ -1,49 +1,48 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#ifndef HW_INIT_H_
-#define HW_INIT_H_
-
-#include <config.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-void hw_init(void);
-void hw_usb_process(void);
-bool hw_usb_connected(void);
-bool hw_usb_enum_done(void);
-
-void hw_led_red(bool on);
-void hw_led_green(bool on);
-
-uint32_t tim_get_ms(void);
-uint64_t tim_get_us(void);
-void tim_wait_ms(uint32_t ms);
-
-#endif /* HW_INIT_H_ */
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef HW_INIT_H_
+#define HW_INIT_H_
+
+#include <config.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+void hw_init(void);
+void hw_usb_process(void);
+bool hw_usb_connected(void);
+bool hw_usb_enum_done(void);
+
+void hw_led_red(bool on);
+void hw_led_green(bool on);
+
+uint32_t tim_get_ms(void);
+uint64_t tim_get_us(void);
+void tim_wait_ms(uint32_t ms);
+
+#endif /* HW_INIT_H_ */
--- a/demos/stm32f429_disco/main.c
+++ b/demos/stm32f429_disco/main.c
@@ -1,486 +1,169 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-#include <hw_init.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <stdbool.h>
-#include <time.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <usb_msc_lwext4.h>
-#include <ext4.h>
-
-/**@brief Read-write size*/
-#define READ_WRITE_SZIZE 1024 * 16
-
-/**@brief Delay test (slower LCD scroll)*/
-#define TEST_DELAY_MS 1000
-
-/**@brief Input stream name.*/
-char input_name[128] = "ext2";
-
-/**@brief Read-write size*/
-static int rw_szie = READ_WRITE_SZIZE;
-
-/**@brief Read-write size*/
-static int rw_count = 100;
-
-/**@brief Directory test count*/
-static int dir_cnt = 100;
-
-/**@brief Static or dynamic cache mode*/
-static bool cache_mode = false;
-
-/**@brief Cleanup after test.*/
-static bool cleanup_flag = false;
-
-/**@brief Block device stats.*/
-static bool bstat = false;
-
-/**@brief Superblock stats.*/
-static bool sbstat = false;
-
-/**@brief File write buffer*/
-static uint8_t wr_buff[READ_WRITE_SZIZE];
-
-/**@brief File read buffer.*/
-static uint8_t rd_buff[READ_WRITE_SZIZE];
-
-/**@brief Block device handle.*/
-static struct ext4_blockdev *bd;
-
-/**@brief Block cache handle.*/
-static struct ext4_bcache *bc;
-
-static char* entry_to_str(uint8_t type)
-{
- switch(type){
- case EXT4_DIRENTRY_UNKNOWN:
- return "[UNK] ";
- case EXT4_DIRENTRY_REG_FILE:
- return "[FIL] ";
- case EXT4_DIRENTRY_DIR:
- return "[DIR] ";
- case EXT4_DIRENTRY_CHRDEV:
- return "[CHA] ";
- case EXT4_DIRENTRY_BLKDEV:
- return "[BLK] ";
- case EXT4_DIRENTRY_FIFO:
- return "[FIF] ";
- case EXT4_DIRENTRY_SOCK:
- return "[SOC] ";
- case EXT4_DIRENTRY_SYMLINK:
- return "[SYM] ";
- default:
- break;
- }
- return "[???]";
-}
-
-static void dir_ls(const char *path)
-{
- char sss[255];
- ext4_dir d;
- const ext4_direntry *de;
-
- printf("ls %s\n", path);
-
- ext4_dir_open(&d, path);
- de = ext4_dir_entry_next(&d);
-
- while(de){
- memcpy(sss, de->name, de->name_length);
- sss[de->name_length] = 0;
- printf(" %s", entry_to_str(de->inode_type));
- printf("%s", sss);
- printf("\n");
- de = ext4_dir_entry_next(&d);
- }
- ext4_dir_close(&d);
-}
-
-static void mp_stats(void)
-{
- struct ext4_mount_stats stats;
- ext4_mount_point_stats("/mp/", &stats);
-
- printf("********************\n");
- printf("ext4_mount_point_stats\n");
- printf("inodes_count = %u\n", stats.inodes_count);
- printf("free_inodes_count = %u\n", stats.free_inodes_count);
- printf("blocks_count = %u\n", (uint32_t)stats.blocks_count);
- printf("free_blocks_count = %u\n", (uint32_t)stats.free_blocks_count);
- printf("block_size = %u\n", stats.block_size);
- printf("block_group_count = %u\n", stats.block_group_count);
- printf("blocks_per_group= %u\n", stats.blocks_per_group);
- printf("inodes_per_group = %u\n", stats.inodes_per_group);
- printf("volume_name = %s\n", stats.volume_name);
-
- printf("********************\n");
-
-}
-
-static void block_stats(void)
-{
- uint32_t i;
-
- printf("********************\n");
- printf("ext4 blockdev stats\n");
- printf("bdev->bread_ctr = %u\n", bd->bread_ctr);
- printf("bdev->bwrite_ctr = %u\n", bd->bwrite_ctr);
-
-
- printf("bcache->ref_blocks = %u\n", bc->ref_blocks);
- printf("bcache->max_ref_blocks = %u\n", bc->max_ref_blocks);
- printf("bcache->lru_ctr = %u\n", bc->lru_ctr);
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->refctr[%d]= %u\n", i, bc->refctr[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->lru_id[%d] = %u\n", i, bc->lru_id[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->free_delay[%d] = %d\n", i, bc->free_delay[i]);
- }
-
- printf("\n");
- for (i = 0; i < bc->cnt; ++i) {
- printf("bcache->lba[%d] = %u\n", i, (uint32_t)bc->lba[i]);
- }
-
- printf("********************\n");
-}
-
-static clock_t get_ms(void)
-{
- return tim_get_ms();
-}
-
-static void printf_io_timings(clock_t diff)
-{
- const struct ext4_io_stats *stats = io_timings_get(diff);
- printf("io_timings:\n");
- printf(" io_read: %.3f%%\n", stats->io_read);
- printf(" io_write: %.3f%%\n", stats->io_write);
- printf(" io_cpu: %.3f%%\n", stats->cpu);
-}
-
-static bool dir_test(int len)
-{
- ext4_file f;
- int r;
- int i;
- char path[64];
- clock_t diff;
- clock_t stop;
- clock_t start;
-
- printf("dir_test: %d\n", len);
- io_timings_clear();
- start = get_ms();
-
- printf("directory create: /mp/dir1\n");
- r = ext4_dir_mk("/mp/dir1");
- if(r != EOK){
- printf("ext4_dir_mk: rc = %d\n", r);
- return false;
- }
-
- printf("add files to: /mp/dir1\n");
- for (i = 0; i < len; ++i) {
- sprintf(path, "/mp/dir1/f%d", i);
- r = ext4_fopen(&f, path, "wb");
- if(r != EOK){
- printf("ext4_fopen: rc = %d\n", r);
- return false;
- }
- }
-
- stop = get_ms();
- diff = stop - start;
- dir_ls("/mp/dir1");
- printf("dir_test: time: %d ms\n", (int)diff);
- printf("dir_test: av: %d ms/entry\n", (int)diff / len);
- printf_io_timings(diff);
- return true;
-}
-
-
-static bool file_test(void)
-{
- int r;
- size_t size;
- ext4_file f;
- int i;
- clock_t start;
- clock_t stop;
- clock_t diff;
- uint32_t kbps;
- uint64_t size_bytes;
-
- printf("file_test:\n");
-
- /*Add hello world file.*/
- r = ext4_fopen(&f, "/mp/hello.txt", "wb");
- r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);
- r = ext4_fclose(&f);
-
-
- io_timings_clear();
- start = get_ms();
- r = ext4_fopen(&f, "/mp/test1", "wb");
- if(r != EOK){
- printf("ext4_fopen ERROR = %d\n", r);
- return false;
- }
-
- printf("ext4_write: %d * %d ...\n" , rw_szie, rw_count);
- for (i = 0; i < rw_count; ++i) {
-
- memset(wr_buff, i % 10 + '0', rw_szie);
-
- r = ext4_fwrite(&f, wr_buff, rw_szie, &size);
-
- if((r != EOK) || (size != rw_szie))
- break;
- }
-
- if(i != rw_count){
- printf(" file_test: rw_count = %d\n", i);
- return false;
- }
-
- stop = get_ms();
- diff = stop - start;
- size_bytes = rw_szie * rw_count;
- size_bytes = (size_bytes * 1000) / 1024;
- kbps = (size_bytes) / (diff + 1);
- printf(" write time: %d ms\n", (int)diff);
- printf(" write speed: %d KB/s\n", kbps);
- printf_io_timings(diff);
- r = ext4_fclose(&f);
-
-
- io_timings_clear();
- start = get_ms();
- r = ext4_fopen(&f, "/mp/test1", "r+");
- if(r != EOK){
- printf("ext4_fopen ERROR = %d\n", r);
- return false;
- }
-
- printf("ext4_read: %d * %d ...\n" , rw_szie, rw_count);
-
- for (i = 0; i < rw_count; ++i) {
- memset(wr_buff, i % 10 + '0', rw_szie);
- r = ext4_fread(&f, rd_buff, rw_szie, &size);
-
- if((r != EOK) || (size != rw_szie))
- break;
-
- if(memcmp(rd_buff, wr_buff, rw_szie))
- break;
- }
-
- if(i != rw_count){
- printf(" file_test: rw_count = %d\n", i);
- return false;
- }
-
- stop = get_ms();
- diff = stop - start;
- size_bytes = rw_szie * rw_count;
- size_bytes = (size_bytes * 1000) / 1024;
- kbps = (size_bytes) / (diff + 1);
- printf(" read time: %d ms\n", (int)diff);
- printf(" read speed: %d KB/s\n", kbps);
- printf_io_timings(diff);
-
- r = ext4_fclose(&f);
- return true;
-
-}
-static void cleanup(void)
-{
- clock_t start;
- clock_t stop;
- clock_t diff;
-
- printf("\ncleanup:\n");
- ext4_fremove("/mp/hello.txt");
-
- printf("remove /mp/test1\n");
- ext4_fremove("/mp/test1");
-
-
- printf("remove /mp/dir1\n");
- io_timings_clear();
- start = get_ms();
- ext4_dir_rm("/mp/dir1");
- stop = get_ms();
- diff = stop - start;
- printf("cleanup: time: %d ms\n", (int)diff);
- printf_io_timings(diff);
-}
-
-static bool open_filedev(void)
-{
-
- bd = ext4_usb_msc_get();
- bc = ext4_usb_msc_cache_get();
- if(!bd || !bc){
- printf("open_filedev: fail\n");
- return false;
- }
- return true;
-}
-
-static bool mount(void)
-{
- int r;
-
- if(!open_filedev())
- return false;
-
- ext4_dmask_set(EXT4_DEBUG_ALL);
-
- r = ext4_device_register(bd, cache_mode ? 0 : bc, "ext4_fs");
- if(r != EOK){
- printf("ext4_device_register: rc = %d\n", r);
- return false;
- }
-
- r = ext4_mount("ext4_fs", "/mp/");
- if(r != EOK){
- printf("ext4_mount: rc = %d\n", r);
- return false;
- }
-
- return true;
-}
-
-static bool umount(void)
-{
- int r = ext4_umount("/mp/");
- if(r != EOK){
- printf("ext4_umount: fail %d", r);
- return false;
- }
- return true;
-}
-
-
-int main(void)
-{
- hw_init();
-
- setbuf(stdout, 0);
- printf("connect usb drive...\n");
-
- while(!hw_usb_connected())
- hw_usb_process();
- printf("usb drive connected\n");
-
- while(!hw_usb_enum_done())
- hw_usb_process();
- printf("usb drive enum done\n");
-
- hw_led_red(1);
-
- printf("test conditions:\n");
- printf(" rw size: %d\n", rw_szie);
- printf(" rw count: %d\n", rw_count);
- printf(" cache mode: %s\n", cache_mode ? "dynamic" : "static");
-
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!mount())
- return EXIT_FAILURE;
-
- tim_wait_ms(TEST_DELAY_MS);
-
- ext4_cache_write_back("/mp/", 1);
- cleanup();
-
- if(sbstat){
- tim_wait_ms(TEST_DELAY_MS);
- mp_stats();
- }
-
- tim_wait_ms(TEST_DELAY_MS);
- dir_ls("/mp/");
- if(!dir_test(dir_cnt))
- return EXIT_FAILURE;
-
- tim_wait_ms(TEST_DELAY_MS);
- if(!file_test())
- return EXIT_FAILURE;
-
- if(sbstat){
- tim_wait_ms(TEST_DELAY_MS);
- mp_stats();
- }
-
- if(cleanup_flag){
- tim_wait_ms(TEST_DELAY_MS);
- cleanup();
- }
-
- if(bstat){
- tim_wait_ms(TEST_DELAY_MS);
- block_stats();
- }
-
- ext4_cache_write_back("/mp/", 0);
- if(!umount())
- return EXIT_FAILURE;
-
- printf("press RESET button to restart\n");
-
- while (1) {
- tim_wait_ms(500);
- hw_led_green(1);
- tim_wait_ms(500);
- hw_led_green(0);
-
- }
-}
-
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+#include <hw_init.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <stdbool.h>
+#include <time.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <usb_msc_lwext4.h>
+#include <ext4.h>
+#include "../../blockdev/test_lwext4.h"
+
+/**@brief Read-write size*/
+#define READ_WRITE_SZIZE 1024 * 16
+
+/**@brief Delay test (slower LCD scroll)*/
+#define TEST_DELAY_MS 1000
+
+/**@brief Input stream name.*/
+char input_name[128] = "ext2";
+
+/**@brief Read-write size*/
+static int rw_szie = READ_WRITE_SZIZE;
+
+/**@brief Read-write size*/
+static int rw_count = 100;
+
+/**@brief Directory test count*/
+static int dir_cnt = 100;
+
+/**@brief Static or dynamic cache mode*/
+static bool cache_mode = false;
+
+/**@brief Cleanup after test.*/
+static bool cleanup_flag = false;
+
+/**@brief Block device stats.*/
+static bool bstat = false;
+
+/**@brief Superblock stats.*/
+static bool sbstat = false;
+
+/**@brief Block device handle.*/
+static struct ext4_blockdev *bd;
+
+/**@brief Block cache handle.*/
+static struct ext4_bcache *bc;
+
+static bool open_filedev(void)
+{
+
+ bd = ext4_usb_msc_get();
+ bc = ext4_usb_msc_cache_get();
+ if (!bd || !bc) {
+ printf("open_filedev: fail\n");
+ return false;
+ }
+ return true;
+}
+
+int main(void)
+{
+ hw_init();
+
+ setbuf(stdout, 0);
+ printf("connect usb drive...\n");
+
+ while (!hw_usb_connected())
+ hw_usb_process();
+ printf("usb drive connected\n");
+
+ while (!hw_usb_enum_done())
+ hw_usb_process();
+ printf("usb drive enum done\n");
+
+ hw_led_red(1);
+
+ printf("test conditions:\n");
+ printf(" rw size: %d\n", rw_szie);
+ printf(" rw count: %d\n", rw_count);
+ printf(" cache mode: %s\n", cache_mode ? "dynamic" : "static");
+
+ if (!open_filedev())
+ goto Finish;
+
+ tim_wait_ms(TEST_DELAY_MS);
+ if (!test_lwext4_mount(bd, bc))
+ return EXIT_FAILURE;
+
+ tim_wait_ms(TEST_DELAY_MS);
+
+ ext4_cache_write_back("/mp/", 1);
+ test_lwext4_cleanup();
+
+ if (sbstat) {
+ tim_wait_ms(TEST_DELAY_MS);
+ test_lwext4_mp_stats();
+ }
+
+ tim_wait_ms(TEST_DELAY_MS);
+ test_lwext4_dir_ls("/mp/");
+ if (!test_lwext4_dir_test(dir_cnt))
+ return EXIT_FAILURE;
+
+ tim_wait_ms(TEST_DELAY_MS);
+ if (!test_lwext4_file_test(rw_szie, rw_count))
+ return EXIT_FAILURE;
+
+ if (sbstat) {
+ tim_wait_ms(TEST_DELAY_MS);
+ test_lwext4_mp_stats();
+ }
+
+ if (cleanup_flag) {
+ tim_wait_ms(TEST_DELAY_MS);
+ test_lwext4_cleanup();
+ }
+
+ if (bstat) {
+ tim_wait_ms(TEST_DELAY_MS);
+ test_lwext4_block_stats();
+ }
+
+ ext4_cache_write_back("/mp/", 0);
+ if (!test_lwext4_umount())
+ return EXIT_FAILURE;
+
+ printf("press RESET button to restart\n");
+Finish:
+ while (1) {
+ tim_wait_ms(500);
+ hw_led_green(1);
+ tim_wait_ms(500);
+ hw_led_green(0);
+ }
+}
--- a/demos/stm32f429_disco/stm/usb_host/Core/src/usbh_core.c
+++ b/demos/stm32f429_disco/stm/usb_host/Core/src/usbh_core.c
@@ -276,10 +276,6 @@
pif = (USBH_InterfaceDescTypeDef *)0;
pcfg = &phost->device.CfgDesc;
- if((pif->bInterfaceClass == 0xFF) &&(pif->bInterfaceSubClass == 0xFF) && (pif->bInterfaceProtocol == 0xFF))
- {
- return 0xFF;
- }
while (if_ix < USBH_MAX_NUM_INTERFACES)
{
--- a/demos/stm32f429_disco/syscalls.c
+++ b/demos/stm32f429_disco/syscalls.c
@@ -1,156 +1,139 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <stdio.h>
-#include <signal.h>
-#include <time.h>
-
-#include <lcd_log.h>
-
-int _getpid(void)
-{
- return 1;
-}
-
-int _kill(int pid, int sig)
-{
- errno = EINVAL;
- return -1;
-}
-
-void _exit (int status)
-{
- _kill(status, -1);
- while (1) {} /* Make sure we hang here */
-}
-
-int _write(int file, char *ptr, int len)
-{
- int todo;
-
- for (todo = 0; todo < len; todo++)
- {
- __io_putchar( *ptr++ );
- }
-
- /* Implement your write code here, this is used by puts and printf for example */
- return len;
-}
-
-caddr_t _sbrk(int incr)
-{
- extern char __heap_start;
- extern char __heap_end;
- static char *current_heap_end = &__heap_start;
- char *previous_heap_end;
-
- previous_heap_end = current_heap_end;
-
- if (current_heap_end + incr > &__heap_end)
- {
- errno = ENOMEM;
- return (caddr_t) -1;
- }
-
- current_heap_end += incr;
-
- return (caddr_t)previous_heap_end;
-}
-
-int _close(int file)
-{
- return -1;
-}
-
-
-int _fstat(int file, struct stat *st)
-{
- st->st_mode = S_IFCHR;
- return 0;
-}
-
-int _isatty(int file)
-{
- return 1;
-}
-
-int _lseek(int file, int ptr, int dir)
-{
- return 0;
-}
-
-int _read(int file, char *ptr, int len)
-{
- return 0;
-}
-
-int _open(char *path, int flags, ...)
-{
- /* Pretend like we always fail */
- return -1;
-}
-
-int _wait(int *status)
-{
- errno = ECHILD;
- return -1;
-}
-
-int _unlink(char *name)
-{
- errno = ENOENT;
- return -1;
-}
-
-
-int _stat(char *file, struct stat *st)
-{
- st->st_mode = S_IFCHR;
- return 0;
-}
-
-int _link(char *old, char *new)
-{
- errno = EMLINK;
- return -1;
-}
-
-int _fork(void)
-{
- errno = EAGAIN;
- return -1;
-}
-
-int _execve(char *name, char **argv, char **env)
-{
- errno = ENOMEM;
- return -1;
-}
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <signal.h>
+#include <time.h>
+
+#include <lcd_log.h>
+
+int _getpid(void) { return 1; }
+
+int _kill(int pid, int sig)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+void _exit(int status)
+{
+ _kill(status, -1);
+ while (1) {
+ } /* Make sure we hang here */
+}
+
+int _write(int file, char *ptr, int len)
+{
+ int todo;
+
+ for (todo = 0; todo < len; todo++) {
+ __io_putchar(*ptr++);
+ }
+
+ /* Implement your write code here, this is used by puts and printf for
+ * example */
+ return len;
+}
+
+caddr_t _sbrk(int incr)
+{
+ extern char __heap_start;
+ extern char __heap_end;
+ static char *current_heap_end = &__heap_start;
+ char *previous_heap_end;
+
+ previous_heap_end = current_heap_end;
+
+ if (current_heap_end + incr > &__heap_end) {
+ errno = ENOMEM;
+ return (caddr_t)-1;
+ }
+
+ current_heap_end += incr;
+
+ return (caddr_t)previous_heap_end;
+}
+
+int _close(int file) { return -1; }
+
+int _fstat(int file, struct stat *st)
+{
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+int _isatty(int file) { return 1; }
+
+int _lseek(int file, int ptr, int dir) { return 0; }
+
+int _read(int file, char *ptr, int len) { return 0; }
+
+int _open(char *path, int flags, ...)
+{
+ /* Pretend like we always fail */
+ return -1;
+}
+
+int _wait(int *status)
+{
+ errno = ECHILD;
+ return -1;
+}
+
+int _unlink(char *name)
+{
+ errno = ENOENT;
+ return -1;
+}
+
+int _stat(char *file, struct stat *st)
+{
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+int _link(char *old, char *new)
+{
+ errno = EMLINK;
+ return -1;
+}
+
+int _fork(void)
+{
+ errno = EAGAIN;
+ return -1;
+}
+
+int _execve(char *name, char **argv, char **env)
+{
+ errno = ENOMEM;
+ return -1;
+}
--- a/demos/stm32f429_disco/system_stm32f4xx.c
+++ b/demos/stm32f429_disco/system_stm32f4xx.c
@@ -1,270 +1,302 @@
-/**
- ******************************************************************************
- * @file system_stm32f4xx.c
- * @author MCD Application Team
- * @version V1.0.1
- * @date 26-February-2014
- * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
- *
- * This file provides two functions and one global variable to be called from
- * user application:
- * - SystemInit(): This function is called at startup just after reset and
- * before branch to main program. This call is made inside
- * the "startup_stm32f4xx.s" file.
- *
- * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
- * by the user application to setup the SysTick
- * timer or configure other parameters.
- *
- * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
- * be called whenever the core clock is changed
- * during program execution.
- *
- *
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
-
-/** @addtogroup CMSIS
- * @{
- */
-
-/** @addtogroup stm32f4xx_system
- * @{
- */
-
-/** @addtogroup STM32F4xx_System_Private_Includes
- * @{
- */
-
-#include "stm32f4xx_hal.h"
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
- * @{
- */
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_Defines
- * @{
- */
-
-/************************* Miscellaneous Configuration ************************/
-
-/*!< Uncomment the following line if you need to relocate your vector Table in
- Internal SRAM. */
-/* #define VECT_TAB_SRAM */
-#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
- This value must be a multiple of 0x200. */
-/******************************************************************************/
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_Macros
- * @{
- */
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_Variables
- * @{
- */
- /* This variable is updated in three ways:
- 1) by calling CMSIS function SystemCoreClockUpdate()
- 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
- 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
- Note: If you use this function to configure the system clock; then there
- is no need to call the 2 first functions listed above, since SystemCoreClock
- variable is updated automatically.
- */
- uint32_t SystemCoreClock = 16000000;
- __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
- * @{
- */
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_Functions
- * @{
- */
-
-/**
- * @brief Setup the microcontroller system
- * Initialize the FPU setting, vector table location and External memory
- * configuration.
- * @param None
- * @retval None
- */
-void SystemInit(void)
-{
- /* FPU settings ------------------------------------------------------------*/
- #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
- SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
- #endif
- /* Reset the RCC clock configuration to the default reset state ------------*/
- /* Set HSION bit */
- RCC->CR |= (uint32_t)0x00000001;
-
- /* Reset CFGR register */
- RCC->CFGR = 0x00000000;
-
- /* Reset HSEON, CSSON and PLLON bits */
- RCC->CR &= (uint32_t)0xFEF6FFFF;
-
- /* Reset PLLCFGR register */
- RCC->PLLCFGR = 0x24003010;
-
- /* Reset HSEBYP bit */
- RCC->CR &= (uint32_t)0xFFFBFFFF;
-
- /* Disable all interrupts */
- RCC->CIR = 0x00000000;
-
- /* Configure the Vector Table location add offset address ------------------*/
-#ifdef VECT_TAB_SRAM
- SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
-#else
- SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
-#endif
-}
-
-/**
- * @brief Update SystemCoreClock variable according to Clock Register Values.
- * The SystemCoreClock variable contains the core clock (HCLK), it can
- * be used by the user application to setup the SysTick timer or configure
- * other parameters.
- *
- * @note Each time the core clock (HCLK) changes, this function must be called
- * to update SystemCoreClock variable value. Otherwise, any configuration
- * based on this variable will be incorrect.
- *
- * @note - The system frequency computed by this function is not the real
- * frequency in the chip. It is calculated based on the predefined
- * constant and the selected clock source:
- *
- * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
- *
- * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
- *
- * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
- * or HSI_VALUE(*) multiplied/divided by the PLL factors.
- *
- * (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
- * 16 MHz) but the real value may vary depending on the variations
- * in voltage and temperature.
- *
- * (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (its value
- * depends on the application requirements), user has to ensure that HSE_VALUE
- * is same as the real frequency of the crystal used. Otherwise, this function
- * may have wrong result.
- *
- * - The result of this function could be not correct when using fractional
- * value for HSE crystal.
- *
- * @param None
- * @retval None
- */
-void SystemCoreClockUpdate(void)
-{
- uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
-
- /* Get SYSCLK source -------------------------------------------------------*/
- tmp = RCC->CFGR & RCC_CFGR_SWS;
-
- switch (tmp)
- {
- case 0x00: /* HSI used as system clock source */
- SystemCoreClock = HSI_VALUE;
- break;
- case 0x04: /* HSE used as system clock source */
- SystemCoreClock = HSE_VALUE;
- break;
- case 0x08: /* PLL used as system clock source */
-
- /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
- SYSCLK = PLL_VCO / PLL_P
- */
- pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
- pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
-
- if (pllsource != 0)
- {
- /* HSE used as PLL clock source */
- pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
- }
- else
- {
- /* HSI used as PLL clock source */
- pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
- }
-
- pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
- SystemCoreClock = pllvco/pllp;
- break;
- default:
- SystemCoreClock = HSI_VALUE;
- break;
- }
- /* Compute HCLK frequency --------------------------------------------------*/
- /* Get HCLK prescaler */
- tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
- /* HCLK frequency */
- SystemCoreClock >>= tmp;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/**
+ ******************************************************************************
+ * @file system_stm32f4xx.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 26-February-2014
+ * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
+ *
+ * This file provides two functions and one global variable to be called from
+ * user application:
+ * - SystemInit(): This function is called at startup just after reset and
+ * before branch to main program. This call is made inside
+ * the "startup_stm32f4xx.s" file.
+ *
+ * - SystemCoreClock variable: Contains the core clock (HCLK), it can be
+ *used
+ * by the user application to setup the
+ *SysTick
+ * timer or configure other parameters.
+ *
+ * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and
+ *must
+ * be called whenever the core clock is changed
+ * during program execution.
+ *
+ *
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ *modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice,
+ * this list of conditions and the following disclaimer in the
+ *documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its
+ *contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ *ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ *LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/** @addtogroup CMSIS
+ * @{
+ */
+
+/** @addtogroup stm32f4xx_system
+ * @{
+ */
+
+/** @addtogroup STM32F4xx_System_Private_Includes
+ * @{
+ */
+
+#include "stm32f4xx_hal.h"
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F4xx_System_Private_Defines
+ * @{
+ */
+
+/************************* Miscellaneous Configuration ************************/
+
+/*!< Uncomment the following line if you need to relocate your vector Table in
+ Internal SRAM. */
+/* #define VECT_TAB_SRAM */
+#define VECT_TAB_OFFSET \
+ 0x00 /*!< Vector Table base offset field. \
+ This value must be a multiple of 0x200. */
+/******************************************************************************/
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F4xx_System_Private_Macros
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F4xx_System_Private_Variables
+ * @{
+ */
+/* This variable is updated in three ways:
+ 1) by calling CMSIS function SystemCoreClockUpdate()
+ 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
+ 3) each time HAL_RCC_ClockConfig() is called to configure the system clock
+ frequency
+ Note: If you use this function to configure the system clock; then there
+ is no need to call the 2 first functions listed above, since
+ SystemCoreClock
+ variable is updated automatically.
+*/
+uint32_t SystemCoreClock = 16000000;
+__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 2, 3, 4, 6, 7, 8, 9};
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F4xx_System_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Setup the microcontroller system
+ * Initialize the FPU setting, vector table location and External
+ * memory
+ * configuration.
+ * @param None
+ * @retval None
+ */
+void SystemInit(void)
+{
+/* FPU settings ------------------------------------------------------------*/
+#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
+ SCB->CPACR |= ((3UL << 10 * 2) |
+ (3UL << 11 * 2)); /* set CP10 and CP11 Full Access */
+#endif
+ /* Reset the RCC clock configuration to the default reset state
+ * ------------*/
+ /* Set HSION bit */
+ RCC->CR |= (uint32_t)0x00000001;
+
+ /* Reset CFGR register */
+ RCC->CFGR = 0x00000000;
+
+ /* Reset HSEON, CSSON and PLLON bits */
+ RCC->CR &= (uint32_t)0xFEF6FFFF;
+
+ /* Reset PLLCFGR register */
+ RCC->PLLCFGR = 0x24003010;
+
+ /* Reset HSEBYP bit */
+ RCC->CR &= (uint32_t)0xFFFBFFFF;
+
+ /* Disable all interrupts */
+ RCC->CIR = 0x00000000;
+
+/* Configure the Vector Table location add offset address ------------------*/
+#ifdef VECT_TAB_SRAM
+ SCB->VTOR =
+ SRAM_BASE |
+ VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
+#else
+ SCB->VTOR =
+ FLASH_BASE |
+ VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
+#endif
+}
+
+/**
+ * @brief Update SystemCoreClock variable according to Clock Register Values.
+ * The SystemCoreClock variable contains the core clock (HCLK), it can
+ * be used by the user application to setup the SysTick timer or
+ * configure
+ * other parameters.
+ *
+ * @note Each time the core clock (HCLK) changes, this function must be
+ * called
+ * to update SystemCoreClock variable value. Otherwise, any
+ * configuration
+ * based on this variable will be incorrect.
+ *
+ * @note - The system frequency computed by this function is not the real
+ * frequency in the chip. It is calculated based on the predefined
+ * constant and the selected clock source:
+ *
+ * - If SYSCLK source is HSI, SystemCoreClock will contain the
+ * HSI_VALUE(*)
+ *
+ * - If SYSCLK source is HSE, SystemCoreClock will contain the
+ * HSE_VALUE(**)
+ *
+ * - If SYSCLK source is PLL, SystemCoreClock will contain the
+ * HSE_VALUE(**)
+ * or HSI_VALUE(*) multiplied/divided by the PLL factors.
+ *
+ * (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file
+ * (default value
+ * 16 MHz) but the real value may vary depending on the variations
+ * in voltage and temperature.
+ *
+ * (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file
+ * (its value
+ * depends on the application requirements), user has to ensure
+ * that HSE_VALUE
+ * is same as the real frequency of the crystal used. Otherwise,
+ * this function
+ * may have wrong result.
+ *
+ * - The result of this function could be not correct when using
+ * fractional
+ * value for HSE crystal.
+ *
+ * @param None
+ * @retval None
+ */
+void SystemCoreClockUpdate(void)
+{
+ uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
+
+ /* Get SYSCLK source
+ * -------------------------------------------------------*/
+ tmp = RCC->CFGR & RCC_CFGR_SWS;
+
+ switch (tmp) {
+ case 0x00: /* HSI used as system clock source */
+ SystemCoreClock = HSI_VALUE;
+ break;
+ case 0x04: /* HSE used as system clock source */
+ SystemCoreClock = HSE_VALUE;
+ break;
+ case 0x08: /* PLL used as system clock source */
+
+ /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
+ SYSCLK = PLL_VCO / PLL_P
+ */
+ pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
+ pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
+
+ if (pllsource != 0) {
+ /* HSE used as PLL clock source */
+ pllvco = (HSE_VALUE / pllm) *
+ ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+ } else {
+ /* HSI used as PLL clock source */
+ pllvco = (HSI_VALUE / pllm) *
+ ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+ }
+
+ pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> 16) + 1) * 2;
+ SystemCoreClock = pllvco / pllp;
+ break;
+ default:
+ SystemCoreClock = HSI_VALUE;
+ break;
+ }
+ /* Compute HCLK frequency
+ * --------------------------------------------------*/
+ /* Get HCLK prescaler */
+ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
+ /* HCLK frequency */
+ SystemCoreClock >>= tmp;
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/demos/stm32f429_disco/usb_msc_lwext4.c
+++ b/demos/stm32f429_disco/usb_msc_lwext4.c
@@ -1,220 +1,203 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <fcntl.h>
-
-
-#include <hw_init.h>
-#include <usbh_core.h>
-#include <usbh_msc.h>
-
-#include <usb_msc_lwext4.h>
-
-extern USBH_HandleTypeDef hUSB_Host;
-
-/**@brief Block size.*/
-#define USB_MSC_BLOCK_SIZE 512
-
-/**@brief MBR_block ID*/
-#define MBR_BLOCK_ID 0
-#define MBR_PART_TABLE_OFF 446
-
-struct part_tab_entry {
- uint8_t status;
- uint8_t chs1[3];
- uint8_t type;
- uint8_t chs2[3];
- uint32_t first_lba;
- uint32_t sectors;
-}__attribute__((packed));
-
-/**@brief Partition block offset*/
-static uint32_t part_offset;
-
-/**@brief IO timings*/
-struct usb_msc_io_timings {
- uint64_t acc_bread;
- uint64_t acc_bwrite;
-
- uint32_t cnt_bread;
- uint32_t cnt_bwrite;
-
- uint32_t av_bread;
- uint32_t av_bwrite;
-};
-
-
-static struct usb_msc_io_timings io_timings;
-
-
-void io_timings_clear(void)
-{
- memset(&io_timings, 0, sizeof(struct usb_msc_io_timings));
-}
-
-const struct ext4_io_stats * io_timings_get(uint32_t time_sum_ms)
-{
- static struct ext4_io_stats s;
-
- s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);
- s.io_read /= 1000.0;
-
- s.io_write= (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);
- s.io_write /= 1000.0;
-
- s.cpu = 100.0 - s.io_read - s.io_write;
-
- return &s;
-}
-
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int usb_msc_open(struct ext4_blockdev *bdev);
-static int usb_msc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt);
-static int usb_msc_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt);
-static int usb_msc_close(struct ext4_blockdev *bdev);
-
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(
- _usb_msc,
- USB_MSC_BLOCK_SIZE,
- 0,
- usb_msc_open,
- usb_msc_bread,
- usb_msc_bwrite,
- usb_msc_close
-);
-
-/******************************************************************************/
-EXT4_BCACHE_STATIC_INSTANCE(_usb_msc_cache, CONFIG_BLOCK_DEV_CACHE_SIZE, EXT_LOGICAL_BLOCK_SIZE);
-
-/******************************************************************************/
-
-static int usb_msc_open(struct ext4_blockdev *bdev)
-{
- (void)bdev;
-
- static uint8_t mbr[512];
- struct part_tab_entry *part0;
- uint8_t status;
-
- if(!hw_usb_connected())
- return EIO;
-
- status = USBH_MSC_Read(&hUSB_Host, 0, 0, mbr, 1);
- if(status != USBH_OK)
- return EIO;
-
- part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);
-
- MSC_LUNTypeDef lun;
- USBH_MSC_GetLUNInfo(&hUSB_Host, 0, &lun);
-
- part_offset = part0->first_lba;
- _usb_msc.ph_bcnt = lun.capacity.block_nbr;
-
- return hw_usb_connected() ? EOK : EIO;
-}
-
-static int usb_msc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
-{
- uint8_t status;
-
- uint64_t v = tim_get_us();
-
- if(!hw_usb_connected())
- return EIO;
-
- while(!USBH_MSC_UnitIsReady(&hUSB_Host, 0))
- ;
-
- status = USBH_MSC_Read(&hUSB_Host, 0, blk_id + part_offset, buf, blk_cnt);
- if(status != USBH_OK)
- return EIO;
-
- io_timings.acc_bread += tim_get_us() - v;
- io_timings.cnt_bread++;
- io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;
-
- return EOK;
-
-}
-
-static int usb_msc_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt)
-{
- uint8_t status;
-
- uint64_t v = tim_get_us();
-
- if(!hw_usb_connected())
- return EIO;
-
- while(!USBH_MSC_UnitIsReady(&hUSB_Host, 0))
- ;
-
- status = USBH_MSC_Write(&hUSB_Host, 0, blk_id + part_offset, (void *)buf, blk_cnt);
- if(status != USBH_OK)
- return EIO;
-
- io_timings.acc_bwrite += tim_get_us() - v;
- io_timings.cnt_bwrite++;
- io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;
-
- return EOK;
-}
-
-static int usb_msc_close(struct ext4_blockdev *bdev)
-{
- (void)bdev;
- return EOK;
-}
-
-/******************************************************************************/
-
-struct ext4_bcache* ext4_usb_msc_cache_get(void)
-{
- return &_usb_msc_cache;
-}
-
-
-struct ext4_blockdev* ext4_usb_msc_get(void)
-{
- return &_usb_msc;
-}
-
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include <hw_init.h>
+#include <usbh_core.h>
+#include <usbh_msc.h>
+
+#include <usb_msc_lwext4.h>
+#include "../../blockdev/test_lwext4.h"
+
+extern USBH_HandleTypeDef hUSB_Host;
+
+/**@brief Block size.*/
+#define USB_MSC_BLOCK_SIZE 512
+
+/**@brief MBR_block ID*/
+#define MBR_BLOCK_ID 0
+#define MBR_PART_TABLE_OFF 446
+
+struct part_tab_entry {
+ uint8_t status;
+ uint8_t chs1[3];
+ uint8_t type;
+ uint8_t chs2[3];
+ uint32_t first_lba;
+ uint32_t sectors;
+} __attribute__((packed));
+
+/**@brief Partition block offset*/
+static uint32_t part_offset;
+
+/**@brief IO timings*/
+struct usb_msc_io_timings {
+ uint64_t acc_bread;
+ uint64_t acc_bwrite;
+
+ uint32_t cnt_bread;
+ uint32_t cnt_bwrite;
+
+ uint32_t av_bread;
+ uint32_t av_bwrite;
+};
+
+static struct usb_msc_io_timings io_timings;
+
+void io_timings_clear(void)
+{
+ memset(&io_timings, 0, sizeof(struct usb_msc_io_timings));
+}
+
+const struct ext4_io_stats *io_timings_get(uint32_t time_sum_ms)
+{
+ static struct ext4_io_stats s;
+
+ s.io_read = (((float)io_timings.acc_bread * 100.0) / time_sum_ms);
+ s.io_read /= 1000.0;
+
+ s.io_write = (((float)io_timings.acc_bwrite * 100.0) / time_sum_ms);
+ s.io_write /= 1000.0;
+
+ s.cpu = 100.0 - s.io_read - s.io_write;
+
+ return &s;
+}
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int usb_msc_open(struct ext4_blockdev *bdev);
+static int usb_msc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt);
+static int usb_msc_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt);
+static int usb_msc_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_usb_msc, USB_MSC_BLOCK_SIZE, 0, usb_msc_open,
+ usb_msc_bread, usb_msc_bwrite, usb_msc_close);
+
+/******************************************************************************/
+EXT4_BCACHE_STATIC_INSTANCE(_usb_msc_cache, CONFIG_BLOCK_DEV_CACHE_SIZE,
+ EXT_LOGICAL_BLOCK_SIZE);
+
+/******************************************************************************/
+
+static int usb_msc_open(struct ext4_blockdev *bdev)
+{
+ (void)bdev;
+
+ static uint8_t mbr[512];
+ struct part_tab_entry *part0;
+ uint8_t status;
+
+ if (!hw_usb_connected())
+ return EIO;
+
+ status = USBH_MSC_Read(&hUSB_Host, 0, 0, mbr, 1);
+ if (status != USBH_OK)
+ return EIO;
+
+ part0 = (struct part_tab_entry *)(mbr + MBR_PART_TABLE_OFF);
+
+ MSC_LUNTypeDef lun;
+ USBH_MSC_GetLUNInfo(&hUSB_Host, 0, &lun);
+
+ part_offset = part0->first_lba;
+ _usb_msc.ph_bcnt = lun.capacity.block_nbr;
+
+ return hw_usb_connected() ? EOK : EIO;
+}
+
+static int usb_msc_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt)
+{
+ uint8_t status;
+
+ uint64_t v = tim_get_us();
+
+ if (!hw_usb_connected())
+ return EIO;
+
+ while (!USBH_MSC_UnitIsReady(&hUSB_Host, 0))
+ ;
+
+ status =
+ USBH_MSC_Read(&hUSB_Host, 0, blk_id + part_offset, buf, blk_cnt);
+ if (status != USBH_OK)
+ return EIO;
+
+ io_timings.acc_bread += tim_get_us() - v;
+ io_timings.cnt_bread++;
+ io_timings.av_bread = io_timings.acc_bread / io_timings.cnt_bread;
+
+ return EOK;
+}
+
+static int usb_msc_bwrite(struct ext4_blockdev *bdev, const void *buf,
+ uint64_t blk_id, uint32_t blk_cnt)
+{
+ uint8_t status;
+
+ uint64_t v = tim_get_us();
+
+ if (!hw_usb_connected())
+ return EIO;
+
+ while (!USBH_MSC_UnitIsReady(&hUSB_Host, 0))
+ ;
+
+ status = USBH_MSC_Write(&hUSB_Host, 0, blk_id + part_offset,
+ (void *)buf, blk_cnt);
+ if (status != USBH_OK)
+ return EIO;
+
+ io_timings.acc_bwrite += tim_get_us() - v;
+ io_timings.cnt_bwrite++;
+ io_timings.av_bwrite = io_timings.acc_bwrite / io_timings.cnt_bwrite;
+
+ return EOK;
+}
+
+static int usb_msc_close(struct ext4_blockdev *bdev)
+{
+ (void)bdev;
+ return EOK;
+}
+
+/******************************************************************************/
+
+struct ext4_bcache *ext4_usb_msc_cache_get(void) { return &_usb_msc_cache; }
+
+struct ext4_blockdev *ext4_usb_msc_get(void) { return &_usb_msc; }
--- a/demos/stm32f429_disco/usb_msc_lwext4.h
+++ b/demos/stm32f429_disco/usb_msc_lwext4.h
@@ -1,57 +1,43 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef USB_MSC_LWEXT4_H_
-#define USB_MSC_LWEXT4_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief USB MSC cache get.*/
-struct ext4_bcache* ext4_usb_msc_cache_get(void);
-
-/**@brief USB MSC blockdev get.*/
-struct ext4_blockdev* ext4_usb_msc_get(void);
-
-
-
-struct ext4_io_stats {
- float io_read;
- float io_write;
- float cpu;
-};
-
-void io_timings_clear(void);
-const struct ext4_io_stats * io_timings_get(uint32_t time_sum_ms);
-
-
-
-
-#endif /* USB_MSC_LWEXT4_H_ */
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef USB_MSC_LWEXT4_H_
+#define USB_MSC_LWEXT4_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief USB MSC cache get.*/
+struct ext4_bcache *ext4_usb_msc_cache_get(void);
+
+/**@brief USB MSC blockdev get.*/
+struct ext4_blockdev *ext4_usb_msc_get(void);
+
+#endif /* USB_MSC_LWEXT4_H_ */
--- a/demos/stm32f429_disco/vectors.c
+++ b/demos/stm32f429_disco/vectors.c
@@ -1,473 +1,577 @@
-/** \file vectors.c
- * \brief STM32F4x vector table and __Default_Handler()
- * \details STM32F4x vector table and __Default_Handler()
- * \author Freddie Chopin, http://www.freddiechopin.info/
- * \date 2012-03-15
- */
-
-/******************************************************************************
-* chip: STM32F4x
-* compiler: arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.6.2
-* 20110921 (release) [ARM/embedded-4_6-branch revision 182083]
-******************************************************************************/
-
-/*------------------------------------------------------------------------*//**
-* \brief Default interrupt handler.
-* \details Default interrupt handler, used for interrupts that don't have their
-* own handler defined.
-*//*-------------------------------------------------------------------------*/
-
-static void __Default_Handler(void) __attribute__ ((interrupt));
-static void __Default_Handler(void)
-{
- while (1);
-}
-
-/*
-+=============================================================================+
-| assign all unhandled interrupts to the default handler
-+=============================================================================+
-*/
-
-// Non-maskable interrupt (RCC clock security system)
-void NMI_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// All class of fault
-void HardFault_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Memory management
-void MemManage_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Pre-fetch fault, memory access fault
-void BusFault_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Undefined instruction or illegal state
-void UsageFault_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Reserved 0x1C
-void __Reserved_0x1C_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Reserved 0x20
-void __Reserved_0x20_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Reserved 0x24
-void __Reserved_0x24_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Reserved 0x28
-void __Reserved_0x28_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// System service call via SWI instruction
-void SVC_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Debug monitor
-void DebugMon_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Reserved 0x34
-void __Reserved_0x34_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Pendable request for system service
-void PendSV_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// System tick timer
-void SysTick_Handler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Window WatchDog
-void WWDG_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// PVD through EXTI Line detection
-void PVD_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Tamper and TimeStamps through the EXTI line
-void TAMP_STAMP_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// RTC Wakeup through the EXTI line
-void RTC_WKUP_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// FLASH
-void FLASH_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// RCC
-void RCC_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// EXTI Line0
-void EXTI0_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// EXTI Line1
-void EXTI1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// EXTI Line2
-void EXTI2_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// EXTI Line3
-void EXTI3_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// EXTI Line4
-void EXTI4_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream 0
-void DMA1_Stream0_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream 1
-void DMA1_Stream1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream 2
-void DMA1_Stream2_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream 3
-void DMA1_Stream3_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream 4
-void DMA1_Stream4_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream 5
-void DMA1_Stream5_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream 6
-void DMA1_Stream6_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// ADC1, ADC2 and ADC3s
-void ADC_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN1 TX
-void CAN1_TX_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN1 RX0
-void CAN1_RX0_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN1 RX1
-void CAN1_RX1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN1 SCE
-void CAN1_SCE_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// External Line[9:5]s
-void EXTI9_5_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM1 Break and TIM9
-void TIM1_BRK_TIM9_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM1 Update and TIM10
-void TIM1_UP_TIM10_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM1 Trigger and Commutation and TIM11
-void TIM1_TRG_COM_TIM11_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM1 Capture Compare
-void TIM1_CC_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM2
-void TIM2_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM3
-void TIM3_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM4
-void TIM4_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// I2C1 Event
-void I2C1_EV_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// I2C1 Error
-void I2C1_ER_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// I2C2 Event
-void I2C2_EV_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// I2C2 Error
-void I2C2_ER_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SPI1
-void SPI1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SPI2
-void SPI2_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USART1
-void USART1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USART2
-void USART2_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USART3
-void USART3_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// External Line[15:10]s
-void EXTI15_10_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// RTC Alarm (A and B) through EXTI Line
-void RTC_Alarm_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USB OTG FS Wakeup through EXTI line
-void OTG_FS_WKUP_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM8 Break and TIM12
-void TIM8_BRK_TIM12_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM8 Update and TIM13
-void TIM8_UP_TIM13_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM8 Trigger and Commutation and TIM14
-void TIM8_TRG_COM_TIM14_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM8 Capture Compare
-void TIM8_CC_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA1 Stream7
-void DMA1_Stream7_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// FSMC
-void FSMC_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SDIO
-void SDIO_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM5
-void TIM5_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SPI3
-void SPI3_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// UART4
-void UART4_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// UART5
-void UART5_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM6 and DAC1&2 underrun errors
-void TIM6_DAC_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// TIM7
-void TIM7_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 0
-void DMA2_Stream0_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 1
-void DMA2_Stream1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 2
-void DMA2_Stream2_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 3
-void DMA2_Stream3_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 4
-void DMA2_Stream4_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Ethernet
-void ETH_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Ethernet Wakeup through EXTI line
-void ETH_WKUP_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN2 TX
-void CAN2_TX_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN2 RX0
-void CAN2_RX0_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN2 RX1
-void CAN2_RX1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CAN2 SCE
-void CAN2_SCE_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USB OTG FS
-void OTG_FS_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 5
-void DMA2_Stream5_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 6
-void DMA2_Stream6_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2 Stream 7
-void DMA2_Stream7_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USART6
-void USART6_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// I2C3 event
-void I2C3_EV_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// I2C3 error
-void I2C3_ER_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USB OTG HS End Point 1 Out
-void OTG_HS_EP1_OUT_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USB OTG HS End Point 1 In
-void OTG_HS_EP1_IN_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USB OTG HS Wakeup through EXTI
-void OTG_HS_WKUP_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// USB OTG HS
-void OTG_HS_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DCMI
-void DCMI_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// CRYP crypto
-void CRYP_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// Hash and Rng
-void HASH_RNG_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// FPU
-void FPU_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// UART7
-void UART7_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// UART8
-void UART8_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SPI4
-void SPI4_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SPI5
-void SPI5_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SPI6
-void SPI6_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// SAI1
-void SAI1_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// LTDC
-void LTDC_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// LTDC_ER
-void LTDC_ER_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-// DMA2D
-void DMA2D_IRQHandler(void) __attribute__ ((interrupt, weak, alias("__Default_Handler")));
-
-
-/*
-+=============================================================================+
-| Vector table
-+=============================================================================+
-*/
-
-extern const char __main_stack_end; // imported main stack end (from linker script)
-
-void Reset_Handler(void); // import the address of Reset_Handler()
-
-void (* const vectors[])(void) __attribute__ ((section(".vectors"))) = {
- (void (*)(void))&__main_stack_end, // Main stack end address
- Reset_Handler, // Reset
- NMI_Handler, // Non-maskable interrupt (RCC clock security system)
- HardFault_Handler, // All class of fault
- MemManage_Handler, // Memory management
- BusFault_Handler, // Pre-fetch fault, memory access fault
- UsageFault_Handler, // Undefined instruction or illegal state
- __Reserved_0x1C_Handler, // Reserved 0x1C
- __Reserved_0x20_Handler, // Reserved 0x20
- __Reserved_0x24_Handler, // Reserved 0x24
- __Reserved_0x28_Handler, // Reserved 0x28
- SVC_Handler, // System service call via SWI instruction
- DebugMon_Handler, // Debug monitor
- __Reserved_0x34_Handler, // Reserved 0x34
- PendSV_Handler, // Pendable request for system service
- SysTick_Handler, // System tick timer
-
- WWDG_IRQHandler, /* Window WatchDog */
- PVD_IRQHandler, /* PVD through EXTI Line detection */
- TAMP_STAMP_IRQHandler, /* Tamper and TimeStamps through the EXTI line */
- RTC_WKUP_IRQHandler, /* RTC Wakeup through the EXTI line */
- FLASH_IRQHandler, /* FLASH */
- RCC_IRQHandler, /* RCC */
- EXTI0_IRQHandler, /* EXTI Line0 */
- EXTI1_IRQHandler, /* EXTI Line1 */
- EXTI2_IRQHandler, /* EXTI Line2 */
- EXTI3_IRQHandler, /* EXTI Line3 */
- EXTI4_IRQHandler, /* EXTI Line4 */
- DMA1_Stream0_IRQHandler, /* DMA1 Stream 0 */
- DMA1_Stream1_IRQHandler, /* DMA1 Stream 1 */
- DMA1_Stream2_IRQHandler, /* DMA1 Stream 2 */
- DMA1_Stream3_IRQHandler, /* DMA1 Stream 3 */
- DMA1_Stream4_IRQHandler, /* DMA1 Stream 4 */
- DMA1_Stream5_IRQHandler, /* DMA1 Stream 5 */
- DMA1_Stream6_IRQHandler, /* DMA1 Stream 6 */
- ADC_IRQHandler, /* ADC1, ADC2 and ADC3s */
- CAN1_TX_IRQHandler, /* CAN1 TX */
- CAN1_RX0_IRQHandler, /* CAN1 RX0 */
- CAN1_RX1_IRQHandler, /* CAN1 RX1 */
- CAN1_SCE_IRQHandler, /* CAN1 SCE */
- EXTI9_5_IRQHandler, /* External Line[9:5]s */
- TIM1_BRK_TIM9_IRQHandler, /* TIM1 Break and TIM9 */
- TIM1_UP_TIM10_IRQHandler, /* TIM1 Update and TIM10 */
- TIM1_TRG_COM_TIM11_IRQHandler, /* TIM1 Trigger and Commutation and TIM11 */
- TIM1_CC_IRQHandler, /* TIM1 Capture Compare */
- TIM2_IRQHandler, /* TIM2 */
- TIM3_IRQHandler, /* TIM3 */
- TIM4_IRQHandler, /* TIM4 */
- I2C1_EV_IRQHandler, /* I2C1 Event */
- I2C1_ER_IRQHandler, /* I2C1 Error */
- I2C2_EV_IRQHandler, /* I2C2 Event */
- I2C2_ER_IRQHandler, /* I2C2 Error */
- SPI1_IRQHandler, /* SPI1 */
- SPI2_IRQHandler, /* SPI2 */
- USART1_IRQHandler, /* USART1 */
- USART2_IRQHandler, /* USART2 */
- USART3_IRQHandler, /* USART3 */
- EXTI15_10_IRQHandler, /* External Line[15:10]s */
- RTC_Alarm_IRQHandler, /* RTC Alarm (A and B) through EXTI Line */
- OTG_FS_WKUP_IRQHandler, /* USB OTG FS Wakeup through EXTI line */
- TIM8_BRK_TIM12_IRQHandler, /* TIM8 Break and TIM12 */
- TIM8_UP_TIM13_IRQHandler, /* TIM8 Update and TIM13 */
- TIM8_TRG_COM_TIM14_IRQHandler, /* TIM8 Trigger and Commutation and TIM14 */
- TIM8_CC_IRQHandler, /* TIM8 Capture Compare */
- DMA1_Stream7_IRQHandler, /* DMA1 Stream7 */
- FSMC_IRQHandler, /* FSMC */
- SDIO_IRQHandler, /* SDIO */
- TIM5_IRQHandler, /* TIM5 */
- SPI3_IRQHandler, /* SPI3 */
- UART4_IRQHandler, /* UART4 */
- UART5_IRQHandler, /* UART5 */
- TIM6_DAC_IRQHandler, /* TIM6 and DAC1&2 underrun errors */
- TIM7_IRQHandler, /* TIM7 */
- DMA2_Stream0_IRQHandler, /* DMA2 Stream 0 */
- DMA2_Stream1_IRQHandler, /* DMA2 Stream 1 */
- DMA2_Stream2_IRQHandler, /* DMA2 Stream 2 */
- DMA2_Stream3_IRQHandler, /* DMA2 Stream 3 */
- DMA2_Stream4_IRQHandler, /* DMA2 Stream 4 */
- ETH_IRQHandler, /* Ethernet */
- ETH_WKUP_IRQHandler, /* Ethernet Wakeup through EXTI line */
- CAN2_TX_IRQHandler, /* CAN2 TX */
- CAN2_RX0_IRQHandler, /* CAN2 RX0 */
- CAN2_RX1_IRQHandler, /* CAN2 RX1 */
- CAN2_SCE_IRQHandler, /* CAN2 SCE */
- OTG_FS_IRQHandler, /* USB OTG FS */
- DMA2_Stream5_IRQHandler, /* DMA2 Stream 5 */
- DMA2_Stream6_IRQHandler, /* DMA2 Stream 6 */
- DMA2_Stream7_IRQHandler, /* DMA2 Stream 7 */
- USART6_IRQHandler, /* USART6 */
- I2C3_EV_IRQHandler, /* I2C3 event */
- I2C3_ER_IRQHandler, /* I2C3 error */
- OTG_HS_EP1_OUT_IRQHandler, /* USB OTG HS End Point 1 Out */
- OTG_HS_EP1_IN_IRQHandler, /* USB OTG HS End Point 1 In */
- OTG_HS_WKUP_IRQHandler, /* USB OTG HS Wakeup through EXTI */
- OTG_HS_IRQHandler, /* USB OTG HS */
- DCMI_IRQHandler, /* DCMI */
- CRYP_IRQHandler, /* CRYP crypto */
- HASH_RNG_IRQHandler, /* Hash and Rng */
- FPU_IRQHandler, /* FPU */
- UART7_IRQHandler, /* UART7 */
- UART8_IRQHandler, /* UART8 */
- SPI4_IRQHandler, /* SPI4 */
- SPI5_IRQHandler, /* SPI5 */
- SPI6_IRQHandler, /* SPI6 */
- SAI1_IRQHandler, /* SAI1 */
- LTDC_IRQHandler, /* LTDC */
- LTDC_ER_IRQHandler, /* LTDC error */
- DMA2D_IRQHandler /* DMA2D */
-};
-
-
-
-/******************************************************************************
-* END OF FILE
-******************************************************************************/
+/** \file vectors.c
+ * \brief STM32F4x vector table and __Default_Handler()
+ * \details STM32F4x vector table and __Default_Handler()
+ * \author Freddie Chopin, http://www.freddiechopin.info/
+ * \date 2012-03-15
+ */
+
+/******************************************************************************
+* chip: STM32F4x
+* compiler: arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.6.2
+* 20110921 (release) [ARM/embedded-4_6-branch revision 182083]
+******************************************************************************/
+
+/*------------------------------------------------------------------------*/ /**
+* \brief Default interrupt handler.
+* \details Default interrupt handler, used for interrupts that don't have their
+* own handler defined.
+*/ /*-------------------------------------------------------------------------*/
+
+static void __Default_Handler(void) __attribute__((interrupt));
+static void __Default_Handler(void)
+{
+ while (1)
+ ;
+}
+
+/*
++=============================================================================+
+| assign all unhandled interrupts to the default handler
++=============================================================================+
+*/
+
+// Non-maskable interrupt (RCC clock security system)
+void NMI_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// All class of fault
+void HardFault_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Memory management
+void MemManage_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Pre-fetch fault, memory access fault
+void BusFault_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Undefined instruction or illegal state
+void UsageFault_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Reserved 0x1C
+void __Reserved_0x1C_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Reserved 0x20
+void __Reserved_0x20_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Reserved 0x24
+void __Reserved_0x24_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Reserved 0x28
+void __Reserved_0x28_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// System service call via SWI instruction
+void SVC_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Debug monitor
+void DebugMon_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Reserved 0x34
+void __Reserved_0x34_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Pendable request for system service
+void PendSV_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// System tick timer
+void SysTick_Handler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Window WatchDog
+void WWDG_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// PVD through EXTI Line detection
+void PVD_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Tamper and TimeStamps through the EXTI line
+void TAMP_STAMP_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// RTC Wakeup through the EXTI line
+void RTC_WKUP_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// FLASH
+void FLASH_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// RCC
+void RCC_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// EXTI Line0
+void EXTI0_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// EXTI Line1
+void EXTI1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// EXTI Line2
+void EXTI2_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// EXTI Line3
+void EXTI3_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// EXTI Line4
+void EXTI4_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream 0
+void DMA1_Stream0_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream 1
+void DMA1_Stream1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream 2
+void DMA1_Stream2_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream 3
+void DMA1_Stream3_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream 4
+void DMA1_Stream4_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream 5
+void DMA1_Stream5_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream 6
+void DMA1_Stream6_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// ADC1, ADC2 and ADC3s
+void ADC_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN1 TX
+void CAN1_TX_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN1 RX0
+void CAN1_RX0_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN1 RX1
+void CAN1_RX1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN1 SCE
+void CAN1_SCE_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// External Line[9:5]s
+void EXTI9_5_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM1 Break and TIM9
+void TIM1_BRK_TIM9_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM1 Update and TIM10
+void TIM1_UP_TIM10_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM1 Trigger and Commutation and TIM11
+void TIM1_TRG_COM_TIM11_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM1 Capture Compare
+void TIM1_CC_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM2
+void TIM2_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM3
+void TIM3_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM4
+void TIM4_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// I2C1 Event
+void I2C1_EV_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// I2C1 Error
+void I2C1_ER_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// I2C2 Event
+void I2C2_EV_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// I2C2 Error
+void I2C2_ER_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SPI1
+void SPI1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SPI2
+void SPI2_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USART1
+void USART1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USART2
+void USART2_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USART3
+void USART3_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// External Line[15:10]s
+void EXTI15_10_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// RTC Alarm (A and B) through EXTI Line
+void RTC_Alarm_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USB OTG FS Wakeup through EXTI line
+void OTG_FS_WKUP_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM8 Break and TIM12
+void TIM8_BRK_TIM12_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM8 Update and TIM13
+void TIM8_UP_TIM13_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM8 Trigger and Commutation and TIM14
+void TIM8_TRG_COM_TIM14_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM8 Capture Compare
+void TIM8_CC_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA1 Stream7
+void DMA1_Stream7_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// FSMC
+void FSMC_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SDIO
+void SDIO_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM5
+void TIM5_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SPI3
+void SPI3_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// UART4
+void UART4_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// UART5
+void UART5_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM6 and DAC1&2 underrun errors
+void TIM6_DAC_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// TIM7
+void TIM7_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 0
+void DMA2_Stream0_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 1
+void DMA2_Stream1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 2
+void DMA2_Stream2_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 3
+void DMA2_Stream3_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 4
+void DMA2_Stream4_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Ethernet
+void ETH_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Ethernet Wakeup through EXTI line
+void ETH_WKUP_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN2 TX
+void CAN2_TX_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN2 RX0
+void CAN2_RX0_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN2 RX1
+void CAN2_RX1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CAN2 SCE
+void CAN2_SCE_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USB OTG FS
+void OTG_FS_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 5
+void DMA2_Stream5_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 6
+void DMA2_Stream6_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2 Stream 7
+void DMA2_Stream7_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USART6
+void USART6_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// I2C3 event
+void I2C3_EV_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// I2C3 error
+void I2C3_ER_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USB OTG HS End Point 1 Out
+void OTG_HS_EP1_OUT_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USB OTG HS End Point 1 In
+void OTG_HS_EP1_IN_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USB OTG HS Wakeup through EXTI
+void OTG_HS_WKUP_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// USB OTG HS
+void OTG_HS_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DCMI
+void DCMI_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// CRYP crypto
+void CRYP_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// Hash and Rng
+void HASH_RNG_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// FPU
+void FPU_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// UART7
+void UART7_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// UART8
+void UART8_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SPI4
+void SPI4_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SPI5
+void SPI5_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SPI6
+void SPI6_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// SAI1
+void SAI1_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// LTDC
+void LTDC_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// LTDC_ER
+void LTDC_ER_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+// DMA2D
+void DMA2D_IRQHandler(void)
+ __attribute__((interrupt, weak, alias("__Default_Handler")));
+
+/*
++=============================================================================+
+| Vector table
++=============================================================================+
+*/
+
+extern const char
+ __main_stack_end; // imported main stack end (from linker script)
+
+void Reset_Handler(void); // import the address of Reset_Handler()
+
+void (*const vectors[])(void) __attribute__((section(".vectors"))) = {
+ (void (*)(void)) & __main_stack_end, // Main stack end address
+ Reset_Handler, // Reset
+ NMI_Handler, // Non-maskable interrupt (RCC clock security system)
+ HardFault_Handler, // All class of fault
+ MemManage_Handler, // Memory management
+ BusFault_Handler, // Pre-fetch fault, memory access fault
+ UsageFault_Handler, // Undefined instruction or illegal state
+ __Reserved_0x1C_Handler, // Reserved 0x1C
+ __Reserved_0x20_Handler, // Reserved 0x20
+ __Reserved_0x24_Handler, // Reserved 0x24
+ __Reserved_0x28_Handler, // Reserved 0x28
+ SVC_Handler, // System service call via SWI instruction
+ DebugMon_Handler, // Debug monitor
+ __Reserved_0x34_Handler, // Reserved 0x34
+ PendSV_Handler, // Pendable request for system service
+ SysTick_Handler, // System tick timer
+
+ WWDG_IRQHandler, /* Window WatchDog */
+ PVD_IRQHandler, /* PVD through EXTI Line detection */
+ TAMP_STAMP_IRQHandler, /* Tamper and TimeStamps through the EXTI line */
+ RTC_WKUP_IRQHandler, /* RTC Wakeup through the EXTI line */
+ FLASH_IRQHandler, /* FLASH */
+ RCC_IRQHandler, /* RCC */
+ EXTI0_IRQHandler, /* EXTI Line0 */
+ EXTI1_IRQHandler, /* EXTI Line1 */
+ EXTI2_IRQHandler, /* EXTI Line2 */
+ EXTI3_IRQHandler, /* EXTI Line3 */
+ EXTI4_IRQHandler, /* EXTI Line4 */
+ DMA1_Stream0_IRQHandler, /* DMA1 Stream 0 */
+ DMA1_Stream1_IRQHandler, /* DMA1 Stream 1 */
+ DMA1_Stream2_IRQHandler, /* DMA1 Stream 2 */
+ DMA1_Stream3_IRQHandler, /* DMA1 Stream 3 */
+ DMA1_Stream4_IRQHandler, /* DMA1 Stream 4 */
+ DMA1_Stream5_IRQHandler, /* DMA1 Stream 5 */
+ DMA1_Stream6_IRQHandler, /* DMA1 Stream 6 */
+ ADC_IRQHandler, /* ADC1, ADC2 and ADC3s */
+ CAN1_TX_IRQHandler, /* CAN1 TX */
+ CAN1_RX0_IRQHandler, /* CAN1 RX0 */
+ CAN1_RX1_IRQHandler, /* CAN1 RX1 */
+ CAN1_SCE_IRQHandler, /* CAN1 SCE */
+ EXTI9_5_IRQHandler, /* External Line[9:5]s */
+ TIM1_BRK_TIM9_IRQHandler, /* TIM1 Break and TIM9 */
+ TIM1_UP_TIM10_IRQHandler, /* TIM1 Update and TIM10 */
+ TIM1_TRG_COM_TIM11_IRQHandler, /* TIM1 Trigger and Commutation and TIM11 */
+ TIM1_CC_IRQHandler, /* TIM1 Capture Compare */
+ TIM2_IRQHandler, /* TIM2 */
+ TIM3_IRQHandler, /* TIM3 */
+ TIM4_IRQHandler, /* TIM4 */
+ I2C1_EV_IRQHandler, /* I2C1 Event */
+ I2C1_ER_IRQHandler, /* I2C1 Error */
+ I2C2_EV_IRQHandler, /* I2C2 Event */
+ I2C2_ER_IRQHandler, /* I2C2 Error */
+ SPI1_IRQHandler, /* SPI1 */
+ SPI2_IRQHandler, /* SPI2 */
+ USART1_IRQHandler, /* USART1 */
+ USART2_IRQHandler, /* USART2 */
+ USART3_IRQHandler, /* USART3 */
+ EXTI15_10_IRQHandler, /* External Line[15:10]s */
+ RTC_Alarm_IRQHandler, /* RTC Alarm (A and B) through EXTI Line */
+ OTG_FS_WKUP_IRQHandler, /* USB OTG FS Wakeup through EXTI line */
+ TIM8_BRK_TIM12_IRQHandler, /* TIM8 Break and TIM12 */
+ TIM8_UP_TIM13_IRQHandler, /* TIM8 Update and TIM13 */
+ TIM8_TRG_COM_TIM14_IRQHandler, /* TIM8 Trigger and Commutation and TIM14 */
+ TIM8_CC_IRQHandler, /* TIM8 Capture Compare */
+ DMA1_Stream7_IRQHandler, /* DMA1 Stream7 */
+ FSMC_IRQHandler, /* FSMC */
+ SDIO_IRQHandler, /* SDIO */
+ TIM5_IRQHandler, /* TIM5 */
+ SPI3_IRQHandler, /* SPI3 */
+ UART4_IRQHandler, /* UART4 */
+ UART5_IRQHandler, /* UART5 */
+ TIM6_DAC_IRQHandler, /* TIM6 and DAC1&2 underrun errors */
+ TIM7_IRQHandler, /* TIM7 */
+ DMA2_Stream0_IRQHandler, /* DMA2 Stream 0 */
+ DMA2_Stream1_IRQHandler, /* DMA2 Stream 1 */
+ DMA2_Stream2_IRQHandler, /* DMA2 Stream 2 */
+ DMA2_Stream3_IRQHandler, /* DMA2 Stream 3 */
+ DMA2_Stream4_IRQHandler, /* DMA2 Stream 4 */
+ ETH_IRQHandler, /* Ethernet */
+ ETH_WKUP_IRQHandler, /* Ethernet Wakeup through EXTI line */
+ CAN2_TX_IRQHandler, /* CAN2 TX */
+ CAN2_RX0_IRQHandler, /* CAN2 RX0 */
+ CAN2_RX1_IRQHandler, /* CAN2 RX1 */
+ CAN2_SCE_IRQHandler, /* CAN2 SCE */
+ OTG_FS_IRQHandler, /* USB OTG FS */
+ DMA2_Stream5_IRQHandler, /* DMA2 Stream 5 */
+ DMA2_Stream6_IRQHandler, /* DMA2 Stream 6 */
+ DMA2_Stream7_IRQHandler, /* DMA2 Stream 7 */
+ USART6_IRQHandler, /* USART6 */
+ I2C3_EV_IRQHandler, /* I2C3 event */
+ I2C3_ER_IRQHandler, /* I2C3 error */
+ OTG_HS_EP1_OUT_IRQHandler, /* USB OTG HS End Point 1 Out */
+ OTG_HS_EP1_IN_IRQHandler, /* USB OTG HS End Point 1 In */
+ OTG_HS_WKUP_IRQHandler, /* USB OTG HS Wakeup through EXTI */
+ OTG_HS_IRQHandler, /* USB OTG HS */
+ DCMI_IRQHandler, /* DCMI */
+ CRYP_IRQHandler, /* CRYP crypto */
+ HASH_RNG_IRQHandler, /* Hash and Rng */
+ FPU_IRQHandler, /* FPU */
+ UART7_IRQHandler, /* UART7 */
+ UART8_IRQHandler, /* UART8 */
+ SPI4_IRQHandler, /* SPI4 */
+ SPI5_IRQHandler, /* SPI5 */
+ SPI6_IRQHandler, /* SPI6 */
+ SAI1_IRQHandler, /* SAI1 */
+ LTDC_IRQHandler, /* LTDC */
+ LTDC_ER_IRQHandler, /* LTDC error */
+ DMA2D_IRQHandler /* DMA2D */
+};
+
+/******************************************************************************
+* END OF FILE
+******************************************************************************/
--- a/fs_test/CMakeLists.txt
+++ b/fs_test/CMakeLists.txt
@@ -1,12 +1,12 @@
-#fs_test executables
-add_executable(lwext4_server lwext4_server.c)
-target_link_libraries(lwext4_server lwext4)
-target_link_libraries(lwext4_server blockdev)
-if(WIN32)
-target_link_libraries(lwext4_server ws2_32)
-endif(WIN32)
-add_executable(lwext4_client lwext4_client.c)
-target_link_libraries(lwext4_client lwext4)
-if(WIN32)
-target_link_libraries(lwext4_client ws2_32)
-endif(WIN32)
+#fs_test executables
+add_executable(lwext4_server lwext4_server.c)
+target_link_libraries(lwext4_server lwext4)
+target_link_libraries(lwext4_server blockdev)
+if(WIN32)
+target_link_libraries(lwext4_server ws2_32)
+endif(WIN32)
+add_executable(lwext4_client lwext4_client.c)
+target_link_libraries(lwext4_client lwext4)
+if(WIN32)
+target_link_libraries(lwext4_client ws2_32)
+endif(WIN32)
--- a/fs_test/lwext4_client.c
+++ b/fs_test/lwext4_client.c
@@ -1,215 +1,215 @@
-/*
- * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <getopt.h>
-
-#ifdef WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <windows.h>
-static int inet_pton(int af, const char *src, void *dst);
-
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#endif
-
-static int winsock_init(void);
-static void winsock_fini(void);
-
-/**@brief Default server addres.*/
-static char *server_addr = "127.0.0.1";
-
-/**@brief Default connection port.*/
-static int connection_port = 1234;
-
-/**@brief Call op*/
-static char *op_code;
-
-static const char *usage = " \n\
-Welcome in lwext4_client. \n\
-Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com) \n\
-Usage: \n\
- --call (-c) - call opt \n\
- --port (-p) - server port \n\
- --addr (-a) - server ip address \n\
-\n";
-
-static int client_connect(void)
-{
- int fd = 0;
- struct sockaddr_in serv_addr;
-
- if (winsock_init() < 0) {
- printf("winsock_init error\n");
- exit(-1);
- }
-
- memset(&serv_addr, '0', sizeof(serv_addr));
- fd = socket(AF_INET, SOCK_STREAM, 0);
- if (fd < 0) {
- printf("socket() error: %s\n", strerror(errno));
- exit(-1);
- }
-
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons(connection_port);
-
- if (!inet_pton(AF_INET, server_addr, &serv_addr.sin_addr)) {
- printf("inet_pton() error\n");
- exit(-1);
- }
-
- if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) {
- printf("connect() error: %s\n", strerror(errno));
- exit(-1);
- }
-
- return fd;
-}
-
-static bool parse_opt(int argc, char **argv)
-{
- int option_index = 0;
- int c;
-
- static struct option long_options[] = {
- {"call", required_argument, 0, 'c'},
- {"port", required_argument, 0, 'p'},
- {"addr", required_argument, 0, 'a'},
- {0, 0, 0, 0}};
-
- while (-1 != (c = getopt_long(argc, argv, "c:p:a:", long_options,
- &option_index))) {
-
- switch (c) {
- case 'a':
- server_addr = optarg;
- break;
- case 'p':
- connection_port = atoi(optarg);
- break;
- case 'c':
- op_code = optarg;
- break;
- default:
- printf("%s", usage);
- return false;
- }
- }
- return true;
-}
-
-int main(int argc, char *argv[])
-{
- int sockfd;
- int n;
- int rc;
- char recvBuff[1024];
-
- if (!parse_opt(argc, argv))
- return -1;
-
- sockfd = client_connect();
-
- n = send(sockfd, op_code, strlen(op_code), 0);
- if (n < 0) {
- printf("\tWrite error: %s fd = %d\n", strerror(errno), sockfd);
- return -1;
- }
-
- n = recv(sockfd, (void *)&rc, sizeof(rc), 0);
- if (n < 0) {
- printf("\tWrite error: %s fd = %d\n", strerror(errno), sockfd);
- return -1;
- }
-
- printf("rc: %d %s\n", rc, strerror(rc));
- if (rc)
- printf("\t%s\n", op_code);
-
- winsock_fini();
- return rc;
-}
-
-static int winsock_init(void)
-{
-#if WIN32
- int rc;
- static WSADATA wsaData;
- rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (rc != 0) {
- return -1;
- }
-#endif
- return 0;
-}
-
-static void winsock_fini(void)
-{
-#if WIN32
- WSACleanup();
-#endif
-}
-
-#if WIN32
-static int inet_pton(int af, const char *src, void *dst)
-{
- struct sockaddr_storage ss;
- int size = sizeof(ss);
- char src_copy[INET6_ADDRSTRLEN + 1];
-
- ZeroMemory(&ss, sizeof(ss));
- /* stupid non-const API */
- strncpy(src_copy, src, INET6_ADDRSTRLEN + 1);
- src_copy[INET6_ADDRSTRLEN] = 0;
-
- if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss,
- &size) == 0) {
- switch (af) {
- case AF_INET:
- *(struct in_addr *)dst =
- ((struct sockaddr_in *)&ss)->sin_addr;
- return 1;
- case AF_INET6:
- *(struct in6_addr *)dst =
- ((struct sockaddr_in6 *)&ss)->sin6_addr;
- return 1;
- }
- }
- return 0;
-}
-#endif
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <getopt.h>
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+static int inet_pton(int af, const char *src, void *dst);
+
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+#endif
+
+static int winsock_init(void);
+static void winsock_fini(void);
+
+/**@brief Default server addres.*/
+static char *server_addr = "127.0.0.1";
+
+/**@brief Default connection port.*/
+static int connection_port = 1234;
+
+/**@brief Call op*/
+static char *op_code;
+
+static const char *usage = " \n\
+Welcome in lwext4_client. \n\
+Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com) \n\
+Usage: \n\
+ --call (-c) - call opt \n\
+ --port (-p) - server port \n\
+ --addr (-a) - server ip address \n\
+\n";
+
+static int client_connect(void)
+{
+ int fd = 0;
+ struct sockaddr_in serv_addr;
+
+ if (winsock_init() < 0) {
+ printf("winsock_init error\n");
+ exit(-1);
+ }
+
+ memset(&serv_addr, '0', sizeof(serv_addr));
+ fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd < 0) {
+ printf("socket() error: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_port = htons(connection_port);
+
+ if (!inet_pton(AF_INET, server_addr, &serv_addr.sin_addr)) {
+ printf("inet_pton() error\n");
+ exit(-1);
+ }
+
+ if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) {
+ printf("connect() error: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ return fd;
+}
+
+static bool parse_opt(int argc, char **argv)
+{
+ int option_index = 0;
+ int c;
+
+ static struct option long_options[] = {
+ {"call", required_argument, 0, 'c'},
+ {"port", required_argument, 0, 'p'},
+ {"addr", required_argument, 0, 'a'},
+ {0, 0, 0, 0}};
+
+ while (-1 != (c = getopt_long(argc, argv, "c:p:a:", long_options,
+ &option_index))) {
+
+ switch (c) {
+ case 'a':
+ server_addr = optarg;
+ break;
+ case 'p':
+ connection_port = atoi(optarg);
+ break;
+ case 'c':
+ op_code = optarg;
+ break;
+ default:
+ printf("%s", usage);
+ return false;
+ }
+ }
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ int sockfd;
+ int n;
+ int rc;
+ char recvBuff[1024];
+
+ if (!parse_opt(argc, argv))
+ return -1;
+
+ sockfd = client_connect();
+
+ n = send(sockfd, op_code, strlen(op_code), 0);
+ if (n < 0) {
+ printf("\tWrite error: %s fd = %d\n", strerror(errno), sockfd);
+ return -1;
+ }
+
+ n = recv(sockfd, (void *)&rc, sizeof(rc), 0);
+ if (n < 0) {
+ printf("\tWrite error: %s fd = %d\n", strerror(errno), sockfd);
+ return -1;
+ }
+
+ printf("rc: %d %s\n", rc, strerror(rc));
+ if (rc)
+ printf("\t%s\n", op_code);
+
+ winsock_fini();
+ return rc;
+}
+
+static int winsock_init(void)
+{
+#if WIN32
+ int rc;
+ static WSADATA wsaData;
+ rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
+ if (rc != 0) {
+ return -1;
+ }
+#endif
+ return 0;
+}
+
+static void winsock_fini(void)
+{
+#if WIN32
+ WSACleanup();
+#endif
+}
+
+#if WIN32
+static int inet_pton(int af, const char *src, void *dst)
+{
+ struct sockaddr_storage ss;
+ int size = sizeof(ss);
+ char src_copy[INET6_ADDRSTRLEN + 1];
+
+ ZeroMemory(&ss, sizeof(ss));
+ /* stupid non-const API */
+ strncpy(src_copy, src, INET6_ADDRSTRLEN + 1);
+ src_copy[INET6_ADDRSTRLEN] = 0;
+
+ if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss,
+ &size) == 0) {
+ switch (af) {
+ case AF_INET:
+ *(struct in_addr *)dst =
+ ((struct sockaddr_in *)&ss)->sin_addr;
+ return 1;
+ case AF_INET6:
+ *(struct in6_addr *)dst =
+ ((struct sockaddr_in6 *)&ss)->sin6_addr;
+ return 1;
+ }
+ }
+ return 0;
+}
+#endif
--- a/fs_test/lwext4_server.c
+++ b/fs_test/lwext4_server.c
@@ -1,1145 +1,1145 @@
-/*
- * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <getopt.h>
-#include <time.h>
-#include <sys/time.h>
-
-#ifdef WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <windows.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#endif
-
-#include <ext4_filedev.h>
-#include <io_raw.h>
-
-#include <ext4.h>
-#include <errno.h>
-
-static int winsock_init(void);
-static void winsock_fini(void);
-static char *entry_to_str(uint8_t type);
-
-#define MAX_FILES 64
-#define MAX_DIRS 64
-
-#define MAX_RW_BUFFER (1024 * 1024)
-#define RW_BUFFER_PATERN ('x')
-
-/**@brief Default connection port*/
-static int connection_port = 1234;
-
-/**@brief Default filesystem filename.*/
-static char *ext4_fname = "ext2";
-
-/**@brief Verbose mode*/
-static int verbose = 0;
-
-/**@brief Winpart mode*/
-static int winpart = 0;
-
-/**@brief Blockdev handle*/
-static struct ext4_blockdev *bd;
-
-static int cache_wb = 0;
-
-static char read_buffer[MAX_RW_BUFFER];
-static char write_buffer[MAX_RW_BUFFER];
-
-static const char *usage = " \n\
-Welcome in lwext4_server. \n\
-Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com) \n\
-Usage: \n\
- --image (-i) - ext2/3/4 image file \n\
- --port (-p) - server port \n\
- --verbose (-v) - verbose mode \n\
- --winpart (-w) - windows_partition mode \n\
- --cache_wb (-c) - cache writeback_mode \n\
-\n";
-
-/**@brief Open file instance descriptor.*/
-struct lwext4_files {
- char name[255];
- ext4_file fd;
-};
-
-/**@brief Open directory instance descriptor.*/
-struct lwext4_dirs {
- char name[255];
- ext4_dir fd;
-};
-
-/**@brief Library call opcode.*/
-struct lwext4_op_codes {
- char *func;
-};
-
-/**@brief Library call wraper.*/
-struct lwext4_call {
- int (*lwext4_call)(char *p);
-};
-
-/**@brief */
-static struct lwext4_files file_tab[MAX_FILES];
-
-/**@brief */
-static struct lwext4_dirs dir_tab[MAX_DIRS];
-
-/**@brief */
-static struct lwext4_op_codes op_codes[] = {
- "device_register",
- "mount",
- "umount",
- "mount_point_stats",
- "cache_write_back",
- "fremove",
- "fopen",
- "fclose",
- "fread",
- "fwrite",
- "fseek",
- "ftell",
- "fsize",
- "dir_rm",
- "dir_mk",
- "dir_open",
- "dir_close",
- "dir_entry_get",
-
- "multi_fcreate",
- "multi_fwrite",
- "multi_fread",
- "multi_fremove",
- "multi_dcreate",
- "multi_dremove",
- "stats_save",
- "stats_check",
-};
-
-int _device_register(char *p);
-int _mount(char *p);
-int _umount(char *p);
-int _mount_point_stats(char *p);
-int _cache_write_back(char *p);
-int _fremove(char *p);
-int _fopen(char *p);
-int _fclose(char *p);
-int _fread(char *p);
-int _fwrite(char *p);
-int _fseek(char *p);
-int _ftell(char *p);
-int _fsize(char *p);
-int _dir_rm(char *p);
-int _dir_mk(char *p);
-int _dir_open(char *p);
-int _dir_close(char *p);
-int _dir_close(char *p);
-int _dir_entry_get(char *p);
-
-int _multi_fcreate(char *p);
-int _multi_fwrite(char *p);
-int _multi_fread(char *p);
-int _multi_fremove(char *p);
-int _multi_dcreate(char *p);
-int _multi_dremove(char *p);
-int _stats_save(char *p);
-int _stats_check(char *p);
-
-/**@brief */
-static struct lwext4_call op_call[] = {
- _device_register, /*PARAMS(3): 0 cache_mode dev_name */
- _mount, /*PARAMS(2): dev_name mount_point */
- _umount, /*PARAMS(1): mount_point */
- _mount_point_stats, /*PARAMS(2): mount_point, 0 */
- _cache_write_back, /*PARAMS(2): mount_point, en */
- _fremove, /*PARAMS(1): path */
- _fopen, /*PARAMS(2): fid path flags */
- _fclose, /*PARAMS(1): fid */
- _fread, /*PARAMS(4): fid 0 len 0 */
- _fwrite, /*PARAMS(4): fid 0 len 0 */
- _fseek, /*PARAMS(2): fid off origin */
- _ftell, /*PARAMS(2): fid exp */
- _fsize, /*PARAMS(2): fid exp */
- _dir_rm, /*PARAMS(1): path */
- _dir_mk, /*PARAMS(1): path */
- _dir_open, /*PARAMS(2): did, path */
- _dir_close, /*PARAMS(1): did */
- _dir_entry_get, /*PARAMS(2): did, exp */
-
- _multi_fcreate, /*PARAMS(3): path prefix cnt */
- _multi_fwrite, /*PARAMS(4): path prefix cnt size */
- _multi_fread, /*PARAMS(4): path prefix cnt size */
- _multi_fremove, /*PARAMS(2): path prefix cnt */
- _multi_dcreate, /*PARAMS(3): path prefix cnt */
- _multi_dremove, /*PARAMS(2): path prefix */
- _stats_save, /*PARAMS(1): path */
- _stats_check, /*PARAMS(1): path */
-};
-
-static clock_t get_ms(void)
-{
- struct timeval t;
- gettimeofday(&t, NULL);
- return (t.tv_sec * 1000) + (t.tv_usec / 1000);
-}
-
-/**@brief */
-static int exec_op_code(char *opcode)
-{
- int i;
- int r = -1;
-
- for (i = 0; i < sizeof(op_codes) / sizeof(op_codes[0]); ++i) {
-
- if (strncmp(op_codes[i].func, opcode, strlen(op_codes[i].func)))
- continue;
-
- if (opcode[strlen(op_codes[i].func)] != ' ')
- continue;
-
- printf("%s\n", opcode);
- opcode += strlen(op_codes[i].func);
- /*Call*/
-
- clock_t t = get_ms();
- r = op_call[i].lwext4_call(opcode);
-
- printf("rc: %d, time: %ums\n", r, (unsigned int)(get_ms() - t));
-
- break;
- }
-
- return r;
-}
-
-static int server_open(void)
-{
- int fd = 0;
- struct sockaddr_in serv_addr;
-
- memset(&serv_addr, 0, sizeof(serv_addr));
-
- if (winsock_init() < 0) {
- printf("winsock_init() error\n");
- exit(-1);
- }
-
- fd = socket(AF_INET, SOCK_STREAM, 0);
- if (fd < 0) {
- printf("socket() error: %s\n", strerror(errno));
- exit(-1);
- }
-
- int yes = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes,
- sizeof(int))) {
- printf("setsockopt() error: %s\n", strerror(errno));
- exit(-1);
- }
-
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(connection_port);
-
- if (bind(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) {
- printf("bind() error: %s\n", strerror(errno));
- exit(-1);
- }
-
- if (listen(fd, 1)) {
- printf("listen() error: %s\n", strerror(errno));
- exit(-1);
- }
-
- return fd;
-}
-
-static bool parse_opt(int argc, char **argv)
-{
- int option_index = 0;
- int c;
-
- static struct option long_options[] = {
- {"image", required_argument, 0, 'i'},
- {"port", required_argument, 0, 'p'},
- {"verbose", required_argument, 0, 'v'},
- {"winpart", required_argument, 0, 'w'},
- {"cache_wb", required_argument, 0, 'c'},
- {0, 0, 0, 0}};
-
- while (-1 != (c = getopt_long(argc, argv, "c:i:p:v:w:", long_options,
- &option_index))) {
-
- switch (c) {
- case 'i':
- ext4_fname = optarg;
- break;
- case 'p':
- connection_port = atoi(optarg);
- break;
- case 'v':
- verbose = atoi(optarg);
- break;
- case 'c':
- cache_wb = atoi(optarg);
- break;
- case 'w':
- winpart = atoi(optarg);
- break;
- default:
- printf("%s", usage);
- return false;
- }
- }
- return true;
-}
-
-int main(int argc, char *argv[])
-{
- int n;
- int listenfd;
- int connfd;
- char op_code[128];
-
- if (!parse_opt(argc, argv))
- return -1;
-
- listenfd = server_open();
-
- printf("lwext4_server: listening on port: %d\n", connection_port);
-
- memset(write_buffer, RW_BUFFER_PATERN, MAX_RW_BUFFER);
- while (1) {
- connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
-
- n = recv(connfd, op_code, sizeof(op_code), 0);
-
- if (n < 0) {
- printf("recv() error: %s fd = %d\n", strerror(errno),
- connfd);
- break;
- }
-
- op_code[n] = 0;
-
- int r = exec_op_code(op_code);
-
- n = send(connfd, (void *)&r, sizeof(r), 0);
- if (n < 0) {
- printf("send() error: %s fd = %d\n", strerror(errno),
- connfd);
- break;
- }
-
- close(connfd);
- }
-
- winsock_fini();
- return 0;
-}
-
-int _device_register(char *p)
-{
- int dev;
- int cache_mode;
- char dev_name[32];
-
- if (sscanf(p, "%d %d %s", &dev, &cache_mode, dev_name) != 3) {
- printf("Param list error\n");
- return -1;
- }
-
-#ifdef WIN32
- if (winpart) {
- ext4_io_raw_filename(ext4_fname);
- bd = ext4_io_raw_dev_get();
-
- } else
-#endif
- {
- ext4_filedev_filename(ext4_fname);
- bd = ext4_filedev_get();
- }
- return ext4_device_register(bd, 0, dev_name);
-}
-
-int _mount(char *p)
-{
- char dev_name[32];
- char mount_point[32];
- int rc;
-
- if (sscanf(p, "%s %s", dev_name, mount_point) != 2) {
- printf("Param list error\n");
- return -1;
- }
-
- rc = ext4_mount(dev_name, mount_point);
- if (cache_wb)
- ext4_cache_write_back(mount_point, 1);
- return rc;
-}
-
-int _umount(char *p)
-{
- char mount_point[32];
-
- if (sscanf(p, "%s", mount_point) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- if (cache_wb)
- ext4_cache_write_back(mount_point, 0);
-
- return ext4_umount(mount_point);
-}
-
-int _mount_point_stats(char *p)
-{
- char mount_point[32];
- int d;
- int rc;
- struct ext4_mount_stats stats;
-
- if (sscanf(p, "%s %d", mount_point, &d) != 2) {
- printf("Param list error\n");
- return -1;
- }
-
- rc = ext4_mount_point_stats(mount_point, &stats);
-
- if (rc != EOK)
- return rc;
-
- if (verbose) {
- printf("\tinodes_count = %d\n", stats.inodes_count);
- printf("\tfree_inodes_count = %d\n", stats.free_inodes_count);
- printf("\tblocks_count = %llu\n", stats.blocks_count);
- printf("\tfree_blocks_count = %llu\n", stats.free_blocks_count);
-
- printf("\tblock_size = %d\n", stats.block_size);
- printf("\tblock_group_count = %d\n", stats.block_group_count);
- printf("\tblocks_per_group = %d\n", stats.blocks_per_group);
- printf("\tinodes_per_group = %d\n", stats.inodes_per_group);
-
- printf("\tvolume_name = %s\n", stats.volume_name);
- }
-
- return rc;
-}
-
-int _cache_write_back(char *p)
-{
- char mount_point[32];
- int en;
-
- if (sscanf(p, "%s %d", mount_point, &en) != 2) {
- printf("Param list error\n");
- return -1;
- }
-
- return ext4_cache_write_back(mount_point, en);
-}
-
-int _fremove(char *p)
-{
- char path[255];
-
- if (sscanf(p, "%s", path) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- return ext4_fremove(path);
-}
-
-int _fopen(char *p)
-{
- int fid = MAX_FILES;
- char path[256];
- char flags[8];
- int rc;
-
- if (sscanf(p, "%d %s %s", &fid, path, flags) != 3) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(fid < MAX_FILES)) {
- printf("File id too big\n");
- return -1;
- }
-
- rc = ext4_fopen(&file_tab[fid].fd, path, flags);
-
- if (rc == EOK)
- strcpy(file_tab[fid].name, path);
-
- return rc;
-}
-
-int _fclose(char *p)
-{
- int fid = MAX_FILES;
- int rc;
-
- if (sscanf(p, "%d", &fid) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(fid < MAX_FILES)) {
- printf("File id too big\n");
- return -1;
- }
-
- if (file_tab[fid].name[0] == 0) {
- printf("File id empty\n");
- return -1;
- }
-
- rc = ext4_fclose(&file_tab[fid].fd);
-
- if (rc == EOK)
- file_tab[fid].name[0] = 0;
-
- return rc;
-}
-
-int _fread(char *p)
-{
- int fid = MAX_FILES;
- int len;
- int d;
- int rc;
- size_t rb;
-
- if (sscanf(p, "%d %d %d %d", &fid, &d, &len, &d) != 4) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(fid < MAX_FILES)) {
- printf("File id too big\n");
- return -1;
- }
-
- if (file_tab[fid].name[0] == 0) {
- printf("File id empty\n");
- return -1;
- }
-
- while (len) {
- d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
-
- memset(read_buffer, 0, MAX_RW_BUFFER);
- rc = ext4_fread(&file_tab[fid].fd, read_buffer, d, &rb);
-
- if (rc != EOK)
- break;
-
- if (rb != d) {
- printf("Read count error\n");
- return -1;
- }
-
- if (memcmp(read_buffer, write_buffer, d)) {
- printf("Read compare error\n");
- return -1;
- }
-
- len -= d;
- }
-
- return rc;
-}
-
-int _fwrite(char *p)
-{
- int fid = MAX_FILES;
- int d;
- int rc;
-
- size_t len;
- size_t wb;
-
- if (sscanf(p, "%d %d %d %d", &fid, &d, &len, &d) != 4) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(fid < MAX_FILES)) {
- printf("File id too big\n");
- return -1;
- }
-
- if (file_tab[fid].name[0] == 0) {
- printf("File id empty\n");
- return -1;
- }
-
- while (len) {
- d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
- rc = ext4_fwrite(&file_tab[fid].fd, write_buffer, d, &wb);
-
- if (rc != EOK)
- break;
-
- if (wb != d) {
- printf("Write count error\n");
- return -1;
- }
-
- len -= d;
- }
-
- return rc;
-}
-
-int _fseek(char *p)
-{
- int fid = MAX_FILES;
- int off;
- int origin;
-
- if (sscanf(p, "%d %d %d", &fid, &off, &origin) != 3) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(fid < MAX_FILES)) {
- printf("File id too big\n");
- return -1;
- }
-
- if (file_tab[fid].name[0] == 0) {
- printf("File id empty\n");
- return -1;
- }
-
- return ext4_fseek(&file_tab[fid].fd, off, origin);
-}
-
-int _ftell(char *p)
-{
- int fid = MAX_FILES;
- uint32_t exp_pos;
-
- if (sscanf(p, "%d %u", &fid, &exp_pos) != 2) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(fid < MAX_FILES)) {
- printf("File id too big\n");
- return -1;
- }
-
- if (file_tab[fid].name[0] == 0) {
- printf("File id empty\n");
- return -1;
- }
-
- if (exp_pos != ext4_ftell(&file_tab[fid].fd)) {
- printf("Expected filepos error\n");
- return -1;
- }
-
- return EOK;
-}
-
-int _fsize(char *p)
-{
- int fid = MAX_FILES;
- uint32_t exp_size;
-
- if (sscanf(p, "%d %u", &fid, &exp_size) != 2) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(fid < MAX_FILES)) {
- printf("File id too big\n");
- return -1;
- }
-
- if (file_tab[fid].name[0] == 0) {
- printf("File id empty\n");
- return -1;
- }
-
- if (exp_size != ext4_fsize(&file_tab[fid].fd)) {
- printf("Expected filesize error\n");
- return -1;
- }
-
- return EOK;
-}
-
-int _dir_rm(char *p)
-{
- char path[255];
-
- if (sscanf(p, "%s", path) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- return ext4_dir_rm(path);
-}
-
-int _dir_mk(char *p)
-{
- char path[255];
-
- if (sscanf(p, "%s", path) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- return ext4_dir_mk(path);
-}
-
-int _dir_open(char *p)
-{
- int did = MAX_DIRS;
- char path[255];
- int rc;
-
- if (sscanf(p, "%d %s", &did, path) != 2) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(did < MAX_DIRS)) {
- printf("Dir id too big\n");
- return -1;
- }
-
- rc = ext4_dir_open(&dir_tab[did].fd, path);
-
- if (rc == EOK)
- strcpy(dir_tab[did].name, path);
-
- return rc;
-}
-
-int _dir_close(char *p)
-{
- int did = MAX_DIRS;
- int rc;
-
- if (sscanf(p, "%d", &did) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(did < MAX_DIRS)) {
- printf("Dir id too big\n");
- return -1;
- }
-
- if (dir_tab[did].name[0] == 0) {
- printf("Dir id empty\n");
- return -1;
- }
-
- rc = ext4_dir_close(&dir_tab[did].fd);
-
- if (rc == EOK)
- dir_tab[did].name[0] = 0;
-
- return rc;
-}
-
-int _dir_entry_get(char *p)
-{
- int did = MAX_DIRS;
- int exp;
- char name[256];
-
- if (sscanf(p, "%d %d", &did, &exp) != 2) {
- printf("Param list error\n");
- return -1;
- }
-
- if (!(did < MAX_DIRS)) {
- printf("Dir id too big\n");
- return -1;
- }
-
- if (dir_tab[did].name[0] == 0) {
- printf("Dir id empty\n");
- return -1;
- }
-
- int idx = 0;
- const ext4_direntry *d;
-
- while ((d = ext4_dir_entry_next(&dir_tab[did].fd)) != NULL) {
-
- idx++;
- memcpy(name, d->name, d->name_length);
- name[d->name_length] = 0;
- if (verbose) {
- printf("\t%s %s\n", entry_to_str(d->inode_type), name);
- }
- }
-
- if (idx < 2) {
- printf("Minumum dir entry error\n");
- return -1;
- }
-
- if ((idx - 2) != exp) {
- printf("Expected dir entry error\n");
- return -1;
- }
-
- return EOK;
-}
-
-int _multi_fcreate(char *p)
-{
- char path[256];
- char path1[256];
- char prefix[32];
- int cnt;
- int rc;
- int i;
- ext4_file fd;
-
- if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
- printf("Param list error\n");
- return -1;
- }
-
- for (i = 0; i < cnt; ++i) {
- sprintf(path1, "%s%s%d", path, prefix, i);
- rc = ext4_fopen(&fd, path1, "wb+");
-
- if (rc != EOK)
- break;
- }
-
- return rc;
-}
-
-int _multi_fwrite(char *p)
-{
- char path[256];
- char path1[256];
- char prefix[32];
- int cnt, i;
- int len, ll;
- int rc;
- size_t d, wb;
- ext4_file fd;
-
- if (sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4) {
- printf("Param list error\n");
- return -1;
- }
-
- for (i = 0; i < cnt; ++i) {
- sprintf(path1, "%s%s%d", path, prefix, i);
- rc = ext4_fopen(&fd, path1, "rb+");
-
- if (rc != EOK)
- break;
-
- len = ll;
- while (len) {
- d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
- rc = ext4_fwrite(&fd, write_buffer, d, &wb);
-
- if (rc != EOK)
- break;
-
- if (wb != d) {
- printf("Write count error\n");
- return -1;
- }
-
- len -= d;
- }
- }
-
- return rc;
-}
-
-int _multi_fread(char *p)
-{
- char path[256];
- char path1[256];
- char prefix[32];
- int cnt;
- int len, ll;
- int rc ,i, d;
- size_t rb;
- ext4_file fd;
-
- if (sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4) {
- printf("Param list error\n");
- return -1;
- }
-
- for (i = 0; i < cnt; ++i) {
- sprintf(path1, "%s%s%d", path, prefix, i);
- rc = ext4_fopen(&fd, path1, "rb+");
-
- if (rc != EOK)
- break;
-
- len = ll;
- while (len) {
- d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
-
- memset(read_buffer, 0, MAX_RW_BUFFER);
- rc = ext4_fread(&fd, read_buffer, d, &rb);
-
- if (rc != EOK)
- break;
-
- if (rb != d) {
- printf("Read count error\n");
- return -1;
- }
-
- if (memcmp(read_buffer, write_buffer, d)) {
- printf("Read compare error\n");
- return -1;
- }
-
- len -= d;
- }
- }
-
- return rc;
-}
-
-int _multi_fremove(char *p)
-{
- char path[256];
- char path1[256];
- char prefix[32];
- int cnt, i, rc;
-
- if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
- printf("Param list error\n");
- return -1;
- }
-
- for (i = 0; i < cnt; ++i) {
- sprintf(path1, "%s%s%d", path, prefix, i);
- rc = ext4_fremove(path1);
- if (rc != EOK)
- break;
- }
-
- return rc;
-}
-
-int _multi_dcreate(char *p)
-{
- char path[256];
- char path1[256];
- char prefix[32];
- int cnt, i, rc;
-
- if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
- printf("Param list error\n");
- return -1;
- }
-
- for (i = 0; i < cnt; ++i) {
- sprintf(path1, "%s%s%d", path, prefix, i);
- rc = ext4_dir_mk(path1);
- if (rc != EOK)
- break;
- }
-
- return rc;
-}
-
-int _multi_dremove(char *p)
-{
- char path[256];
- char path1[256];
- char prefix[32];
- int cnt, i, rc;
-
- if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
- printf("Param list error\n");
- return -1;
- }
-
- for (i = 0; i < cnt; ++i) {
- sprintf(path1, "%s%s%d", path, prefix, i);
- rc = ext4_dir_rm(path1);
- if (rc != EOK)
- break;
- }
-
- return rc;
-}
-
-struct ext4_mount_stats saved_stats;
-
-int _stats_save(char *p)
-{
- char path[256];
-
- if (sscanf(p, "%s", path) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- return ext4_mount_point_stats(path, &saved_stats);
-}
-
-int _stats_check(char *p)
-{
- char path[256];
- int rc;
-
- struct ext4_mount_stats actual_stats;
-
- if (sscanf(p, "%s", path) != 1) {
- printf("Param list error\n");
- return -1;
- }
-
- rc = ext4_mount_point_stats(path, &actual_stats);
-
- if (rc != EOK)
- return rc;
-
- if (memcmp(&saved_stats, &actual_stats,
- sizeof(struct ext4_mount_stats))) {
- if (verbose) {
- printf("\tMount point stats error:\n");
- printf("\tsaved_stats:\n");
- printf("\tinodes_count = %d\n",
- saved_stats.inodes_count);
- printf("\tfree_inodes_count = %d\n",
- saved_stats.free_inodes_count);
- printf("\tblocks_count = %llu\n",
- saved_stats.blocks_count);
- printf("\tfree_blocks_count = %llu\n",
- saved_stats.free_blocks_count);
- printf("\tblock_size = %d\n", saved_stats.block_size);
- printf("\tblock_group_count = %d\n",
- saved_stats.block_group_count);
- printf("\tblocks_per_group = %d\n",
- saved_stats.blocks_per_group);
- printf("\tinodes_per_group = %d\n",
- saved_stats.inodes_per_group);
- printf("\tvolume_name = %s\n", saved_stats.volume_name);
- printf("\tactual_stats:\n");
- printf("\tinodes_count = %d\n",
- actual_stats.inodes_count);
- printf("\tfree_inodes_count = %d\n",
- actual_stats.free_inodes_count);
- printf("\tblocks_count = %llu\n",
- actual_stats.blocks_count);
- printf("\tfree_blocks_count = %llu\n",
- actual_stats.free_blocks_count);
- printf("\tblock_size = %d\n", actual_stats.block_size);
- printf("\tblock_group_count = %d\n",
- actual_stats.block_group_count);
- printf("\tblocks_per_group = %d\n",
- actual_stats.blocks_per_group);
- printf("\tinodes_per_group = %d\n",
- actual_stats.inodes_per_group);
- printf("\tvolume_name = %s\n",
- actual_stats.volume_name);
- }
- return -1;
- }
-
- return rc;
-}
-
-static char *entry_to_str(uint8_t type)
-{
- switch (type) {
- case EXT4_DIRENTRY_UNKNOWN:
- return "[UNK] ";
- case EXT4_DIRENTRY_REG_FILE:
- return "[FIL] ";
- case EXT4_DIRENTRY_DIR:
- return "[DIR] ";
- case EXT4_DIRENTRY_CHRDEV:
- return "[CHA] ";
- case EXT4_DIRENTRY_BLKDEV:
- return "[BLK] ";
- case EXT4_DIRENTRY_FIFO:
- return "[FIF] ";
- case EXT4_DIRENTRY_SOCK:
- return "[SOC] ";
- case EXT4_DIRENTRY_SYMLINK:
- return "[SYM] ";
- default:
- break;
- }
- return "[???]";
-}
-
-static int winsock_init(void)
-{
-#if WIN32
- int rc;
- static WSADATA wsaData;
- rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (rc != 0) {
- return -1;
- }
-#endif
- return 0;
-}
-
-static void winsock_fini(void)
-{
-#if WIN32
- WSACleanup();
-#endif
-}
+/*
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <getopt.h>
+#include <time.h>
+#include <sys/time.h>
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+#endif
+
+#include "../blockdev/linux/ext4_filedev.h"
+#include "../blockdev/windows/io_raw.h"
+
+#include <ext4.h>
+#include <errno.h>
+
+static int winsock_init(void);
+static void winsock_fini(void);
+static char *entry_to_str(uint8_t type);
+
+#define MAX_FILES 64
+#define MAX_DIRS 64
+
+#define MAX_RW_BUFFER (1024 * 1024)
+#define RW_BUFFER_PATERN ('x')
+
+/**@brief Default connection port*/
+static int connection_port = 1234;
+
+/**@brief Default filesystem filename.*/
+static char *ext4_fname = "ext2";
+
+/**@brief Verbose mode*/
+static int verbose = 0;
+
+/**@brief Winpart mode*/
+static int winpart = 0;
+
+/**@brief Blockdev handle*/
+static struct ext4_blockdev *bd;
+
+static int cache_wb = 0;
+
+static char read_buffer[MAX_RW_BUFFER];
+static char write_buffer[MAX_RW_BUFFER];
+
+static const char *usage = " \n\
+Welcome in lwext4_server. \n\
+Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com) \n\
+Usage: \n\
+ --image (-i) - ext2/3/4 image file \n\
+ --port (-p) - server port \n\
+ --verbose (-v) - verbose mode \n\
+ --winpart (-w) - windows_partition mode \n\
+ --cache_wb (-c) - cache writeback_mode \n\
+\n";
+
+/**@brief Open file instance descriptor.*/
+struct lwext4_files {
+ char name[255];
+ ext4_file fd;
+};
+
+/**@brief Open directory instance descriptor.*/
+struct lwext4_dirs {
+ char name[255];
+ ext4_dir fd;
+};
+
+/**@brief Library call opcode.*/
+struct lwext4_op_codes {
+ char *func;
+};
+
+/**@brief Library call wraper.*/
+struct lwext4_call {
+ int (*lwext4_call)(char *p);
+};
+
+/**@brief */
+static struct lwext4_files file_tab[MAX_FILES];
+
+/**@brief */
+static struct lwext4_dirs dir_tab[MAX_DIRS];
+
+/**@brief */
+static struct lwext4_op_codes op_codes[] = {
+ "device_register",
+ "mount",
+ "umount",
+ "mount_point_stats",
+ "cache_write_back",
+ "fremove",
+ "fopen",
+ "fclose",
+ "fread",
+ "fwrite",
+ "fseek",
+ "ftell",
+ "fsize",
+ "dir_rm",
+ "dir_mk",
+ "dir_open",
+ "dir_close",
+ "dir_entry_get",
+
+ "multi_fcreate",
+ "multi_fwrite",
+ "multi_fread",
+ "multi_fremove",
+ "multi_dcreate",
+ "multi_dremove",
+ "stats_save",
+ "stats_check",
+};
+
+int _device_register(char *p);
+int _mount(char *p);
+int _umount(char *p);
+int _mount_point_stats(char *p);
+int _cache_write_back(char *p);
+int _fremove(char *p);
+int _fopen(char *p);
+int _fclose(char *p);
+int _fread(char *p);
+int _fwrite(char *p);
+int _fseek(char *p);
+int _ftell(char *p);
+int _fsize(char *p);
+int _dir_rm(char *p);
+int _dir_mk(char *p);
+int _dir_open(char *p);
+int _dir_close(char *p);
+int _dir_close(char *p);
+int _dir_entry_get(char *p);
+
+int _multi_fcreate(char *p);
+int _multi_fwrite(char *p);
+int _multi_fread(char *p);
+int _multi_fremove(char *p);
+int _multi_dcreate(char *p);
+int _multi_dremove(char *p);
+int _stats_save(char *p);
+int _stats_check(char *p);
+
+/**@brief */
+static struct lwext4_call op_call[] = {
+ _device_register, /*PARAMS(3): 0 cache_mode dev_name */
+ _mount, /*PARAMS(2): dev_name mount_point */
+ _umount, /*PARAMS(1): mount_point */
+ _mount_point_stats, /*PARAMS(2): mount_point, 0 */
+ _cache_write_back, /*PARAMS(2): mount_point, en */
+ _fremove, /*PARAMS(1): path */
+ _fopen, /*PARAMS(2): fid path flags */
+ _fclose, /*PARAMS(1): fid */
+ _fread, /*PARAMS(4): fid 0 len 0 */
+ _fwrite, /*PARAMS(4): fid 0 len 0 */
+ _fseek, /*PARAMS(2): fid off origin */
+ _ftell, /*PARAMS(2): fid exp */
+ _fsize, /*PARAMS(2): fid exp */
+ _dir_rm, /*PARAMS(1): path */
+ _dir_mk, /*PARAMS(1): path */
+ _dir_open, /*PARAMS(2): did, path */
+ _dir_close, /*PARAMS(1): did */
+ _dir_entry_get, /*PARAMS(2): did, exp */
+
+ _multi_fcreate, /*PARAMS(3): path prefix cnt */
+ _multi_fwrite, /*PARAMS(4): path prefix cnt size */
+ _multi_fread, /*PARAMS(4): path prefix cnt size */
+ _multi_fremove, /*PARAMS(2): path prefix cnt */
+ _multi_dcreate, /*PARAMS(3): path prefix cnt */
+ _multi_dremove, /*PARAMS(2): path prefix */
+ _stats_save, /*PARAMS(1): path */
+ _stats_check, /*PARAMS(1): path */
+};
+
+static clock_t get_ms(void)
+{
+ struct timeval t;
+ gettimeofday(&t, NULL);
+ return (t.tv_sec * 1000) + (t.tv_usec / 1000);
+}
+
+/**@brief */
+static int exec_op_code(char *opcode)
+{
+ int i;
+ int r = -1;
+
+ for (i = 0; i < sizeof(op_codes) / sizeof(op_codes[0]); ++i) {
+
+ if (strncmp(op_codes[i].func, opcode, strlen(op_codes[i].func)))
+ continue;
+
+ if (opcode[strlen(op_codes[i].func)] != ' ')
+ continue;
+
+ printf("%s\n", opcode);
+ opcode += strlen(op_codes[i].func);
+ /*Call*/
+
+ clock_t t = get_ms();
+ r = op_call[i].lwext4_call(opcode);
+
+ printf("rc: %d, time: %ums\n", r, (unsigned int)(get_ms() - t));
+
+ break;
+ }
+
+ return r;
+}
+
+static int server_open(void)
+{
+ int fd = 0;
+ struct sockaddr_in serv_addr;
+
+ memset(&serv_addr, 0, sizeof(serv_addr));
+
+ if (winsock_init() < 0) {
+ printf("winsock_init() error\n");
+ exit(-1);
+ }
+
+ fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd < 0) {
+ printf("socket() error: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ int yes = 1;
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes,
+ sizeof(int))) {
+ printf("setsockopt() error: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serv_addr.sin_port = htons(connection_port);
+
+ if (bind(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) {
+ printf("bind() error: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ if (listen(fd, 1)) {
+ printf("listen() error: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ return fd;
+}
+
+static bool parse_opt(int argc, char **argv)
+{
+ int option_index = 0;
+ int c;
+
+ static struct option long_options[] = {
+ {"image", required_argument, 0, 'i'},
+ {"port", required_argument, 0, 'p'},
+ {"verbose", required_argument, 0, 'v'},
+ {"winpart", required_argument, 0, 'w'},
+ {"cache_wb", required_argument, 0, 'c'},
+ {0, 0, 0, 0}};
+
+ while (-1 != (c = getopt_long(argc, argv, "c:i:p:v:w:", long_options,
+ &option_index))) {
+
+ switch (c) {
+ case 'i':
+ ext4_fname = optarg;
+ break;
+ case 'p':
+ connection_port = atoi(optarg);
+ break;
+ case 'v':
+ verbose = atoi(optarg);
+ break;
+ case 'c':
+ cache_wb = atoi(optarg);
+ break;
+ case 'w':
+ winpart = atoi(optarg);
+ break;
+ default:
+ printf("%s", usage);
+ return false;
+ }
+ }
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ int n;
+ int listenfd;
+ int connfd;
+ char op_code[128];
+
+ if (!parse_opt(argc, argv))
+ return -1;
+
+ listenfd = server_open();
+
+ printf("lwext4_server: listening on port: %d\n", connection_port);
+
+ memset(write_buffer, RW_BUFFER_PATERN, MAX_RW_BUFFER);
+ while (1) {
+ connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
+
+ n = recv(connfd, op_code, sizeof(op_code), 0);
+
+ if (n < 0) {
+ printf("recv() error: %s fd = %d\n", strerror(errno),
+ connfd);
+ break;
+ }
+
+ op_code[n] = 0;
+
+ int r = exec_op_code(op_code);
+
+ n = send(connfd, (void *)&r, sizeof(r), 0);
+ if (n < 0) {
+ printf("send() error: %s fd = %d\n", strerror(errno),
+ connfd);
+ break;
+ }
+
+ close(connfd);
+ }
+
+ winsock_fini();
+ return 0;
+}
+
+int _device_register(char *p)
+{
+ int dev;
+ int cache_mode;
+ char dev_name[32];
+
+ if (sscanf(p, "%d %d %s", &dev, &cache_mode, dev_name) != 3) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+#ifdef WIN32
+ if (winpart) {
+ ext4_io_raw_filename(ext4_fname);
+ bd = ext4_io_raw_dev_get();
+
+ } else
+#endif
+ {
+ ext4_filedev_filename(ext4_fname);
+ bd = ext4_filedev_get();
+ }
+ return ext4_device_register(bd, 0, dev_name);
+}
+
+int _mount(char *p)
+{
+ char dev_name[32];
+ char mount_point[32];
+ int rc;
+
+ if (sscanf(p, "%s %s", dev_name, mount_point) != 2) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ rc = ext4_mount(dev_name, mount_point);
+ if (cache_wb)
+ ext4_cache_write_back(mount_point, 1);
+ return rc;
+}
+
+int _umount(char *p)
+{
+ char mount_point[32];
+
+ if (sscanf(p, "%s", mount_point) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (cache_wb)
+ ext4_cache_write_back(mount_point, 0);
+
+ return ext4_umount(mount_point);
+}
+
+int _mount_point_stats(char *p)
+{
+ char mount_point[32];
+ int d;
+ int rc;
+ struct ext4_mount_stats stats;
+
+ if (sscanf(p, "%s %d", mount_point, &d) != 2) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ rc = ext4_mount_point_stats(mount_point, &stats);
+
+ if (rc != EOK)
+ return rc;
+
+ if (verbose) {
+ printf("\tinodes_count = %d\n", stats.inodes_count);
+ printf("\tfree_inodes_count = %d\n", stats.free_inodes_count);
+ printf("\tblocks_count = %llu\n", stats.blocks_count);
+ printf("\tfree_blocks_count = %llu\n", stats.free_blocks_count);
+
+ printf("\tblock_size = %d\n", stats.block_size);
+ printf("\tblock_group_count = %d\n", stats.block_group_count);
+ printf("\tblocks_per_group = %d\n", stats.blocks_per_group);
+ printf("\tinodes_per_group = %d\n", stats.inodes_per_group);
+
+ printf("\tvolume_name = %s\n", stats.volume_name);
+ }
+
+ return rc;
+}
+
+int _cache_write_back(char *p)
+{
+ char mount_point[32];
+ int en;
+
+ if (sscanf(p, "%s %d", mount_point, &en) != 2) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ return ext4_cache_write_back(mount_point, en);
+}
+
+int _fremove(char *p)
+{
+ char path[255];
+
+ if (sscanf(p, "%s", path) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ return ext4_fremove(path);
+}
+
+int _fopen(char *p)
+{
+ int fid = MAX_FILES;
+ char path[256];
+ char flags[8];
+ int rc;
+
+ if (sscanf(p, "%d %s %s", &fid, path, flags) != 3) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(fid < MAX_FILES)) {
+ printf("File id too big\n");
+ return -1;
+ }
+
+ rc = ext4_fopen(&file_tab[fid].fd, path, flags);
+
+ if (rc == EOK)
+ strcpy(file_tab[fid].name, path);
+
+ return rc;
+}
+
+int _fclose(char *p)
+{
+ int fid = MAX_FILES;
+ int rc;
+
+ if (sscanf(p, "%d", &fid) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(fid < MAX_FILES)) {
+ printf("File id too big\n");
+ return -1;
+ }
+
+ if (file_tab[fid].name[0] == 0) {
+ printf("File id empty\n");
+ return -1;
+ }
+
+ rc = ext4_fclose(&file_tab[fid].fd);
+
+ if (rc == EOK)
+ file_tab[fid].name[0] = 0;
+
+ return rc;
+}
+
+int _fread(char *p)
+{
+ int fid = MAX_FILES;
+ int len;
+ int d;
+ int rc;
+ size_t rb;
+
+ if (sscanf(p, "%d %d %d %d", &fid, &d, &len, &d) != 4) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(fid < MAX_FILES)) {
+ printf("File id too big\n");
+ return -1;
+ }
+
+ if (file_tab[fid].name[0] == 0) {
+ printf("File id empty\n");
+ return -1;
+ }
+
+ while (len) {
+ d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+
+ memset(read_buffer, 0, MAX_RW_BUFFER);
+ rc = ext4_fread(&file_tab[fid].fd, read_buffer, d, &rb);
+
+ if (rc != EOK)
+ break;
+
+ if (rb != d) {
+ printf("Read count error\n");
+ return -1;
+ }
+
+ if (memcmp(read_buffer, write_buffer, d)) {
+ printf("Read compare error\n");
+ return -1;
+ }
+
+ len -= d;
+ }
+
+ return rc;
+}
+
+int _fwrite(char *p)
+{
+ int fid = MAX_FILES;
+ int d;
+ int rc;
+
+ size_t len;
+ size_t wb;
+
+ if (sscanf(p, "%d %d %d %d", &fid, &d, &len, &d) != 4) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(fid < MAX_FILES)) {
+ printf("File id too big\n");
+ return -1;
+ }
+
+ if (file_tab[fid].name[0] == 0) {
+ printf("File id empty\n");
+ return -1;
+ }
+
+ while (len) {
+ d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+ rc = ext4_fwrite(&file_tab[fid].fd, write_buffer, d, &wb);
+
+ if (rc != EOK)
+ break;
+
+ if (wb != d) {
+ printf("Write count error\n");
+ return -1;
+ }
+
+ len -= d;
+ }
+
+ return rc;
+}
+
+int _fseek(char *p)
+{
+ int fid = MAX_FILES;
+ int off;
+ int origin;
+
+ if (sscanf(p, "%d %d %d", &fid, &off, &origin) != 3) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(fid < MAX_FILES)) {
+ printf("File id too big\n");
+ return -1;
+ }
+
+ if (file_tab[fid].name[0] == 0) {
+ printf("File id empty\n");
+ return -1;
+ }
+
+ return ext4_fseek(&file_tab[fid].fd, off, origin);
+}
+
+int _ftell(char *p)
+{
+ int fid = MAX_FILES;
+ uint32_t exp_pos;
+
+ if (sscanf(p, "%d %u", &fid, &exp_pos) != 2) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(fid < MAX_FILES)) {
+ printf("File id too big\n");
+ return -1;
+ }
+
+ if (file_tab[fid].name[0] == 0) {
+ printf("File id empty\n");
+ return -1;
+ }
+
+ if (exp_pos != ext4_ftell(&file_tab[fid].fd)) {
+ printf("Expected filepos error\n");
+ return -1;
+ }
+
+ return EOK;
+}
+
+int _fsize(char *p)
+{
+ int fid = MAX_FILES;
+ uint32_t exp_size;
+
+ if (sscanf(p, "%d %u", &fid, &exp_size) != 2) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(fid < MAX_FILES)) {
+ printf("File id too big\n");
+ return -1;
+ }
+
+ if (file_tab[fid].name[0] == 0) {
+ printf("File id empty\n");
+ return -1;
+ }
+
+ if (exp_size != ext4_fsize(&file_tab[fid].fd)) {
+ printf("Expected filesize error\n");
+ return -1;
+ }
+
+ return EOK;
+}
+
+int _dir_rm(char *p)
+{
+ char path[255];
+
+ if (sscanf(p, "%s", path) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ return ext4_dir_rm(path);
+}
+
+int _dir_mk(char *p)
+{
+ char path[255];
+
+ if (sscanf(p, "%s", path) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ return ext4_dir_mk(path);
+}
+
+int _dir_open(char *p)
+{
+ int did = MAX_DIRS;
+ char path[255];
+ int rc;
+
+ if (sscanf(p, "%d %s", &did, path) != 2) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(did < MAX_DIRS)) {
+ printf("Dir id too big\n");
+ return -1;
+ }
+
+ rc = ext4_dir_open(&dir_tab[did].fd, path);
+
+ if (rc == EOK)
+ strcpy(dir_tab[did].name, path);
+
+ return rc;
+}
+
+int _dir_close(char *p)
+{
+ int did = MAX_DIRS;
+ int rc;
+
+ if (sscanf(p, "%d", &did) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(did < MAX_DIRS)) {
+ printf("Dir id too big\n");
+ return -1;
+ }
+
+ if (dir_tab[did].name[0] == 0) {
+ printf("Dir id empty\n");
+ return -1;
+ }
+
+ rc = ext4_dir_close(&dir_tab[did].fd);
+
+ if (rc == EOK)
+ dir_tab[did].name[0] = 0;
+
+ return rc;
+}
+
+int _dir_entry_get(char *p)
+{
+ int did = MAX_DIRS;
+ int exp;
+ char name[256];
+
+ if (sscanf(p, "%d %d", &did, &exp) != 2) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ if (!(did < MAX_DIRS)) {
+ printf("Dir id too big\n");
+ return -1;
+ }
+
+ if (dir_tab[did].name[0] == 0) {
+ printf("Dir id empty\n");
+ return -1;
+ }
+
+ int idx = 0;
+ const ext4_direntry *d;
+
+ while ((d = ext4_dir_entry_next(&dir_tab[did].fd)) != NULL) {
+
+ idx++;
+ memcpy(name, d->name, d->name_length);
+ name[d->name_length] = 0;
+ if (verbose) {
+ printf("\t%s %s\n", entry_to_str(d->inode_type), name);
+ }
+ }
+
+ if (idx < 2) {
+ printf("Minumum dir entry error\n");
+ return -1;
+ }
+
+ if ((idx - 2) != exp) {
+ printf("Expected dir entry error\n");
+ return -1;
+ }
+
+ return EOK;
+}
+
+int _multi_fcreate(char *p)
+{
+ char path[256];
+ char path1[256];
+ char prefix[32];
+ int cnt;
+ int rc;
+ int i;
+ ext4_file fd;
+
+ if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ for (i = 0; i < cnt; ++i) {
+ sprintf(path1, "%s%s%d", path, prefix, i);
+ rc = ext4_fopen(&fd, path1, "wb+");
+
+ if (rc != EOK)
+ break;
+ }
+
+ return rc;
+}
+
+int _multi_fwrite(char *p)
+{
+ char path[256];
+ char path1[256];
+ char prefix[32];
+ int cnt, i;
+ int len, ll;
+ int rc;
+ size_t d, wb;
+ ext4_file fd;
+
+ if (sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ for (i = 0; i < cnt; ++i) {
+ sprintf(path1, "%s%s%d", path, prefix, i);
+ rc = ext4_fopen(&fd, path1, "rb+");
+
+ if (rc != EOK)
+ break;
+
+ len = ll;
+ while (len) {
+ d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+ rc = ext4_fwrite(&fd, write_buffer, d, &wb);
+
+ if (rc != EOK)
+ break;
+
+ if (wb != d) {
+ printf("Write count error\n");
+ return -1;
+ }
+
+ len -= d;
+ }
+ }
+
+ return rc;
+}
+
+int _multi_fread(char *p)
+{
+ char path[256];
+ char path1[256];
+ char prefix[32];
+ int cnt;
+ int len, ll;
+ int rc ,i, d;
+ size_t rb;
+ ext4_file fd;
+
+ if (sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ for (i = 0; i < cnt; ++i) {
+ sprintf(path1, "%s%s%d", path, prefix, i);
+ rc = ext4_fopen(&fd, path1, "rb+");
+
+ if (rc != EOK)
+ break;
+
+ len = ll;
+ while (len) {
+ d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+
+ memset(read_buffer, 0, MAX_RW_BUFFER);
+ rc = ext4_fread(&fd, read_buffer, d, &rb);
+
+ if (rc != EOK)
+ break;
+
+ if (rb != d) {
+ printf("Read count error\n");
+ return -1;
+ }
+
+ if (memcmp(read_buffer, write_buffer, d)) {
+ printf("Read compare error\n");
+ return -1;
+ }
+
+ len -= d;
+ }
+ }
+
+ return rc;
+}
+
+int _multi_fremove(char *p)
+{
+ char path[256];
+ char path1[256];
+ char prefix[32];
+ int cnt, i, rc;
+
+ if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ for (i = 0; i < cnt; ++i) {
+ sprintf(path1, "%s%s%d", path, prefix, i);
+ rc = ext4_fremove(path1);
+ if (rc != EOK)
+ break;
+ }
+
+ return rc;
+}
+
+int _multi_dcreate(char *p)
+{
+ char path[256];
+ char path1[256];
+ char prefix[32];
+ int cnt, i, rc;
+
+ if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ for (i = 0; i < cnt; ++i) {
+ sprintf(path1, "%s%s%d", path, prefix, i);
+ rc = ext4_dir_mk(path1);
+ if (rc != EOK)
+ break;
+ }
+
+ return rc;
+}
+
+int _multi_dremove(char *p)
+{
+ char path[256];
+ char path1[256];
+ char prefix[32];
+ int cnt, i, rc;
+
+ if (sscanf(p, "%s %s %d", path, prefix, &cnt) != 3) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ for (i = 0; i < cnt; ++i) {
+ sprintf(path1, "%s%s%d", path, prefix, i);
+ rc = ext4_dir_rm(path1);
+ if (rc != EOK)
+ break;
+ }
+
+ return rc;
+}
+
+struct ext4_mount_stats saved_stats;
+
+int _stats_save(char *p)
+{
+ char path[256];
+
+ if (sscanf(p, "%s", path) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ return ext4_mount_point_stats(path, &saved_stats);
+}
+
+int _stats_check(char *p)
+{
+ char path[256];
+ int rc;
+
+ struct ext4_mount_stats actual_stats;
+
+ if (sscanf(p, "%s", path) != 1) {
+ printf("Param list error\n");
+ return -1;
+ }
+
+ rc = ext4_mount_point_stats(path, &actual_stats);
+
+ if (rc != EOK)
+ return rc;
+
+ if (memcmp(&saved_stats, &actual_stats,
+ sizeof(struct ext4_mount_stats))) {
+ if (verbose) {
+ printf("\tMount point stats error:\n");
+ printf("\tsaved_stats:\n");
+ printf("\tinodes_count = %d\n",
+ saved_stats.inodes_count);
+ printf("\tfree_inodes_count = %d\n",
+ saved_stats.free_inodes_count);
+ printf("\tblocks_count = %llu\n",
+ saved_stats.blocks_count);
+ printf("\tfree_blocks_count = %llu\n",
+ saved_stats.free_blocks_count);
+ printf("\tblock_size = %d\n", saved_stats.block_size);
+ printf("\tblock_group_count = %d\n",
+ saved_stats.block_group_count);
+ printf("\tblocks_per_group = %d\n",
+ saved_stats.blocks_per_group);
+ printf("\tinodes_per_group = %d\n",
+ saved_stats.inodes_per_group);
+ printf("\tvolume_name = %s\n", saved_stats.volume_name);
+ printf("\tactual_stats:\n");
+ printf("\tinodes_count = %d\n",
+ actual_stats.inodes_count);
+ printf("\tfree_inodes_count = %d\n",
+ actual_stats.free_inodes_count);
+ printf("\tblocks_count = %llu\n",
+ actual_stats.blocks_count);
+ printf("\tfree_blocks_count = %llu\n",
+ actual_stats.free_blocks_count);
+ printf("\tblock_size = %d\n", actual_stats.block_size);
+ printf("\tblock_group_count = %d\n",
+ actual_stats.block_group_count);
+ printf("\tblocks_per_group = %d\n",
+ actual_stats.blocks_per_group);
+ printf("\tinodes_per_group = %d\n",
+ actual_stats.inodes_per_group);
+ printf("\tvolume_name = %s\n",
+ actual_stats.volume_name);
+ }
+ return -1;
+ }
+
+ return rc;
+}
+
+static char *entry_to_str(uint8_t type)
+{
+ switch (type) {
+ case EXT4_DIRENTRY_UNKNOWN:
+ return "[UNK] ";
+ case EXT4_DIRENTRY_REG_FILE:
+ return "[FIL] ";
+ case EXT4_DIRENTRY_DIR:
+ return "[DIR] ";
+ case EXT4_DIRENTRY_CHRDEV:
+ return "[CHA] ";
+ case EXT4_DIRENTRY_BLKDEV:
+ return "[BLK] ";
+ case EXT4_DIRENTRY_FIFO:
+ return "[FIF] ";
+ case EXT4_DIRENTRY_SOCK:
+ return "[SOC] ";
+ case EXT4_DIRENTRY_SYMLINK:
+ return "[SYM] ";
+ default:
+ break;
+ }
+ return "[???]";
+}
+
+static int winsock_init(void)
+{
+#if WIN32
+ int rc;
+ static WSADATA wsaData;
+ rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
+ if (rc != 0) {
+ return -1;
+ }
+#endif
+ return 0;
+}
+
+static void winsock_fini(void)
+{
+#if WIN32
+ WSACleanup();
+#endif
+}