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

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

?? halstack.c

?? zigbeeC++的源代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
  V0.1 Initial Release   10/July/2006

*/

#include "hal.h"
#include "halStack.h"
#include "console.h"
#include "debug.h"
#include "ieee_lrwpan_defs.h"
#include "memalloc.h"
#include "phy.h"
#include "mac.h"

/*
V0.2.2.
  8/2/2006 Fixed problem with checking of CRC byte.
*/


RADIO_FLAGS local_radio_flags;

#ifdef  LRWPAN_ASYNC_INTIO

static volatile BYTE serio_rxBuff[LRWPAN_ASYNC_RX_BUFSIZE];
static volatile BYTE serio_rxHead, serio_rxTail;

#endif




//halInit contains both processor specific initialization
void halInit(void){
  //Set clock source
  local_radio_flags.val = 0;
  SET_MAIN_CLOCK_SOURCE(CRYSTAL);
  halInitUart();
  halSetBaud(LRWPAN_DEFAULT_BAUDRATE);
  halInitMACTimer();
}


//initialize UART to be used by
void halInitUart(void) {
  // Setup for UART0
   IO_PER_LOC_UART0_AT_PORT0_PIN2345();
   UTX0IF = 1;

#ifdef LRWPAN_ASYNC_INTIO
  serio_rxHead = 0;
  serio_rxTail = 0;
  INT_ENABLE_URX0(INT_ON);
#endif

}

#ifdef  LRWPAN_ASYNC_INTIO

//get a character from serial port, uses interrupt driven IO
char halGetch(void){
    char x;
    do {
      x = serio_rxHead;  //use tmp because of volt decl
    }  while(serio_rxTail == x);
    serio_rxTail++;
   if (serio_rxTail == LRWPAN_ASYNC_RX_BUFSIZE) serio_rxTail = 0;
   return (serio_rxBuff[serio_rxTail]);
}

 BOOL halGetchRdy(void){
   char x;
   x = serio_rxHead;
   return(serio_rxTail != x);
 }

#else
//get a character from serial port
char halGetch(void){
   char c;

   while (!URX0IF);
   c = U0DBUF;
   URX0IF = FALSE;

   return c;
}

BOOL halGetchRdy(void){

  if (URX0IF) return (1);
  else return(0);

}

#endif


void halUtilMemCopy(BYTE *dst, BYTE *src, BYTE len) {
  while (len) {
    *dst = *src;
    dst++;src++;
    len--;
  }
}

// assuming 16us period, have 1/16us = 62500 tics per seocnd
#define T2CMPVAL (62500/SLOWTICKS_PER_SECOND)

//use timer2, will set it up for one tick per symbol
//assuming 2.4GHZ and a 32 MHZ clock.
// this is a 20 bit counter, will overflow in ~16 seconds
//should be long enough for MAC timeout cases
void halInitMACTimer(void) {

  T2CNF = 0x00; //ensure timer is idle

  T2CAPHPH = 0x02;  // setting for 16 u-second periods
  T2CAPLPL = 0x00;  // (0x0200) / 32 = 16 u-seconds
  //set the interrupt compare to its maximum value

#ifdef LRWPAN_ENABLE_SLOW_TIMER
  T2PEROF0 = 0xFF & (T2CMPVAL);
  T2PEROF1 = (BYTE) (T2CMPVAL>>8);
  //enable overflow count compare interrupt
  T2PEROF2 = ((BYTE) (T2CMPVAL>>16)) | 0x20;
#endif

  //turn on timer
  //configure timer
  T2CNF = 0x03; //start timer

  INT_SETFLAG_T2(INT_CLR); //clear processor interrupt flag
  //enable T2 processor interrupt
#ifdef LRWPAN_ENABLE_SLOW_TIMER
  INT_ENABLE_T2(INT_ON);
#endif

}

UINT32 halGetMACTimer(void){
  UINT32 t;
  BOOL gie_status;

  SAVE_AND_DISABLE_GLOBAL_INTERRUPT(gie_status);
  t = 0x0FF & T2OF0;
  t += (((UINT16)T2OF1)<<8);
  t += (((UINT32) T2OF2 & 0x0F)<<16);
  RESTORE_GLOBAL_INTERRUPT(gie_status);
  return (t);
}

#ifdef LRWPAN_COMPILER_NO_RECURSION
UINT32 halISRGetMACTimer(void){
  UINT32 t;
  BOOL gie_status;

  SAVE_AND_DISABLE_GLOBAL_INTERRUPT(gie_status);
  t = 0x0FF & T2OF0;
  t += (((UINT16)T2OF1)<<8);
  t += (((UINT32) T2OF2 & 0x0F)<<16);
  RESTORE_GLOBAL_INTERRUPT(gie_status);
  return (t);
}

#endif




//only works as long as SYMBOLS_PER_MAC_TICK is not less than 1
UINT32 halMacTicksToUs(UINT32 ticks){

   UINT32 rval;

   rval =  (ticks/SYMBOLS_PER_MAC_TICK())* (1000000/LRWPAN_SYMBOLS_PER_SECOND);
   return(rval);
}

//assumes that Timer2 has been initialized and is running
UINT8 halGetRandomByte(void) {
  return(T2OF0);
}

//write a character to serial port
// Uses UART initialized by halInitUart

void halPutch(char c){
  while (!UTX0IF);
  UTX0IF = 0;
  U0DBUF = c;
}

void halRawPut(char c){
  while (!UTX0IF);
  UTX0IF = 0;
  U0DBUF = c;
}





//set the radio frequency
LRWPAN_STATUS_ENUM halSetRadioIEEEFrequency(PHY_FREQ_ENUM frequency, BYTE channel)
{
   UINT16 afreq;

   if (frequency != PHY_FREQ_2405M) return(LRWPAN_STATUS_PHY_FAILED);
   if ((channel < 11) || (channel > 26)) return(LRWPAN_STATUS_PHY_FAILED);
   afreq = 357 + 5*(channel - 11);
   FSCTRLL = (BYTE) afreq;
   FSCTRLH = ((FSCTRLH & ~0x03) | (BYTE)((afreq >> 8) & 0x03));
   return(LRWPAN_STATUS_SUCCESS);
}

//this assumes 2.4GHz frequency
LRWPAN_STATUS_ENUM halSetChannel(BYTE channel){
 return(halSetRadioIEEEFrequency(PHY_FREQ_2405M, channel));
}


#if defined(IAR8051)
//this uses the IEEE address stored in program memory.
//ensure that the flash programmer is configured to retain
//the IEEE address
void halGetProcessorIEEEAddress(BYTE *buf) {
#if (CC2430_FLASH_SIZE == 128)
  unsigned char bank;
  bank = MEMCTR;
  //switch to bank 3
  MEMCTR |= 0x30;
#endif
  //note that the flash programmer stores these in BIG ENDIAN order for some reason!!!
  buf[7] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+0);
  buf[6] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+1);
  buf[5] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+2);
  buf[4] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+3);
  buf[3] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+4);
  buf[2] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+5);
  buf[1] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+6);
  buf[0] = *(ROMCHAR *)(IEEE_ADDRESS_ARRAY+7);
 #if (CC2430_FLASH_SIZE == 128)
  //resore old bank settings
  MEMCTR = bank;
#endif
}

#endif


#if defined(HI_TECH_C)
//cannot figure out how to get the Hi-Tech C51 compiler to support
//banking, so can't access the IEEE address stored in memory

//use this if you don't want to use the IEEE Address stored in program memory
//by the flash memory
void halGetProcessorIEEEAddress(BYTE *buf) {
	buf[0] = aExtendedAddress_B0;
	buf[1] = aExtendedAddress_B1;
	buf[2] = aExtendedAddress_B2;
	buf[3] = aExtendedAddress_B3;
	buf[4] = aExtendedAddress_B4;
	buf[5] = aExtendedAddress_B5;
	buf[6] = aExtendedAddress_B6;
	buf[7] = aExtendedAddress_B7;
}
#endif



void halSetRadioIEEEAddress(void) {
  BYTE buf[8];
  halGetProcessorIEEEAddress(buf);
  IEEE_ADDR0 = buf[0];
  IEEE_ADDR1 = buf[1];
  IEEE_ADDR2 = buf[2];
  IEEE_ADDR3 = buf[3];
  IEEE_ADDR4 = buf[4];
  IEEE_ADDR5 = buf[5];
  IEEE_ADDR6 = buf[6];
  IEEE_ADDR7 = buf[7];
}

void halSetRadioPANID(UINT16 panid){
  PANIDL = (BYTE) (panid);
  PANIDH = (BYTE) (panid>>8);
 }

void halSetRadioShortAddr(SADDR saddr){
  SHORTADDRL = (BYTE) (saddr);
  SHORTADDRH = (BYTE) (saddr>>8);
}



//return value of non-zero indicates failure
//Turn on Radio, initialize for RF mode
//assumes that auto-ack is enabled
//this function based on sppInit example from ChipCon
//also sets the IEEE address
//if listen_flag is true, then radio is configured for
//listen only (no auto-ack, no address recognition)

/*
Eventually, change this so that auto-ack can be configured as
on or off. When Coordinator is trying to start a network,
auto-ack, addr decoding will be off as Coordinator will be doing an energy
scan and detecting PAN collisions, and thus will not be doing
any acking of packets. After the network is started, then
will enable auto-acking.
Routers and End devices will always auto-ack

i
*/



LRWPAN_STATUS_ENUM halInitRadio(PHY_FREQ_ENUM frequency, BYTE channel, RADIO_FLAGS radio_flags)
{
  LRWPAN_STATUS_ENUM status;


  // Setting the frequency
  status = halSetRadioIEEEFrequency(frequency, channel);
  if (status != LRWPAN_STATUS_SUCCESS) return(status);

  //turning on power to analog part of radio and waiting for voltage regulator.
  RFPWR = 0x04;
  while((RFPWR & 0x10)){}
  //radio_flags.listen_mode=1; //debug
  if (radio_flags.bits.listen_mode) {
    //corresponds to promiscuous modes
    //radio accepts all packets, the HUSSY!
    MDMCTRL0H &= ~ADR_DECODE;    //no address decode
    MDMCTRL0L &= ~AUTO_ACK;       //no auto ack
  } else {
    // Turning on Address Decoding
    MDMCTRL0H |= ADR_DECODE;
    //enable auto_ack
    MDMCTRL0L |= AUTO_ACK;
  }
  local_radio_flags = radio_flags;  //save this for later
  // Setting for AUTO CRC
  MDMCTRL0L |= AUTO_CRC;

  //pan
  if (radio_flags.bits.pan_coordinator) {
    MDMCTRL0H |= PAN_COORDINATOR;  //accepts frames with only source addressing modes
  } else {
    MDMCTRL0H &= ~PAN_COORDINATOR;  //rejects frames with only source addressing modes
  }

  // Turning on AUTO_TX2RX
  FSMTC1 = ((FSMTC1 & (~AUTO_TX2RX_OFF & ~RX2RX_TIME_OFF))  | ACCEPT_ACKPKT);

  // Turning off abortRxOnSrxon.
  FSMTC1 &= ~0x20;

  //now configure the RX, TX systems.
  // Setting the number of bytes to assert the FIFOP flag
  IOCFG0 = 127;  //set to max value as the FIFOP flag goes high when complete packet received

  // Flushing both Tx and Rx FiFo. The flush-Rx is issued twice to reset the SFD.
  // Calibrating the radio and turning on Rx to evaluate the CCA.
  SRXON;
  SFLUSHTX;
  SFLUSHRX;
  SFLUSHRX;
  STXCALN;
  ISSTART;

//this controls the frame pending bit in ACK frames.
//because of auto-ack, we will not have time to determine if data
//is actually pending or not.
#if defined(LWRPAN_RFD)
  SACK;  //RFDs never have data pending for FFDs
#else
  SACKPEND;  //routers/
#endif

  halSetRadioIEEEAddress();

   //Radio can interrupt when
   //RX configuration
   //clear flags/mask in radio
   RFIF = 0;
   RFIM = 0;   //all interrupts are masked.
   //enable RX interrupt on processor
   INT_SETFLAG_RF(INT_CLR);
   INT_ENABLE_RF(INT_ON);

   //enable RX RFERR interrupt on processor
   INT_SETFLAG_RFERR(INT_CLR);
   INT_ENABLE_RFERR(INT_ON);

   //do not use DMA at this point
   //enable the RX receive interrupt here.
   RFIM |= IRQ_FIFOP;

   return(LRWPAN_STATUS_SUCCESS);
}

#define PIN_CCA   CCA    //CCA is defined in hal.h

//regardless of what happens here, we will try TXONCCA after this returns.
void  doIEEE_backoff(void) {
     BYTE be, nb, tmp, rannum;
    UINT32  delay, start_tick;

   be = aMinBE;
   nb = 0;
  do {
      if (be) {
        //do random delay
        tmp = be;
        //compute new delay
        delay = 1;
        while (tmp) {
          delay = delay << 1;  //delay = 2**be;
           tmp--;
         }
        rannum =  halGetRandomByte() & (delay-1); //rannum will be between 0 and delay-1
        delay = 0;
        while (rannum) {
            delay  += SYMBOLS_TO_MACTICKS(aUnitBackoffPeriod);
            rannum--;
         }//delay = aUnitBackoff * rannum
        //now do backoff
       start_tick = halGetMACTimer();
        while (halMACTimerNowDelta(start_tick) < delay);
      }
      //check CCA
      if (PIN_CCA)  break;
      nb++;
      be++;
      if (be > aMaxBE) be =aMaxBE;
   }while (nb <= macMaxCSMABackoffs);
  return;
}

//transmit packet
//hdrlen - header lenth
//hdr - pointer to header data
//plen - payload length
//pload - pointer to payload

LRWPAN_STATUS_ENUM halSendPacket(BYTE flen, BYTE *frm)
{
  BYTE len;
  LRWPAN_STATUS_ENUM res;

  //if you print out the packet, this can cause timeouts on waits
  //dbgPrintPacket(frm,flen+2);

  //total length, does not include length byte itself
  //last two bytes are the FCS bytes that are added automatically
  len = flen + PACKET_FOOTER_SIZE;

  DEBUG_STRING(DBG_INFO, "TX PKT Size: ");
  DEBUG_UINT8(DBG_INFO,len);
  DEBUG_STRING(DBG_INFO,"\n");
  if (len > 127) {
    //packet size is too large!
    return(LRWPAN_STATUS_PHY_TX_PKT_TOO_BIG);
  }

  // Clearing RF interrupt flags and enabling RF interrupts.
  if(FSMSTATE == 6 && RXFIFOCNT > 0)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品一区二区免费看| 1024亚洲合集| 欧美久久免费观看| 欧美日韩在线免费视频| 欧美探花视频资源| 欧美美女黄视频| 欧美精品少妇一区二区三区| 欧美久久一二三四区| 日韩欧美国产精品| 欧美激情一区二区三区四区| 国产精品日韩成人| 一区二区三区日韩精品| 亚洲国产日韩一级| 美女视频黄久久| 国产麻豆一精品一av一免费| 成人理论电影网| 91看片淫黄大片一级| 欧美日韩一区二区欧美激情| 日韩欧美一卡二卡| 欧美国产日本视频| 亚洲国产综合在线| 九色|91porny| 91黄视频在线观看| 日韩一区二区三免费高清| 久久伊人蜜桃av一区二区| 成人欧美一区二区三区白人| 日本vs亚洲vs韩国一区三区 | 精品国产污网站| 亚洲国产精品二十页| 亚洲一二三区视频在线观看| 捆绑调教一区二区三区| av中文字幕在线不卡| 欧美日韩欧美一区二区| 精品久久久久久久久久久久包黑料 | 91精品国产综合久久精品性色| 欧美一区二区视频在线观看2022| 日本一区二区三区国色天香| 亚洲高清免费一级二级三级| 国产成人鲁色资源国产91色综| 色哟哟欧美精品| 国产日韩欧美一区二区三区乱码| 成人免费一区二区三区视频 | 国产成人精品亚洲777人妖 | www国产亚洲精品久久麻豆| 一区二区三区精品久久久| 国产一区二区剧情av在线| 欧美视频三区在线播放| 中文字幕中文字幕中文字幕亚洲无线| 亚洲一区二区视频在线| 国产成人综合精品三级| 欧美一区二区三区不卡| 亚洲自拍偷拍网站| 91最新地址在线播放| 久久久五月婷婷| 日韩激情中文字幕| 在线一区二区三区做爰视频网站| 国产亚洲综合性久久久影院| 丝袜亚洲另类丝袜在线| 日本丶国产丶欧美色综合| 国产精品色一区二区三区| 国产米奇在线777精品观看| 欧美精品久久久久久久多人混战 | 秋霞午夜鲁丝一区二区老狼| 在线看不卡av| 亚洲精品免费在线观看| av在线这里只有精品| 国产片一区二区三区| 精品在线观看免费| 欧美va亚洲va在线观看蝴蝶网| 性做久久久久久久久| 欧美伊人久久久久久久久影院| 亚洲人成网站在线| 在线视频一区二区三| 亚洲视频免费在线| 色综合天天性综合| 伊人婷婷欧美激情| 欧美三区免费完整视频在线观看| 亚洲男人天堂一区| 欧美色网一区二区| 日韩成人精品视频| 亚洲精品在线免费观看视频| 激情综合亚洲精品| 国产精品午夜在线观看| 91麻豆高清视频| 亚洲国产成人91porn| 欧美一区二区三区免费在线看| 日本欧美加勒比视频| 日韩亚洲电影在线| 国产一区二区三区在线观看免费视频 | 91美女片黄在线| 天天综合网天天综合色| 欧美一区二区三区婷婷月色| 秋霞午夜av一区二区三区| 欧美精品一区二区三| 成人高清免费观看| 亚洲激情五月婷婷| 制服.丝袜.亚洲.另类.中文| 国产乱理伦片在线观看夜一区 | 亚洲综合清纯丝袜自拍| 91精品久久久久久久99蜜桃| 国产精品538一区二区在线| 亚洲欧美日韩国产中文在线| 欧美一区二区三区的| 东方aⅴ免费观看久久av| 亚洲国产精品一区二区尤物区| 日韩免费观看2025年上映的电影| 国产99久久久精品| 性做久久久久久久免费看| 久久―日本道色综合久久| 色婷婷av一区二区三区大白胸 | 欧美色图片你懂的| 国产伦精品一区二区三区免费| 亚洲视频小说图片| 欧美一级日韩不卡播放免费| 91蜜桃网址入口| 国产在线不卡一区| 亚洲 欧美综合在线网络| 欧美激情综合五月色丁香| 日韩一区二区视频在线观看| 成人app软件下载大全免费| 免费人成网站在线观看欧美高清| 亚洲日本在线看| 久久日韩粉嫩一区二区三区| 7777精品伊人久久久大香线蕉超级流畅 | 国产日本亚洲高清| 欧美日韩不卡一区二区| 91香蕉视频黄| 成人爱爱电影网址| 精品一区二区成人精品| 日本欧美韩国一区三区| 亚洲伦在线观看| 国产精品电影院| 欧美激情一区二区| 久久在线免费观看| 日韩午夜电影在线观看| 欧美日韩视频专区在线播放| 色婷婷激情综合| 一本大道久久a久久综合| 成人av免费在线| 成人小视频在线| 国产91精品免费| 国产白丝网站精品污在线入口 | 中文字幕av一区 二区| 久久先锋影音av鲁色资源| 日韩午夜av一区| 日韩视频免费观看高清完整版 | 美女视频黄 久久| 亚洲成国产人片在线观看| 一区二区三区免费在线观看| 亚洲女人的天堂| 亚洲视频在线观看三级| 1024成人网| 亚洲综合图片区| 亚洲成在线观看| 免费成人在线观看视频| 久草精品在线观看| 国产精品一二三区在线| 国产麻豆午夜三级精品| 成人免费高清在线观看| 91女神在线视频| 欧美在线观看一区| 欧美一级日韩免费不卡| 久久亚洲春色中文字幕久久久| 国产亚洲va综合人人澡精品| 亚洲国产精品成人综合| 伊人开心综合网| 日本成人在线网站| 国产精品一级黄| 色88888久久久久久影院按摩| 欧美综合天天夜夜久久| 日韩手机在线导航| 国产日韩欧美综合在线| 一区二区三区.www| 免费xxxx性欧美18vr| 国产精品一区二区三区99| 99久久国产综合色|国产精品| 欧美在线一区二区三区| 精品免费视频一区二区| 国产欧美1区2区3区| 一区二区成人在线| 麻豆视频观看网址久久| 99精品国产91久久久久久 | 成人一级片在线观看| 欧美午夜电影在线播放| 久久婷婷综合激情| 亚洲永久精品大片| 国产一区亚洲一区| 91豆麻精品91久久久久久| 欧美xfplay| 亚洲国产中文字幕在线视频综合| 狠狠色丁香久久婷婷综| 色天使色偷偷av一区二区| 欧美mv日韩mv国产网站app| 亚洲精品一二三四区| 黑人精品欧美一区二区蜜桃| 欧美中文字幕不卡| 中文字幕精品综合| 免费观看91视频大全| 色94色欧美sute亚洲线路二| 国产日产欧美一区|