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

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

?? bdm.c

?? freecale單片機基于bdm接口的一些源代碼
?? C
?? 第 1 頁 / 共 5 頁
字號:
/*
    Turbo BDM Light - BDM communication
    Copyright (C) 2005  Daniel Malik

    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 "MC68HC908JB8.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[]=
  {914,     1129,    1335,    1541,    1747,    1952,    2157,    2465,    2877,    3288,
   3800,    4418,    5136,    6059,    7189,    8524,    10066,   11814,   13867,   16988};
*/
//new values for tics as the JB16 CPU is 2 times faster
const unsigned int bdm_tx_sel_tresholds[]=
  {914/2,     1129/2,    1335/2,    1541/2,    1747/2,    1952/2,    2157/2,    2465/2,    2877/2,    3288/2,
   3800/2,    4418/2,    5136/2,    6059/2,    7189/2,    8524/2,    10066/2,   11814/2,   13867/2,   16988/2};
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[]=
  {853,     1101,    1347,    1592,    1837,    2202,    2694,    3303,    4042,    4897,
   5998,    7346,    9055,    11257,   13952,   17919};
*/
//new values for tics as the JB16 CPU is 2 times faster
const unsigned int bdm_rx_sel_tresholds[]=
  {853/2,     1101/2,    1347/2,    1592/2,    1837/2,    2202/2,    2694/2,    3303/2,    4042/2,    4897/2,
   5998/2,    7346/2,    9055/2,    11257/2,   13952/2,   17919/2};
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 TSC0_CH0F_BITNUM,TSC0); /* clear timer capture flag, in assembly to make sure the compiler does not mess it up... */

/* functions */

/* 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 */
  TMOD = 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 */
  TSC = TSC_TRST_MASK | TSC_PS1_MASK | TSC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  TSC_TOF = 0;
  while(((RESET_IN==0)||(BDM_IN==0))&&(TSC_TOF==0));  /* wait for reset and bdm to rise or timeout */
  if (TSC_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_reset(unsigned char mode) {
  BDM_DIR1 = 1;                                       /* stop driving the BDM */
  KBSCR_IMASKK = 1;                                   /* mask KBD interrupts */
  TMOD = 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 */
  TSC = TSC_TRST_MASK | TSC_PS1_MASK | TSC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  TSC_TOF = 0;
  while((RESET_IN==0)&&(TSC_TOF==0));                 /* wait for reset to rise or timeout */
  if (TSC_TOF) return(1);
  if (mode==0) {
    BDM_OUT = 0;                                      /* drive BDM low */
    BDM_DIR1 = 0;
    TMOD = RESET_SETTLE * BUS_FREQUENCY;              /* time to wait for signals to settle */
    TSC = TSC_TRST_MASK;                              /* reset the timer and start counting @ bus clock */
    TSC_TOF = 0;
    while(TSC_TOF==0);                                /* wait for timeout */
  }
  RESET_OUT = 0;                                      /* start driving RESET */
  RESET_OUT_DDR |= RESET_OUT_MASK;
  TMOD = RESET_LENGTH * BUS_FREQUENCY * 16;           /* time of the RESET pulse */
  TSC = TSC_TRST_MASK | TSC_PS1_MASK | TSC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  TSC_TOF = 0;
  while(TSC_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 */
  TMOD = RESET_WAIT * BUS_FREQUENCY * 16;             /* time to wait for reset to rise */
  TSC = TSC_TRST_MASK | TSC_PS1_MASK | TSC_PS2_MASK;  /* reset the timer and start counting @ bus clock divided by 64 */
  TSC_TOF = 0;
  while((RESET_IN==0)&&(TSC_TOF==0));                 /* wait for reset to rise or timeout */
  if (TSC_TOF) return(1);
  if (mode==0) {
    TMOD = RESET_SETTLE * BUS_FREQUENCY;              /* time to wait for signals to settle */
    TSC = TSC_TRST_MASK;                              /* reset the timer and start counting @ bus clock */
    TSC_TOF = 0;
    while(TSC_TOF==0);                                /* wait for timeout */
    asm {
      CLRX   						                              /* point to PTA */
      CLRH
      LDA   #BDM_OUT_MASK + RESET_OUT_MASK  
      STA   ,X                                        /* bring BDM high */
      ORA   #BDM_DIR1_MASK
      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 */
  TMOD = RESET_SETTLE * BUS_FREQUENCY;                /* time to wait for signals to settle */
  TSC = TSC_TRST_MASK;                                /* reset the timer and start counting @ bus clock */
  TSC_TOF = 0;
  while(TSC_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... */
  TMOD = BDM_SYNC_REQ * BUS_FREQUENCY;  /* load TMOD with the longest SYNC REQUEST possible */
  BDM_DIR1 = 1;         /* stop driving the BDM */
  TSC = TSC_TRST_MASK;  /* restart the timer */
  TSC_TOF = 0;          /* clear TOF */
  while((TSC_TOF==0)&&(BDM_IN==0)); /* wait for the BDM to come high or timeout */
  if (TSC_TOF) return(1);           /* timeout ! */
  BDM_OUT = 0;
  BDM_DIR1 = 0;         /* bring BDM low */
  TSC = TSC_TRST_MASK;  /* restart the timer */
  TSC_TOF = 0;          /* clear TOF */
  while(TSC_TOF==0);    /* wait for timeout */
  TSC_TOF = 0;          /* clear the TOF flag */
  TSC0 = TSC0_ELS0B_MASK; /* capture falling edges */
  TSC0_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_OUT_MASK + RESET_OUT_MASK  
    STA   ,X            /* bring BDM high */
    ORA   #BDM_DIR1_MASK
    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 ((TSC0_CH0F==0)&&(TSC_TOF==0));     /* wait for capture or timeout */  
  time=TCH0;                                /* capture start of the SYNC */
  TSC0 = TSC0_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 ((TSC0_CH0F==0)&&(TSC_TOF==0));     /* wait for capture or timeout */  
  time=TCH0-time;                           /* calculate length of the SYNC */
  if (TSC_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)
    bdm_status.sync_length=(time<<1)+(time<<3);   /* multiply by 10 to get the time in 60MHz ticks */
  #else
    bdm_status.sync_length=time*(60/BUS_FREQUENCY); /* if not 3 or 6 then do it the stupid way... */
  #endif
  bdm_status.speed = SYNC_SUPPORTED; /* SYNC feature is supported by the target */
  return(0);
}

/* waits 64 BDM cycles of the target MCU */
void bdm_wait64(void) {
  asm {
    LDA  bdm_status.wait64_cnt  /* number of loop iterations to wait */
  loop:  
    DBNZA loop                  /* 3 cycles per iteration */
  }
}

/* waits 150 BDM cycles of the target MCU */
void bdm_wait150(void) {
  asm {
    LDA  bdm_status.wait150_cnt  /* number of loop iterations to wait */
  loop:  
    DBNZA loop                  /* 3 cycles per iteration */
  }
}

/* enables ACKN and prepares the timer for easy ACKN timeout use */
void bdm_ackn_init(void) {
  TMOD = ACKN_TIMEOUT * BUS_FREQUENCY;  /* the timer will set the TOF flag as soon as the timeout time is reached */
  TSC = TSC_TRST_MASK;    /* start the timer, prescaler = 1 */
  TSC0 = TSC0_ELS0A_MASK;	/* capture rising edges */
  bdm_status.ackn = ACKN; /* switch ACKN on */
  BDM_CMD_ACK_ENABLE();   /* send the enable command to the target */
}

/* waits for ACKN pulse from the target */
void bdm_ackn(void) {
  TSC = TSC_TRST_MASK;                      /* clear the TOF flag if set and restart the timer */
  TSC_TOF = 0;                              /* clear TOF */
  while ((TSC0_CH0F==0)&&(TSC_TOF==0));     /* wait for capture or timeout */  
  TSC0 = TSC0_ELS0A_MASK;                   /* capture rising edge, clear capture flag */
  if (TSC_TOF) {
    /* timeout */
    bdm_status.ackn = WAIT;                 /* switch the ackn feature off */
  }
}

/* selects Rx and Tx routine to be used according to SYNC length in bdm_status structure */
/* returns 0 on success and 1 when no appropriate function can be found */
unsigned char bdm_rx_tx_select(void) {
  signed char i;
  bdm_rx_ptr = bdm_empty_rx_tx;                         /* clear the pointers */
  bdm_tx_ptr = bdm_empty_rx_tx;
  for (i=(sizeof(bdm_tx_sel_tresholds)/2)-1;i>=0;i--) { /* search through the table */
    if (bdm_status.sync_length>=bdm_tx_sel_tresholds[i]) {
      bdm_tx_ptr = bdm_tx_sel_ptrs[i];                  /* is SYNC is >=, select this routine */
      break;                                            /* and finish the search */
    }
  }
  if (bdm_tx_ptr==bdm_empty_rx_tx) return(1);           /* check if valid routine has been found */
  for (i=(sizeof(bdm_rx_sel_tresholds)/2)-1;i>=0;i--) { /* do the same for Rx as well */
    if (bdm_status.sync_length>=bdm_rx_sel_tresholds[i]) {
      bdm_rx_ptr = bdm_rx_sel_ptrs[i];
      break;
    }
  }
  if (bdm_rx_ptr==bdm_empty_rx_tx) return(1);
  /* there is plenty of overhead: JSR, LDA and RTS of the WAIT, RTS from the previous routine, JSR to the next routine: at least 21 cycles */
  /* cannot subtract more than the smallest possible result -1 as the number must be > 0 */
  bdm_status.wait64_cnt = bdm_status.sync_length/(3*(60/BUS_FREQUENCY)*128/64)-6; 
  bdm_status.wait150_cnt = bdm_status.sync_length/(3*(60/BUS_FREQUENCY)*128/150)-7; 
  return(0);
}

/* when no function appropriate for the target speed can be found the following routine is selected */

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成熟亚洲日本毛茸茸凸凹| 91精品国产麻豆国产自产在线| 在线看国产日韩| 日韩午夜在线播放| 夜夜精品浪潮av一区二区三区| 国产麻豆午夜三级精品| 91国产福利在线| 国产精品视频一二三| 日韩国产精品久久久久久亚洲| 色综合天天综合色综合av| 精品成人免费观看| 首页欧美精品中文字幕| 色8久久人人97超碰香蕉987| 国产午夜精品一区二区| 久久99日本精品| 91精品久久久久久久91蜜桃| 一卡二卡三卡日韩欧美| www.久久精品| 国产精品欧美久久久久一区二区| 免费在线看成人av| 欧美日韩精品一二三区| 亚洲免费观看高清在线观看| 成人在线视频一区二区| 亚洲欧美影音先锋| 国产成+人+日韩+欧美+亚洲| 欧美mv日韩mv国产网站app| 日韩av一二三| 日韩一区二区三区免费看| 婷婷国产v国产偷v亚洲高清| 精品1区2区3区| 亚洲国产欧美在线人成| 欧美自拍偷拍一区| 香蕉久久夜色精品国产使用方法| 日本韩国精品一区二区在线观看| 成人欧美一区二区三区1314| 99riav久久精品riav| 国产精品国模大尺度视频| 99久久99久久精品免费观看| 日韩美女视频一区二区| 色综合天天做天天爱| 一区二区欧美视频| 欧美综合欧美视频| 日韩电影在线观看网站| 日韩亚洲欧美综合| 国产毛片精品视频| 国产精品久久网站| 色94色欧美sute亚洲13| 日日夜夜免费精品| 久久亚洲综合色一区二区三区| 岛国精品在线播放| 亚洲蜜桃精久久久久久久| 欧美私人免费视频| 久久99久久久久久久久久久| 国产亚洲婷婷免费| 色综合天天视频在线观看| 亚洲一区二区三区四区五区中文| 欧美高清视频不卡网| 激情小说亚洲一区| 亚洲色图清纯唯美| 日韩一卡二卡三卡四卡| 成人免费高清在线| 日韩在线一二三区| 国产欧美日本一区视频| 欧美偷拍一区二区| 国产福利精品一区| 亚洲国产欧美在线人成| xvideos.蜜桃一区二区| 91福利小视频| 激情综合色播五月| 亚洲男人电影天堂| 久久亚洲精华国产精华液| 97成人超碰视| 麻豆精品视频在线| 一区二区在线观看不卡| 精品国产百合女同互慰| 91麻豆福利精品推荐| 欧美a级理论片| 亚洲精品中文在线| 久久久国际精品| 欧美一区二区三区公司| 97久久超碰国产精品| 久久se这里有精品| 五月婷婷欧美视频| 亚洲欧美影音先锋| 国产欧美日韩综合| 欧美va亚洲va| 91精品久久久久久久久99蜜臂| av男人天堂一区| 国产一区二区三区在线观看免费 | 欧美刺激午夜性久久久久久久| av在线播放成人| 国产麻豆午夜三级精品| 日韩av网站免费在线| 亚洲精品中文字幕乱码三区| www欧美成人18+| 日韩欧美一区二区不卡| 欧美伊人久久大香线蕉综合69| 成人午夜大片免费观看| 天堂影院一区二区| 亚洲国产一区二区a毛片| 亚洲视频免费观看| 中文成人综合网| 国产视频一区二区在线| 精品入口麻豆88视频| 欧美一级久久久久久久大片| 欧美精选一区二区| 欧美午夜在线观看| 一本一本久久a久久精品综合麻豆 一本一道波多野结衣一区二区 | 久久久久久99久久久精品网站| 这里只有精品99re| 欧美情侣在线播放| 欧美日本韩国一区二区三区视频 | 亚洲精品一线二线三线| 日韩午夜电影av| 精品欧美乱码久久久久久| 欧美一二区视频| 欧美电影免费观看高清完整版在线| 67194成人在线观看| 制服.丝袜.亚洲.中文.综合| 欧美精品日日鲁夜夜添| 7777精品伊人久久久大香线蕉| 欧美日韩一区视频| 欧美高清精品3d| 精品日韩在线观看| 久久久综合激的五月天| 欧美韩日一区二区三区| 日韩美女久久久| 亚洲国产色一区| 六月丁香综合在线视频| 国产在线麻豆精品观看| 国产精品资源在线看| 成人免费va视频| 色88888久久久久久影院按摩| 欧美日韩专区在线| 精品剧情v国产在线观看在线| 国产视频视频一区| 尤物在线观看一区| 天天影视涩香欲综合网| 国产一区二区三区黄视频| 大白屁股一区二区视频| 欧洲一区二区三区在线| 91精品国产色综合久久不卡蜜臀 | 国产在线精品一区二区不卡了| 国产高清亚洲一区| 欧美午夜精品电影| 欧美不卡在线视频| 亚洲视频小说图片| 久久精品国产精品亚洲红杏 | 国产精品麻豆网站| 日精品一区二区| 成人av资源在线| 欧美日韩国产一二三| xnxx国产精品| 亚洲国产精品视频| 国产精品一级黄| 欧美日韩精品二区第二页| 久久亚洲春色中文字幕久久久| 一区二区三区欧美视频| 久草在线在线精品观看| 91在线观看美女| 日韩欧美的一区| 亚洲精品免费在线播放| 国产综合久久久久久久久久久久| 26uuu久久综合| 亚洲成人久久影院| www.日韩大片| 久久久九九九九| 天天色天天操综合| 99精品欧美一区| 久久视频一区二区| 亚州成人在线电影| 成人黄动漫网站免费app| 538在线一区二区精品国产| 国产精品激情偷乱一区二区∴| 蜜桃精品视频在线| 欧美主播一区二区三区美女| 日韩精品一区二区三区中文精品| 亚洲激情男女视频| 国产·精品毛片| 久久综合色婷婷| 日本不卡一区二区三区高清视频| gogogo免费视频观看亚洲一| 26uuu国产电影一区二区| 日韩国产在线观看| 欧美伊人久久久久久久久影院 | 国产精品99久久久| 欧美一区二区视频观看视频 | 亚洲精品中文字幕乱码三区| 国产99一区视频免费| 精品捆绑美女sm三区| 全国精品久久少妇| 国产精品理伦片| 国产成人一级电影| 久久久精品一品道一区| 国内精品久久久久影院薰衣草| 日韩精品中午字幕| 精品影视av免费| 日韩限制级电影在线观看| 美国十次综合导航| 欧美v日韩v国产v|