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

📄 command.c

📁 DSP 5409 plc应用程序,调试通过,是用在电力线通讯上的演示程序.
💻 C
📖 第 1 页 / 共 5 页
字号:
//==========================================================================================
// Filename:		command.c
//
// Description:		Routines to interpret commands.  On Master these are from UART,
//					on slave from PLC.
//
// Copyright (C) 2003 Texas Instruments Incorporated
// Texas Instruments Proprietary Information
// Use subject to terms and conditions of TI Software License Agreement
//
// Revision History:
//==========================================================================================

#include "ofdm_modem.h"
#include "uart.h"
#include "intr.h"

static u16	emeterMsgString[20];	// Holds command string to be sent to emeter.
									// Do not pack two bytes into each word.  This makes the 
									// transmitting much more straightforward.
									// 20 bytes is long enough to hold the longest string that
									// the HOST/Master protocol allows.
									// (global/static for debug)
//==========================================================================================
// Function:		ProcessMasterCommand()
//
// Description: 	This function interprets and executes a command from the UART for the
//					MASTER.  Commands must either be executed quickly, or set up state
//					variables which allow additional processing later.  They may not
//					tie up the processor for extended processing.
//
//					The command from the UART is received in 8 16-bit parms.
//					parm[0] contains the command number
//					parms[1-7] are optional depending on the command and described for each
//						command below.
//
//
// Revision History:
//==========================================================================================
void ProcessMasterCommand(void)
{
/*Master*/	u16		i;					// Loop index
/*Master*/  u16		emeterStringIndex;
/*Master*/  u32		ulAddr;				// 32-bit address formed from received uart data
/*Master*/
/*Master*/	switch(uUartCommand[0])		// command number
/*Master*/	{
/*Master*/		case MC_GET_PARM:
/*Master*/			//==============================================================================
/*Master*/			// Command:  Get master parm.
/*Master*/			// 	uUartCommand[1] = index into address table of requested value.
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		If the requested configuration parameter is valid, SUCCESS is returned
/*Master*/			//		for an acknowledge followed by the requested value(s).
/*Master*/			//		If an unrecognized parameter is requested an error code is returned.
/*Master*/			//==============================================================================
/*Master*/			// ***** Error checking for parm number < 40
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);	// command acknowlege
/*Master*/			if(uUartCommand[1] < 30)	// request for 16-bit parm
/*Master*/			{
/*Master*/				WriteUART(UART_TARGET_HOST, 1, (u16*) uppParms16[uUartCommand[1]]);
/*Master*/			}
/*Master*/			else
/*Master*/			{
/*Master*/				WriteUART(UART_TARGET_HOST, 2, (u16*) uppParms32[uUartCommand[1]-30]);
/*Master*/			}
/*Master*/			ulAutoPollCounter = 0L;
/*Master*/			uAutoPollPause=0;		// Release AutoPoll.
/*Master*/			break;
/*Master*/
/*Master*/		case MC_SET_PARM:
/*Master*/			//==============================================================================
/*Master*/			// Command:  Set parm.
/*Master*/			// 	uUartCommand[1] = index into address table of requested value.
/*Master*/			// 	uUartCommand[2] = value. (high word if 32-bit parm)
/*Master*/			// 	uUartCommand[3] = (low word of value if 32-bit parm)
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		If the configuration parmeters are valid, SUCCESS is returned,
/*Master*/			//		otherwise an error code is returned.
/*Master*/			//==============================================================================
/*Master*/			// ***** Error checking for parm number < 40
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);
/*Master*/			if(uUartCommand[1] < 30)	// writing 16-bit parm
/*Master*/			{
/*Master*/				*uppParms16[uUartCommand[1]] = uUartCommand[2];
/*Master*/			}
/*Master*/			else
/*Master*/			{
/*Master*/				*uppParms32[uUartCommand[1]-30] = (u32)(uUartCommand[2])*65536 + (u32)(uUartCommand[3]);
/*Master*/			}
/*Master*/			ulAutoPollCounter = 0L;
/*Master*/			uAutoPollPause=0;		// Release AutoPoll.
/*Master*/			break;
/*Master*/
/*Master*/		case MC_GET_STATUS:
/*Master*/			//==============================================================================
/*Master*/			// Command:  Get status.
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		If the requested configuration parameter is valid, SUCCESS is returned
/*Master*/			//		for an acknowledge followed by the status array values.
/*Master*/			//==============================================================================
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);
/*Master*/			for(i=0; i<30; i++)		// 16-bit parms
/*Master*/			{
/*Master*/				WriteUART(UART_TARGET_HOST, 1, (u16*) uppParms16[i]);
/*Master*/			}
/*Master*/			for(i=0; i<10; i++)		// 32-bit parms
/*Master*/			{
/*Master*/				WriteUART(UART_TARGET_HOST, 2, (u16*) uppParms32[i]);
/*Master*/			}
/*Master*/			ulAutoPollCounter = 0L;
/*Master*/			uAutoPollPause=0;		// Release AutoPoll.
/*Master*/			break;
/*Master*/
/*Master*/		case MC_START_BER:
/*Master*/			//==============================================================================
/*Master*/			// Start BER test.
/*Master*/			// 	uUartCommand[1] = slave address - high (0 = use uClosestSlave).
/*Master*/			// 	uUartCommand[2] = slave address -low   (0 = use uClosestSlave).
/*Master*/			// 	uUartCommand[3] = nuber of BER packets requested (high).
/*Master*/			// 	uUartCommand[4] = nuber of BER packets requested (low). 
/*Master*/			//
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		SUCCESS/ERROR is returned here.  Details of the BER can be polled using
/*Master*/			//		the Get Master Configuration command.
/*Master*/			//==============================================================================
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);		// Acknowlege command.
/*Master*/			uUartState = UART_RECEIVE_COMMAND;	// Next thing coming should be another cmd.
/*Master*/			
/*Master*/			ulAddr = (u32)uUartCommand[1]*65536L + (u32)uUartCommand[2];
/*Master*/			ulNumBerPackets = (u32)uUartCommand[3]*65536L + (u32)uUartCommand[4];
/*Master*/			ulBerCounter = 0L;		// Reset number sent counter.
/*Master*/			
/*Master*/			// Set flag to start sending BER packets
/*Master*/			uBerTestInProgress = 1;
/*Master*/	
/*Master*/			if(ulAddr == 0L)
/*Master*/			{
/*Master*/				ulBERSlaveAddr = ulClosestSlaveAddr;
/*Master*/			}
/*Master*/			else
/*Master*/			{
/*Master*/				ulBERSlaveAddr = ulAddr;
/*Master*/			}
/*Master*/	
/*Master*/			break;
/*Master*/	
/*Master*/		case MC_ABORT_BER:
/*Master*/			//==============================================================================
/*Master*/			// Abort BER test.
/*Master*/			//		This command will halt the BER test if running.
/*Master*/			// 	uUartCommand[1] = slave address - high (0 = use uClosestSlave).
/*Master*/			// 	uUartCommand[2] = slave address - low  (0 = use uClosestSlave).
/*Master*/			//
/*Master*/			// The slave gets notified also so it will stop adding to stats.
/*Master*/			//
/*Master*/			//  txUserDataArray[0] = dest addr - high
/*Master*/			//  txUserDataArray[1] = dest addr - low
/*Master*/			//  txUserDataArray[2] = source addr - high
/*Master*/			//  txUserDataArray[3] = source addr - low
/*Master*/			//  txUserDataArray[4] = command number
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		SUCCESS/ERROR is returned here.  Details of the BER can be polled using
/*Master*/			//		the Get Master Configuration command.
/*Master*/			//==============================================================================
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);			// Acknowlege command.
/*Master*/			memset(txUserDataArray, 0, DATA_BUFFER_LEN*sizeof(txUserDataArray[0]));	
/*Master*/
/*Master*/			ulAddr = (u32)uUartCommand[1]*65536L + (u32)uUartCommand[2];
/*Master*/			if(ulAddr == 0L)				// Command[1] specifies slave address
/*Master*/			{								// 0L --> use "uClosestSlave"
/*Master*/				*(u32*)&txUserDataArray[0] = ulClosestSlaveAddr;
/*Master*/			}
/*Master*/			else								// else used passed arguement for slave addr
/*Master*/			{
/*Master*/				*(u32*)&txUserDataArray[0] = ulAddr;
/*Master*/			}
/*Master*/	
/*Master*/			*(u32*)&txUserDataArray[2] = ulMyAddr;
/*Master*/			txUserDataArray[4] = SC_ABORT_BER;	// Command number = SLAVE abort BER
/*Master*/			uTransmitPacketReady = 1;			// Send completed command to the SLAVE.
/*Master*/	
/*Master*/			uBerTestInProgress = 0;				// Stop sending packets.
/*Master*/			ulAutoPollCounter = 0L;
/*Master*/			uAutoPollPause=0;					// Release AutoPoll.
/*Master*/			break;
/*Master*/			
/*Master*/		case MC_WRITE_FLASH:
/*Master*/			//==============================================================================
/*Master*/			// Command:  Write Flash
/*Master*/			// 	uUartCommand[1] = Target device FLASH_TARGET_XXX (XXX=PROG, DATA, or MSP).
/*Master*/			// 	uUartCommand[2] = Number of BYTES to follow this command.
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		Nothing here.  The return is send in dsp_modem.c
/*Master*/			//==============================================================================
/*Master*/			uUartState = UART_RECEIVE_DATA;
/*Master*/			uFlashTarget = uUartCommand[1];
/*Master*/			uUartDataLength = uUartCommand[2];
/*Master*/			uUartDataIndex = 0;
/*Master*/			ulUartCounter = 0L;		// Reset timeout counter
/*Master*/			break;
/*Master*/
/*Master*/		case MC_READ_BLOCK:
/*Master*/			//==============================================================================
/*Master*/			// Command:  Read Block
/*Master*/			// 	uUartCommand[1] = Starting address.
/*Master*/			// 	uUartCommand[2] = Count (words) to read.
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		If the requested configuration parameter is valid, SUCCESS is returned
/*Master*/			//		for an acknowledge followed by the requested data
/*Master*/			//==============================================================================
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);
/*Master*/
/*Master*/			WriteUART(UART_TARGET_HOST, uUartCommand[2], (u16*) uUartCommand[1]);
/*Master*/
/*Master*/			ulAutoPollCounter = 0L;
/*Master*/			uAutoPollPause=0;		// Release AutoPoll.
/*Master*/			break;
/*Master*/			
/*Master*/		case MC_ERASE_FLASH:
/*Master*/			//==============================================================================
/*Master*/			// Command:  Erase Flash
/*Master*/			// 	uUartCommand[1] = Target device FLASH_TARGET_XXX (XXX=PROG, MSP).
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		Nothing here.  The return is send in dsp_modem.c
/*Master*/			//==============================================================================
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);
/*Master*/			uFlashTarget = uUartCommand[1];
/*Master*/			uFlashWriteStatus = FLASH_STATUS_ERASING;
/*Master*/			break;
/*Master*/
/*Master*/		case MC_READ_FLASH:
/*Master*/			//==============================================================================
/*Master*/			// Command:  Read Flash
/*Master*/			// 	uUartCommand[1] = Starting address - high.
/*Master*/			// 	uUartCommand[2] = Starting address - low.
/*Master*/			// 	uUartCommand[3] = Count (words) to read.
/*Master*/			//
/*Master*/			// return:
/*Master*/			// 		If the requested configuration parameter is valid, SUCCESS is returned
/*Master*/			//		for an acknowledge followed by the requested data
/*Master*/			//==============================================================================
/*Master*/			WriteUARTValue(UART_TARGET_HOST, SUCCESS);
/*Master*/
/*Master*/			ulAddr = (u32)uUartCommand[1]*65536L + (u32)uUartCommand[2];
/*Master*/			for(i=0; i<uUartCommand[3]; i++)
/*Master*/			{
/*Master*/				WriteUARTValue(UART_TARGET_HOST, ReadFlash(ulAddr++));
/*Master*/			}
/*Master*/
/*Master*/			ulAutoPollCounter = 0L;

⌨️ 快捷键说明

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