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

📄 os_view.c

📁 keil 下的ucOS移植程序。移植平台AT91SAM7S64.
💻 C
📖 第 1 页 / 共 3 页
字号:
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                        STORE DATA IN Rx BUFFER
*
* Description: This routine is called whenever a valid byte has been received.
*********************************************************************************************************
*/

static  void  OSView_RxStoINT8U (INT8U data)
{
    if (OSView_RxBufCnt < OS_VIEW_RX_BUF_SIZE) {
        OSView_RxBuf[OSView_RxBufCnt++] = data;
    }
}


/*
*********************************************************************************************************
*                                           CLEAR Rx BUFFER
*********************************************************************************************************
*/

static  void  OSView_RxBufClr (void)
{
    OSView_RxBufCnt = 0;
    OSView_RxRdIx   = 0;
}

/*
*********************************************************************************************************
*                                     GET 8, 16 or 32-bit DATA
*********************************************************************************************************
*/

static  INT8U  OSView_RxGetINT8U (void)
{
    return (OSView_RxBuf[OSView_RxRdIx++]);
}


static  INT16U  OSView_RxGetINT16U (void)
{
    INT16U  lowbyte;
    INT16U  highbyte;


    highbyte = OSView_RxGetINT8U();
    lowbyte  = OSView_RxGetINT8U();
    return ((highbyte << 8) | lowbyte);
}


static  INT32U  OSView_RxGetINT32U (void)
{
    INT32U  highword;
    INT32U  lowword;


    highword = OSView_RxGetINT16U();
    lowword  = OSView_RxGetINT16U();
    return ((highword << 16) | lowword);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                  START TRANSMISSION OF REPLY PACKET
*********************************************************************************************************
*/

void  OSView_TerminalRxSetCallback (void (*call_back)(INT8U data))
{
    OSView_TerminalRxCallbackFnct = call_back;
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                 SEND AN ASCII STRING TO TERMINAL WINDOW
*
* Description: This function allows an application to send strings to the TERMINAL window in the viewer.
*
* Arguments  : s     is a pointer to the string to send.
*
*              dly   allows the calling task to delay itself for 'dly' ticks until the current string
*                    is sent.  If 'dly' is set to 0, then the string will not be sent if a string is 
*                    currently in the process of being sent.  In other words, if there is a string currently
*                    being sent and you sent 'dly' to 0, OSView_TxStr() will return to the caller and the
*                    string will not be sent.
*
* Note(s)    : 1) This function MUST be called from a TASK and NOT an ISR.
*********************************************************************************************************
*/

void  OSView_TxStr (char *s, INT16U dly)
{
    INT16U  len;


    len = (INT16U)strlen(s);                          /* Make sure string fits in buffer               */
    if (len >= OS_VIEW_TX_STR_SIZE) {                 /* Force end of string if string too long        */
        len    = OS_VIEW_TX_STR_SIZE - 1;
        s[len] = '\0';
    }
    if (OSView_TxStrLen > 0) {                        /* Are currently busy sending a string?          */
        if (dly > 0) {                                /* Yes, does caller want to wait?                */
            while (OSView_TxStrLen > 0) {             /* Yes, let other tasks run                      */
                OSView_TxStrDlyCtr++;
                OSTimeDly(dly);
            }
            OSView_TxStrLen = len;                    /* Update the string length                      */
            strcpy((char *)&OSView_TxStrBuf[0], s);   /* Copy string to send to buffer                 */
            if (OSView_TxStrLen > 0) {
                OSView_TxStart();
            }
        }
    } else {
        OSView_TxStrLen = len;                        /* Update the string length                      */
        strcpy((char *)&OSView_TxStrBuf[0], s);       /* Copy string to send to buffer                 */
        if (OSView_TxStrLen > 0) {
            OSView_TxStart();
        }
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                  START TRANSMISSION OF REPLY PACKET
*********************************************************************************************************
*/

static  void  OSView_TxStart (void)
{
    OS_ENTER_CRITICAL();
    if (OSView_TxActiveFlag == FALSE) {
        OSView_TxHandler();
		OSView_TxIntEn();
    }
    OS_EXIT_CRITICAL();
}

/*
*********************************************************************************************************
*                                               Tx Handler
*
* Description: This routine is called from the transmitter buffer empty interrupt service handler.
*              It will send out the next byte in the buffer.
*
* Returns:     0    : There are more bytes to be send.
*              != 0 : Buffer empty, no more bytes to be send
*********************************************************************************************************
*/

void  OSView_TxHandler (void)
{
    INT8U  data;


    switch (OSView_TxState) {
        case OS_VIEW_TX_STATE_SD0:
             if (OSView_TxLen > 0 || OSView_TxStrLen > 0) { /* Packet in buffer or string waiting to be send ? */
                 OSView_Tx1(OS_VIEW_PROTOCOL_TX_SD0);
                 OSView_TxActiveFlag = TRUE;
                 OSView_TxState      = OS_VIEW_TX_STATE_SD1;
                 OSView_TxIx         = 0;
             } else {                                       /* If there is nothing to do end transmission      */
                 OSView_TxActiveFlag = FALSE;
                 OSView_TxIntDis();                         /* No more data to send, disable Tx interrupts     */
                 break;
             }
             break;

      case OS_VIEW_TX_STATE_SD1:
           OSView_Tx1(OS_VIEW_PROTOCOL_TX_SD1);
		   if (OSView_TxLen > 0) {
               OSView_TxState = OS_VIEW_TX_STATE_DATA_LEN;
           } else {
               OSView_TxState = OS_VIEW_TX_STATE_STR_LEN;
		   }
           break;

      case OS_VIEW_TX_STATE_DATA_LEN:                       /* Include the packet length in the packet         */
           OSView_Tx1(OSView_TxLen);
           OSView_TxState  = OS_VIEW_TX_STATE_DATA;
           OSView_TxChkSum = OSView_TxLen;
           break;

      case OS_VIEW_TX_STATE_DATA:
           data = OSView_TxBuf[OSView_TxIx];
           OSView_Tx1(data);
           OSView_TxChkSum += data;
           OSView_TxIx++;
           if (OSView_TxIx >= OSView_TxLen) {               /* See if we are done sending the packet           */
               OSView_TxState  = OS_VIEW_TX_STATE_CHKSUM;
               OSView_TxLen    = 0;
           }
           break;

      case OS_VIEW_TX_STATE_STR_LEN:                        /* String sending                                  */
           OSView_Tx1(OSView_TxStrLen + 1);
           OSView_TxState  = OS_VIEW_TX_STATE_STR_TYPE;
           OSView_TxChkSum = OSView_TxStrLen + 1;
           break;

      case OS_VIEW_TX_STATE_STR_TYPE:
           OSView_Tx1('C');
           OSView_TxState   = OS_VIEW_TX_STATE_STR_DATA;
           OSView_TxChkSum += 'C';
           break;

      case OS_VIEW_TX_STATE_STR_DATA:
           data = OSView_TxStrBuf[OSView_TxIx];
           OSView_Tx1(data);
           OSView_TxChkSum += data;
           if (++OSView_TxIx >= OSView_TxStrLen) {
               OSView_TxState  = OS_VIEW_TX_STATE_CHKSUM;
               OSView_TxStrLen = 0;
           }
           break;

      case OS_VIEW_TX_STATE_CHKSUM:                         /* Epilog ... checksum & end delimiter             */
           OSView_Tx1(OSView_TxChkSum);
           OSView_TxState = OS_VIEW_TX_STATE_ED;
           break;

      case OS_VIEW_TX_STATE_ED:
           OSView_Tx1(OS_VIEW_PROTOCOL_TX_ED);
           OSView_TxState  = OS_VIEW_TX_STATE_SD0;
           OSView_TxBufCnt = 0;                             /* Clear the Tx buffer                             */
           OSView_TxPktCtr++;
		   break;
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                     STORE 8, 16 or 32-bit DATA
*********************************************************************************************************
*/

static  void  OSView_TxStoINT8U (INT8U data)
{
    if (OSView_TxBufCnt < OS_VIEW_TX_BUF_SIZE) {
        OSView_TxBuf[OSView_TxBufCnt++] = data;
    }
}


static  void  OSView_TxStoINT16U (INT16U data)
{
    OSView_TxStoINT8U(data >> 8);
    OSView_TxStoINT8U(data & 0x00FF);
}


static  void  OSView_TxStoINT32U (INT32U data)
{
    OSView_TxStoINT16U(data >> 16);
    OSView_TxStoINT16U(data & 0x0000FFFFL);
}


static  void  OSView_TxStoPtr (void *ptr)
{
    INT32U  data;


    data = (INT32U)ptr;
    OSView_TxStoINT16U(data >> 16);
    OSView_TxStoINT16U(data & 0x0000FFFFL);
}


static  void  OSView_TxStoStr (char *s, int max_len)
{
    INT8U   len;
    INT8U   i;
    char   *ps;


    len = 0;
    ps  = s;
    if (ps != (char *)0) {                                  /* Calculate length of string                      */
        while (*ps && (len < max_len)) {
            len++;
        }
    }
    OSView_TxStoINT8U(len);                                 /* Store string, length first                      */
    ps = s;
    for (i = 0; i < len; i++) {
        OSView_TxStoINT8U((INT8U)*ps);
        ps++;
    }
}

⌨️ 快捷键说明

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