main.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * FreeRTOS V202104.00
  3. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * http://www.FreeRTOS.org
  23. * http://aws.amazon.com/freertos
  24. *
  25. * 1 tab == 4 spaces!
  26. */
  27. /******************************************************************************
  28. * This project provides two demo applications. A simple blinky style project,
  29. * and a more comprehensive test and demo application. The
  30. * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
  31. * select between the two. The simply blinky demo is implemented and described
  32. * in main_blinky.c. The more comprehensive test and demo application is
  33. * implemented and described in main_full.c.
  34. *
  35. * This file implements the code that is not demo specific, including the
  36. * hardware setup, standard FreeRTOS hook functions, and the ISR hander called
  37. * by the RTOS after interrupt entry (including nesting) has been taken care of.
  38. *
  39. * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
  40. * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
  41. * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
  42. *
  43. */
  44. #include "FreeRTOS.h"
  45. #include "task.h"
  46. #include "semphr.h"
  47. #include "board.h"
  48. #include "chip.h"
  49. #ifdef ADC_TOUCH
  50. #include "touch.h"
  51. #endif
  52. #ifdef ADC_KEY
  53. #include "keypad.h"
  54. #endif
  55. #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
  56. #pragma data_alignment=16*1024
  57. static uint32_t MMUTable[4*1024];
  58. #else
  59. static uint32_t MMUTable[4*1024] __attribute__((aligned(16*1024)));
  60. #endif
  61. extern int main_awtk(void);
  62. extern int sound_init(void);
  63. extern int ark_usb_init(void);
  64. extern void mipi_init(void);
  65. extern void sema_init(void);
  66. extern void McuAccessModule(void);
  67. #ifdef WIFI_SUPPORT
  68. static void wifi_reset(void)
  69. {
  70. gpio_direction_output(WIFI_RESET_IO, 1);
  71. mdelay(10);
  72. gpio_direction_output(WIFI_RESET_IO, 0);
  73. mdelay(20);
  74. gpio_direction_output(WIFI_RESET_IO, 1);
  75. mdelay(10);
  76. }
  77. #endif
  78. static void prvBoardLateInitTask( void *pvParameters )
  79. {
  80. if(!ark_lcd_get_boot_status())
  81. ark_lcd_enable(1);
  82. #ifdef WIFI_SUPPORT
  83. wifi_reset();
  84. #endif
  85. #ifdef SDMMC_SUPPORT
  86. mmcsd_core_init();
  87. mmc_init();
  88. #endif
  89. #ifdef ADC_TOUCH
  90. adc_channel_enable(ADC_CH_TP);
  91. /* tp enable */
  92. vSysctlConfigure(SYS_ANA1_CFG, 26, 1, 1);
  93. if (LoadTouchConfigure()) {
  94. AdjustTouch();
  95. }
  96. #endif
  97. #ifdef MAILBOX_SUPPORT
  98. mailbox_msg_init();
  99. McuAccessModule();
  100. #endif
  101. #ifdef ADC_KEY
  102. KeypadInit();
  103. #endif
  104. #if defined(AUDIO_REPLAY) || defined(AUDIO_RECORD)
  105. sound_init();
  106. #endif
  107. #ifdef USB_SUPPORT
  108. ark_usb_init();
  109. #endif
  110. /* you'd better init the rtc driver at last */
  111. #ifdef RTC_SUPPORT
  112. SystemTime_t tm;
  113. iGetLocalTime(&tm);
  114. printf("Time: %d-%.2d-%.2d %.2d:%.2d:%.2d.\n", tm.tm_year, tm.tm_mon,
  115. tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  116. #endif
  117. for (;;) {
  118. vTaskDelay(portMAX_DELAY);
  119. }
  120. }
  121. static void prvSetupHardware( void )
  122. {
  123. /* Initialize interrupt contorller */
  124. GIC_Initialize();
  125. sema_init();
  126. /* Disable watchdog */
  127. wdt_stop();
  128. /* Setup pinctrl */
  129. vPinctrlSetup();
  130. /* Setup clock */
  131. vClkInit();
  132. /* Configure a timer for delay */
  133. vInitialiseTimerForDelay();
  134. /* Initialize Debug Uart */
  135. vDebugConsoleInitialise();
  136. /* Configure ports used by LEDs. */
  137. //vParTestInitialise();
  138. /* get chip hardware version */
  139. GetChipHWVeriosn();
  140. /* enable cache */
  141. MMU_Initialize(MMUTable);
  142. CP15_EnableSMP();
  143. CP15_EnableMMU();
  144. CP15_EnableDcache();
  145. CP15_EnableIcache();
  146. printf("sys_pll=%d\n", ulClkGetRate(CLK_SYSPLL));
  147. printf("cpu_pll=%d\n", ulClkGetRate(CLK_CPUPLL));
  148. printf("vpu_pll=%d\n", ulClkGetRate(CLK_VPUPLL));
  149. printf("ddr_pll=%d\n", ulClkGetRate(CLK_DDRPLL));
  150. printf("mfc_pll=%d\n", ulClkGetRate(CLK_MFCPLL));
  151. printf("ahb_pll=%d\n", ulClkGetRate(CLK_AHBPLL));
  152. printf("gpu_pll=%d\n", ulClkGetRate(CLK_GPUPLL));
  153. printf("apb_clk=%d\n", ulClkGetRate(CLK_APB));
  154. printf("mmc_clk=%d\n", ulClkGetRate(CLK_SDMMC0));
  155. dma_init();
  156. spi_init();
  157. i2c_init();
  158. wdt_init();
  159. vdec_init();
  160. itu_init();
  161. pxp_init();
  162. VideoDisplayBufInit();
  163. #ifdef ADC_SUPPORT
  164. adc_init();
  165. #endif
  166. qoi_dec_init();
  167. #if LCD_INTERFACE_TYPE == LCD_INTERFACE_CPU
  168. Cpulcd_Init();
  169. #elif LCD_INTERFACE_TYPE == LCD_INTERFACE_MIPI
  170. mipi_init();
  171. #endif
  172. lcd_init();
  173. #ifdef ADC_TOUCH
  174. TouchInit();
  175. #endif
  176. #ifdef REMOTE_SUPPORT
  177. RemoteKeyInit();
  178. #endif
  179. blend2d_init();
  180. }
  181. int main( void )
  182. {
  183. /* Configure the hardware ready to run the demo. */
  184. prvSetupHardware();
  185. /* lateinit the hardware which needs call task funcs */
  186. xTaskCreate(prvBoardLateInitTask, "lateinit", configMINIMAL_STACK_SIZE * 10, NULL,
  187. configMAX_PRIORITIES - 1, NULL);
  188. #ifdef WRAP_SUPPORT
  189. extern void wrap_demo(void);
  190. wrap_demo();
  191. #else
  192. main_awtk();
  193. #endif
  194. /* Start the tasks and timer running. */
  195. vTaskStartScheduler();
  196. /* If all is well, the scheduler will now be running, and the following
  197. line will never be reached. If the following line does execute, then
  198. there was insufficient FreeRTOS heap memory available for the idle and/or
  199. timer tasks to be created. See the memory management section on the
  200. FreeRTOS web site for more details. */
  201. for( ;; );
  202. }