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

📄 flag.c

📁 TDK 6521 SOC 芯片 DEMO程序
💻 C
字号:
/***************************************************************************
 * This code and information is provided "as is" without warranty of any   *
 * kind, either expressed or implied, including but not limited to the     *
 * implied warranties of merchantability and/or fitness for a particular   *
 * purpose.                                                                *
 *                                                                         *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 ***************************************************************************/
//**************************************************************************
//    
//  DESCRIPTION: 71M652x POWER METER - FLAG protocol. 
// 
//  AUTHOR:  RGV
//
//  HISTORY: See end of file
//
//**************************************************************************
//               
// File: flag.c
//               
//**************************************************************************
// This file is the shared logic of all the flag interfaces on a meter.
// This flag protocol is a simplified subset, with fixed baud rates, 
// a fixed password and only a few commands.
// To use this file, include it after including a serial hardware abstraction
// layer.  See flag0.c and ser0.h for an example.

#include "options.h"
#if FLAG
#include "ce.h"
#include "flag.h"
#include "meter.h"

// This begins the list of messages

// initial message from HHU to meter
uint8r_t msg_sign_on[] =
{ '/', '?', DEVICE_ADDRESS, '!', CR, LF, END };

// meter identifies itself to the HHU
// In an HHU, FLAG_ID would become ID
uint8r_t msg_id[] =
{ '/', 'T', 'D', 'K', Z, FLAG_ID, CR, LF, END };

// HHU acknowledges meter's identification
uint8r_t msg_ack_id[] =
{ ACK, '0', Z, Y, CR, LF, END };

// meter responds to HHU's acknowledge of meter's identification
uint8r_t msg_nak_ack_id[] =
{ STX, BEGIN_BCC, '(', ')', '!', ETX, BCC, END };

// ACK
uint8r_t msg_ack[] = { ACK, END }; 

// NAK
uint8r_t msg_nak[] = { NAK, END };

// meter sends an error message
uint8r_t msg_err[] =
{ STX, BEGIN_BCC, 'E', 'R', 'R', ERROR, ETX, BCC, END };

// meter sends a data message
uint8r_t msg_data[] =
{ STX, BEGIN_BCC, '(', HEX_DATA, ')', ETX, BCC, END };

// basic form of a command
uint8r_t msg_cmd[] =
{ SOH, BEGIN_BCC, C, D,
    STX, DATA_ADDRESS, '(', HEX_DATA, ')', ETX, BCC, END };

// an "EXIT B" command
uint8r_t msg_B0[] =
{ SOH, BEGIN_BCC, 'B', '0', ETX, BCC, END };

// password operand command
uint8r_t msg_P0[] =
{ SOH, BEGIN_BCC, 'P', '0',
    STX, '(', 'T', 'D', 'K', ')', ETX, BCC, END };

// password receive
uint8r_t msg_P1[] =
{ SOH, BEGIN_BCC, 'P', '1',
    STX, '(', 'T', 'D', 'K', ')', ETX, BCC, END };

uint8r_t msg_R1[] = // read up to 128 items
{ SOH, BEGIN_BCC, 'R', '1',
    STX, DATA_ADDRESS, '(', DATA_COUNT, ')', ETX, BCC, END };

uint8r_t msg_W1[] = // write up to 128 items
{ SOH, BEGIN_BCC, 'W', '1',
    STX, DATA_ADDRESS, '(', HEX_DATA, ')', ETX, BCC, END };

// start of TDK's nonstandard command message types
uint8r_t msg_U0[] = // message to update the data
{ SOH, BEGIN_BCC, 'U', '0', ETX, BCC, END };

uint8r_t msg_C0[] = // message to save the calibration
{ SOH, BEGIN_BCC, 'C', '0', ETX, BCC, END };

uint8r_t msg_Z0[] = // message to reset meter
{ SOH, BEGIN_BCC, 'Z', '0', ETX, BCC, END };

// end of TDK's nonstandard command message types

// This array is searched backward
// by the command subtype
// to find a valid message template
#define CMD_FLD_INDEX 2
#define CMD_SUBTYPE_FLD_INDEX 3
#define MAX_MSG_INDEX 7
const uint8r_t * code msg_ptr_array[MAX_MSG_INDEX + 1] =
{
msg_cmd, // default command (failure)
msg_U0, // message to update data
msg_B0, // break command
msg_P1, // message to set password
msg_W1, // message to write data
msg_Z0, // message to reset meter
msg_C0, // message to save calibration
msg_R1 // message to read data (keep at end to find off-by one errors)
};

#endif // FLAG.

/***************************************************************************
 *  $Log: flag.c,v $
 *  Revision 1.7  2006/07/22 01:32:19  tvander
 *  Fopund some lurking xdata arrays that needed to be in code space.
 *
 *  Revision 1.6  2006/03/06 03:29:43  Michael T. Fischer
 *  More 6530 prep.
 *
 *  Revision 1.5  2005/09/22 23:45:00  tvander
 *  Clean build all models and unit tests, updated copyright to be fore Teridian
 *
 *  Revision 1.4  2005/09/01 02:02:46  gmikef
 *  Cleaned up the builds.
 *
 *  Revision 1.3  2005/08/28 02:10:55  gmikef
 *  *** empty log message ***
 *
 *  Revision 1.2  2005/08/19 01:04:38  gmikef
 *  *** empty log message ***
 *
 *  Revision 1.1  2005/05/27 23:27:44  tvander
 *  Table-driven flag, verified large (64 byte) transfers and calibration command.
 *
 *  Revision 1.10  2005/05/26 21:54:36  tvander
 *  Flag is grossly working with GUI: signs on, reads, writes both xdata and idata, interlocks with CE cycle, and timeouts work.
 *
 *  Revision 1.9  2005/05/21 01:47:39  gmikef
 *  *** empty log message ***
 *
 *  Revision 1.8  2005/05/19 00:49:04  tvander
 *  Flag0 verified to compile without calibration flag.
 *
 *  Revision 1.7  2005/05/18 22:42:52  tvander
 *  Added second FLAG interface
 *
 *  Revision 1.6  2005/05/18 22:23:55  tvander
 *  Successfully signed on with an HHU
 *
 *  Revision 1.5  2005/05/14 00:56:18  tvander
 *  Integrated flag0, ser0
 *  Regression tested and fixed 6521b
 *
 *  Revision 1.4  2005/04/22 21:40:08  tvander
 *  Major revision- it works pretty well.
 *
 *  Revision 1.3  2005/04/19 18:08:13  tvander
 *  First working flag interface.
 *
 *  Revision 1.2  2005/04/07 21:25:50  tvander
 *  Gotos removed
 *
 *  Revision 1.1  2005/04/06 23:02:49  tvander
 *  First valid compile of flag
 *
 *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 * this program is fully protected by the United States copyright          *
 * laws and is the property of Teridian Semiconductor Corporation.         *
 ***************************************************************************/

⌨️ 快捷键说明

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