From af492ffe895b62ac0eddae8d4b369bfaa0e3f870 Mon Sep 17 00:00:00 2001 From: laranjeiro Date: Mon, 19 May 2008 08:22:25 +0000 Subject: pwl: complete the scilab simulation to write the table for the unit test in C. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2015 017c9cb6-072f-447c-8318-d5b54f68fe89 --- cesar/cp2/pwl/doc/scilab/convertc.sce | 35 ++++++++++++++++++++ .../pwl/doc/scilab/estimate_acl_freq_decrease.sce | 32 +++++++++++------- .../pwl/doc/scilab/estimate_acl_freq_increase.sce | 38 +++++++++++++++------- cesar/cp2/pwl/doc/scilab/estimate_acl_stable.sce | 29 +++++++++++++---- cesar/cp2/pwl/doc/scilab/src/estimateBP.sce | 5 ++- cesar/cp2/pwl/doc/scilab/src/zc_capture.sce | 5 ++- .../cp2/pwl/doc/scilab/src/zc_capture_decrease.sce | 21 ++++++++++++ .../cp2/pwl/doc/scilab/src/zc_capture_increase.sce | 21 ++++++++++++ 8 files changed, 151 insertions(+), 35 deletions(-) create mode 100644 cesar/cp2/pwl/doc/scilab/convertc.sce create mode 100644 cesar/cp2/pwl/doc/scilab/src/zc_capture_decrease.sce create mode 100644 cesar/cp2/pwl/doc/scilab/src/zc_capture_increase.sce (limited to 'cesar/cp2') diff --git a/cesar/cp2/pwl/doc/scilab/convertc.sce b/cesar/cp2/pwl/doc/scilab/convertc.sce new file mode 100644 index 0000000000..0c202fe5ce --- /dev/null +++ b/cesar/cp2/pwl/doc/scilab/convertc.sce @@ -0,0 +1,35 @@ +// SPiDCOM Technologies. +// Nélio Laranjeiro +// 16-05-2008 +// Cesar project. + +// Convert an array of values to a C array. + +// @param file_name the file name to write the data in. The file shall be a +// c file. +// @param array_name the array name. +// @param array the array to write. +function convertc_array (file_name, array_name, array) + +nb_points = length(array); +define_name = file_name + "_" + array_name; + +// Provide an array for the C unit test. +result_file = file ('open', file_name, 'unknown'); + fprintf (result_file, "#ifndef %s", define_name); + fprintf (result_file, "#define %s", define_name); + fprintf (result_file, "/* File generated by scilab */"); + fprintf (result_file, ""); + fprintf (result_file, "u8 %s [%d] = {", array_name, nb_points); + for i = 1:nb_points - 1 + fprintf (result_file, " %d, ", array(i)); + end + +// Write the last value. +fprintf (result_file, "%d };", array(nb_points)); +fprintf (result_file, "uint %s = %d;", array_name + '_length', nb_points); + +fprintf (result_file, "#endif /* %s */", define_name); +file ('close', result_file); + +endfunction diff --git a/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_decrease.sce b/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_decrease.sce index de8f5ce372..df3f65af51 100644 --- a/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_decrease.sce +++ b/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_decrease.sce @@ -7,31 +7,41 @@ // load the file, containing the function to generate a stable 50hz zero // cross. -getf ('src/zc_capture.sce'); +getf ('src/zc_capture_decrease.sce'); getf ('src/estimateBP.sce'); +// C array writer +getf('convertc.sce'); + // Initialise the environment. date_ntb = [240000; 0]; // 50 Hz in ticks. bp_ntb = 1e6; zc_ntb = bp_ntb / 4; -// Write the result in a file. -result_file = file('open', 'result_decrease.csv', 'unknown'); +nb_points = 1e3; -var = 1000; -fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2\n"); +//Vector of points. +result = zeros(nb_points,3); for i = 1:1000 - if (modulo(i, 50) == 0) - fprintf (result_file, "Variation : %d\n", var); - var = var + 1000; - end - res = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb, var); + res = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb); + + result (i,:) = res; + bp_ntb = res(1) + 1e6; date_ntb(2) = res(2); date_ntb(1) = res(3); - fprintf (result_file, "%d, %d, %d, %d\n", res(1), res(1) / 256, res(3), res(2)); end +// Write the result in a file. +result_file = file('open', 'result_decrease.csv', 'unknown'); +fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2\n"); +for i = 1:nb_points + fprintf (result_file, "%d, %d, %d, %d\n", result(i,1), int(result(i,1) / 256), result(i,3), result(i,2)); +end // Close the file. file('close', result_file); + +// Write the array. +res = result(:,3); +convertc_array ('table_descrease.c', 'ac_decrease', res); diff --git a/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_increase.sce b/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_increase.sce index 76c844964e..b15ccd57b2 100644 --- a/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_increase.sce +++ b/cesar/cp2/pwl/doc/scilab/estimate_acl_freq_increase.sce @@ -7,31 +7,45 @@ // load the file, containing the function to generate a stable 50hz zero // cross. -getf ('src/zc_capture.sce'); +getf ('src/zc_capture_increase.sce'); getf ('src/estimateBP.sce'); +// C array writer +getf('convertc.sce'); + // Initialise the environment. date_ntb = [240000; 0]; // 50 Hz in ticks. bp_ntb = 1e6; zc_ntb = bp_ntb / 4; -// Write the result in a file. -result_file = file('open', 'result_increase.csv', 'unknown'); +// Number of points. +nb_points = 1000; + +//Vector of points. +result = zeros(nb_points,3); + + +for i = 1:nb_points + res = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb); + + result (i,:) = res; -var = -1000; -fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2\n"); -for i = 1:1000 - if (modulo(i, 50) == 0) - fprintf (result_file, "Variation : %d\n", var); - var = var - 1000; - end - res = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb, var); bp_ntb = res(1) + 1e6; date_ntb(2) = res(2); date_ntb(1) = res(3); - fprintf (result_file, "%d, %d, %d, %d\n", res(1), res(1) / 256, res(3), res(2)); end +// Write the result in a file. +result_file = file('open', 'result_increase.csv', 'unknown'); + +fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2\n"); +for i = 1:nb_points + fprintf (result_file, "%d, %d, %d, %d\n", result(i,1), int(result(i,1) / 256), result(i,3), result(i,2)); +end // Close the file. file('close', result_file); + +// Write the array. +res = result(:,3); +convertc_array ('table_increase.c', 'ac_increase', res); diff --git a/cesar/cp2/pwl/doc/scilab/estimate_acl_stable.sce b/cesar/cp2/pwl/doc/scilab/estimate_acl_stable.sce index c7ed92fc94..b7aeb6ecfd 100644 --- a/cesar/cp2/pwl/doc/scilab/estimate_acl_stable.sce +++ b/cesar/cp2/pwl/doc/scilab/estimate_acl_stable.sce @@ -10,23 +10,40 @@ getf ('src/zc_capture.sce'); getf ('src/estimateBP.sce'); +// C array writer +getf('convertc.sce'); + // Initialise the environment. date_ntb = [240000; 0]; // 50 Hz in ticks. bp_ntb = 1e6; zc_ntb = bp_ntb / 4; -// Write the result in a file. -result_file = file('open', 'result_stable.csv', 'unknown'); +// Number of points. +nb_points = 1e3; + +//Vector of points. +result = zeros(nb_points,3); + +for i = 1:nb_points + res = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb); + + result (i,:) = res; -fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2\n"); -for i = 1:1000 - res = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb, 0); bp_ntb = res(1) + 1e6; date_ntb(2) = res(2); date_ntb(1) = res(3); - fprintf (result_file, "%d, %d, %d, %d\n", res(1), res(1) / 256, res(3), res(2)); end +// Write the result in a file. +result_file = file('open', 'result_stable.csv', 'unknown'); +fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2\n"); +for i = 1:nb_points + fprintf (result_file, "%d, %d, %d, %d\n", result(i,1), int(result(i,1) / 256), result(i,3), result(i,2)); +end // Close the file. file('close', result_file); + +// Write the array. +res = result(:,3); +convertc_array ('table.c', 'ac_stable', res); diff --git a/cesar/cp2/pwl/doc/scilab/src/estimateBP.sce b/cesar/cp2/pwl/doc/scilab/src/estimateBP.sce index 9564822286..3f7329db01 100644 --- a/cesar/cp2/pwl/doc/scilab/src/estimateBP.sce +++ b/cesar/cp2/pwl/doc/scilab/src/estimateBP.sce @@ -14,11 +14,10 @@ // @param date_ntb the matrix containing the previous zc cross. // @param bp_ntb the beacon period in NTB clock base. // @param zc ntb the ACL zero cross. -// @param fvar_ntb the frequency variation in NTB. // @return the [per, date_ntb'] -function [res] = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb, fvar_ntb) +function [res] = cp_pwl_estimate_beacon_period (date_ntb, bp_ntb, zc_ntb) -date_ntb(1) = phy_clock_get_zero_cross_captured_date (date_ntb(2), fvar_ntb); +date_ntb(1) = phy_clock_get_zero_cross_captured_date (date_ntb(2)); diff_ntb = modulo((date_ntb(1) - date_ntb(2)), bp_ntb + 10000); per_ntb = (4-(diff_ntb / zc_ntb)) * zc_ntb + diff_ntb; diff --git a/cesar/cp2/pwl/doc/scilab/src/zc_capture.sce b/cesar/cp2/pwl/doc/scilab/src/zc_capture.sce index 089dedf019..ba46a463ec 100644 --- a/cesar/cp2/pwl/doc/scilab/src/zc_capture.sce +++ b/cesar/cp2/pwl/doc/scilab/src/zc_capture.sce @@ -9,11 +9,10 @@ // Function to simulate the frequency of the AC line. // @param phy the previous value provided. -// @param var The variation of frequency. // @Return phy + 250 000 -function phy = phy_clock_get_zero_cross_captured_date(phy, var) +function phy = phy_clock_get_zero_cross_captured_date(phy) -phy = phy + 1000000 + var; +phy = phy + 1000000; return phy; endfunction diff --git a/cesar/cp2/pwl/doc/scilab/src/zc_capture_decrease.sce b/cesar/cp2/pwl/doc/scilab/src/zc_capture_decrease.sce new file mode 100644 index 0000000000..2009ebeb72 --- /dev/null +++ b/cesar/cp2/pwl/doc/scilab/src/zc_capture_decrease.sce @@ -0,0 +1,21 @@ +// SPiDCOM Technologies. +// Nélio Laranjeiro +// 16-05-2008 +// Cesar project. + +// This script will provide a function to generate a 50 Hz frequency +// AC Line based on the NTB date with a little jitter. + + +// Function to simulate the frequency of the AC line. +// @param phy the previous value provided. +// @param var The variation of frequency. +// @Return phy + 250 000 +function phy = phy_clock_get_zero_cross_captured_date(phy) + +var = int(rand (1) * 100000); +phy = phy + 1000000 - var; +return phy; + +endfunction + diff --git a/cesar/cp2/pwl/doc/scilab/src/zc_capture_increase.sce b/cesar/cp2/pwl/doc/scilab/src/zc_capture_increase.sce new file mode 100644 index 0000000000..f20f6843a4 --- /dev/null +++ b/cesar/cp2/pwl/doc/scilab/src/zc_capture_increase.sce @@ -0,0 +1,21 @@ +// SPiDCOM Technologies. +// Nélio Laranjeiro +// 16-05-2008 +// Cesar project. + +// This script will provide a function to generate a 50 Hz frequency +// AC Line based on the NTB date with a little jitter. + + +// Function to simulate the frequency of the AC line. +// @param phy the previous value provided. +// @param var The variation of frequency. +// @Return phy + 250 000 +function phy = phy_clock_get_zero_cross_captured_date(phy) + +var = int(rand (1) * 100000); +phy = phy + 1000000 + var; +return phy; + +endfunction + -- cgit v1.2.3