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

📄 freemaster_protocol.c

📁 freescale最新的16位单片机
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2005 Freescale Semiconductor, Inc.
* (c) Copyright 2001-2004 Motorola, Inc.
* ALL RIGHTS RESERVED.
*
****************************************************************************//*!
*
* @file   freemaster_protocol.c
*
* @brief  FreeMaster (PC Master) protocol handler
*
* @version 1.0.3.0
* 
* @date Jul-25-2006
* 
*******************************************************************************
*
* This file contains the PC Master protocol decoder and also the handlers 
* of basic protocol commands (read/write memory etc).
* 
*******************************************************************************/

#include "freemaster.h"
#include "freemaster_private.h"
#include "freemaster_protocol.h"

/**************************************************************************//*!
*
* @brief    PC Master driver initialization
*
******************************************************************************/

void FMSTR_Init(void)
{   
#if FMSTR_USE_TSA
    // initialize TSA
    FMSTR_InitTsa();
#endif

#if FMSTR_USE_SCOPE
    // initialize Scope
    FMSTR_InitScope();
#endif

#if FMSTR_USE_RECORDER
    // initialize Recorder
    FMSTR_InitRec();
#endif

#if FMSTR_USE_APPCMD
    // initialize application commands
    FMSTR_InitAppCmds();
#endif

#if FMSTR_USE_SCI || FMSTR_USE_JTAG
    // initialize communication and start listening for commands
    FMSTR_InitSerial();
#endif  
}

/**************************************************************************//*!
*
* @brief    Decodes the PC Master protocol and calls appropriate handlers 
*
* @param    pMessageIO - message in/out buffer
*
*
* This Function decodes given message and invokes proper command handler
* which fills in the response. The response transmission is initiated
* in this call as well.
*
******************************************************************************/

void FMSTR_ProtocolDecoder(FMSTR_BPTR pMessageIO)
{
    FMSTR_BPTR pResponseEnd;
    FMSTR_U8 nCmd;
    
    // no EX access by default
    FMSTR_SetExAddr(0);
    
    // command code comes first in the message
    FMSTR_ValueFromBuffer8(&nCmd, pMessageIO);

    // process command  
    switch (nCmd)
    {
    
#if FMSTR_USE_READVAR

        // read byte
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_READVAR8_EX:
            FMSTR_SetExAddr(1);
#endif
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_READVAR8:
#endif          
            pResponseEnd = FMSTR_ReadVar(pMessageIO, 1);
            break;
            
        // read word
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_READVAR16_EX:
            FMSTR_SetExAddr(1);
#endif
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_READVAR16:
#endif
            pResponseEnd = FMSTR_ReadVar(pMessageIO, 2);
            break;
            
        // read dword
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_READVAR32_EX:
            FMSTR_SetExAddr(1);
#endif
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_READVAR32:
#endif
            pResponseEnd = FMSTR_ReadVar(pMessageIO, 4);
            break;
#endif

#if FMSTR_USE_READMEM

        // read a block of memory
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_READMEM_EX:
            FMSTR_SetExAddr(1);
#endif
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_READMEM:
#endif
            pResponseEnd = FMSTR_ReadMem(pMessageIO);
            break;
            
#endif

#if FMSTR_USE_SCOPE

        // prepare scope variables
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_SETUPSCOPE_EX:
            FMSTR_SetExAddr(1);
#endif
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_SETUPSCOPE:
#endif
            pResponseEnd = FMSTR_SetUpScope(pMessageIO);
            break;  
            
        case FMSTR_CMD_READSCOPE:
            pResponseEnd = FMSTR_ReadScope(pMessageIO);
            break;
#endif

#if FMSTR_USE_RECORDER

        // get recorder status
        case FMSTR_CMD_GETRECSTS:
            pResponseEnd = FMSTR_GetRecStatus(pMessageIO);
            break;

        // start recorder
        case FMSTR_CMD_STARTREC:
            pResponseEnd = FMSTR_StartRec(pMessageIO);
            break;

        // stop recorder
        case FMSTR_CMD_STOPREC:
            pResponseEnd = FMSTR_StopRec(pMessageIO);
            break;

        // setup recorder
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_SETUPREC_EX:                 
            FMSTR_SetExAddr(1);
#endif
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_SETUPREC:                    
#endif
            pResponseEnd = FMSTR_SetUpRec(pMessageIO);
            break;
            
        // get recorder buffer information (force EX instead of non-EX)
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_GETRECBUFF_EX:
            FMSTR_SetExAddr(1);
#elif FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_GETRECBUFF:                  
#endif
            pResponseEnd = FMSTR_GetRecBuff(pMessageIO);
            break; 
#endif
 
#if FMSTR_USE_APPCMD

        // accept the application command
        case FMSTR_CMD_SENDAPPCMD:
            pResponseEnd = FMSTR_StoreAppCmd(pMessageIO);
            break;

        // get the application command status
        case FMSTR_CMD_GETAPPCMDSTS:
            pResponseEnd = FMSTR_GetAppCmdStatus(pMessageIO);
            break;

        // get the application command data
        case FMSTR_CMD_GETAPPCMDDATA:
            pResponseEnd = FMSTR_GetAppCmdRespData(pMessageIO);
            break;
#endif                      

#if FMSTR_USE_WRITEMEM

        // write a block of memory
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_WRITEMEM_EX:
            FMSTR_SetExAddr(1);
#endif          
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_WRITEMEM:
#endif
            pResponseEnd = FMSTR_WriteMem(pMessageIO);
            break;
#endif          

#if FMSTR_USE_WRITEMEMMASK  

        // write block of memory with a bit mask
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_WRITEMEMMASK_EX:
            FMSTR_SetExAddr(1);
#endif
#if FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_WRITEMEMMASK:
#endif
            pResponseEnd = FMSTR_WriteMemMask(pMessageIO);
            break;
#endif          
            
#if FMSTR_USE_WRITEVAR

        // write byte
        case FMSTR_CMD_WRITEVAR8:
            pResponseEnd = FMSTR_WriteVar(pMessageIO, 1);
            break;

        // write word
        case FMSTR_CMD_WRITEVAR16:
            pResponseEnd = FMSTR_WriteVar(pMessageIO, 2);
            break;

        // write dword
        case FMSTR_CMD_WRITEVAR32:
            pResponseEnd = FMSTR_WriteVar(pMessageIO, 4);
            break;
#endif          

#if FMSTR_USE_WRITEVARMASK

        // write byte with mask
        case FMSTR_CMD_WRITEVAR8MASK:
            pResponseEnd = FMSTR_WriteVarMask(pMessageIO, 1);
            break;

        // write word with mask
        case FMSTR_CMD_WRITEVAR16MASK:
            pResponseEnd = FMSTR_WriteVarMask(pMessageIO, 2);
            break;

#endif

#if FMSTR_USE_TSA

        // get TSA table (force EX instead of non-EX)
#if FMSTR_USE_EX_CMDS       
        case FMSTR_CMD_GETTSAINFO_EX:
            FMSTR_SetExAddr(1);
#elif FMSTR_USE_NOEX_CMDS
        case FMSTR_CMD_GETTSAINFO:
#endif
            pResponseEnd = FMSTR_GetTsaInfo(pMessageIO);
            break;
            

⌨️ 快捷键说明

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