source: rtems/cpukit/include/rtems/capture.h

Last change on this file was f5233fe, checked in by Chris Johns <chrisj@…>, on 08/19/22 at 05:22:17

cpukit/include: Fixes for C++

Updates #4706

  • Property mode set to 100644
File size: 32.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Capture Engine Component of the RTEMS Measurement and
5 * Monitoring System
6 *
7 * This is the Capture Engine component of the RTEMS Measurement and
8 * Monitoring system.
9 */
10
11/*
12  ------------------------------------------------------------------------
13
14  Copyright 2002, 2016 Chris Johns <chrisj@rtems.org>.
15  All rights reserved.
16
17  COPYRIGHT (c) 1989-2014
18  On-Line Applications Research Corporation (OAR).
19
20  The license and distribution terms for this file may be
21  found in the file LICENSE in this distribution.
22
23  This software with is provided ``as is'' and with NO WARRANTY.
24
25  ------------------------------------------------------------------------
26
27  RTEMS Performance Monitoring and Measurement Framework.
28  This is the Capture Engine component.
29
30*/
31
32#ifndef __CAPTURE_H_
33#define __CAPTURE_H_
34
35#include <rtems.h>
36#include <rtems/rtems/tasksimpl.h>
37
38#include <string.h>
39
40/**
41 *  @defgroup libmisc_capture RTEMS Capture Engine
42 *
43 *  @ingroup RTEMSAPITracing
44 *
45 *  Capture Engine Component of the RTEMS Measurement and Monitoring System
46 */
47/**@{*/
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*
53 * Global capture flags.
54 */
55#define RTEMS_CAPTURE_INIT           (1u << 0)
56#define RTEMS_CAPTURE_ON             (1U << 1)
57#define RTEMS_CAPTURE_NO_MEMORY      (1U << 2)
58#define RTEMS_CAPTURE_TRIGGERED      (1U << 3)
59#define RTEMS_CAPTURE_GLOBAL_WATCH   (1U << 4)
60#define RTEMS_CAPTURE_ONLY_MONITOR   (1U << 5)
61
62/*
63 * Per-CPU capture flags.
64 */
65#define RTEMS_CAPTURE_OVERFLOW       (1U << 0)
66#define RTEMS_CAPTURE_READER_ACTIVE  (1U << 1)
67#define RTEMS_CAPTURE_READER_WAITING (1U << 2)
68
69/**
70 * The number of tasks in a trigger group.
71 */
72#define RTEMS_CAPTURE_TRIGGER_TASKS (32)
73
74/**
75 * @brief A capture timestamp.
76 *
77 * This is a nanosecond capture timestamp
78 */
79typedef uint64_t rtems_capture_time;
80
81/**
82 * @brief Task id and mask for the from trigger.
83 *
84 * A from capture is a task id and a mask for the type of
85 * from trigger we are interested in. The mask uses the same
86 * bit maps as the flags field in the control structure. There
87 * will only be a from type trigger if the flags in the control
88 * structure has the specific *_BY bit set.
89 */
90typedef struct rtems_capture_from
91{
92  rtems_name name;
93  rtems_id   id;
94  uint32_t   trigger;
95} rtems_capture_from;
96
97/**
98 * @brief Capture control structure for a group of tasks.
99 *
100 * RTEMS control holds the trigger and watch configuration for a group of
101 * tasks with the same name. The flags hold global control flags.
102 *
103 * The to_triggers fields holds triggers TO this task. The from_triggers holds
104 * triggers from this task. The by_triggers is an OR or triggers which are
105 * caused BY the task listed TO this task. The by_valid flag which entries
106 * in by are valid.
107 */
108typedef struct rtems_capture_control
109{
110  rtems_name                    name;
111  rtems_id                      id;
112  uint32_t                      flags;
113  uint32_t                      to_triggers;
114  uint32_t                      from_triggers;
115  uint32_t                      by_triggers;
116  uint32_t                      by_valid;
117  rtems_capture_from            by[RTEMS_CAPTURE_TRIGGER_TASKS];
118  struct rtems_capture_control* next;
119} rtems_capture_control;
120
121/**
122 * The from_valid mask.
123 */
124#define RTEMS_CAPTURE_CONTROL_FROM_MASK(_s) \
125 (UINT32_C(1) << (RTEMS_CAPTURE_TRIGGER_TASKS - ((_s) + 1)))
126
127/**
128 * Control flags.
129 */
130#define RTEMS_CAPTURE_WATCH         (1U << 0)
131
132/**
133 * Control triggers.
134 */
135#define RTEMS_CAPTURE_SWITCH        (1 << 0)
136#define RTEMS_CAPTURE_CREATE        (1 << 1)
137#define RTEMS_CAPTURE_START         (1 << 2)
138#define RTEMS_CAPTURE_RESTART       (1 << 3)
139#define RTEMS_CAPTURE_DELETE        (1 << 4)
140#define RTEMS_CAPTURE_BEGIN         (1 << 5)
141#define RTEMS_CAPTURE_EXITTED       (1 << 6)
142#define RTEMS_CAPTURE_TERMINATED    (1 << 7)
143
144#define RTEMS_CAPTURE_FROM_TRIGS    (RTEMS_CAPTURE_SWITCH  | \
145                                     RTEMS_CAPTURE_CREATE | \
146                                     RTEMS_CAPTURE_START | \
147                                     RTEMS_CAPTURE_RESTART | \
148                                     RTEMS_CAPTURE_DELETE)
149
150#define RTEMS_CAPTURE_TO_TRIGS      (RTEMS_CAPTURE_SWITCH | \
151                                     RTEMS_CAPTURE_CREATE | \
152                                     RTEMS_CAPTURE_START | \
153                                     RTEMS_CAPTURE_RESTART | \
154                                     RTEMS_CAPTURE_DELETE | \
155                                     RTEMS_CAPTURE_BEGIN | \
156                                     RTEMS_CAPTURE_EXITTED)
157
158/**
159 * Task flags.
160 */
161#define RTEMS_CAPTURE_TRACED      (1U << 0)
162#define RTEMS_CAPTURE_INIT_TASK   (1U << 1)
163#define RTEMS_CAPTURE_RECORD_TASK (1U << 2)
164
165/*
166 * @brief Capture record.
167 *
168 * This is a record that is written into
169 * the buffer. The events includes the priority of the task
170 * at the time of the context switch.
171 */
172typedef struct rtems_capture_record
173{
174  size_t             size;
175  uint32_t           events;
176  rtems_id           task_id;
177  rtems_capture_time time;
178} RTEMS_PACKED rtems_capture_record;
179
180/*
181 * @brief Capture task record.
182 *
183 * This is a record that is written into
184 * the buffer. The events includes the priority of the task
185 * at the time of the context switch.
186 */
187typedef struct rtems_capture_task_record
188{
189  rtems_name          name;
190  rtems_task_priority start_priority;
191  uint32_t            stack_size;
192} RTEMS_PACKED rtems_capture_task_record;
193
194/**
195 * The capture record event flags.
196 */
197#define RTEMS_CAPTURE_REAL_PRI_EVENT_MASK UINT32_C (0x000000ff)
198#define RTEMS_CAPTURE_CURR_PRI_EVENT_MASK UINT32_C (0x0000ff00)
199#define RTEMS_CAPTURE_REAL_PRIORITY_EVENT (0)
200#define RTEMS_CAPTURE_CURR_PRIORITY_EVENT (8)
201#define RTEMS_CAPTURE_EVENT_START         (16)
202#define RTEMS_CAPTURE_CREATED_BY_EVENT    UINT32_C (0x00010000)
203#define RTEMS_CAPTURE_CREATED_EVENT       UINT32_C (0x00020000)
204#define RTEMS_CAPTURE_STARTED_BY_EVENT    UINT32_C (0x00040000)
205#define RTEMS_CAPTURE_STARTED_EVENT       UINT32_C (0x00080000)
206#define RTEMS_CAPTURE_RESTARTED_BY_EVENT  UINT32_C (0x00100000)
207#define RTEMS_CAPTURE_RESTARTED_EVENT     UINT32_C (0x00200000)
208#define RTEMS_CAPTURE_DELETED_BY_EVENT    UINT32_C (0x00400000)
209#define RTEMS_CAPTURE_DELETED_EVENT       UINT32_C (0x00800000)
210#define RTEMS_CAPTURE_TERMINATED_EVENT    UINT32_C (0x01000000)
211#define RTEMS_CAPTURE_BEGIN_EVENT         UINT32_C (0x02000000)
212#define RTEMS_CAPTURE_EXITTED_EVENT       UINT32_C (0x04000000)
213#define RTEMS_CAPTURE_SWITCHED_OUT_EVENT  UINT32_C (0x08000000)
214#define RTEMS_CAPTURE_SWITCHED_IN_EVENT   UINT32_C (0x10000000)
215#define RTEMS_CAPTURE_TIMESTAMP           UINT32_C (0x20000000)
216#define RTEMS_CAPTURE_EVENT_END           (29)
217
218/**
219 * @brief Capture trigger modes
220 *
221 * The types of trigger modes that exist.
222 */
223typedef enum rtems_capture_trigger_mode
224{
225  rtems_capture_to_any,
226  rtems_capture_from_any,
227  rtems_capture_from_to
228} rtems_capture_trigger_mode;
229
230/**
231 * @brief Capture trigger.
232 *
233 * The types of triggers that exist.
234 */
235typedef enum rtems_capture_trigger
236{
237  rtems_capture_switch,
238  rtems_capture_create,
239  rtems_capture_start,
240  rtems_capture_restart,
241  rtems_capture_delete,
242  rtems_capture_begin,
243  rtems_capture_exitted,
244  rtems_capture_terminated
245} rtems_capture_trigger;
246
247/**
248 * @brief Capture timestamp callout handler.
249 *
250 * This defines the callout handler to obtain a time stamp. The
251 * value returned is time count since the last read.
252 *
253 */
254
255typedef void (*rtems_capture_timestamp)(rtems_capture_time* time);
256
257/**
258 * @brief Capture record lock context.
259 *
260 * This structure is used to lock a per CPU buffer when opeining recording. The
261 * per CPU buffer is held locked until the record close is called. Locking
262 * masks interrupts so use this lock only when needed and do not hold it for
263 * long.
264 *
265 * The lock first masks the CPU interrupt before taking the interrupt
266 * lock. This stops a thread context taking the lock and then an interrupt on
267 * the same CPU attempting to take the lock so creating a deadlock.
268 *
269 */
270typedef struct {
271  rtems_interrupt_lock_context lock_context;
272  rtems_interrupt_lock*        lock;
273} rtems_capture_record_lock_context;
274
275/**
276 * @brief Capture open
277 *
278 * This function initialises the realtime trace manager allocating the
279 * capture buffer. It is assumed we have a working heap at stage of
280 * initialisation.
281 *
282 * @param[in] size The number of capture records to define.
283 * @param[in] timestamp The timestamp callout handler to use. If the
284 *            the handler is NULL a default  nano-second timestamp
285 *            will be used.
286 *
287 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
288 *         error. Otherwise, a status code is returned indicating the
289 *         source of the error.
290 */
291rtems_status_code rtems_capture_open (uint32_t                size,
292                                      rtems_capture_timestamp timestamp);
293
294/**
295 * @brief Capture close
296 *
297 * This function shutdowns the tracer and release any claimed
298 * resources.
299 *
300 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
301 *         error. Otherwise, a status code is returned indicating the
302 *         source of the error.
303 */
304rtems_status_code rtems_capture_close (void);
305
306/**
307 * @brief Capture control trace enable/disable.
308 *
309 * This function allows control of tracing at a global level.
310 *
311 * @param[in]  enable The trace enable/disable flag.
312 *
313 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
314 *         error. Otherwise, a status code is returned indicating the
315 *         source of the error.
316 */
317rtems_status_code rtems_capture_set_control (bool enable);
318
319/**
320 * @brief Capture monitor enable/disable.
321 *
322 * This function enable the monitor mode. When in the monitor mode
323 * the tasks are monitored but no data is saved. This can be used
324 * to profile the load on a system.
325 *
326 * @param[in]  enable The monitor enable/disable flag.
327 *
328 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
329 *         error. Otherwise, a status code is returned indicating the
330 *         source of the error.
331 */
332rtems_status_code rtems_capture_set_monitor (bool enable);
333
334/*
335 * @brief Capture flush trace buffer.
336 *
337 * This function flushes the trace buffer. The prime parameter allows the
338 * capture engine to also be primed again.
339 *
340 * @param[in]  prime The prime after flush flag.
341 *
342 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
343 *         error. Otherwise, a status code is returned indicating the
344 *         source of the error.
345 */
346rtems_status_code rtems_capture_flush (bool prime);
347
348/**
349 * @brief Capture add watch
350 *
351 * This function defines a watch for a specific task given a name. A watch
352 * causes it to be traced either in or out of context. The watch can be
353 * optionally enabled or disabled with the set routine. It is disabled by
354 * default.
355 *
356 * @param[in]  name The name of the @a capture_controls entry
357 * @param[in]  id The id of the @a capture_controls entry.
358 *
359 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
360 *         error. Otherwise, a status code is returned indicating the
361 *         source of the error.
362 */
363rtems_status_code rtems_capture_watch_add (rtems_name name, rtems_id id);
364
365/**
366 * @brief Capture delete watch.
367 *
368 * This function removes a watch for a specific task given a name. The task
369 * description will still exist if referenced by a trace record in the trace
370 * buffer or a global watch is defined.
371 *
372 * @param[in]  name The name of the @a capture_controls entry
373 * @param[in]  id The id of the @a capture_controls entry.
374 *
375 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
376 *         error. Otherwise, a status code is returned indicating the
377 *         source of the error.
378 */
379rtems_status_code rtems_capture_watch_del (rtems_name name, rtems_id id);
380
381/**
382 * @brief Capture enable/disable watch.
383 *
384 * This function allows control of a watch. The watch can be enabled or
385 * disabled.
386 *
387 * @param[in]  name The name of the @a capture_controls entry
388 * @param[in]  id The id of the @a capture_controls entry.
389 * @param[in]  enable The enable/disable flag for the watch.
390 *
391 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
392 *         error. Otherwise, a status code is returned indicating the
393 *         source of the error.
394 */
395rtems_status_code rtems_capture_watch_ctrl (rtems_name name,
396                                            rtems_id   id,
397                                            bool       enable);
398
399/**
400 * @brief Capture enable/disable global watch.
401 *
402 * This function allows control of a global watch. The watch can
403 * be enabled or disabled. A global watch configures all tasks below
404 * the ceiling and above the floor to be traced.
405 *
406 * @param[in]  enable The enable/disable flag for the watch.
407 *
408 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
409 *         error. Otherwise, a status code is returned indicating the
410 *         source of the error.
411 */
412rtems_status_code rtems_capture_watch_global (bool enable);
413
414/**
415 * @brief Get global watch state
416 *
417 * This function returns the global watch state.
418 *
419 * @retval This method returns true  if the global watch
420 *         is on.  Otherwise, it returns false.
421 */
422bool rtems_capture_watch_global_on (void);
423
424/**
425 * @brief Set watch ceiling.
426 *
427 * This function sets a watch ceiling. Events from tasks at or greater
428 * than the ceiling priority are ignored. This is a simple way to
429 * monitor an application and exclude system tasks running at a higher
430 * priority level.
431 *
432 * @param[in] ceiling specifies the priority level immediately above
433 *     that at which events from tasks are not captured.
434 *
435 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
436 *         error. Otherwise, a status code is returned indicating the
437 *         source of the error.
438 */
439rtems_status_code rtems_capture_watch_ceiling (rtems_task_priority ceiling);
440
441/**
442 * @brief Get watch ceiling.
443 *
444 * This function gets the watch ceiling.
445 *
446 * @retval The priority level immediately above that at which events
447 *         from tasks are not captured.
448 */
449rtems_task_priority rtems_capture_watch_get_ceiling (void);
450
451/**
452 * @brief Capture set watch floor.
453 *
454 * This function sets a watch floor. Tasks at or less than the
455 * floor priority are not watched. This is a simple way to monitor
456 * an application and exclude system tasks running at a lower
457 * priority level.
458 *
459 * @param[in] floor specifies the priority level immediately below
460 *     that at which events from tasks are not captured.
461 *
462 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
463 *         error. Otherwise, a status code is returned indicating the
464 *         source of the error.
465 */
466rtems_status_code rtems_capture_watch_floor (rtems_task_priority floor);
467
468/**
469 * @brief Capture set watch floor
470 *
471 * This function gets the watch floor.
472 *
473 * @retval The priority level immediately below
474 *     that at which events from tasks are not captured.
475 */
476rtems_task_priority rtems_capture_watch_get_floor (void);
477
478/**
479 * @brief Capture set trigger
480 *
481 * This function sets a trigger.
482 *
483 * This set trigger routine will create a trace control for the
484 * target task. The task list is searched and any existing tasks
485 * are linked to the new control.
486 *
487 * We can have a number of tasks that have the same name so we
488 * search using names. This means a number of tasks can be
489 * linked to single control.
490 *
491 * Some events captured such as context switch include two
492 * tasks. These are referred to as being "from" and "to"
493 * Some events may only have one task specified.
494 *
495 * @param[in] from_name specifies the name of the from task.
496 * @param[in] from_id specifies the id of the from task.
497 * @param[in] to_name specifies the name of the to task.
498 * @param[in] to_id specifies the id of the to task.
499 * @param[in] mode specifies the trigger mode.
500 * @param[in] trigger specifies the type of trigger.
501 *
502 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
503 *         error. Otherwise, a status code is returned indicating the
504 *         source of the error.
505 */
506rtems_status_code
507rtems_capture_set_trigger (rtems_name                 from_name,
508                           rtems_id                   from_id,
509                           rtems_name                 to_name,
510                           rtems_id                   to_id,
511                           rtems_capture_trigger_mode mode,
512                           rtems_capture_trigger      trigger);
513
514/**
515 * @brief Capture clear trigger.
516 *
517 * This function clears a trigger.
518 *
519 * This clear trigger routine will not clear a watch.
520 *
521 * @param[in] from_name specifies the name of the from task.
522 * @param[in] from_id specifies the id of the from task.
523 * @param[in] to_name specifies the name of the to task.
524 * @param[in] to_id specifies the id of the to task.
525 * @param[in] mode specifies the trigger mode.
526 * @param[in] trigger specifies the type of trigger.
527 *
528 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
529 *         error. Otherwise, a status code is returned indicating the
530 *         source of the error.
531 */
532rtems_status_code
533rtems_capture_clear_trigger (rtems_name                 from_name,
534                             rtems_id                   from_id,
535                             rtems_name                 to_name,
536                             rtems_id                   to_id,
537                             rtems_capture_trigger_mode mode,
538                             rtems_capture_trigger      trigger);
539
540/**
541 * @brief Capture read records from capture buffer
542 *
543 * This function reads a number of records from the capture buffer.
544 *
545 * The function returns the number of record that is has that are
546 * in a continous block of memory. If the number of available records
547 * wrap then only those records are provided. This removes the need for
548 * caller to be concerned about buffer wrappings. If the number of
549 * requested records cannot be met due to the wrapping of the records
550 * less than the specified number will be returned.
551 *
552 * The user must release the records. This is achieved with a call to
553 * rtems_capture_release. Calls this function without a release will
554 * result in at least the same number of records being released.
555 *
556 * @param[in]  cpu The cpu number that the records were recorded on
557 * @param[out] read will contain the number of records read
558 * @param[out] recs The capture records that are read.
559 *
560 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
561 *         error. Otherwise, a status code is returned indicating the
562 *         source of the error.
563 */
564rtems_status_code rtems_capture_read (uint32_t     cpu,
565                                      size_t*      read,
566                                      const void** recs);
567
568/**
569 * @brief Capture release records.
570 *
571 * This function releases the requested number of record slots back
572 * to the capture engine. The count must match the number read.
573 *
574 * @param[in] count The number of record slots to release
575 *
576 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
577 *         error. Otherwise, a status code is returned indicating the
578 *         source of the error.
579 */
580rtems_status_code rtems_capture_release (uint32_t cpu, uint32_t count);
581
582/**
583 * @brief Capture filter
584 *
585 * This function this function specifies if the given task and events should be
586 * logged.
587 *
588 * @param[in] task specifies the capture task control block
589 * @param[in] events specifies the events
590 *
591 * @retval This method returns true if this data should be filtered from the
592 *         log. It returns false if this data should be logged.
593 */
594bool rtems_capture_filter (rtems_tcb* task, uint32_t events);
595
596/**
597 * @brief Capture returns the current time.
598 *
599 * This function returns the current time. If a handler is provided
600 * by the user the time is gotten from that.
601 *
602 * @param[in] time specifies the capture time
603 *
604 * @retval This method returns a nano-second time if no user handler
605 * is provided.  Otherwise, it returns a resolution defined by the handler.
606 */
607void rtems_capture_get_time (rtems_capture_time* time);
608
609/**
610 * @brief Capture get event text.
611 *
612 * This function returns a string for an event based on the bit in the
613 * event. The functions takes the bit offset as a number not the bit
614 * set in a bit map.
615 *
616 * @param[in] event specifies the event to describe
617 *
618 * @retval This method returns a string description of the given event.
619 */
620const char* rtems_capture_event_text (int event);
621
622/**
623 * @brief Capture initialize task
624 *
625 * This function initializes capture control in the tcb.
626 *
627 * @param[in] tcb is the task control block for the task
628 */
629void rtems_capture_initialize_task (rtems_tcb* tcb);
630
631/**
632 * @brief Capture record task.
633 *
634 * This function records a new capture task record.
635 *
636 * @param[in] tcb is the task control block for the task
637 */
638void rtems_capture_record_task (rtems_tcb* tcb);
639
640/**
641 * @brief Capture record lock.
642 *
643 * This does a lock acquire which will remain in effect until
644 * rtems_capture_record_unlock is called.
645 *
646 * @param[out] context specifies the record context
647 */
648void rtems_capture_record_lock (rtems_capture_record_lock_context* context);
649
650/**
651 * @brief Capture record unlock.
652 *
653 * This unlocks the record lock.
654 *
655 * @param[in] context specifies the record context
656 */
657void rtems_capture_record_unlock (rtems_capture_record_lock_context* context);
658
659/**
660 * @brief Capture record open.
661 *
662 * This function allocates a record and fills in the header information. It
663 * does a lock acquire which will remain in effect until
664 * rtems_capture_record_close is called. The size is the amount of user data
665 * being recorded. The record header is internally managed.
666 *
667 * @param[in] task specifies the caputre task block
668 * @param[in] events specifies the events
669 * @param[in] size specifies the user's capture data size
670 * @param[out] context specifies the record context
671 *
672 * @retval This method returns a pointer to the next location in
673 * the capture record to store data.
674 */
675void* rtems_capture_record_open (rtems_tcb*                         task,
676                                 uint32_t                           events,
677                                 size_t                             size,
678                                 rtems_capture_record_lock_context* context);
679
680/**
681 * @brief Capture record close.
682 *
683 * This function closes writing to capure record and releases the lock that was
684 * held on the per CPU buffer.
685 *
686 * @param[out] context specifies the record context
687 */
688void rtems_capture_record_close (rtems_capture_record_lock_context* context);
689
690/**
691 * @brief Capture append to record to the per CPU buffer.
692 *
693 * This function appends data of a specifed size into a capture buffer.
694 *
695 * @param[in] rec specifies the next write point in the capture record
696 * @param[in] data specifies the data to write
697 * @param[in] size specifies the size of the data
698 *
699 * @retval This method returns the next write point in the capture record.
700 */
701static inline void*
702rtems_capture_record_append (void* rec, const void* data, size_t size)
703{
704  memcpy (rec, data, size);
705  return ((uint8_t*) rec) + size;
706}
707
708/**
709 * @brief Capture read a record from the per CPU buffer.
710 *
711 * This function reads data of a  specifed size from a capture buffer.
712 *
713 * @param[in] rec specifies the next read point in the capture record
714 * @param[in] data specifies where to write the data
715 * @param[in] size specifies the size of the data
716 *
717 * @retval This method returns the next write point in the capture record.
718 */
719static inline void*
720rtems_capture_record_extract (const void* rec, void* data, size_t size)
721{
722  memcpy (data, rec, size);
723  return ((uint8_t*) rec) + size;
724}
725
726/**
727 * @brief Capture task recorded
728 *
729 * This function returns true if this task information has been
730 * recorded.
731 *
732 * @param[in] tcb is the task control block for the task
733 */
734static inline bool rtems_capture_task_recorded (rtems_tcb* tcb) {
735  return ((tcb->Capture.flags & RTEMS_CAPTURE_RECORD_TASK) != 0);
736}
737
738/**
739 * @brief Capture task initialized
740 *
741 * This function returns true if this task information has been
742 * initialized.
743 *
744 * @param[in] tcb is the task control block for the task
745 */
746static inline bool rtems_capture_task_initialized (rtems_tcb* tcb) {
747  return ((tcb->Capture.flags & RTEMS_CAPTURE_INIT_TASK) != 0);
748}
749
750/**
751 * @brief Capture get task id.
752 *
753 * This function returns the task id.
754 *
755 * @param[in] task The capture task.
756 *
757 * @retval This function returns the task id.
758 */
759static inline rtems_id
760rtems_capture_task_id (rtems_tcb* tcb)
761{
762  return tcb->Object.id;
763}
764
765/**
766 * @brief Capture get task API.
767 *
768 * This function returns the task API as an int.
769 *
770 * @param[in] task The capture task.
771 *
772 * @retval This function returns the task API as an int.
773 */
774static inline int
775rtems_capture_task_api (rtems_id id)
776{
777  return _Objects_Get_API (id);
778}
779
780/**
781 * @brief Capture get task state.
782 *
783 * This function returns the task state.
784 *
785 * @param[in] task The capture task.
786 *
787 * @retval This function returns the task state.
788 */
789static inline States_Control
790rtems_capture_task_state (rtems_tcb* tcb)
791{
792  if (tcb)
793    return tcb->current_state;
794  return 0;
795}
796
797/**
798 * @brief Capture get task name.
799 *
800 * This function returns the task name.
801 *
802 * @param[in] task The capture task.
803 *
804 * @retval This function returns the task name.
805 */
806static inline rtems_name
807rtems_capture_task_name (rtems_tcb* tcb)
808{
809  rtems_name  name;
810  rtems_object_get_classic_name( tcb->Object.id, &name );
811  return name;
812}
813
814/**
815 * @brief Capture get task flags.
816 *
817 * This function returns the task flags.
818 *
819 * @param[in] task The capture task.
820 *
821 * @retval This function returns the task flags.
822 */
823static inline uint32_t
824rtems_capture_task_flags (rtems_tcb* tcb)
825{
826  return tcb->Capture.flags;
827}
828
829/**
830 * @brief Capture get task control
831 *
832 * This function returns the task control if present.
833 *
834 * @param[in] task The capture task.
835 *
836 * @retval This function returns the task control if present.
837 */
838static inline rtems_capture_control*
839rtems_capture_task_control (rtems_tcb* tcb)
840{
841  return (rtems_capture_control*) tcb->Capture.control;
842}
843
844/**
845 * @brief Capture get task control flags.
846 *
847 * This function returns the task control flags if a control is present.
848 *
849 * @param[in] task The capture task.
850 *
851 * @retval This function returns the task control flags if a control is present.
852 */
853static inline uint32_t
854rtems_capture_task_control_flags (rtems_tcb* tcb)
855{
856  rtems_capture_control*  control = rtems_capture_task_control (tcb);
857  if (!control)
858    return 0;
859  return control->flags;
860}
861
862/**
863 * @brief Capture get task start priority.
864 *
865 * This function returns the tasks start priority. The tracer needs this
866 * to track where the task's priority goes.
867 *
868 * @param[in] task The capture task.
869 *
870 * @retval This function returns the tasks start priority. The tracer needs this
871 * to track where the task's priority goes.
872 */
873static inline rtems_task_priority
874rtems_capture_task_start_priority (rtems_tcb* tcb)
875{
876  return _RTEMS_Priority_From_core (_Thread_Scheduler_get_home( tcb ),
877                                    tcb->Start.initial_priority);
878}
879
880/**
881 * @brief Capture get task real priority.
882 *
883 * This function returns the tasks real priority.
884 *
885 * @param[in] task The capture task.
886 *
887 * @retval This function returns the tasks real priority.
888 */
889static inline rtems_task_priority
890rtems_capture_task_real_priority (rtems_tcb* tcb)
891{
892  return _Thread_Get_unmapped_real_priority (tcb);
893}
894
895/**
896 * @brief Capture get task current priority.
897 *
898 * This function returns the tasks current priority.
899 *
900 * @param[in] task The capture task.
901 *
902 * @retval This function returns the tasks current priority.
903 */
904static inline rtems_task_priority
905rtems_capture_task_curr_priority (rtems_tcb* tcb)
906{
907  return _Thread_Get_unmapped_priority (tcb);
908}
909
910/**
911 * @brief Capture get control list.
912 *
913 * This function returns the head of the list of controls in the
914 * capture engine.
915 *
916 * @retval This function returns the head of the list of controls in the
917 * capture engine.
918 */
919rtems_capture_control*
920rtems_capture_get_control_list (void);
921
922/**
923 * @brief Capture get next capture control.
924 *
925 * This function returns the pointer to the next control in the list. The
926 * pointer NULL terminates the list.
927 *
928 * @param[in] control the current capture control.
929 *
930 * @retval This function returns the pointer to the next control in the list. The
931 * pointer NULL terminates the list.
932 */
933static inline rtems_capture_control*
934rtems_capture_next_control (rtems_capture_control* control)
935{
936  return control->next;
937}
938
939/**
940 * @brief Capture get capture control id.
941 *
942 * This function returns the control id.
943 *
944 * @param[in] control the capture control.
945 *
946 * @retval This function returns the control id.
947 */
948static inline rtems_id
949rtems_capture_control_id (rtems_capture_control* control)
950{
951  return control->id;
952}
953
954/**
955 * @brief Capture get capture control name.
956 *
957 * This function returns the control name.
958 *
959 * @param[in] control the capture control.
960 *
961 * @retval This function returns the control name.
962 */
963static inline rtems_name
964rtems_capture_control_name (rtems_capture_control* control)
965{
966  return control->name;
967}
968
969/**
970 * @brief Capture get capture control flags.
971 *
972 * This function returns the control flags.
973 *
974 * @param[in] control the capture control.
975 *
976 * @retval This function returns the control flags.
977 */
978static inline uint32_t
979rtems_capture_control_flags (rtems_capture_control* control)
980{
981  return control->flags;
982}
983
984/**
985 * @brief Capture get capture control to triggers.
986 *
987 * This function returns the task control to triggers.
988 *
989 * @param[in] control the capture control.
990 *
991 * @retval This function returns the task control to triggers.
992 */
993static inline uint32_t
994rtems_capture_control_to_triggers (rtems_capture_control* control)
995{
996  return control->to_triggers;
997}
998
999/**
1000 * @brief Capture get capture control from triggers.
1001 *
1002 * This function returns the task control from triggers.
1003 *
1004 * @param[in] control the capture control.
1005 *
1006 * @retval This function returns the task control from triggers.
1007 */
1008static inline uint32_t
1009rtems_capture_control_from_triggers (rtems_capture_control* control)
1010{
1011  return control->from_triggers;
1012}
1013
1014/**
1015 * @brief Capture get capture control by triggers.
1016 *
1017 * This function returns the task control by triggers.
1018 *
1019 * @param[in] control the capture control.
1020 *
1021 * @retval This function returns the task control by triggers.
1022 */
1023static inline uint32_t
1024rtems_capture_control_all_by_triggers (rtems_capture_control* control)
1025{
1026  return control->by_triggers;
1027}
1028
1029/**
1030 * @brief Capture get capture control valid by flags.
1031 *
1032 * This function returns the control valid BY flags.
1033 *
1034 * @param[in] control The capture control.
1035 * @param[in] slot The slot.
1036 *
1037 * @retval This function returns the control valid BY flags.
1038 */
1039static inline int
1040rtems_capture_control_by_valid (rtems_capture_control* control, int slot)
1041{
1042  return control->by_valid & RTEMS_CAPTURE_CONTROL_FROM_MASK (slot);
1043}
1044
1045/**
1046 * @brief Capture get capture control by task name.
1047 *
1048 * This function returns the control @a by task name.
1049 *
1050 * @param[in] control The capture control.
1051 * @param[in] by The by index.
1052 *
1053 * @retval This function returns the control @a by task name.
1054 */
1055static inline rtems_name
1056rtems_capture_control_by_name (rtems_capture_control* control, int by)
1057{
1058  if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
1059    return control->by[by].name;
1060  return control->by[0].name;
1061}
1062
1063/**
1064 * @brief Capture get capture control by task id.
1065 *
1066 * This function returns the control @a by task id
1067 *
1068 * @retval This function returns the control @a by task id.
1069 */
1070static inline rtems_id
1071rtems_capture_control_by_id (rtems_capture_control* control, int by)
1072{
1073  if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
1074    return control->by[by].id;
1075  return control->by[0].id;
1076}
1077
1078/**
1079 * @brief Capture get capture control by task triggers.
1080 *
1081 * This function returns the control @a by task triggers.
1082 *
1083 * @retval This function returns the control @a by task triggers.
1084 */
1085static inline uint32_t
1086rtems_capture_control_by_triggers (rtems_capture_control* control,
1087                                   int                      by)
1088{
1089  if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
1090    return control->by[by].trigger;
1091  return control->by[0].trigger;
1092}
1093
1094/**
1095 * @brief Capture get capture control count.
1096 *
1097 * This function returns the number of controls the capture
1098 * engine has.
1099 *
1100 * @retval This function returns the number of controls the capture
1101 * engine has.
1102 */
1103static inline uint32_t
1104rtems_capture_control_count (void)
1105{
1106  rtems_capture_control* control = rtems_capture_get_control_list ();
1107  uint32_t               count = 0;
1108
1109  while (control)
1110  {
1111    count++;
1112    control = rtems_capture_next_control (control);
1113  }
1114
1115  return count;
1116}
1117
1118#ifdef __cplusplus
1119}
1120#endif
1121/**@}*/
1122
1123#endif
Note: See TracBrowser for help on using the repository browser.