1#![doc = include_str!("../README.md")]
2#![no_std]
3
4#[cfg(not(any(feature = "cortex-m")))]
5compile_error!("You must select a target architecture. Supported are: cortex-m");
6
7#[cfg(feature = "log")]
8pub mod log;
9mod macros;
10mod stub;
11mod wrapper;
12
13use core::ptr::null;
14#[cfg(feature = "log")]
15pub use heapless;
16pub use rtos_trace::RtosTrace;
17use rtos_trace::TaskInfo;
18use wrapper::*;
19
20pub struct SystemView;
21
22impl SystemView {
23 pub const fn new() -> SystemView {
24 SystemView
25 }
26
27 pub fn init(&self) {
28 unsafe {
29 SEGGER_SYSVIEW_Conf();
30 }
31 }
32
33 pub fn send_system_description(desc: &str) {
34 unsafe {
35 SEGGER_SYSVIEW_SendSysDesc(desc.as_ptr());
36 }
37 }
38}
39
40impl RtosTrace for SystemView {
41 fn start() {
42 unsafe {
43 SEGGER_SYSVIEW_Start();
44 }
45 }
46
47 fn stop() {
48 unsafe {
49 SEGGER_SYSVIEW_Stop();
50 }
51 }
52
53 fn task_new(id: u32) {
54 unsafe {
55 SEGGER_SYSVIEW_OnTaskCreate(id);
56 }
57 }
58
59 fn task_send_info(id: u32, info: TaskInfo) {
60 let name = if info.name.is_empty() {
61 null()
62 } else {
63 info.name.as_ptr()
64 };
65 let info = SEGGER_SYSVIEW_TASKINFO {
66 TaskID: id,
67 sName: name,
68 Prio: info.priority,
69 StackBase: info.stack_base as u32,
70 StackSize: info.stack_size as u32,
71 StackUsage: 0,
72 };
73 unsafe {
74 SEGGER_SYSVIEW_SendTaskInfo(&info);
75 }
76 }
77
78 fn task_new_stackless(id: u32, name: &'static str, priority: u32) {
79 Self::task_new(id);
80 Self::task_send_info(
81 id,
82 TaskInfo {
83 name,
84 priority,
85 stack_base: 0,
86 stack_size: 0,
87 },
88 );
89 }
90
91 fn task_terminate(id: u32) {
92 unsafe {
93 SEGGER_SYSVIEW_OnTaskTerminate(id);
94 }
95 }
96
97 fn task_exec_begin(id: u32) {
98 unsafe {
99 SEGGER_SYSVIEW_OnTaskStartExec(id);
100 }
101 }
102
103 fn task_exec_end() {
104 unsafe {
105 SEGGER_SYSVIEW_OnTaskStopExec();
106 }
107 }
108
109 fn task_ready_begin(id: u32) {
110 unsafe {
111 SEGGER_SYSVIEW_OnTaskStartReady(id);
112 }
113 }
114
115 fn task_ready_end(id: u32) {
116 unsafe {
117 SEGGER_SYSVIEW_OnTaskStopReady(id, 0);
118 }
119 }
120
121 fn system_idle() {
122 unsafe {
123 SEGGER_SYSVIEW_OnIdle();
124 }
125 }
126
127 fn isr_enter() {
128 unsafe {
129 SEGGER_SYSVIEW_RecordEnterISR();
130 }
131 }
132
133 fn isr_exit() {
134 unsafe {
135 SEGGER_SYSVIEW_RecordExitISR();
136 }
137 }
138
139 fn isr_exit_to_scheduler() {
140 unsafe {
141 SEGGER_SYSVIEW_RecordExitISRToScheduler();
142 }
143 }
144
145 fn name_marker(id: u32, name: &'static str) {
146 unsafe {
147 SEGGER_SYSVIEW_NameMarker(id, name.as_ptr());
148 }
149 }
150
151 fn marker(id: u32) {
152 unsafe {
153 SEGGER_SYSVIEW_Mark(id);
154 }
155 }
156
157 fn marker_begin(id: u32) {
158 unsafe {
159 SEGGER_SYSVIEW_MarkStart(id);
160 }
161 }
162
163 fn marker_end(id: u32) {
164 unsafe {
165 SEGGER_SYSVIEW_MarkStop(id);
166 }
167 }
168}
169
170impl Default for SystemView {
171 fn default() -> Self {
172 Self::new()
173 }
174}