1 /*
2 * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3 *
4 * UniProton is licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 * http://license.coscl.org.cn/MulanPSL2
8 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11 * See the Mulan PSL v2 for more details.
12 * Create: 2009-12-22
13 * Description: the uniproton helloworld demo
14 */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdarg.h>
19 #include "securec.h"
20 #include "rtt_viewer.h"
21 #include "prt_config.h"
22 #include "prt_config_internal.h"
23 #include "prt_clk.h"
24 #include "test.h"
25
helloworld_task(U32 uwParam1,U32 uParam2,U32 uwParam3,U32 uwParam4)26 void helloworld_task(U32 uwParam1, U32 uParam2, U32 uwParam3, U32 uwParam4)
27 {
28 printf("hello world!\n");
29 while (1) {
30 PRT_TaskDelay(10);
31 }
32
33 return;
34 }
35
PRT_AppInit(void)36 U32 PRT_AppInit(void)
37 {
38 U32 ret;
39 TskHandle taskPid;
40 struct TskInitParam stInitParam = {helloworld_task, 10, 0, {0}, 0x800, "TaskA", 0};
41
42 ret = PRT_TaskCreate(&taskPid, &stInitParam);
43 if (ret) {
44 return ret;
45 }
46
47 ret = PRT_TaskResume(taskPid);
48 if (ret) {
49 return ret;
50 }
51
52 return OS_OK;
53 }
54
PRT_HardDrvInit(void)55 U32 PRT_HardDrvInit(void)
56 {
57 RttViewerInit();
58 RttViewerModeSet(0, RTT_VIEWER_MODE_BLOCK_IF_FIFO_FULL);
59
60 return OS_OK;
61 }
62
63 U32 g_testRandStackProtect;
OsRandomSeedInit(void)64 void OsRandomSeedInit(void)
65 {
66 #if defined(OS_OPTION_RND)
67 U32 ret;
68 U32 seed;
69 seed = PRT_ClkGetCycleCount64();
70 g_testRandStackProtect = rand_r(&seed);
71 ret = PRT_SysSetRndNum(OS_SYS_RND_STACK_PROTECT,g_testRandStackProtect);
72 #endif
73 }
74
75 extern U32 __data_start__;
76 extern U32 __data_end__;
77 extern U32 __text_end__;
OsGlobalDataInit(void)78 void OsGlobalDataInit(void)
79 {
80 U32 size;
81 U32 *dest = (U32 *)&__data_start__;
82 U32 *src = (U32 *)&__text_end__;
83 U32 i;
84
85 size = (U32)&__data_end__ - (U32)&__data_start__;
86 for (i = 0; i < (size / 4); i++) {
87 dest[i] = src[i];
88 }
89 }
90
PRT_HardBootInit(void)91 void PRT_HardBootInit(void)
92 {
93 OsGlobalDataInit();
94 OsRandomSeedInit();
95 }
96
PRT_Printf(const char * format,...)97 U32 PRT_Printf(const char *format, ...)
98 {
99 va_list vaList;
100 char buff[0x200] = { 0 };
101 S32 count;
102 U32 ret;
103
104 va_start(vaList, format);
105 count = vsprintf_s(buff, 0x200, format, vaList);
106 va_end(vaList);
107
108 if (count == -1) {
109 return OS_ERROR;
110 }
111
112 RttViewerWrite(0, buff, count);
113
114 return count;
115 }
116
main(void)117 S32 main(void)
118 {
119 return OsConfigStart();
120 }
121
122