Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:18

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief Print misc stuff for the monitor dump routines
0007  *
0008  * Each routine returns the number of characters it output.
0009  */
0010 
0011 /*
0012  * COPYRIGHT (c) 1989-2022. On-Line Applications Research Corporation (OAR).
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039 
0040 #include <rtems.h>
0041 #include <rtems/monitor.h>
0042 #include <rtems/assoc.h>
0043 
0044 #include <stdio.h>
0045 #include <ctype.h>
0046 #include <inttypes.h>
0047 
0048 void
0049 rtems_monitor_separator(void)
0050 {
0051     fprintf(stdout,"------------------------------------------------------------------------------\n");
0052 }
0053 
0054 uint32_t
0055 rtems_monitor_pad(
0056     uint32_t    destination_column,
0057     uint32_t    current_column
0058 )
0059 {
0060     int pad_length;
0061 
0062     if (destination_column <= current_column)
0063         pad_length = 1;
0064     else
0065         pad_length = destination_column - current_column;
0066 
0067     return fprintf(stdout,"%*s", pad_length, "");
0068 }
0069 
0070 int
0071 rtems_monitor_dump_decimal(uint32_t   num)
0072 {
0073     return fprintf(stdout,"%4" PRId32, num);
0074 }
0075 
0076 int
0077 rtems_monitor_dump_addr(const void *addr)
0078 {
0079     return fprintf(stdout,"%08" PRIxPTR, (intptr_t) addr);
0080 }
0081 
0082 int
0083 rtems_monitor_dump_hex(uint32_t   num)
0084 {
0085     return fprintf(stdout,"0x%" PRIx32, num);
0086 }
0087 
0088 static int
0089 rtems_monitor_dump_assoc_bitfield(
0090     const rtems_assoc_t *ap,
0091     const char          *separator,
0092     uint32_t             value
0093   )
0094 {
0095     uint32_t   b;
0096     uint32_t   length = 0;
0097     const char *name;
0098 
0099     for (b = 1; b; b <<= 1)
0100         if (b & value)
0101         {
0102             if (length)
0103                 length += fprintf(stdout,"%s", separator);
0104 
0105             name = rtems_assoc_name_by_local(ap, b);
0106 
0107             if (name)
0108                 length += fprintf(stdout,"%s", name);
0109             else
0110                 length += fprintf(stdout,"0x%" PRIx32, b);
0111         }
0112 
0113     return length;
0114 }
0115 
0116 int
0117 rtems_monitor_dump_id(rtems_id id)
0118 {
0119     return fprintf(stdout,"%08" PRIx32, id);
0120 }
0121 
0122 int
0123 rtems_monitor_dump_name(rtems_id id)
0124 {
0125     char name_buffer[18] = "????";
0126 
0127     rtems_object_get_name( id, sizeof(name_buffer), name_buffer );
0128 
0129     return fprintf(stdout, "%s", name_buffer);
0130 }
0131 
0132 int
0133 rtems_monitor_dump_priority(rtems_task_priority priority)
0134 {
0135     return fprintf(stdout,"%3" PRId32, priority);
0136 }
0137 
0138 int
0139 rtems_monitor_dump_state(States_Control state)
0140 {
0141     char buf[16];
0142 
0143     rtems_assoc_thread_states_to_string(state, buf, sizeof(buf));
0144     return fprintf(stdout, "%s", buf);
0145 }
0146 
0147 static const rtems_assoc_t rtems_monitor_attribute_assoc[] = {
0148     { "GL",  RTEMS_GLOBAL, 0 },
0149     { "PR",  RTEMS_PRIORITY, 0 },
0150     { "FL",  RTEMS_FLOATING_POINT, 0 },
0151     { "BI",  RTEMS_BINARY_SEMAPHORE, 0 },
0152     { "SB",  RTEMS_SIMPLE_BINARY_SEMAPHORE, 0 },
0153     { "IN",  RTEMS_INHERIT_PRIORITY, 0 },
0154     { "CE",  RTEMS_PRIORITY_CEILING, 0 },
0155     { "AR",  RTEMS_BARRIER_AUTOMATIC_RELEASE, 0 },
0156     { "ST",  RTEMS_SYSTEM_TASK, 0 },
0157     { 0, 0, 0 },
0158 };
0159 
0160 int
0161 rtems_monitor_dump_attributes(rtems_attribute attributes)
0162 {
0163     int   length = 0;
0164 
0165     if (attributes == RTEMS_DEFAULT_ATTRIBUTES)  /* value is 0 */
0166         length += fprintf(stdout,"DEFAULT");
0167 
0168     length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_attribute_assoc,
0169                                                 ":",
0170                                                 attributes);
0171     return length;
0172 }
0173 
0174 static const rtems_assoc_t rtems_monitor_modes_assoc[] = {
0175     { "nP",     RTEMS_NO_PREEMPT, 0 },
0176     { "T",      RTEMS_TIMESLICE, 0 },
0177     { "nA",     RTEMS_NO_ASR, 0 },
0178     { 0, 0, 0 },
0179 };
0180 
0181 int
0182 rtems_monitor_dump_modes(rtems_mode modes)
0183 {
0184     uint32_t   length = 0;
0185 
0186     if (modes == RTEMS_DEFAULT_MODES)  /* value is 0 */
0187         length += fprintf(stdout,"P:T:nA");
0188 
0189     length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_modes_assoc,
0190                                                 ":",
0191                                                 modes);
0192     return length;
0193 }
0194 
0195 int
0196 rtems_monitor_dump_events(rtems_event_set events)
0197 {
0198     if (events == 0)
0199         return fprintf(stdout,"  NONE  ");
0200 
0201     return fprintf(stdout,"%08" PRIx32, events);
0202 }