Callisto4Bootloader: lib/c4_parser.c File Reference

Callisto4Bootloader

Macros | Functions | Variables
c4_parser.c File Reference

Parse ASCII config file. More...

`#include "c4_privilege_modes.h"`
`#include "c4_parser.h"`
`#include "c4_qspi.h"`
`#include "platform-memory-map.h"`
`#include "fsl_debug_console.h"`
`#include <string.h>`
`#include <stdio.h>`
`#include <ctype.h>`

Go to the source code of this file.

## Macros

#define | CALLISTO_PARSER(Id, Text, Desc, Exa) Text,
#define | CALLISTO_PARSER(Id, Text, Desc, Exa) Desc,
#define | CALLISTO_PARSER(Id, Text, Desc, Exa) Text""Exa,

## Functions

void | printConfigExample ()
| Print out config file example. More...
void | printConfigHelp ()
| Print out config file description. More...
exit_code_t | checkConfigVersion (const char *ver)
| Check the file version. More...
exit_code_t | verifyConfigChecksum (const char *cfg_file, size_t file_len)
| Verify the checksum. More...
exit_code_t | writeConfigChecksum (const char *cfg_file, size_t file_len)
| Write checksum. More...
static uint32_t | calc_checksum (volatile const unsigned char *pvBase, uint32_t uiNumBytes)
| Calculate a config header checksum. More...
exit_code_t | GetConfig (const char *mem, uint32_t mem_len, E_parseIndices_t field, char *val)
| Parse the specified memory location. More...
exit_code_t | SetConfig (const char *mem, uint32_t mem_len, E_parseIndices_t field, const char *val, file_op_t op)
| Set value in the specified memory location. More...

## Variables

const char *const | config_addr
static const uint8_t | CFG_VER_MAJ = 0
| Config file major version numbers. More...
static const uint8_t | CFG_VER_MIN = 1
| Config file minor version number. More...
static const uint32_t | HASH_MULTIPLIER =37
| Multiplier for hash function. More...
static const uint32_t | HASH_SALT =0xfeedb4be
| Salt for hash function. More...
const char | C4_parseStrings [NUM_PARSE_TERMS+1][32]
| Array of strings to use in parser. More...
static const char | C4_helpStrings [NUM_PARSE_TERMS+1][512]
| Array of description strings to use in parser help. More...
static const char | C4_exampleStrings [NUM_PARSE_TERMS+1][64]
| Array of strings to construct example config file. More...

## Detailed Description

Parse ASCII config file.

Copyright
  2020 Remsdaq Ltd.

A simple parser built using strtok to identify keywords.

Date
  20 May 2020

Author
  : Dan Smithers dwhs@.nosp@m.rems.nosp@m.daq.c.nosp@m.om

Definition in file c4_parser.c.

## Macro Definition Documentation

## ◆ CALLISTO_PARSER [1/3]

#define CALLISTO_PARSER | ( |  | Id,
|  |  | Text,
|  |  | Desc,
|  |  | Exa
| ) |  | Text,

## ◆ CALLISTO_PARSER [2/3]

#define CALLISTO_PARSER | ( |  | Id,
|  |  | Text,
|  |  | Desc,
|  |  | Exa
| ) |  | Desc,

## ◆ CALLISTO_PARSER [3/3]

#define CALLISTO_PARSER | ( |  | Id,
|  |  | Text,
|  |  | Desc,
|  |  | Exa
| ) |  | Text""Exa,

## Function Documentation

## ◆ calc_checksum()

static uint32_t calc_checksum | ( | volatile const unsigned char * | pvBase,
|  | uint32_t | uiNumBytes
| ) |  |

static

Calculate a config header checksum.

Parameters

  [in] | pvBase | Base address of configuration block
  [in] | uiNumBytes | Length (in bytes) of the configuration

Returns
  32-bit additive checksum value

Calculate the checksum of a platform configuration EEPROM header

Definition at line 487 of file c4_parser.c.

## ◆ checkConfigVersion()

exit_code_t checkConfigVersion | ( | const char * | ver | ) |

Check the file version.

Parameters

  [in] | ver | Version string

Returns
  Whether the config file read is compatible.

Return values

  C4_ERR_OK | File is compatible.
  C4_ERR_VERSION | File is not compatible

Definition at line 436 of file c4_parser.c.

References C4_exampleStrings, and i.

## ◆ GetConfig()

exit_code_t GetConfig | ( | const char * | mem,
|  | uint32_t | mem_len,
|  | E_parseIndices_t | field,
|  | char * | pVal
| ) |  |

Parse the specified memory location.

Search from the memory location for the specified field and return the value stored there in pVal

Parameters

  [in] | mem | Memory location for start of file.
  [in] | mem_len | Length of data at location
  [in] | field | Field identifier
  [out] | pVal | Pointer to return field value.

Returns
  Exit code.

Return values

  ERR_OK | Success.
  ERR_FILE_NOT_FOUND | Memory file not found.
  ERR_FIELD_NOT_FOUND | Memory field not found.
  ERR_SYNTAX | Memory file does not parse.

Definition at line 139 of file c4_parser.c.

## ◆ printConfigExample()

void printConfigExample | ( |  | ) |

Print out config file example.

Definition at line 425 of file c4_parser.c.

## ◆ printConfigHelp()

void printConfigHelp | ( |  | ) |

Print out config file description.

Definition at line 412 of file c4_parser.c.

## ◆ SetConfig()

exit_code_t SetConfig | ( | const char * | mem,
|  | uint32_t | mem_len,
|  | E_parseIndices_t | field,
|  | const char * | val,
|  | file_op_t | op
| ) |  |

Set value in the specified memory location.

Search from the memory location for the specified field and return the

Parameters

  [in] | mem | Memory location for start of file.
  [in] | mem_len | Length of data at location
  [in] | field | Field identifying string
  [in] | val | New field value.
  [in] | op | Flag to denote whether the value should be replaced only, used to extend existing field, or appended if not found

Returns
  Exit code.

Return values

  ERR_OK | Success.
  ERR_FILE_NOT_FOUND | Memory file not found.
  ERR_FIELD_NOT_FOUND | Memory field not found.
  ERR_NOT_IMPLEMENTED | Operation not implemented.
  ERR_SYNTAX | Memory file does not parse.

Definition at line 221 of file c4_parser.c.

## ◆ verifyConfigChecksum()

exit_code_t verifyConfigChecksum | ( | const char * | cfg_file,
|  | size_t | file_len
| ) |  |

Verify the checksum.

Parameters

  [in] | cfg_file | Start of file to check.
  [in] | file_len | Length in bytes of file to check.

Returns
  Whether checksum matches.

Return values

  C4_ERR_OK | Checksum matches.
  C4_ERR_FILE_CORRUPT | Checksum does not match.

Definition at line 453 of file c4_parser.c.

## ◆ writeConfigChecksum()

exit_code_t writeConfigChecksum | ( | const char * | cfg_file,
|  | size_t | file_len
| ) |  |

Write checksum.

Parameters

  [in] | cfg_file | Start of file being written
  [in] | file_len | Length in bytes of file to check.

Returns
  whether checksum has been written.

Return values

  C4_ERR_OK | Checksum written.
  C4_ERR_FAILED | Checksum has not been written.

Definition at line 464 of file c4_parser.c.

## Variable Documentation

## ◆ C4_exampleStrings

const char C4_exampleStrings[NUM_PARSE_TERMS+1][64]

static

Initial value:
= {
#define CALLISTO_PARSER(Id, Text, Desc, Exa)
PARSER_KEYWORDS
"N/A"
}

Array of strings to construct example config file.

Definition at line 128 of file c4_parser.c.

Referenced by checkConfigVersion().

## ◆ C4_helpStrings

const char C4_helpStrings[NUM_PARSE_TERMS+1][512]

static

Initial value:
= {
#define CALLISTO_PARSER(Id, Text, Desc, Exa)
PARSER_KEYWORDS
"Total number of parse terms"
}

Array of description strings to use in parser help.

Definition at line 120 of file c4_parser.c.

## ◆ C4_parseStrings

const char C4_parseStrings[NUM_PARSE_TERMS+1][32]

Initial value:
= {
#define CALLISTO_PARSER(Id, Text, Desc, Exa)
PARSER_KEYWORDS
"Number of Parse terms"
}

Array of strings to use in parser.

Definition at line 110 of file c4_parser.c.

## ◆ CFG_VER_MAJ

const uint8_t CFG_VER_MAJ = 0

static

Config file major version numbers.

Definition at line 35 of file c4_parser.c.

## ◆ CFG_VER_MIN

const uint8_t CFG_VER_MIN = 1

static

Config file minor version number.

Definition at line 38 of file c4_parser.c.

## ◆ config_addr

const char* const config_addr

## ◆ HASH_MULTIPLIER

const uint32_t HASH_MULTIPLIER =37

static

Multiplier for hash function.

Definition at line 41 of file c4_parser.c.

## ◆ HASH_SALT

const uint32_t HASH_SALT =0xfeedb4be

static

Salt for hash function.

Definition at line 44 of file c4_parser.c.

PARSER_KEYWORDS
#define PARSER_KEYWORDS
definition of parser keywords.
Definition: c4_parser.h:34