Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RegulatorInternalAPI
0007  *
0008  * @brief Regulator Library Implementation Support
0009  */
0010 
0011 /*
0012  * Copyright (C) 2023 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 /**
0037  * @defgroup RegulatorInternalAPI Regulator API Internals
0038  *
0039  * @brief Regulator Internal Information
0040  *
0041  * This concerns implementation information about the Regulator.
0042  */
0043 
0044 #ifndef RTEMS_REGULATORIMPL_H
0045 #define RTEMS_REGULATORIMPL_H
0046 
0047 #include <stdatomic.h>
0048 
0049 #include <rtems/chain.h>
0050 
0051 
0052 /**
0053  * @ingroup RegulatorInternalAPI
0054  *
0055  * This constant is used to indicate the regulator instance is initialized.
0056  */
0057 #define REGULATOR_INITIALIZED 0xDeadF00d
0058 
0059 /**
0060  * @ingroup RegulatorInternalAPI
0061  *
0062  * @brief Regulator Message Instance Management Structure
0063  */
0064 typedef struct {
0065   /** This points to the message contents. */
0066   void   *buffer;
0067   /** This is the length of the message. */
0068   size_t  length;
0069 } _Regulator_Message_t;
0070 
0071 /**
0072  * @ingroup RegulatorInternalAPI
0073  *
0074  * @brief Regulator Statistics Private Structure
0075  *
0076  * An instance of this structure is allocated per regulator instance.
0077  */
0078 typedef struct {
0079   /** Number of successfully obtained buffers. */
0080   atomic_size_t    obtained;
0081   
0082   /** Number of successfully released buffers. */
0083   atomic_size_t    released;
0084 
0085   /** Number of successfully delivered buffers. */
0086   atomic_size_t    delivered;
0087 } _Regulator_Statistics;
0088  
0089 /**
0090  * @ingroup RegulatorInternalAPI
0091  *
0092  * @brief Regulator Instance Private Structure
0093  *
0094  * An instance of this structure is allocated per regulator instance.
0095  */
0096 typedef struct {
0097   /** Has magic value when instance is usable */
0098   uint32_t   initialized;
0099 
0100   /** Attributes for this instance -- copied from user */
0101   rtems_regulator_attributes  Attributes;
0102 
0103   /** Pointer to allocated message memory */
0104   void *message_memory;
0105 
0106   /** Pointer to allocated memory for RTEMS Message Queue for pending buffers*/
0107   void *message_queue_storage;
0108 
0109   /** RTEMS Message Queue of pending outgoing messages */
0110   rtems_id  queue_id;
0111 
0112   /** RTEMS Partition for pool of unused messages */
0113   rtems_id  messages_partition_id;
0114 
0115   /** RTEMS Task for performing output */
0116   rtems_id  delivery_thread_id;
0117 
0118   /** Id of period used by output thread */
0119   rtems_id  delivery_thread_period_id;
0120 
0121   /** Indicates Delivery thread is running */
0122   bool  delivery_thread_is_running;
0123 
0124   /** Indicates Delivery thread has been requested to exit */
0125   bool  delivery_thread_request_exit;
0126 
0127   /** Indicates Delivery thread has exited */
0128   bool  delivery_thread_has_exited;
0129 
0130   /** Internal Statistics */
0131   _Regulator_Statistics Statistics;
0132 
0133 } _Regulator_Control;
0134 
0135 #endif /* RTEMS_REGULATORIMPL_H */