test_suite_flowcontroll.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <unity.h>
  2. #include "components/jomjol-flowcontroll/test_flow.cpp"
  3. #include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp"
  4. #include "components/jomjol-flowcontroll/test_flow_pp_negative.cpp"
  5. // SD-Card ////////////////////
  6. #include "nvs_flash.h"
  7. #include "esp_vfs_fat.h"
  8. #include "sdmmc_cmd.h"
  9. #include "driver/sdmmc_host.h"
  10. #include "driver/sdmmc_defs.h"
  11. static const char *TAGMAIN = "main";
  12. #define __SD_USE_ONE_LINE_MODE__
  13. #include "server_GPIO.h"
  14. void initGPIO()
  15. {
  16. gpio_config_t io_conf;
  17. //set as output mode
  18. io_conf.mode = gpio_mode_t::GPIO_MODE_INPUT;
  19. //bit mask of the pins that you want to set,e.g.GPIO18/19
  20. io_conf.pull_down_en = gpio_pulldown_t::GPIO_PULLDOWN_ENABLE;
  21. //set pull-up mode
  22. io_conf.pull_up_en = gpio_pullup_t::GPIO_PULLUP_DISABLE;
  23. //configure GPIO with the given settings
  24. gpio_config(&io_conf);
  25. }
  26. bool Init_NVS_SDCard()
  27. {
  28. esp_err_t ret = nvs_flash_init();
  29. if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
  30. ESP_ERROR_CHECK(nvs_flash_erase());
  31. ret = nvs_flash_init();
  32. }
  33. ////////////////////////////////////////////////
  34. ESP_LOGI(TAGMAIN, "Using SDMMC peripheral");
  35. sdmmc_host_t host = SDMMC_HOST_DEFAULT();
  36. // This initializes the slot without card detect (CD) and write protect (WP) signals.
  37. // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
  38. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
  39. // To use 1-line SD mode, uncomment the following line:
  40. #ifdef __SD_USE_ONE_LINE_MODE__
  41. slot_config.width = 1;
  42. #endif
  43. // GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
  44. // Internal pull-ups are not sufficient. However, enabling internal pull-ups
  45. // does make a difference some boards, so we do that here.
  46. gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
  47. gpio_set_pull_mode(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
  48. #ifndef __SD_USE_ONE_LINE_MODE__
  49. gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only
  50. gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
  51. #endif
  52. gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
  53. // Options for mounting the filesystem.
  54. // If format_if_mount_failed is set to true, SD card will be partitioned and
  55. // formatted in case when mounting fails.
  56. esp_vfs_fat_sdmmc_mount_config_t mount_config = {
  57. .format_if_mount_failed = false,
  58. .max_files = 5,
  59. .allocation_unit_size = 16 * 1024
  60. };
  61. // Use settings defined above to initialize SD card and mount FAT filesystem.
  62. // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
  63. // Please check its source code and implement error recovery when developing
  64. // production applications.
  65. sdmmc_card_t* card;
  66. ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
  67. if (ret != ESP_OK) {
  68. if (ret == ESP_FAIL) {
  69. ESP_LOGE(TAGMAIN, "Failed to mount filesystem. "
  70. "If you want the card to be formatted, set format_if_mount_failed = true.");
  71. } else {
  72. ESP_LOGE(TAGMAIN, "Failed to initialize the card (%s). "
  73. "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
  74. }
  75. return false;
  76. }
  77. sdmmc_card_print_info(stdout, card);
  78. return true;
  79. }
  80. /**
  81. * @brief startup the test. Like a test-suite
  82. * all test methods must be called here
  83. */
  84. extern "C" void app_main()
  85. {
  86. initGPIO();
  87. Init_NVS_SDCard();
  88. UNITY_BEGIN();
  89. RUN_TEST(testNegative);
  90. RUN_TEST(test_doFlow);
  91. UNITY_END();
  92. }