The foxBMS secondary mcu API documentation
diag.c File Reference

Diagnosis driver implementation. More...

#include "diag.h"
#include "com.h"
#include "os.h"
#include "rtc.h"
#include "stdio.h"
Include dependency graph for diag.c:

Functions

int _write (int fd, char *ptr, int len)
 
static void DIAG_Reset (void)
 DIAG_Reset resets/initializes all needed structures/buffers. More...
 
static uint8_t DIAG_EntryWrite (uint8_t eventID, DIAG_EVENT_e event, uint32_t item_nr)
 DIAG_EntryWrite adds an error entry. More...
 
STD_RETURN_TYPE_e DIAG_Init (DIAG_DEV_s *diag_dev_pointer, STD_RETURN_TYPE_e bkpramValid)
 DIAG_Init initializes all needed structures/buffers. More...
 
void DIAG_PrintErrors (void)
 DIAG_PrintErrors prints contents of the error buffer on user request. More...
 
DIAG_RETURNTYPE_e DIAG_Handler (DIAG_CH_ID_e diag_ch_id, DIAG_EVENT_e event, uint32_t item_nr)
 DIAG_Handler provides generic error handling, based on diagnosis group.This function calls the handler functions depending on the diagnosis group of call. It needs to get called in every function which wants to apply some kind of diagnosis handling. According to its return value further treatment is either left to the calling module itself, or can be done in the callback function defined in diag_cfg.c. More...
 
STD_RETURN_TYPE_e DIAG_checkEvent (STD_RETURN_TYPE_e cond, DIAG_CH_ID_e diag_ch_id, uint32_t item_nr)
 DIAG_checkEvent provides a simple interface to check an event for E_OK. More...
 
void DIAG_SysMon (void)
 overall system monitoring More...
 
void DIAG_SysMonNotify (DIAG_SYSMON_MODULE_ID_e module_id, uint32_t state)
 DIAG_SysMonNotify has to be called in every function using the system monitoring. More...
 
void DIAG_configASSERT (void)
 trap of configuration errors derived by FreeRTOS configASSERT More...
 

Variables

static DIAG_s diag
 
static DIAG_DEV_sdiag_devptr
 
static uint32_t diagsysmonTimestamp = 0
 
static uint8_t diag_locked = 0
 
DIAG_SYSMON_NOTIFICATION_s diag_sysmon [DIAG_SYSMON_MODULE_ID_MAX]
 
DIAG_SYSMON_NOTIFICATION_s diag_sysmon_last [DIAG_SYSMON_MODULE_ID_MAX]
 
uint32_t diag_sysmon_cnt [DIAG_SYSMON_MODULE_ID_MAX]
 
DIAG_ERROR_ENTRY_s MEM_BKP_SRAM diag_memory [DIAG_FAIL_ENTRY_LENGTH]
 
DIAG_ERROR_ENTRY_s MEM_BKP_SRAMdiag_entry_wrptr
 
DIAG_ERROR_ENTRY_s MEM_BKP_SRAMdiag_entry_rdptr
 
DIAG_CONTACTOR_ERROR_ENTRY_s MEM_BKP_SRAM diagContactorErrorMemory [DIAG_FAIL_ENTRY_CONTACTOR_LENGTH]
 
DIAG_CONTACTOR_ERROR_ENTRY_s MEM_BKP_SRAMdiagContactorError_entry_wrptr
 
DIAG_CONTACTOR_ERROR_ENTRY_s MEM_BKP_SRAMdiagContactorError_entry_rdptr
 
DIAG_FAILURECODE_s diag_fc
 

Detailed Description

Diagnosis driver implementation.

BSD 3-Clause License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:

″This product uses parts of foxBMS®″

″This product includes parts of foxBMS®″

″This product is derived from foxBMS®″

Author
foxBMS Team
Date
09.11.2015 (date of creation)
Module-prefix DIAG

This diagnose module is responsible for error handling and reporting. Reported errors are logged into the global database and can be reviewed on user request.

Function Documentation

◆ _write()

int _write ( int  fd,
char *  ptr,
int  len 
)

◆ DIAG_checkEvent()

STD_RETURN_TYPE_e DIAG_checkEvent ( STD_RETURN_TYPE_e  cond,
DIAG_CH_ID_e  diag_ch_id,
uint32_t  item_nr 
)

DIAG_checkEvent provides a simple interface to check an event for E_OK.

DIAG_checkEvent is a wrapper function for DIAG_Handler. In simple cases where a return value that is not E_OK (or a 0 casted to E_OK) should increase the error counter in a diagnosis channel, this function should be used instead of directly calling the DIAG_Handler().

Parameters
condcondition
diag_ch_idevent ID of the event that has occurred
item_nritem nr of event, to distinguish between different calling locations of the event
Returns
E_OK if ok, E_NOK if not ok
Here is the call graph for this function:

◆ DIAG_configASSERT()

void DIAG_configASSERT ( void  )

trap of configuration errors derived by FreeRTOS configASSERT

Here is the call graph for this function:

◆ DIAG_EntryWrite()

static uint8_t DIAG_EntryWrite ( uint8_t  eventID,
DIAG_EVENT_e  event,
uint32_t  item_nr 
)
static

DIAG_EntryWrite adds an error entry.

This function adds an entry to the error buffer. It provides some functionality to prevent duplicates from being logged. Multiple occurring error doesn't get logged anymore after they reached a pre-defined error count.

Parameters
eventIDID of entry
eventOK, NOK or RESET
item_nritem number of event
Returns
0xFF if event is logged, otherwise 0
Here is the call graph for this function:

◆ DIAG_Init()

STD_RETURN_TYPE_e DIAG_Init ( DIAG_DEV_s diag_dev_pointer,
STD_RETURN_TYPE_e  bkpramValid 
)

DIAG_Init initializes all needed structures/buffers.

This function provides initialization of the diagnose module. In case of miss behaviour it calls Reset and adds an entry into database to ensure data validity/report back malfunction

Parameters
diag_dev_pointer
Here is the call graph for this function:

◆ DIAG_PrintErrors()

void DIAG_PrintErrors ( void  )

DIAG_PrintErrors prints contents of the error buffer on user request.

This function prints out complete error buffer using the UART interface.

◆ DIAG_Reset()

static void DIAG_Reset ( void  )
static

DIAG_Reset resets/initializes all needed structures/buffers.

This function gets called during initialization of the diagnose module. It clears memory and counters used by diag later on.

◆ DIAG_SysMon()

void DIAG_SysMon ( void  )

overall system monitoring

checks notifications (state and timestamps) of all system-relevant tasks or functions all checks should be customized corresponding to its timing and state requirements

Here is the call graph for this function:

◆ DIAG_SysMonNotify()

void DIAG_SysMonNotify ( DIAG_SYSMON_MODULE_ID_e  module_id,
uint32_t  state 
)

DIAG_SysMonNotify has to be called in every function using the system monitoring.

Parameters
module_idmodule id to notify system monitoring
statestate of module
Here is the call graph for this function:

Variable Documentation

◆ diag

DIAG_s diag
static

◆ diag_devptr

DIAG_DEV_s* diag_devptr
static

◆ diag_entry_rdptr

DIAG_ERROR_ENTRY_s MEM_BKP_SRAM* diag_entry_rdptr

◆ diag_entry_wrptr

DIAG_ERROR_ENTRY_s MEM_BKP_SRAM* diag_entry_wrptr

◆ diag_fc

◆ diag_locked

uint8_t diag_locked = 0
static

◆ diag_memory

◆ diag_sysmon

◆ diag_sysmon_cnt

uint32_t diag_sysmon_cnt[DIAG_SYSMON_MODULE_ID_MAX]

◆ diag_sysmon_last

◆ diagContactorError_entry_rdptr

DIAG_CONTACTOR_ERROR_ENTRY_s MEM_BKP_SRAM* diagContactorError_entry_rdptr

◆ diagContactorError_entry_wrptr

DIAG_CONTACTOR_ERROR_ENTRY_s MEM_BKP_SRAM* diagContactorError_entry_wrptr

◆ diagContactorErrorMemory

◆ diagsysmonTimestamp

uint32_t diagsysmonTimestamp = 0
static