Загрузка данных
###############################################################################
sub generate_dox
{
my ($outDir, $cfgRef) = @_;
my $fileName = 'config.dox';
my @dox = grep(/^DOX\b/, @$cfgRef);
# Open file
open my $out, '>', $outDir . '/' . $fileName
or die "error: failure to open: $outDir/$fileName, $!";
if ($verbose)
{
my $fn = fileparse($fileName);
printf("Generating $fn ...\n");
}
# Get copyright
my $cr = ©right();
# Get CONFIG name
if ((my $parm = ¶m($dox[0], 'name')) ne '!')
{
$config_name = 'CONFIG_' . $parm;
}
# Get desc
my $config_desc = 'Configuration Data';
if ($dox[0] =~ /desc=\"([\w\s\.]+)\"/)
{
$config_desc = $1;
}
# Output copyright
print $out $cr;
# Output config group header
print $out '/*!' . "\n";
print $out ' * @addtogroup SM_CONFIG' . "\n";
print $out ' * @{' . "\n";
print $out ' */' . "\n\n";
# Output dox group header
print $out '/*!' . "\n";
print $out "\n";
print $out '@defgroup ' . $config_name . ' ' . $config_name
. ': ' . $config_desc . "\n";
print $out '' . "\n";
print $out '@brief Module for ' . $config_desc . '.' . "\n";
print $out "\n";
print $out '*/' . "\n\n";
print $out '/** @} */' . "\n\n";
# Close file
close($out);
}
###############################################################################
sub generate_mb
{
my ($outDir, $cfgRef) = @_;
my @list = grep(/^MAILBOX\b/ || /^LM\d*\b/ || /^CHANNEL\b/,
@$cfgRef);
# Log MB info
&log_array('Mailbox info', \@list);
# Loop over mailbox types
foreach my $mbt (@mbTypes)
{
my $lcMbt = lc $mbt;
my @mbList = grep(/^MAILBOX\b/ && /type=$lcMbt\b/, @list);
my $num = @mbList;
# MU of this type found?
if ($num > 0)
{
my $fileName = 'config_mb_' . lc $mbt . '.h';
my $i;
my $x;
my $xportType = '<invalid>';
my %xportChannel;
# Open file
open my $out, '>', $outDir . '/' . $fileName
or die "error: failure to open: $outDir/$fileName, $!";
if ($verbose)
{
my $fn = fileparse($fileName);
printf("Generating $fn ...\n");
}
# Output header
print $out &header('MB_' . $mbt, 'MB_' . $mbt);
print $out '/* Includes */' . "\n\n";
print $out '#include "config_user.h"' . "\n";
print $out '#include "mb_' . lc $mbt . '_config.h"' . "\n\n";
print $out '/* Defines */' . "\n\n";
# Loop over the LM+MB+CHANNEL list
$i = -1;
$x = 0;
my @defLst;
foreach my $mb (@list)
{
# Handle LM
if ($mb =~ /^(LM\d*)\b/)
{
my $line = $1 . ' MB_' . $mbt . ' Config';
if ((my $parm = ¶m($mb, 'name')) ne '!')
{
$parm =~ s/\"//g;
$line .= ' (' . $parm . ')';
}
if ($x != 0)
{
print $out ' }' . "\n\n";
$x = 0;
}
print $out &banner($line);
next;
}
# Handle channel
if ($mb =~ /^CHANNEL\b/)
{
if ((my $parm = ¶m($mb, 'xport')) ne '!')
{
$xportType = 'XPORT_' . uc $parm;
$xportChannel{$xportType}++;
}
if ((my $parm = ¶m($mb, 'db')) ne '!')
{
print $out ' .xportType[' . $parm
. '] = SM_' . $xportType
. ', \\' . "\n";
print $out ' .xportChannel[' . $parm
. '] = ' . ($xportChannel{$xportType}
- 1) . 'U, \\' . "\n";
$x++;
}
else
{
error_line('no doorbell', $mb);
}
next;
}
# Handle MB
if ($mb =~ /^MAILBOX\b/)
{
if ($x != 0)
{
print $out ' }' . "\n\n";
$x = 0;
}
$i++;
my $mu = $i;
if ((my $parm = ¶m($mb, 'mu')) ne '!')
{
$mu = $parm;
}
print $out '/*! Config for ' . $mbt . $mu . ' MB */' . "\n";
print $out '#define SM_MB_' . $mbt . $mu . '_CONFIG \\' . "\n";
print $out ' { \\' . "\n";
if ((my $parm = ¶m($mb, 'mu')) ne '!')
{
print $out ' .mu = ' . $parm . 'U, \\' . "\n";
}
if ((my $parm = ¶m($mb, 'sma')) ne '!')
{
print $out ' .sma = ' . $parm . 'U, \\' . "\n";
}
if ((my $parm = ¶m($mb, 'priority')) ne '!')
{
print $out ' .priority = IRQ_PRIO_NOPREEMPT_'
. uc $parm . ', \\' . "\n";
}
$defLst[$i] = $mu;
}
}
if ($x != -1)
{
print $out ' }' . "\n\n";
$x = 0;
}
# Output collected define
print $out &banner('MB ' . $mbt . ' Config');
print $out '/*! Config for number of ' . $mbt . ' MB */' . "\n";
print $out '#define SM_NUM_MB_' . $mbt . ' '
. $num . 'U' . "\n\n";
# Loop over the MB list
$i = 0;
print $out '/*! Config data array for ' . $mbt . ' MB */' . "\n";
print $out '#define SM_MB_' . $mbt . '_CONFIG_DATA';
foreach my $mb (@mbList)
{
if ($i != 0)
{
print $out ',';
}
print $out ' \\' . "\n" . ' SM_MB_' . $mbt
. $defLst[$i] . '_CONFIG';
$i++;
}
print $out "\n";
# Output footer
print $out &footer('MB_' . $mbt);
# Close file
close($out);
# Include in make
$makeInclude{$mbt} = 'rpc/mb_' . lc $mbt;
}
}
}
###############################################################################
sub generate_xport
{
my ($outDir, $cfgRef) = @_;
# Loop over xport types
foreach my $xpt (@xportTypes)
{
my $lcXpt = lc $xpt;
my @list = grep((/^CHANNEL\b/ && /\bxport=$lcXpt\b/)
|| /^MAILBOX\b/ || /^LM\d*\b/, @$cfgRef);
my @chnList = grep(/^CHANNEL\b/, @list);
my $num = @chnList;
# Log xport info
&log_array('Transort info (' . $xpt . ')', \@list);
# Channels found?
if ($num > 0)
{
my $fileName = 'config_' . $lcXpt . '.h';
my $i;
my $rpcType = '<invalid>';
my %rpcChannel;
my $mbType = '<invalid>';
my %mbInst;
my %crc;
# Open file
open my $out, '>', $outDir . '/' . $fileName
or die "error: failure to open: $outDir/$fileName, $!";
if ($verbose)
{
my $fn = fileparse($fileName);
printf("Generating $fn ...\n");
}
# Output header
print $out &header($xpt, $xpt);
print $out '/* Includes */' . "\n\n";
print $out '#include "config_user.h"' . "\n";
print $out '#include "rpc_' . $lcXpt . '_config.h"' . "\n\n";
print $out '/* Defines */' . "\n\n";
# Loop over the LM+MU+CHN list
$i = 0;
foreach my $mb (@list)
{
# Handle LM
if ($mb =~ /^(LM\d*)\b/)
{
my $line = $1 . ' ' . $xpt . ' Config';
if ((my $parm = ¶m($mb, 'name')) ne '!')
{
$parm =~ s/\"//g;
$line .= ' (' . $parm . ')';
}
print $out &banner($line);
next;
}
# Handle MB
if ($mb =~ /^MAILBOX\b/)
{
if ((my $parm = ¶m($mb, 'type')) ne '!')
{
$mbType = 'MB_' . uc $parm;
$mbInst{$mbType}++;
}
next;
}
# Handle channel
if ($mb =~ /^CHANNEL\b/)
{
if ((my $parm = ¶m($mb, 'rpc')) ne '!')
{
$rpcType = 'RPC_' . uc $parm;
$rpcChannel{$rpcType}++;
}
# Check for default channel
if ($mbType eq '<invalid>')
{
error_line('no mailbox', $mb);
}
# Output channel define
print $out '/*! Config for ' . $xpt . ' channel ' . $i
. ' */' . "\n";
print $out '#define SM_' . $xpt . '_CHN'
. $i . '_CONFIG \\' . "\n";
print $out ' { \\' . "\n";
print $out ' .rpcType = SM_' . $rpcType
. ', \\' . "\n";
print $out ' .rpcChannel = ' . ($rpcChannel{$rpcType}
- 1) . 'U, \\' . "\n";
print $out ' .mbType = SM_' . $mbType
. ', \\' . "\n";
print $out ' .mbInst = ' . ($mbInst{$mbType}
- 1) . 'U, \\' . "\n";
if ((my $parm = ¶m($mb, 'db')) ne '!')
{
print $out ' .mbDoorbell = ' . $parm
. 'U, \\' . "\n";
}
if ((my $parm = ¶m($mb, 'check')) ne '!')
{
$crc{$parm}++;
print $out ' .crc = SM_SMT_CRC_'
. uc $parm . ', \\' . "\n";
}
print $out ' }' . "\n\n";
$i++;
}
}
# Output collected define
print $out &banner($xpt . ' Config');
print $out '/*! Config for number of ' . $xpt . ' channels'
. ' */' . "\n";
print $out '#define SM_NUM_' . $xpt . '_CHN '
. $num . 'U' . "\n\n";
# Loop over the channel list
$i = 0;
print $out '/*! Config data array for ' . $xpt . ' channels */' . "\n";
print $out '#define SM_' . $xpt . '_CHN_CONFIG_DATA';
foreach my $chn (@chnList)
{
if ($i != 0)
{
print $out ',';
}
print $out ' \\' . "\n" . ' SM_' . $xpt . '_CHN'
. $i . '_CONFIG';
$i++;
}
print $out "\n\n";
# Output defines for MU type support
print $out '/* Mailbox and CRC types to support */'
. "\n";
foreach my $key (keys %mbInst)
{
my $value = $mbInst{$key};
if ($value != 0)
{
print $out '/*! Config for ' . uc $key . ' use */' . "\n";
print $out '#define USES_' . uc $key . "\n";
}
}
# Output defines for CRC support
foreach my $key (sort keys %crc)
{
my $value = $crc{$key};
if ($value != 0)
{
print $out '/*! Config for ' . uc $key . ' CRC use */' . "\n";
print $out '#define USES_CRC_' . uc $key . "\n";
}
}
# Output footer
print $out &footer($xpt);
# Close file
close($out);
# Include in make
$makeInclude{$xpt} = 'rpc/' . $lcXpt;
}
}
}