main.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**************************************************************************/
  2. /*!
  3. @file main.c
  4. @author hathach (tinyusb.org)
  5. @section LICENSE
  6. Software License Agreement (BSD License)
  7. Copyright (c) 2013, hathach (tinyusb.org)
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. 3. Neither the name of the copyright holders nor the
  17. names of its contributors may be used to endorse or promote products
  18. derived from this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
  20. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  23. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
  26. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. This file is part of the tinyusb stack.
  30. */
  31. /**************************************************************************/
  32. //--------------------------------------------------------------------+
  33. // INCLUDE
  34. //--------------------------------------------------------------------+
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include "board.h"
  39. #include "tusb.h"
  40. #include "mouse_host_app.h"
  41. #include "keyboard_host_app.h"
  42. #include "msc_host_app.h"
  43. #include "cdc_serial_host_app.h"
  44. //--------------------------------------------------------------------+
  45. // MACRO CONSTANT TYPEDEF
  46. //--------------------------------------------------------------------+
  47. //--------------------------------------------------------------------+
  48. // INTERNAL OBJECT & FUNCTION DECLARATION
  49. //--------------------------------------------------------------------+
  50. void print_greeting(void);
  51. //--------------------------------------------------------------------+
  52. // IMPLEMENTATION
  53. //--------------------------------------------------------------------+
  54. #if TUSB_CFG_OS == TUSB_OS_NONE
  55. // like a real RTOS, this function is a main loop invoking each task in application and never return
  56. void os_none_start_scheduler(void)
  57. {
  58. while (1)
  59. {
  60. tusb_task();
  61. led_blinking_task(NULL);
  62. keyboard_host_app_task(NULL);
  63. mouse_host_app_task(NULL);
  64. msc_host_app_task(NULL);
  65. cdc_serial_host_app_task(NULL);
  66. }
  67. }
  68. #endif
  69. int main(void)
  70. {
  71. #if TUSB_CFG_OS == TUSB_OS_CMSIS_RTX
  72. osKernelInitialize(); // CMSIS RTX requires kernel init before any other OS functions
  73. #endif
  74. board_init();
  75. print_greeting();
  76. tusb_init();
  77. //------------- application task init -------------//
  78. led_blinking_init();
  79. keyboard_host_app_init();
  80. mouse_host_app_init();
  81. msc_host_app_init();
  82. cdc_serial_host_app_init();
  83. //------------- start OS scheduler (never return) -------------//
  84. #if TUSB_CFG_OS == TUSB_OS_FREERTOS
  85. vTaskStartScheduler();
  86. #elif TUSB_CFG_OS == TUSB_OS_NONE
  87. os_none_start_scheduler();
  88. #elif TUSB_CFG_OS == TUSB_OS_CMSIS_RTX
  89. osKernelStart();
  90. #else
  91. #error need to start RTOS schduler
  92. #endif
  93. return 0;
  94. }
  95. //--------------------------------------------------------------------+
  96. // HELPER FUNCTION
  97. //--------------------------------------------------------------------+
  98. void print_greeting(void)
  99. {
  100. char const * const rtos_name[] =
  101. {
  102. [TUSB_OS_NONE] = "None",
  103. [TUSB_OS_FREERTOS] = "FreeRTOS",
  104. };
  105. puts("\n\
  106. --------------------------------------------------------------------\n\
  107. - Host Demo (a tinyusb example)\n\
  108. - if you find any bugs or get any questions, feel free to file an\n\
  109. - issue at https://github.com/hathach/tinyusb\n\
  110. --------------------------------------------------------------------\n"
  111. );
  112. puts("This HOST demo is configured to support:");
  113. printf(" - RTOS = %s\n", rtos_name[TUSB_CFG_OS]);
  114. if (TUSB_CFG_HOST_HUB ) puts(" - Hub (1 level only)");
  115. if (TUSB_CFG_HOST_HID_MOUSE ) puts(" - HID Mouse");
  116. if (TUSB_CFG_HOST_HID_KEYBOARD ) puts(" - HID Keyboard");
  117. if (TUSB_CFG_HOST_MSC ) puts(" - Mass Storage");
  118. if (TUSB_CFG_HOST_CDC ) puts(" - Communication Device Class");
  119. }