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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? level3.c

?? EM4094示例Firmware
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
*-------------------------------------------------------------------------------
*--  RCSId: $Id: level3.c,v 1.33 2004-06-30 12:47:41+02 mjg Exp mjg $
*--         $Name:  $
*-------------------------------------------------------------------------------
*-- level3.c - High level data transformations and main loop 
*-------------------------------------------------------------------------------
*-- $Log: level3.c,v $*-- Revision 1.33  2004-06-30 12:47:41+02  mjg*-- key selection extension*--
*-- Revision 1.32  2004-05-31 16:41:51+02  mjg
*-- single carrier too slow caused CRC errors, speeded up
*--
*-- Revision 1.31  2004-05-21 09:29:37+02  mjg
*-- startup inventory, to toggle EAS off for EM4034
*--
*-- Revision 1.30  2004-05-10 09:23:28+02  mjg
*-- to toggle EAS off
*--
*-- Revision 1.29  2004-05-07 08:10:25+02  mjg
*-- HW auth passed
*--
*-- Revision 1.28  2004-04-27 17:05:44+02  mjg
*-- to better test the design
*--
*-- Revision 1.27  2004-04-21 15:48:47+02  mjg
*-- FSK low data rate support
*--
*-- Revision 1.26  2004-04-21 13:05:21+02  mjg
*-- EOF ignored because of FSK and 4034 support
*--
*-- Revision 1.25  2004-04-13 11:21:39+02  mjg
*-- sync
*--
*-- Revision 1.24  2004-03-25 16:09:19+01  mjg
*-- to add delayed EOF feature
*--
*-- Revision 1.23  2004-03-25 15:13:23+01  mjg
*-- to add delayed EOF feature
*--
*-- Revision 1.22  2004-03-24 13:35:36+01  mjg
*-- error msg needs better handling
*--
*-- Revision 1.21  2004-03-15 16:59:06+01  mjg
*-- to check SPI
*--
*-- Revision 1.20  2004-02-16 08:04:11+01  mjg
*-- preliminary CD
*--
*-- Revision 1.18  2004-02-10 19:24:40+01  mjg
*-- FSK to add valid bits
*--
*-- Revision 1.17  2004-02-10 18:30:46+01  mjg
*-- dual carrier raw, decoded 1st try
*--
*-- Revision 1.16  2004-02-09 18:03:33+01  mjg
*-- raw dual carrier capture
*--
*-- Revision 1.15  2004-02-08 12:30:52+01  mjg
*-- Decode var removed, FSK polling added
*--
*-- Revision 1.14  2004-02-07 14:59:47+01  mjg
*-- Response parsing correction
*--
*-- Revision 1.13  2004-02-03 08:42:52+01  mjg
*-- hubneme II
*--
*-- Revision 1.12  2004-02-03 07:24:37+01  mjg
*-- fwd debug implemented and removed from being compiled
*--
*-- Revision 1.11  2004-01-19 14:08:05+01  mjg
*-- hubneme I
*--
*-- Revision 1.10  2004-01-14 14:57:35+01  mjg
*-- to Invenotry version 2
*--
*-- Revision 1.9  2003-12-11 17:37:20+01  mjg
*-- yes
*--
*-- Revision 1.8  2003-12-11 16:33:41+01  mjg
*-- 1TS gives too much responses, stayquiet ?
*--
*-- Revision 1.7  2003-12-10 08:15:48+01  mjg
*-- to add dbg code
*--
*-- Revision 1.6  2003-12-09 12:43:01+01  mjg
*-- to 1TS inventory
*--
*-- Revision 1.5  2003-12-09 12:42:44+01  mjg
*-- to 1TS inventory
*--
*-- Revision 1.3  2003-12-05 08:38:56+01  mjg
*-- write update
*--
*-- Revision 1.2  2003-12-04 15:58:08+01  mjg
*-- to write
*--
*-- Revision 1.1  2003-12-01 08:18:04+01  mjg
*-- single carrier low drate level1 ok
*--
*-- Revision 1.0  2003-11-26 09:01:02+01  mjg
*-- Initial revision
*--
*-------------------------------------------------------------------------------
*/


#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/wdt.h>
#include "level4.h"
#include "level3.h"
#include "level2.h"
#include "level1.h"

//--------------------------------------------------------------
//global variables

uint8_t maxCaptureTimeLow;           //lower part of current maximum capture time (used to initialise TCNT1)
uint8_t maxCaptureTimeHi;            //upper part of current maximum capture time (expected value 0xFF or 0xFE only)

//register uint8_t capture_cnt asm ("r8");        //store_bit current capture byte index (this is a mirror from main.c)

//--------------------------------------------------------------
//local declarations

#define STD_WAIT 145                  //~318us = (145+13)x32 @ 16MHz , 13x32 uC clocks is a setup reserve

uint8_t clean_data_cnt;               //clean response data length

//uint16_t maxTRead;                    //current datarate maximum response capture time
uint16_t maxTGeneral;                 //current datarate maximum response capture time
uint16_t maxTwa1ee;                   //

uint8_t signed_crc;                   //flag of signed response

void SendCaptureData( uint8_t cmd, uint8_t ack );
void Send(uint8_t len, uint16_t wait_time);
void Compute_Timeouts( uint8_t flags );

uint8_t Inventory(void);
uint8_t HW_Authentication(void);
uint8_t ToggleEAS(void);
uint8_t GeneralRead(void);

//--------------------------------------------------------------
// main loop routine
//--------------------------------------------------------------

void main_receiver(void) {
  uint8_t check_stat;
  uint8_t fwd_bit_count;
  uint8_t i;

  if (watchdog_reset != 0) {
    FormatResponse_Short( 0x00, ERR_ASIC_ANTENNA_FAULT );
  } else {
    decode_number = 2;
    forward_link_type = 0x01;            //default value = 1 from 4 forward link    
    counter1set = (1<<ICNC1) | (1<<CS10);
  }

  enable_capture = 0;

  while (21) {                              // infinite loop

    wdt_reset();                            // reset the watchdog

    if((check_stat = CheckIncommingMessage()) != UART_MESSAGE_OK)     // check any incoming message
      FormatResponse_Short( 0, check_stat );
    else {                                                            // no error, processing command

      forward_ptr = data_buffer;            // initialize fwd pointer
      fwd_bit_count = 0;
  
      switch (uart_command) {

//...............................................................................................

        case 0x83 :                               //1TS Inventory
          Inventory();
          Wait(512);
          FormatResponse_Short( uart_command, Inventory() );
          break;

//...............................................................................................

        case 0x85 :                               //Stay Quiet
          Send( cmd_message_len, 0 );

          FormatResponse_Short( uart_command, 0x00 );
          break;

//...............................................................................................

        case 0x88 :                               //general read command
          i = GeneralRead();

          if (debug_mode == 0) {

            if (clean_data_cnt == 0)
              SendCaptureData( uart_command, i );
            else
              FormatResponse_Data( uart_command, i, clean_data_cnt, (uint8_t*)data_buffer );

          } else 
          if (debug_mode == 2) 
            SendCaptureData( uart_command, ERR_EM4035_CAPT_DATA );
          else
            FormatResponse_Data( uart_command, ERR_EM4035_RAW_DATA, capture_cnt, (uint8_t*)capture.capture_data );

          break;

//...............................................................................................

        case 0x89 :                               //HW Authentication
          i = HW_Authentication();
      
          if (i == UART_MESSAGE_OK)
            FormatResponse_Data( uart_command, i, clean_data_cnt, (uint8_t*)data_buffer );
          else
            SendCaptureData( uart_command, i );
          break;

//...............................................................................................

        case 0x8A :                               //Toggle EAS

          i = ToggleEAS();

          if (i == UART_MESSAGE_OK)
            FormatResponse_Data( uart_command, i, clean_data_cnt, (uint8_t*)data_buffer );
          else
            SendCaptureData( uart_command, i );
          break;

//...............................................................................................

        case 0x8B :                               //Startup Invenotry

          //RF Reset
          WriteSPI( write_4094_low & 0xFFFE, write_4094_hi );
          Wait(32768);
          WriteSPI( write_4094_low | 1, write_4094_hi );
          Wait(1000);                            //wait for ~2ms

          i = GeneralRead();

          if (debug_mode == 0) {

            if (clean_data_cnt == 0)
              SendCaptureData( uart_command, i );
            else
              FormatResponse_Data( uart_command, i, clean_data_cnt, (uint8_t*)data_buffer );

          } else 
          if (debug_mode == 2) 
            SendCaptureData( uart_command, ERR_EM4035_CAPT_DATA );
          else
            FormatResponse_Data( uart_command, ERR_EM4035_RAW_DATA, capture_cnt, (uint8_t*)capture.capture_data );

          break;

//...............................................................................................

        case 0x90 :                               //general write command

          signed_crc = 0;

          if (cmd_message[1] == 0xE3) {                  //signed operation

            //sign the CRC
            HWSign( &cmd_message[cmd_message_len-2], &cmd_message[cmd_message_len-2], 16);

            if ((cmd_message[0] & 0x40) != 0) {
              signed_crc = 1;
            }
          }

          Send( cmd_message_len, 0 );

          if ((cmd_message[0] & 0x40) && ((cmd_message[1] == 0x21) ||
              (cmd_message[1] == 0x22) || (cmd_message[1] == 0x27))) {    //optionFlag = '1'

            Wait( write_tag_memory_delay );
            
            SendEOF();

            maxCaptureTimeLow = (uint8_t)maxTGeneral; 
            maxCaptureTimeHi = maxTGeneral >> 8; 

          } else {                              //optionFlag = '0'

            maxCaptureTimeLow = (uint8_t)maxTwa1ee; 
            maxCaptureTimeHi = maxTwa1ee >> 8; 
          }
   
          Capture(2);

          if (debug_mode == 0) {

            clean_data_cnt = 0;
            if (sof >= 1) {

              i = 248 - ExtractData( 248 );              //extract data, max effective size is 248/8 bytes
                            
              if ((i >= 33) && (data_buffer[0] != 0)) {  //error message found
                i = ERR_EM4035_ERROR_MSG;
                clean_data_cnt = 4;

                if (signed_crc != 0) {
                  //unsign
                  HWSign( (uint8_t*)&data_buffer[clean_data_cnt-2], (uint8_t*)&data_buffer[clean_data_cnt-2], 16);
                }

              } else if ((i-1) < expectedResponseLen) { //no good header found or not enough data
                clean_data_cnt = 0;

                i = ERR_EM4035_WRONG_LEN;
              } else {                                   //clamp data to bytes
                i = 0;
                clean_data_cnt = expectedResponseLen / 8;

                if (signed_crc != 0) {
                  //unsign
                  HWSign( (uint8_t*)&data_buffer[clean_data_cnt-2], (uint8_t*)&data_buffer[clean_data_cnt-2], 16);
                }

              }

              if (clean_data_cnt != 0) {
                FormatResponse_Data( uart_command, i, clean_data_cnt, (uint8_t*)data_buffer );
                break;
              }

            } else {
              i = ERR_EM4035_NO_SOF;
            }
            SendCaptureData( 0x90, i );
          }
          else
          if (debug_mode == 2) 
            SendCaptureData( uart_command, ERR_EM4035_CAPT_DATA );
          else
            FormatResponse_Data( uart_command, ERR_EM4035_RAW_DATA, capture_cnt, (uint8_t*)capture.capture_data );
          break;

//...............................................................................................

        case 0xF1 :                               //write SPI configuration word directly
          WriteSPI( write_4094_low, write_4094_hi );
          FormatResponse_Short( uart_command, 0x00 );
          break;

//...............................................................................................

        case 0xF0 :                               //RF reset using SPI configuration word
          WriteSPI( write_4094_low & 0xFFFE, write_4094_hi );
          FormatResponse_Short( uart_command, 0x00 );

          wdt_disable();

          i = write_tag_memory_delay;
          while (i-->0) {
            Wait(16384);
          }

          wdt_enable(0x7);

          WriteSPI( write_4094_low | 1, write_4094_hi );
          break;

//...............................................................................................

        case 0x00 :                               //no command
          continue;

//...............................................................................................

        default:
          FormatResponse_Short( 0, ERR_UART_UNKNOWN_CMD );
          break;
      }

      uart_command = 0;

    }

  }
}

//--------------------------------------------------------------
//compute the timeouts according to the flag byte
//
void Compute_Timeouts(uint8_t flags) {

  register uint16_t pom;
  register uint16_t corr;

  pom = expectedResponseLen * 16;        //512RF/32 = 16 TCNT0 pulses per bit
  pom += 128;                            //reserve
  corr = expectedResponseLen / 2 + 2;    //correction for dual carrier

  if ((flags & 2) == 0)
    pom *= 4;
  else
    corr >>= 2;

  if ((flags & 1) == 1)
    pom -= corr;

  pom = (38 * (uint32_t)pom) / 32 + 1;

  decode_number = flags & 3;

  switch (decode_number) {
  case 0 :           //single carrier, low datarate
    halfDataRate    = 288 * 4;
    pulsesPerBit    = 32;
//    maxTRead        = 7904 + 1;     // = 4 * ((768 + 24 * 32 + 256 + 256) + 96 * 512 + (256 + 256 + 24 * 32 + 768)) * 38 / 32 / 32 + 1;
    break;

  case 1 :             //dual carrier, low_datarate
    halfDataRate    = 288*4;
    pulsesPerBit    = 32;
//    maxTRead        = 7842 + 1; //4 * ((27*28 + 24 * 32 + 508) + 96 * 508 + (508 + 24 * 32 + 27*28)) * 38 / 32 / 32 + 1;
    break;

  case 2 :             //single carrier, high datarate
    halfDataRate    = 288;
    pulsesPerBit    = 8;
//    maxTRead        = 1976 + 1; //((768 + 24 * 32 + 256 + 256) + 96 * 512 + (256 + 256 + 24 * 32 + 768)) * 38 / 32 / 32 + 1;
    break;

  case 3 :             //dual carrier, high datarate
    halfDataRate    = 288;
    pulsesPerBit    = 8;
//    maxTRead        = 1960 + 1; //((27*28 + 24 * 32 + 508) + 96 * 508 + (508 + 24 * 32 + 27*28)) * 38 / 32 / 32 + 1;
    break;

  default :
    decode_number = 0xFF;
  }

  maxTGeneral     = pom;
  maxTwa1ee       = write_tag_memory_delay + pom;

}


//--------------------------------------------------------------
//Output of default read
// 

void SendCaptureData(uint8_t cmd, uint8_t ack) {

  uint8_t check_stat;

  SendByte(0x02);
  SendByte(4 + 2 * capture_cnt);
  SendByte(cmd);
  SendByte(ack);

  check_stat = (4 + 2 * capture_cnt) ^ cmd ^ ack;

  check_stat ^= Block_Output (capture_cnt, capture.capture_data);

  check_stat ^= Block_Output (capture_cnt, capture.capture_valid);

  SendByte(check_stat);
  SendByte(0x03);
}

//--------------------------------------------------------------
//send command and wait
//
void Send(uint8_t len, uint16_t wait_time) {

  uint8_t fwd_bit_count;
  int i;

  forward_ptr = data_buffer;
  fwd_bit_count = 0;

  for(i=0; i < len; i++) 
    fwd_bit_count += Prepare_Data( cmd_message[i] );

  Compute_Timeouts(cmd_message[0]);
  ClearCaptureBuffers();

  maxCaptureTimeLow = (uint8_t)maxTGeneral; 
  maxCaptureTimeHi = maxTGeneral >> 8; 

  SendForward(fwd_bit_count);

  if (wait_time != 0) Wait( wait_time );
}

//--------------------------------------------------------------
// general read function
//
uint8_t GeneralRead(void) {

  uint8_t i = UART_MESSAGE_OK;
  signed_crc = 0;

  if (cmd_message[1] == 0xE2) {                  //signed operation

    //sign the CRC
    HWSign( &cmd_message[cmd_message_len-2], &cmd_message[cmd_message_len-2], 16);

    if ((cmd_message[0] & 0x40) != 0) {
      signed_crc = 1;
    }
  }

  Send( cmd_message_len, STD_WAIT );

  maxCaptureTimeLow = (uint8_t)maxTGeneral; 
  maxCaptureTimeHi = maxTGeneral >> 8; 
   
  Capture(2);

  if (debug_mode == 0) {

    int i;
    clean_data_cnt = 0;
    if (sof >= 1) {

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美美女喷水视频| 精品在线免费观看| 一区二区三区四区中文字幕| 久久精品国产亚洲5555| 在线观看一区日韩| 亚洲欧美另类综合偷拍| 成人精品一区二区三区中文字幕| 久久久精品免费网站| 久久99精品视频| 精品国产乱码久久久久久图片| 肉丝袜脚交视频一区二区| 色欧美片视频在线观看在线视频| 26uuu亚洲综合色欧美| 视频精品一区二区| 欧美一区二区三区的| 亚洲国产毛片aaaaa无费看| 色香蕉久久蜜桃| 国产午夜三级一区二区三| 奇米777欧美一区二区| 久久影院午夜论| 99久久婷婷国产精品综合| 亚洲欧洲精品一区二区三区不卡| 欧美综合天天夜夜久久| 婷婷综合五月天| 久久亚洲一区二区三区明星换脸| 国产91精品久久久久久久网曝门| 中文一区二区在线观看| 91论坛在线播放| 久久国产精品色婷婷| 国产精品欧美极品| 亚洲精品一区在线观看| 欧美剧情片在线观看| 色天使久久综合网天天| 99久久亚洲一区二区三区青草 | 国精产品一区一区三区mba桃花 | 亚洲一区二区四区蜜桃| 一区在线播放视频| 欧美三级日韩三级国产三级| 成人动漫在线一区| 成人精品视频.| 国产毛片精品视频| 成人午夜电影网站| 国产精品亚洲一区二区三区在线 | 偷拍与自拍一区| 亚洲成av人综合在线观看| 亚洲一区二区三区四区不卡| 亚洲免费在线电影| 午夜伦欧美伦电影理论片| 亚洲制服丝袜av| 日韩综合小视频| 久久国产日韩欧美精品| 国产精品亚洲专一区二区三区 | 99国产精品久久久久久久久久久| 91精品办公室少妇高潮对白| 欧美性受xxxx黑人xyx性爽| 日韩欧美一二三四区| 国产午夜一区二区三区| 亚洲午夜精品一区二区三区他趣| 日本视频在线一区| 99久久精品99国产精品| 日韩欧美精品三级| 国产精品久久看| 日韩不卡手机在线v区| 成人av手机在线观看| 欧美精品1区2区| 亚洲视频一区二区免费在线观看 | 中文字幕欧美国产| 香港成人在线视频| 成人av在线影院| 精品成人一区二区| 亚洲男女毛片无遮挡| 麻豆freexxxx性91精品| 91在线视频免费观看| 久久久精品国产免大香伊| 午夜精品福利一区二区蜜股av| 99久久99久久免费精品蜜臀| 精品国产区一区| 日韩中文字幕区一区有砖一区 | 91在线高清观看| 亚洲精品在线电影| 精品亚洲porn| 欧美一区二区三区视频在线 | 一道本成人在线| 亚洲天堂精品在线观看| 91色porny蝌蚪| 一区二区三区**美女毛片| 色婷婷av一区二区三区gif | 亚洲成在线观看| 日本高清成人免费播放| 亚洲三级理论片| 色老汉av一区二区三区| 亚洲精品免费在线观看| 欧美日韩免费观看一区二区三区| 亚洲欧美激情插| 欧美日韩免费电影| 美女一区二区在线观看| 国产三级精品三级| 欧洲中文字幕精品| 日本最新不卡在线| 久久久亚洲欧洲日产国码αv| 国产成人亚洲综合a∨婷婷| 国产精品久久777777| 在线观看亚洲专区| 久久精品国产一区二区三| 欧美日韩一本到| 国产成人av电影在线观看| 最新日韩av在线| 欧美日韩一区三区四区| 奇米影视一区二区三区| 久久众筹精品私拍模特| 国产成人综合视频| 亚洲精品日产精品乱码不卡| 日韩精品中文字幕在线一区| 国产精品一二一区| 久久―日本道色综合久久| 99re这里只有精品首页| 日本在线观看不卡视频| 久久日一线二线三线suv| 99国产精品久久久久久久久久久| 婷婷丁香激情综合| 国产日韩欧美亚洲| 欧美疯狂性受xxxxx喷水图片| 国产一区二区影院| 亚洲一二三四区| 久久精品人人做人人综合| 99久久精品国产精品久久| 看电视剧不卡顿的网站| 亚洲欧美偷拍卡通变态| 精品美女被调教视频大全网站| 成人av在线观| 国产大片一区二区| 日韩精品每日更新| 午夜日韩在线观看| 亚洲精品日产精品乱码不卡| 国产精品视频在线看| 制服丝袜日韩国产| 色综合久久久久| 91欧美激情一区二区三区成人| 精品一区二区三区视频| 亚洲一区二区三区影院| 中文字幕免费在线观看视频一区| 欧美一级搡bbbb搡bbbb| 91国产成人在线| 色一情一乱一乱一91av| 成人伦理片在线| 国产91丝袜在线播放0| 久久不见久久见免费视频1| 日韩精品每日更新| 蜜臀99久久精品久久久久久软件| 婷婷成人综合网| 免费看日韩a级影片| 久久精品国产秦先生| 国产一区二区中文字幕| 粉嫩在线一区二区三区视频| 高清在线不卡av| 91亚洲精品久久久蜜桃网站 | 精品国免费一区二区三区| 欧美高清视频一二三区| 3d成人动漫网站| 欧美电影精品一区二区| 欧美极品另类videosde| 亚洲视频在线一区观看| 亚洲国产欧美另类丝袜| 免费日本视频一区| 久久不见久久见中文字幕免费| 成人一区在线观看| 91麻豆自制传媒国产之光| 欧美精品一二三| 亚洲精品一线二线三线| 一区二区三区免费看视频| 另类小说色综合网站| 成人毛片在线观看| 日韩美女视频在线| 国产精品毛片久久久久久| 天堂资源在线中文精品| 国产美女av一区二区三区| 欧美美女喷水视频| 国产精品超碰97尤物18| 男人的j进女人的j一区| 成人福利视频网站| 欧美岛国在线观看| 婷婷久久综合九色综合伊人色| 成人精品免费看| 日韩女优av电影在线观看| 亚洲福利视频一区| 91视频在线观看免费| 久久精品视频一区二区| 另类专区欧美蜜桃臀第一页| 欧美精品1区2区3区| 午夜天堂影视香蕉久久| 91亚洲精品乱码久久久久久蜜桃| 国产三区在线成人av| 日本aⅴ亚洲精品中文乱码| 欧美在线免费观看视频| 一二三区精品福利视频| 91在线看国产| 日韩一区欧美一区| www.亚洲人| 亚洲男帅同性gay1069| 在线观看亚洲a|