main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include <string.h>
  14. #include "ch.h"
  15. #include "hal.h"
  16. #include "hal_serial_nor.h"
  17. #include "hal_mfs.h"
  18. #include "mfs_test_root.h"
  19. #include "portab.h"
  20. const SNORConfig snorcfg1 = {
  21. .busp = &PORTAB_WSPI1,
  22. .buscfg = &WSPIcfg1
  23. };
  24. SNORDriver snor1;
  25. const MFSConfig mfscfg1 = {
  26. .flashp = (BaseFlash *)&snor1,
  27. .erased = 0xFFFFFFFFU,
  28. .bank_size = 4096U,
  29. .bank0_start = 0U,
  30. .bank0_sectors = 1U,
  31. .bank1_start = 1U,
  32. .bank1_sectors = 1U
  33. };
  34. /*
  35. * LED blinker thread, times are in milliseconds.
  36. */
  37. static THD_WORKING_AREA(waThread1, 128);
  38. static THD_FUNCTION(Thread1, arg) {
  39. (void)arg;
  40. chRegSetThreadName("blinker");
  41. while (true) {
  42. palToggleLine(PORTAB_LINE_LED1);
  43. chThdSleepMilliseconds(500);
  44. palToggleLine(PORTAB_LINE_LED1);
  45. chThdSleepMilliseconds(500);
  46. }
  47. }
  48. /*
  49. * Application entry point.
  50. */
  51. int main(void) {
  52. /*
  53. * System initializations.
  54. * - HAL initialization, this also initializes the configured device drivers
  55. * and performs the board-specific initializations.
  56. * - Kernel initialization, the main() function becomes a thread and the
  57. * RTOS is active.
  58. */
  59. halInit();
  60. chSysInit();
  61. /* Board-dependent GPIO setup code.*/
  62. portab_setup();
  63. /* Starting a serial port for test report output.*/
  64. sdStart(&PORTAB_SD1, NULL);
  65. /* Initializing and starting snor1 driver.*/
  66. snorObjectInit(&snor1);
  67. snorStart(&snor1, &snorcfg1);
  68. #if 1
  69. /* Testing memory mapped mode.*/
  70. {
  71. uint8_t *addr;
  72. snorMemoryMap(&snor1, &addr);
  73. chThdSleepMilliseconds(50);
  74. snorMemoryUnmap(&snor1);
  75. }
  76. #endif
  77. /* Creates the blinker thread.*/
  78. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  79. /* Normal main() thread activity, in this demo it does nothing.*/
  80. while (true) {
  81. if (palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED) {
  82. test_execute((BaseSequentialStream *)&PORTAB_SD1, &mfs_test_suite);
  83. }
  84. chThdSleepMilliseconds(500);
  85. }
  86. return 0;
  87. }