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/sysinit.h>
0035 #include <rtems/score/timecounter.h>
0036 #include <rtems/score/watchdogimpl.h>
0037 
0038 static Watchdog_Interval _Record_Tick_interval;
0039 
0040 void _Record_Initialize( void )
0041 {
0042   Record_Control *control;
0043   size_t          control_size;
0044   uint32_t        cpu_max;
0045   uint32_t        cpu_index;
0046   unsigned int    item_count;
0047 
0048   cpu_max = rtems_configuration_get_maximum_processors();
0049   item_count = _Record_Configuration.item_count;
0050   control = _Record_Configuration.controls;
0051   control_size = sizeof( *control );
0052   control_size += sizeof( control->Items[ 0 ] ) * item_count;
0053 
0054   for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {
0055     Per_CPU_Control *cpu;
0056 
0057     cpu = _Per_CPU_Get_by_index( cpu_index );
0058     control->mask = item_count - 1U;
0059     cpu->record = control;
0060     control = (Record_Control *) ( (char *) control + control_size );
0061   }
0062 }
0063 
0064 static void _Record_Watchdog( Watchdog_Control *watchdog )
0065 {
0066   ISR_Level            level;
0067   rtems_record_context context;
0068   sbintime_t           now;
0069 
0070   _ISR_Local_disable( level );
0071   _Watchdog_Per_CPU_insert_ticks(
0072     watchdog,
0073     _Watchdog_Get_CPU( watchdog ),
0074     _Record_Tick_interval
0075   );
0076   now = _Timecounter_Sbinuptime();
0077   rtems_record_prepare_critical( &context, _Per_CPU_Get() );
0078   rtems_record_add(
0079     &context,
0080     RTEMS_RECORD_UPTIME_LOW,
0081     (uint32_t) ( now >> 0 )
0082   );
0083   rtems_record_add(
0084     &context,
0085     RTEMS_RECORD_UPTIME_HIGH,
0086     (uint32_t) ( now >> 32 )
0087   );
0088   rtems_record_commit_critical( &context );
0089   _ISR_Local_enable( level );
0090 }
0091 
0092 static void _Record_Initialize_watchdogs( void )
0093 {
0094   Watchdog_Interval interval;
0095   uint32_t          cpu_max;
0096   uint32_t          cpu_index;
0097   sbintime_t        now;
0098 
0099   interval = rtems_counter_frequency() / _Watchdog_Ticks_per_second;
0100   interval = ( UINT32_C( 1 ) << 22 ) / interval;
0101 
0102   if ( interval == 0 ) {
0103     interval = 1;
0104   }
0105 
0106   _Record_Tick_interval = interval;
0107 
0108   cpu_max = rtems_configuration_get_maximum_processors();
0109 
0110   for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {
0111     Per_CPU_Control *cpu;
0112     Record_Control  *control;
0113 
0114     cpu = _Per_CPU_Get_by_index( cpu_index );
0115     control = cpu->record;
0116     _Watchdog_Preinitialize( &control->Watchdog, cpu );
0117     _Watchdog_Initialize( &control->Watchdog, _Record_Watchdog );
0118     _Watchdog_Per_CPU_insert_ticks(
0119       &control->Watchdog,
0120       cpu,
0121       _Record_Tick_interval
0122     );
0123   }
0124 
0125   now = _Timecounter_Sbinuptime();
0126   rtems_record_produce_2(
0127     RTEMS_RECORD_UPTIME_LOW,
0128     (uint32_t) ( now >> 0 ),
0129     RTEMS_RECORD_UPTIME_HIGH,
0130     (uint32_t) ( now >> 32 )
0131   );
0132 }
0133 
0134 RTEMS_SYSINIT_ITEM(
0135   _Record_Initialize_watchdogs,
0136   RTEMS_SYSINIT_DEVICE_DRIVERS,
0137   RTEMS_SYSINIT_ORDER_LAST_BUT_5
0138 );