ME507 Utility Library  0.2.1
Mechatronics Course Support Software for ARM/Arduino/FreeRTOS
baseshare.h
Go to the documentation of this file.
1 //*****************************************************************************
2 /** @file baseshare.h
3  * @brief Headers for a base class for type-safe, thread-safe task data
4  * exchange classes.
5  * @details This file contains a base class for classes which exchange data
6  * between tasks. Inter-task data must be exchanged in a thread-safe
7  * manner, so the classes which share the data use mutexes or mutual
8  * exclusion mechanisms to prevent corruption of data. A linked list
9  * of all inter-task data items is kept by this system, and this base
10  * class contains members that handle that linked list.
11  *
12  * @date 2014-Oct-18 JRR Created file
13  * @date 2020-Oct-19 JRR Modified for use with Arduino/FreeRTOS platform
14  *
15  * License:
16  * This file is copyright 2014 - 2020 by JR Ridgely and released under the
17  * Lesser GNU Public License, version 2. It intended for educational use
18  * only, but its use is not limited thereto. */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIB-
23  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29  * THE POSSIBILITY OF SUCH DAMAGE. */
30 //*****************************************************************************
31 
32 // This define prevents this .h file from being included more than once
33 #ifndef _BASESHARE_H_
34 #define _BASESHARE_H_
35 
36 #include <Arduino.h>
37 
38 // Different functions are used in STM32's and ESP32's to determine if the CPU
39 // is currently running within an interrupt service routine
40 #ifdef ESP32
41  #define CHECK_IF_IN_ISR() xPortInIsrContext()
42 #elif (defined STM32F4xx || defined STM32L4xx)
43  #define CHECK_IF_IN_ISR() xPortIsInsideInterrupt()
44 #endif
45 
46 
47 /** @brief Base class for classes that share data in a thread-safe manner
48  * between tasks.
49  * @details This is a base class for classes which share data between tasks
50  * without the risk of data corruption associated with global
51  * variables. Queues and task shares are two examples of such shared
52  * data classes.
53  */
54 class BaseShare
55 {
56  protected:
57  /** @brief The name of the shared item.
58  * @details This string holds the shared item's name. The name is only
59  * used for identification on debugging printouts or logs.
60  */
61  char name[16];
62 
63  /** @brief Pointer to the next item in the linked list of shares.
64  * @details This pointer points to the next item in the system's list
65  * of shared data items (shares, queues, @e etc.) If this
66  * share is the most recently created one, the pointer will
67  * be @c NULL. The list goes backwards; the next item is the
68  * previously created one.
69  */
71 
72  /** @brief Pointer to the most recently created shared data item.
73  * @details This @c static variable, one copy of which is shared by
74  * all shared data items, is a pointer to the most recently
75  * created one. It is used as the beginning of a linked list
76  * of all shared data items in the system.
77  */
79 
80  public:
81  // Construct a base shared data item
82  BaseShare (const char* p_name = NULL);
83 
84  /** @brief Print one shared data item within a list.
85  * @details Make a printout showing the condition of this shared data
86  * item, such as the value of a shared variable or how full a
87  * queue's buffer is. This method must be overridden in each
88  * descendent class with a method that actually @e does
89  * something.
90  * @param printer Reference to a serial device on which to print
91  */
92  virtual void print_in_list (Print& printer) = 0;
93 
94  // }
95  friend void print_all_shares (Print& printer);
96 };
97 
98 
99 // Function that prints a list of shares and queues
100 void print_all_shares (Print& printer);
101 
102 #endif // _BASESHARE_H_
BaseShare::print_all_shares
friend void print_all_shares(Print &printer)
Start the printout showing the status of all shared data items.
Definition: baseshare.cpp:74
BaseShare::print_in_list
virtual void print_in_list(Print &printer)=0
Print one shared data item within a list.
BaseShare::name
char name[16]
The name of the shared item.
Definition: baseshare.h:61
BaseShare::p_next
BaseShare * p_next
Pointer to the next item in the linked list of shares.
Definition: baseshare.h:70
BaseShare::p_newest
static BaseShare * p_newest
Pointer to the most recently created shared data item.
Definition: baseshare.h:78
BaseShare::BaseShare
BaseShare(const char *p_name=NULL)
Construct a base shared data item.
Definition: baseshare.cpp:46
print_all_shares
void print_all_shares(Print &printer)
Start the printout showing the status of all shared data items.
Definition: baseshare.cpp:74
BaseShare
Base class for classes that share data in a thread-safe manner between tasks.
Definition: baseshare.h:54