main.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2015 Daniel Campora
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include <stdint.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include "py/mpconfig.h"
  30. #include "py/mphal.h"
  31. #include "mptask.h"
  32. #include "simplelink.h"
  33. #include "pybwdt.h"
  34. #include "debug.h"
  35. #include "antenna.h"
  36. #include "mperror.h"
  37. #include "task.h"
  38. /******************************************************************************
  39. DECLARE PRIVATE CONSTANTS
  40. ******************************************************************************/
  41. /******************************************************************************
  42. DECLARE PRIVATE FUNCTIONS
  43. ******************************************************************************/
  44. /******************************************************************************
  45. DECLARE PRIVATE DATA
  46. ******************************************************************************/
  47. // This is the static memory (TCB and stack) for the idle task
  48. static StaticTask_t xIdleTaskTCB __attribute__ ((section (".rtos_heap")));
  49. static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
  50. /******************************************************************************
  51. DECLARE PUBLIC DATA
  52. ******************************************************************************/
  53. #ifdef DEBUG
  54. OsiTaskHandle mpTaskHandle;
  55. #endif
  56. // This is the FreeRTOS heap, defined here so we can put it in a special segment
  57. uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
  58. // This is the static memory (TCB and stack) for the main MicroPython task
  59. StaticTask_t mpTaskTCB __attribute__ ((section (".rtos_heap")));
  60. StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
  61. /******************************************************************************
  62. DEFINE PUBLIC FUNCTIONS
  63. ******************************************************************************/
  64. __attribute__ ((section (".boot")))
  65. int main (void) {
  66. // Initialize the clocks and the interrupt system
  67. HAL_SystemInit();
  68. #if MICROPY_HW_ANTENNA_DIVERSITY
  69. // configure the antenna selection pins
  70. antenna_init0();
  71. #endif
  72. // Init the watchdog
  73. pybwdt_init0();
  74. #ifndef DEBUG
  75. OsiTaskHandle mpTaskHandle;
  76. #endif
  77. mpTaskHandle = xTaskCreateStatic(TASK_MicroPython, "MicroPy",
  78. MICROPY_TASK_STACK_LEN, NULL, MICROPY_TASK_PRIORITY, mpTaskStack, &mpTaskTCB);
  79. ASSERT(mpTaskHandle != NULL);
  80. osi_start();
  81. for ( ; ; );
  82. }
  83. // We need this when configSUPPORT_STATIC_ALLOCATION is enabled
  84. void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
  85. StackType_t **ppxIdleTaskStackBuffer,
  86. uint32_t *pulIdleTaskStackSize ) {
  87. *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
  88. *ppxIdleTaskStackBuffer = uxIdleTaskStack;
  89. *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
  90. }