mini-led-cube/tools/param2HexFrame.pl

79 lines
2.5 KiB
Perl
Raw Normal View History

#!/usr/bin/perl -w
2011-12-29 22:50:22 +01:00
#
# usage:
#
# ./param2HexFrame.pl "frame 1 data" "frame 2 data" ... "frame N data"
#
# frame X data = delay; layer 1; layer 2; layer 3
#
# delay = 0 to 31 (multiplied by 8 in firmware and equals to the ISR calls (delay/300 seconds)
# 0 equals to a delay of 255/300 seconds.
#
2011-12-29 22:54:59 +01:00
# layer Y = layer no(1,2,3), bit0, bit1, bit2, ..., bit8 (bitN = 1 ... 9)
2011-12-29 22:50:22 +01:00
#
# Sample usage which generates 5 frames:
#
# ./param2HexFrame.pl "25;3,2,5,8;" "14;3,3,5,7" "3;3,4,5,6;2,6,5,4" "23;3,1,5,9" "0;2,1,2,3,4,5,6,7,8,9;1,5"
# Frame 0 = 0xca480000 = hi:0xca48 = lo:0x0000 = 0b11001010010010000000000000000000
# Frame 1 = 0x71500000 = hi:0x7150 = lo:0x0000 = 0b01110001010100000000000000000000
# Frame 2 = 0x18e07000 = hi:0x18e0 = lo:0x7000 = 0b00011000111000000111000000000000
# Frame 3 = 0xbc440000 = hi:0xbc44 = lo:0x0000 = 0b10111100010001000000000000000000
# Frame 4 = 0x0003fe10 = hi:0x0003 = lo:0xfe10 = 0b00000000000000111111111000010000
#
use strict;
for (my $i=0; $i<=$#ARGV; $i++)
{
2011-12-29 22:50:22 +01:00
printf("Frame %02d = ", $i);
2011-12-29 22:50:22 +01:00
my @list = split(";", $ARGV[$i]);
my $frame = 0;
my $status = 1;
foreach my $ele (@list)
{
2011-12-29 22:50:22 +01:00
my @list2 = split(",", $ele);
2011-12-29 22:50:22 +01:00
my $status2 = 1;
my $layer = 0;
my $bit = 0;
if ($status == 1) { # read the delay
$status = 0;
# minimum delay is 0 (equals to a delay of 255 ISR calls)
# maximum delay is 31 (equals to a delay of 31*8 ISR calls)
if ($ele > -1 && $ele < 32)
{
$frame |= $ele << 27;
}
} else {
if ($#list >= 0 && $#list <= 9)
{
my $ele = 0;
foreach my $ele2 (@list2)
{
2011-12-29 22:50:22 +01:00
if ($status2 == 1) # read the layer
{
# the layer has to be in range of 1 to 3
if ($ele2 > 0 && $ele2 < 4)
{
$layer = ($ele2 - 1) * 9;
$status2 = 0;
}
} else {
if ($ele2 > 0 && $ele2 < 10) # bit 1 to 9 allowed
{
$bit = $layer + $ele2-1;
$frame |= (1 << $bit);
}
}
}
}
}
}
2011-12-29 22:50:22 +01:00
printf("0x%08x = ", $frame);
printf("hi:0x%04x = ", $frame >> 16);
printf("lo:0x%04x = ", $frame & 0xffff);
printf("0b%032b\n", $frame);
}
2011-12-29 22:54:59 +01:00