亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? flag0.c

?? TDK 6521 SOC 芯片 DEMO程序
?? C
?? 第 1 頁 / 共 3 頁
字號:
/***************************************************************************
 * 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. 
//  This code is a state machine that sends and receives messages.
//  The messages are interpreted and constructed using "templates."
//  The code was written once, tested, then ported to the other port
//  by copying the code, and including the other port's serial driver.
//  The message templates are byte-arrays stored in flag.c.
//  The input interrupt flag_in() steps through the message template.
//  The output interrupt flag_out() uses the message template to construct
//  the next character to send.
//  Whenever an input or output message is complete, the interrupt
//  calls the overall state machine, flag_state().
// 
//  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 && FLAG0
#include "calibration.h"
#include "irq.h"
#include "ce.h"
#include "flag.h" // shared parts, mostly message templates
#include "library.h"
#include "meter.h"
#include "sfrs.h"  // access to SFRs
#include "stm.h"

#define PORT 0

#if PORT==0
#include "ser0.h"
#include "flag0.h"
#endif

#if PORT==1
#include "ser1.h"
#include "flag1.h"
#endif

#define LOGGING 0

// Variables are not differentiated by direction of data motion
// because the protocol is "strictly half duplex"- it's not needed
static uint8x_t state; // the protocol state
static bool authorized; // got a valid password
static bool out; // 1 = transmitting is OK, 0 = receving is ok
static uint8x_t cur_char; // the current character
static uint8d_t t;  // temporary data (has to be "data" to read SFRs)
static uint8x_t bcc; // the checksum (longitudinal parity)
static uint8x_t error; // the current error status
static uint8x_t error_last_rcv; // the error of the last receved message
static uint8r_t *msg_ptr; // the current message
static uint8x_t msg_fld_index; // where it is in the current message
static uint8x_t msg_fld, msg_fld_next; // the data that should be at this place
static uint8x_t cmd, cmd_subtype; // the last command and subtype
static uint8x_t cmd_main;  // set in interrupt, cleared in main loop
static uint16x_t address;  // xdata memory address
static uint8x_t data_bit_index;  // where to put the next hex digit, usually
static uint8x_t hex_byte;  // the value of a byte
static uint8x_t char_cnt;  // req. characters...
static uint8x_t data_cnt;  // req. bytes...
static uint8x_t data_index;  // where to put the next data byte, usually
static uint8x_t data_buffer[MAX_DATA_INDEX + 1]; // Buffers data for writing
static STM      char_timer; // measures time between characters
static uint16x_t *session_timer;        // time till flag signs off


#if LOGGING != 1
#define log(_v_)
#else
uint8x_t log_data[16];
uint8d_t log_index;

// insert to the log
#pragma save
#pragma NOAREGS
void log (uint8_t val) small reentrant
{
   log_index = 0x0f & (++log_index);
   log_data[log_index] = val;
}
#pragma restore
#endif

// This starts the shared routines of the flag state machine

/* starts the character receive timeout */
#pragma save
#pragma NOAREGS
static void fail_char_timer (void) small reentrant
{
    error = CharTimeout;
    log(0x80);
    log(error);
    char_timer = NULL;
}
static void reset_char_timer (void) small reentrant
{
#if TIMERS
    if (char_timer != NULL)
    {
        *char_timer = CHAR_TIMEOUT;
    }
    else
    {
        char_timer = stm_start (CHAR_TIMEOUT, FALSE, fail_char_timer);
    }
#endif
}
#pragma restore

/* stops the character receive timeout */
#if TIMERS
#pragma save
#pragma NOAREGS
static void stop_char_timer (void) small reentrant
{
    if (char_timer != NULL) {
        stm_stop ( char_timer );
    }
    char_timer = NULL;
}
#pragma restore
#endif

/* starts the session timeout */
#if TIMERS
#pragma save
#pragma NOAREGS
static void fail_session_timer (void) small reentrant
{
    error = SessionTimeout;
    log(0x81);
    log(error);
    session_timer = NULL;
}
static void reset_session_timer (void) small reentrant
{
    if ( session_timer != NULL ) {
        *session_timer = SESSION_TIMEOUT;
    } else {
        session_timer = stm_start (SESSION_TIMEOUT, FALSE, fail_session_timer);
    }
}
#pragma restore
#endif

/* transmit- starts transmission a message */
#pragma save
#pragma NOAREGS
static void xmit(void) small reentrant
{
#if TIMERS
    stop_char_timer ();
#endif
    ser_disable_rcv_rdy(); // disable receive interrupt
    data_index = 0;  // where to put the next data byte, usually
    out = 1;
    log(0xFF);
    ser_xmit_on(); // power up or switch-in transmitter; xmit is not free
    ser_enable_xmit_rdy(); // enable transmit interrupt
}
#pragma restore

/* receive- starts receiving a message */
#pragma save
#pragma NOAREGS
static void recv(void) small reentrant
{
    #if TIMERS
    stop_char_timer ();
    reset_session_timer (); // start the session timer
    #endif
    
    ser_xmit_off(); // power off or switch-out transmitter; xmit is not free
    ser_disable_xmit_rdy(); // disable transmit interrupt
    out = 0;
    data_index = 0;  // where to put the next data byte, usually
    log(0xFE);
    ser_enable_rcv_rdy(); // enable receive interrupt
}
#pragma restore

// start transmitting an error
#pragma save
#pragma NOAREGS
static void xmit_error (void) small reentrant
{
    state = STATE_XMIT_ERR;
    msg_ptr = msg_err;
    xmit(); /* start transmitting a message */
}
#pragma restore

// request that the message be repeated
#pragma save
#pragma NOAREGS
static void xmit_nak (void) small reentrant
{
    state = STATE_XMIT_NAK;
    msg_ptr = msg_nak;
    xmit(); /* start transmitting a message */
}
#pragma restore

// start a new message
#pragma save
#pragma NOAREGS
static void new_msg (void) small reentrant
{
    msg_fld_index = 0;
    cmd = 0;
    cmd_subtype = 0; // the last command and subtype
    address = 0;  // default
    data_bit_index = 0;  // where to put the next hex digit, usually
    hex_byte = 0;  // the value of a byte
    char_cnt = 0;  // up to characters...
    data_cnt = 0;  // up to bytes...
    error = NoError;
    log(0x82);
    log(error);
}
#pragma restore

//  starting state; permits signing on
#pragma save
#pragma NOAREGS
static void sign_on (void) small reentrant
{
    ser_xmit_free ();  // free the transmit LED for pulsing 
    new_msg ();  // initialize the message variables
    authorized = FALSE;
    REG_LOCKED = FALSE;
    state = STATE_RCV_SIGN_ON;
    msg_ptr = msg_sign_on;
    recv(); /* start receiving a message */
    #if TIMERS
    if (session_timer != NULL) {
       stm_stop (session_timer);
    }
    session_timer = NULL;
    stop_char_timer ();
    #endif
}
#pragma restore

// acknowledge the previous message, so it is not retransmitted
#pragma save
#pragma NOAREGS
static void xmit_ack (void) small reentrant
{
    state = STATE_XMIT_ACK;
    msg_ptr = msg_ack;
    xmit(); /* start transmitting a message */
}
#pragma restore

/* the flag state machine- the one that selects which
 * messages to send and receive 
 * This machine runs when a message is complete, to 
 * determine the next message to send or receive.
 * The flag protocol is strictly half-duplex...
 * */

#pragma save
#pragma NOAREGS
// this copes with the received sign-on message
static void send_id (void) small reentrant
{
    if (error != NoError) {
       sign_on (); // enables receive, turns off timeouts
    } else {
       state = STATE_XMIT_ID;
       msg_ptr = msg_id;
       xmit(); // transmit a message, char timeout stops, restart msg timeout
    }
}
#pragma restore

#pragma save
#pragma NOAREGS
// STATE_XMIT_ID, next step of sign on
static void rcv_id_ack(void) small reentrant
{
   if (error != NoError) {
       sign_on (); // enables receive, turns off timeouts
   } else {
       new_msg(); // clear old message data
       state = STATE_RCV_ID_ACK;
       msg_ptr = msg_ack_id;
       recv(); // enables receive, and character time out 
   }
}
#pragma restore

#pragma save
#pragma NOAREGS
// STATE_RCV_ID_ACK, receive the ack of the ID
static void send_password (void) small reentrant
{

    error_last_rcv = error;

    error = NoError;
    log(0x83);
    log(error);

    switch (error_last_rcv)
    {
    case NoError:
        state = STATE_XMIT_PASSWORD_OPERAND;
        msg_ptr = msg_P0;
        xmit(); // transmit msg, char timeout stops, restart msg timeout
        break;
    case AuthorizationBad: // is Y = 1?
    default: // any data or message errors?
        state = STATE_XMIT_EMPTY_READOUT;
        msg_ptr = msg_nak_ack_id;
        xmit(); // transmit msg, char timeout stops, restart msg timeout
        break;
    case ParityBad:
    case ChecksumBad:
        sign_on ();
        break;
    }
}
#pragma restore

#pragma save
#pragma NOAREGS
// prepare to receive a command
static void get_cmd (void) small reentrant // after data is xmitted
{
    new_msg ();
    state = STATE_RCV_COMMAND;
    msg_ptr = msg_cmd;
    recv(); /* start receiving a message */
}
#pragma restore

#pragma save
#pragma NOAREGS
static void do_cmd_after_ack (void) small reentrant // STATE_XMIT_ACK
{
    // perform commands that have to finish after acknowledge
    // This is where a change of baud rate should occur
    while (cmd == 'Z') {
        EA = 0; // disable interrupts, force watchdog reset
    }

    get_cmd ();
}
#pragma restore

#pragma save
#pragma NOAREGS
// STATE_RCV_COMMAND, after a command is received, act on it
static void do_cmd (void) small reentrant
{
    // the error status is from a received message
    error_last_rcv = error; // save it
    error = NoError;
    log(0x84);
    log(error);
    // errors override commands
    // See the no-error case for the commands
    switch (error_last_rcv)
    {
    default:
    case AuthorizationBad: // checked when the C field is received
    case CommandBad: // checked when the D field is received
    case DataBad: // checked by the data and address field
    case MessageBad: // unexpected format checked by default
        xmit_error (); // transmit error, char timeout off, msg timeout st.
        break;
    case ParityBad: // checked by the serial driver
    case ChecksumBad: // checked by BCC field
    case CharTimeout: // checked by a timer
    case SessionTimeout: // checked by a timer
        xmit_nak (); // transmit nak, char timeout off, msg timeout st.
        break;
    case NoError:
    case PasswordBad: // checked by default
        switch (cmd) // interpret a command
        {
        default: // unknown command
            error_last_rcv = CommandBad;
            xmit_error (); // char timeout off, msg timeout restarts
            break;
        case 'U': // update command (nonstandard)
            if (REG_SOURCE_OK)
            {
                cmd_main = cmd; // ask the main loop routine to do this
                xmit_ack (); // char timeout off, msg timeout restarts
            } else {
                xmit_nak (); // char timeout off, msg timeout restarts
            }
            break;
        #if CAL_SAVE
        case 'C': // save calibration (nonstandard)
            cmd_main = cmd; // ask the main loop routine to do this
            xmit_ack (); // char timeout off, msg timeout restarts
            break;
        #endif
        case 'Z': // reset (nonstandard)
            xmit_ack (); // have to send the ack before resetting
            break;
        case 'B': // break, i.e. cease communicating
            sign_on (); // enable receive, all timeouts off
            break;
        case 'P': // password validation
            if (error_last_rcv == PasswordBad) {
                authorized = FALSE;
                state = STATE_XMIT_BREAK;
                msg_ptr = msg_B0;
                xmit(); // transmit msg, char timeout off, msg timeout st.
                break;
            }
            authorized = TRUE;
            REG_LOCKED = TRUE; // stop background updates
            xmit_ack (); // char timeout off, msg timeout restarts

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产一区二区三区香蕉| 国产精品久久久久一区二区三区共 | 中文字幕乱码一区二区免费| 欧美成人精品3d动漫h| 欧美高清激情brazzers| 欧美日产在线观看| 911精品国产一区二区在线| 欧美性猛交xxxx黑人交| 在线观看视频91| 欧美日韩一区在线| 欧美麻豆精品久久久久久| 欧美高清视频一二三区 | 99视频有精品| 99久久久国产精品免费蜜臀| 99久久er热在这里只有精品66| eeuss影院一区二区三区| 99re亚洲国产精品| 在线亚洲高清视频| 欧美日韩在线直播| 日韩视频一区二区三区| 精品国产91久久久久久久妲己| 精品国产污污免费网站入口 | 国产精品激情偷乱一区二区∴| 国产精品久久久久久久久免费桃花| 国产精品的网站| 亚洲一区二区三区国产| 天天影视涩香欲综合网| 老司机精品视频在线| 狠狠色丁香久久婷婷综| 丁香网亚洲国际| 91黄色免费看| 日韩午夜电影av| 欧美国产日产图区| 亚洲自拍偷拍麻豆| 蜜臀av一区二区在线观看| 国产99久久久国产精品| 色狠狠色噜噜噜综合网| 日韩一区二区在线看片| 国产欧美中文在线| 亚洲成人第一页| 国产一区二区三区在线看麻豆| 不卡的av电影在线观看| 欧美乱妇15p| 久久精品日韩一区二区三区| 亚洲精品国产一区二区精华液 | 国产精品乱码久久久久久| 亚洲免费伊人电影| 久久精品国产免费看久久精品| 国产电影精品久久禁18| 欧美特级限制片免费在线观看| 日韩欧美国产系列| ㊣最新国产の精品bt伙计久久| 手机精品视频在线观看| 成人白浆超碰人人人人| 3d动漫精品啪啪1区2区免费 | 国产福利精品导航| 欧美在线视频不卡| 久久精品夜色噜噜亚洲aⅴ| 亚洲激情av在线| 国模娜娜一区二区三区| 在线观看视频一区| 国产肉丝袜一区二区| 天堂成人免费av电影一区| 成人免费三级在线| 欧美一区二区三区免费大片| 亚洲色图在线播放| 国产精品白丝jk白祙喷水网站| 欧美三级电影在线看| 国产拍欧美日韩视频二区| 免费不卡在线观看| 欧美日韩一区二区在线观看视频 | 三级成人在线视频| 99久久婷婷国产综合精品| 欧美一二三在线| 一区二区三区在线看| 成人午夜视频福利| 亚洲精品一区二区在线观看| 午夜婷婷国产麻豆精品| 色综合色综合色综合| 国产视频在线观看一区二区三区 | 9久草视频在线视频精品| 久久夜色精品一区| 青娱乐精品在线视频| 欧美在线视频你懂得| 亚洲蜜臀av乱码久久精品蜜桃| 国产高清在线观看免费不卡| 日韩亚洲国产中文字幕欧美| 视频一区二区国产| 欧美日韩一区二区三区四区五区| 中文字幕一区二区在线观看| 成人一级片在线观看| 久久久久久久网| 国产综合久久久久久鬼色| 日韩一二在线观看| 免费成人在线观看视频| 日韩片之四级片| 青青青伊人色综合久久| 欧美一区二区网站| 青青草精品视频| 日韩一级大片在线| 激情丁香综合五月| 久久一区二区三区四区| 国产一区二区三区国产| 久久午夜国产精品| 国产伦精一区二区三区| 久久亚洲二区三区| 国产成人免费网站| 国产精品免费人成网站| 成人a区在线观看| 亚洲丝袜美腿综合| 91国产丝袜在线播放| 亚洲国产一二三| 欧美精品v日韩精品v韩国精品v| 午夜一区二区三区在线观看| 欧美麻豆精品久久久久久| 美女脱光内衣内裤视频久久影院| 欧美日韩成人在线| 精品中文av资源站在线观看| 久久久青草青青国产亚洲免观| 国产v综合v亚洲欧| 亚洲少妇屁股交4| 欧美图片一区二区三区| 久久精品国产一区二区三| 精品对白一区国产伦| 国产精品中文字幕欧美| 国产精品久线观看视频| 色狠狠色狠狠综合| 免费高清视频精品| 国产精品久线观看视频| 欧美在线综合视频| 精品无码三级在线观看视频| 国产亚洲成年网址在线观看| 99国产精品国产精品毛片| 午夜精品一区二区三区免费视频 | 欧美一级免费大片| 国产呦精品一区二区三区网站| 中文字幕国产一区二区| 日本韩国一区二区三区| 奇米影视7777精品一区二区| 国产午夜精品一区二区| 欧美少妇xxx| 国产一区二区电影| 亚洲精品写真福利| 欧美成人三级电影在线| 91在线观看美女| 奇米精品一区二区三区在线观看一| 久久精品人人爽人人爽| 欧美在线观看禁18| 国产尤物一区二区在线| 亚洲在线视频一区| 久久亚洲一级片| 欧美性大战久久久久久久蜜臀| 激情成人综合网| 亚洲国产精品精华液网站| 久久久综合精品| 欧美日免费三级在线| 国产成人在线影院| 日韩成人伦理电影在线观看| 国产精品九色蝌蚪自拍| 精品美女在线播放| 欧美唯美清纯偷拍| 国产电影精品久久禁18| 秋霞av亚洲一区二区三| 亚洲欧美日韩中文播放| 亚洲精品一区二区三区在线观看| 色婷婷久久久综合中文字幕 | 久久九九影视网| 欧美一区二区三区四区视频| 99国产精品视频免费观看| 国产美女一区二区三区| 天天综合天天做天天综合| 亚洲欧美影音先锋| 久久亚洲精精品中文字幕早川悠里 | 国产精品中文欧美| 日韩国产欧美视频| 亚洲精品成a人| 久久青草欧美一区二区三区| 欧美精品久久久久久久多人混战 | 色综合中文综合网| 精品粉嫩超白一线天av| 欧美日韩精品一区视频| 91免费观看在线| 成人污污视频在线观看| 精品夜夜嗨av一区二区三区| 性做久久久久久久久| 亚洲欧美怡红院| 国产精品美日韩| 久久久久久久综合色一本| 精品国精品国产尤物美女| 欧美二区在线观看| 欧美性生交片4| 色婷婷久久久综合中文字幕| 成人高清视频在线观看| 东方欧美亚洲色图在线| 国产精品一二三四五| 国内一区二区在线| 美腿丝袜在线亚洲一区| 日本不卡一区二区三区高清视频| 午夜久久电影网| 日本午夜精品一区二区三区电影|