blob: f13afa3d1aa1699bc2b1873517345f1eb81a1765 [file] [log] [blame]
yang.li5664bb32022-01-12 15:50:17 +08001/*
2 * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: MIT
5 */
Xiaohu.Huang90570a32022-03-12 22:55:20 +08006#include <stdio.h>
Xiaohu.Huanged896772021-11-18 13:57:56 +08007#include "FreeRTOS.h"
8#include "task.h"
bangzheng.liu8718cc12024-06-27 16:37:47 +08009#include "soc_business.h"
Xiaohu.Huanged896772021-11-18 13:57:56 +080010#include "hw_business.h"
11#include "sw_business.h"
benlong.zhoubda63b12022-11-25 02:56:52 +000012#include "gcc_compiler_attributes.h"
bangzheng.liub7fedec2023-05-08 20:04:38 +080013#include "board_version.h"
benlong.zhoubda63b12022-11-25 02:56:52 +000014
15void __weak aocpu_bringup_finished(void)
16{
17}
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080018
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080019int main(void)
20{
Xiaohu.Huanged896772021-11-18 13:57:56 +080021 printf("Starting AOCPU FreeRTOS\n");
bangzheng.liub7fedec2023-05-08 20:04:38 +080022 output_aocpu_info();
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080023
bangzheng.liu8718cc12024-06-27 16:37:47 +080024 soc_business_process();
Xiaohu.Huanged896772021-11-18 13:57:56 +080025 hw_business_process();
26 sw_business_process();
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080027
bangzheng.liub7fedec2023-05-08 20:04:38 +080028#ifdef CONFIG_BL30_VERSION_SAVE
29 bl30_plat_save_version();
30#endif
31
Xiaohu.Huanged896772021-11-18 13:57:56 +080032 printf("Starting task scheduler ...\n");
benlong.zhoubda63b12022-11-25 02:56:52 +000033 aocpu_bringup_finished();
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080034 vTaskStartScheduler();
fugui.zhange2b11812024-06-06 13:22:42 +080035 /*
36 * The Coverity tool think that the for loop is a structurally dead code, so it's
37 * flagged as such. But the for loop is necessary for ordering the
38 * FreeRTOS's format rules.
39 */
40 /* coverity[340441:SUPPRESS] */
41 for ( ; ; )
42 ;
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080043
44 return 0;
45}
46
47void vApplicationIdleHook( void )
48{
Shunzhou Jiangde73ea92024-11-21 17:41:39 +080049 //printf("enter idle task\n");
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080050
Shunzhou Jiangde73ea92024-11-21 17:41:39 +080051 //write_csr(mie, 1); // open mstatue.mie
52 asm volatile ("wfi"); // enter low power mode
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080053}
54/*-----------------------------------------------------------*/
bangzheng.liu79304392024-11-15 18:44:39 +080055void vApplicationMallocFailedHook(void);
56void vApplicationMallocFailedHook(void)
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080057{
bangzheng.liu79304392024-11-15 18:44:39 +080058 /* The malloc failed hook is enabled by setting
59 * configUSE_MALLOC_FAILED_HOOK to 1 in FreeRTOSConfig.h.
60 *
61 * Called if a call to pvPortMalloc() fails because there is insufficient
62 * free memory available in the FreeRTOS heap. pvPortMalloc() is called
63 * internally by FreeRTOS API functions that create tasks, queues, software
64 * timers, and semaphores. The size of the FreeRTOS heap is set by the
65 * configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h.
66 */
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080067
bangzheng.liu79304392024-11-15 18:44:39 +080068 printf("bl30 task %s malloc failed\n", pcTaskGetName(xTaskGetCurrentTaskHandle()));
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080069 vPrintFreeListAfterMallocFail();
bangzheng.liu79304392024-11-15 18:44:39 +080070 for ( ;; )
71 ;
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080072}
73/*-----------------------------------------------------------*/
74
xiaohu.huangd302fe82022-04-02 19:24:19 +080075void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080076{
bangzheng.liu29196322024-12-02 11:36:41 +080077 (void)xTask;
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080078
bangzheng.liu29196322024-12-02 11:36:41 +080079 /* Run time stack overflow checking is performed if
80 * configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
81 * function is called if a stack overflow is detected. pxCurrentTCB can be
82 * inspected in the debugger if the task name passed into this function is
83 * corrupt.
84 */
85 printf("bl30 task %s stack overflow\n", pcTaskName);
bangzheng.liu1ab41222023-05-22 14:47:03 +080086 vTaskDumpStack(NULL);
bangzheng.liu29196322024-12-02 11:36:41 +080087 for ( ;; )
88 ;
Xiaohu.Huang9696cbe2021-10-15 11:33:44 +080089}
90/*-----------------------------------------------------------*/
xiaohu.huang1860c3a2024-09-03 13:51:24 +080091
92#ifdef CONFIG_STACK_PROTECTOR_STRONG
93void additional_message_hook(void *address)
94{
bangzheng.liu29196322024-12-02 11:36:41 +080095 printf("bl30 stack smashing func last addr: 0x%x, stop!\n", address);
xiaohu.huang1860c3a2024-09-03 13:51:24 +080096}
97#endif