main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (C) 2015 Robert Lippert
  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 "ch.h"
  14. #include "hal.h"
  15. #include "shell.h"
  16. #include "usbcfg.h"
  17. /*
  18. * LED blinker thread, times are in milliseconds.
  19. */
  20. static THD_WORKING_AREA(waThread1, 128);
  21. static THD_FUNCTION(Thread1, arg) {
  22. (void)arg;
  23. chRegSetThreadName("blinker");
  24. while (true) {
  25. palTogglePad(IOPORT4, BOARD_LED1);
  26. chThdSleepMilliseconds(1000);
  27. }
  28. }
  29. #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(512)
  30. static const ShellConfig shell_cfg1 = {
  31. (BaseSequentialStream *)&SDU1,
  32. NULL
  33. };
  34. /*
  35. * Application entry point.
  36. */
  37. int main(void) {
  38. /*
  39. * System initializations.
  40. * - HAL initialization, this also initializes the configured device drivers
  41. * and performs the board-specific initializations.
  42. * - Kernel initialization, the main() function becomes a thread and the
  43. * RTOS is active.
  44. */
  45. halInit();
  46. chSysInit();
  47. palClearPad(IOPORT4, BOARD_LED1);
  48. /*
  49. * Shell manager initialization.
  50. */
  51. shellInit();
  52. /* Initializes a serial-over-USB CDC driver. */
  53. sduObjectInit(&SDU1);
  54. sduStart(&SDU1, &serusbcfg);
  55. /* Initialize USB */
  56. usbStart(serusbcfg.usbp, &usbcfg);
  57. /*
  58. * Starts the LED blinker thread.
  59. */
  60. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  61. /*
  62. * Normal main() thread activity.
  63. */
  64. while (true) {
  65. if (SDU1.config->usbp->state == USB_ACTIVE) {
  66. thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
  67. "shell", NORMALPRIO + 1,
  68. shellThread, (void *)&shell_cfg1);
  69. chThdWait(shelltp); /* Waiting termination. */
  70. }
  71. chThdSleepMilliseconds(1000);
  72. }
  73. }