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 237 of file shared_params.c.

238{
239 uint16_t result = 0;
240 uint32_t byteIdx;
241
242 /* Add the identifier bytes to the checksum. */
243 result += (uint8_t)sharedParamsBuffer.identifier;
244 result += (uint8_t)(sharedParamsBuffer.identifier >> 8u);
245 result += (uint8_t)(sharedParamsBuffer.identifier >> 16u);
246 result += (uint8_t)(sharedParamsBuffer.identifier >> 24u);
247 /* Loop through the parameter data array. */
248 for (byteIdx=0; byteIdx<SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++)
249 {
250 /* Add parameter data byte to the checksum. */
251 result += (uint8_t)sharedParamsBuffer.data[byteIdx];
252 }
253 /* Determine one's complement. */
254 result = ~result;
255 /* Determine two's complement. */
256 result += 1;
257 /* Give the result back to the caller. */
258 return result;
259} /*** 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 180 of file shared_params.c.

181{
182 bool result = false;
183
184 /* Perform validation. */
185 if ( (sharedParamsBuffer.identifier == SHARED_PARAMS_BUFFER_ID) &&
187 {
188 /* The shared parameter buffer is valid, so update the result value. */
189 result = true;
190 }
191 /* Give the result back to the caller. */
192 return result;
193} /*** 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 214 of file shared_params.c.

215{
216 bool result = false;
217
218 /* Calculate and verify the checksum. */
219 if (SharedParamsCalculateChecksum() == sharedParamsBuffer.checksum)
220 {
221 /* Checksum is correct, so update the result value. */
222 result = true;
223 }
224 /* Give the result back to the caller. */
225 return result;
226} /*** 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
160 // Flush pipelines
161 __ISB();
162 __DSB();
163
164 #if CORTEX_MODEL == 7
165 // If we have a cache, drop the relevant cache lines.
166 SCB_CleanDCache_by_Addr((uint32_t*)&sharedParamsBuffer, sizeof(sharedParamsBuffer));
167 #endif
168 }
169 /* Give the result back to the caller. */
170 return result;
171} /*** 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 201 of file shared_params.c.

202{
203 /* Calculate and write the checksum. */
204 sharedParamsBuffer.checksum = SharedParamsCalculateChecksum();
205} /*** 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.