/** Sample ALOE component implementation file */ /** Include SW API header and SW API utils (skeleton) */ #include #include /** Include general data type library */ #include "typetools.h" /** include input/output interfaces and stats. * itf_types.h must be included 'before' input.h if it defines e.g. control * interface packet structure */ #include "itf_types.h" #include "skeletonExtendedInputs.h" #include "skeletonExtendedOutputs.h" #include "stats.h" #include "my_prog.h" /*GLOBAL DEFINITIONS*/ #define BITSPERCHAR 8 #define ERROR -1 #define READY 1 #define NONREADY 0 /*GLOBAL VARIABLES & BUFFERS*/ int configured=0; int dataprocessedready=NONREADY; int input_temp[INPUT_MAX_DATA*8],output_temp[OUTPUT_MAX_DATA*8]; char pinput[INPUT_MAX_DATA*8], poutput[INPUT_MAX_DATA*8]; /* PREDEFINED FUNCTIONS*/ void print_array(char *Pin, int Dtype, int Dlength, int Dcolums, \ int print, int numTS, int printingTS, int nprintTS); int datainflow_bypass(int len,int numTS,int print,\ int numcols,int dattype, int outdattype); void check_config(); /*----------------------- SQUELETON CALLED FUNCTIONS ------------------------*/ /** INPUT INTERFACE 1: CONTROL //////////////////////////////////////////CONTROL * controlin_length() Returns the maximum length (in control type words) of the * expected control flow at each time-slot * Funtion activated if control flow has been received */ int controlin_length() { int length=INPUT_MAX_CONTROL; return(length); } /** Process the received control flow according to the length returned by * get_controlin_length() "len" indicates the number of control words to be * processed * This is the processing function for the control interface. Here, we simply * have to validate the parameters and update our internal state variables. */ int process_inputcontrol(int len) { if(len<=0)return(1); configured=1; //CAPTURE MODULE CONFIG //memcpy(&ctrl,&ctrlpkt,sizeof(ControlMODULENAME_h)); memcpy(&ctrl,&ctrlpkt,sizeof(ctrl)); //PRINT CONFIG VALUES xprintf("%s: O---->%s (config): CONFIG BY CONTROL ITF\n",GetObjectName()); xprintf("O---->%s (config): TSLOT%d, STATUS=%d\n",GetObjectName(),\ ctrl.time_slot,\ ctrl.status); xprintf("O NumInputdata=%d, NumOutputdata=%d\n",\ ctrl.inputdatalength,\ ctrl.outputdatalength); xprintf("O transporttypeIN=%d, transporttypeOUT=%d\n",\ ctrl.transporttypeIN,\ ctrl.transporttypeOUT); xprintf("O-----------------------------------------0\n"); if(ctrl.inputdatalength>INPUT_MAX_DATA) { printf("ERROR: %s.PROCESS_INPUTCONTROL(): \n",GetObjectName()); printf("ERROR: ctrl.inputdatalength=%d>INPUT_MAX_DATA=%d\n",\ ctrl.inputdatalength, INPUT_MAX_DATA); return(0); } /*return 1 if OK; return 0 if error*/ return(1); } /** END INPUT INTERFACE 1: CONTROL /////////////////////////////////////CONTROL /** INPUT INTERFACE 2: DATA ///////////////////////////////////////////////DATA * datain_length() Returns the maximum length (in data type words) of the * expected data flow at each time-slot * Funtion activated if data flow has been received */ int datain_length() { int length=0; length=typeSizeArray(ctrl.transporttypeIN, ctrl.inputdatalength); if(length > INPUT_MAX_DATA){ printf("%s.datain_length(): ERROR length too long\n",GetObjectName()); printf("length=%d INPUT_MAX_DATA=%d\n", ctrl.inputdatalength, INPUT_MAX_DATA); } dataprocessedready=NONREADY; return(length); } /** Process the received data flow according to the length returned by * datain_length(). Run function. return 1 if ok, 0 if error. * "len" indicates the number of data bytes (input buffer defined as char) * to be processed * This is the main processing function. It will be called every time * data is available for process. Here you will place your signal processing * code. */ int process_inputdata(int lengthbytes) { int i, lengthdata; // printf("%s.PROCESS_INPUTDATA(): lengthbytes=%d,ctrl.time_slot=%d \n",GetObjectName(),lengthbytes, ctrl.time_slot); /*Check if configured*/ if (!configured)return(1); /*CHECK DATA INPUT LENGTH*/ /** In general, we want to make sure we have received the expected * amount of data. * The function typeSizeArray() returns the expected bytes as a function * of a general datatype and expected number of elements. For example, if * blockLength=128 and datatype is INTEGER, it returns 128*4=512. * If for example the datatype is BITSTREAM the function will * return 128/8=16 */ if (lengthbytesctrl.time_slot)){ printf("%s.PROCESS_INPUTDATA(): INPUT\n",GetObjectName()); printf("%s.PROCESS_INPUTDATA(): lengthbytes=%d,dataINPUTlength=%d \n",GetObjectName(),\ lengthbytes, ctrl.inputdatalength); } if(ctrl.transporttypeIN == TYPE_BITSTREAM)lengthdata=lengthbytes*BITSPERCHAR; else lengthdata=lengthbytes/typeSize(ctrl.transporttypeIN); print_array(input_data, ctrl.transporttypeIN,\ lengthdata, NUMCOLS, printting, ctrl.time_slot,\ numTS2print, NUM_TS_PRINTS); /**CONVERT TYPE RECEIVED TO TYPE TO BE PROCESSED*/ lengthdata=type2type(input_data, pinput,\ ctrl.transporttypeIN, PROCESSINGTYPEIN, lengthdata, 1.0); if(lengthdata==ERROR){ printf("ERROR: %s.PROCESS_INPUTDATA(): INPUT DATA CONVERSION\n",GetObjectName()); return(0); } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// /** YOUR PROCESSING FUNCTION*/ ctrl.outputdatalength=my_prog(pinput, poutput,\ PROCESSINGTYPEIN, PROCESSINGTYPEOUT,lengthdata, ctrl); if(ctrl.outputdatalength==ERROR)return(0); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// /**CONVERT TYPE PROCESSED TO TYPE TO BE SENT*/ lengthdata=type2type(poutput, output_data,\ PROCESSINGTYPEOUT, ctrl.transporttypeOUT,\ ctrl.outputdatalength, 1.0); if(lengthdata==ERROR){ printf("ERROR: %s.PROCESS_INPUTDATA(): OUTPUT DATA CONVERSION\n",GetObjectName()); return(0); } /** PRINT OUTPUT IN CASE*/ if(printting==PRINT) if((NUM_TS<=ctrl.time_slot)&&((NUM_TS+NUM_TS_PRINTS)>ctrl.time_slot)) printf("%s.PROCESS_INPUTDATA(): OUTPUT lengthdata=%d,ctrl.outputdatalength=%d \n",GetObjectName(),\ lengthdata, ctrl.outputdatalength); print_array(output_data, ctrl.transporttypeOUT, lengthdata,\ NUMCOLS, printting, ctrl.time_slot, numTS2print, NUM_TS_PRINTS); /**CALCULATE THE NUMBER OF BYTES TO BE SENT*/ ctrl.outputdatalength=typeSizeArray(ctrl.transporttypeOUT,lengthdata); if(printting==PRINT)if(ctrl.time_slot==numTS2print) printf("%s. PROCESS_INPUT_DATA(): ctrl.outputdatalength=%d \n",GetObjectName(),ctrl.outputdatalength); dataprocessedready=READY; } /** The skeleton will read from the output_data buffer the required * amount of bytes (depending of the data type) that must be sended. */ /* We return 1 to indicate the processing finished correctly. If we return * 0 we will force the module to stop. */ return 1; } /** OUTPUT INTERFACE 2: DATA //////////////////////////////////////////////DATA /** get_output_length() function returns the amount of data typewords the * skeleton will send through the output interface (after all input functions * finished). * Note that again we are using the typetools library to convert from the * desired processing data types to transport data types */ int get_output_length() { if(dataprocessedready==READY){ dataprocessedready=NONREADY; return(ctrl.outputdatalength); } if(dataprocessedready==NONREADY)return(0); } /*Generate the data words to be send according the length provided by get_dataout_length()*/ /** Run function. return 1 if ok, 0 if error*/ /*"len" indicates the number of data words to be generated*/ /** Our output process function does nothing. It can be used to make sure * we have processed all data, or to generate data if there are not inputs */ int generate_outputdata(int len) { return 1; } /** This function is called after all interface processing functions have been * called. You can place other state-update code here. */ int RunCustom() { ctrl.time_slot++; //check_config(); return 1; } /** This function is called after all interfaces have been initialized. * You can place other custom initialization code here. */ int InitCustom() { check_config(); init_my_prog(); return 1; } /** This function is called after initializing parameters and before * creating interfaces. It is useful when the number of interfaces or buffers * is a function of an initialization parameter. */ void ConfigInterfaces() { } /*----------------------- SQUELETON CALLED FUNCTIONS END -------------------*/ /** Perfom a bypass input output without any data modification * Parameters * int len Data lenght (number of received bytes) * int numTS Time slot when print * int print print (1) or no print (0) * int numcols Number of printing columns * int indattype Intput Data type to print * int outdattype Output Data type to print */ int datainflow_bypass(int len,int numTS,int print,int numcols,\ int indattype, int outdattype) { int i, lengthprint; /** Print output in case*/ if(indattype == TYPE_BITSTREAM)lengthprint=len*BITSPERCHAR; else lengthprint=len/typeSize(indattype); if(print==printting)if(ctrl.time_slot==numTS)printf("%s BYPASS INPUTDATA\n",GetObjectName()); print_array(input_data, indattype, lengthprint, numcols, print, ctrl.time_slot, numTS, 1); /**BYPASS DATA TYPE RECEIVED TO DATA TYPE TO BE SEND*/ len=type2type(input_data, output_data,\ ctrl.transporttypeIN, ctrl.transporttypeOUT, len, 1.0); /** Print output in case*/ if(outdattype == TYPE_BITSTREAM)lengthprint=len*BITSPERCHAR; else lengthprint=len/typeSize(outdattype); if(print==printting)if(ctrl.time_slot==numTS)printf("%s BYPASS OUTPUTDATA\n",GetObjectName()); print_array(output_data, outdattype, lengthprint, numcols, print, ctrl.time_slot, numTS, 1); /**CALCULATE THE NUMBER OF DATA TO BE SENT*/ if(outdattype == TYPE_BITSTREAM)len=len*BITSPERCHAR; ctrl.outputdatalength=typeSizeArray(outdattype,len); if(print==printting)if(ctrl.time_slot==numTS) printf("%s BYPASS dataOUTPUTlength=%d\n", GetObjectName(),ctrl.outputdatalength); return(1); } /** Checks the current module status and capture the configuration defined at * stats.h */ void check_config() { if(configSTATS==FALSE)return; configSTATS=FALSE; configured=1; /*PRINT CONFIG VALUE*/ xprintf("O---->%s (config): CONFIG BY STATS.h\n",GetObjectName()); if(ctrl.status==NONACTIVE) xprintf("O---->%s (config): STATUS=NONACTIVE\n",GetObjectName()); if(ctrl.status==ACTIVE){ xprintf("O---->%s (config): TSLOT%d, STATUS=ACTIVE\n",GetObjectName(),\ ctrl.time_slot); } if(ctrl.status==TEST_FLOW){ xprintf("O---->%s (config): TSLOT%d, STATUS=TEST_FLOW\n",GetObjectName(),\ ctrl.time_slot); } if(ctrl.status==TEST_PROCESS){ ctrl.transporttypeOUT=0; xprintf("O---->%s (config): TSLOT%d, STATUS=TEST_PROCESS\n",GetObjectName(),\ ctrl.time_slot); } xprintf("O NumInputdata=%d, NumOutputdata=%d\n",\ ctrl.inputdatalength,\ ctrl.outputdatalength); xprintf("O datatypeIN=%d, datatypeOUT=%d\n",\ ctrl.transporttypeIN,ctrl.transporttypeOUT); xprintf("O---------------------------------------"); xprintf("----------------------------------------0\n"); } /** print_array(): Prints an array according their type at selected Time-Slot * and between Time-Slot printingTS and Time-Slot printingTS+nprintTS. * print parameter allow to desactivate printing. * * char *Pin :Input data pointers * int Dtype :Data type * int Dlength :Number of data * int Dcolums :Printed columns * int print :Print command * int numTS :number of Time-slot * int printingTS :Initial Printing Time-slot * int nprintTS :Number of printing Time-slots */ void print_array(char *Pin, int Dtype, int Dlength, int Dcolums, \ int print, int numTS, int printingTS, int nprintTS) { int i; float *input_f; char *input_c; int *input_i; short *input_s; if(Dtype==TYPE_BITSTREAM)input_c=(unsigned char *)Pin; if(Dtype==TYPE_BIT8)input_c=(unsigned char *)Pin; if(Dtype==TYPE_CHAR)input_c=(unsigned char *)Pin; if(Dtype==TYPE_SHORT)input_s=(short *)Pin; if(Dtype==TYPE_INT)input_i=(int *)Pin; if(Dtype==TYPE_FLOAT)input_f=(float *)Pin; if(print!=PRINT)return; if((printingTS<=numTS)&&((printingTS+nprintTS)>numTS)){ if(Dtype==TYPE_BITSTREAM)Dlength=Dlength/8; printf("000) "); for(i=1; i<=Dlength; i++){ if(Dtype==TYPE_BITSTREAM)printf("%03d ", (unsigned char) *(input_c+i-1)); if(Dtype==TYPE_BIT8)printf("%03d ", (unsigned char )input_c[i-1]); if(Dtype==TYPE_CHAR)printf("%03d ", (unsigned char)input_c[i-1]); if(Dtype==TYPE_SHORT)printf("%d ", (short )input_s[i-1]); if(Dtype==TYPE_INT)printf("%d ", (int)input_i[i-1]); if(Dtype==TYPE_FLOAT)printf("%4.2f ", (float)input_f[i-1]); if(i