foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests API Documentation
sys_mon.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file sys_mon.c
44  * @author foxBMS Team
45  * @date 2019-11-28 (date of creation)
46  * @updated 2020-05-28 (date of last update)
47  * @ingroup ENGINE
48  * @prefix SYSM
49  *
50  * @brief TODO
51  */
52 
53 /*========== Includes =======================================================*/
54 #include "sys_mon.h"
55 
56 #include "diag.h"
57 #include "os.h"
58 
59 /*========== Macros and Definitions =========================================*/
60 
61 /*========== Static Constant and Variable Definitions =======================*/
62 /** tracking variable for System monitoring notifications */
64 
65 /*========== Extern Constant and Variable Definitions =======================*/
66 
67 /*========== Static Function Prototypes =====================================*/
68 
69 /*========== Static Function Implementations ================================*/
70 
71 /*========== Extern Function Implementations ================================*/
73  static uint32_t sysm_timestamp = 0;
74 
75  /** early exit if nothing to do */
76  uint32_t local_timer = OS_GetTickCount();
77  if (sysm_timestamp == local_timer) {
78  return;
79  }
80  sysm_timestamp = local_timer;
81 
82  uint32_t time_since_last_call = 0;
83  uint32_t max_allowed_jitter = 0;
84 
85  for (SYSM_TASK_ID_e taskId = (SYSM_TASK_ID_e)0; taskId < SYSM_TASK_ID_MAX; taskId++) {
86  if (sysm_ch_cfg[taskId].enable == SYSM_ENABLED) {
87  /* check that the task gets called within its timing threshold plus jitter and
88  then check that the tasks duration is shorter than tasks cycle time */
89  time_since_last_call = local_timer - sysm_notifications[taskId].timestampEnter;
90  max_allowed_jitter = sysm_ch_cfg[taskId].cycleTime + sysm_ch_cfg[taskId].maxJitter;
91  if ((time_since_last_call > max_allowed_jitter) &&
92  (sysm_notifications[taskId].duration > sysm_ch_cfg[taskId].cycleTime)) {
93  /* module not running within its timed limits */
95  if (sysm_ch_cfg[taskId].enableRecording == SYSM_RECORDING_ENABLED) {
96  /* TODO add recording function (when MRAM/FRAM are available) */
97  }
98  sysm_ch_cfg[taskId].callbackfunc(taskId);
99  }
100  }
101  }
102 }
103 
104 void SYSM_Notify(SYSM_TASK_ID_e taskId, SYSM_NOTIFY_TYPE_e state, uint32_t time) {
105  if (taskId < SYSM_TASK_ID_MAX) {
106  sysm_notifications[taskId].state = state;
108  if (SYSM_NOTIFY_ENTER == state) {
109  sysm_notifications[taskId].timestampEnter = time;
110  } else if (SYSM_NOTIFY_EXIT == state) {
111  sysm_notifications[taskId].timestampExit = time;
113  } else {
114  /* state has an illegal value */
116  }
118  }
119 }
120 
121 /*========== Getter for static Variables (Unit Test) ========================*/
122 #ifdef UNITY_UNIT_TEST
124  return sysm_notifications;
125 }
126 #endif
127 
128 /*========== Externalized Static Function Implementations (Unit Test) =======*/
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diag_id, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
Definition: diag.c:226
Diagnosis driver header.
@ DIAG_SYSTEM
Definition: diag_cfg.h:248
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:236
@ DIAG_ID_SYSTEMMONITORING
Definition: diag_cfg.h:158
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:235
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:110
Declaration of the OS wrapper interface.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:125
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:121
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:129
uint8_t maxJitter
Definition: sys_mon_cfg.h:98
void(* callbackfunc)(SYSM_TASK_ID_e taskID)
Definition: sys_mon_cfg.h:101
uint8_t cycleTime
Definition: sys_mon_cfg.h:97
uint32_t duration
Definition: sys_mon.h:71
uint32_t timestampEnter
Definition: sys_mon.h:69
SYSM_NOTIFY_TYPE_e state
Definition: sys_mon.h:68
uint32_t timestampExit
Definition: sys_mon.h:70
SYSM_NOTIFICATION_s * TEST_SYSM_GetNotifications(void)
Definition: sys_mon.c:123
void SYSM_CheckNotifications(void)
overall system monitoring
Definition: sys_mon.c:72
static SYSM_NOTIFICATION_s sysm_notifications[SYSM_TASK_ID_MAX]
Definition: sys_mon.c:63
void SYSM_Notify(SYSM_TASK_ID_e taskId, SYSM_NOTIFY_TYPE_e state, uint32_t time)
Sets needed bits to indicate that a task is running.
Definition: sys_mon.c:104
enum SYSM_NOTIFY_TYPE SYSM_NOTIFY_TYPE_e
@ SYSM_NOTIFY_ENTER
Definition: sys_mon.h:62
@ SYSM_NOTIFY_EXIT
Definition: sys_mon.h:63
SYSM_MONITORING_CFG_s sysm_ch_cfg[]
Definition: sys_mon_cfg.c:66
@ SYSM_ENABLED
Definition: sys_mon_cfg.h:89
@ SYSM_TASK_ID_MAX
Definition: sys_mon_cfg.h:78
@ SYSM_RECORDING_ENABLED
Definition: sys_mon_cfg.h:83
enum SYSM_TASK_ID SYSM_TASK_ID_e