📄 pcmaster.c
字号:
/******************************************************************************
*
* Motorola Inc.
* (c) Copyright 2001 Motorola, Inc.
* ALL RIGHTS RESERVED.
*
*******************************************************************************
*
* FILE NAME: pcmaster.c
*
* DESCRIPTION: Source file for PC Master
*
* MODULES INCLUDED: string.h
* types.h
* arch.h
* periph.h
* sci.h
* itcn.h
* pcmaster.h
*
* NOTES:
*
*******************************************************************************/
#include <string.h>
#include "types.h"
#include "arch.h"
#include "periph.h"
#include "appconfig.h"
#include "sci.h"
#include "pcmaster.h"
/*-----------------------------------------------------------------------------
TYPES
---------------------------------------------------------------------------*/
/* recorder settings structure (recorder settings and
temporary variables are stored in this structure) */
typedef struct{
UWord16 trgMode; /* 0x00 - manual, 0x01 - rising edge,
0x02 - falling edge */
UWord16 totalSmps; /* number of samples required */
UWord16 postTrigger; /* samples after trigger */
UWord16 timeDiv; /* time div */
UWord16 trgVarAddr; /* address of trigger variable */
UWord16 trgVarSize; /* size of variable (bytes) */
UWord16 trgVarSigned; /* 0x00 - unsigned, 0x01 - signed */
union{
/* union is used to access various types of treshold */
UWord16 uw;
UWord32 ud;
Word16 sw;
Word32 sd;
} trgTreshold; /* trigger treshold */
UWord16 varCnt; /* number of variables */
struct{
UWord16 varSize; /* size of variable */
UWord16 varAddr; /* address of variable */
} varDef[8];
/* position in recorder buffer - position of the next samples
(incremented with RecSetLen) */
UWord16 recPos;
/* length of required set of variables (in words) */
UWord16 recSetLen;
/* position to end of buffer (the variable is decremented after trigger
and recorder stops at 0) */
UWord16 recToEnd;
/* time div of Recorder */
UWord16 recTime;
/* recorder last value (last value the triggering variable
is stored after launch of Recorder routine) */
union{
UWord16 uw;
UWord32 ud;
Word16 sw;
Word32 sd;
} recLastVal; /* last value of synchronizing variable */
} sRecorder;
/* scope settings buffer (scope settings are stored in this structure) */
typedef struct{
UWord16 varCnt;
struct{
UWord16 varSize; /* size of scope variable */
UWord16 varAddr; /* address of scope variable */
} varDef[8]; /* maximum number of variables is 8 */
} sScope;
/*-----------------------------------------------------------------------------
CONSTANTS
---------------------------------------------------------------------------*/
/* call user application command status */
/* no application command called (board after reset) */
#define PCMASTER_APPCMD_NOCMD 0xFF
/* application command not finished */
#define PCMASTER_APPCMD_RUNNING 0xFE
/* status byte masks (used with 'status' variable) */
/* receiving started, beginning of message already detected ('+') */
#define ST_STARTED 0x0010
/* last received char was '+' */
#define ST_ST_CHAR_REC 0x0020
/* received message is standard command (for length decoding) */
#define ST_STD_CMD 0x0040
/* recorder is running (trigger already detected) */
#define ST_REC_RUNNING 0x0100
/* recorder is activated (waiting for trigger) */
#define ST_REC_ACTIVATED 0x0200
/* read pretrigger samples before waiting for trigger */
#define ST_REC_READ_PRETRIG 0x0400
/* response is being send to PC */
#define ST_SENDING 0x1000
/* last sent char was '+' */
#define ST_ST_SENT 0x2000
/* checksum already added to the message */
#define ST_CS_ADDED 0x4000
#define START '+' /* start of message */
/* recorder configuration */
#define REC_WORD_UNSIGNED 0x0004
#define REC_WORD_SIGNED 0x0005
#define REC_DWORD_UNSIGNED 0x0008
#define REC_DWORD_SIGNED 0x0009
/*-----------------------------------------------------------------------------
MACROS
---------------------------------------------------------------------------*/
/* save data for response to PC */
#define respPrepare(sts, len) {response.status = sts; \
response.length = len;}
/*-----------------------------------------------------------------------------
GLOBAL VARIABLES
---------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
STATIC VARIABLES
---------------------------------------------------------------------------*/
/* input/output communication buffer */
static UWord16 dataBuff[PCMASTER_BUFFER_SIZE + 1];
#ifdef PCMASTER_INCLUDE_CMD_SCOPE
/* scope config data */
static sScope scope;
#endif
#ifdef PCMASTER_INCLUDE_CMD_RECORDER
/* recorder config and temp data */
static sRecorder recorder;
/* recorder buffer */
static UWord16 recorderBuff[PCMASTER_REC_BUFF_LEN];
#endif
#ifdef PCMASTER_INCLUDE_CMD_APPCMD
/* application command call status */
static unsigned int appCmdSts;
/* application command data buffer */
extern UWord16 appCmdBuff[];
#endif
static unsigned int status; /* status word of receiver */
/* currently read input char (it contains checksum at the end of message) */
static unsigned int inChar;
/* position in buffer (0,1,2,...) */
static unsigned int pos;
/* length of data in a message used for receiving and transmitting
(includes checksum) */
static unsigned int length;
/* variable for checksum accumulation */
static unsigned int checkSum;
/* response structure type (this structure is used to save
the parameters of response to be sent to PC) */
typedef struct{
unsigned int status; /* status byte of response */
unsigned int length; /* length of the whole response */
} sResponse;
static sResponse response; /* variable with response data */
static UWord16 recPretrigCount; /* recorder pretrigger counter */
/*-----------------------------------------------------------------------------
STATIC FUNCTIONS
---------------------------------------------------------------------------*/
/* send one byte from output buffer */
static void inline sendBuffer(void);
/* prepare data for transmitting
(response.status -> status code, response.len -> length of data) */
static void sendResponse(sResponse *resp) ;
/* sample recorder data */
static asm void readSample( UWord16 *Addr, UWord16 *DestAddr);
/* decoding of incoming message after the last byte was received */
static void messageDecode(void); /* PC MASTER of Level 1 */
/* routine callled after filtering doubled SOM */
static void messageData(UWord16 startOfMessage);
/* all functions that begins with Cmd execute
the command and place proper data in dataBuff */
/* command - read block of memory from address *Addr to *DestAddr */
static asm void cmdReadMem(UWord16 *Addr, UWord16 *DestAddr);
/* command - get info */
static void inline cmdGetInfo(void);
/* command - get brief info */
static void inline cmdGetInfoBrief(void);
/* command - write block of memory */
static asm void inline cmdWriteMem(UWord16 *Addr, UWord16 *Data);
/* command - write block of memory with mask */
static asm void inline cmdWriteMemMask(UWord16 *AddrData, UWord16 *AddrMask);
/* command - scope setup */
static asm inline cmdScopeInit(UWord16 *Addr,UWord16 *DestAddr);
/* command - read scope data */
static asm void inline cmdReadScope(UWord16 *Addr, UWord16 *DestAddr);
/* command - call application command */
static asm void inline cmdCallAppCmd(UWord16 *Addr, UWord16 *Data);
/* command - recorder setup */
static asm void inline cmdRecInit(UWord16 *Addr, UWord16 *DestAddr);
/*-----------------------------------------------------------------------------
FUNCTION IMPLEMENTATIONS
---------------------------------------------------------------------------*/
Word16 pcmasterInit(void)
{
status=0; /* reset receiver */
#ifdef PCMASTER_INCLUDE_CMD_SCOPE
scope.varCnt=0; /* reset scope */
#endif
#ifdef PCMASTER_INCLUDE_CMD_RECORDER
recorder.varCnt=0; /* reset recorder */
#endif
#ifdef PCMASTER_INCLUDE_CMD_APPCMD
/* initialize application command status */
appCmdSts = PCMASTER_APPCMD_NOCMD;
#endif
return(0);
}
/*------------------------------------------------------------------------------*/
#ifdef PCMASTER_INCLUDE_CMD_APPCMD
UWord16 pcmasterGetAppCmdSts(void)
/* return state of application command call */
{
if (appCmdSts == PCMASTER_APPCMD_RUNNING)
return(1); /* new application command received */
else
return(0); /* no new application command */
}
#endif
/*------------------------------------------------------------------------------*/
#ifdef PCMASTER_INCLUDE_CMD_APPCMD
Word16 pcmasterWriteAppCmdSts(UWord16 state)
/* write state of application command call */
{
appCmdSts = state;
return(0); /* OK */
}
#endif
/*------------------------------------------------------------------------------*/
#undef add
static asm void cmdReadMem(UWord16 *Addr, UWord16 *DestAddr)
/* read 16bit data from 16bit address and send it to PC
(length is length of data block)
Addr - address of address
DestAddr - start address of data in buffer
using length */
{
move x:(r2)+,y1 /* low byte of address */
move x:(r2)+,y0 /* high byte of address */
move #8,x0 /* shifting value */
lsll y0,x0,y0 /* high byte shifted in Y0 */
add y0,y1 /* complete address */
/* read data */
move y1,r2 /* initialize R2 register */
move x0,y0 /* shifting value */
move length,x0 /* use length of message */
lsr x0
do x0,EndRead
move x:(r2)+,a1 /* read the requested variable */
/* disassemble in two bytes */
move a1,a0
bfclr #0xff00,a0 /* low byte -> a0 */
move a0,x:(r3)+ /* write low byte into memory */
bfclr #0x00ff,a1 /* high byte -> a1 */
lsrr a1,y0,a
move a1,x:(r3)+ /* write high byte into memory */
EndRead:
rts
}
/*------------------------------------------------------------------------------*/
static asm cmdScopeInit(UWord16 *Addr,UWord16 *DestAddr)
/* initialize scope/recorder (copy data from dataBuff to Scope or
Recorder structure)
Addr - address of data in input buffer
DestAddr - address of Scope/Recorder buffer with settings */
{
move x:(r2)+,lc /* number of scope channels */
move lc,x:(r3)+ /* write number of channels */
move #8,x0 /* shifting value */
do lc,EndDo
move x:(r2)+,a1 /* size of scope variable */
move a1,x:(r3)+ /* write size of scope variable */
move x:(r2)+,y1 /* low byte of address */
move x:(r2)+,y0 /* high byte of address */
lsll y0,x0,y0 /* high byte shifted in Y0 */
add y1,y0 /* complete address */
move y0,x:(r3)+ /* write address */
EndDo:
rts
}
/*------------------------------------------------------------------------------*/
static asm void cmdReadScope(UWord16 *Addr, UWord16 *DestAddr)
/* read scope data (data will be copied to dataBuff,
length is computed during copying and will contain
number of bytes of scope data)
Addr - address of scope settings buffer
DestAddr - address of io buffer
modifying length */
{
move x:(r2)+,lc /* number of channels */
clr y1
do lc,EndChannel /* loop for channels */
move x:(r2)+,x0 /* read length of variable */
add x0,y1 /* compute length */
lsr x0 /* number of words */
move x:(r2)+,r1 /* address of scope variable */
move #8,y0 /* shifting value */
push x0 /* loop counter */
Word:
move x:(r1)+,a1 /* read scope variable */
move a1,a0
bfclr #0x00ff,a1 /* high byte of scope variable -> a1 */
bfclr #0xff00,a0 /* low byte of scope variable -> a0 */
move a0,x:(r3)+ /* low byte */
lsrr a1,y0,a
move a1,x:(r3)+ /* high byte */
pop a /* loop for all variables */
dec a
tst a
push a
bgt Word
pop a
nop /* needed for correct DO execution */
EndChannel:
inc y1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -