rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Typedefs | Functions
shared_params.c File Reference

Typedefs

typedef struct t_shared_params_buffer tSharedParamsBuffer
 Layout of the shared parameters RAM buffer.
 

Functions

static tSharedParamsBuffer sharedParamsBuffer __attribute__ ((section(".shared")))
 
static bool SharedParamsValidateBuffer (void)
 Validates the shared parameter buffer contents by looking at the table identifier and verifying its checksum.
 
static void SharedParamsWriteChecksum (void)
 Calculates and writes the checksum into the buffer.
 
static bool SharedParamsVerifyChecksum (void)
 Calculates and verifies the checksum that is currently present in the buffer.
 
static uint16_t SharedParamsCalculateChecksum (void)
 Calculates and returns the checksum value for the current contents in the buffer. The checksum is calculated by taking the sum of all bytes in the parameter buffer (excluding the checksum at the end) and them taking the two's complement value of it.
 
void SharedParamsInit (void)
 Initializes the shared RAM parameters module.
 
bool SharedParamsReadByIndex (uint32_t idx, uint8_t *value)
 Reads a data byte from the shared parameter buffer at the specified index.
 
bool SharedParamsWriteByIndex (uint32_t idx, uint8_t value)
 Writes a data byte to the shared parameter buffer at the specified index.
 

Typedef Documentation

◆ tSharedParamsBuffer

typedef struct t_shared_params_buffer tSharedParamsBuffer

Layout of the shared parameters RAM buffer.

Function Documentation

◆ __attribute__()

static tSharedParamsBuffer sharedParamsBuffer __attribute__ ( (section(".shared"))  )
static

◆ SharedParamsCalculateChecksum()

static uint16_t SharedParamsCalculateChecksum ( void  )
static

Calculates and returns the checksum value for the current contents in the buffer. The checksum is calculated by taking the sum of all bytes in the parameter buffer (excluding the checksum at the end) and them taking the two's complement value of it.

Returns
The calculated checksum value.

Definition at line 232 of file shared_params.c.

233{
234 uint16_t result = 0;
235 uint32_t byteIdx;
236
237 /* Add the identifier bytes to the checksum. */
238 result += (uint8_t)sharedParamsBuffer.identifier;
239 result += (uint8_t)(sharedParamsBuffer.identifier >> 8u);
240 result += (uint8_t)(sharedParamsBuffer.identifier >> 16u);
241 result += (uint8_t)(sharedParamsBuffer.identifier >> 24u);
242 /* Loop through the parameter data array. */
243 for (byteIdx=0; byteIdx<SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++)
244 {
245 /* Add parameter data byte to the checksum. */
246 result += (uint8_t)sharedParamsBuffer.data[byteIdx];
247 }
248 /* Determine one's complement. */
249 result = ~result;
250 /* Determine two's complement. */
251 result += 1;
252 /* Give the result back to the caller. */
253 return result;
254} /*** end of SharedParamsCalculateChecksum ***/

Referenced by SharedParamsVerifyChecksum(), and SharedParamsWriteChecksum().

Here is the caller graph for this function:

◆ SharedParamsInit()

void SharedParamsInit ( void  )

Initializes the shared RAM parameters module.

Returns
none.

Definition at line 83 of file shared_params.c.

84{
85 uint32_t byteIdx;
86
87 /* The shared parameter buffer does not get initialized by the C-startup code. Another
88 * previously running program could have initialized it, in which case it is ready
89 * for use and nothing more needs to be done.
90 */
92 {
93 /* The shared parameter buffer was not yet initialized by a running program. This
94 * typically happens after a cold reset where the RAM contents were lost. In this
95 * case we need to explicitly configure and initialize it, since the C-startup code
96 * was configured to not do this.
97 *
98 * The initialization consists of setting the buffer identifier, zeroing the
99 * actual parameter data and updating the checksum at the end.
100 */
101 sharedParamsBuffer.identifier = SHARED_PARAMS_BUFFER_ID;
102 for (byteIdx=0; byteIdx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++)
103 {
104 sharedParamsBuffer.data[byteIdx] = 0;
105 }
107 }
108} /*** end of SharedParamsInit ***/
static void SharedParamsWriteChecksum(void)
Calculates and writes the checksum into the buffer.
static bool SharedParamsValidateBuffer(void)
Validates the shared parameter buffer contents by looking at the table identifier and verifying its c...

Referenced by jump_to_openblt(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SharedParamsReadByIndex()

bool SharedParamsReadByIndex ( uint32_t  idx,
uint8_t *  value 
)

Reads a data byte from the shared parameter buffer at the specified index.

Parameters
idxIndex into the parameter data array. A valid value is between 0 and (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1).
valuePointer to where the read data value is stored.
Returns
True if successful, false otherwise.

Definition at line 119 of file shared_params.c.

120{
121 bool result = false;
122
123 /* Only continue if the buffer and the specified parameters are valid. */
125 (idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) &&
126 (value != NULL) )
127 {
128 /* Read the value and update the result. */
129 *value = sharedParamsBuffer.data[idx];
130 result = true;
131 }
132 /* Give the result back to the caller. */
133 return result;
134} /*** end of SharedParamsReadByIndex ***/

Referenced by checkIfRebootIntoOpenBltRequested(), and checkIfResetLoop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SharedParamsValidateBuffer()

static bool SharedParamsValidateBuffer ( void  )
static

Validates the shared parameter buffer contents by looking at the table identifier and verifying its checksum.

Returns
True if successful, false otherwise.

Definition at line 175 of file shared_params.c.

176{
177 bool result = false;
178
179 /* Perform validation. */
180 if ( (sharedParamsBuffer.identifier == SHARED_PARAMS_BUFFER_ID) &&
182 {
183 /* The shared parameter buffer is valid, so update the result value. */
184 result = true;
185 }
186 /* Give the result back to the caller. */
187 return result;
188} /*** end of SharedParamsValitabeTable ***/
static bool SharedParamsVerifyChecksum(void)
Calculates and verifies the checksum that is currently present in the buffer.

Referenced by SharedParamsInit(), SharedParamsReadByIndex(), and SharedParamsWriteByIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SharedParamsVerifyChecksum()

static bool SharedParamsVerifyChecksum ( void  )
static

Calculates and verifies the checksum that is currently present in the buffer.

Returns
True is the checksum is correct, false otherwise.

Definition at line 209 of file shared_params.c.

210{
211 bool result = false;
212
213 /* Calculate and verify the checksum. */
214 if (SharedParamsCalculateChecksum() == sharedParamsBuffer.checksum)
215 {
216 /* Checksum is correct, so update the result value. */
217 result = true;
218 }
219 /* Give the result back to the caller. */
220 return result;
221} /*** end of SharedParamsVerifyChecksum ***/
static uint16_t SharedParamsCalculateChecksum(void)
Calculates and returns the checksum value for the current contents in the buffer. The checksum is cal...

Referenced by SharedParamsValidateBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SharedParamsWriteByIndex()

bool SharedParamsWriteByIndex ( uint32_t  idx,
uint8_t  value 
)

Writes a data byte to the shared parameter buffer at the specified index.

Parameters
idxIndex into the parameter data array. A valid value is between 0 and (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1).
valueValue to write.
Returns
True if successful, false otherwise.

Definition at line 145 of file shared_params.c.

146{
147 bool result = false;
148
149 /* Only continue if the buffer and the specified parameters are valid. */
151 (idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) )
152 {
153 /* Write the value. */
154 sharedParamsBuffer.data[idx] = value;
155 /* Update the checksum since the contents were just changed. */
157 /* Update the result. */
158 result = true;
159 #if CORTEX_MODEL == 7
160 // If we have a cache, drop the relevant cache lines.
161 SCB_CleanDCache_by_Addr((uint32_t*)&sharedParamsBuffer, sizeof(sharedParamsBuffer));
162 #endif
163 }
164 /* Give the result back to the caller. */
165 return result;
166} /*** end of SharedParamsWriteByIndex ***/

Referenced by checkIfRebootIntoOpenBltRequested(), checkIfResetLoop(), jump_to_openblt(), and tryResetWatchdog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SharedParamsWriteChecksum()

static void SharedParamsWriteChecksum ( void  )
static

Calculates and writes the checksum into the buffer.

Returns
none.

Definition at line 196 of file shared_params.c.

197{
198 /* Calculate and write the checksum. */
199 sharedParamsBuffer.checksum = SharedParamsCalculateChecksum();
200} /*** end of SharedParamsWriteChecksum ***/

Referenced by SharedParamsInit(), and SharedParamsWriteByIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.