📄 updown.c
字号:
/* $Revision: 1.1.6.11.4.1 $
* Copyright 1994-2006 The MathWorks, Inc.
*/
/*
* Adapted for rtmc9s12-Target, fw-09-7
*/
#include <stdlib.h>
#include <string.h>
/*Real Time Workshop headers*/
#include "tmwtypes.h"
#include "simstruc_types.h"
#include "ext_types.h"
#include "ext_share.h"
#include "ext_svr.h"
#include "ext_work.h"
#include "updown_util.h"
#include "dt_info.h"
#include <stdio.h>
/**********************
* External Variables *
**********************/
#ifdef VXWORKS
# include <sockLib.h>
# include <inetLib.h>
# include <selectLib.h>
extern SEM_ID uploadSem;
#endif
#include "cpp_req_defines.h" /* CIRCBUFSIZE */
#include "mc_signal.h" /* abort_LED, SCIx_Init, etc. */
#include "debugMsgs.h" /* macros PRINT_DEBUG_MSG_LVL2 to PRINT_DEBUG_MSG_LVL5, fw-06-07 */
#ifdef LCDUSE4ERRORS
#include "lcd.h" /* writeLine() */
#endif
#if DISP_CIRCBUF_FREE == 1
/* Microcontroller specific and system headers */
#if MC9S12_TYPE == DP256
#include <mc9s12dp256.h> /* port definitions etc. */
#elif MC9S12_TYPE == C128
#include <mc9s12c128.h> /* port definitions etc. */
#elif MC9S12_TYPE == C32
#include <mc9s12c32.h> /* port definitions etc. */
#endif
#endif
#ifdef HOSTALIVECHECK
/* stop buffering data when the target buffer is full and the host seems busy */
extern boolean_T HostIsAlive; /* defined in mc_main.c */
#endif
#if DEBUG_MSG_LVL > 0
#include "ext_serial_port.h" /* ExtSerialPortPeekRB */
/* define a local copy of the data type name table (see MODEL_dt.h) */
static const char_T *myrtDataTypeNames[]= {
"real_T",
"real32_T",
"int8_T",
"uint8_T",
"int16_T",
"uint16_T",
"int32_T",
"uint32_T",
"boolean_T",
"fcn_call_T",
"int_T",
"pointer_T",
"action_T",
"timer_uint32_pair_T"
};
static const char *debugTriggerStrings[6]= {
"TRIGGER_UNARMED",
"TRIGGER_HOLDING_OFF",
"TRIGGER_ARMED",
"TRIGGER_DELAYED",
"TRIGGER_FIRED",
"TRIGGER_TERMINATING"
};
#endif
/******************************************************************************
* Parameter Download *
******************************************************************************/
/* make sure... fw-04-05 */
#undef VERBOSE
#ifdef VERBOSE
/* Function: DType2Real_T ======================================================
* Convert a built-in data type to a real_T value. Return the real_T value
* as well as a string (by reference) corresponding to the original data type.
* If the data type is not recognized as a Simulink built-in data type, then
* NULL is returned forthe dTypeName and 0 is returned for the dTypeValue.
*/
PRIVATE double DType2Double(const char *vPtr, const int dTypeIdx, const DataTypeTransInfo *dtInfo, const char **dTypeName) {
real_T outVal;
char * const *dTypeNames=(char * const*)dtGetDataTypeNames(dtInfo);
const char *thisName=dTypeNames[dTypeIdx];
*dTypeName=thisName;
if(strcmp(thisName, "real_T")==0) {
outVal=(real_T)(((const real_T*)vPtr)[0]);
}
else if(strcmp(thisName, "real32_T")==0) {
outVal=(real_T)(((const real32_T*)vPtr)[0]);
}
else if(strcmp(thisName, "int8_T")==0) {
outVal=(real_T)(((const int8_T*)vPtr)[0]);
}
else if(strcmp(thisName, "uint8_T")==0) {
outVal=(real_T)(((const uint8_T*)vPtr)[0]);
}
else if(strcmp(thisName, "int16_T")==0) {
outVal=(real_T)(((const int16_T*)vPtr)[0]);
}
else if(strcmp(thisName, "uint16_T")==0) {
outVal=(real_T)(((const uint16_T*)vPtr)[0]);
}
else if(strcmp(thisName, "int32_T")==0) {
outVal=(real_T)(((const int32_T*)vPtr)[0]);
}
else if(strcmp(thisName, "uint32_T")==0) {
outVal=(real_T)(((const uint32_T*)vPtr)[0]);
}
else if(strcmp(thisName, "boolean_T")==0) {
outVal=(real_T)(((const boolean_T*)vPtr)[0]);
}
else {
outVal=0;
dTypeName=NULL;
}
return(outVal);
} /* end DType2Double */
#endif
/* Function: SetParam ==========================================================
* Install new parameters.
*
* NOTE: pbuf looks like:
* [NPARAMS
* B S W DI DATA % pVal 0
* B S W DI DATA % pVal 1
* B S W DI DATA % pVal N
* ]
*
* No assumptions about the aligment of pbuf may be made.
*
* where,
* B : Data type transition index. Note that on the target the data
* type transition index provides both the base address (B)
* of the transition as well as whether or not
* that section of the array contains complex elements.
* S : starting offset of the data from the DT_TRANS_IDX
* W : number of elements for this param
* DI : index into rtw data type table (inUse idx)
* DATA: the param values (in target format).
*
* and,
* All values, excluding DATA, are int32_T.
*/
PUBLIC void SetParam(RTWExtModeInfo *ei, const char *pbuf) {
int i;
int32_T nParams;
const char *bufPtr=pbuf;
const int B=0; /* index into dtype tran table (base address) */
const int SI=1; /* starting index - wrt to base address */
const int W=2; /* width of section (number of elements) */
const int DI=3; /* index into data type tables */
const int tmpBufSize=sizeof(int32_T)*4;
int32_T tmpBuf[4];
const DataTypeTransInfo *dtInfo=rteiGetModelMappingInfo(ei);
const DataTypeTransitionTable *dtTable=dtGetParamDataTypeTrans(dtInfo);
const uint_T *dtSizes=dtGetDataTypeSizes(dtInfo);
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="SetParam";
#endif
PRINT_DEBUG_MSG_LVL3("IN\n\r");
/* unpack NPARAMS */
(void)memcpy(&nParams, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_LVL3("Expected number of parameters: ");
PRINT_DEBUG_MSG_LVL3_UDec((uint16_T)nParams);
PRINT_DEBUG_MSG_NL3;
/*
* Unpack the data and install the new parameters.
*/
for(i=0; i<nParams; i++) {
int_T elSize;
int_T nBytes;
char_T *start;
char_T *tranAddress;
int_T tranIsComplex;
PRINT_DEBUG_MSG_LVL3("Unpacking parameter number: ");
PRINT_DEBUG_MSG_LVL3_UDec(i+1);
PRINT_DEBUG_MSG_NL3;
/* unpack B SI W DI */
(void)memcpy(tmpBuf, bufPtr, tmpBufSize);
bufPtr+=tmpBufSize;
/* Display style:
*
* Data Type Trans: 0
* Start index : 6
* nEls: : 1
* Data Type : [double, 0]
* Values : 0.99995000041666526, ...
*/
PRINT_DEBUG_MSG_LVL3("Data Type Transition: ");
PRINT_DEBUG_MSG_LVL3_UDec((uint16_T)tmpBuf[B]);
PRINT_DEBUG_MSG_NL3;
PRINT_DEBUG_MSG_LVL3("Start Index : ");
PRINT_DEBUG_MSG_LVL3_UDec((uint16_T)tmpBuf[SI]);
PRINT_DEBUG_MSG_NL3;
PRINT_DEBUG_MSG_LVL3("nEls : ");
PRINT_DEBUG_MSG_LVL3_UDec((uint16_T)tmpBuf[W]);
PRINT_DEBUG_MSG_NL3;
PRINT_DEBUG_MSG_LVL3("Data Type : [ ");
PRINT_DEBUG_MSG_LVL3_Raw((const char_T*)myrtDataTypeNames[tmpBuf[DI]]);
PRINT_DEBUG_MSG_LVL3_Raw(", ");
PRINT_DEBUG_MSG_LVL3_UDec((uint16_T)tmpBuf[DI]);
PRINT_DEBUG_MSG_LVL3_Raw("]\n\r");
/*
* Find starting address and size (nBytes) for this parameters
* section of memory.
*/
tranAddress=dtTransGetAddress(dtTable, tmpBuf[B]);
tranIsComplex=dtTransGetComplexFlag(dtTable, tmpBuf[B]);
elSize=dtSizes[tmpBuf[DI]]*(tranIsComplex?2:1);
nBytes=(int_T)(tmpBuf[W]*elSize);
start=tranAddress+(tmpBuf[SI]*elSize);
#if DEBUG_MSG_LVL >= 3
PRINT_DEBUG_MSG_LVL3("Values :");
{
int i;
for(i=0; i<nBytes; i++) {
PRINT_DEBUG_MSG_LVL3_Raw(" 0x");
PRINT_DEBUG_MSG_LVL3_UHex((uint16_T)bufPtr[i]);
}
PRINT_DEBUG_MSG_NL3;
PRINT_DEBUG_MSG_NL3;
}
#endif
/* Install the params. */
(void)memcpy(start, bufPtr, nBytes);
bufPtr+=nBytes;
#ifdef VERBOSE
/*
* It is safe to assume that once the params are installed into
* the param vector that they are properly aligned. So we
* do our verbosity print-out here.
*/
{
double val;
const char *dTypeName;
const char *vPtr=(const char *)start;
val=DType2Double(start, tmpBuf[DI], dtInfo, &dTypeName);
printf("\n\tParam| "
"DT_Trans: %d, index: %d, nEls: %d, data type: [%s, %d]\n", tmpBuf[B], tmpBuf[SI], tmpBuf[W], (dTypeName!=NULL)?dTypeName:"", tmpBuf[DI]);
if(!tranIsComplex) {
int j;
for(j=0; j<tmpBuf[W]; j++) {
val=DType2Double(vPtr, tmpBuf[DI], dtInfo, &dTypeName);
printf("\t\t%f\n", val);
vPtr+=dtSizes[tmpBuf[DI]];
}
}
else {
int j;
for(j=0; j<tmpBuf[W]; j++) {
val=DType2Double(vPtr, tmpBuf[DI], dtInfo, &dTypeName);
printf("\t\t%f + ", val);
vPtr+=dtSizes[tmpBuf[DI]];
val=DType2Double(vPtr, tmpBuf[DI], dtInfo, &dTypeName);
printf("\t\t%fi\n", val);
vPtr+=dtSizes[tmpBuf[DI]];
}
}
}
#endif
}
PRINT_DEBUG_MSG_LVL3("OUT\n\r");
} /* end SetParam */
/******************************************************************************
* Parameter Upload *
******************************************************************************/
#include "upsup_public.h"
#define DUMP_PKT (1)
/*=============================================================================
* Circular buffer stuff.
*============================================================================*/
typedef struct BufMemList_tag {
#if ASSERTS_ON
int_T maxBufs; /* for debugging */
#endif
int_T nActiveBufs; /* num non-empty bufs */
int_T *tids; /* tid associated with each active buf */
BufMem *bufs; /* sections of each buffer to upload */
} BufMemList;
typedef struct CircularBuf_tag {
int_T empty;
#ifdef HOSTALIVECHECK
int_T full; /* fw-07-07 */
#endif
int_T bufSize;
char_T *buf;
char_T *head;
char_T *tail;
char_T *newTail;
struct {
int_T count;
} preTrig;
} CircularBuf;
/*==============================================================================
* Trigger stuff.
*============================================================================*/
typedef enum { TRIGGER_UNARMED,
TRIGGER_HOLDING_OFF,
TRIGGER_ARMED,
TRIGGER_DELAYED,
TRIGGER_FIRED,
TRIGGER_TERMINATING } TriggerState;
/*==============================================================================
* General stuff.
*============================================================================*/
/*
* An UploadSection defines a contiguous section of the blockio or dwork
* structure. Each section consists of elements of the same data type and same
* complexity.
* xxx 'start' should be a const pointer
*/
typedef struct UploadSection_tag {
void *start;
int_T nBytes;
} UploadSection;
/*
* An UploadMap is an array of UploadSections. Typically a map consists of all
* of the sections of the blockio or dwork structure that are relevent to a
* given task.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -