1 /*********************************************************************
2 * SEGGER Microcontroller GmbH *
3 * The Embedded Experts *
4 **********************************************************************
5 * *
6 * (c) 1995 - 2019 SEGGER Microcontroller GmbH *
7 * *
8 * www.segger.com Support: support@segger.com *
9 * *
10 **********************************************************************
11 * *
12 * SEGGER SystemView * Real-time application analysis *
13 * *
14 **********************************************************************
15 * *
16 * All rights reserved. *
17 * *
18 * SEGGER strongly recommends to not make any changes *
19 * to or modify the source code of this software in order to stay *
20 * compatible with the SystemView and RTT protocol, and J-Link. *
21 * *
22 * Redistribution and use in source and binary forms, with or *
23 * without modification, are permitted provided that the following *
24 * condition is met: *
25 * *
26 * o Redistributions of source code must retain the above copyright *
27 * notice, this condition and the following disclaimer. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
33 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
34 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
36 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
37 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
40 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
41 * DAMAGE. *
42 * *
43 **********************************************************************
44 * *
45 * SystemView version: 3.30 *
46 * *
47 **********************************************************************
48 -------------------------- END-OF-HEADER -----------------------------
49
50 File : SEGGER_SYSVIEW_AliOSThings.c
51 Purpose : Interface between AliOS Things and SystemView.
52 Revision: $Rev: 7947 $
53 */
54 #include "k_api.h"
55 #include "SEGGER_SYSVIEW.h"
56
57 /*********************************************************************
58 *
59 * _cbSendTaskList()
60 *
61 * Function description
62 * This function is part of the link between FreeRTOS and SYSVIEW.
63 * Called from SystemView when asked by the host, it uses SYSVIEW
64 * functions to send the entire task list to the host.
65 */
_cbSendTaskList(void)66 static void _cbSendTaskList(void) {
67 klist_t *taskhead = &g_kobj_list.task_head;
68 klist_t *taskend = taskhead;
69 klist_t *tmp;
70 ktask_t *task;
71
72 krhino_sched_disable();
73 for (tmp = taskhead->next; tmp != taskend; tmp = tmp->next) {
74 task = krhino_list_entry(tmp, ktask_t, task_stats_item);
75 SYSVIEW_SendTaskInfo((U32)task, task->task_name, task->prio, (U32)task->task_stack_base, task->stack_size);
76 }
77 krhino_sched_enable();
78 }
79
80 /*********************************************************************
81 *
82 * _cbGetTime()
83 *
84 * Function description
85 * This function is part of the link between FreeRTOS and SYSVIEW.
86 * Called from SystemView when asked by the host, returns the
87 * current system time in micro seconds.
88 */
_cbGetTime(void)89 static U64 _cbGetTime(void) {
90 return aos_now_ms();
91 }
92
93 /*********************************************************************
94 *
95 * Global functions
96 *
97 **********************************************************************
98 */
99
100 /*********************************************************************
101 *
102 * SYSVIEW_SendTaskInfo()
103 *
104 * Function description
105 * Record task information.
106 */
SYSVIEW_SendTaskInfo(U32 TaskID,const char * sName,unsigned Prio,U32 StackBase,unsigned StackSize)107 void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) {
108 SEGGER_SYSVIEW_TASKINFO TaskInfo;
109
110 memset(&TaskInfo, 0, sizeof(TaskInfo)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code
111 TaskInfo.TaskID = TaskID;
112 TaskInfo.sName = sName;
113 TaskInfo.Prio = Prio;
114 TaskInfo.StackBase = StackBase;
115 TaskInfo.StackSize = StackSize;
116 SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo);
117 }
118
119 /*********************************************************************
120 *
121 * Public API structures
122 *
123 **********************************************************************
124 */
125 // Callbacks provided to SYSTEMVIEW by FreeRTOS
126 const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = {
127 _cbGetTime,
128 _cbSendTaskList,
129 };
130
131 /*************************** End of file ****************************/
132