stm32f429 demo code format
[lwext4.git] / demos / stm32f429_disco / main.c
index 935e94298690a21622b168623880c26af4adca00..d553ea1f11b9d2abb40c54d424394697f5e71631 100644 (file)
-/*\r
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright\r
- *   notice, this list of conditions and the following disclaimer.\r
- * - Redistributions in binary form must reproduce the above copyright\r
- *   notice, this list of conditions and the following disclaimer in the\r
- *   documentation and/or other materials provided with the distribution.\r
- * - The name of the author may not be used to endorse or promote products\r
- *   derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-\r
-#include <config.h>\r
-#include <hw_init.h>\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <unistd.h>\r
-#include <getopt.h>\r
-#include <stdbool.h>\r
-#include <time.h>\r
-#include <unistd.h>\r
-#include <time.h>\r
-\r
-#include <usb_msc_lwext4.h>\r
-#include <ext4.h>\r
-#include "../../blockdev/test_lwext4.h"\r
-\r
-\r
-/**@brief   Read-write size*/\r
-#define READ_WRITE_SZIZE 1024 * 16\r
-\r
-/**@brief   Delay test (slower LCD scroll)*/\r
-#define TEST_DELAY_MS    1000\r
-\r
-/**@brief   Input stream name.*/\r
-char input_name[128] = "ext2";\r
-\r
-/**@brief   Read-write size*/\r
-static int rw_szie  = READ_WRITE_SZIZE;\r
-\r
-/**@brief   Read-write size*/\r
-static int rw_count = 100;\r
-\r
-/**@brief   Directory test count*/\r
-static int dir_cnt  = 100;\r
-\r
-/**@brief   Static or dynamic cache mode*/\r
-static bool cache_mode = false;\r
-\r
-/**@brief   Cleanup after test.*/\r
-static bool cleanup_flag = false;\r
-\r
-/**@brief   Block device stats.*/\r
-static bool bstat = false;\r
-\r
-/**@brief   Superblock stats.*/\r
-static bool sbstat = false;\r
-\r
-/**@brief   Block device handle.*/\r
-static struct ext4_blockdev *bd;\r
-\r
-/**@brief   Block cache handle.*/\r
-static struct ext4_bcache   *bc;\r
-\r
-static bool open_filedev(void)\r
-{\r
-\r
-       bd = ext4_usb_msc_get();\r
-       bc = ext4_usb_msc_cache_get();\r
-       if(!bd || !bc){\r
-               printf("open_filedev: fail\n");\r
-               return false;\r
-       }\r
-       return true;\r
-}\r
-\r
-int main(void)\r
-{\r
-       hw_init();\r
-\r
-       setbuf(stdout, 0);\r
-       printf("connect usb drive...\n");\r
-\r
-       while(!hw_usb_connected())\r
-               hw_usb_process();\r
-       printf("usb drive connected\n");\r
-\r
-       while(!hw_usb_enum_done())\r
-               hw_usb_process();\r
-       printf("usb drive enum done\n");\r
-\r
-       hw_led_red(1);\r
-\r
-       printf("test conditions:\n");\r
-       printf("  rw size: %d\n",  rw_szie);\r
-       printf("  rw count: %d\n", rw_count);\r
-       printf("  cache mode: %s\n", cache_mode ? "dynamic" : "static");\r
-\r
-       if (!open_filedev())\r
-               goto Finish;\r
-\r
-       tim_wait_ms(TEST_DELAY_MS);\r
-       if(!test_lwext4_mount(bd, bc))\r
-               return EXIT_FAILURE;\r
-\r
-       tim_wait_ms(TEST_DELAY_MS);\r
-\r
-       ext4_cache_write_back("/mp/", 1);\r
-       test_lwext4_cleanup();\r
-\r
-       if(sbstat){\r
-               tim_wait_ms(TEST_DELAY_MS);\r
-               test_lwext4_mp_stats();\r
-       }\r
-\r
-       tim_wait_ms(TEST_DELAY_MS);\r
-       test_lwext4_dir_ls("/mp/");\r
-       if(!test_lwext4_dir_test(dir_cnt))\r
-               return EXIT_FAILURE;\r
-\r
-       tim_wait_ms(TEST_DELAY_MS);\r
-       if(!test_lwext4_file_test(rw_szie, rw_count))\r
-               return EXIT_FAILURE;\r
-\r
-       if(sbstat){\r
-               tim_wait_ms(TEST_DELAY_MS);\r
-               test_lwext4_mp_stats();\r
-       }\r
-\r
-       if(cleanup_flag){\r
-               tim_wait_ms(TEST_DELAY_MS);\r
-               test_lwext4_cleanup();\r
-       }\r
-\r
-       if(bstat){\r
-               tim_wait_ms(TEST_DELAY_MS);\r
-               test_lwext4_block_stats();\r
-       }\r
-\r
-       ext4_cache_write_back("/mp/", 0);\r
-       if(!test_lwext4_umount())\r
-               return EXIT_FAILURE;\r
-\r
-       printf("press RESET button to restart\n");\r
-       Finish:\r
-       while (1) {\r
-               tim_wait_ms(500);\r
-               hw_led_green(1);\r
-               tim_wait_ms(500);\r
-               hw_led_green(0);\r
-\r
-       }\r
-}\r
-\r
+/*
+ * 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);
+       }
+}