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

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

?? bdm.c

?? HCS08仿真器資料:資料詳細
?? C
?? 第 1 頁 / 共 5 頁
字號:
/*
    Open Source BDM - BDM communication
 	 /* Prominent Notice-This software was modified from TBDML software - 12/05
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "MC68HC908JB16.h"
#include "hidef.h"
#include "bdm.h"
#include "commands.h"
#include "usb.h"

/* i, j & k are used as timing and general purpose variables in the Tx & Rx routines */
/* must be placed into the direct segment */
static unsigned char i;
static unsigned char j;
static unsigned char k;

/* pointers to Rx & Tx routines, tables for selection */
unsigned char (*bdm_rx_ptr)(void) = bdm_empty_rx_tx;
void (*bdm_tx_ptr)(unsigned char) = bdm_empty_rx_tx;

/* when SYNC length expressed in 60MHz ticks is ABOVE OR EQUAL to the value in the table, the correspnding pointer is selected */
/* if SYNC is shother than the first entry, the target runs too fast */
/* if SYNC is longer or equal to the last entry, the target runs too slow */
const unsigned int bdm_tx_sel_tresholds[]=
  {600,     1129,    1335,    1541,    1747,    1952,    2157,    2465,    2877,    3288,
   3800,    4418,    5136,    6059,    7189,    8524,    10066,   11814,   13867,   16988};
void (* const bdm_tx_sel_ptrs[])(unsigned char)=
  {bdm_tx1, bdm_tx2, bdm_tx3, bdm_tx4, bdm_tx5, bdm_tx6, bdm_tx7, bdm_tx8, bdm_tx9, bdm_tx10,
   bdm_tx11,bdm_tx12,bdm_tx13,bdm_tx14,bdm_tx15,bdm_tx16,bdm_tx17,bdm_tx18,bdm_tx19,bdm_empty_rx_tx};
const unsigned int bdm_rx_sel_tresholds[]=
  {600,     1101,    1347,    1592,    1837,    2202,    2694,    3303,    4042,    4897,
   5998,    7346,    9055,    11257,   13952,   17919};
unsigned char (* const bdm_rx_sel_ptrs[])(void)=
  {bdm_rx1, bdm_rx2, bdm_rx3, bdm_rx4, bdm_rx5, bdm_rx6, bdm_rx7, bdm_rx8, bdm_rx9, bdm_rx10,
   bdm_rx11,bdm_rx12,bdm_rx13,bdm_rx14,bdm_rx15,bdm_empty_rx_tx};

/* status of the BDM communication */
bdm_status_t bdm_status;

/* private macros */

#define ACKN_CLR   asm (BCLR T1SC0_CH0F_BITNUM,T1SC0); /* clear timer capture flag, in assembly to make sure the compiler does not mess it up... */

/* functions */
 unsigned char bdm08_stat(void) {
  unsigned char bdm_sts;               
   /* try the ACKN feature */
 BDM08_CMD_READSTATUS(&bdm_sts);
 if ((bdm_sts&0x40)==0) {
  
  return(0);
 }
 return(1);/* connection established */
}
 unsigned char bdm08_connect(void) {
  unsigned char bdm_sts;               
  bdm_status.ackn = WAIT;               /* clear the ACKN feature */
  bdm_status.reset = NO_RESET_ACTIVITY;               /* clear the reset flag */
  /* first wait until both RESET and BDM are high */
  T1MOD = RESET_WAIT * BUS_FREQUENCY * 16;             /* this is by 2.4% longer than (RESET_WAIT * BUS_FREQUENCY * 1000)/64, but cannot do that in 16-bit math */
  T1SC = T1SC_TRST_MASK | T1SC_PS1_MASK | T1SC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  T1SC_TOF = 0;
  while(((RESET_IN==0)||(BDM_IN==0))&&(T1SC_TOF==0));  /* wait for reset and bdm to rise or timeout */
  if (T1SC_TOF) return(1);                             /* timeout */  
  if (bdm_sync_meas()) {
    /* trying to measure SYNC was not successful */
      return(1);  
  }
 if (bdm_rx_tx_select()) return(1); /* if at least one of the two methods succeeded, we can select the right Rx and Tx routines */
 bdm_ackn_init();    /* try the ACKN feature */
 BDM08_CMD_READSTATUS(&bdm_sts);
 if ((bdm_sts&0x80)==0) BDM08_CMD_WRITECONTROL(0x80|bdm_sts); /* if BDM not enabled yet, enable it so it can be made active */
  return(0);          /* connection established */
}

 
 
/* connect to HC12 or HCS12 target */
/* returns 0 on succes or 1 on failure */
unsigned char bdm12_connect(void) {
  unsigned char bdm_sts;															
  bdm_status.ackn = WAIT;															/* clear the ACKN feature */
  bdm_status.reset = NO_RESET_ACTIVITY;               /* clear the reset flag */
  /* first wait until both RESET and BDM are high */
  T1MOD = RESET_WAIT * BUS_FREQUENCY * 16;             /* this is by 2.4% longer than (RESET_WAIT * BUS_FREQUENCY * 1000)/64, but cannot do that in 16-bit math */
  T1SC = T1SC_TRST_MASK | T1SC_PS1_MASK | T1SC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  T1SC_TOF = 0;
  while(((RESET_IN==0)||(BDM_IN==0))&&(T1SC_TOF==0));  /* wait for reset and bdm to rise or timeout */
  if (T1SC_TOF) return(1);                             /* timeout */  
  if (bdm_sync_meas()) {
    /* trying to measure SYNC was not successful */
      return(1);  
  }
	if (bdm_rx_tx_select()) return(1); /* if at least one of the two methods succeeded, we can select the right Rx and Tx routines */
	bdm_ackn_init();    /* try the ACKN feature */
	BDM12_CMD_BDREADB(BDM12_STS_ADDR,&bdm_sts);
	if ((bdm_sts&0x80)==0) BDM12_CMD_BDWRITEB(BDM12_STS_ADDR,0x80|bdm_sts);	/* if BDM not enabled yet, enable it so it can be made active */
  return(0);          /* connection established */
}

/* resets the target */
/* mode == 0 -> reset to special mode, mode == 1 -> reset to normal mode */
/* returns zero on success and non-zero if reset signal stuck to ground */
  unsigned char bdm_softreset(unsigned char mode) {
  
  		  if(mode ==0){
  		    
  		    BDM08_CMD_Res(0x1801,0x01);
						  
         	     BDM_OUT = 0;                                      /* drive BDM low */
          asm{
            MOV   #01,BDM_DIR2_PORT    /* start driving the BDM */
          }
            T1MOD = RESET_SETTLE * BUS_FREQUENCY;              /* time to wait for signals to settle */
            T1SC = T1SC_TRST_MASK;                              /* reset the timer and start counting @ bus clock */
            T1SC_TOF = 0;
           while(T1SC_TOF==0);                                /* wait for timeout */
  	
          T1MOD = RESET_SETTLE * BUS_FREQUENCY;              /* time to wait for signals to settle */
          T1SC = T1SC_TRST_MASK;                              /* reset the timer and start counting @ bus clock */
          T1SC_TOF = 0;
            while(T1SC_TOF==0);                                /* wait for timeout */
          asm {
             CLRX   						                              /* point to PTA */
             CLRH
      
               LDA   #BDM_DIR1_MASK + BDM_OUT_MASK + RESET_OUT_MASK  
               STA   ,X                                        /* bring BDM high */
            AND   #0xEF
      
               STA   ,X                                        /* stop driving the BDM */
      /* it took 4 cycles from bringing BDM high to stop driving it and that is fast enough up to 16*3/4 = 12 MHz of BDM frequency on JB8 */
             }
             
  /* wait one more settling time before allowing anythig else to happen on the BDM */
           T1MOD = RESET_SETTLE * BUS_FREQUENCY;                /* time to wait for signals to settle */
            T1SC = T1SC_TRST_MASK;                                /* reset the timer and start counting @ bus clock */
          T1SC_TOF = 0;
          while(T1SC_TOF==0); 
         	 bdm_tx_finish(); 
  		  }
  		  
  		  
  		  if (mode ==1){
  		  
  		  	  BDM08_CMD_WRITEB(0x1801,0x01);
  		  
  		  }
         
  }


/* resets the target */
/* mode == 0 -> reset to special mode, mode == 1 -> reset to normal mode */
/* returns zero on success and non-zero if reset signal stuck to ground */
unsigned char bdm_reset(unsigned char mode) {
  
  BDM_DIR1 = 0;                                       /* stop driving the BDM */
  KBSCR_IMASKK = 1;                                   /* mask KBD interrupts */
  T1MOD = RESET_WAIT * BUS_FREQUENCY * 16;             /* this is by 2.4% longer than (RESET_WAIT * BUS_FREQUENCY * 1000)/64, but cannot do that in 16-bit math */
  T1SC = T1SC_TRST_MASK | T1SC_PS1_MASK | T1SC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  T1SC_TOF = 0;
  while((RESET_IN==0)&&(T1SC_TOF==0));                 /* wait for reset to rise or timeout */
  if (T1SC_TOF) return(1);
  if (mode==0) {
    BDM_OUT = 0;                                      /* drive BDM low */
    
    BDM_DIR1 = 1;
    T1MOD = RESET_SETTLE * BUS_FREQUENCY;              /* time to wait for signals to settle */
    T1SC = T1SC_TRST_MASK;                              /* reset the timer and start counting @ bus clock */
    T1SC_TOF = 0;
    while(T1SC_TOF==0);                                /* wait for timeout */
  }
  //Switch To A to B to drive Reset
  RESET_DR = 1; //Default is B to A for Input
  RESET_DR_DDR |= RESET_DR_MASK;  // Set as output to Drive the buffer 
  
  RESET_OUT = 0;                                      /* start driving RESET */
  RESET_OUT_DDR |= RESET_OUT_MASK;
  T1MOD = RESET_LENGTH * BUS_FREQUENCY * 16;           /* time of the RESET pulse */
  T1SC = T1SC_TRST_MASK | T1SC_PS1_MASK | T1SC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  T1SC_TOF = 0;
  while(T1SC_TOF==0);                                  /* wait for timeout */
  RESET_OUT = 1;																			/* stop driving the RESET */
  RESET_OUT_DDR &= ~RESET_OUT_MASK;            /* and make the pin input again so nothing interferes with it */
  
  //Switch To B to A
  RESET_DR = 0; //Default is B to A for Input
  
  T1MOD = RESET_WAIT * BUS_FREQUENCY * 16;             /* time to wait for reset to rise */
  T1SC = T1SC_TRST_MASK | T1SC_PS1_MASK | T1SC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  T1SC_TOF = 0;
  while((RESET_IN==0)&&(T1SC_TOF==0));                 /* wait for reset to rise or timeout */
  if (T1SC_TOF) return(1);
  if (mode==0) {
    T1MOD = RESET_SETTLE * BUS_FREQUENCY;              /* time to wait for signals to settle */
    T1SC = T1SC_TRST_MASK;                              /* reset the timer and start counting @ bus clock */
    T1SC_TOF = 0;
    while(T1SC_TOF==0);                                /* wait for timeout */
    asm {
      CLRX   						                              /* point to PTA */
      CLRH
      
      LDA   #BDM_DIR1_MASK + BDM_OUT_MASK + RESET_OUT_MASK  
      STA   ,X                                        /* bring BDM high */
      AND   #0xEF
      
      STA   ,X                                        /* stop driving the BDM */
      /* it took 4 cycles from bringing BDM high to stop driving it and that is fast enough up to 16*3/4 = 12 MHz of BDM frequency on JB8 */
    }
  }
  /* wait one more settling time before allowing anythig else to happen on the BDM */
  T1MOD = RESET_SETTLE * BUS_FREQUENCY;                /* time to wait for signals to settle */
  T1SC = T1SC_TRST_MASK;                                /* reset the timer and start counting @ bus clock */
  T1SC_TOF = 0;
  while(T1SC_TOF==0);                                  /* wait for timeout */
  KBSCR_ACKK=1;                                       /* acknowledge KBD interrupt */
  KBSCR_IMASKK = 0;                                   /* enable KBD interrupts again */
  return(0);
}

/* interrupt function servicing the KBD interrupt from RESET_IN assertion */
void interrupt bdm_reset_sense(void) {
  KBSCR_ACKK=1;                    /* acknowledge the interrupt */
  bdm_status.reset=RESET_DETECTED; /* record the fact that reset was asserted */  
}

/* measures the SYNC length and writes the result into bdm_status structure */
/* returns 0 on succes and non-zero on timeout */
unsigned char bdm_sync_meas(void) {
  unsigned int time;
  bdm_status.speed = NO_INFO; /* indicate that we do not have a clue about target speed at the moment... */
  T1MOD = BDM_SYNC_REQ * BUS_FREQUENCY;  /* load T1MOD with the longest SYNC REQUEST possible */
  BDM_DIR1 = 0;         /* stop driving the BDM */
  T1SC = T1SC_TRST_MASK;  /* restart the timer */
  T1SC_TOF = 0;          /* clear TOF */
  while((T1SC_TOF==0)&&(BDM_IN==0)); /* wait for the BDM to come high or timeout */
  if (T1SC_TOF) return(1);           /* timeout ! */
  BDM_OUT = 0;
  BDM_DIR1 = 1;         /* bring BDM low */
  T1SC = T1SC_TRST_MASK;  /* restart the timer */
  T1SC_TOF = 0;          /* clear TOF */
  while(T1SC_TOF==0);    /* wait for timeout */
  T1SC_TOF = 0;          /* clear the TOF flag */
  T1SC0 = T1SC0_ELS0B_MASK; /* capture falling edges */
  T1SC0_CH0F=0;          /* clear capture flag */
  //this is not fast enough, the target will start driving 16 BDM cycles after the pin comes high
  //BDM_OUT_PORT = BDM_OUT_MASK;  /* bring BDM high */
  //BDM_DIR1_PORT = BDM_OUT_MASK | BDM_DIR1_MASK; /* stop driving it */
  asm {
    CLRX   						  /* point to PTA */
    CLRH
    
    LDA   #BDM_DIR1_MASK + BDM_OUT_MASK + RESET_OUT_MASK  
    STA   ,X            /* bring BDM high */
    AND   #0xEF
    STA   ,X            /* stop driving the BDM */
    /* it took 4 cycles from bringing BDM high to stop driving it and that is fast enough up to 16*3/4 = 12 MHz of BDM frequency on JB8 */
  }
  while ((T1SC0_CH0F==0)&&(T1SC_TOF==0));     /* wait for capture or timeout */  
  time=T1CH0;                                /* capture start of the SYNC */
  T1SC0 = T1SC0_ELS0A_MASK;                   /* capture rising edge, clear capture flag */
  /* it takes 32 cycles to reenable capture (worst case) which is good enough up to 128*3/32 = 12 MHz again on JB8 */ 
  while ((T1SC0_CH0F==0)&&(T1SC_TOF==0));     /* wait for capture or timeout */  
  time=T1CH0-time;                           /* calculate length of the SYNC */
  if (T1SC_TOF) return(2);                   /* timeout ! */
  #if (BUS_FREQUENCY==3)
    bdm_status.sync_length=(time<<2)+(time<<4);   /* multiply by 20 to get the time in 60MHz ticks */
  #elif (BUS_FREQUENCY==6)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一级欧美三级在线观看 | 国产在线视频一区二区| 中文字幕欧美三区| 日韩亚洲欧美在线| 欧美日韩dvd在线观看| 不卡的av中国片| 国产精品乡下勾搭老头1| 美国十次综合导航| 免费成人结看片| 日韩成人免费电影| 五月婷婷另类国产| 亚洲福利一二三区| 亚洲sss视频在线视频| 亚洲成a人片在线不卡一二三区| 亚洲摸摸操操av| 亚洲视频小说图片| 亚洲男同性视频| 亚洲人成网站色在线观看| 亚洲欧洲一区二区在线播放| 中文字幕日本不卡| 亚洲美女免费视频| 亚洲一区二区三区中文字幕在线| 一区二区三区高清不卡| 亚洲夂夂婷婷色拍ww47| 亚洲国产精品嫩草影院| 亚洲已满18点击进入久久| 亚洲成年人影院| 久久激情五月婷婷| 国产一区二区按摩在线观看| 粉嫩在线一区二区三区视频| 91免费国产在线观看| 欧美手机在线视频| 日韩无一区二区| 久久久久久毛片| 亚洲少妇屁股交4| 三级亚洲高清视频| 韩国在线一区二区| www.亚洲激情.com| 欧美精品欧美精品系列| 欧美成人女星排名| 成人免费视频在线观看| 婷婷六月综合亚洲| 国产盗摄女厕一区二区三区| 91蜜桃免费观看视频| 777久久久精品| 久久九九全国免费| 亚洲综合一区二区| 国产一区美女在线| 日本二三区不卡| 日韩欧美国产wwwww| 国产精品久久久久久久裸模| 午夜成人免费电影| 国产精品一二三四五| 在线观看国产日韩| 国产亚洲精品免费| 亚洲国产成人高清精品| 丰满白嫩尤物一区二区| 91精品蜜臀在线一区尤物| 国产精品天干天干在线综合| 视频在线在亚洲| 9久草视频在线视频精品| 日韩午夜中文字幕| 一区二区三区在线视频免费 | 精品sm在线观看| 一区二区激情视频| 国产资源精品在线观看| 欧美日韩免费视频| 中文字幕一区二区三区视频| 久久se这里有精品| 欧美撒尿777hd撒尿| 中文字幕日韩欧美一区二区三区| 韩国v欧美v亚洲v日本v| 欧美日本乱大交xxxxx| 亚洲精品美国一| 成人免费看的视频| 久久久蜜桃精品| 久久精品国产999大香线蕉| 欧美日韩美少妇| 亚洲夂夂婷婷色拍ww47| 91小视频免费观看| 国产精品久久毛片a| 精品综合久久久久久8888| 欧美另类一区二区三区| 亚洲成人1区2区| 欧美视频一区在线| 亚洲美女视频在线观看| 97精品久久久午夜一区二区三区| 久久久高清一区二区三区| 精品亚洲欧美一区| 欧美r级电影在线观看| 欧美96一区二区免费视频| 在线不卡免费欧美| 日韩国产欧美在线视频| 在线播放视频一区| 日韩成人午夜精品| 日韩午夜在线播放| 激情综合网天天干| 久久久久久久综合狠狠综合| 国产99久久久精品| 国产精品不卡视频| 91在线播放网址| 亚洲乱码精品一二三四区日韩在线 | 综合久久综合久久| 91在线观看一区二区| 亚洲日本电影在线| 欧美日韩综合一区| 日韩精品久久久久久| 欧美一区二区三区四区在线观看| 日韩有码一区二区三区| 欧美大片在线观看| 成人妖精视频yjsp地址| 亚洲视频一区二区在线观看| 在线精品视频一区二区| 亚洲18影院在线观看| 精品久久人人做人人爰| 成人18精品视频| 亚洲香肠在线观看| 日韩视频永久免费| 成人永久免费视频| 夜夜精品视频一区二区| 日韩欧美成人一区二区| 成人激情校园春色| 亚洲香肠在线观看| 26uuu亚洲综合色欧美| www.99精品| 亚洲午夜激情av| 国产亚洲欧美一区在线观看| 色哦色哦哦色天天综合| 全国精品久久少妇| 国产精品成人一区二区三区夜夜夜| 色婷婷综合久久久中文字幕| 日韩高清在线观看| 欧美经典三级视频一区二区三区| 91传媒视频在线播放| 精品一区二区在线视频| 亚洲激情图片小说视频| 精品国产乱码久久| 91丨九色丨蝌蚪富婆spa| 美女诱惑一区二区| 最新国产成人在线观看| 欧美成人艳星乳罩| 91国在线观看| 国产v综合v亚洲欧| 日韩综合小视频| 亚洲伦理在线精品| 欧美国产欧美亚州国产日韩mv天天看完整| 欧美主播一区二区三区| 国产精品99久久久久久久女警| 亚洲精品中文在线观看| 国产丝袜美腿一区二区三区| 欧美老人xxxx18| 91老司机福利 在线| 高清国产一区二区三区| 看电视剧不卡顿的网站| 亚洲国产精品精华液网站| 国产精品国产精品国产专区不片| 欧美xxxxxxxx| 欧美日韩高清在线播放| 91网站最新地址| 国产馆精品极品| 极品美女销魂一区二区三区| 午夜精品成人在线视频| 亚洲精品免费在线观看| 欧美激情一区在线观看| 欧美成人国产一区二区| 欧美放荡的少妇| 欧美精品一卡二卡| 欧美三级电影网| 欧美在线一二三四区| 欧美在线制服丝袜| 在线看一区二区| 欧美最猛性xxxxx直播| 91麻豆.com| 色域天天综合网| 91国产福利在线| 色噜噜狠狠成人中文综合| 99riav久久精品riav| caoporn国产一区二区| 99久久综合国产精品| eeuss国产一区二区三区| 成人av在线观| 99久久99久久免费精品蜜臀| 9i看片成人免费高清| 91欧美一区二区| 欧美午夜影院一区| 欧美日韩情趣电影| 欧美一区二区福利在线| 精品美女一区二区| 久久亚洲私人国产精品va媚药| 久久久精品免费网站| 国产精品国产三级国产aⅴ无密码| 欧美激情综合五月色丁香| 国产精品进线69影院| 伊人夜夜躁av伊人久久| 亚洲成人av一区| 精品一区二区在线播放| 成人午夜免费视频| 色av成人天堂桃色av| 日韩一区二区三区精品视频| 2020日本不卡一区二区视频|