diff options
Diffstat (limited to 'src/occApplet')
21 files changed, 4973 insertions, 0 deletions
diff --git a/src/occApplet/Makefile b/src/occApplet/Makefile new file mode 100755 index 0000000..1aa4200 --- /dev/null +++ b/src/occApplet/Makefile @@ -0,0 +1,53 @@ +# @file Makefile +# +# @brief OCC Applet Makefile +# + +# @page ChangeLogs Change Logs +# @section Makefile +# @verbatim +# +# +# Change Log ****************************************************************** +# Flag Defect/Feature User Date Description +# ------ -------------- ---------- ------------ ----------- +# @pb001 pbavari 07/21/2011 Created +# @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments +# +# @endverbatim +# + +# >> gitprep +ifndef ROOTPATH +ROOTPATH = $(shell pwd)/../ +export OCCROOT = $(ROOTPATH) +endif +# << gitprep + +#******************************************************************************* +# mk variable Declaration +#******************************************************************************* +SUBDIRS = productApplet testApplet +CLEANCMD = $(MAKE) clean -C $(dir); +ALLCMD = $(MAKE) -j6 -C $(dir); +COMBINEIMAGE = $(MAKE) combineImage -C $(dir); + +#******************************************************************************* +# Compilation +#******************************************************************************* +all: + $(foreach dir,$(SUBDIRS),$(ALLCMD)) + +#******************************************************************************* +# combineImage +#******************************************************************************* +.PHONY : combineImage +combineImage: + $(foreach dir,$(SUBDIRS),$(COMBINEIMAGE)) + +#******************************************************************************* +# Clean +#******************************************************************************* +clean: + $(foreach dir,$(SUBDIRS),$(CLEANCMD)) + diff --git a/src/occApplet/createApplet b/src/occApplet/createApplet new file mode 100755 index 0000000..784fcaa --- /dev/null +++ b/src/occApplet/createApplet @@ -0,0 +1,135 @@ +#!/usr/bin/perl +# +# Create a new applet source file from a template +# +# +my $template; +my $newfile = 0; +my $typeflag = 0; +my $feature = ""; +my $username = $ENV{USER}; +# version 2: Added applet id name support. +# version 1: Created this file +my $VERSION = "2"; + +#template file path +$template = $ENV{SANDBOXBASE} . "/src/occc/405/occApplet/template"; + +#usage +sub usage() +{ + + print "Usage: $0 -d <short_description_of_file> -f <functionNM> -i <unique applet Id String> <filename> \n"; + print "\n"; + print "-d: short description for the file\n"; + print "-f: Entry point function name\n"; + print "-i: Unique Applet Id string(15 char long and must be unique within applets)\n"; + print "-n: Applet ID name from the OCC_APLT enumeration for this applet (eg: OCC_APLT_TEST)\n"; + print "-V: Version\n"; + print "\n\n"; + + exit 1; +} + +sub createfile(@) +{ + + ($newfile,$type,$shortDesc,$funcNm,$appIdStr,$appIdNm) = @_; + + open TEMPL, "<$template.$type" || die "Unable to open: $template.$type\n"; + open NEWFILE, ">$newfile.$type" || die "Can't open: $newfile.$type\n"; + + read TEMPL, $buf, ( -s TEMPL ) || die "Unable to read template $template.$type\n"; + close TEMPL; + + # change the filename,function name, short description, applet id string + # and applet id + $upperNewFile = uc($newfile); + $upperFuncNm = uc($funcNm); + $buf =~ s/<filename.$type>/$newfile.$type/g; + $buf =~ s/<FILENAME.$type>/$upperNewFile.$type/g; + $buf =~ s/<shortDesc>/$shortDesc/g; + $buf =~ s/<funcNm>/$funcNm/g; + $buf =~ s/<FUNCNM>/$upperFuncNm/g; + $buf =~ s/<APPLET_ID_STR>/$appIdStr/g; + $buf =~ s/<APLT_ID>/$appIdNm/g; + + #change creation date + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; + $year = sprintf("%02s", $year % 100); + $mon = sprintf("%02s", $mon + 1); + $mday = sprintf("%02s", $mday); + $buf =~ s/MM\/DD\/YY/$mon\/$mday\/$year/; + + #change the userid + $buf =~ s/USERID/$username/; + + #write the file + print NEWFILE $buf; + + close NEWFILE; + +} + +while ($ARGV = shift) +{ + + if ($ARGV =~ m/-V/) + { + print "$0 version = $VERSION\n\n"; + exit 0; + } + elsif ($ARGV =~ m/-d/i) + { + $desc = shift; + usage() if $desc =~ m/(-f|-i)/; + $shortDesc = $desc; + $descFound = 1; + } + elsif ($ARGV =~ m/-f/i) + { + $func = shift; + usage() if $func =~ m/(-i)/; + $funcNm = $func; + } + elsif ($ARGV =~ m/-i/i) + { + $appIdStr = shift; + usage() if ! $appIdStr =~ m/\w+/; + } + elsif ($ARGV =~ m/-n/i) + { + $appIdNm = shift; + usage() if ! $appIdNm =~ m/\w+/; + } + elsif ($ARGV =~ m/\w+/) + { + $newfile = $ARGV; + } +} + +# check if all the expected inputs are received +if ( ! $newfile || ! $desc || ! $func || ! $appIdStr || !$appIdNm) +{ + usage(); +} + +if ( -e "$newfile.c" ) +{ + print "File $newfile exists, clobber file? (y/n) [n] "; + $clobber = <STDIN>; + if ( $clobber !~ m/^y/i ) + { + die "\nFile exists, cannot continue....\n"; + } + else + { + createfile($newfile,"c",$shortDesc,$funcNm,$appIdStr,$appIdNm); + } +} +else +{ + createfile($newfile,"c",$shortDesc,$funcNm,$appIdStr,$appIdNm); +} + + diff --git a/src/occApplet/productApplet/Makefile b/src/occApplet/productApplet/Makefile new file mode 100755 index 0000000..e87e37d --- /dev/null +++ b/src/occApplet/productApplet/Makefile @@ -0,0 +1,130 @@ +# $Id$ +# @file Makefile +# +# @brief OCC Product Applet Makefile +# + +# @page ChangeLogs Change Logs +# @section Makefile +# @verbatim +# +# +# Change Log ****************************************************************** +# Flag Defect/Feature User Date Description +# ------ -------------- ---------- ------------ ----------- +# @pb001 pbavari 07/18/2011 Created +# @ani01 abagepa 08/08/2011 Creating to "test" applets +# as placeholders for real applets +# Update to include for easier compiling +# @pb006 pbavari 09/16/2011 Display size support +# @pb004 pbavari 09/20/2011 Initialization Section support +# @pb00A pbavari 11/14/2011 Moved sensor_init from applet to init section +# @th005 thallet 11/23/2011 Sensor querySensorList support +# @pb00C pbavari 01/20/2012 Added debug_trace.mk +# @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments +# @at009 859308 alvinwan 10/15/2012 Added tracepp support +# @th029 thallet 01/23/2013 MD5sum in applet version & include aplt headers +# +# @endverbatim +# + +# >> gitprep +ifndef ROOTPATH +ROOTPATH = $(shell pwd)/../../ +export OCCROOT = $(ROOTPATH) +endif +# << gitprep + +#******************************************************************************* +# mk variable Declaration +#******************************************************************************* +OCC = ../../occ +BOOTLOADER = ../../occBootLoader +SSX = ../../ssx +PRODUCTAPPLET = . +LIB = ../../lib + +# New product applet source file must to listed as part of the SOURCES variable +# to create product applet image. Prodcut applet images will be added to the +# mainstore single image in the order source files are listed in SOURCES +# variable. +# @ani01c +# Note: New applets must be updated in the applet enum list +# see occ/aplt/appletManager.h + +# >> gitprep +# Add missing flags for GNU build +LDFLAGS = -L $(SSX)/ssx -L $(SSX)/ppc32 -L $(SSX)/ppc405 -L $(SSX)/pgp \ + -L $(OCC) -L $(LIB) -lssx -lppc32 --oformat=elf32-powerpc -melf32ppc +buildImage = $(LD) -R $(OCC)/occ.out $(obj) -Tlinkscript $(LDFLAGS) \ + -Map $(basename $(obj)).map -Bstatic -o $(basename $(obj)).out;\ + $(OBJCOPY) -I elf32-powerpc -O binary $(basename $(obj)).out $(basename $(obj)).bin; \ + $(OBJDUMP) -d $(basename $(obj)).out > $(basename $(obj)).dis; \ + $(BOOTLOADER)/imageHdrScript $(basename $(obj)).bin `md5sum $(OCC)/occ.out | cut -c 1-4`; +# << gitprep + +image = $(BOOTLOADER)/imageHdrScript $(basename $(obj)).bin combineImage;\ + $(BOOTLOADER)/imageHdrScript $(basename $(obj)).out displaySize; + +#******************************************************************************* +# Includes +#******************************************************************************* +include $(SSX)/pgp/ssx.mk +#$pb00Ca - Added for debug traces +include $(OCC)/debug_trace.mk +include productappletfiles.mk + +# >> gitprep +# Add needed includes for GNU build +INCLUDES = -I. -I$(OCC)/incl -I$(OCC)/errl -I$(OCC)/trac -I$(LIB) -I$(SSX)/ssx \ + -I$(OCC)/sensor -I$(OCC) -I$(OCC)/rtls -I$(OCC)/cmdh -I$(OCC)/pss -I$(OCC)/gpe \ + -I$(OCC)/aplt/incl -I$(OCC)/aplt -I$(OCC)/cent -I$(OCC)/proc -I$(OCC)/thread \ + -I$(SSX)/ppc405 -I$(SSX)/pgp -I$(SSX)/ppc32 -I$(SSX)/pgp/registers +# << gitprep + +#******************************************************************************* +# Flags +#******************************************************************************* +#D = -DSIMICS_MAGIC_PANIC=1 \ + -DINITIALIZE_SIMICS_IO=1 + +DEFS += $(D) +DEFS += -DAPPLET_BUILD=1 +# >> gitprep +# Very important we build applets with custom cfg header +DEFS += -DUSE_SSX_APP_CFG_H=1 +# << gitprep + +# If this makefile is called as "make NO_TRAC_STRINGS=1" then trace strings +# won't be built into the image. This will be used for metrics regarded to the +# realistic OCC Code Size. Note that "make clean" must be run before this define +# will be picked up by the compiler, otherwise previously compiled objects will +# be used. You can also see the space used by strings by running: +# strings occ.bin | \grep "ERR\|INF\|IMP" | sed 's/^...: %s: //g' | wc -m +ifdef NO_TRAC_STRINGS +D += -DNO_TRAC_STRINGS=1 +endif + +# Do not use SDA sections for product applet +GCC-CFLAGS = -c -g -Wall -fsigned-char -msoft-float -pipe \ + -Wa,-m405 -m32 -mcpu=405 -mmultiple -mstring -meabi \ + -ffreestanding -Os -mno-sdata +#******************************************************************************* +# Compilation +#******************************************************************************* +all: $(PRDTAPLT_OBJECTS) + $(CPP) -P $(DEFS) < linkProductApplet.cmd > linkscript + $(foreach obj,$(PRDTAPLT_OBJECTS),$(buildImage)) + +#******************************************************************************* +# combineImage +#******************************************************************************* +.PHONY : combineImage +combineImage: + $(foreach obj,$(PRDTAPLT_OBJECTS),$(image)) + +#******************************************************************************* +# Clean +#******************************************************************************* +clean: + rm -f *.o *.out *.bin *.dis *.map *.hash linkscript diff --git a/src/occApplet/productApplet/apssInitApplet.c b/src/occApplet/productApplet/apssInitApplet.c new file mode 100755 index 0000000..4a7a84f --- /dev/null +++ b/src/occApplet/productApplet/apssInitApplet.c @@ -0,0 +1,322 @@ +/****************************************************************************** +// @file apssInitApplet.c +// @brief APSS initialization product applet +*/ + +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section apssInitApplet.c APSSINITAPPLET.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * @pb004 pbavari 09/13/2011 created + * @pb009 pbavari 10/31/2011 Moved apss_initialize retry + * inside applet + * @dw000 dwoodham 12/12/2011 Update call to IMAGE_HEADER + * @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments + * @nh001 neilhsu 05/23/2012 Add missing error log tags + * @at009 859308 alvinwan 10/15/2012 Added tracepp support + * @ly003 861535 lychen 11/19/2012 Remove APSS configuration/gathering of Altitude & Temperature + * @th042 892056 thallet 07/19/2013 Send OCC to safe mode if first APSS GPE fails + * @at023 910877 alvinwan 01/09/2014 Excessive fan increase requests error for mfg + * @fk005 911760 fmkassem 01/21/2014 APSS retry support. + * + * @endverbatim + * + *///*************************************************************************/ + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include <trac.h> // For traces +#include <occ_service_codes.h> // for SSX_GENERIC_FAILURE // @nh001a +#include <pss_service_codes.h> // APSS module ids +#include <apss.h> // APSS defines +#include <appletId.h> // For applet ID num dw000a +#include "ssx_io.h" // For printf +#include <state.h> + +//************************************************************************* +// Externs +//************************************************************************* +extern PoreEntryPoint GPE_apss_initialize_gpio; +extern PoreEntryPoint GPE_apss_set_composite_mode; +extern PoreFlex G_meas_start_request; +extern PoreFlex G_meas_cont_request; +extern PoreFlex G_meas_complete_request; +extern apss_start_args_t G_gpe_start_pwr_meas_read_args; +extern apss_continue_args_t G_gpe_continue_pwr_meas_read_args; +extern apss_complete_args_t G_gpe_complete_pwr_meas_read_args; +extern PoreEntryPoint GPE_apss_start_pwr_meas_read; +extern PoreEntryPoint GPE_apss_continue_pwr_meas_read; +extern PoreEntryPoint GPE_apss_complete_pwr_meas_read; +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define APSS_INITIALIZE_ID "APSS Init Aplt\0" + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + + +// Function Specification +// +// Name: apss_initialize +// +// Description: Completes all APSS initialization including GPIOs, altitude and +// mode +// +// Flow: 07/20/11 FN=apss_initialize +// +// changeTags: @fk005c, +// +// End Function Specification +errlHndl_t apss_initialize() +{ + errlHndl_t l_err = NULL; + PoreFlex request; + + // Setup the GPIO init structure to pass to the GPE program + G_gpe_apss_initialize_gpio_args.error.error = 0; + G_gpe_apss_initialize_gpio_args.error.ffdc = 0; + G_gpe_apss_initialize_gpio_args.config0.direction + = G_gpio_config[0].direction; + G_gpe_apss_initialize_gpio_args.config0.drive + = G_gpio_config[0].drive; + G_gpe_apss_initialize_gpio_args.config0.interrupt + = G_gpio_config[0].interrupt; + G_gpe_apss_initialize_gpio_args.config1.direction + = G_gpio_config[1].direction; + G_gpe_apss_initialize_gpio_args.config1.drive = G_gpio_config[1].drive; + G_gpe_apss_initialize_gpio_args.config1.interrupt + = G_gpio_config[1].interrupt; + + // Create/schedule GPE_apss_initialize_gpio and wait for it to complete (BLOCKING) + TRAC_INFO("Creating request for GPE_apss_initialize_gpio"); + pore_flex_create(&request, // request + &G_pore_gpe0_queue, // queue + (void*)GPE_apss_initialize_gpio, // GPE entry_point + (uint32_t)&G_gpe_apss_initialize_gpio_args,// GPE argument_ptr + SSX_SECONDS(5), // timeout + NULL, // callback + NULL, // callback arg + ASYNC_REQUEST_BLOCKING); // options + // Schedule the request to be executed + pore_flex_schedule(&request); + + // Check for a timeout, will create the error log later + // NOTE: As of 2013/07/16, simics will still fail here on a OCC reset + + if(ASYNC_REQUEST_STATE_TIMED_OUT == request.request.completion_state) + { + // For whatever reason, we hit a timeout. It could be either + // that the HW did not work, or the request didn't ever make + // it to the front of the queue. + // Let's log an error, and include the FFDC data if it was + // generated. + TRAC_ERR("Timeout communicating with PORE-GPE for APSS Init"); + } + + TRAC_INFO("GPE_apss_initialize_gpio completed w/rc=0x%08x\n", + request.request.completion_state); + + // Only continue if completed without errors... + if (ASYNC_REQUEST_STATE_COMPLETE == request.request.completion_state) + { + // @ly003c - start + // Setup the composite mode structure to pass to the GPE program + G_gpe_apss_set_composite_mode_args.error.error = 0; + G_gpe_apss_set_composite_mode_args.error.ffdc = 0; + G_gpe_apss_set_composite_mode_args.config.numAdcChannelsToRead = + G_apss_composite_config.numAdcChannelsToRead; + G_gpe_apss_set_composite_mode_args.config.numGpioPortsToRead = + G_apss_composite_config.numGpioPortsToRead; + + // Create/schedule GPE_apss_set_composite_mode and wait for it to complete (BLOCKING) + TRAC_INFO("Creating request for GPE_apss_set_composite_mode"); + pore_flex_create(&request, // request + &G_pore_gpe0_queue, // queue + (void*)GPE_apss_set_composite_mode, // GPE entry_point + (uint32_t)&G_gpe_apss_set_composite_mode_args,// GPE argument_ptr + SSX_SECONDS(5), // timeout + NULL, // callback + NULL, // callback arg + ASYNC_REQUEST_BLOCKING); // options + pore_flex_schedule(&request); + + // Check for a timeout, will create the error log later + // NOTE: As of 2013/07/16, simics will still fail here on a OCC reset + + if(ASYNC_REQUEST_STATE_TIMED_OUT == request.request.completion_state) + { + // For whatever reason, we hit a timeout. It could be either + // that the HW did not work, or the request didn't ever make + // it to the front of the queue. + // Let's log an error, and include the FFDC data if it was + // generated. + TRAC_ERR("Timeout communicating with PORE-GPE for APSS Init"); + } + + TRAC_INFO("GPE_apss_set_composite_mode completed w/rc=0x%08x", + request.request.completion_state); + + if (ASYNC_REQUEST_STATE_COMPLETE != request.request.completion_state) + { + /* + * @errortype + * @moduleid PSS_MID_APSS_INIT + * @reasoncode INTERNAL_FAILURE + * @userdata1 GPE returned rc code + * @userdata2 GPE returned abort code + * @userdata4 ERC_PSS_COMPOSITE_MODE_FAIL + * @devdesc Failure from GPE for setting composite mode on + * APSS + */ + l_err = createErrl(PSS_MID_APSS_INIT, // i_modId, + INTERNAL_FAILURE, // i_reasonCode, + ERC_PSS_COMPOSITE_MODE_FAIL, // extended reason code + ERRL_SEV_UNRECOVERABLE, // i_severity + NULL, // TODO - tracDesc_t i_trace, + 0x0000, // i_traceSz, + request.request.completion_state, // i_userData1, + request.request.abort_state); // i_userData2 + addUsrDtlsToErrl(l_err, + (uint8_t*)&G_gpe_apss_set_composite_mode_args, + sizeof(G_gpe_apss_set_composite_mode_args), + ERRL_STRUCT_VERSION_1, // TODO + ERRL_USR_DTL_TRACE_DATA); + + // Returning an error log will cause us to go to safe + // state so we can report error to FSP + } + // @ly003c - end + + + TRAC_INFO("apss_initialize: Creating request G_meas_start_request."); + //Create the request for measure start. Scheduling will happen in apss.c + pore_flex_create(&G_meas_start_request, + &G_pore_gpe0_queue, // queue + (void*)GPE_apss_start_pwr_meas_read, // entry_point + (uint32_t)&G_gpe_start_pwr_meas_read_args, // entry_point arg + SSX_WAIT_FOREVER, // no timeout + NULL, // callback + NULL, // callback arg + ASYNC_CALLBACK_IMMEDIATE); // options + + TRAC_INFO("apss_initialize: Creating request G_meas_cont_request."); + //Create the request for measure continue. Scheduling will happen in apss.c + pore_flex_create(&G_meas_cont_request, + &G_pore_gpe0_queue, // request + (void*)GPE_apss_continue_pwr_meas_read, // entry_point + (uint32_t)&G_gpe_continue_pwr_meas_read_args, // entry_point arg + SSX_WAIT_FOREVER, // no timeout + NULL, // callback + NULL, // callback arg + ASYNC_CALLBACK_IMMEDIATE); // options + + TRAC_INFO("apss_initialize: Creating request G_meas_complete_request."); + //Create the request for measure complete. Scheduling will happen in apss.c + pore_flex_create(&G_meas_complete_request, + &G_pore_gpe0_queue, // queue + (void*)GPE_apss_complete_pwr_meas_read, // entry_point + (uint32_t)&G_gpe_complete_pwr_meas_read_args,// entry_point arg + SSX_WAIT_FOREVER, // no timeout + (AsyncRequestCallback)reformat_meas_data, // callback, + (void*)NULL, // callback arg + ASYNC_CALLBACK_IMMEDIATE); // options + + } + else + { + /* + * @errortype + * @moduleid PSS_MID_APSS_INIT + * @reasoncode INTERNAL_FAILURE + * @userdata1 GPE returned rc code + * @userdata2 GPE returned abort code + * @userdata4 ERC_PSS_GPIO_INIT_FAIL + * @devdesc Failure from GPE for gpio initialization on APSS + */ + l_err = createErrl(PSS_MID_APSS_INIT, // i_modId, + INTERNAL_FAILURE, // i_reasonCode, + ERC_PSS_GPIO_INIT_FAIL, // extended reason code + ERRL_SEV_UNRECOVERABLE, // i_severity + NULL, // tracDesc_t i_trace, + 0x0000, // i_traceSz, + request.request.completion_state, // i_userData1, + request.request.abort_state); // i_userData2 + addUsrDtlsToErrl(l_err, + (uint8_t*)&G_gpe_apss_initialize_gpio_args, + sizeof(G_gpe_apss_initialize_gpio_args), + ERRL_STRUCT_VERSION_1, // TODO + ERRL_USR_DTL_TRACE_DATA); + + // Returning an error log will cause us to go to safe + // state so we can report error to FSP + } + + return l_err; +} + + +// Function Specification +// +// Name: apssInitApplet +// +// Description: Entry point function +// +// Flow: --/--/---- FN= None +// +// End Function Specification +errlHndl_t apssInitApplet(void * i_arg) +{ + errlHndl_t l_err = NULL; + + // Initialize APSS + l_err = apss_initialize(); + + if( NULL != l_err) + { + TRAC_ERR("APSS Init failed! (retrying) ErrLog[%p]", l_err ); + setErrlSevToInfo(l_err); + // commit & delete + commitErrl( &l_err ); + + // Retry one more time + l_err = apss_initialize(); + + if( NULL != l_err) + { + TRAC_ERR("APSS Init failed again! ErrLog[%p]",l_err); + } + } + + return l_err; +} +/*****************************************************************************/ +// Image Header +/*****************************************************************************/ +// @dw000 - Add applet ID arg to IMAGE_HEADER macro call +IMAGE_HEADER (G_apss_initialize,apssInitApplet,APSS_INITIALIZE_ID,OCC_APLT_APSS_INIT); + diff --git a/src/occApplet/productApplet/cmdhDbugCmd.c b/src/occApplet/productApplet/cmdhDbugCmd.c new file mode 100755 index 0000000..2ef7788 --- /dev/null +++ b/src/occApplet/productApplet/cmdhDbugCmd.c @@ -0,0 +1,341 @@ +/****************************************************************************** +// @file cmdhDebugCmd.c +// @brief CMDH Debug Command +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section cmdhDbugCmd.c CMDHDEBUGCMD.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * @th00d thallet 04/25/2012 created + * @nh004 864941 neilhsu 12/20/2012 Support get/delete errl & added trace info + * @th031 878471 thallet 04/15/2013 Centaur Throttles + * @th032 thallet 04/26/2013 Tuleta HW Bringup + * @th036 881677 thallet 05/07/2013 Cleanup + * @gm006 SW224414 milesg 09/16/2013 Reset and FFDC improvements + * @rt001 897459 tapiar 10/02/2013 Update module ids with unique ids + * @fk002 905632 fmkassem 11/05/2013 Remove CriticalPathMonitor code + * + * @endverbatim + * + *///*************************************************************************/ + + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <occ_service_codes.h> // For reason code +#include <aplt_service_codes.h> // For test applet module ID +#include <errl.h> // For error handle +#include <trac.h> // For traces +#include <state.h> +#include <appletId.h> +#include <cmdhDbugCmd.h> +#include <cmdh_fsp.h> +#include <cmdh_fsp_cmds.h> +#include <centaur_data.h> +#include <gpe_data.h> +#include <proc_data.h> +#include <apss.h> + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define CMDH_DBUG_APPLET_ID "Cmdh_Dbug_Aplt\0" + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + +// Function Specification +// +// Name: dbug_err_inject +// +// Description: Injects an error +// +// Flow: --/--/-- FN= +// +// End Function Specification +void dbug_err_inject(const cmdh_fsp_cmd_t * i_cmd_ptr, + cmdh_fsp_rsp_t * i_rsp_ptr) // @nh004c +{ + errlHndl_t l_err; + cmdh_dbug_inject_errl_query_t *l_cmd_ptr = (cmdh_dbug_inject_errl_query_t*) i_cmd_ptr; + + i_rsp_ptr->data_length[0] = 0; + i_rsp_ptr->data_length[1] = 0; + i_rsp_ptr->rc = ERRL_RC_SUCCESS; + + if(!strncmp(l_cmd_ptr->comp, "RST", OCC_TRACE_NAME_SIZE)) //@gm006 + { + l_err = createErrl(TEST_APLT_MODID_ERRLTEST, //modId + INTERNAL_FAILURE, //reasoncode + OCC_NO_EXTENDED_RC, //Extended reason code + ERRL_SEV_PREDICTIVE, //Severity + NULL, //Trace Buf + DEFAULT_TRACE_SIZE, //Trace Size + 0xff, //userdata1 + 0); //userdata2 + + if (INVALID_ERR_HNDL == l_err) + { + i_rsp_ptr->rc = ERRL_RC_INTERNAL_FAIL; + } + + addCalloutToErrl(l_err, + ERRL_CALLOUT_TYPE_HUID, //callout type (HUID/CompID) + G_sysConfigData.proc_huid, //callout data + ERRL_CALLOUT_PRIORITY_HIGH); //priority + + REQUEST_RESET(l_err); + } + else + { + l_err = createErrl(TEST_APLT_MODID_ERRLTEST, //modId + INTERNAL_FAILURE, //reasoncode + OCC_NO_EXTENDED_RC, //Extended reason code + ERRL_SEV_UNRECOVERABLE, //Severity + TRAC_get_td(l_cmd_ptr->comp), //Trace Buf + DEFAULT_TRACE_SIZE, //Trace Size + 0xff, //userdata1 + 0); //userdata2 + + if (INVALID_ERR_HNDL == l_err) + { + i_rsp_ptr->rc = ERRL_RC_INTERNAL_FAIL; + } + + // Commit Error log + commitErrl(&l_err); + } + + if (i_rsp_ptr->rc == ERRL_RC_INTERNAL_FAIL) + { + TRAC_ERR("cmdh_dbug_inject_errl: Fail creating ERR Log\n"); + } + else + { + TRAC_INFO("cmdh_dbug_inject_errl: inject errl for COMP : %s\n", l_cmd_ptr->comp); + } + + return; +} + +// Function Specification +// +// Name: dbug_centaur_dump +// +// Description: Injects an error +// +// Flow: --/--/-- FN= +// +// End Function Specification +void dbug_centaur_dump(const cmdh_fsp_cmd_t * i_cmd_ptr, + cmdh_fsp_rsp_t * i_rsp_ptr) // @nh004c +{ + uint16_t l_datalen = 0; + uint8_t l_jj=0; + + // Determine the size of the data we are returning + l_datalen = (sizeof(MemData) * MAX_NUM_CENTAURS); + + // Fill out the response with the data we are returning + for(l_jj=0; l_jj < MAX_NUM_CENTAURS; l_jj++) + { + MemData * l_sensor_cache_ptr = + cent_get_centaur_data_ptr(l_jj); + + memcpy((void *) &(i_rsp_ptr->data[l_jj*sizeof(MemData)]), + (void *) l_sensor_cache_ptr, + sizeof(MemData)); + } + + // Fill out the rest of the response data + i_rsp_ptr->data_length[0] = CONVERT_UINT16_UINT8_HIGH(l_datalen); + i_rsp_ptr->data_length[1] = CONVERT_UINT16_UINT8_LOW(l_datalen); + i_rsp_ptr->rc = ERRL_RC_SUCCESS; + + + return; +} + + +// Function Specification +// +// Name: dbug_apss_dump +// +// Description: Dumps the APSS power measurement raw ADC / GPIO data +// +// Flow: --/--/-- FN= +// +// End Function Specification +void dbug_apss_dump(const cmdh_fsp_cmd_t * i_cmd_ptr, + cmdh_fsp_rsp_t * i_rsp_ptr) +{ + uint16_t l_datalen = 0; + + // Determine the size of the data we are returning + l_datalen = (sizeof(apssPwrMeasStruct_t)); + + memcpy((void *) &(i_rsp_ptr->data[0]), + (void *) &G_apss_pwr_meas, + sizeof(apssPwrMeasStruct_t)); + + // Fill out the rest of the response data + i_rsp_ptr->data_length[0] = CONVERT_UINT16_UINT8_HIGH(l_datalen); + i_rsp_ptr->data_length[1] = CONVERT_UINT16_UINT8_LOW(l_datalen); + i_rsp_ptr->rc = ERRL_RC_SUCCESS; + + + return; +} + + +// Function Specification +// +// Name: dbug_proc_data_dump +// +// Description: Dumps the processor core data +// +// Flow: --/--/-- FN= +// +// End Function Specification +void dbug_proc_data_dump(const cmdh_fsp_cmd_t * i_cmd_ptr, + cmdh_fsp_rsp_t * i_rsp_ptr) +{ + uint16_t l_datalen = 0; + uint8_t l_jj=0; + + // Determine the size of the data we are returning + l_datalen = (sizeof(CoreData) * MAX_NUM_CORES); + + // Fill out the response with the data we are returning + for(l_jj=0; l_jj < MAX_NUM_CORES; l_jj++) + { + CoreData * l_core_data_ptr = + proc_get_bulk_core_data_ptr(l_jj); + + memcpy((void *) &(i_rsp_ptr->data[l_jj*sizeof(CoreData)]), + (void *) l_core_data_ptr, + sizeof(CoreData)); + } + + // Fill out the rest of the response data + i_rsp_ptr->data_length[0] = CONVERT_UINT16_UINT8_HIGH(l_datalen); + i_rsp_ptr->data_length[1] = CONVERT_UINT16_UINT8_LOW(l_datalen); + i_rsp_ptr->rc = ERRL_RC_SUCCESS; + + + return; +} + +// Function Specification +// +// Name: cmdhDbugCmd +// +// Description: Entry-point for CMDH Debug Commands +// +// Flow: --/--/-- FN= +// +// End Function Specification +errlHndl_t cmdhDbugCmd(void * i_arg) +{ + errlHndl_t l_errl = NULL; + cmdhDbugCmdAppletArg_t * l_arg = (cmdhDbugCmdAppletArg_t *) i_arg; + cmdh_fsp_cmd_t * l_cmd_ptr = l_arg->i_cmd_ptr; + cmdh_fsp_rsp_t * l_rsp_ptr = l_arg->io_rsp_ptr; + uint8_t l_sub_cmd = 0; + + // Sub Command for debug is always first byte of data + l_sub_cmd = l_cmd_ptr->data[0]; + + // Trace that a debug command was run + TRAC_INFO("Debug Command via Applet: Sub:0x%02x\n", l_sub_cmd); + + // Build up a successful default response + l_rsp_ptr->rc = ERRL_RC_SUCCESS; + l_rsp_ptr->data_length[0] = 0; + l_rsp_ptr->data_length[1] = 0; + + switch ( l_sub_cmd ) + { + case DBUG_INJECT_ERRL: + dbug_err_inject(l_cmd_ptr, l_rsp_ptr); + break; + + case DBUG_CENTAUR_SENSOR_CACHE: + dbug_centaur_dump(l_cmd_ptr, l_rsp_ptr); + break; + + case DBUG_DUMP_RAW_AD: + dbug_apss_dump(l_cmd_ptr, l_rsp_ptr); + break; + + case DBUG_DUMP_PROC_DATA: + dbug_proc_data_dump(l_cmd_ptr, l_rsp_ptr); + break; + + case DBUG_READ_SCOM: // Obsolete + case DBUG_PUT_SCOM: // Obsolete + case DBUG_POKE: // Can't allow in trusted + case DBUG_GET_TRACE: + case DBUG_CLEAR_TRACE: + case DBUG_SET_PEXE_EVENT: + case DBUG_DUMP_THEMAL: + case DBUG_DUMP_POWER: + case DBUG_MEM_PWR_CTL: + case DBUG_PERFCOUNT: + case DBUG_TEST_INTF: + case DBUG_SET_BUS_SPEED: // Obsolete + case DBUG_FAN_CONTROL: // Obsolete + case DBUG_IIC_READ: // Obsolete + case DBUG_IIC_WRITE: // Obsolete + case DBUG_GPIO_READ: + case DBUG_CALCULATE_MAX_DIFF: + case DBUG_FORCE_ELOG: + case DBUG_SWITCH_PHASE: + case DBUG_INJECT_ERR: + case DBUG_VERIFY_V_F: + case DBUG_DUMP_PPM_DATA: + default: + l_rsp_ptr->rc = ERRL_RC_INVALID_DATA; + break; + } //end switch + + + return l_errl; +} + + + + + +/*****************************************************************************/ +// Image Header +/*****************************************************************************/ +IMAGE_HEADER (G_cmdhDbugCmd,cmdhDbugCmd,CMDH_DBUG_APPLET_ID,OCC_APLT_CMDH_DBUG); + diff --git a/src/occApplet/productApplet/dpssInitApplet.c b/src/occApplet/productApplet/dpssInitApplet.c new file mode 100755 index 0000000..5015feb --- /dev/null +++ b/src/occApplet/productApplet/dpssInitApplet.c @@ -0,0 +1,304 @@ +/****************************************************************************** +// @file dpssInitApplet.c +// @brief DPSS initialization product applet +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section dpssInitApplet.c DPSSINITAPPLET.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * @at000 alvinwan 12/07/2011 created + * @dw000 dwoodham 12/16/2011 Update call to IMAGE_HEADER + * @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments + * @nh001 neilhsu 05/23/2012 Add missing error log tags + * + * @endverbatim + * + *///*************************************************************************/ + + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include <dpss.h> +#include <trac.h> // For traces +#include <occ_sys_config.h> +#include <occ_service_codes.h> // for SSX_GENERIC_FAILURE // @nh001a +#include <pss_service_codes.h> +#include <state.h> +#include <appletId.h> // For applet ID num dw000a + +//************************************************************************* +// Externs +//************************************************************************* +extern PoreEntryPoint GPE_dpss_send_command_stream; +extern PoreFlex G_dpss_read_status_request; +extern gpeDpssCommandStream_t G_gpe_dpss_read_status; + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define DPSSINITAPPLET_ID "DPSS_Init_Aplt\0" + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + +// Function Specification +// +// Name: dpss_initialize +// +// Description: Initializes DPSS fans and oversubscription interrupt +// If errHndl is returned, caller should call this function again, +// one time only, in the hopes that it will work on the retry. +// +// Flow: 08/03/11 FN=dpss_initialize +// +// End Function Specification +errlHndl_t dpss_initialize(void) +{ + errlHndl_t l_err = NULL; + PoreFlex request; + uint8_t i, l_idx_limit; // index counter and limit value + + // Build command data + // Structures from this array we will be passed into our GPE program one-by-one + gpeDpssCommandStream_t l_gpe_dpss_stream_dpss_config[] = { + + { .dpss_msg_stream = { + .command[0] = DPSS_CMD_SET_MIN_FANS | G_sysConfigData.dpss_fan.min_fans, + .command[1] = DPSS_CMD_SET_PWM_DELAY | G_sysConfigData.dpss_fan.pwm_delay_reg, + .command[2] = DPSS_CMD_SET_PWM_STEP | G_sysConfigData.dpss_fan.pwm_step_reg, + .command[3] = 0x0000, + .response = {0} + }, + }, + + { .dpss_msg_stream = { + .command[0] = DPSS_CMD_SET_FAN_PPR_0 | G_sysConfigData.dpss_fan.fan_ppr[0], + .command[1] = DPSS_CMD_SET_FAN_PPR_1 | G_sysConfigData.dpss_fan.fan_ppr[1], + .command[2] = 0x0000, + .command[3] = 0x0000, + .response = {0} + }, + }, + + // Fan hysterisis: write low byte, then high byte + { .dpss_msg_stream = { + .command[0] = DPSS_CMD_SET_FAN_HYST_1_LO | G_sysConfigData.dpss_fan.fan_hysterisis[1], + .command[1] = DPSS_CMD_SET_FAN_HYST_0_HI | G_sysConfigData.dpss_fan.fan_hysterisis[0], + .command[2] = 0x0000, + .command[3] = 0x0000, + .response = {0} + }, + }, + + // Fan hysterisis: write low byte, then high byte + { .dpss_msg_stream = { + .command[0] = DPSS_CMD_SET_FAN_HYST_3_LO | G_sysConfigData.dpss_fan.fan_hysterisis[3], + .command[1] = DPSS_CMD_SET_FAN_HYST_2_HI | G_sysConfigData.dpss_fan.fan_hysterisis[2], + .command[2] = DPSS_CMD_SET_FAN_MODE | G_sysConfigData.dpss_fan.fan_mode, + .command[3] = 0x0000, + .response = {0} + }, + }, + + { .dpss_msg_stream = { + .command[0] = DPSS_CMD_SET_FAN_MASK | G_sysConfigData.dpss_fan.fan_mask, + .command[1] = DPSS_CMD_SET_FAN_HYST_MASK | G_sysConfigData.dpss_fan.fan_hyst_mask, + .command[2] = DPSS_CMD_SET_MAX_FAN_PWM | G_sysConfigData.dpss_fan.max_fan_pwm, + .command[3] = 0x0000, + .response = {0} + }, + }, + + { .dpss_msg_stream = { + .command[0] = DPSS_CMD_SET_MIN_PWM | G_sysConfigData.dpss_fan.min_pwm, + .command[1] = DPSS_CMD_SET_SPI_FFS | G_sysConfigData.dpss_fan.spi_ffs, + .command[2] = DPSS_CMD_SET_SPIS_INT_MASK | G_sysConfigData.dpss_spis_int_mask, + .command[3] = 0x0000, + .response = {0} + }, + }, + + { .dpss_msg_stream = { + .command[0] = DPSS_CMD_SET_END_COUNT | G_sysConfigData.dpss_fan.end_count_reg, + .command[1] = DPSS_CMD_SET_FAN_WARN_COUNT | G_sysConfigData.dpss_fan.fan_warning_cnt, + .command[2] = 0x0000, + .command[3] = 0x0000, + .response = {0} + }, + }, + }; + + // Calculate the array size dynamically so we don't have to update it if the array changes. + l_idx_limit = sizeof(l_gpe_dpss_stream_dpss_config) / sizeof(gpeDpssCommandStream_t); + + for( i = 0; i < l_idx_limit; i++) { + // Clear the error reporting parts of the argument structure. + l_gpe_dpss_stream_dpss_config[i].gpe_error.error = 0; + l_gpe_dpss_stream_dpss_config[i].gpe_error.ffdc = 0; + + // Create GPE program request + DPSS_DEBUG_PRINTF(("%s: Calling GPE_dpss_send_command_stream for index %d\n", __FUNCTION__, i)); + pore_flex_create(&request, // request + &pore_gpe0_queue, // queue + (void*)GPE_dpss_send_command_stream, // GPE entry_point + (uint32_t)&l_gpe_dpss_stream_dpss_config[i], // GPE argument_ptr + NULL, // callback + NULL, // callback arg + ASYNC_REQUEST_BLOCKING); // options + + // Schedule the request to be executed + // Because our GPE structures are not in non-cacheable RAM (they are in the .init section instead), + // we have to flush the dcache before making the pore flex request, then invalidate the dcache afterward. + dcache_flush(&l_gpe_dpss_stream_dpss_config[i], sizeof(l_gpe_dpss_stream_dpss_config[i])); + pore_flex_schedule(&request); + dcache_invalidate((void *)(&l_gpe_dpss_stream_dpss_config[i]), sizeof(l_gpe_dpss_stream_dpss_config[i])); + + DPSS_DEBUG_PRINTF(("%s: GPE_dpss_send_command_stream for index %d returned: 0x%08X\n", __FUNCTION__, i, l_gpe_dpss_stream_dpss_config[i].gpe_error.rc)); + DPSS_DEBUG_PRINTF(("\tcommand[0] = 0x%04x, response[0] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[0], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[0])); + DPSS_DEBUG_PRINTF(("\tcommand[1] = 0x%04x, response[1] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[1], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[1])); + DPSS_DEBUG_PRINTF(("\tcommand[2] = 0x%04x, response[2] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[2], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[2])); + DPSS_DEBUG_PRINTF(("\tcommand[3] = 0x%04x, response[3] = 0x%04x\n", l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[3], l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[3])); + + // Check for errors and invalid DPSS responses. + // (Valid DPSS responses should be an echo of the cmd & data passed in). + + if ( (l_gpe_dpss_stream_dpss_config[i].gpe_error.rc != 0) || + (l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[0] != l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[0]) || + (l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[1] != l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[1]) || + (l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.response[2] != l_gpe_dpss_stream_dpss_config[i].dpss_msg_stream.command[2]) ) + { + DPSS_DEBUG_PRINTF(("%s: ...Failed with error.\n", __FUNCTION__)); + + /*@ + * @moduleid PSS_MID_DPSS_INIT + * @reasonCode INTERNAL_HW_FAILURE + * @severity ERRL_SEV_UNRECOVERABLE + * @userdata1 GPE error return code + * @userdata2 GPE error ffdc + * @userdata4 OCC_NO_EXTENDED_RC + * @devdesc GPE command failed to initialize the DPSS + */ + l_err = createErrl(PSS_MID_DPSS_INIT, // i_modId, + INTERNAL_HW_FAILURE, // i_reasonCode, + OCC_NO_EXTENDED_RC, // extended reason code // @nh001a + ERRL_SEV_UNRECOVERABLE, + NULL, // tracDesc_t i_trace, + 0x0000, // i_traceSz, + l_gpe_dpss_stream_dpss_config[i].gpe_error.rc, // i_userData1, + l_gpe_dpss_stream_dpss_config[i].gpe_error.ffdc >> 32); // i_userData2 + + // Put extra debug info into local data struct + addUsrDtlsToErrl(l_err, + (uint8_t*)&l_gpe_dpss_stream_dpss_config[i], + sizeof(l_gpe_dpss_stream_dpss_config[i]), + ERRL_STRUCT_VERSION_1, + ERRL_USR_DTL_TRACE_DATA); + break; + } + else { + DPSS_DEBUG_PRINTF(("%s: ...Success!\n", __FUNCTION__)); + } + } + + return l_err; +} // end dpss_initialize() + +// Function Specification +// +// Name: dpssInitApplet (old name is start_dpss) +// +// Description: +// Entry-point for enabling DPSS functionality. +// Initializes the DPSS chip. Starts the "DPSS Read Status" RTLS task. +// +// Flow: 08/03/11 FN=dpss_initialize +// Modified from original flow (approved, T. Hallett, 10/03/2011). +// Further mods recommended in DPSS code review 10/19/2011. +// +// End Function Specification +errlHndl_t dpssInitApplet(void * i_arg) +{ + // Init DPSS + TRAC_INFO("Initializing DPSS registers..."); + + errlHndl_t l_errl = dpss_initialize(); + + if (l_errl) + { + // init failed, attempt one more time before giving up + TRAC_ERR("dpss_initialize failed! (retrying)..."); + + // Convert the error severity to info and log it. + setErrlSevToInfo(l_errl); + commitErrl( &l_errl ); + + l_errl = dpss_initialize(); + + if (l_errl) + { + TRAC_ERR("dpss_initialize failed again! OCC will be reset."); + + // Log the error with its original unrecoverable severity + commitErrl( &l_errl ); + + REQUEST_RESET(); // @th006 + } + } + + if( !l_errl ) + { + TRAC_INFO("...DPSS initialized."); + TRAC_INFO("Enabling DPSS Read Status RTLS task."); + + // Init the global DPSS read-status PORE flex request. + // None of these values is expected to change. + pore_flex_create(&G_dpss_read_status_request, // request + &pore_gpe0_queue, // queue + (void*)GPE_dpss_send_command_stream, // GPE entry_point + (uint32_t)&G_gpe_dpss_read_status, // GPE argument_ptr + NULL, // callback + NULL, // callback arg + 0); // options DO NOT set this to ASYNC_REQUEST_BLOCKING + + // Make this task runnable. + rtl_start_task(TASK_ID_DPSS_RD_STATUS); + } + + return l_errl; +} // end dpssInitApplet + + + + + +/*****************************************************************************/ +// Image Header +/*****************************************************************************/ +// @dw000 - Add applet ID arg to IMAGE_HEADER macro call +// TODO: Change this if/when DPSS is enabled. +IMAGE_HEADER (G_dpssInitApplet,dpssInitApplet,DPSSINITAPPLET_ID,OCC_APLT_INVALID); + diff --git a/src/occApplet/productApplet/linkProductApplet.cmd b/src/occApplet/productApplet/linkProductApplet.cmd new file mode 100755 index 0000000..f806f92 --- /dev/null +++ b/src/occApplet/productApplet/linkProductApplet.cmd @@ -0,0 +1,55 @@ + +// $Id$ + + +// This linker script for the product applet. + +#define APP_IMAGE_SRAM_START_ADDR 0xFFFF8000 +#define WORD_ALIGN 4 +#define BYTE_ALIGN 1024 +#ifdef OCCMK +INCLUDE occLinkInputFile +#endif + +MEMORY +{ + AppMem : ORIGIN = APP_IMAGE_SRAM_START_ADDR, LENGTH = 0x4000 +} + +SECTIONS +{ + . = APP_IMAGE_SRAM_START_ADDR; + + __START_ADDR__ = .; + + //////////////////////////////// + // start read-only section + //////////////////////////////// + imageHeader . : { *(imageHeader) } > AppMem + + //////////////////////////////// + // text section 1024 byte aligned + //////////////////////////////// + .text . : { *(.text) . = ALIGN(1024);} > AppMem + // NOTE: rodata section needs to be 1k aligned as it is used for setting + // mmu permission druing applet execution + .rodata . : { *(.rodata) *(.got2) *(.rodata.str1.4) *(.rodata.str1.1). = ALIGN(BYTE_ALIGN); } > AppMem + __READ_ONLY_DATA_LEN__ = . - APP_IMAGE_SRAM_START_ADDR ; + + //////////////////////////////// + // start writeable section + //////////////////////////////// + __WRITEABLE_DATA_ADDR__ = .; + + //////////////////////////////// + // read-write section 1024 byte aligned + //////////////////////////////// + .rela . : { *(.rela*) . = ALIGN(WORD_ALIGN);} > AppMem + // NOTE: rwdata section needs to be 1024 bytes aligned for setting mmu + // permission, so that applet total size is 1024 bytes aligned. + // It is needed for doing DMA copy of the applet. + .rwdata . : { *(.data) *(.bss) *(COMMON) . = ALIGN(BYTE_ALIGN);} > AppMem + + __WRITEABLE_DATA_LEN__ = . - __WRITEABLE_DATA_ADDR__; + +} diff --git a/src/occApplet/productApplet/occLinkInputFile b/src/occApplet/productApplet/occLinkInputFile new file mode 100644 index 0000000..24c17c3 --- /dev/null +++ b/src/occApplet/productApplet/occLinkInputFile @@ -0,0 +1 @@ +INPUT ( cmdhDbugCmd.o ) diff --git a/src/occApplet/productApplet/productappletfiles.mk b/src/occApplet/productApplet/productappletfiles.mk new file mode 100755 index 0000000..d11968d --- /dev/null +++ b/src/occApplet/productApplet/productappletfiles.mk @@ -0,0 +1,30 @@ +# @file libofiles.mk +# +# @brief mk for libssx.a object files +# +# @page ChangeLogs Change Logs +# @section ofiles.mk +# @verbatim +# +# +# Change Log ****************************************************************** +# Flag Defect/Feature User Date Description +# ------ -------------- ---------- ------------ ----------- +# @pb00E pbavari 03/28/2012 Makefile ODE support +# +# @endverbatim +# +########################################################################## +# INCLUDES +########################################################################## +C-SOURCES = apssInitApplet.c sensorQueryList.c cmdhDbugCmd.c + +PRDTAPLT_OBJECTS = $(C-SOURCES:.c=.o) + +apssInitApplet_OFILES = apssInitApplet.o +sensorQueryList_OFILES = sensorQueryList.o +cmdhDbugCmd_OFILES = cmdhDbugCmd.o + + + + diff --git a/src/occApplet/productApplet/sensorQueryList.c b/src/occApplet/productApplet/sensorQueryList.c new file mode 100755 index 0000000..e78ec12 --- /dev/null +++ b/src/occApplet/productApplet/sensorQueryList.c @@ -0,0 +1,308 @@ +/****************************************************************************** +// @file sensorQueryList.c +// @brief sensor sensorQueryList product applet +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section sensorQueryList.c SENSORQUERYLIST.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * @th005 thallet 11/21/2011 Created + * @dw000 dwoodham 12/12/2011 Update call to IMAGE_HEADER + * @pb00C pbavari 01/20/2012 Changed printf to SNR_DBG + * @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments + * @at003 alvinwan 03/19/2012 Add o_sensorInfoPtrs to querySensorListAppletArg_t + * @nh001 neilhsu 05/23/2012 Add missing error log tags + * @gm002 885429 milesg 05/30/2013 change loc/type to 16 bit bitmask + * @wb003 920760 wilbryan 03/25/2014 Update SRCs to match TPMD SRCs + * + * @endverbatim + * + *///*************************************************************************/ + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <occ_common.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include "ssx_io.h" // For sprintf +#include <trac.h> // For traces +#include <sensor_service_codes.h> // sensor module ids +#include <occ_service_codes.h> // sensor module ids +#include <sensor.h> // For Sensor defines +#include <sensorQueryList.h> // For args to applet +#include <appletId.h> // For applet ID num dw000a + +/*****************************************************************************/ +// C Source File Includes for this Applet +// -------------------------------------- +// \_ Must be done to give this applet access to the G_sensor_info +// sensor list +/*****************************************************************************/ +#include "sensor_info.c" + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define SENSOR_QUERY_ID "SNSR QueryList\0" + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + + +// Function Specification +// +// Name: printSensorInfo +// +// Description: Dump a sensor's info via printf +// +// Flow: --/--/---- FN= None +// +// End Function Specification +void printSensorInfo(uint16_t i_gsid) +{ + //@pb00Cc - Changed to initialize variable j and k with NULL and then + // point to sensor to avoid compilation error when SNSR_DEBUG is not + // defined. j and k are only used with SNSR_DBG which is no-op statement + // when SNSR_DEBUG is not defined. + sensor_t * k = NULL; + k = G_amec_sensor_list[i_gsid]; + uint16_t * j = NULL; + j = G_amec_sensor_list[i_gsid]->mini_sensor; + + // Print Sensors Information from Sensor_info_t Table + SNSR_DBG("Sensor [%d] = Name: %s, Units: %s, Type: 0x%04x, Loc: 0x%04x, Num: %d, Freq: 0x%08x, Scale: 0x%08x\n", + i_gsid, + G_sensor_info[i_gsid].name, + G_sensor_info[i_gsid].sensor.units, + G_sensor_info[i_gsid].sensor.type, + G_sensor_info[i_gsid].sensor.location, + G_sensor_info[i_gsid].sensor.number, + G_sensor_info[i_gsid].sensor.freq, + G_sensor_info[i_gsid].sensor.scalefactor + ); + + // Print Sensor Information from Sensor_t + SNSR_DBG("SensorPtr=0x%08x, Sample=%d, Max=%d, Min=%d, Tag=%d, MiniSensorPtr=0x%08x, MiniSensorVal=0x%04x\n", + (uint32_t) k, + k->sample, + k->sample_max, + k->sample_min, + k->update_tag, + (uint32_t)k->mini_sensor, + (NULL != j) ? *j : 0 + ); +} + + +// Function Specification +// +// Name: printAllSensors +// +// Description: Dump all sensors via printf. +// +// Flow: --/--/---- FN= none +// +// End Function Specification +void printAllSensors(void) +{ + int i; + + // Loop through sensor table and printf all sensors + for(i=0; i < NUMBER_OF_SENSORS_IN_LIST; i++) + { + printSensorInfo(i); + } +} + + +/*****************************************************************************/ +// Entry point function +/*****************************************************************************/ + +// Function Specification +// +// Name: querySensorList +// +// Description: Query sensor list +// +// Flow: 06/27/2011 FN= querySensorList +// +// End Function Specification + +// When this moved to applet, instead of getting the data +// via sensor_t, it now has to get some of it via sensor_info_t. The sensor +// info array is still be indexed by gsid, so this should be easy. +errlHndl_t querySensorList(const querySensorListAppletArg_t * i_argPtr) +{ + errlHndl_t l_err = NULL; + + if(i_argPtr != NULL) + { + uint16_t i_startGsid = i_argPtr->i_startGsid; + uint8_t i_present = i_argPtr->i_present; + uint16_t i_type = i_argPtr->i_type; + uint16_t i_loc = i_argPtr->i_loc; + uint16_t * io_numOfSensors = i_argPtr->io_numOfSensors; + sensorQueryList_t * o_sensors = i_argPtr->o_sensors; + sensor_info_t * o_sensorInfoPtrs= i_argPtr->o_sensorInfoPtrs; //@at003A + + // Validate input parameters + if( (i_startGsid >= NUMBER_OF_SENSORS_IN_LIST) || + ((o_sensors == NULL) && (o_sensorInfoPtrs ==NULL)) || //@at003M + (io_numOfSensors == NULL)) + { + TRAC_ERR("Invalid input pointers OR start GSID is out of range: " + "i_startGsid: 0x%x, G_amec_sensor_count: 0x%x", + i_startGsid,G_amec_sensor_count); + + /* @ + * @errortype + * @moduleid SENSOR_QUERY_LIST + * @reasoncode INTERNAL_INVALID_INPUT_DATA + * @userdata1 i_startGsid -- passed in Global Sensor ID + * @userdata2 G_amec_sensor_count -- number of OCC sensors + * @userdata4 OCC_NO_EXTENDED_RC + * @devdesc Firmware failure caused due to invalid GSID passed + */ + + /* @ + * @errortype + * @moduleid SENSOR_QUERY_LIST + * @reasoncode INTERNAL_FAILURE + * @userdata1 i_startGsid -- passed in Global Sensor ID + * @userdata2 G_amec_sensor_count -- number of OCC sensors + * @userdata4 OCC_NO_EXTENDED_RC + * @devdesc NULL pointer passed for querySensorList applet output args + */ + l_err = createErrl(SENSOR_QUERY_LIST, //modId + ((i_startGsid >= NUMBER_OF_SENSORS_IN_LIST)? + INTERNAL_INVALID_INPUT_DATA : INTERNAL_FAILURE), //reasoncode // @wb003 + OCC_NO_EXTENDED_RC, //Extended reason code + ERRL_SEV_PREDICTIVE, //Severity + NULL, //Trace Buf + 0, //Trace Size + i_startGsid, //userdata1 + G_amec_sensor_count //userdata2 + ); + } + else + { + uint32_t l_cnt = i_startGsid; + uint32_t l_num = *io_numOfSensors; + *io_numOfSensors = 0; + + // Traverse through sensor list starting at i_startGsid to find + // matching sensor. Return it in the output variable + for(;(l_cnt < NUMBER_OF_SENSORS_IN_LIST && ((*io_numOfSensors) < l_num)); + l_cnt++) + { + // If sample value is not zero then it means sensor is present. + // This is currently only used by debug/mfg purpose + // If user is looking for present sensors and sample is zero, + // then don't include current sensor in the query list + if( (i_present) && (G_amec_sensor_list[l_cnt]->sample == 0)) + { + continue; + } + + // If user is NOT looking for any sensor type and input type, + // does not match the current sensor type, then don't include + // current sensor in the query list + if((i_type & G_sensor_info[l_cnt].sensor.type) == 0) + { + continue; + } + + // If user is NOT looking for any sensor location and input loc, + // does not match the current sensor location, then don't include + // current sensor in the query list + if((i_loc & G_sensor_info[l_cnt].sensor.location) == 0) + { + continue; + } + + //@at003M begin< + if( o_sensors != NULL) + { + // All conditions match. Include current sensor in the query list + // Copy gsid, name and sample + o_sensors->gsid = l_cnt; + strncpy(o_sensors->name,G_sensor_info[l_cnt].name, + MAX_SENSOR_NAME_SZ); + o_sensors->sample = G_amec_sensor_list[l_cnt]->sample; + o_sensors++; + } + + if( o_sensorInfoPtrs != NULL) + { + memcpy( o_sensorInfoPtrs, &G_sensor_info[l_cnt], sizeof(sensor_info_t)); + o_sensorInfoPtrs++; + } + // @at003M end> + + (*io_numOfSensors)++; + } // end for loop + } // valid input parameter path + } + else + { + TRAC_ERR("Invalid applet argument pointer = NULL"); + + /* @ + * @errortype + * @moduleid SENSOR_QUERY_LIST + * @reasoncode INTERNAL_INVALID_INPUT_DATA + * @userdata1 NULL + * @userdata2 NULL + * @userdata4 ERC_ARG_POINTER_FAILURE + * @devdesc NULL pointer passed to querySensorList applet + */ + l_err = createErrl( + SENSOR_QUERY_LIST, // Module ID + INTERNAL_INVALID_INPUT_DATA, // Reason Code // @wb003 + ERC_ARG_POINTER_FAILURE, // Extended reason code + ERRL_SEV_PREDICTIVE, // Severity + NULL, // Trace + 0, // Trace Size + 0, // UserData 1 + 0 // UserData 2 + ); + } + + return l_err; +} + + + +/*****************************************************************************/ +// Image Header +/*****************************************************************************/ +// @dw000 - Add applet ID arg to IMAGE_HEADER macro call +IMAGE_HEADER (G_querySensorList,querySensorList,SENSOR_QUERY_ID,OCC_APLT_SNSR_QUERY); + diff --git a/src/occApplet/template.c b/src/occApplet/template.c new file mode 100755 index 0000000..749f79d --- /dev/null +++ b/src/occApplet/template.c @@ -0,0 +1,73 @@ +/****************************************************************************** +// @file <filename.c> +// @brief <shortDesc> +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section <filename.c> <FILENAME.c> + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * USERID MM/DD/YY created + * + * @endverbatim + * + *///*************************************************************************/ + + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include "ssx_io.h" // For printfs +#include <trac.h> // For traces +#include <appletId.h> // For applet ID + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define <FUNCNM>_ID "<APPLET_ID_STR>\0" + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + +//************************************************************************* +// Entry point function +//************************************************************************* +errlHndl_t <funcNm>(void * i_arg) +{ + TRAC_INFO("Enter"); + errlHndl_t l_err = NULL; + + TRAC_INFO("Exit"); + return l_err; +} + +//************************************************************************* +// Image Header +//************************************************************************* +IMAGE_HEADER (G_<funcNm>,<funcNm>,<FUNCNM>_ID,<APLT_ID>); diff --git a/src/occApplet/testApplet/Makefile b/src/occApplet/testApplet/Makefile new file mode 100755 index 0000000..9a5ea0b --- /dev/null +++ b/src/occApplet/testApplet/Makefile @@ -0,0 +1,107 @@ +# @file Makefile +# +# @brief OCC Test Applet Makefile +# + +# @page ChangeLogs Change Logs +# @section Makefile +# @verbatim +# +# +# Change Log ****************************************************************** +# Flag Defect/Feature User Date Description +# ------ -------------- ---------- ------------ ----------- +# @pb001 pbavari 07/18/2011 Created +# @pb002 pbavari 08/17/2011 Added sensorTest.c +# @cc000 cjcain 08/30/2011 Added apssTest.c +# @pb004 pbavari 09/15/2011 Added support for calling +# product aplt from test aplt +# @02 tapiar 10/03/2011 Adding new dir includes +# @dw000 dwodham 12/13/2011 Add include for appletId +# @rc001 rickylie 01/16/2012 Include debug_trace.mk +# @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments +# @at002 alvinwan 02/10/2012 Added errlTest.c +# @at009 859308 alvinwan 10/15/2012 Added tracepp support +# @th029 thallet 01/23/2013 Added md5sum in version +# +# @endverbatim +# + +# >> gitprep +ifndef ROOTPATH +ROOTPATH = $(shell pwd)/../../ +export OCCROOT = $(ROOTPATH) +endif +# << gitprep + +#******************************************************************************* +# mk variable Declaration +#******************************************************************************* +OCC = ../../occ +BOOTLOADER = ../../occBootLoader +SSX = ../../ssx +TESTAPPLET = . +LIB = ../../lib + +# >> gitprep +# Add missing link flags fir GNU build +LDFLAGS += --oformat=elf32-powerpc -melf32ppc + +buildImage = $(LD) -R $(OCC)/occ.out $(obj) -Tlinkscript $(LDFLAGS) \ + -Map $(basename $(obj)).map -Bstatic -o $(basename $(obj)).out;\ + $(OBJCOPY) -I elf32-powerpc -O binary $(basename $(obj)).out $(basename $(obj)).bin; \ + $(OBJDUMP) -d $(basename $(obj)).out > $(basename $(obj)).dis; \ + $(BOOTLOADER)/imageHdrScript $(basename $(obj)).bin `md5sum $(OCC)/occ.out | cut -c 1-4`; \ +# << gitprep + +#******************************************************************************* +# Includes +#******************************************************************************* +include $(SSX)/pgp/ssx.mk +#@rc001a +include $(OCC)/debug_trace.mk +include testappletfiles.mk + +INCLUDES = -I. -I$(OCC)/rtls -I$(OCC)/incl -I$(OCC)/errl -I$(OCC)/trac -I$(LIB) -I$(SSX)/ssx +INCLUDES += -I$(SSX)/ppc405 -I$(SSX)/pgp -I$(SSX)/ppc32 -I$(SSX)/pgp/registers +INCLUDES += -I$(OCC)/sensor -I$(OCC)/pss -I$(OCC)/gpe -I$(OCC) -I$(OCC)/aplt -I$(OCC)/dcom +# >> gitprep +# Add missing include paths +INCLUDES += -I$(OCC)/aplt/incl -I$(OCC)/cmdh +# << gitprep + +#******************************************************************************* +# Flags +#******************************************************************************* +#D = -DSIMICS_MAGIC_PANIC=1 \ + -DINITIALIZE_SIMICS_IO=1 + +DEFS += $(D) +DEFS += -DOCC=1 \ + -DUSE_SSX_APP_CFG_H=1 + +# Do not use SDA sections for product applet +# >> gitprep +# Add missing compile flags for GNU build +GCC-CFLAGS = -c -g -Wall -fsigned-char -msoft-float -pipe \ + -m32 -Wa,-m405 -mcpu=405 -mmultiple -mstring -meabi \ + -ffreestanding -Os -mno-sdata +# << gitprep + +#******************************************************************************* +# Compilation +#******************************************************************************* +all: $(TESTAPLT_OBJECTS) + $(CPP) -P $(DEFS) < linkTestApplet.cmd > linkscript + $(foreach obj,$(TESTAPLT_OBJECTS),$(buildImage)) + +#******************************************************************************* +# combineImage +#******************************************************************************* +.PHONY : combineImage +combineImage: +#******************************************************************************* +# Clean +#******************************************************************************* +clean: + rm -f *.o *.out *.bin *.dis *.map *.hash linkscript diff --git a/src/occApplet/testApplet/apsstest.c b/src/occApplet/testApplet/apsstest.c new file mode 100755 index 0000000..8ccd968 --- /dev/null +++ b/src/occApplet/testApplet/apsstest.c @@ -0,0 +1,107 @@ +/****************************************************************************** +// @file apsstest.c +// @brief APSS test applet +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section apsstest.c APSSTEST.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * cjcain 08/30/2011 created + * @02 abagepa 10/03/2011 updated task signature + * @dw000 dwoodham 12/12/2011 Update call to IMAGE_HEADER macro + * @rc001 rickylie 01/10/2012 Change DEBUG_PRINTF to APSS_DBG + * @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments + * + * @endverbatim + * + *///*************************************************************************/ + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include "ssx_io.h" // For printfs +#include <apss.h> // APSS Interfaces +#include <appletId.h> // For applet ID @dw000a +#include <trac.h> // For traces + +//************************************************************************* +// Externs +//************************************************************************* +extern PoreEntryPoint GPE_pore_nop; // Sleep for specified amount of time... + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define APSSTESTMAIN_ID "apsstest1\0" + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + +// Function Specification +// +// Name: apssTestMain +// +// Description: +// +// Flow: FN=None +// +// End Function Specification +errlHndl_t apssTestMain(void * i_arg) +{ + APSS_DBG("Running apssTestMain\n"); + errlHndl_t l_err = NULL; + task_apss_start_pwr_meas(NULL); + + // Schedule GPE program to delay to ensure the data is available... (BLOCKING) + // bad: 48, good: 56 + PoreFlex test_request; + APSS_DBG("apss_test_pwr_meas: delay...\n"); + pore_flex_create(&test_request, + &G_pore_gpe0_queue, + (void*)GPE_pore_nop, // entry_point + (uint32_t)56, // entry_point argument + SSX_WAIT_FOREVER, // no timeout + NULL, // callback, + NULL, // callback arg + ASYNC_REQUEST_BLOCKING); // options + pore_flex_schedule(&test_request); + APSS_DBG("apss_test_pwr_meas: delay complete\n"); + + task_apss_continue_pwr_meas(NULL); + + task_apss_complete_pwr_meas(NULL); + + APSS_DBG("Done apssTestMain\n"); + + return l_err; +} + +/*****************************************************************************/ +// Image Header +/*****************************************************************************/ +// @dw000 - call macro with Applet ID arg +IMAGE_HEADER (G_apssTestMain,apssTestMain,APSSTESTMAIN_ID,OCC_APLT_TEST); + diff --git a/src/occApplet/testApplet/errlTest.c b/src/occApplet/testApplet/errlTest.c new file mode 100755 index 0000000..c466c8f --- /dev/null +++ b/src/occApplet/testApplet/errlTest.c @@ -0,0 +1,1210 @@ +/****************************************************************************** +// @file errlTest.c +// @brief OCC errl component test applet +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section errlTest.c ERRLTEST.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * @at002 alvinwan 02/10/2012 Created + * @nh001 neilhsu 05/23/2012 Add missing error log tags + * @at012 868019 alvinwan 01/25/2014 TRAC_get_buffer_partial() can result in TLB Miss Exception + * @jh001 881996 joshych 05/07/2013 Support SRAM error log format + * @jh003 890574 joshych 15/07/2013 Fix errlTest Applet + * @rt001 901927 tapiar 10/02/2013 Update error log to use unique module id + * @fk006 914801 fmkassem 01/05/2013 Remove wrong reference to a reasoncode + * @sb100 916174 sbroyles 02/18/2014 Remove rand.h include for ssx release release20140214 + * + * @endverbatim + * + *///*************************************************************************/ + +#define ERRL_DEBUG +/*****************************************************************************/ +// Includes +/*****************************************************************************/ +#include <common_types.h> // imageHdr_t declaration and image header macro +#include "ssx.h" +#include "ssx_io.h" // For ERRL_DBGs +#include <errl.h> +#include <appletId.h> // For applet ID +// #include <rand.h> @sb100 +#include <trac.h> // For traces +#include <occ_service_codes.h> // Reason code +#include <cmdh_fsp.h> // Needed for rc codes. +#include <trac_interface.h> +#include <aplt_service_codes.h> // For test applet module ID +#include <testApltId.h> // For test applet ID + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* +#define CHECK_CONDITION(cond, rv) \ + if( !(cond) ) \ + { \ + rv = __LINE__; \ + break; \ + } + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define ERRLTESTMAIN_ID "errl Test\0" +#define TRAC_PATTERN 0x55 +#define MAX_BUFFER_SIZE MAX_ERRL_CALL_HOME_SZ +#define TEST_MODULE_ID 0x1616 // @nh001a + +// sensor test module ID enumeration +typedef enum +{ + TEST_ERROR_HANDLING = 0x00, + TEST_CREATE_COMMIT_DELETE_LOG = 0x01, + TEST_ADD_USRDTLS_TO_ERRL = 0x02, + TEST_ADD_TRACE_TO_ERRL = 0x03, + TEST_TIME = 0x04, + TEST_CREATE2INFO_CALLHOMELOG = 0x05, + TEST_CREATE_MAX_LOGS = 0x06, + TEST_CALLOUTS = 0x07, + TEST_SET_ERRLSEV_TO_INFO = 0x08, + TEST_ERRL_TEST_WORD_ALIGN = 0x09 +} errlTestModId; + +// errl test return codes +typedef enum +{ + SUCCESS_RC = 0x00000000, +} errlTestRc; + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* +// TRACE: Trace buffers initialized +uint8_t G_data[ MAX_BUFFER_SIZE]; +//************************************************************************* +// Function Prototypes +//************************************************************************* +uint32_t errlTestErrorHandling(); +uint32_t errlTestAddUsrDtlsToErrl(); +uint32_t errlTestAddTraceToErrl(); +uint32_t errlTestDtlSizeLimit(); +uint32_t errlTestTime(); +uint32_t errlTestCreateCommitDeleteLog(); +uint32_t errlTestCreate2InfoCallhomeLog(); +uint32_t errlTestCreateMaxLogs(); +uint32_t errlTestCallouts(); +uint32_t errlTestSetErrlSevToInfo(); +uint32_t errlTestWordAlign(); +void dumpLog( errlHndl_t i_log, uint32_t i_len ); +void ppdumpslot(void); + +//************************************************************************* +// Functions +//************************************************************************* +// Function errlTestMain +// +// Name: sensorTestMain +// +// Description: Entry point function +// +// Flow: FN=None +// +// End Function Specification +errlHndl_t errlTestMain(void * i_arg) +{ + + errlHndl_t l_err = NULL; + uint16_t l_modId = 0; + uint32_t l_rc = ERRL_RC_SUCCESS; + + ERRL_DBG("Enter errlTestMain\n"); + + do + { + l_rc = errlTestErrorHandling(); + l_modId = TEST_ERROR_HANDLING; + + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on error handling test"); + break; + }; + + l_rc = errlTestCreateCommitDeleteLog(); + l_modId = TEST_CREATE_COMMIT_DELETE_LOG ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on Log test"); + break; + } + + l_rc = errlTestAddUsrDtlsToErrl(); + l_modId = TEST_ADD_USRDTLS_TO_ERRL ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on add user detail test"); + break; + } + + l_rc = errlTestAddTraceToErrl(); + l_modId = TEST_ADD_TRACE_TO_ERRL ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on add trace test"); + break; + } + + l_rc = errlTestTime(); + l_modId = TEST_TIME ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on time test"); + break; + } + + l_rc = errlTestCreate2InfoCallhomeLog(); + l_modId = TEST_CREATE2INFO_CALLHOMELOG ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on create call home log test"); + break; + } + + l_rc = errlTestCreateMaxLogs(); + l_modId = TEST_CREATE_MAX_LOGS ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on create max logs test"); + break; + } + + l_rc = errlTestCallouts(); + l_modId = TEST_CALLOUTS ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on callouts test"); + break; + } + + l_rc = errlTestSetErrlSevToInfo(); + l_modId = TEST_SET_ERRLSEV_TO_INFO ; + if( l_rc != ERRL_RC_SUCCESS) + { + TRAC_INFO("Failure on SetErrlSevToInfo test"); + break; + } + + // @jh003c + // comment out the test case since we no longer add the alignment in addUsrDtlsToErrl + //l_rc = errlTestWordAlign(); + //l_modId = TEST_ERRL_TEST_WORD_ALIGN ; + //if( l_rc != ERRL_RC_SUCCESS) + //{ + // TRAC_INFO("Failure on word alignment test"); + // break; + //} + } while (0); + + if( l_rc != ERRL_RC_SUCCESS) + { + ERRL_DBG("**********************************************"); + ERRL_DBG("* errl Test Failed (errlTest.c): line: %d",l_rc); + ERRL_DBG("**********************************************"); + /* @ + * @errortype + * @moduleid TEST_APLT_MODID_ERRLTEST + * @reasoncode INTERNAL_FAILURE + * @userdata1 Test Applet ID + * @userdata2 Return Code + * @userdata4 OCC_NO_EXTENDED_RC + * @devdesc Failure executing test applet + */ + l_err = createErrl(TEST_APLT_MODID_ERRLTEST, + INTERNAL_FAILURE, // @nh001c + OCC_NO_EXTENDED_RC, + ERRL_SEV_INFORMATIONAL, + NULL, + 0, + ERRL_TEST_APLT, + l_rc); + } + else + { + ERRL_DBG("**********************************************"); + ERRL_DBG("* errl Test Passed (errlTest.c)"); + ERRL_DBG("**********************************************"); + } + + ERRL_DBG("Exit errlTestMain\n"); + + return l_err; +} + + +// Function Specification +// +// Name: errlTestErrorHandling +// +// Description: errlTestErrorHandling +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestErrorHandling() +{ + uint32_t l_rc = 0; + errlHndl_t l_errlHnd = NULL; + uint8_t l_dataPtr[10]; + uint16_t l_entrySizeBefore = 0; + uint16_t l_entrySizeAfter = 0; + + ERRL_DBG(" START"); + do + { + /****************************************************/ + // Test createErrl with incorrect parameter + // Set ERRL_SEVERITY to 0x04, out of range so log won't be created + l_errlHnd = createErrl(TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, 0x04, NULL, 0, 0x01, 0x02); // @nh001c + CHECK_CONDITION( l_errlHnd == INVALID_ERR_HNDL, l_rc); + + /****************************************************/ + // Test addTraceToErrl with incorrect parameter + // Create a log + l_errlHnd = createErrl(TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 0, 0x01, 0x02); // @nh001c + CHECK_CONDITION( l_errlHnd != INVALID_ERR_HNDL, l_rc); + + // i_trace = NULL, so entry size doesn't change + l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize; + addTraceToErrl(NULL, 5, l_errlHnd); + l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize; + CHECK_CONDITION(l_entrySizeBefore == l_entrySizeAfter, l_rc); + + // i_traceSz = 0, entry size doesn't change + l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, 0, l_errlHnd); // @at012c + l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc); + + // io_err = NULL, entry size doesn't change + l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, 32, NULL); // @at012c + l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc); + + // test addTraceToErrl after log is comitted so entry size doesn't change + errlHndl_t l_errlHndx = l_errlHnd; + commitErrl(&l_errlHnd); + l_entrySizeBefore = l_errlHndx->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, 32, l_errlHndx); // @at012c + l_entrySizeAfter = l_errlHndx->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc); + + deleteErrl(&l_errlHndx); + CHECK_CONDITION( l_errlHndx == NULL, l_rc); + + // io_err = INVALID_ERR_HNDL + // We are making sure that this function + // handles a INVALID_ERR_HNDL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + l_errlHnd = INVALID_ERR_HNDL; + addTraceToErrl(g_trac_inf, 32, l_errlHnd); // @at012c + + /****************************************************/ + // Test commitErrl with incorrect parameter + // io_err = NULL + // We are making sure that this function + // handles a NULL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + commitErrl( NULL); + + // l_errlHnd should be set to NULL + l_errlHnd = INVALID_ERR_HNDL; + commitErrl(&l_errlHnd); + CHECK_CONDITION( l_errlHnd == NULL, l_rc); + + /****************************************************/ + // Test deleteErrl with incorrect parameter + // io_err = NULL + // We are making sure that this function + // handles a NULL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + deleteErrl( NULL); + + // l_errlHnd should be set to NULL + l_errlHnd = INVALID_ERR_HNDL; + deleteErrl(&l_errlHnd); + CHECK_CONDITION( l_errlHnd == NULL, l_rc); + + /****************************************************/ + // Test addCalloutToErrl with incorrect parameter + // Set io_err to NULL + // We are making sure that this function + // handles a NULL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + addCalloutToErrl(NULL, ERRL_CALLOUT_TYPE_HUID, 0, ERRL_CALLOUT_PRIORITY_LOW); // @jh001c + + // Set io_err to INVALID_ERR_HNDL + // We are making sure that this function + // handles a INVALID_ERR_HNDL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + addCalloutToErrl(INVALID_ERR_HNDL, ERRL_CALLOUT_TYPE_HUID, 0, ERRL_CALLOUT_PRIORITY_LOW); // @jh001c + + /****************************************************/ + // Test addUsrDtlsToErrl with incorrect parameter + // Create a log + l_errlHnd = createErrl(TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 0, 0x01, 0x02); // @nh001c + CHECK_CONDITION( l_errlHnd != INVALID_ERR_HNDL, l_rc); + + // io_err = NULL + // We are making sure that this function + // handles a NULL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + addUsrDtlsToErrl(NULL, l_dataPtr, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA); + + // io_err = INVALID_ERR_HNDL + // We are making sure that this function + // handles a INVALID_ERR_HNDL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + addUsrDtlsToErrl(INVALID_ERR_HNDL, l_dataPtr, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA); + + // i_dataPtr = NULL so entry size doesn't change + l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize; + addUsrDtlsToErrl(l_errlHnd, NULL, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA); + l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc); + + // i_size = 0 so so entry size doesn't change + l_entrySizeBefore = l_errlHnd->iv_userDetails.iv_entrySize; + addUsrDtlsToErrl(l_errlHnd, l_dataPtr, 0, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA); + l_entrySizeAfter = l_errlHnd->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc); + + // test addUsrDtlsToErrl after log is committed so entry size doesn't change + l_errlHndx = l_errlHnd; + commitErrl(&l_errlHnd); + l_entrySizeBefore = l_errlHndx->iv_userDetails.iv_entrySize; + addUsrDtlsToErrl(l_errlHndx, l_dataPtr, 10, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA); + l_entrySizeAfter = l_errlHndx->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeBefore == l_entrySizeAfter, l_rc); + + deleteErrl(&l_errlHndx); + CHECK_CONDITION( l_errlHndx == NULL, l_rc); + + /****************************************************/ + // Test setErrlSevToInfo with incorrect parameter + // Set io_err to NULL. + // We are making sure that this function + // handles a NULL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + setErrlSevToInfo(NULL); + + // Set io_err to INVALID_ERR_HNDL + // We are making sure that this function + // handles a INVALID_ERR_HNDL being passed, and that we can't verify if + // an error occured by checking anything. (It will just cause + // a TLB exception) + setErrlSevToInfo(INVALID_ERR_HNDL); + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestCreateCommitDeleteLog +// +// Description: errlTestCreateCommitDeleteLog +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestCreateCommitDeleteLog() +{ + ERRL_DBG("START"); + uint32_t l_rc = 0; + + do + { + /****************************************************/ + // Test create log + errlHndl_t l_handle = NULL; + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 512, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + ERRL_DBG("Slots after Creating call home log" ); + ppdumpslot(); + + /****************************************************/ + // Test commit log + errlHndl_t l_handle2 = l_handle; + commitErrl( &l_handle ); + CHECK_CONDITION( (l_handle == NULL) && + (l_handle2->iv_userDetails.iv_committed == 1), l_rc); + + ERRL_DBG("Slots after Commiting call home log" ); + dumpLog( l_handle2, l_handle2->iv_userDetails.iv_entrySize ); + ppdumpslot(); + + /****************************************************/ + // Test delete log + deleteErrl(&l_handle2); + CHECK_CONDITION( l_handle2 == NULL, l_rc); + + ERRL_DBG("Slots after delete Log" ); + ppdumpslot(); + + ERRL_DBG("END \n"); + + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestAddUsrDtlsToErrl +// +// Description: errlTestAddUsrDtlsToErrl +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestAddUsrDtlsToErrl() +{ + uint32_t l_rc = 0; + ERRL_DBG("START"); + uint16_t l_entrySizeBefore = 0; + uint16_t l_entrySizeAfter = 0; + + do + { + // Create three err logs + errlHndl_t l_handle = NULL; + errlHndl_t l_handle2 = NULL; + errlHndl_t l_handle3 = NULL; + + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_UNRECOVERABLE, NULL, 512, 0x1, 0x2); // @nh001c + l_handle2 = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, NULL, 512, 0x1, 0x2); // @nh001c + l_handle3 = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL, NULL, 512, 0x1, 0x2); // @nh001c + + // l_handle will set to NULL after calling the commitErrl, so we need to store it + errlHndl_t l_handleX = l_handle; + errlHndl_t l_handle2X = l_handle2; + errlHndl_t l_handle3X = l_handle3; + ERRL_DBG("Slots after Create - 3 slots should be used (one of each"); + ppdumpslot(); + + CHECK_CONDITION( (l_handle != INVALID_ERR_HNDL) && + (l_handle2 != INVALID_ERR_HNDL) && + (l_handle3 != INVALID_ERR_HNDL), l_rc); + + /****************************************************/ + // Test sizelimit for addUsrDtlsToErrl + // Add "user details" data that exceeds the max size for l_handle + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + memset( G_data, 0xCC, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle, G_data, sizeof( G_data ), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeAfter == MAX_ERRL_ENTRY_SZ, l_rc); + + // Add "user details" data that exceeds the max size for l_handle2 + l_entrySizeBefore = l_handle2->iv_userDetails.iv_entrySize; + memset( G_data, 0xDD, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle2, G_data, sizeof( G_data ), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_CALLHOME_DATA ); + l_entrySizeAfter = l_handle2->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeAfter == MAX_ERRL_CALL_HOME_SZ, l_rc); + + // Add "user details" with size 76 for l_handle3 + l_entrySizeBefore = l_handle3->iv_userDetails.iv_entrySize; + memset( G_data, 0xEE, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle3, G_data, 76, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); + l_entrySizeAfter = l_handle3->iv_userDetails.iv_entrySize; + // (header + 76) is the size that add to entry + CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+76), l_rc); + + dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize ); + dumpLog( l_handle2, l_handle2->iv_userDetails.iv_entrySize ); + dumpLog( l_handle3, l_handle3->iv_userDetails.iv_entrySize ); + + commitErrl( &l_handle ); + commitErrl( &l_handle2 ); + commitErrl( &l_handle3 ); + ERRL_DBG("Slots after Commit - 3 slots should be used/committed"); + ppdumpslot(); + + deleteErrl(&l_handleX); + deleteErrl(&l_handle2X); + deleteErrl(&l_handle3X); + CHECK_CONDITION( (l_handleX == NULL) && + (l_handle2X == NULL) && + (l_handle3X == NULL), l_rc); + + ERRL_DBG("Slots after delete Log - All slots should be empty"); + ppdumpslot(); + + /****************************************************/ + // Test sizelimit for addUsrDtlsToErrl with continuous calls + // Create log with 512 bytes trace + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, g_trac_inf, 512, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // l_handle will set to NULL after calling the commitErrl, so we need to store it + l_handleX = l_handle; + ppdumpslot(); + + // add 256 bytes of "user details" (512+256) + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + memset( G_data, 0xAA, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle, G_data, 256, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 256 bytes" ); + ppdumpslot(); + // (header + 256) is the size that add to entry + CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+256), l_rc); + + // add 512 bytes of "user details" (512+256+512) + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + memset( G_data, 0xBB, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle, G_data, 512, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 256 + 512 bytes"); + ppdumpslot(); + // (header + 512) is the size that add to entry + CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+512), l_rc); + + // add 1024 bytes of "user details" (512+256+512+1024), the entry size is more than 2048 now + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + memset( G_data, 0xCC, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle, G_data, 1024, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 256 + 512 +1024 bytes"); + ppdumpslot(); + // (header + 1024) is the size that add to entry + CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc); // @at012c + + commitErrl( &l_handle ); + deleteErrl(&l_handleX); + ERRL_DBG("Slots should now be empty"); + ppdumpslot(); + ERRL_DBG("END \n"); + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestAddTraceToErrl +// +// Description: errlTestAddTraceToErrl +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestAddTraceToErrl() +{ + uint32_t l_rc = 0; + uint16_t l_entrySizeBefore = 0; + uint16_t l_entrySizeAfter = 0; + ERRL_DBG("START"); + + do + { + // Create one err log + errlHndl_t l_handle = NULL; + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 512, 0x1, 0x2); // @nh001c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // l_handle will set to NULL after calling the commitErrl, so we need to store it + errlHndl_t l_handleX = l_handle; + ERRL_DBG("Slots after Create - 1 slots should be used (one of each"); + ppdumpslot(); + + /****************************************************/ + // Test sizelimit for addTraceToErrl + // Add "trace" data that exceeds the max size + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, MAX_BUFFER_SIZE, l_handle); // @at012c + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc); // @at012c + + dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize ); + commitErrl( &l_handle ); + ERRL_DBG("Slots after Commit - 1 slots should be used/committed"); + ppdumpslot(); + + deleteErrl(&l_handleX); + ERRL_DBG("Slots after delete Log - All slots should be empty"); + ppdumpslot(); + + /****************************************************/ + // Test sizelimit for addTraceToErrl with continuous calls + // Create log with 512 bytes trace + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, g_trac_inf, 512, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // l_handle will set to NULL after calling the commitErrl, so we need to store it + l_handleX = l_handle; + ppdumpslot(); + + // Add 256 bytes of trace (512+256) + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, 256, l_handle); // @at012c + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 256 bytes" ); + ppdumpslot(); + // (header + 256) is the size that add to entry + CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+256), l_rc); // @at012c + + // Add 512 bytes of trace (512+256+512) + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, 512, l_handle); // @at012c + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 256 + 512 bytes"); + ppdumpslot(); + CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+512), l_rc); // @at012c + + // Add 1024 bytes of trace (512+256+512+1024), the entry size is more than 2048 now + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, 1024, l_handle); // @at012c + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 256 + 512 bytes"); + ppdumpslot(); + CHECK_CONDITION( l_entrySizeAfter <= MAX_ERRL_ENTRY_SZ, l_rc); // @at012c + + commitErrl( &l_handle ); + deleteErrl(&l_handleX); + ERRL_DBG("Slots should now be empty"); + ppdumpslot(); + ERRL_DBG("END \n"); + + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestTime +// +// Description: errlTestTime +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestTime() +{ + uint32_t l_rc = 0; + + do + { + ERRL_DBG("START"); + errlHndl_t l_handle = NULL; + uint64_t l_start = 0; + uint64_t l_end = 0; + + + /****************************************************/ + // Check timeStamp + // Create one log + l_start = ssx_timebase_get(); + l_handle = createErrl( 0x1716, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 128, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + + // check time stamp + errlHndl_t l_handle2 = l_handle; + commitErrl( &l_handle ); + l_end = ssx_timebase_get(); + CHECK_CONDITION( (l_handle2->iv_userDetails.iv_timeStamp >= l_start) && + (l_handle2->iv_userDetails.iv_timeStamp <= l_end ), l_rc); + + deleteErrl(&l_handle2); + ERRL_DBG("END \n"); + + }while(0); + + return l_rc; +} + +/*****************************************************************************/ +// errlTestCreate2InfoCallhomeLog +/*****************************************************************************/ +uint32_t errlTestCreate2InfoCallhomeLog() +{ + ERRL_DBG("START" ); + uint32_t l_rc = 0; + + do + { + /****************************************************/ + // Check creating Info logs twice + // Create first Info log + errlHndl_t l_handle = NULL; + errlHndl_t l_handle2= NULL; + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL,g_trac_inf, 32, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // Create second Info log and it should fail + l_handle2 = createErrl( 0x2727, 0x19, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL, g_trac_inf, 32, 0x2, 0x3); // @nh001c @at012c + CHECK_CONDITION( l_handle2 == INVALID_ERR_HNDL, l_rc); + + deleteErrl(&l_handle); + + /****************************************************/ + // Check creating Callhome logs twice + // Create first Callhome log + l_handle = NULL; + l_handle2= NULL; + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA,g_trac_inf, 32, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // Create second Callhome log and it should fail + l_handle2 = createErrl( 0x2727, 0x19, OCC_NO_EXTENDED_RC, ERRL_SEV_CALLHOME_DATA, g_trac_inf, 32, 0x2, 0x3); // @nh001c @at012c + CHECK_CONDITION( l_handle2 == INVALID_ERR_HNDL, l_rc); + + deleteErrl(&l_handle); + + ERRL_DBG("END \n"); + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestCreateMaxLogs +// +// Description: errlTestCreateMaxLogs +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestCreateMaxLogs() +{ + uint32_t l_rc = 0; + + ERRL_DBG("START"); + do + { + + /****************************************************/ + // Check max logs + ERRL_SEVERITY l_sev = 0; + errlHndl_t l_backupHandle[ERRL_MAX_SLOTS-2]; + errlHndl_t l_handle = NULL; + + uint32_t l_index = 0; + // Create 7 ERRL_SEV_PREDICTIVE or ERRL_SEV_UNRECOVERABLE slots randomly + for(l_index =0; l_index < ERRL_MAX_SLOTS-2; l_index++) + { + + uint64_t l_time = ssx_timebase_get(); + l_sev = l_time%2 ? ERRL_SEV_PREDICTIVE : ERRL_SEV_UNRECOVERABLE; + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, l_sev, g_trac_inf, 512, 0x1, l_index); // @nh001c @at012c + CHECK_CONDITION( (l_handle != INVALID_ERR_HNDL) && + (l_handle != NULL), l_rc); + + // backup handle + l_backupHandle[l_index] = l_handle; + + ERRL_DBG("Log Created @ %p with Sev: %d\n",l_handle, l_sev ); + // addUsrDtlsToErrl + memset( G_data, l_index, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle, G_data, sizeof(G_data), ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); + + // commitErrl( &l_handle ); + } + // check if something wrong in for loop + if(l_rc != 0) + break; + + // Create one more and it should fail + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, l_sev, g_trac_inf, 512, 0x1, l_index); // @nh001c @at012c + CHECK_CONDITION( l_handle == INVALID_ERR_HNDL, l_rc); + + // delete errl + for(l_index = 0; l_index < ERRL_MAX_SLOTS-2; l_index++) + { + deleteErrl(&l_backupHandle[l_index]); + } + ppdumpslot(); + + /****************************************************/ + // Check log id overflow + for(l_index = 0; l_index < 256; l_index++) + { + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, l_sev, g_trac_inf, 512, 0x1, l_index); // @nh001c @at012c + CHECK_CONDITION( (l_handle != INVALID_ERR_HNDL) && + (l_handle != NULL), l_rc); + + deleteErrl(&l_handle); + } + + ERRL_DBG("END \n"); + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestCallouts +// +// Description: errlTestCallouts +// +// Flow: FN=None +// +// End Function Specification +// @jh001c +uint32_t errlTestCallouts() +{ + uint32_t l_rc = 0; + ERRL_DBG("START"); + + do + { + errlHndl_t l_handle = NULL; + ERRL_DBG("--------------------------------\n"); + + /****************************************************/ + // Check max callouts + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 128, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + ERRL_CALLOUT_PRIORITY l_array[8] = { + ERRL_CALLOUT_PRIORITY_HIGH, + ERRL_CALLOUT_PRIORITY_MED, + ERRL_CALLOUT_PRIORITY_LOW, + ERRL_CALLOUT_PRIORITY_HIGH, + ERRL_CALLOUT_PRIORITY_MED, + ERRL_CALLOUT_PRIORITY_MED, + ERRL_CALLOUT_PRIORITY_LOW, + ERRL_CALLOUT_PRIORITY_LOW, + }; + + ERRL_CALLOUT_TYPE l_type[8] = { + ERRL_CALLOUT_TYPE_HUID, + ERRL_CALLOUT_TYPE_COMPONENT_ID, + ERRL_CALLOUT_TYPE_HUID, + ERRL_CALLOUT_TYPE_COMPONENT_ID, + ERRL_CALLOUT_TYPE_HUID, + ERRL_CALLOUT_TYPE_COMPONENT_ID, + ERRL_CALLOUT_TYPE_HUID, + ERRL_CALLOUT_TYPE_COMPONENT_ID, + }; + + // add 6 (ERRL_MAX_CALLOUTS) callouts + uint8_t l_index = 0; + for(l_index = 0; l_index < ERRL_MAX_CALLOUTS; l_index++) + { + ERRL_DBG("current callouts %d attempting to add callout # %d with type %d ,priority %d", l_handle->iv_numCallouts, l_index, l_type[l_index], l_array[l_index] ); + addCalloutToErrl(l_handle,l_type[l_index],l_index,l_array[l_index]); + } + CHECK_CONDITION( l_handle->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc); + + // add one more callout and it should fail + addCalloutToErrl(l_handle,l_type[0],l_index,l_array[0]); + CHECK_CONDITION( l_handle->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc); + + dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize ); + deleteErrl( &l_handle ); + ppdumpslot(); + + /****************************************************/ + // Check callouts after errl is committed + // Create log + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 32, 0x1, 0x2); // @nh001c @at012c + errlHndl_t l_log = l_handle; + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // Commit log and add callout. But adding callout should fail + commitErrl( &l_handle ); + addCalloutToErrl(l_handle,l_type[0],0,l_array[0]); + CHECK_CONDITION( l_log->iv_numCallouts == ERRL_MAX_CALLOUTS, l_rc); // @jh003c + + deleteErrl(&l_log); + + /****************************************************/ + // Check addCalloutToErrl for ERRL_SEV_INFORMATIONAL log + // Create ERRL_SEV_INFORMATIONAL log + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_INFORMATIONAL,g_trac_inf, 128, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + if(l_handle == INVALID_ERR_HNDL) + + // add one callout and it should fail + addCalloutToErrl(l_handle,l_type[0],l_index,l_array[0]); + CHECK_CONDITION( l_handle->iv_numCallouts == 0, l_rc); + + dumpLog( l_handle, l_handle->iv_userDetails.iv_entrySize ); + deleteErrl( &l_handle ); + ppdumpslot(); + + ERRL_DBG("END \n"); + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestSetErrlSevToInfo +// +// Description: errlTestSetErrlSevToInfo +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestSetErrlSevToInfo() +{ + uint32_t l_rc = 0; + ERRL_DBG("START"); + + do + { + errlHndl_t l_handle = NULL; + + /****************************************************/ + // Check setErrlSevToInfo + // Create ERRL_SEV_PREDICTIVE log + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 128, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // Add callout + addCalloutToErrl(l_handle,ERRL_CALLOUT_TYPE_HUID,0x00,ERRL_CALLOUT_PRIORITY_LOW); // @jh001c + CHECK_CONDITION( l_handle->iv_numCallouts == 1, l_rc); + + // Call setErrlSevToInfo. Callouts within log should be cleared and + // iv_severity should be set to ERRL_SEV_INFORMATIONAL + setErrlSevToInfo(l_handle); + CHECK_CONDITION( (l_handle->iv_numCallouts == 0) && + (l_handle->iv_severity == ERRL_SEV_INFORMATIONAL), l_rc); + + deleteErrl( &l_handle ); + ppdumpslot(); + + /****************************************************/ + // Check setErrlSevToInfo after errl is committed + // Create log + l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE,g_trac_inf, 128, 0x1, 0x2); // @nh001c @at012c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + errlHndl_t l_log = l_handle; + + // Add callout + addCalloutToErrl(l_handle,ERRL_CALLOUT_TYPE_HUID,0x00,ERRL_CALLOUT_PRIORITY_LOW); // @jh001c + CHECK_CONDITION( l_handle->iv_numCallouts == 1, l_rc); + + // Commit log and call setErrlSevToInfo. But setErrlSevToInfo will do nothing + commitErrl( &l_handle ); + setErrlSevToInfo(l_handle); + CHECK_CONDITION( (l_log->iv_numCallouts == ERRL_MAX_CALLOUTS) && // @jh003c + (l_log->iv_severity == ERRL_SEV_PREDICTIVE), l_rc); + + deleteErrl(&l_log); + ERRL_DBG("END \n"); + + }while(0); + + return l_rc; +} + +// Function Specification +// +// Name: errlTestWordAlign +// +// Description: errlTestWordAlign +// +// Flow: FN=None +// +// End Function Specification +uint32_t errlTestWordAlign() +{ + uint32_t l_rc = 0; + uint16_t l_entrySizeBefore = 0; + uint16_t l_entrySizeAfter = 0; + ERRL_DBG("START"); + + do + { + /****************************************************/ + // Test word align for addUsrDtlsToErrl + // Create log + errlHndl_t l_handle = createErrl( TEST_MODULE_ID, 0x08, OCC_NO_EXTENDED_RC, ERRL_SEV_PREDICTIVE, NULL, 0, 0x1, 0x2); // @nh001c + CHECK_CONDITION( l_handle != INVALID_ERR_HNDL, l_rc); + + // l_handle will set to NULL after calling the commitErrl, so we need to store it + errlHndl_t l_handleX = l_handle; + ppdumpslot(); + + // add 13 bytes of "user details" + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + memset( G_data, 0xAA, sizeof( G_data ) ); + addUsrDtlsToErrl( l_handle, G_data, 13, ERRL_USR_DTL_STRUCT_VERSION_1, ERRL_USR_DTL_TRACE_DATA ); + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 13 bytes" ); + ppdumpslot(); + // (header + WORDALIGN(13)) is the size that add to entry + CHECK_CONDITION( l_entrySizeAfter == (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+16), l_rc); + + /****************************************************/ + // Test word align for addTraceToErrl + // add 21 bytes of trace + l_entrySizeBefore = l_handle->iv_userDetails.iv_entrySize; + addTraceToErrl(g_trac_inf, 21, l_handle); // @at012c + l_entrySizeAfter = l_handle->iv_userDetails.iv_entrySize; + ERRL_DBG("Slots after create + 21 bytes" ); + ppdumpslot(); + // (header + WORDALIGN(21)) is the size that add to entry + CHECK_CONDITION( l_entrySizeAfter <= (l_entrySizeBefore+sizeof(ErrlUserDetailsEntry_t)+24), l_rc); // @at012c + + commitErrl( &l_handle ); + deleteErrl(&l_handleX); + ERRL_DBG("Slots should now be empty"); + ppdumpslot(); + ERRL_DBG("END \n"); + }while(0); + + return l_rc; +} + + +// Function Specification +// +// Name: dumpLog +// +// Description: dumpLog +// +// Flow: FN=None +// +// End Function Specification +void dumpLog( errlHndl_t i_log, uint32_t i_len ) +{ + uint32_t l_written = 0; + uint32_t l_counter = 0; + uint8_t * l_data = (uint8_t*) i_log; + + printf("----------%p---------- \n", i_log ); + + if ( i_log == NULL ) + return; + + while ( l_counter < i_len) + { + printf("| %08X ", (uint32_t) l_data + l_counter); + + // Display 16 bytes in Hex with 2 spaces in between + l_written = 0; + uint8_t i = 0; + for ( i = 0; i < 16 && l_counter < i_len; i++ ) + { + l_written += printf("%02X",l_data[l_counter++]); + + if ( ! ( l_counter % 4 ) ) + { + l_written += printf(" "); + } + } + + // Pad with spaces + uint8_t l_space[64] = {0}; + memset( l_space, 0x00, sizeof( l_space )); + memset( l_space, ' ', 43-l_written); + printf("%s", l_space ); + + // Display ASCII + l_written = 0; + uint8_t l_char = 0; + for ( ; i > 0 ; i-- ) + { + l_char = l_data[ l_counter-i ]; + + if ( isprint( l_char ) && + ( l_char != '&' ) && + ( l_char != '<' ) && + ( l_char != '>' ) + ) + { + l_written += printf("%c",l_char ); + } + else + { + l_written += printf("." ); + } + } + + // Pad with spaces + uint8_t l_space2[64] = {0}; + memset( l_space2, 0x00, sizeof( l_space2 )); + memset( l_space2, ' ', 19-l_written); + printf("%s\n", l_space2 ); + } + printf("----------%p---------- \n", i_log ); + +} + +// Function Specification +// +// Name: ppdumpslot +// +// Description: ppdumpslot +// +// Flow: FN=None +// +// End Function Specification +void ppdumpslot(void) +{ + errlHndl_t l_array[ERRL_MAX_SLOTS] = { + (errlHndl_t)G_errslot1, + (errlHndl_t)G_errslot2, + (errlHndl_t)G_errslot3, + (errlHndl_t)G_errslot4, + (errlHndl_t)G_errslot5, + (errlHndl_t)G_errslot6, + (errlHndl_t)G_errslot7, + (errlHndl_t)G_infoslot, + (errlHndl_t)G_callslot, + }; + + + printf("-------- \n"); + + uint8_t l_index = 0; + for(l_index = 0; l_index < ERRL_MAX_SLOTS; l_index++) + { + if(l_array[l_index]->iv_version != 0) + { + printf("slot[%01d] sz[%04d] id[%03d] @[%p] \n",l_index,l_array[l_index]->iv_userDetails.iv_entrySize, l_array[l_index]->iv_entryId, l_array[l_index]); + } + else + { + printf("slot[%01d] [0] \n",l_index); + } + } + printf("-------- \n"); +} + +/*****************************************************************************/ +// Image Header +/*****************************************************************************/ +IMAGE_HEADER (G_errlTestMain,errlTestMain,ERRLTESTMAIN_ID,OCC_APLT_TEST); + diff --git a/src/occApplet/testApplet/linkTestApplet.cmd b/src/occApplet/testApplet/linkTestApplet.cmd new file mode 100755 index 0000000..d5635d0 --- /dev/null +++ b/src/occApplet/testApplet/linkTestApplet.cmd @@ -0,0 +1,60 @@ + +// $Id$ + + +// This linker script for the test applet + +#define APP_IMAGE_SRAM_START_ADDR 0xFFFFC000 +#define WORD_ALIGN 4 +#define BYTE_ALIGN 1024 +#ifdef OCCMK +INCLUDE occLinkInputFile +#endif + +MEMORY +{ + AppMem : ORIGIN = APP_IMAGE_SRAM_START_ADDR, LENGTH = 0x3C00 +} + +SECTIONS +{ + . = APP_IMAGE_SRAM_START_ADDR; + + __START_ADDR__ = .; + + //////////////////////////////// + // start read-only section + //////////////////////////////// + imageHeader . : { *(imageHeader) } > AppMem + + //////////////////////////////// + // text section 1024 byte aligned + //////////////////////////////// + .text . : { *(.text) . = ALIGN(BYTE_ALIGN);} > AppMem + // NOTE: rodata section needs to be 1k aligned as it is used for setting + // mmu permission during applet execution + .rodata . : { *(.rodata) *(.got2) *(.rodata.str1.1) *(.rodata.str1.4) . = ALIGN(BYTE_ALIGN);} > AppMem + + __READ_ONLY_DATA_LEN__ = . - APP_IMAGE_SRAM_START_ADDR ; + + //////////////////////////////// + // start writeable section + //////////////////////////////// + __WRITEABLE_DATA_ADDR__ = .; + + //////////////////////////////// + // read-write section 1024 byte aligned + //////////////////////////////// + .rela . : { *(.rela*) . = ALIGN(WORD_ALIGN);} > AppMem + // NOTE: rwdata section needs to be 1024 bytes aligned for setting mmu + // permission, so that applet total size is 1024 bytes aligned. + // It is needed for doing DMA copy of the applet. + // NOTE: add one dummy bye "BYTE(1)" to prevent this section empty. If section + // is empty, "ALIGN(BYTE_ALIGN)" won't work. + .rwdata . : { *(.data) *(.bss) *(COMMON) BYTE(1); . = ALIGN(BYTE_ALIGN);} > AppMem + + __WRITEABLE_DATA_LEN__ = . - __WRITEABLE_DATA_ADDR__ ; + + // NOTE: make sure the whole image is 128-byte aligned + +} diff --git a/src/occApplet/testApplet/occLinkInputFile b/src/occApplet/testApplet/occLinkInputFile new file mode 100644 index 0000000..273836b --- /dev/null +++ b/src/occApplet/testApplet/occLinkInputFile @@ -0,0 +1 @@ +INPUT ( pstApplet.o ) diff --git a/src/occApplet/testApplet/pstApplet.c b/src/occApplet/testApplet/pstApplet.c new file mode 100755 index 0000000..a658d1a --- /dev/null +++ b/src/occApplet/testApplet/pstApplet.c @@ -0,0 +1,124 @@ +/****************************************************************************** +// @file pstApplet.c +// @brief pstate_applet +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section pstApplet.c PSTAPPLET.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * prpulusa 02/05/14 created + * @gm043 928988 milesg 06/19/14 checked in to cmvc after some bug fixes. + * + * @endverbatim + * + *///*************************************************************************/ + + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include "ssx_io.h" // For printfs +#include <trac.h> // For traces +#include <appletId.h> // For applet ID +#include "ssx.h" +#include "pgp_common.h" +#include "pstates.h" +#include "gpsm.h" + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define MYENTRYPOINT_ID "pstApplet\0" + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + +//************************************************************************* +// Entry point function +//************************************************************************* +errlHndl_t myEntryPoint(void * i_arg) +{ + + TRAC_INFO("Enter"); + //initialize variables + errlHndl_t l_err = NULL; + int rc=0; + GlobalPstateTable * l_gpst_ptr = NULL; + l_gpst_ptr = gpsm_gpst(); + unsigned int deconfigured_cores = in32(PMC_CORE_DECONFIGURATION_REG); + pcbs_power_management_control_reg_t pmcr; + pmcr.value=0; + unsigned char trace_count[PGP_NCORES] = {0}; + + + //get minimum and maximum p states + Pstate min_ps = gpst_pmin(l_gpst_ptr); + Pstate max_ps = gpst_pmax(l_gpst_ptr); + int iterations; + for(iterations=0;iterations<1000;iterations++){ + //loop through the functioning cores + int core; + for (core = 0; core < PGP_NCORES; core++) { + if (deconfigured_cores & (0x80000000 >> core)) continue; + //go through all the valid power states + int ps; + for (ps=min_ps;ps<=max_ps;ps++){ + + //Issue scoms l + pmcr.fields.local_pstate_req=ps; + pmcr.fields.global_pstate_req=ps; + rc = _putscom(CORE_CHIPLET_ADDRESS(PCBS_POWER_MANAGEMENT_CONTROL_REG,core),pmcr.value, SCOM_TIMEOUT * 20); + if (rc) { + if(trace_count[core] < 5) + { + trace_count[core]++; + TRAC_ERR("pstApplet: putscom failed on core %d with rc = 0x%08x, deconfig_cores = 0x%08x, iteration = %d", + core, rc, deconfigured_cores, iterations); + } + if(rc == 7) + { + continue; + } + break; + } + //Wait 500us before changing the pstate + ssx_sleep(SSX_MICROSECONDS(500)); + + } + } + } + TRAC_INFO("Exit"); + return l_err; +} + +//************************************************************************* +// Image Header +//************************************************************************* +IMAGE_HEADER (G_myEntryPoint,myEntryPoint,MYENTRYPOINT_ID,OCC_APLT_TEST); diff --git a/src/occApplet/testApplet/sensorTest.c b/src/occApplet/testApplet/sensorTest.c new file mode 100755 index 0000000..74a51be --- /dev/null +++ b/src/occApplet/testApplet/sensorTest.c @@ -0,0 +1,1175 @@ +/****************************************************************************** +// @file sensorTest.c +// @brief OCC Sensor test applet +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section sensorTest.c SENSORTEST.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * pbavari 08/17/2011 created + * @pb003 pbavari 08/31/2011 mini-sensor support + * @pb004 pbavari 09/14/2011 Changed to call sensor_init + * product applet + * @pb00A pbavari 11/14/2011 Moved sensor_init from applet and + * updated with latest design change + * @th005 thallet 11/21/2011 #if'd out reset of sensor test so + * it would compile + * @dw000 dwoodham 12/12/2011 Update call to IMAGE_HEADER macro + * @at001 alvinwan 01/10/2012 Enable sensor test applet due to + * sensor interface design changes + * @rc003 rickylie 02/03/2012 Verify & Clean Up OCC Headers & Comments + * @at003 alvinwan 03/19/2012 Add test case for querySensorList. + * @nh001 neilhsu 05/23/2012 Add missing error log tags + * @ai003 ailutsar 11/06/2012 Fix OCC Test Applets so they don't crash OCC + * @th030 thallet 02/04/2013 Removed sensor list query b/c too big + * @gm002 885429 milesg 05/30/2013 change type/location to 16 bit bitmask + * @rt002 901927 tapiar 10/02/2013 update error log to use unique module id + * @fk009 942864 fmkassem 09/30/2014 BMC/HTMGT Poll command version 0x10 support. + * @endverbatim + * + *///*************************************************************************/ +#define SNSR_DEBUG +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include "ssx_io.h" // For printfs +#include <sensor.h> // Sensor interfaces +#include <occ_service_codes.h> // Reason code +#include <errl.h> // For errlHndl_t +#include <trac.h> // For traces +#include <appletManager.h> +#include <sensorQueryList.h> +#include <appletId.h> // For applet ID @dw000a +#include <aplt_service_codes.h> // For test applet module ID +#include <testApltId.h> // For test applet ID + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define SENSORTESTMAIN_ID "Sensor Test\0" +#define UINT16_MIN 0 + +//sensor test module ID enumeration +typedef enum +{ + TEST_NULL_POINTER = 0x00, + TEST_GET_SENSOR_BY_GSID = 0x01, + TEST_COMMON = 0x02, + TEST_QUERY_LIST = 0x03, + +} sensorTestModId; + +// sensor test return codes +typedef enum +{ + SUCCESS_RC = 0x00000000, + GET_SNSR_FAILURE = 0x00000001, + SNSR_RESET_FAILURE = 0x00000002, + SNSR_UPDT_FAILURE = 0x00000003, + SNSR_UPDT_FAILURE2 = 0x00000004, + SNSR_UPDT_FAILURE3 = 0x00000005, + SNSR_UPDT_FAILURE4 = 0x00000006, + SNSR_UPDT_FAILURE5 = 0x00000007, + SNSR_RESET_FAILURE2 = 0x00000008, + RESET_WITH_VECTORIZE_FAILURE= 0x00000009, + VECTORIZE_FAILURE = 0x0000000A, + VECTORIZE_FAILURE2 = 0x0000000B, + VECTORIZE_FAILURE3 = 0x0000000C, + VECTOR_ADD_FAILURE = 0x0000000D, + VECTOR_ADD_FAILURE2 = 0x0000000E, + VECTOR_ADD_FAILURE3 = 0x0000000F, + VECTOR_UPDT_FAILURE = 0x00000010, + VECTOR_UPDT_FAILURE2 = 0x00000011, + VECTOR_UPDT_FAILURE3 = 0x00000012, + VECTOR_UPDT_FAILURE4 = 0x00000013, + VECTOR_UPDT_FAILURE5 = 0x00000014, + VECTOR_UPDT_FAILURE6 = 0x00000015, + VECTOR_UPDT_FAILURE7 = 0x00000016, + VECTOR_UPDT_FAILURE8 = 0x00000017, + VECTOR_UPDT_FAILURE9 = 0x00000018, + VECTOR_UPDT_FAILURE10 = 0x00000019, + VECTOR_ADD_FAILURE4 = 0x0000001A, + QUERY_LIST_FAILURE = 0x0000001B, + QUERY_LIST_FAILURE2 = 0x0000001C, + QUERY_LIST_FAILURE3 = 0x0000001D, + QUERY_LIST_FAILURE4 = 0x0000001E, + QUERY_LIST_FAILURE5 = 0x0000001F, + QUERY_LIST_FAILURE6 = 0x00000020, + QUERY_LIST_FAILURE7 = 0x00000021, + QUERY_LIST_FAILURE8 = 0x00000022, + QUERY_LIST_FAILURE9 = 0x00000023, + QUERY_LIST_FAILURE10 = 0x00000024, + QUERY_LIST_FAILURE11 = 0x00000025, + QUERY_LIST_FAILURE12 = 0x00000026, + QUERY_LIST_FAILURE13 = 0x00000027, + QUERY_LIST_FAILURE14 = 0x00000028, + GET_SNSR_FAILURE1 = 0x00000029, + GET_SNSR_FAILURE2 = 0x0000002A, +} sensorTestRc; + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* +// @ai003A +// Stack size for test applet thread is only 4000 bytes, +// put big structure here for prevent stack overflow + +// @th030 -- ifdef'd out b/c the sensor list is too big to test in applet +#if 0 +sensorQueryList_t G_snsrList[NUMBER_OF_SENSORS_IN_LIST]; +#endif + +//************************************************************************* +// Function Prototypes +//************************************************************************* +uint32_t sensorTestNullPointer(); +uint32_t sensorTestGetSensorByGsid(); +uint32_t sensorTestCommon(); +void printSensor(sensor_t i_snsr); +uint32_t sensorTestQueryList(); + +//************************************************************************* +// Functions +//************************************************************************* + +// Function Specification +// +// Name: sensorTestMain +// +// Description: Entry point function +// +// Flow: FN=None +// +// End Function Specification +errlHndl_t sensorTestMain(void * i_arg) +{ + SNSR_DBG("Enter sensorTestMain\n"); + errlHndl_t l_err = NULL; + + uint32_t l_rc = SUCCESS_RC; + uint8_t l_modId = 0; + + do + { + l_rc = sensorTestNullPointer(); + if( l_rc != SUCCESS_RC) + { + l_modId = TEST_NULL_POINTER; + TRAC_INFO("Failure on null pointer test"); + break; + } + + l_rc = sensorTestGetSensorByGsid(); + if( l_rc != SUCCESS_RC) + { + l_modId = TEST_GET_SENSOR_BY_GSID; + TRAC_INFO("Failure on get sensor by Gsid test"); + break; + } + + l_rc = sensorTestCommon(); + if( l_rc != SUCCESS_RC) + { + l_modId = TEST_COMMON; + TRAC_INFO("Failure on common test"); + break; + } +// @th030 - If'd out b/c the sensor list is too big for an applet +#if 0 + l_rc = sensorTestQueryList(); + if( l_rc != SUCCESS_RC) + { + l_modId = TEST_QUERY_LIST; + TRAC_INFO("Failure on query list test"); + break; + } +#endif + } while (0); + + if( l_rc != SUCCESS_RC) + { + SNSR_DBG("**********************************************\n"); + SNSR_DBG("* Sensor Test Failed: ModId: 0x%x,l_rc: 0x%x\n",l_modId,l_rc); + SNSR_DBG("**********************************************\n"); + /* @ + * @errortype + * @moduleid TEST_APLT_MODID_SENSORTEST + * @reasoncode INTERNAL_FAILURE + * @userdata1 Test Applet ID + * @userdata2 Return Code + * @userdata4 OCC_NO_EXTENDED_RC + * @devdesc Failure executing test applet + */ + l_err = createErrl(TEST_APLT_MODID_SENSORTEST, + INTERNAL_FAILURE, // @nh001c + OCC_NO_EXTENDED_RC, + ERRL_SEV_INFORMATIONAL, + NULL, + 0, + SNSR_TEST_APLT, + l_rc); + } + else + { + SNSR_DBG("**********************************************\n"); + SNSR_DBG("* Sensor Test Passed\n"); + SNSR_DBG("**********************************************\n"); + } + + + SNSR_DBG("Exit sensorTestMain\n"); + + return l_err; +} + + +// Function Specification +// +// Name: sensorTestNullPointer +// +// Description: SensorTestNullPointers +// +// Flow: FN=None +// +// End Function Specification +uint32_t sensorTestNullPointer() +{ + uint32_t l_rc = SUCCESS_RC; + /****************************************************/ + // Try to clear minmax with NULL sensor pointer. Call will be no-op + sensor_clear_minmax(NULL); + + /****************************************************/ + // Try to reset sensor with NULL sensor pointer. Call will be no-op + sensor_reset(NULL); + + /****************************************************/ + // Try to vectorize with NULL sensor pointer and valid vector sensor. + // Call will be no-op + vectorSensor_t l_vecsnsr; + sensor_vectorize(NULL,&l_vecsnsr,0); + + /****************************************************/ + // Try to vectorize with NULL vector sensor pointer and valid sensor pointer + // Call will be no-op + sensor_t l_snsr; + sensor_vectorize(&l_snsr,NULL,0); + + /****************************************************/ + // Try to update sensor with NULL sensor pointer. Call will be no-op + sensor_update(NULL,1); + + /****************************************************/ + // Try to do vector update with NULL sensor pointer. Call will be no-op + sensor_vector_update(NULL,1); + + /****************************************************/ + // Try to enable vector sensor with NULL pointer. Call will be no-op + sensor_vector_elem_enable(NULL,1,1); + + /****************************************************/ + // Try to add vector element with NULL vector sensor pointer. + // Call will be no-op + sensor_t l_sensor; + sensor_vector_elem_add(NULL,1,&l_sensor); + + /****************************************************/ + // Try to add vector element with NULL element pointer. + // Call will be no-op + vectorSensor_t l_vecSensor; + sensor_vector_elem_add(&l_vecSensor,1,NULL); + + return l_rc; +} + + +// Function Specification +// +// Name: sensorTestGetSensorByGsid +// +// Description: SensorTestGetSensorByGsid +// +// Flow: FN=None +// +// End Function Specification +uint32_t sensorTestGetSensorByGsid() +{ + uint32_t l_rc = SUCCESS_RC; + + do + { + /****************************************************/ + // Try to get sensor with invalid GSID. It should return NULL + sensor_t * l_sensor = NULL; + l_sensor = getSensorByGsid(0xFFFF); + + if( l_sensor != NULL) + { + l_rc = GET_SNSR_FAILURE; + break; + } + + // Good path for this function is already tested with other test cases. + + }while(0); + + return l_rc; +} + + +// Function Specification +// +// Name: printSensor +// +// Description: printSensor +// +// Flow: FN=None +// +// End Function Specification +void printSensor(sensor_t i_snsr) +{ + SNSR_DBG("Printing sensor information\n"); + SNSR_DBG("*******************************\n"); + SNSR_DBG("GSID: 0x%x\n",i_snsr.gsid); + SNSR_DBG("sample: 0x%x\n",i_snsr.sample); + SNSR_DBG("sample_min: 0x%x\n",i_snsr.sample_min); + SNSR_DBG("sample_max: 0x%x\n",i_snsr.sample_max); + SNSR_DBG("status.reset: 0x%x\n",i_snsr.status.reset); + SNSR_DBG("accumulator: 0x%x\n",i_snsr.accumulator); + SNSR_DBG("update_tag: 0x%x\n",i_snsr.update_tag); + SNSR_DBG("src_accum_snapshot: 0x%x\n",i_snsr.src_accum_snapshot); + SNSR_DBG("ipmi sensor id: 0x%x\n",i_snsr.ipmi_sid); //@fk009c + SNSR_DBG("vector sensor:\n"); + if( i_snsr.vector != NULL) + { + SNSR_DBG("\toperation: 0x%x\n",i_snsr.vector->operation); + SNSR_DBG("\tsize: 0x%x\n",i_snsr.vector->size); + SNSR_DBG("\tmin_pos: 0x%x\n",i_snsr.vector->min_pos); + SNSR_DBG("\tmax_pos: 0x%x\n",i_snsr.vector->max_pos); + uint16_t i = 0; + for(; i < i_snsr.vector->size; i++) + { + SNSR_DBG("\t[%d].sample:0x%x\n",i, + i_snsr.vector->source_ptr[i]->sample); + } // end for loop + } + SNSR_DBG("mini sensor:\n"); + if( i_snsr.mini_sensor != NULL) + { + SNSR_DBG("\tmini sensor sample: 0x%x\n",*(i_snsr.mini_sensor)); + } + SNSR_DBG("*******************************\n"); + +} + + +// Function Specification +// +// Name: sensorTestCommon +// +// Description: sensorTestCommon +// +// Flow: FN=None +// +// End Function Specification +uint32_t sensorTestCommon() +{ + uint32_t l_rc = SUCCESS_RC; + /****************************************************/ + // Use test sensors to avoid the conflict with other components + // PROBE250US0, // Internal Sensor for debug via AMESTER + // PROBE250US1, // Internal Sensor for debug via AMESTER + // PROBE250US2, // Internal Sensor for debug via AMESTER + // PROBE250US3, // Internal Sensor for debug via AMESTER + // PROBE250US4, // Internal Sensor for debug via AMESTER + // PROBE250US5, // Internal Sensor for debug via AMESTER + // PROBE250US6, // Internal Sensor for debug via AMESTER + // PROBE250US7, // Internal Sensor for debug via AMESTER + + sensor_t *l_sensor=getSensorByGsid(PROBE250US0); + sensor_t *l_sensor1=getSensorByGsid(PROBE250US1); + sensor_t *l_sensor2=getSensorByGsid(PROBE250US4); + sensor_t *l_sensor3=getSensorByGsid(PROBE250US7); + do + { + // make sure getSensorByGsid did not return NULL pointer. + if( (l_sensor == NULL) || + (l_sensor1 == NULL) || + (l_sensor2 == NULL) || + (l_sensor3 == NULL)) + { + l_rc = GET_SNSR_FAILURE2; + break; + } + + //Check sensor gsid + if((l_sensor->gsid!=PROBE250US0) || + (l_sensor1->gsid!=PROBE250US1) || + (l_sensor2->gsid!=PROBE250US4) || + (l_sensor3->gsid!=PROBE250US7) ) + { + l_rc = GET_SNSR_FAILURE1; + break; + } + + // Reset sensors before any other test so that we don't + // end up using old data if exists. + sensor_reset(l_sensor); + sensor_reset(l_sensor1); + sensor_reset(l_sensor2); + sensor_reset(l_sensor3); + + /****************************************************/ + uint16_t l_miniSnsr = 0; + // Set minisnsr to test minisnr reset and update + l_sensor2->mini_sensor = &l_miniSnsr; + // test update sensors. + sensor_update(l_sensor,10); + sensor_update(l_sensor1,11); + sensor_update(l_sensor2,12); + + if( (l_sensor->sample != 10) || + (l_sensor->mini_sensor != NULL) || + (l_sensor->sample_max!=10) || + (l_sensor->sample_min!=10) || + (l_sensor1->sample != 11) || + (l_sensor1->mini_sensor != NULL) || + (l_sensor1->sample_max!=11) || + (l_sensor1->sample_min!=11) || + (l_sensor2->sample != 12) || + (l_sensor2->mini_sensor == NULL) || + (l_sensor2->sample_max!=12) || + (l_sensor2->sample_min!=12) || + (*(l_sensor2->mini_sensor) != 12) || + (l_miniSnsr != 12) + ) + { + l_rc = SNSR_UPDT_FAILURE; + break; + } + + /****************************************************/ + // test reset sensors without vectorize + sensor_reset(l_sensor2); + if( (l_sensor2->sample != 0) || + (l_sensor2->status.reset != 0) || + (l_sensor2->sample_min != UINT16_MAX) || + (l_sensor2->sample_max != UINT16_MIN) || + (*(l_sensor2->mini_sensor) != 0) || + (l_miniSnsr != 0)) + { + l_rc = SNSR_RESET_FAILURE; + break; + } + /****************************************************/ + // test update of sensor with reset status bit set + l_sensor2->status.reset = 1; + sensor_update(l_sensor2,12); + + if( (l_sensor2->sample != 12) || + (l_sensor2->status.reset != 0) || + (l_sensor2->sample_min != 12) || + (l_sensor2->sample_max != 12) ) + { + l_rc = SNSR_RESET_FAILURE2; + break; + } + + /****************************************************/ + // vectorize with reset status bit set + l_sensor->status.reset = 1; + vectorSensor_t l_vecSnsr; + + sensor_vectorize(l_sensor,&l_vecSnsr, VECTOR_OP_MIN); + + if(l_sensor->vector==NULL) + { + l_rc = VECTORIZE_FAILURE2; + break; + } + else + { + if(l_vecSnsr.operation!=VECTOR_OP_MIN) + { + l_rc = VECTORIZE_FAILURE3; + break; + } + } + + /****************************************************/ + // test getSensorByGsid with valid GSID + sensor_t * l_tempSensor = getSensorByGsid(PROBE250US0); + + if((l_tempSensor == NULL) || + (l_tempSensor->gsid!=PROBE250US0)) + { + l_rc = GET_SNSR_FAILURE; + break; + } + else + { + if( l_tempSensor->vector->operation != VECTOR_OP_MIN) + { + l_rc = VECTORIZE_FAILURE; + break; + } + } + /****************************************************/ + // test reset sensor with vectorize + sensor_reset(l_sensor); + if((l_sensor->vector->max_pos != VECTOR_SENSOR_DEFAULT_VAL) || + (l_vecSnsr.max_pos != VECTOR_SENSOR_DEFAULT_VAL) || + (l_sensor->vector->min_pos != VECTOR_SENSOR_DEFAULT_VAL) || + (l_vecSnsr.min_pos != VECTOR_SENSOR_DEFAULT_VAL) || + (l_sensor->sample_min != UINT16_MAX) || + (l_sensor->sample_max != UINT16_MIN) ) + { + l_rc = RESET_WITH_VECTORIZE_FAILURE; + break; + } + + /****************************************************/ + // test update of sensor with different min and max values + sensor_update(l_sensor,10); + + sensor_update(l_sensor3,5); + if( (l_sensor3->sample != 5) || + (l_sensor3->mini_sensor != NULL) || + (l_sensor3->sample_max!=5) || + (l_sensor3->sample_min!=5) + ) + { + l_rc = SNSR_UPDT_FAILURE2; + break; + } + sensor_update(l_sensor3,2); + if( (l_sensor3->sample != 2) || + (l_sensor3->mini_sensor != NULL) || + (l_sensor3->sample_max!=5) || + (l_sensor3->sample_min!=2) + ) + { + l_rc = SNSR_UPDT_FAILURE3; + break; + } + sensor_update(l_sensor3,8); + if( (l_sensor3->sample != 8) || + (l_sensor3->mini_sensor != NULL) || + (l_sensor3->sample_max!=8) || + (l_sensor3->sample_min!=2) + ) + { + l_rc = SNSR_UPDT_FAILURE4; + break; + } + sensor_update(l_sensor3,5); + if( (l_sensor3->sample != 5) || + (l_sensor3->mini_sensor != NULL) || + (l_sensor3->sample_max!=8) || + (l_sensor3->sample_min!=2) + ) + { + l_rc = SNSR_UPDT_FAILURE5; + break; + } + + /****************************************************/ + // test adding vector element with invalid location + sensor_vector_elem_add(l_sensor->vector,0xFF,l_sensor3); + + if( (l_sensor->vector->size != 0) || + (l_vecSnsr.size != 0)) + { + l_rc = VECTOR_ADD_FAILURE; + break; + } + + /****************************************************/ + // test adding vector element with valid location + sensor_vector_elem_add(l_sensor->vector,0,l_sensor2); + + if( (l_sensor->vector->size != 1) || + (l_vecSnsr.size != 1)) + { + l_rc = VECTOR_ADD_FAILURE4; + break; + } + + /****************************************************/ + // test adding vector element with non-contiguous location. + // It should not add element to the vector + sensor_vector_elem_add(l_sensor->vector,2,l_sensor1); + + if((l_sensor->vector->size != 1) || + (l_vecSnsr.size != 1)) + { + l_rc = VECTOR_ADD_FAILURE2; + break; + } + + /****************************************************/ + // test adding vector element with contiguous location + sensor_vector_elem_add(l_sensor->vector,1,l_sensor1); + sensor_vector_elem_add(l_sensor->vector,0,l_sensor3); + + if((l_sensor->vector->size != 2) || + (l_vecSnsr.size != 2)) + { + l_rc = VECTOR_ADD_FAILURE3; + break; + } + sensor_vector_elem_add(l_sensor->vector,2,l_sensor2); + + //so far the source sensors of vector sensor are: + // l_sensor3=5 + // l_sensor1=11 + // l_sensor2=12 + + /****************************************************/ + // test disabling vector element with valid location + sensor_vector_elem_enable(l_sensor->vector,0,0); + + /****************************************************/ + // test updating vector element with min operation and + // element disabled + + uint32_t l_tempacc=l_sensor->accumulator; + sensor_vector_update(l_sensor,0); + if( (l_sensor->sample != 11) || (l_sensor->sample_min != 10 ) || + (l_sensor->sample_max != 11 ) || + (l_sensor->accumulator != l_tempacc+11)|| + (l_sensor->vector->min_pos != 1 )) + { + l_rc = VECTOR_UPDT_FAILURE; + break; + } + + /****************************************************/ + // test enabling vector element with min + + l_tempacc=l_sensor->accumulator; + sensor_vector_elem_enable(l_sensor->vector,0,1); + sensor_vector_update(l_sensor,0); + + if( (l_sensor->sample != 5) || (l_sensor->sample_min != 5 ) || + (l_sensor->sample_max != 11 ) || + (l_sensor->accumulator != l_tempacc+5)|| + (l_sensor->vector->min_pos != 0 )) + { + l_rc = VECTOR_UPDT_FAILURE9; + break; + } + + /****************************************************/ + // test updating vector element with max operation + vectorSensor_t l_vecSnsr3; + sensor_vectorize(l_sensor3,&l_vecSnsr3,VECTOR_OP_MAX); + + sensor_vector_elem_add(l_sensor3->vector,0,l_sensor1); + sensor_vector_elem_add(l_sensor3->vector,1,l_sensor2); + sensor_vector_elem_add(l_sensor3->vector,2,l_sensor); + + + //so far the source sensors of vector sensor are: + // l_sensor1=11 + // l_sensor2=12 + // l_sensor=5 + /****************************************************/ + // test enabling vector element with invalid location + sensor_vector_elem_enable(l_sensor3->vector,0xFF,0); + sensor_vector_elem_enable(l_sensor3->vector,2,0); + + /****************************************************/ + // test updating vector element with max operation and + // disabled element + l_tempacc=l_sensor3->accumulator; + sensor_vector_update(l_sensor3,0); + + if( (l_sensor3->sample != 12) || (l_sensor3->sample_min != 2 ) || + (l_sensor3->sample_max != 12 ) || + (l_sensor3->accumulator != l_tempacc+12)|| + (l_sensor3->vector->max_pos != 1)) + { + l_rc = VECTOR_UPDT_FAILURE2; + break; + } + + l_tempacc=l_sensor3->accumulator; + sensor_vector_elem_enable(l_sensor3->vector,2,1); + sensor_vector_update(l_sensor3,0); + + if( (l_sensor3->sample != 12) || (l_sensor3->sample_min != 2 ) || + (l_sensor3->sample_max != 12 ) || + (l_sensor3->accumulator != l_tempacc+12)|| + (l_sensor3->vector->max_pos != 1)) + { + l_rc = VECTOR_UPDT_FAILURE10; + break; + } + + vectorSensor_t l_vecSnsr1; + /****************************************************/ + // test updating vector element with average operation + sensor_vectorize(l_sensor1,&l_vecSnsr1,VECTOR_OP_AVG); + sensor_vector_elem_add(l_sensor1->vector,0,l_sensor2); + sensor_vector_elem_add(l_sensor1->vector,1,l_sensor); + /****************************************************/ + + //so far the source sensors of vector sensor are: + // l_sensor2=12 + // l_sensor=5 + + // test updating vector element with status reset bit set and + // average op + l_sensor1->status.reset = 1; + sensor_vector_update(l_sensor1,11); + if( (l_sensor1->sample != 12) || (l_sensor1->sample_min != 12 ) || + (l_sensor1->sample_max != 12 ) || (l_sensor1->accumulator != 12)|| + (l_sensor1->vector->max_pos != VECTOR_SENSOR_DEFAULT_VAL) || + (l_sensor1->vector->min_pos != VECTOR_SENSOR_DEFAULT_VAL)) + { + l_rc = VECTOR_UPDT_FAILURE3; + break; + } + + /****************************************************/ + // test updating vector element with average operation and + // disabled element + l_tempacc=l_sensor1->accumulator; + sensor_vector_elem_enable(l_sensor1->vector,0,0); + sensor_vector_update(l_sensor1,2); + + if( (l_sensor1->sample != 5) || (l_sensor1->sample_min != 5 ) || + (l_sensor1->sample_max != 12 ) || + (l_sensor1->accumulator != l_tempacc+5)) + { + l_rc = VECTOR_UPDT_FAILURE7; + break; + } + + sensor_vector_elem_enable(l_sensor1->vector,0,1); + /****************************************************/ + // test updating vector element with average operation and + // threshold greater than samples + l_tempacc=l_sensor1->accumulator; + sensor_vector_update(l_sensor1,25); + + if( (l_sensor1->sample != 5) || (l_sensor1->sample_min != 5 ) || + (l_sensor1->sample_max != 12 ) || + (l_sensor1->accumulator != l_tempacc) ) + { + l_rc = VECTOR_UPDT_FAILURE4; + break; + } + + /****************************************************/ + // test updating vector element with average operation and + // threshold lower than samples + l_tempacc=l_sensor1->accumulator; + sensor_vector_update(l_sensor1,2); + if( (l_sensor1->sample != 8) || (l_sensor1->sample_min != 5 ) || + (l_sensor1->sample_max != 12 ) || + (l_sensor1->accumulator != l_tempacc+8)) + { + l_rc = VECTOR_UPDT_FAILURE8; + break; + } + + l_sensor2->status.reset = 0; + /****************************************************/ + // test update without vectorize should not do anything. Call should be + // noop + sensor_vector_update(l_sensor2,0); + + if( (l_sensor2->sample != 12)) + { + l_rc = VECTOR_UPDT_FAILURE5; + break; + } + + vectorSensor_t l_vecSnsr2; + /****************************************************/ + // test updating vector and vectorize with invalid operation + // should not update anything + sensor_vectorize(l_sensor2,&l_vecSnsr2,0xFF); + + sensor_vector_elem_add(l_sensor2->vector,0,l_sensor); + sensor_vector_elem_add(l_sensor2->vector,1,l_sensor3); + //so far the source sensors of vector sensor are: + // l_sensor=5 + // l_sensor3=12 + sensor_vector_update(l_sensor2,0); + + if( (l_sensor2->sample != 12)) + { + l_rc = VECTOR_UPDT_FAILURE6; + break; + } + + }while(0); + + if( (l_sensor != NULL) && + (l_sensor1 != NULL) && + (l_sensor2 != NULL) && + (l_sensor3 != NULL)) + { + l_sensor->vector = NULL; + l_sensor1->vector = NULL; + l_sensor2->vector = NULL; + l_sensor3->vector = NULL; + l_sensor->mini_sensor = NULL; + l_sensor1->mini_sensor = NULL; + l_sensor2->mini_sensor = NULL; + l_sensor3->mini_sensor = NULL; + } + + return l_rc; +} + + +// Function Specification +// +// Name: callQuerySensorList +// +// Description: querySensorList: Will call the SenosrQeryList product applet +// +// Flow: FN=None +// +// End Function Specification +errlHndl_t callQuerySensorList(const uint16_t i_startGsid, + const uint8_t i_present, + const uint16_t i_type, + const uint16_t i_loc, + uint16_t * io_numOfSensors, + sensorQueryList_t * o_sensors, + sensor_info_t * o_sensorInfoPtrs // @at003A + ) +{ + OCC_APLT_STATUS_CODES l_status = OCC_APLT_SUCCESS; + errlHndl_t l_errl = NULL; + + querySensorListAppletArg_t l_querySensorListAppletArg={ + i_startGsid, + i_present, + i_type, + i_loc, + io_numOfSensors, + o_sensors, + o_sensorInfoPtrs // @at003A + }; + + + //Call sensor query list applet + runApplet(OCC_APLT_SNSR_QUERY, // Applet enum Name + &l_querySensorListAppletArg, // Applet arguments + TRUE, // Blocking call? + NULL, // Applet finished semaphore + &l_errl, // Error log handle + &l_status); // Error status + + return l_errl; + +} + + +// Function Specification +// +// Name: printQuerySensor +// +// Description: printQuerySensor +// +// Flow: FN=None +// +// End Function Specification +void printQuerySensor( const uint16_t i_count, + sensorQueryList_t * i_sensors, + sensor_info_t * i_sensorInfos) +{ + int i; + if(i_count!=0 && // @at003M + ( (i_sensors!=NULL) || // @at003M + (i_sensorInfos!=NULL) ) ) // @at003M + { + // Print sensorQueryList_t + if( i_sensors != NULL ) + { + SNSR_DBG("Printing sensorQueryList_t information"); + SNSR_DBG("*******************************"); + + for(i=0;i<i_count;i++) + { + SNSR_DBG("ID:0x%4x Value:%4d Name:%s",i_sensors[i].gsid, + i_sensors[i].sample, i_sensors[i].name); + } + SNSR_DBG("*******************************\n"); + } + + // @at003A begin + // Print sensor_info_t + if ( i_sensorInfos != NULL ) + { + SNSR_DBG("Printing sensor_info_t information"); + SNSR_DBG("*******************************"); + + for(i=0;i<i_count;i++) + { + SNSR_DBG("Name:%s", i_sensorInfos[i].name); + SNSR_DBG("Frq:0x%4x", i_sensorInfos[i].sensor.freq); + SNSR_DBG("Location:0x%4x", i_sensorInfos[i].sensor.location); + SNSR_DBG("Number:0x%4x", i_sensorInfos[i].sensor.number); + SNSR_DBG("Scalefactor:0x%4x", i_sensorInfos[i].sensor.scalefactor); + SNSR_DBG("Type:0x%4x", i_sensorInfos[i].sensor.type); + SNSR_DBG("Unit:%s", i_sensorInfos[i].sensor.units); + } + SNSR_DBG("*******************************\n"); + } + } + // @at003A end +} + + +// @th030 -- ifdef'd out b/c the sensor list is too big to test this in an applet +#if 0 + +// Function Specification +// +// Name: sensorTestQueryList +// +// Description: sensorTestQueryList +// +// Flow: FN=None +// +// End Function Specification +uint32_t sensorTestQueryList() +{ + uint32_t l_rc = SUCCESS_RC; + uint16_t l_count = NUMBER_OF_SENSORS_IN_LIST; + errlHndl_t l_err = NULL; + + do + { + uint16_t l_numOfSensors = 0; + sensor_info_t l_sensorInfo; // @at003M + /****************************************************/ + // Test with invalid GSID. Must return error + l_err = callQuerySensorList(0xFFFF,1,SENSOR_TYPE_ALL,SENSOR_LOC_ALL, + &l_numOfSensors,G_snsrList, NULL); // @at003M // @ai003M + + if( NULL == l_err) + { + l_rc = QUERY_LIST_FAILURE; + break; + } + else if( (l_err != INVALID_ERR_HNDL) && + (l_err->iv_reasonCode != INTERNAL_FAILURE)) // @nh001c + { + l_rc = QUERY_LIST_FAILURE12; + break; + + } + + deleteErrl(&l_err); + + /****************************************************/ + // Test with NULL number of sensor pointer. Must return error + l_err = callQuerySensorList(0,1,SENSOR_TYPE_ALL,SENSOR_LOC_ALL, + NULL,G_snsrList, NULL); // @at003M // @ai003M + + if( NULL == l_err) + { + l_rc = QUERY_LIST_FAILURE2; + break; + } + else if( (l_err != INVALID_ERR_HNDL) && + (l_err->iv_reasonCode != INTERNAL_FAILURE)) // @nh001c + { + l_rc = QUERY_LIST_FAILURE13; + break; + + } + + deleteErrl(&l_err); + + /****************************************************/ + // Test with NULL sensor list pointer. Must return error + l_err = callQuerySensorList(0,1,SENSOR_TYPE_ALL,SENSOR_LOC_ALL, + &l_numOfSensors,NULL, NULL); // @at003M + + if( NULL == l_err) + { + l_rc = QUERY_LIST_FAILURE3; + break; + } + else if( (l_err != INVALID_ERR_HNDL) && + (l_err->iv_reasonCode != INTERNAL_FAILURE)) // @nh001c + { + l_rc = QUERY_LIST_FAILURE14; + break; + + } + + deleteErrl(&l_err); + + /****************************************************/ + // Query 0 # of sensors. Must return 0 sensors and no error + l_err = callQuerySensorList(0,1,SENSOR_TYPE_ALL,SENSOR_LOC_ALL, + &l_numOfSensors,G_snsrList,NULL); // @at003M // @ai003M + + if( (l_err != NULL) || (l_numOfSensors != 0)) + { + l_rc = QUERY_LIST_FAILURE4; + break; + } + + /****************************************************/ + // Query All sensors except last one. Must return no error + l_numOfSensors = l_count -1; //(-1) to leave out last sensor + l_err = callQuerySensorList(0,1,SENSOR_TYPE_ALL,SENSOR_LOC_ALL, + &l_numOfSensors,G_snsrList, NULL); // @at003M // @ai003M + + + if( (l_err != NULL) || (l_numOfSensors > (l_count-1))) + { + l_rc = QUERY_LIST_FAILURE5; + break; + } + + /****************************************************/ + // Query last sensors. Must return no error. Trying to get + // more sensors but should return only once since start GSID + // is of last sensor + l_numOfSensors = 5; + sensor_t *l_sensor=getSensorByGsid(l_count-1); + sensor_update(l_sensor, 10); + + l_err = callQuerySensorList(l_count-1,1,SENSOR_TYPE_ALL, + SENSOR_LOC_ALL,&l_numOfSensors,G_snsrList, NULL); // @at003M // @ai003M + + if( (l_err != NULL) || (l_numOfSensors != 1) || + (l_sensor->gsid!=l_count-1)) + { + l_rc = QUERY_LIST_FAILURE6; + + break; + } + + /****************************************************/ + // Query sensors that are not present Must return no error. + l_numOfSensors = 10; + l_err = callQuerySensorList(PROBE250US0,0,SENSOR_TYPE_ALL, + SENSOR_LOC_ALL,&l_numOfSensors,G_snsrList, NULL); // @at003M // @ai003M + //printQuerySensor(l_numOfSensors,G_snsrList, NULL ); // @ai003M + if( (l_err != NULL) || (l_numOfSensors == 0)) + { + l_rc = QUERY_LIST_FAILURE7; + break; + } + + /****************************************************/ + // Query sensors that are present, type and location + // does not match any. Must return no error and no sensors + l_numOfSensors = 10; + l_err = callQuerySensorList(PROBE250US0,1,0x0,0x0, + &l_numOfSensors,G_snsrList, NULL); // @at003M // @ai003M + printQuerySensor(l_numOfSensors,G_snsrList, NULL ); // @ai003M + + if( (l_err != NULL) || (l_numOfSensors != 0)) + { + l_rc = QUERY_LIST_FAILURE8; + break; + } + + /****************************************************/ + // Query sensors that are present,type=AMEC_SENSOR_TYPE_GENERIC, + // loc=AMEC_SENSOR_LOC_OCC. Must return no error. + l_numOfSensors = 10; + l_err = callQuerySensorList(PROBE250US0,1,AMEC_SENSOR_TYPE_GENERIC, + AMEC_SENSOR_LOC_OCC, + &l_numOfSensors,G_snsrList, NULL); // @at003M // @ai003M + + if( (l_err != NULL) || (l_numOfSensors == 0)) + { + l_rc = QUERY_LIST_FAILURE9; + break; + } + + /****************************************************/ + // Query sensors that are present,type=AMEC_SENSOR_TYPE_GENERIC and + // any location. Must return no error. + l_numOfSensors = 10; + l_err = callQuerySensorList(PROBE250US0,1,AMEC_SENSOR_TYPE_GENERIC, + SENSOR_LOC_ALL, + &l_numOfSensors,G_snsrList, NULL); // @at003M // @ai003M + + if( (l_err != NULL) || (l_numOfSensors == 0)) + { + l_rc = QUERY_LIST_FAILURE10; + break; + } + + /****************************************************/ + // Query sensors that are present,any type and + // location=AMEC_SENSOR_LOC_OCC. Must return no error. + l_numOfSensors = 10; + l_err = callQuerySensorList(PROBE250US0,1,SENSOR_TYPE_ALL, + AMEC_SENSOR_LOC_OCC,&l_numOfSensors, + G_snsrList, NULL); // @at003M // @ai003M + + if( (l_err != NULL) || (l_numOfSensors == 0)) + { + l_rc = QUERY_LIST_FAILURE11; + break; + } + + // @at003A begin + /****************************************************/ + // Query sensors to get sensor info,any type and + // location=AMEC_SENSOR_LOC_OCC. Must return no error. + l_numOfSensors = 1; + l_err = callQuerySensorList(PROBE250US0,1,SENSOR_TYPE_ALL, + SENSOR_LOC_ALL,&l_numOfSensors, + NULL, &l_sensorInfo); // @at003M + if( (l_err != NULL) || (l_numOfSensors == 0)) + { + l_rc = QUERY_LIST_FAILURE11; + break; + } + printQuerySensor(l_numOfSensors,NULL, &l_sensorInfo ); + // @at003A end + + }while(0); + + if( l_err != NULL) + { + deleteErrl(&l_err); + } + + return l_rc; +} +#endif + + +/*****************************************************************************/ +// Image Header +/*****************************************************************************/ +// @dw000 - call macro with Applet ID arg +IMAGE_HEADER (G_sensorTestMain,sensorTestMain,SENSORTESTMAIN_ID,OCC_APLT_TEST); + diff --git a/src/occApplet/testApplet/testApltId.h b/src/occApplet/testApplet/testApltId.h new file mode 100755 index 0000000..cda2e64 --- /dev/null +++ b/src/occApplet/testApplet/testApltId.h @@ -0,0 +1,60 @@ +/****************************************************************************** +// @file testApltId.h +// @brief Error codes for aplt component. +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section testApltId.h + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * @nh001 neilhsu 05/23/2012 Add missing error log tags + * + * @endverbatim + * + *///*************************************************************************/ + +#ifndef _TESTAPLTID_H_ +#define _TESTAPLTID_H_ + +//************************************************************************* +// Includes +//************************************************************************* + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* +enum testApltIds +{ + TEST_APLT_ID_UNKNOWN = 0x00, + SNSR_TEST_APLT = 0x01, + ERRL_TEST_APLT = 0x02, +}; + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + +#endif /* #ifndef _TESTAPLTID_H_ */ diff --git a/src/occApplet/testApplet/testappletfiles.mk b/src/occApplet/testApplet/testappletfiles.mk new file mode 100755 index 0000000..7a0962d --- /dev/null +++ b/src/occApplet/testApplet/testappletfiles.mk @@ -0,0 +1,37 @@ +# @file libofiles.mk +# +# @brief mk for libssx.a object files +# +# @page ChangeLogs Change Logs +# @section ofiles.mk +# @verbatim +# +# +# Change Log ****************************************************************** +# Flag Defect/Feature User Date Description +# ------ -------------- ---------- ------------ ----------- +# @pb00E pbavari 03/28/2012 Makefile ODE support +# @gm043 928988 milesg 06/19/2014 Added pstApplet +# +# @endverbatim +# +########################################################################## +# INCLUDES +########################################################################## +# New test applet source file must to listed as part of the SOURCES variable +# to create test applet image. This will only create the image. It will not +# add these images as part of the mainstore single image. To make it part of +# of the mainstore single image, please see comments for IMAGE_TO_COMBINE +# variable +C-SOURCES = sensorTest.c apsstest.c errlTest.c traceTest.c pstApplet.c + +TESTAPLT_OBJECTS = $(C-SOURCES:.c=.o) + +sensorTest_OFILES = sensorTest.o +apsstest_OFILES = apsstest.o +errlTest_OFILES = errlTest.o +traceTest_OFILES = traceTest.o +pstApplet_OFILES = pstApplet.o + + + diff --git a/src/occApplet/testApplet/traceTest.c b/src/occApplet/testApplet/traceTest.c new file mode 100755 index 0000000..975ea72 --- /dev/null +++ b/src/occApplet/testApplet/traceTest.c @@ -0,0 +1,340 @@ +/****************************************************************************** +// @file traceTest.c +// @brief Test applet for trace functions +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section traceTest.c TRACETEST.c + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * ailutsar 11/13/12 created + * + * @endverbatim + * + *///*************************************************************************/ + + +//************************************************************************* +// Includes +//************************************************************************* +#include <common_types.h> // imageHdr_t declaration and image header macro +#include <errl.h> // For error handle +#include "ssx_io.h" // For printfs +#include <trac.h> // For traces +#include <appletId.h> // For applet ID @dw000a +#include <trac_service_codes.h> + +//************************************************************************* +// Externs +//************************************************************************* +extern SsxSemaphore g_trac_mutex; + +//************************************************************************* +// Macros +//************************************************************************* +#define TRAC_INTF_MUTEX_TIMEOUT SSX_SECONDS(5) +//************************************************************************* +// Defines/Enums +//************************************************************************* +#define TRACETEST_ID "traceTest\0" +#define para_int_0 "0 para" +#define para_int_1 "1 para (%d)" +//#define para_int_2 "2 para (%d) (%d)" +//#define para_int_3 "3 para (%d) (%d) (%d)" +//#define para_int_4 "4 para (%d) (%d) (%d) (%d)" +#define para_int_5 "5 para (%d) (%d) (%d) (%d) (%d)" +#define para_int_6 "6 para (%d) (%d) (%d) (%d) (%d) (%d)" +#define para_hex_0 "0 para" +#define para_hex_1 "1 para (%X)" +//#define para_hex_2 "2 para (%X) (%X)" +//#define para_hex_3 "3 para (%X) (%X) (%X)" +//#define para_hex_4 "4 para (%X) (%X) (%X) (%X)" +#define para_hex_5 "5 para (%X) (%X) (%X) (%X) (%X)" +#define para_hex_6 "6 para (%X) (%X) (%X) (%X) (%X) (%X)" +#define para_chr_0 "0 para" +#define para_chr_1 "1 para (%s)" +//#define para_chr_2 "2 para (%s) (%s)" +//#define para_chr_3 "3 para (%s) (%s) (%s)" +//#define para_chr_4 "4 para (%s) (%s) (%s) (%s)" +#define para_chr_5 "5 para (%s) (%s) (%s) (%s) (%s)" +#define para_chr_6 "6 para (%s) (%s) (%s) (%s) (%s) (%s)" +#define MIN_TRACE_ENTRY_SIZE 32 + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* +char G_trac_buffer[TRACE_BUFFER_SIZE + 100]; + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* +int traceSemTest(void) +{ + UINT l_rc = 0; + + // lock trace semaphore first + l_rc = ssx_semaphore_pend(&g_trac_mutex, TRAC_INTF_MUTEX_TIMEOUT); + if(SSX_OK == l_rc) + { + // create one trace + TRAC_INFO("traceTest Applet: test trace semaphore"); + + // Unlock trace semaphore + ssx_semaphore_post(&g_trac_mutex); + + } + else + { + l_rc = 1; + } + + return l_rc; +} + +int traceFuncTest() +{ + UINT l_rc = 0; + UINT l_max_trace_entries = TRACE_BUFFER_SIZE / MIN_TRACE_ENTRY_SIZE; + UINT l_entry_count = 0; + UINT l_buffer_size = 0; + tracDesc_t l_head = NULL; + + do + { + // Test target - trac_write_XXX(), TRAC_get_buffer() and TRAC_get_td() + // This testcase would create l_max_trace_entries +1 trace entries + // to fill trace buffer, times_wrap should be larger than zero + do{ + l_entry_count++; + TRAC_INFO("traceTest applet INFO record: count %d", (int)l_entry_count); + TRAC_ERR("traceTest applet ERR record: count %d", (int)l_entry_count); + TRAC_IMP("traceTest applet IMP record: count %d", (int)l_entry_count); + }while(l_max_trace_entries >= l_entry_count); + + // Check times_wrap in TRAC_INFO. + // Because structures are all the same, skip TRAC_ERR and TRAC_IMP + l_rc = TRAC_get_buffer(TRAC_get_td("INF"), G_trac_buffer); + l_head = (tracDesc_t)&G_trac_buffer; + if((l_rc != 0 ) || (l_head->times_wrap == 0)) + { + printf("Fail: times_wrap error in trace buffer: %d, %d\n", l_rc, l_head->times_wrap); + break; + } + + // Test target - TRAC_get_buffer() and TRAC_get_td() + // case: invalid paramenters + l_rc = TRAC_get_buffer(TRAC_get_td("INF"), NULL); + l_head = (tracDesc_t)&G_trac_buffer; + if(l_rc == 0) + { + printf("TRAC_get_buffer(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer() invalid 1th parameter\n"); + break; + } + + l_rc = TRAC_get_buffer(NULL, G_trac_buffer); + l_head = (tracDesc_t)&G_trac_buffer; + if(l_rc == 0) + { + printf("TRAC_get_buffer(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer() invalid 2nd parameter\n"); + break; + } + + // Test target - TRAC_get_buffer_partial() and TRAC_get_td() + // case: invalid paramenters + l_buffer_size = TRACE_BUFFER_SIZE; + l_rc = TRAC_get_buffer_partial(NULL, G_trac_buffer, &l_buffer_size); + if((l_rc != TRAC_INVALID_PARM) && (l_buffer_size !=0)) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() invalid 1st parameter\n"); + break; + } + + l_rc = TRAC_get_buffer_partial(TRAC_get_td("UNKNOWN"), NULL, &l_buffer_size); + if((l_rc != TRAC_INVALID_PARM) && (l_buffer_size !=0)) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() invalid 1st parameter\n"); + break; + } + + l_rc = TRAC_get_buffer_partial(TRAC_get_td("INF"), NULL, &l_buffer_size); + if((l_rc != TRAC_INVALID_PARM) && (l_buffer_size !=0)) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() invalid 2nd parameter\n"); + break; + } + + l_rc = TRAC_get_buffer_partial(TRAC_get_td("ERR"), G_trac_buffer, NULL); + if(l_rc != TRAC_INVALID_PARM) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() invalid 3rd parameter\n"); + break; + } + + // Test target - TRAC_get_buffer_partial() + // case: input buffer less then the size of trace buffer header + l_buffer_size = sizeof(trace_buf_head_t) - 1; + l_rc = TRAC_get_buffer_partial(TRAC_get_td("IMP"), G_trac_buffer, &l_buffer_size); + if(l_rc != TRAC_DATA_SIZE_LESS_THAN_HEADER_SIZE) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() with illegal small input buffer\n"); + break; + } + + // Test target - TRAC_get_buffer_partial() + // case: input buffer is small then then trace buffer + l_buffer_size = sizeof(trace_buf_head_t) + (TRACE_BUFFER_SIZE/4); + l_rc = TRAC_get_buffer_partial(TRAC_get_td("INF"), G_trac_buffer, &l_buffer_size); + if(l_rc) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() with small input buffer\n"); + break; + } + + // Test target - TRAC_get_buffer_partial() + // case: input buffer is larger then trace buffer + l_buffer_size = sizeof(G_trac_buffer); + l_rc = TRAC_get_buffer_partial(TRAC_get_td("INF"), G_trac_buffer, &l_buffer_size); + if(l_rc || (l_buffer_size != TRACE_BUFFER_SIZE)) + { + printf("TRAC_get_buffer_partial(), reason code: %d size %d/%d\n", l_rc, l_buffer_size, TRACE_BUFFER_SIZE); + printf("Fail: test TRAC_get_buffer_partial() with too large input buffer\n"); + break; + } + + // Test target - TRAC_reset_buf() and TRAC_get_buffer_partial() + // case: clear trace buffer and check with buffer larger than trace buffer + TRAC_reset_buf(); + l_buffer_size = sizeof(G_trac_buffer); + l_rc = TRAC_get_buffer_partial(TRAC_get_td("ERR"), G_trac_buffer, &l_buffer_size); + if(l_rc) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_reset_buf()/TRAC_get_buffer_partial() with empty trace\n"); + break; + } + + // Test target - TRAC_reset_buf() and TRAC_get_buffer_partial() + // case: clear trace buffer and check it with buffer smaller than trace buffer + TRAC_reset_buf(); + l_buffer_size = TRACE_BUFFER_SIZE/2; + l_rc = TRAC_get_buffer_partial(TRAC_get_td("ERR"), G_trac_buffer, &l_buffer_size); + if(l_rc) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_reset_buf()/TRAC_get_buffer_partial() with empty trace\n"); + break; + } + + // Test target - TRAC_get_buffer_partial() + // case: create some traces and test with large input buffer + l_entry_count = 0; + do{ + l_entry_count++; + TRAC_INFO("traceTest applet INFO record: count %d", (int)l_entry_count); + TRAC_ERR("traceTest applet ERR record: count %d", (int)l_entry_count); + TRAC_IMP("traceTest applet IMP record: count %d", (int)l_entry_count); + }while((l_max_trace_entries/4) >= l_entry_count); + l_buffer_size = TRACE_BUFFER_SIZE; + l_rc = TRAC_get_buffer_partial(TRAC_get_td("IMP"), G_trac_buffer, &l_buffer_size); + l_head = (tracDesc_t)&G_trac_buffer; + if(l_rc || (l_head->times_wrap != 0)) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() with large input buffer\n"); + break; + } + + // Test target - TRAC_get_buffer_partial() + // case: create some traces and test with small input buffer + l_buffer_size = sizeof(trace_buf_head_t) + (TRACE_BUFFER_SIZE/4); + l_rc = TRAC_get_buffer_partial(TRAC_get_td("INF"), G_trac_buffer, &l_buffer_size); + if(l_rc) + { + printf("TRAC_get_buffer_partial(), reason code: %d\n", l_rc); + printf("Fail: test TRAC_get_buffer_partial() with small input buffer\n"); + break; + } + + }while(0); + + return l_rc; +} + +//************************************************************************* +// Entry point function +//************************************************************************* +errlHndl_t traceTest(void * i_arg) +{ + errlHndl_t l_err = NULL; + UINT l_rc = 0; + + do + { + // function unit test + l_rc = traceFuncTest(); + if(l_rc) + { + printf("traceTest Applet: Function test failed\n"); + break; + } + + // Macro test: test basic trace macros with/without parameters + // Please check occ memory dump with fsp-trace + + // int: supported + TRAC_INFO(para_int_0); + TRAC_INFO(para_int_1, 1); + TRAC_INFO(para_int_5, 1, 2, 3, 4, 5); + TRAC_INFO(para_int_6, 1, 2, 3, 4, 5, 6); + + // hex: supported + TRAC_ERR(para_hex_0); + TRAC_ERR(para_hex_1, 0xA); + TRAC_ERR(para_hex_5, 0xA, 0xB, 0xC, 0xD, 0xE); + TRAC_ERR(para_hex_6, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF); + + // char: not supported + TRAC_IMP(para_int_0); + TRAC_IMP(para_chr_1, "1"); + TRAC_IMP(para_chr_5, "1", "2", "3", "4", "5"); + TRAC_IMP(para_chr_6, "1", "2", "3", "4", "5", "6"); + +#ifdef TEST_SEMAPHORE + // semaphore test + l_rc = traceSemTest(); + if(l_rc) + { + printf("traceTest Applet: Semaphore test failed\n"); + break; + } +#endif + }while(0); + + printf("traceTest Applet: test finish\n"); + return l_err; +} + + +//************************************************************************* +// Image Header +//************************************************************************* +IMAGE_HEADER (G_traceTest,traceTest,TRACETEST_ID,OCC_APLT_TEST); |