⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updown.c

📁 simulink real-time workshop for dragon12 development board from
💻 C
📖 第 1 页 / 共 5 页
字号:
 *         of non NULL entries in a SysUploadTable)
 *
 * nSections - the number of contiguous blockio sections that correspond to
 *             all blocks within a tid (number of sections in a BIOMap)
 *
 * B  - Index into data type transition table       - gives base address
 * S  - the starting index of a blockio section     - with respect to B
 * W  - the number of elements in a blockio section
 * DI - data type index - index into the rtw data type table
 *
 * target buf size - size of the upload buffer (to be allocated by target) for
 *                   a given tid
 *
 * Here's the message format:
 *
 * [nSys
 *
 *  enableIdx                           ---
 *  nTids                                 |
 *  tid nSections B S W DI B S W DI ...   | system
 *  tid nSections B S W DI B S W DI ...   |
 *                                      ---
 *  enableIdx                           ---
 *  nTids                                 |
 *  tid nSections B S W DI B S W DI ...   | system
 *  tid nSections B S W DI B S W DI ...   |
 *                                      ---
 *  target buf size for tid 0
 *  target buf size for tid 1
 *            .
 *            .
 *  target buf size for tid n
 * ]
 *
 * All elements are int32_T.
 */
#if DUMP_MSG
PRIVATE void DumpSelectSignalMsg(const char *msg, int nRootTids)
{
    int32_T    i,j,k;
    int32_T    nSys;
    const char *bufPtr = msg;

    printf("Signal Select Msg-----------\n");

    /* nSys */
    (void)memcpy(&nSys, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);

    printf("\nnSys: %d\n",nSys);

    for (i=0; i<nSys; i++) {
        int32_T enableIdx, nTids;
        
        /* [enableIdx, nTids] */
        (void)memcpy(&enableIdx, bufPtr, sizeof(int32_T));
        bufPtr += sizeof(int32_T);

        (void)memcpy(&nTids, bufPtr, sizeof(int32_T));
        bufPtr += sizeof(int32_T);

        printf("[enableIdx, nTids]: %d %d\n", enableIdx, nTids);

        for (j=0; j<nTids; j++) {
            int32_T tid;
            int32_T nSections;

            /* [tid nSections] */
            (void)memcpy(&tid, bufPtr, sizeof(int32_T));
            bufPtr += sizeof(int32_T);

            (void)memcpy(&nSections, bufPtr, sizeof(int32_T));
            bufPtr += sizeof(int32_T);

            printf("[tid nSects]: %d %d\n", tid, nSections);

            for (k=0; k<nSections; k++) {
                const int B  = 0;
                const int S  = 1;
                const int W  = 2;
                const int DI = 3;
                int32_T   tmpBuf[4];

                /* [B S W DI] */
                (void)memcpy(&tmpBuf, bufPtr, sizeof(int32_T)*4);
                bufPtr += (sizeof(int32_T) * 4);
                
                printf("%d %d %d %d\n",
                    tmpBuf[B], tmpBuf[S], tmpBuf[W], tmpBuf[DI]);
            }
            printf("\n");
        }
        printf("\n");
    }

    /*
     * Now the buffer sizes.
     */
    printf("bufSizes: ");
    for (i=0; i<nRootTids; i++) {
        int32_T bufSize;

        printf("\nbufSize[%d] of %d: ",i, nRootTids);

        (void)memcpy(&bufSize, bufPtr, sizeof(int32_T));
        bufPtr += sizeof(int32_T);

        printf("%d", bufSize);
    }
    printf("\nEnd of select sigs msg----\n");
} /* end DumpSelectSignalMsg */
#else
#define DumpSelectSignalMsg(buf, nRootTids) /* do nothing */
#endif


/* Function ====================================================================
 * Dump the trigger selection message (EXT_SELECT_TRIGGER).  The message looks
 * like:
 *
 * tid       - tid of the trigger signal
 *
 * duration  - The number of base rate steps for which the data logging event
 *             occurs.
 *
 * holdOff   - (-1), signifies that this trigger event is a one_shot, else we 
 *             are in normal mode.  For normal mode the the value indicates
 *             the number of base rate steps to wait between the end a data
 *             logging event and the re-arming of the trigger for the next data
 *             logging event.  The end of a data logging event is defined as
 *             when the last bit of data has been sent to the host (i.e.,
 *             immediately after the termination flag has been sent).
 *
 * delay     - The number of base rate steps to wait after the trigger event
 *             occurs and the before starting the data collection.  This can
 *             be either positive or negative (pre-trigger).  This field is
 *             ignored if the trigger source is manual.
 *
 * nsections - The sections of the blockio array to monitor for a trigger event.
 *             If the trigger event is not based on a signal, this is set to
 *             0 (e.g., the signal source is manual).
 *
 * sections  - "B, S, W, DI" description of a signal (see Signal Selection Msg).
 *             These are the elements of the blockio vector that are monitored
 *             for trigger events when the trigger is based on a signal.  It is
 *             ignored if the trigger event is not based on a signal
 *             (nsections == 0).
 *
 * direction - If the triggering source is a signal, then this specifies the
 *             direction of the crossing (rising, falling or either).  If we
 *             are not triggering on a signal (nsections == 0), then this field
 *             is ignored.
 *
 * level     - If the triggering source is a signal, then this field specifies
 *             the level (value) of the crossing (0 by default).  If we are not
 *             triggering on a signal (nsections == 0), then this field is
 *             ignored.
 *
 * The message looks like:
 * [tid duration holdOff delay nsections B S W DI B S W DI ... direction level]
 *
 * All fields are int32_T except for level, which is an SL_DOUBLE (real_T
 * on target).
 */
#if DUMP_MSG
PRIVATE void DumpSelectTriggerMsg(const char *msg)
{
    int32_T    i;
    int32_T    tid, duration, holdOff, delay, nSections;
    int32_T    direction;
    real_T     level;
    const char *bufPtr = msg;

    printf("Trigger Select Msg-----------\n");

    /* tid */
    (void)memcpy(&tid, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);

    printf("\ntid: %d\n",tid);
    
    /* duration */
    (void)memcpy(&duration, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);

    printf("\nduration: %d\n",duration);

    /* holdOff */
    (void)memcpy(&holdOff, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);

    printf("\nholdOff: %d\n",holdOff);

    /* delay */
    (void)memcpy(&delay, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);

    printf("\ndelay: %d\n",delay);

    /* nsections */
    (void)memcpy(&nSections, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);

    printf("nSects: %d\n", nSections);

    /* each section */
    for (i=0; i<nSections; i++) {
        const int B  = 0;
        const int S  = 1;
        const int W  = 2;
        const int DI = 3;
        int32_T   tmpBuf[4];

        (void)memcpy(&tmpBuf, bufPtr, sizeof(int32_T)*4);
        bufPtr += (sizeof(int32_T) * 4);
        
        printf("%d %d %d %d\n", tmpBuf[B], tmpBuf[S], tmpBuf[W], tmpBuf[DI]);
    }
    printf("\n");

    /* direction */
    (void)memcpy(&direction, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);

    printf("direction: %d\n",direction);

    /* level */
    (void)memcpy(&level, bufPtr, sizeof(real_T));
    bufPtr += sizeof(real_T);

    printf("level: %f\n",level);
} /* end DumpSelectTriggerMsg */
#else
#define DumpSelectTriggerMsg(buf) /* do nothing */
#endif


/* Function ====================================================================
 * Initialize a BIOSection.
 */
PRIVATE void InitBioSection(
    RTWExtModeInfo  *ei,
    const int32_T   *buf,
    BIOSection      *section)   /* out */
{
    int_T                         elSize;
    int_T                         offset;
    int_T                         nBytes;
    char_T                        *tranAddress;
    int_T                         tranIsComplex;
    
    const DataTypeTransInfo *dtInfo = rteiGetModelMappingInfo(ei);
    const DataTypeTransitionTable *dtTable = dtGetBIODataTypeTrans(dtInfo);
    const uint_T *dtSizes = dtGetDataTypeSizes(dtInfo);

    const int BI = 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                 */

    tranAddress   = dtTransGetAddress(dtTable, buf[BI]);
    tranIsComplex = dtTransGetComplexFlag(dtTable, buf[BI]);

    elSize = dtSizes[buf[DI]] * (tranIsComplex ? 2 : 1);
    nBytes = (uint_T)buf[W] * elSize;
    offset = (uint_T)buf[SI] * elSize;

    section->start  = tranAddress + offset;
    section->nBytes = nBytes;
} /* end InitBioSection */


/* Function ====================================================================
 * Initialize a SysUploadTable.  The callerBufPtr points to the current place in
 * the EXT_SELECT_SIGNALS msg which should be the enableIdx field.  This
 * function moves the callerBufPtr to the next unread field of the message.
 */
PRIVATE boolean_T InitSysUploadTable(
    RTWExtModeInfo  *ei,
    SysUploadTable  *sysTable,
    const char      **callerBufPtr) /* in/out */
{
    int_T        i;
    int_T        nTids;
    const char_T *bufPtr = *callerBufPtr;
    boolean_T    error   = EXT_NO_ERROR;

    /*
     * Set pointer to enable mode.
     */
    {
        int32_T sysIdx;

        /* read sysIdx */
        (void)memcpy(&sysIdx, bufPtr, sizeof(int32_T));
        bufPtr += sizeof(int32_T);

        sysTable->enableState = rteiGetAddrOfSubSystemModeVector(ei,sysIdx);
    }

    /*
     * Allocate/initialize each tid's bioMap.
     */

    /* ...read [nTids] */
    (void)memcpy(&nTids, bufPtr, sizeof(int32_T));
    bufPtr += sizeof(int32_T);
    
    for (i=0; i<nTids; i++) {
        int32_T  tid;
        int32_T  section;
        BIOMap   *map;
        
        /* read tid */
        (void)memcpy(&tid, bufPtr, sizeof(int32_T));
        bufPtr += sizeof(int32_T);
        
        /* allocate BIOMap */
        assert(sysTable->bioMap[tid] == NULL);
        sysTable->bioMap[tid] = (BIOMap *)calloc(1, sizeof(BIOMap));
        if (sysTable->bioMap[tid] == NULL) {
            abort_LED(10); error = EXT_ERROR; goto EXIT_POINT;       
        }
        map = sysTable->bioMap[tid];
        
        /* read nSections */
        (void)memcpy(&map->nSections, bufPtr, sizeof(int32_T));
        bufPtr += sizeof(int32_T);

        /* Allocate the blockio sections. */
        assert(map->sections == NULL);
        map->sections = (BIOSection *)calloc((uint16_T)map->nSections,sizeof(BIOSection));
        if (map->sections == NULL) {
            abort_LED(11); error = EXT_ERROR; goto EXIT_POINT;
        }

        /*
         * Init the BIOSections.
         */
        for (section=0; section<map->nSections; section++) {
            int32_T    tmpBuf[4];
            BIOSection *bioSection = &map->sections[section];

            /* read [B S W DI] */
            (void)memcpy(&tmpBuf, bufPtr, sizeof(int32_T)*4);
            bufPtr += (sizeof(int32_T) * 4);

            InitBioSection(ei, tmpBuf, bioSection);

            /* keep track of total number of bytes in this map */
            map->nBytes += bioSection->nBytes;
        }
    }
    
EXIT_POINT:
    *callerBufPtr = bufPtr;
    return(error);
} /* end InitSysUploadTable */


/* Function ====================================================================
 * Initialize circular buffer fields and allocate required memory.
 */
PRIVATE boolean_T UploadBufInit(CircularBuf *circBuf, int_T size)
{
    boolean_T error = NO_ERR;
    
    assert(circBuf->buf == NULL);

    circBuf->empty = TRUE;
    if (size > 0) {
        assert(circBuf->buf == NULL);
        circBuf->buf = (char_T *)malloc((uint16_T)size);
        if (circBuf->buf == NULL) {
            abort_LED(12); error = EXT_ERROR; goto EXIT_POINT;
        }
    } else {
        circBuf->buf = NULL;
    }
    circBuf->bufSize = size;
    
    circBuf->head = circBuf->buf;
    circBuf->tail = circBuf->buf;

    circBuf->newTail = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -