foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
database.c File Reference

Database module implementation. More...

#include "general.h"
#include "database.h"
#include "ftask.h"
#include "os.h"
#include <stdint.h>
#include <string.h>
Include dependency graph for database.c:

Go to the source code of this file.

Data Structures

struct  DATA_BASE_HEADER_s
 

Macros

#define DATA_MAX_QUEUE_TIMEOUT_MS   (10u)
 
#define DATA_QUEUE_TIMEOUT_MS   (DATA_MAX_QUEUE_TIMEOUT_MS / OS_TICK_RATE_MS)
 

Functions

 FAS_STATIC_ASSERT (DATA_QUEUE_TIMEOUT_MS > 0u, "invalid database queue timeout!")
 
static void DATA_IterateOverDatabaseEntries (const DATA_QUEUE_MESSAGE_s *kpReceiveMessage)
 
static STD_RETURN_TYPE_e DATA_AccessDatabaseEntries (DATA_BLOCK_ACCESS_TYPE_e accessType, void *pData0, void *pData1, void *pData2, void *pData3)
 
static void DATA_CopyData (DATA_BLOCK_ACCESS_TYPE_e accessType, uint32_t dataLength, void *pDatabaseStruct, void *pPassedDataStruct)
 
STD_RETURN_TYPE_e DATA_Initialize (void)
 Initialization of database manager. More...
 
void DATA_Task (void)
 trigger of database manager More...
 
void DATA_DummyFunction (void)
 Dummy void function of the database module. More...
 
STD_RETURN_TYPE_e DATA_Read1DataBlock (void *pDataToReceiver0)
 Reads one data block in database by value. More...
 
STD_RETURN_TYPE_e DATA_Read2DataBlocks (void *pDataToReceiver0, void *pDataToReceiver1)
 Reads two data blocks in database by value. More...
 
STD_RETURN_TYPE_e DATA_Read3DataBlocks (void *pDataToReceiver0, void *pDataToReceiver1, void *pDataToReceiver2)
 Reads three data blocks in database by value. More...
 
STD_RETURN_TYPE_e DATA_Read4DataBlocks (void *pDataToReceiver0, void *pDataToReceiver1, void *pDataToReceiver2, void *pDataToReceiver3)
 Reads four data blocks in database by value. More...
 
STD_RETURN_TYPE_e DATA_Write1DataBlock (void *pDataFromSender0)
 Stores one data block in database. More...
 
STD_RETURN_TYPE_e DATA_Write2DataBlocks (void *pDataFromSender0, void *pDataFromSender1)
 Stores two data blocks in database. More...
 
STD_RETURN_TYPE_e DATA_Write3DataBlocks (void *pDataFromSender0, void *pDataFromSender1, void *pDataFromSender2)
 Stores three data blocks in database. More...
 
STD_RETURN_TYPE_e DATA_Write4DataBlocks (void *pDataFromSender0, void *pDataFromSender1, void *pDataFromSender2, void *pDataFromSender3)
 Stores four data blocks in database. More...
 
void DATA_ExecuteDataBist (void)
 Executes a built-in self-test for the database module. More...
 

Variables

static const DATA_BASE_HEADER_s data_baseHeader
 device configuration of database More...
 
static uint8_t data_uniqueIdToDatabaseEntry [DATA_BLOCK_ID_MAX] = {0}
 uniqueId to respective database entry selector More...
 

Detailed Description

Database module implementation.

SPDX-License-Identifier: BSD-3-Clause

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
2015-08-18 (date of creation)
Updated
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
DATA

The database read/write functions put references to the database entries to be read/written in the database queue. The function DATA_Task() reads the queue to get the database entries to be read/written. Up to DATA_MAX_ENTRIES_PER_ACCESS entries can be read/written with the same function call. To avoid code duplication, the functions to read/write 1 to DATA_MAX_ENTRIES_PER_ACCESS-1 entries call the function to read/write DATA_MAX_ENTRIES_PER_ACCESS entries and use NULL_PTR for the entries that are not to be read/written. DATA_Task() checks that the first entry is not a NULL_PTR and asserts if it is not the case. If subsequent entries are found in the database queue, they are simply ignored if they are NULL_PTR.

Definition in file database.c.

Macro Definition Documentation

◆ DATA_MAX_QUEUE_TIMEOUT_MS

#define DATA_MAX_QUEUE_TIMEOUT_MS   (10u)

Maximum queue timeout time in milliseconds

Definition at line 80 of file database.c.

◆ DATA_QUEUE_TIMEOUT_MS

#define DATA_QUEUE_TIMEOUT_MS   (DATA_MAX_QUEUE_TIMEOUT_MS / OS_TICK_RATE_MS)

Definition at line 82 of file database.c.

Function Documentation

◆ DATA_AccessDatabaseEntries()

static STD_RETURN_TYPE_e DATA_AccessDatabaseEntries ( DATA_BLOCK_ACCESS_TYPE_e  accessType,
void *  pData0,
void *  pData1,
void *  pData2,
void *  pData3 
)
static

Definition at line 131 of file database.c.

Here is the call graph for this function:

◆ DATA_CopyData()

static void DATA_CopyData ( DATA_BLOCK_ACCESS_TYPE_e  accessType,
uint32_t  dataLength,
void *  pDatabaseStruct,
void *  pPassedDataStruct 
)
static

Definition at line 165 of file database.c.

Here is the call graph for this function:

◆ DATA_DummyFunction()

void DATA_DummyFunction ( void  )

Dummy void function of the database module.

This function is needed in the database module in order to implement the DATA_READ_DATA() and DATA_WRITE_DATA() in a ISO C99 standard compatible way. The invocation of a macro that accepts a variable number of arguments (and this is the case for DATA_READ_DATA() and DATA_WRITE_DATA()) needs more arguments in the invocation than there are parameters in the macro definition. For the most simple case, that DATA_READ_DATA() and DATA_WRITE_DATA() are only called with one argument, a violation of the standard would appear if the DATA_DummyFunction() would be omitted: GET_MACRO(databaseVariable, DATA_Read4DataBlocks, DATA_Read3DataBlocks, DATA_Read2DataBlocks, DATA_Read2DataBlocks, DATA_Read1DataBlock)(databaseVariable) So the macro invocation has six parameters, but it needs seven and an ISO C99 violation would appear. Adding the DATA_DummyFunction() fixes this violation. For details see 6.10.3 (paragraph 4) of the ISO C99 standard.

Definition at line 297 of file database.c.

◆ DATA_ExecuteDataBist()

void DATA_ExecuteDataBist ( void  )

Executes a built-in self-test for the database module.

This test writes and reads a database entry in order to check that the database module is working as expected. If the test fails, it will fail an assertion.

Definition at line 363 of file database.c.

◆ DATA_Initialize()

STD_RETURN_TYPE_e DATA_Initialize ( void  )

Initialization of database manager.

Returns
STD_OK if initialization successful, otherwise STD_NOT_OK

Definition at line 229 of file database.c.

Here is the call graph for this function:

◆ DATA_IterateOverDatabaseEntries()

static void DATA_IterateOverDatabaseEntries ( const DATA_QUEUE_MESSAGE_s kpReceiveMessage)
static

Definition at line 199 of file database.c.

Here is the call graph for this function:

◆ DATA_Read1DataBlock()

STD_RETURN_TYPE_e DATA_Read1DataBlock ( void *  pDataToReceiver0)

Reads one data block in database by value.

This function reads data from database and copy this content in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[out]pDataToReceiver0(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 300 of file database.c.

Here is the call graph for this function:

◆ DATA_Read2DataBlocks()

STD_RETURN_TYPE_e DATA_Read2DataBlocks ( void *  pDataToReceiver0,
void *  pDataToReceiver1 
)

Reads two data blocks in database by value.

This function reads data from database and copy this content in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[out]pDataToReceiver0(type: void *)
[out]pDataToReceiver1(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 305 of file database.c.

Here is the call graph for this function:

◆ DATA_Read3DataBlocks()

STD_RETURN_TYPE_e DATA_Read3DataBlocks ( void *  pDataToReceiver0,
void *  pDataToReceiver1,
void *  pDataToReceiver2 
)

Reads three data blocks in database by value.

This function reads data from database and copy this content in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[out]pDataToReceiver0(type: void *)
[out]pDataToReceiver1(type: void *)
[out]pDataToReceiver2(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 311 of file database.c.

Here is the call graph for this function:

◆ DATA_Read4DataBlocks()

STD_RETURN_TYPE_e DATA_Read4DataBlocks ( void *  pDataToReceiver0,
void *  pDataToReceiver1,
void *  pDataToReceiver2,
void *  pDataToReceiver3 
)

Reads four data blocks in database by value.

This function reads data from database and copy this content in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[out]pDataToReceiver0(type: void *)
[out]pDataToReceiver1(type: void *)
[out]pDataToReceiver2(type: void *)
[out]pDataToReceiver3(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 318 of file database.c.

Here is the call graph for this function:

◆ DATA_Task()

void DATA_Task ( void  )

trigger of database manager

TODO

Definition at line 279 of file database.c.

Here is the call graph for this function:

◆ DATA_Write1DataBlock()

STD_RETURN_TYPE_e DATA_Write1DataBlock ( void *  pDataFromSender0)

Stores one data block in database.

This function stores passed data in database and updates timestamp and previous timestamp in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[in,out]pDataFromSender0(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 331 of file database.c.

Here is the call graph for this function:

◆ DATA_Write2DataBlocks()

STD_RETURN_TYPE_e DATA_Write2DataBlocks ( void *  pDataFromSender0,
void *  pDataFromSender1 
)

Stores two data blocks in database.

This function stores passed data in database and updates timestamp and previous timestamp in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[in,out]pDataFromSender0(type: void *)
[in,out]pDataFromSender1(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 336 of file database.c.

Here is the call graph for this function:

◆ DATA_Write3DataBlocks()

STD_RETURN_TYPE_e DATA_Write3DataBlocks ( void *  pDataFromSender0,
void *  pDataFromSender1,
void *  pDataFromSender2 
)

Stores three data blocks in database.

This function stores passed data in database and updates timestamp and previous timestamp in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[in,out]pDataFromSender0(type: void *)
[in,out]pDataFromSender1(type: void *)
[in,out]pDataFromSender2(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 342 of file database.c.

Here is the call graph for this function:

◆ DATA_Write4DataBlocks()

STD_RETURN_TYPE_e DATA_Write4DataBlocks ( void *  pDataFromSender0,
void *  pDataFromSender1,
void *  pDataFromSender2,
void *  pDataFromSender3 
)

Stores four data blocks in database.

This function stores passed data in database and updates timestamp and previous timestamp in passed struct

Warning
Do not call this function from inside a critical section, as it is computationally complex.
Parameters
[in,out]pDataFromSender0(type: void *)
[in,out]pDataFromSender1(type: void *)
[in,out]pDataFromSender2(type: void *)
[in,out]pDataFromSender3(type: void *)
Returns
STD_OK if access was successful, otherwise STD_NOT_OK

Definition at line 350 of file database.c.

Here is the call graph for this function:

◆ FAS_STATIC_ASSERT()

FAS_STATIC_ASSERT ( DATA_QUEUE_TIMEOUT_MS  ,
0u  ,
"invalid database queue timeout!"   
)

Variable Documentation

◆ data_baseHeader

const DATA_BASE_HEADER_s data_baseHeader
static
Initial value:
= {
.nrDatabaseEntries = sizeof(data_database) / sizeof(DATA_BASE_s),
.pDatabase = &data_database[0],
}
DATA_BASE_s data_database[]
channel configuration of database (data blocks)
Definition: database_cfg.c:188

device configuration of database

all attributes of device configuration are listed here (pointer to channel list, number of channels)

Definition at line 99 of file database.c.

◆ data_uniqueIdToDatabaseEntry

uint8_t data_uniqueIdToDatabaseEntry[DATA_BLOCK_ID_MAX] = {0}
static

uniqueId to respective database entry selector

This array is the link between the uniqueId of a database entry and the actual position of the database entry in data_database[]. The IDs are set to its final value, when Data_Initialize is called.

Definition at line 110 of file database.c.