#!/usr/bin/perl -w # ihx2nRF9E5.pl (c) by maZZoo [a] maZZoo.de # licensed under GPLv2 # # mangles EEPROM data for an 8051-based nordic semicondictor # nRF9E5 radio transceiver. # # reads an Intel-hex-formatted file from stdin, # writes it to stdout, all output addresses # will be increased by $offset (>=3) # # prepends bytes as the nRF9E5 requires. # # probably does quite the same job as nordic's # eeprep.exe - I never happened to run it. # # usage: # cat aslinkout.ihx | ./ihx2nRF9E5.pl > myeeprom.hex use strict; my $clock = 0x04; # 1MHz EEPROM, 20MHz clock my $offset = 0x03; # offset to start of prg my $blocks = 0x10; # 16 blocks of 256 bytes sub checksumline{ my $l = $_[0]; my $done = 0; my $c = 0; while ($l =~ m/^([0-9a-fA-F]{2})(.*)/) { $c = $c + hex $1; $l = $2; } $c = $c & 0xFF; $c = 0x100-$c; $c = $c & 0xFF; return $c; } my $line; my $chk; my $adr; # first line holds the nRF9E5-specific data $line = sprintf("03000000%02X%02X%02X", $clock, $offset, $blocks); $chk = checksumline($line); $line = sprintf(":$line%02X\n", $chk); print $line; while (<>) { /^:([0-9a-fA-F]{2})([0-9a-fA-F]{4})([0-9a-fA-F]{2})([0-9a-fA-F]*)([0-9a-fA-F]{2})$/ or die("ERROR: unparsable line $_"); if ($3 eq "01") { # last line ':00000001FF' print ":$1$2$3$4$5\n" }else{ $adr = $offset + hex $2; $line = sprintf("%s%04X%s", $1, $adr, $3); $line = $line . $4; # $4 holds actual EEPROM data - remains unchanged $chk = checksumline($line); $line = sprintf(":$line%02X\n", $chk); print $line; } }