📄 pc_m1.c
字号:
/** ###################################################################
** THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : PC_M1.C
** Project : Iadc
** Processor : 56F8346
** Beantype : PC_Master
** Version : Bean 01.029, Driver 01.13, CPU db: 2.87.097
** Compiler : Metrowerks DSP C Compiler
** Date/Time : 2009-2-9, 10:57
** Abstract :
** The PC master software application is a software tool initially created
** for developers of Motor Control applications but it may be extended to any
** application development. This tool allows control of an application remotely
** from a user-friendly graphical environment running on a PC.
** Settings :
** AsynchroSerial : Inhr1
**
** Initialization:
** Recorder buffer length : 40
** Command buffer length : 4
** Data buffer size : 60
** Recorder timebase : 32816
** Board firmware major number : 0
** Board firmware minor number : 0
** Device identification string : PC Master communication !
** Contents :
** pcmasterdrvInit - Word16 PC_M1_pcmasterdrvInit(sPCMasterComm *p_sPCMasterComm);
** pcmasterdrvIsr - void PC_M1_pcmasterdrvIsr(void);
**
** (c) Freescale Semiconductor
** 2004 All Rights Reserved
**
** (c) Copyright UNIS, spol. s r.o. 1997-2005
** UNIS, spol. s r.o.
** Jundrovska 33
** 624 00 Brno
** Czech Republic
** http : www.processorexpert.com
** mail : info@processorexpert.com
** ###################################################################*/
/* MODULE PC_M1. */
#include "PC_M1.h"
#include "bit.h"
#include "arch.h"
#include "port.h"
#include "string.h"
/*--------------------------------------------------
define which commands will be compiled
--------------------------------------------------*/
#define PCMDRV_INCLUDE_CMD_SCOPE /* read scope, setup scope */
#define PCMDRV_INCLUDE_CMD_RECORDER /* setup recorder, get recorder buffer info,*/
/* start recorder, stop recorder get recorder status */
#define PCMDRV_INCLUDE_CMD_APPCMD /* call app comd, app comd get status */
#undef PCMDRV_INCLUDE_CMD_GETINFOBRIEF /* enable getinfobrief command */
/* (default = getinfo command) */
/* call user application command status */
/* no application command called (board after reset) */
#define PCMDRV_APPCMD_NOCMD 0xFF
/* application command not finished */
#define PCMDRV_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_RECRUNNING 0x0100
/* recorder is activated (waiting for trigger) */
#define ST_RECACTIVATED 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 */
/* types of recorder trigger variables */
#define REC_CHAR_UNSIGNED 0x0002
#define REC_CHAR_SIGNED 0x0003
#define REC_WORD_UNSIGNED 0x0004
#define REC_WORD_SIGNED 0x0005
#define REC_LONG_UNSIGNED 0x0008
#define REC_LONG_SIGNED 0x0009
/*--------------------------------------
Macros
--------------------------------------*/
/* save data for response to PC */
#define respPrepare(sts, len) {response.status = sts; response.length = len;}
/* application command call status */
static unsigned char pcmdrvAppCmdSts;
/******************************************************************************/
/* SCI MACROS - !!! core dependent !!! */
/******************************************************************************/
#define INT_DISABLE 0
#define INT_ENABLE 1
#define SCIread(data) \
{Inhr1_RecvChar(&data);}
#define SCIwrite(data) \
{Inhr1_SendChar(data);}
#define SCItxEmptyIsr(param) \
{if (param==INT_ENABLE) \
{PC_M1_SCITxEmptyInt = INT_ENABLE;}\
else if (param==INT_DISABLE) \
{PC_M1_SCITxEmptyInt = INT_DISABLE;} }
#define SCIrxFullIsr(param) \
{if (param==INT_ENABLE) \
{PC_M1_SCIRxFullInt = INT_ENABLE;}\
else if (param==INT_DISABLE) \
{PC_M1_SCIRxFullInt = INT_DISABLE;} }
/******************************************************************************/
/* MEMORY ACCESS - !!! core dependent !!! */
/******************************************************************************/
#define POINT32_LEN 2
#define BYTE_LEN 1
#define WORD_LEN 2
#define LONG_LEN 4
/********************************************************/
/* PC Master Communication protocol commands data types */
/********************************************************/
/* read variable */
typedef struct{
unsigned char cmd;
unsigned char addrByte[4]; /* address of variable */
} sReadVarEx;
/* response structure type (this structure is used to save
the parameters of response to be sent to PC) */
typedef struct{
unsigned char status; /* status byte of response */
unsigned char length; /* length of the whole response */
} sResponse;
/* standard commands */
/* read memory */
typedef struct{
unsigned char cmd;
unsigned char cmdLen;
unsigned char size; /* size of data block in bytes */
unsigned char addrByte[4]; /* address of data */
} sReadMemEx;
/* write memory */
typedef struct{
unsigned char cmd;
unsigned char cmdLen;
unsigned char size; /* size of data block in bytes */
unsigned char addrByte[4]; /* address of data */
unsigned char data[1]; /* data */
} sWriteMemEx;
/* setup scope */
typedef struct{
unsigned char cmd;
unsigned char cmdLen;
unsigned char varCnt; /* number of variables */
unsigned char dataByte[1]; /* address of variable */
} sSetupScopeEx;
/* setup recorder */
typedef struct{
UWord16 cmd;
UWord16 cmdLen;
UWord16 trgMode;
UWord16 totalSmps;
UWord16 postTrigger;
UWord16 timeDiv; /* Time Base unit multiplier */
UWord32 trgVarAddr[1];
UWord16 trgVarSize;
UWord16 trgVarSigned;
union {
UInt8 uch;
Int8 ch;
UWord16 uw;
Word16 sw;
UWord32 ud;
Word32 sd;
} trgThreshold; /* trigger comparing threshold */
UWord16 varCnt; /* number of variables */
struct{
UWord16 varSize; /* size of variable in bytes */
UWord32 varAddr[1]; /* address of variable */
} varDef[8];
} sSetupRec;
/* call user application command */
typedef struct{
UInt8 cmd;
UInt8 cmdLen;
UInt8 appCmdData[1]; /* application command data */
} sCallAppCmd;
/* return any data */
typedef struct{
unsigned char reserved; /* status code */
unsigned char data[1]; /* data to PC */
} sReturnData;
/* currently read input char (it contains checksum at the end of message) */
static UInt8 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 UInt8 length;
/* variable for checksum accumulation */
static unsigned int checkSum;
/* pointer to sciComm structure passed in initialization */
static sPCMasterComm *PCMasterComm;
static sResponse response; /* variable with response data */
static UWord16 recPretrigCount; /* recorder pretrigger counter */
/* send one byte from output buffer */
static void sendBuffer(void);
/* prepare data for transmitting
(response.status -> status code, len -> length of data) */
static void sendResponse(sResponse *resp) ;
/* sample recorder data */
static asm void readSample(int *Addr, int *DestAddr);
static UWord16 readRecSample(UWord16 position);
/* decoding of incoming message after the last byte was received */
static void messageDecode(void);
/* routine callled after filtering doubled SOM */
static void messageData(UWord16 startOfMessage);
/* all functions that begins with Cmd execute
the command and place the right data in dataBuff */
inline static void cmdGetInfoBrief(void);
static UWord16 memCopy(register volatile unsigned char * srcAddr,
register volatile unsigned char * destAddr,
register volatile char size);
/*---------------------------------------
SCI communication algotithm variables
--------------------------------------- */
static unsigned int status; /* status word of receiver */
static unsigned int PC_M1_SCIRxFullInt; /* internal status register of interrupt */
static unsigned int PC_M1_SCITxEmptyInt; /* internal status register of interrupt */
/*
** ===================================================================
** Method : PC_M1_pcmasterdrvInit (bean PC_Master)
**
** Description :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -