📄 pc_m1.c
字号:
** Initialization of PC Master Communication Algorithm. This
** function must be called first, before start of
** communication.
** Parameters :
** NAME - DESCRIPTION
** * p_sPCMasterComm - Pointer to
** structure with SCI communication
** settings.
** Returns :
** --- - The function returns the PASS (0).
** ===================================================================
*/
Word16 PC_M1_pcmasterdrvInit(sPCMasterComm *p_sPCMasterComm)
{
/* store sPCMasterComm structure address */
PCMasterComm=(sPCMasterComm *)p_sPCMasterComm;
inChar = 1;
status = 0; /* reset receiver */
#ifdef PCMDRV_INCLUDE_CMD_SCOPE
/* reset scope */
((pcmdrv_sScope *)(PCMasterComm->p_scope))->varCnt=0;
#endif
#ifdef PCMDRV_INCLUDE_CMD_RECORDER
/* reset recorder */
((pcmdrv_sScope *)(PCMasterComm->p_recorder))->varCnt=0;
#endif
#ifdef PCMDRV_INCLUDE_CMD_APPCMD
/* initialize application command status */
pcmdrvAppCmdSts = PCMDRV_APPCMD_NOCMD;
#endif
return(0);
}
/*
** ===================================================================
** Method : PC_M1_pcmasterdrvIsr (bean PC_Master)
**
** Description :
** Main PC Master Communication routine which provide
** receiving, decoding of incoming message and sending
** response to PC.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void PC_M1_pcmasterdrvIsr(void)
{
if (status & ST_SENDING) { /* message is transmitting */
sendBuffer(); /* send data */
return; /* response is sending to PC */
}
SCIread(inChar); /* read received character */
if ((status & ST_ST_CHAR_REC) == 0) { /* last byte was not '+' */
if (inChar == '+') { /* '+' received */
bitSet(ST_ST_CHAR_REC,status);
}
else { /* any byte received */
messageData(0); /* byte received */
}
}
else { /* the last byte was '+' */
if (inChar == '+') { /* doubled '+' (this is the second one) */
messageData(0); /* byte received */
}
else { /* start of message */
messageData(1); /* byte received */
}
bitClear(ST_ST_CHAR_REC,status); /* clear flag */
}
}
/*
** ===================================================================
** Method : memCopy (bean PC_Master)
**
** Description :
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static UWord16 memCopy(register volatile char unsigned *srcAddr,
register volatile unsigned char *destAddr,
register volatile char size)
{
while ((--size) >= 0) {
*destAddr++ = *srcAddr++;
}
return(0);
}
/*
** ===================================================================
** Method : sendBuffer (bean PC_Master)
**
** Description :
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
inline static void sendBuffer(void)
{
if (pos <= length) { /* is it end of message ? */
Inhr1_SendChar((PCMasterComm)->p_dataBuff[pos]); /* send one char to SCI */
if ((PCMasterComm)->p_dataBuff[pos] != '+') { /* current character is not '+' */
checkSum += (PCMasterComm)->p_dataBuff[pos]; /* accumulate checksum */
pos++;
}
else { /* current character is '+' */
if (status & ST_ST_SENT) { /* the last sent char was '+' */
bitClear(ST_ST_SENT,status);
checkSum += (PCMasterComm)->p_dataBuff[pos]; /* accumulate checksum */
pos++;
}
else { /* the last sent byte was not '+' */
bitSet(ST_ST_SENT,status);
}
}
if ((pos == length) && !(status & ST_CS_ADDED)) { /* the last byte before cs was sent, now add the checksum */
checkSum = (-checkSum) & 0x00FF; /* compute checksum */
(PCMasterComm)->p_dataBuff[pos] = (UInt8)checkSum;
bitSet(ST_CS_ADDED,status); /* set flag */
}
}
else { /* end of transmitting */
bitClear(ST_SENDING | ST_CS_ADDED,status); /* reset transmitter (switch to receiving mode) */
SCItxEmptyIsr(INT_DISABLE); /* disable SCI Tx Empty Interrupt */
SCIrxFullIsr(INT_ENABLE); /* enable SCI Rx Full Interrupt */
}
}
/*
** ===================================================================
** Method : sendResponse (bean PC_Master)
**
** Description :
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void sendResponse(sResponse *resp)
{
bitSet(ST_SENDING,status); /* set flag */
(PCMasterComm)->p_dataBuff[0] = resp->status; /* status of trasmitted message */
length=resp->length; /* length of message */
pos=0; /* position in the message */
/* send start of message */
inChar = '+';
SCIwrite(inChar); /* send start character */
SCIrxFullIsr(INT_DISABLE); /* disable SCI Rx Full Interrupt */
SCItxEmptyIsr(INT_ENABLE); /* enable SCI Tx Empty Interrupt */
checkSum = 0; /* reset checksum */
}
/*
** ===================================================================
** Method : messageDecode (bean PC_Master)
**
** Description :
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void messageDecode(void)
{
unsigned char *varaddr;
#ifndef PCMDRV_INCLUDE_CMD_GETINFOBRIEF
unsigned char cnt;
#endif
switch(PCMasterComm->p_dataBuff[0]) {
/* -------------------------
special format commands
------------------------- */
case PCMDRV_CMD_READVAR8EX: { /* read 8-bit variable */
/* read address */
memCopy(((sReadVarEx *)(PCMasterComm->p_dataBuff))->addrByte,
(unsigned char *)&varaddr, POINT32_LEN);
/* read data */
memCopy(varaddr, ((sReturnData *)(PCMasterComm->p_dataBuff))->data, BYTE_LEN);
respPrepare(PCMDRV_STC_OK, 2); /* OK */
}break;
case PCMDRV_CMD_READVAR16EX: { /* read 16-bit variable */
/* read address */
memCopy(((sReadVarEx *)(PCMasterComm->p_dataBuff))->addrByte,
(unsigned char *)&varaddr, POINT32_LEN);
/* read data */
memCopy(varaddr, ((sReturnData *)(PCMasterComm->p_dataBuff))->data, WORD_LEN);
respPrepare(PCMDRV_STC_OK, 3); /* OK */
}break;
case PCMDRV_CMD_READVAR32EX: { /* read 32-bit variable */
/* read address */
memCopy(((sReadVarEx *)(PCMasterComm->p_dataBuff))->addrByte,
(unsigned char *)&varaddr, POINT32_LEN);
/* read data */
memCopy(varaddr, ((sReturnData *)(PCMasterComm->p_dataBuff))->data, LONG_LEN);
respPrepare(PCMDRV_STC_OK, 5); /* OK */
}break;
#ifdef PCMDRV_INCLUDE_CMD_SCOPE
case PCMDRV_CMD_READSCOPE: { /* read scope variables */
unsigned char i, cnt, index = 0;
/* scope not configured */
if (((pcmdrv_sScope *)(PCMasterComm->p_scope))->varCnt==0) {
respPrepare(PCMDRV_STC_NOTINIT,1); /* scope not initialized */
}
else { /* scope configured */
/* read number of variables */
cnt = ((pcmdrv_sScope *)(PCMasterComm->p_scope))->varCnt;
for (i=0; i < cnt; i++) {
/* read size of variable */
length = ((pcmdrv_sScope *)(PCMasterComm->p_scope))->varDef[i].varSize;
/* read address of variable */
memCopy( ((pcmdrv_sScope *)(PCMasterComm->p_scope))->varDef[i].addrByte,
(unsigned char *)&varaddr, POINT32_LEN);
/* copy data into the input/output buffer */
memCopy( varaddr, (unsigned char *)&((sReturnData *)
(PCMasterComm->p_dataBuff))->data[index], (Int8) length);
index += length;
}
respPrepare(PCMDRV_STC_OK, (UInt8)(index +1)); /* OK */
}
}break;
#endif
#ifdef PCMDRV_INCLUDE_CMD_APPCMD
case PCMDRV_CMD_GETAPPCMDSTS: { /* get user application command call status */
/* buffer is not initialized (zero length) */
if (PCMasterComm->appCmdSize == 0) {
respPrepare(PCMDRV_STC_INVCMD,1); /* invalid command */
return;
}
/* copy status byte in the output buffer */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[0] = pcmdrvAppCmdSts;
respPrepare(PCMDRV_STC_OK,2); /* OK */
}break;
#endif
#ifdef PCMDRV_INCLUDE_CMD_GETINFOBRIEF
case PCMDRV_CMD_GETINFOBRIEF: { /* get brief info about hardware */
cmdGetInfoBrief(); /* execute the command */
respPrepare(PCMDRV_STC_OK,(1 + 6)); /* OK */
}break;
#endif
#ifndef PCMDRV_INCLUDE_CMD_GETINFOBRIEF
case PCMDRV_CMD_GETINFO: { /* get info about hardware */
/* protocol version */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[0] = PCMDRV_PROT_VER;
/* CFG_FLAFGS */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[1] = PCMDRV_CFG_FLAFGS;
/* dataBusWdt */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[2] = PCMDRV_DATABUSWDT;
/* version */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[3] = PCMasterComm->globVerMajor;
/* version */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[4] = PCMasterComm->globVerMinor;
/* size of input buffer (without CMD, LENGTH) */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[5] = (UInt8)(((PCMasterComm->dataBuffSize) - 1));
/* recorder buff size */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[6] = (UInt8)((PCMasterComm->recSize ) & 0x00ff);
((sReturnData *)(PCMasterComm->p_dataBuff))->data[7] = (UInt8)(((PCMasterComm->recSize)>>8) & 0x00ff);
/* period of Recorder routine launch */
((sReturnData *)(PCMasterComm->p_dataBuff))->data[8] = (UInt8)((PCMasterComm->timeBase) & 0x00ff);
((sReturnData *)(PCMasterComm->p_dataBuff))->data[9] = (UInt8)(((PCMasterComm->timeBase)>>8) & 0x00ff);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -