Back to home page

LXR

 
 

    


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

0001 /*
0002  * SPDX-License-Identifier: BSD-2-Clause
0003  *
0004  * Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <rtems/record.h>
0033 #include <rtems/config.h>
0034 #include <rtems/score/assert.h>
0035 
0036 #include <string.h>
0037 
0038 RTEMS_STATIC_ASSERT( RTEMS_RECORD_USER_0 == 512, RTEMS_RECORD_USER_0 );
0039 
0040 RTEMS_STATIC_ASSERT( RTEMS_RECORD_LAST == 1023, RTEMS_RECORD_LAST );
0041 
0042 RTEMS_STATIC_ASSERT(
0043   RTEMS_RECORD_LAST + 1 == ( 1 << RTEMS_RECORD_EVENT_BITS ),
0044   RTEMS_RECORD_EVENT_BITS
0045 );
0046 
0047 void rtems_record_produce( rtems_record_event event, rtems_record_data data )
0048 {
0049   rtems_record_context context;
0050 
0051   rtems_record_prepare( &context );
0052   rtems_record_add( &context, event, data );
0053   rtems_record_commit( &context );
0054 }
0055 
0056 void rtems_record_produce_2(
0057   rtems_record_event event_0,
0058   rtems_record_data  data_0,
0059   rtems_record_event event_1,
0060   rtems_record_data  data_1
0061 )
0062 {
0063   rtems_record_context context;
0064 
0065   rtems_record_prepare( &context );
0066   rtems_record_add( &context, event_0, data_0 );
0067   rtems_record_add( &context, event_1, data_1 );
0068   rtems_record_commit( &context );
0069 }
0070 
0071 void rtems_record_produce_n(
0072   const rtems_record_item *items,
0073   size_t                   n
0074 )
0075 {
0076   rtems_record_context context;
0077 
0078   _Assert( n > 0 );
0079 
0080   rtems_record_prepare( &context );
0081 
0082   do {
0083     rtems_record_add( &context, items->event, items->data );
0084     ++items;
0085     --n;
0086   } while ( n > 0 );
0087 
0088   rtems_record_commit( &context );
0089 }
0090 
0091 size_t _Record_String_to_items(
0092   rtems_record_event  event,
0093   const char         *str,
0094   size_t              len,
0095   rtems_record_item  *items,
0096   size_t              item_count
0097 )
0098 {
0099   size_t s;
0100   size_t i;
0101 
0102   s = 0;
0103   i = 0;
0104 
0105   while ( s < len && i < item_count ) {
0106     rtems_record_data data;
0107     size_t            k;
0108 
0109     data = 0;
0110 
0111     for ( k = 0; s < len && k < sizeof( data ); ++k ) {
0112       rtems_record_data c;
0113 
0114       c = (unsigned char) str[ s ];
0115       data |= c << ( k * 8 );
0116       ++s;
0117     }
0118 
0119     items[ i ].event = event;
0120     items[ i ].data = data;
0121     ++i;
0122   }
0123 
0124   return i;
0125 }