LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Macros | Functions | Variables
ihex.c File Reference

Contains Routines to decode Intel HEX Files and to send them to the Sensor. More...

Include dependency graph for ihex.c:

Macros

#define MAXBYTES   30
 Maximum number of Bytes per Line (including Address, Type and Byte Count) More...
 
#define MEMSIZE   0x800
 Maximum size of the Sensor Program. More...
 

Functions

int8_t BootldRead (uint16_t adr)
 Reads one page of Sensor ROM via the Sensor Boot Loader. More...
 
int8_t BootldWrite (uint16_t adr)
 Sends one Page to the Sensor Boot Loader. More...
 
void Delay1s ()
 Waits one Second. More...
 
static int8_t DoOneLine (void)
 Parses one Line of an Intel HEX File. More...
 
void HexDump (uint16_t adr, void *ptr, uint8_t n)
 Prints one line of Hexdump. More...
 
static int ProgramSensor (void)
 Programs the Sensor Firmware with the Content of mem[]. More...
 
static int8_t ReadIntelHex (void)
 Reads an Intel HEX File into Memory. More...
 
int8_t UpdateSensorFirmware (void)
 Updates the Sensor Firmware. More...
 
static int8_t VerifySensor (void)
 Verifies the Sensor Firmware against the Content of mem[]. More...
 
int8_t VerifySensorFirmware (void)
 Verifies the Sensor Firmware against an Intel-Hex-File. More...
 

Variables

static char mem [MEMSIZE]
 

Detailed Description

Contains Routines to decode Intel HEX Files and to send them to the Sensor.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Since the boot loader timing is very strict (there must not be a pause of more than a second between two characters) and we have enough of RAM we decode the Intel Hex file into RAM and then start the programming sequence.

Macro Definition Documentation

◆ MAXBYTES

#define MAXBYTES   30

Maximum number of Bytes per Line (including Address, Type and Byte Count)

◆ MEMSIZE

#define MEMSIZE   0x800

Maximum size of the Sensor Program.

Function Documentation

◆ BootldRead()

int8_t BootldRead ( uint16_t  adr)

Reads one page of Sensor ROM via the Sensor Boot Loader.

The page is stored in bootLdPage[]

Parameters
adrThe start Address
Returns
-1 on Error, 0 on Success

References blFlags, BOOTLDDATA, BOOTLDERROR, cksum0, putc0(), and putd0().

Referenced by VerifySensor().

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

◆ BootldWrite()

int8_t BootldWrite ( uint16_t  adr)

Sends one Page to the Sensor Boot Loader.

Parameters
adrThe Start Address of the Page
Returns
-1 on Error, 0 on Success

References blFlags, BOOTLDERROR, cksum0, mem, putc0(), putd0(), and tickCnt.

Referenced by ProgramSensor().

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

◆ Delay1s()

void Delay1s ( )

Waits one Second.

Note
This function uses the hard-timed delay50ms and therefore does not rely on interrupts being enabled.

References delay50ms().

Here is the call graph for this function:

◆ DoOneLine()

static int8_t DoOneLine ( void  )
static

Parses one Line of an Intel HEX File.

Returns
-1 on Error, 0 on Success, 1 on End of File

References cmdline, hprintf_P(), MAXBYTES, mem, MEMSIZE, RECTYPE_DATA, RECTYPE_EOF, and RECTYPE_EXTSEG.

Referenced by ReadIntelHex().

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

◆ HexDump()

void HexDump ( uint16_t  adr,
void *  ptr,
uint8_t  n 
)

Prints one line of Hexdump.

Parameters
adrThe Address to be displayed
ptrA Pointer to the first Byte
nThe number of Bytes to dump

References hprintf_P().

Referenced by VerifySensor().

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

◆ ProgramSensor()

static int ProgramSensor ( void  )
static

Programs the Sensor Firmware with the Content of mem[].

Note
This function requires the Boot Loader activated.
Returns
0 if OK, -1 on Error

References blFlags, BootldWrite(), hprintf_P(), and MEMSIZE.

Referenced by UpdateSensorFirmware().

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

◆ ReadIntelHex()

static int8_t ReadIntelHex ( void  )
static

Reads an Intel HEX File into Memory.

Returns
0 on Success, -1 on Error

References AssertRTS(), CFLAG_CMDRECEIVED, cFlags, cmdline, DoOneLine(), hprintf_P(), mem, and MEMSIZE.

Referenced by UpdateSensorFirmware(), and VerifySensorFirmware().

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

◆ UpdateSensorFirmware()

int8_t UpdateSensorFirmware ( void  )

Updates the Sensor Firmware.

Returns
0 on Success, -1 on Error

References blFlags, BOOTLDHELLO, hprintf_P(), ProgramSensor(), putc0(), ReadIntelHex(), SensorPowerOff(), SensorPowerOn(), and VerifySensor().

Referenced by CmdUpdateSensorFirmware().

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

◆ VerifySensor()

static int8_t VerifySensor ( void  )
static

Verifies the Sensor Firmware against the Content of mem[].

Note
This function requires the Boot Loader activated.
Returns
0 if OK, -1 on Error

References bootLdPage, BootldRead(), HexDump(), hprintf_P(), mem, and MEMSIZE.

Referenced by UpdateSensorFirmware(), and VerifySensorFirmware().

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

◆ VerifySensorFirmware()

int8_t VerifySensorFirmware ( void  )

Verifies the Sensor Firmware against an Intel-Hex-File.

Returns
0 on Success, -1 on Error

References blFlags, BOOTLDHELLO, hprintf_P(), putc0(), ReadIntelHex(), SensorPowerOff(), SensorPowerOn(), and VerifySensor().

Referenced by CmdVerifySensorFirmware().

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

Variable Documentation

◆ mem

char mem[MEMSIZE]
static

mem[] is big enough to hold the whole program memory of the sensor. This takes a lot of RAM but we have enough to maximize reliability. We can load the whole bunch to RAM first and securely transfer it to the sensor.

Referenced by BootldWrite(), DoOneLine(), ReadIntelHex(), and VerifySensor().