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

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

?? flag1.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 && FLAG1
#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 1

#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精品国产综合久久久久久| 一区二区三区91| 日韩欧美在线影院| 欧美日韩日日夜夜| 欧美日韩一区二区欧美激情| 91影院在线观看| 91美女蜜桃在线| 在线免费一区三区| 欧美视频三区在线播放| 欧美亚洲综合另类| 在线观看不卡视频| 欧美视频一区二| 91精品国产一区二区人妖| 欧美一区二区三级| 精品毛片乱码1区2区3区| 26uuu亚洲| 久久免费看少妇高潮| 久久女同互慰一区二区三区| 久久久www成人免费无遮挡大片| 26uuu国产日韩综合| 国产亚洲欧洲997久久综合 | 亚洲图片欧美激情| 亚洲国产精品成人综合| 亚洲免费资源在线播放| 洋洋成人永久网站入口| 日本欧美在线观看| 国产成人啪免费观看软件| 成人免费电影视频| 欧美少妇性性性| 日韩免费观看2025年上映的电影| wwwwww.欧美系列| 亚洲欧美综合网| 亚洲国产日产av| 黑人精品欧美一区二区蜜桃 | 在线播放亚洲一区| 精品欧美乱码久久久久久1区2区| 欧美激情在线一区二区三区| 亚洲日本乱码在线观看| 亚洲国产wwwccc36天堂| 狠狠色丁香久久婷婷综合_中| 成人av网址在线| 欧美精品一二三| 久久久亚洲精华液精华液精华液| 成人欧美一区二区三区在线播放| 亚洲成人av在线电影| 激情亚洲综合在线| 精品美女一区二区三区| 欧美国产成人精品| 午夜欧美一区二区三区在线播放| 精东粉嫩av免费一区二区三区 | 久久久99久久精品欧美| 一区二区三区美女| 国产专区欧美精品| 91高清视频免费看| 久久噜噜亚洲综合| 亚洲成人av一区二区三区| 国产乱一区二区| 欧美日韩在线三区| 中文字幕 久热精品 视频在线| 亚洲成在线观看| 成人激情免费视频| 欧美一区二区三区男人的天堂| 国产精品污网站| 奇米一区二区三区| 91成人国产精品| 国产日韩欧美亚洲| 日日夜夜免费精品视频| 成人a级免费电影| 精品欧美一区二区久久| 亚洲成av人片在线| av在线免费不卡| 精品黑人一区二区三区久久 | 国产成人免费视频精品含羞草妖精| 欧美在线短视频| 国产精品国产三级国产三级人妇| 久久精品久久精品| 在线播放中文一区| 亚洲午夜免费福利视频| av动漫一区二区| 国产日韩欧美a| 麻豆成人久久精品二区三区红| 在线观看91视频| 自拍偷拍欧美精品| 成人精品亚洲人成在线| 久久久久国产精品麻豆ai换脸| 日本不卡123| 精品视频1区2区| 亚洲免费在线看| 91丨porny丨最新| 中文字幕第一页久久| 韩国成人精品a∨在线观看| 欧美一区二视频| 午夜精品视频在线观看| 日本韩国一区二区三区视频| 国产精品青草久久| 国产宾馆实践打屁股91| 久久丝袜美腿综合| 国产一区二区美女| 久久伊99综合婷婷久久伊| 奇米色777欧美一区二区| 欧美日韩亚洲综合在线| 亚洲综合免费观看高清在线观看| 99re亚洲国产精品| 日韩毛片视频在线看| 91在线你懂得| 亚洲人成网站精品片在线观看| 高清免费成人av| 国产精品久久久久影院| 成人av在线资源网| 综合中文字幕亚洲| 在线日韩av片| 日韩中文字幕亚洲一区二区va在线| 欧美日韩一区二区三区视频| 亚洲国产精品久久艾草纯爱| 欧美日韩三级一区| 久久精品国产在热久久| 日韩一级免费观看| 国产又粗又猛又爽又黄91精品| 日韩视频永久免费| 国产精品一区一区三区| 国产欧美日产一区| 91同城在线观看| 亚洲精品视频免费观看| 欧美视频完全免费看| 日本中文在线一区| 久久人人超碰精品| 成人黄页毛片网站| 亚洲精品免费在线播放| 欧美巨大另类极品videosbest | 久久综合九色欧美综合狠狠| 国产电影一区在线| 亚洲人成人一区二区在线观看 | 全部av―极品视觉盛宴亚洲| 日韩欧美一级精品久久| 国产精品1区2区| 一区二区三区加勒比av| 91精品国产高清一区二区三区蜜臀 | 亚洲黄色在线视频| 91精品国产一区二区三区蜜臀| 国产美女精品人人做人人爽| 国产精品久久久久天堂| 欧美手机在线视频| 国产一区二区三区黄视频 | 亚洲一区二区在线免费看| 日韩无一区二区| 成人黄页毛片网站| 肉色丝袜一区二区| 国产精品久久久久久久久久久免费看 | 欧美系列在线观看| 麻豆精品久久精品色综合| 国产亲近乱来精品视频| 在线观看欧美日本| 看电视剧不卡顿的网站| 综合激情网...| 欧美一区二区大片| 色综合一区二区三区| 美国精品在线观看| 亚洲精品免费播放| 久久中文字幕电影| 欧美日韩一区三区四区| 国产成人欧美日韩在线电影| 偷拍日韩校园综合在线| 国产日韩欧美高清在线| 在线电影国产精品| 99精品桃花视频在线观看| 美国三级日本三级久久99| 一区二区三区在线看| 国产亚洲午夜高清国产拍精品 | 2021久久国产精品不只是精品| 日本乱码高清不卡字幕| 国产精品一区二区在线观看不卡 | 麻豆精品国产传媒mv男同| 亚洲欧美一区二区久久| 久久久久久亚洲综合影院红桃| 欧美日本韩国一区| 99精品久久99久久久久| 激情成人综合网| 日本亚洲天堂网| 亚洲精选视频免费看| 国产精品三级久久久久三级| 91麻豆精品国产无毒不卡在线观看| eeuss鲁片一区二区三区| 国产精品一区二区视频| 日韩激情一二三区| 亚洲一区二区三区影院| 中文字幕一区二区5566日韩| 久久日韩精品一区二区五区| 欧美一级午夜免费电影| 欧美日韩精品三区| 色综合久久99| 99久久精品免费看国产免费软件| 国产精品1区2区| 国产美女av一区二区三区| 老司机精品视频一区二区三区| 亚洲国产精品久久艾草纯爱 | 国内精品在线播放| 裸体在线国模精品偷拍| 青青国产91久久久久久| 偷拍一区二区三区四区| 天天色天天操综合|