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

📄 dlcs.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
📖 第 1 页 / 共 2 页
字号:
                       WriteDLCIO(DLC_ESCAPE_OCT);
                       temp &=~(0x20);
                    }
                    #endif
                    WriteDLCIO(temp);
                }
                EndCrc(&crc);
                WriteDLCIO(crc);                                        /* FCS */
                WriteDLCIO(DLC_FLAG);                                   /* FLAG */
            }
        }
    }
}

static void ScanTmrProc(void)
{
    StartTmr(scantmr, PERIOD_SCAN);
    DLCSEntry();
}

static void DiagnoseProc(void)
{
}

void InitDLCS(void)
{
#if DEBUG_UARTNo_DLC <= 3
    InitUART(DEBUG_UARTNo_DLC, DEBUG_UART_BAUD);
#endif

    /* initialize dlcs0 buffer */
    dlcs[0].s_buf     = s_buf0;
    dlcs[0].s_bufsize = sizeof(s_buf0);
    dlcs[0].r_buf     = r_buf0;
    dlcs[0].r_bufsize = sizeof(r_buf0);

    /* initialize dlcs1 buffer */
    dlcs[1].s_buf     = s_buf1;
    dlcs[1].s_bufsize = sizeof(s_buf1);
    dlcs[1].r_buf     = r_buf1;
    dlcs[1].r_bufsize = sizeof(r_buf1);

    /* initialize dlcs2 buffer */
    dlcs[2].s_buf     = s_buf2;
    dlcs[2].s_bufsize = sizeof(s_buf2);
    dlcs[2].r_buf     = r_buf2;
    dlcs[2].r_bufsize = sizeof(r_buf2);

    /* initialize dlcs3 buffer */
    dlcs[3].s_buf     = s_buf3;
    dlcs[3].s_bufsize = sizeof(s_buf3);
    dlcs[3].r_buf     = r_buf3;
    dlcs[3].r_bufsize = sizeof(r_buf3);

    scantmr = CreateTimer(ScanTmrProc, 0);
    StartTmr(scantmr, PERIOD_SCAN);

    InitDLCRecv();

    InitDLCCmd();
    ClearDLCS();
    InitDLCIO();

    InstallDiagProc(DiagnoseProc);
}

void ResetDLCS(void)
{
    ResetDLCRecv();

    ResetDLCCmd();
    ClearDLCS();

    StartTmr(scantmr, PERIOD_SCAN);
}

void WriteDLCRecvRound(INT8U dlci, INT8U data)
{
  
//  OS_ENTER_CRITICAL();
    if ((dlcs[dlci].status & DLC_MASK) != DLC_OPENED) {
  // OS_EXIT_CRITICAL();
    return;
  }
    if (!WriteRoundBuf(&dlcs[dlci].r_round, data)) {
        if ((dlcs[dlci].status & DLC_DATAMODE) == 0) {                  /* TEXT MODE */
            dlcs[dlci].prechar = 0;
            ResetRoundBuf(&dlcs[dlci].r_round);
        //    OS_EXIT_CRITICAL();
            return;
        }
    }
    if ((dlcs[dlci].status & DLC_DATAMODE) == 0) {                      /* TEXT MODE */
        if (data == LF) {
            if (dlcs[dlci].prechar == CR) {
                #if DEBUG_DLC_AT_RECV > 0
                if (UsedOfRoundBuf2(&dlcs[dlci].r_round) > 3) {
                    PrintFromUART(DEBUG_UARTNo_DLC, "AT RECV(");
                    SendFromUART_BYTE(DEBUG_UARTNo_DLC, dlci + '0');
                    SendFromUART_BYTE(DEBUG_UARTNo_DLC, ')');
                    SendFromUART_BYTE(DEBUG_UARTNo_DLC, ':');
                    SendFromUART_BYTE(DEBUG_UARTNo_DLC, ' ');
                    SendFromUART_MEM(DEBUG_UARTNo_DLC, RoundBufStartPos(&dlcs[dlci].r_round), UsedOfRoundBuf(&dlcs[dlci].r_round));
                    PrintFromUART(DEBUG_UARTNo_DLC, "\n");
                }
                #endif
                /* handle one AT command */
                HdlMsg_ATCMD_RECV(dlci, RoundBufStartPos(&dlcs[dlci].r_round), UsedOfRoundBuf(&dlcs[dlci].r_round));
                ResetRoundBuf(&dlcs[dlci].r_round);
            }
        }else ;
        dlcs[dlci].prechar = data;
    }
	//OS_EXIT_CRITICAL();
}

void HdlDLCRecv(void)
{
    switch(DLCRecv.type)
    {
        case TYPE_UA:
            Hdl_TYPE_UA();
            break;
        case TYPE_UIH:
        case TYPE_UIH_RESPOND:
            Hdl_TYPE_UIH();
            break;
        default:
            break;
    }
}

INT8S GetShieldedDLC(void)
{
    INT8U i;

    for (i = 0; i < MAX_DLCS; i++) {
        if ((dlcs[i].status & (DLC_MASK | DLC_SHIELD)) == (DLC_OPENED | DLC_SHIELD)) return i;
    }
    return -1;
}

BOOLEAN EstablishDLC(INT8U dlci, BOOLEAN shielded, void (*informer)(INT8U dlci, INT8U reason))
{
    DLCCMD_STRUCT *curcmd;

    if (dlci >= MAX_DLCS) goto ERROR_RET;
    if (shielded) {
        ClearDLCS();
        OpenDLC(dlci, TRUE);
        goto SUCCESS_RET;
    } else {
        if (GetShieldedDLC() != -1) goto ERROR_RET;
    }

    if (dlci > 0 && (dlcs[0].status & DLC_MASK) != DLC_OPENED) goto ERROR_RET;
    if ((dlcs[dlci].status & DLC_MASK) == DLC_OPENED) goto SUCCESS_RET;
    if ((dlcs[dlci].status & DLC_MASK) != DLC_CLOSED) goto ERROR_RET;

    if ((curcmd = AllocDLCCmd_SABM(dlci, informer)) != NULL) {
        dlcs[dlci].status &= (~DLC_MASK);
        dlcs[dlci].status |= DLC_OPENING;
        AppendListEle(&dlcs[dlci].cmdlist, (LISTMEM *)curcmd);
        return TRUE;
    } else {
        goto ERROR_RET;
    }

    ERROR_RET:
    if (informer != NULL) informer(dlci, _FAILURE);
    return FALSE;

    SUCCESS_RET:
    if (informer != NULL) informer(dlci, _SUCCESS);
    return TRUE;
}

BOOLEAN ReleaseDLC(INT8U dlci, void (*informer)(INT8U dlci, INT8U reason))
{
    DLCCMD_STRUCT *curcmd;

    if (dlci >= MAX_DLCS) goto ERROR_RET;
    if ((dlcs[dlci].status & DLC_MASK) == DLC_CLOSED) goto SUCCESS_RET;
    if ((dlcs[dlci].status & DLC_MASK) != DLC_OPENED) goto ERROR_RET;
    if (dlcs[dlci].status & DLC_SHIELD) {
        ClearDLCS();
        goto SUCCESS_RET;
    }

    if (dlci > 0 && (dlcs[0].status & DLC_MASK) != DLC_OPENED) goto ERROR_RET;

    if ((curcmd = AllocDLCCmd_DISC(dlci, informer)) != NULL) {
        dlcs[dlci].status &= (~DLC_MASK);
        dlcs[dlci].status |= DLC_CLOSING;
        AppendListEle(&dlcs[dlci].cmdlist, (LISTMEM *)curcmd);
        return TRUE;
    } else {
        goto ERROR_RET;
    }

    ERROR_RET:
    if (informer != NULL) informer(dlci, _FAILURE);
    return FALSE;

    SUCCESS_RET:
    if (informer != NULL) informer(dlci, _SUCCESS);
    return TRUE;
}

BOOLEAN ControlDLCSignal(INT8U dlci, INT8U signal)
{
    INT8U mask;
    DLCCMD_STRUCT *curcmd;

    if ((dlcs[dlci].status & DLC_MASK) != DLC_OPENED) return FALSE;

    mask    = (INT8U)(~(SIG_FCS_S | SIG_DSR | SIG_CTS | SIG_RI | SIG_DCD));
    signal &= mask;
    if ((curcmd = AllocDLCCmd_MSC(dlci, signal, FALSE)) != NULL) {
        AppendListEle(&dlcs[0].cmdlist, (LISTMEM *)curcmd);
        dlcs[dlci].signal &= mask;
        dlcs[dlci].signal |= signal;
        return TRUE;
    } else {
        return FALSE;
    }
}
void MSCCtrDTROff(void)
{

   INT8U signal;
   signal=(SIG_DTR  | SIG_DSR | SIG_CTS);
   ControlDLCSignal(1, signal);
}

void MSCCtrDTROn(void)
{
   INT8U signal;

   signal=(SIG_RTS | SIG_DSR | SIG_CTS);
   ControlDLCSignal(1, signal);

}

INT8U GetDLCSignal(INT8U dlci)
{
    return dlcs[dlci].signal;
}

BOOLEAN DLCIsOpen(INT8U dlci)
{
    if ((dlcs[dlci].status & DLC_MASK) == DLC_OPENED) return TRUE;
    else return FALSE;
}

BOOLEAN DLCIsClose(INT8U dlci)
{
    if ((dlcs[dlci].status & DLC_MASK) == DLC_CLOSED) return TRUE;
    else return FALSE;
}

BOOLEAN SetDLCDataMode(INT8U dlci)
{
    if ((dlcs[dlci].status & DLC_MASK) != DLC_OPENED) return FALSE;
    else {
        if ((dlcs[dlci].status & DLC_DATAMODE) == 0) {
            ResetRoundBuf(&dlcs[dlci].s_round);
            ResetRoundBuf(&dlcs[dlci].r_round);
            dlcs[dlci].status |= DLC_DATAMODE;
        }
        return TRUE;
    }
}

BOOLEAN ClearDLCDataMode(INT8U dlci)
{
    if ((dlcs[dlci].status & DLC_MASK) != DLC_OPENED) return FALSE;
    else {
        if (dlcs[dlci].status & DLC_DATAMODE) {
            ResetRoundBuf(&dlcs[dlci].s_round);
            ResetRoundBuf(&dlcs[dlci].r_round);
            dlcs[dlci].prechar = 0;
            dlcs[dlci].status &= (~DLC_DATAMODE);
        }
        return TRUE;
    }
}

BOOLEAN PushDatatoDLC(INT8U dlci, INT8U *data, INT16U len)
{
    if (dlci >= MAX_DLCS) return FALSE;
    if ((dlcs[dlci].status & DLC_MASK) != DLC_OPENED) return FALSE;

    if (WriteBlockRoundBuf(&dlcs[dlci].s_round, data, len)) {

        #if DEBUG_DLC_AT_SEND > 0
        PrintFromUART(DEBUG_UARTNo_DLC, "AT SEND(");
        SendFromUART_BYTE(DEBUG_UARTNo_DLC, dlci + '0');
        SendFromUART_BYTE(DEBUG_UARTNo_DLC, ')');
        SendFromUART_BYTE(DEBUG_UARTNo_DLC, ':');
        SendFromUART_BYTE(DEBUG_UARTNo_DLC, ' ');
        SendFromUART_MEM(DEBUG_UARTNo_DLC, data, len);
        PrintFromUART(DEBUG_UARTNo_DLC, "\n");
        #endif

        ScanSendround();
        return TRUE;
    } else {
        return FALSE;
    }
}

BOOLEAN WriteDatatoDLC(INT8U dlci, INT8U *data, INT16U len)
{
    if (dlci >= MAX_DLCS) return FALSE;
    if ((dlcs[dlci].status & DLC_MASK) != DLC_OPENED) return FALSE;

    return WriteBlockRoundBuf(&dlcs[dlci].s_round, data, len);
}

/* functions for DATA mode */
BOOLEAN CanWriteDLC(INT8U dlci)
{
    if ((dlcs[dlci].status & DLC_DATAMODE) == 0) return FALSE;
    else return TRUE;
}

BOOLEAN WriteBytetoDLC(INT8U dlci, INT8U data)
{
    BOOLEAN ret;

    if ((dlcs[dlci].status & DLC_DATAMODE) == 0) return FALSE;
    else {
        ret = WriteRoundBuf(&dlcs[dlci].s_round, data);
        if (UsedOfRoundBuf(&dlcs[dlci].s_round) == MAX_SENDRDY) {
            OSQPost(GsmTaskMsgQue, MSG_DCLS_SENDTSK, 0, 0);
        }
        return ret;
    }
}

INT16S ReadBytefromDLC(INT8U dlci)
{
    if ((dlcs[dlci].status & DLC_DATAMODE) == 0) return -1;
    else return ReadRoundBuf(&dlcs[dlci].r_round);
}

void DLCSEntry(void)
{
    CheckCmdList();
    if (!ScanCmdList()) ScanSendround();
}

#if IO_DEBUG
void    CommPutChar( int c, INT8U UartOut_NO);

void SendAtCmdKB(INT8U Dlci,INT8U *DataPtr)
{
    INT8U crc;
    if(Dlci>0x05) return ;
    if(Dlci==0)
    {
     while(1)
     {
      CommPutChar(*DataPtr,0);
      if(*DataPtr==0x0d) break;
      DataPtr++;
     }
     return ;
    }
    InitCrc(&crc);
    WriteDLCIO(DLC_FLAG);                 //Flag
    Dlci=(Dlci<<2);
    Dlci|=0x03;                  //address
    CalcCrcByByte(&crc, Dlci);
    WriteDLCIO(Dlci);
    CalcCrcByByte(&crc, 0xEF);            //control field
    WriteDLCIO(0xEF);
    while(1)
    {
        if((*DataPtr)!=0x0D)
        {
          WriteDLCIO(*DataPtr);
	  DataPtr++;
        }
        else
        {
           WriteDLCIO(*DataPtr);
           break;
        }
    }
    EndCrc(&crc);
    WriteDLCIO(crc);                                        /* FCS */
    WriteDLCIO(DLC_FLAG);

}
#endif

⌨️ 快捷键说明

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