亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国产真实乱偷精品视频免| 欧美日高清视频| 欧美三片在线视频观看| 久久亚洲欧美国产精品乐播 | 一区二区三区在线看| 日韩精品成人一区二区三区| 成人黄页在线观看| 日韩美女一区二区三区四区| 一区二区三区.www| 成人av一区二区三区| 欧美精品一区在线观看| 视频在线观看国产精品| 91在线国产观看| 国产色91在线| 麻豆国产91在线播放| 欧美日韩第一区日日骚| 亚洲欧美在线另类| 国产99一区视频免费| 欧美r级在线观看| 日韩成人午夜电影| 欧美日韩精品系列| 亚洲曰韩产成在线| 99re在线精品| 中文字幕一区二区不卡| 成人免费看片app下载| 久久久精品tv| 国产在线视频一区二区| 日韩亚洲电影在线| 水野朝阳av一区二区三区| 69精品人人人人| 亚洲成a人片在线不卡一二三区| 色国产综合视频| 亚洲精品一二三四区| 91原创在线视频| 国产精品理论在线观看| 国产91在线|亚洲| 欧美激情综合五月色丁香小说| 国产一区二区三区视频在线播放| 日韩一区二区三区视频| 麻豆成人在线观看| 精品国产免费一区二区三区四区 | 久久久99免费| 国产.欧美.日韩| 中文字幕视频一区二区三区久| 成人精品国产免费网站| 中文在线资源观看网站视频免费不卡 | 天天综合日日夜夜精品| 欧美性大战久久久| 亚洲成人一区在线| 日韩欧美美女一区二区三区| 黑人巨大精品欧美一区| 国产精品久久久久久久第一福利| 91视视频在线观看入口直接观看www | 精品国产欧美一区二区| 国产福利91精品一区二区三区| 国产欧美一区二区精品性色 | 日韩一级黄色片| 国产在线精品一区二区夜色 | 日韩不卡一区二区| 久久久无码精品亚洲日韩按摩| 粉嫩av亚洲一区二区图片| 亚洲视频免费看| 欧美一区二区三区系列电影| 国产剧情一区二区| 亚洲欧美国产77777| 欧美色综合影院| 精品一区二区久久久| 国产精品久线在线观看| 欧美日韩国产一区| 国产一区二区不卡| 亚洲一区在线电影| 精品不卡在线视频| 91国产丝袜在线播放| 老汉av免费一区二区三区| 国产精品福利一区二区三区| 欧美精品日韩精品| 大胆亚洲人体视频| 日本午夜精品一区二区三区电影 | 精品成a人在线观看| 日本韩国一区二区三区| 狠狠色丁香久久婷婷综合丁香| 一区二区三区在线视频免费| 精品国产亚洲在线| 欧美日精品一区视频| 成人丝袜高跟foot| 琪琪一区二区三区| 亚洲黄一区二区三区| 久久你懂得1024| 337p亚洲精品色噜噜噜| 成人黄色在线看| 激情六月婷婷久久| 国产在线精品一区二区三区不卡 | 国产精品每日更新| 日韩欧美亚洲国产精品字幕久久久| 不卡视频一二三| 国内不卡的二区三区中文字幕 | 国产高清不卡一区二区| 日韩av在线免费观看不卡| 玉米视频成人免费看| 欧美国产激情二区三区| 精品成人a区在线观看| 日韩一区二区在线观看视频| 欧美日韩视频在线第一区 | 国产精品18久久久久久久久久久久| 亚洲一卡二卡三卡四卡| 亚洲人成影院在线观看| 中文天堂在线一区| 亚洲国产精品v| 国产日韩高清在线| 国产日韩欧美综合一区| 2023国产一二三区日本精品2022| 欧美一区二区三区四区高清| 欧美视频日韩视频在线观看| 欧美日韩一区在线观看| 欧美图片一区二区三区| 欧美三级三级三级爽爽爽| 91国产免费看| 欧美日韩国产a| 欧美理论电影在线| 欧美亚洲禁片免费| 欧美日韩美少妇| 3d动漫精品啪啪一区二区竹菊| 欧美久久久一区| 91精品国产91综合久久蜜臀| 5月丁香婷婷综合| 日韩欧美国产电影| 精品国产伦一区二区三区观看体验| 日韩区在线观看| 精品国产91久久久久久久妲己| 久久久久久久久岛国免费| 久久天堂av综合合色蜜桃网| 国产精品丝袜久久久久久app| 国产精品乱人伦一区二区| 1区2区3区精品视频| 一区二区三区四区在线免费观看| 亚洲美女电影在线| 波多野结衣91| 欧美亚洲国产一区在线观看网站| 欧美性色综合网| 精品国内二区三区| 国产精品视频线看| 亚欧色一区w666天堂| 国产一区激情在线| 91视频一区二区三区| 欧美精品免费视频| 国产精品天干天干在线综合| 亚洲综合一区二区| 久久99国产乱子伦精品免费| 风流少妇一区二区| 在线观看亚洲专区| 欧美xxx久久| 亚洲精品国产无天堂网2021| 久久国产麻豆精品| kk眼镜猥琐国模调教系列一区二区| 欧美日韩一区小说| 久久精品人人做人人综合| 亚洲美女区一区| 麻豆精品精品国产自在97香蕉| www.亚洲激情.com| 欧美一区二区网站| 综合色天天鬼久久鬼色| 日本不卡的三区四区五区| 不卡在线视频中文字幕| 欧美久久久久久久久久| 中文字幕在线不卡一区| 日韩国产欧美一区二区三区| 暴力调教一区二区三区| 日韩欧美资源站| 亚洲韩国精品一区| 不卡一区二区中文字幕| 精品国产a毛片| 五月天激情小说综合| 色天使久久综合网天天| 久久久久久久久久久黄色| 日本中文字幕一区二区有限公司| av资源网一区| 国产区在线观看成人精品| 麻豆精品久久精品色综合| 欧美日韩一区二区在线观看| 国产精品视频一二三区| 狠狠色综合色综合网络| 欧美精选午夜久久久乱码6080| 日韩美女视频一区| zzijzzij亚洲日本少妇熟睡| 国产亚洲一区二区三区在线观看| 日韩av不卡一区二区| 欧美色区777第一页| 亚洲最大成人综合| 99久久99久久免费精品蜜臀| 国产精品天干天干在观线| 国产v日产∨综合v精品视频| 精品国偷自产国产一区| 久久精品二区亚洲w码| 欧美一区二区在线播放| 日韩二区三区四区| 欧美一级搡bbbb搡bbbb| 日本不卡免费在线视频| 欧美一区二区三区不卡| 麻豆精品一区二区三区| 精品成人佐山爱一区二区|