久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3051|回復: 0
打印 上一主題 下一主題
收起左側(cè)

DM1000資料與源程序(arm與pc平臺)給大家提供參考

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:265300 發(fā)表于 2018-1-16 21:40 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
給需要采用DM1000的朋友提供一個參考


全部資料51hei下載地址:

evk_sw_package_arm3.05_pc3.05c.zip (5.73 MB, 下載次數(shù): 14)



單片機源程序如下:
  1. /*! ----------------------------------------------------------------------------
  2. *  @file    main.c
  3. *  @brief   main loop for the DecaRanging application
  4. *
  5. * @attention
  6. *
  7. * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland.
  8. *
  9. * All rights reserved.
  10. *
  11. * @author DecaWave
  12. */
  13. /* Includes */
  14. #include "compiler.h"
  15. #include "port.h"

  16. #include "instance.h"

  17. #include "deca_types.h"

  18. #include "deca_spi.h"
  19. #include "stdio.h"

  20. extern void usb_run(void);
  21. extern int usb_init(void);
  22. extern void usb_printconfig(int, uint8*, int);
  23. extern void send_usbmessage(uint8*, int);


  24. #define DWINTERRUPT_EN (1)  //set to 1 when using DW interrupt, set to 0 to poll DW1000 IRQ line

  25. #define SOFTWARE_VER_STRING    "Version 3.05    " //


  26. #define SWS1_SRM_MODE 0x80  //slow ranging mode with PC - response is configurable and > 150 ms
  27. #define SWS1_ANC_MODE 0x08  //anchor mode
  28. #define SWS1_SHF_MODE 0x10        //short frame mode (6.81M) (switch S1-5)
  29. #define SWS1_64M_MODE 0x20        // 64M PRF mode (switch S1-6)
  30. #define SWS1_CH5_MODE 0x40        //channel 5 mode (switch S1-7)

  31. int instance_anchaddr = 0; //0 = 0xDECA020000000001; 1 = 0xDECA020000000002; 2 = 0xDECA020000000003
  32. //NOTE: switches TA_SW1_7 and TA_SW1_8 are used to set tag/anchor address
  33. int dr_mode = 0;
  34. //if instance_mode = TAG_TDOA then the device cannot be selected as anchor
  35. int instance_mode = ANCHOR;
  36. //int instance_mode = TAG;
  37. //int instance_mode = TAG_TDOA;
  38. //int instance_mode = LISTENER;

  39. uint8 s1switch = 0;
  40. int chan, tagaddr, ancaddr;

  41. #define LCD_BUFF_LEN (100)
  42. uint8 dataseq[LCD_BUFF_LEN];
  43. uint8 dataseq1[LCD_BUFF_LEN];

  44. int ranging = 0;

  45. typedef struct
  46. {
  47.     uint8 channel ;
  48.     uint8 prf ;
  49.     uint8 datarate ;
  50.     uint8 preambleCode ;
  51.     uint8 preambleLength ;
  52.     uint8 pacSize ;
  53.     uint8 nsSFD ;
  54.     uint16 sfdTO ;
  55. } chConfig_t ;


  56. //Configuration for DecaRanging Modes (8 default use cases selectable by the switch S1 on EVK)
  57. chConfig_t chConfig[8] ={
  58.                     //mode 1 - S1: 7 off, 6 off, 5 off
  59.                     {
  60.                         2,              // channel
  61.                         DWT_PRF_16M,    // prf
  62.                         DWT_BR_110K,    // datarate
  63.                         3,             // preambleCode
  64.                         DWT_PLEN_1024,  // preambleLength
  65.                         DWT_PAC32,      // pacSize
  66.                         1,       // non-standard SFD
  67.                         (1025 + 64 - 32) //SFD timeout
  68.                     },
  69.                     //mode 2
  70.                     {
  71.                         2,              // channel
  72.                         DWT_PRF_16M,    // prf
  73.                         DWT_BR_6M8,    // datarate
  74.                         3,             // preambleCode
  75.                         DWT_PLEN_128,   // preambleLength
  76.                         DWT_PAC8,       // pacSize
  77.                         0,       // non-standard SFD
  78.                         (129 + 8 - 8) //SFD timeout
  79.                     },
  80.                     //mode 3
  81.                     {
  82.                         2,              // channel
  83.                         DWT_PRF_64M,    // prf
  84.                         DWT_BR_110K,    // datarate
  85.                         9,             // preambleCode
  86.                         DWT_PLEN_1024,  // preambleLength
  87.                         DWT_PAC32,      // pacSize
  88.                         1,       // non-standard SFD
  89.                         (1025 + 64 - 32) //SFD timeout
  90.                     },
  91.                     //mode 4
  92.                     {
  93.                         2,              // channel
  94.                         DWT_PRF_64M,    // prf
  95.                         DWT_BR_6M8,    // datarate
  96.                         9,             // preambleCode
  97.                         DWT_PLEN_128,   // preambleLength
  98.                         DWT_PAC8,       // pacSize
  99.                         0,       // non-standard SFD
  100.                         (129 + 8 - 8) //SFD timeout
  101.                     },
  102.                     //mode 5
  103.                     {
  104.                         5,              // channel
  105.                         DWT_PRF_16M,    // prf
  106.                         DWT_BR_110K,    // datarate
  107.                         3,             // preambleCode
  108.                         DWT_PLEN_1024,  // preambleLength
  109.                         DWT_PAC32,      // pacSize
  110.                         1,       // non-standard SFD
  111.                         (1025 + 64 - 32) //SFD timeout
  112.                     },
  113.                     //mode 6
  114.                     {
  115.                         5,              // channel
  116.                         DWT_PRF_16M,    // prf
  117.                         DWT_BR_6M8,    // datarate
  118.                         3,             // preambleCode
  119.                         DWT_PLEN_128,   // preambleLength
  120.                         DWT_PAC8,       // pacSize
  121.                         0,       // non-standard SFD
  122.                         (129 + 8 - 8) //SFD timeout
  123.                     },
  124.                     //mode 7
  125.                     {
  126.                         5,              // channel
  127.                         DWT_PRF_64M,    // prf
  128.                         DWT_BR_110K,    // datarate
  129.                         9,             // preambleCode
  130.                         DWT_PLEN_1024,  // preambleLength
  131.                         DWT_PAC32,      // pacSize
  132.                         1,       // non-standard SFD
  133.                         (1025 + 64 - 32) //SFD timeout
  134.                     },
  135.                     //mode 8
  136.                     {
  137.                         5,              // channel
  138.                         DWT_PRF_64M,    // prf
  139.                         DWT_BR_6M8,    // datarate
  140.                         9,             // preambleCode
  141.                         DWT_PLEN_128,   // preambleLength
  142.                         DWT_PAC8,       // pacSize
  143.                         0,       // non-standard SFD
  144.                         (129 + 8 - 8) //SFD timeout
  145.                     }
  146. };


  147. uint32 inittestapplication(uint8 s1switch);

  148. // Restart and re-configure
  149. void restartinstance(void)
  150. {
  151.     instance_close() ;                          //shut down instance, PHY, SPI close, etc.

  152.     spi_peripheral_init();                      //re initialise SPI...

  153.     inittestapplication(s1switch) ;                     //re-initialise instance/device
  154. } // end restartinstance()

  155. //NOTE: Channel 5 is not supported for the non-discovery mode
  156. int decarangingmode(uint8 s1switch)
  157. {
  158.     int mode = 0;

  159.     if(s1switch & SWS1_SHF_MODE)
  160.     {
  161.         mode = 1;
  162.     }

  163.     if(s1switch & SWS1_64M_MODE)
  164.     {
  165.         mode = mode + 2;
  166.     }
  167.     if(s1switch & SWS1_CH5_MODE)
  168.     {
  169.         mode = mode + 4;
  170.     }

  171.     return mode;
  172. }

  173. uint32 inittestapplication(uint8 s1switch)
  174. {
  175.     uint32 devID ;
  176.     instanceConfig_t instConfig;
  177.     int result;

  178.     SPI_ConfigFastRate(SPI_BaudRatePrescaler_32);  //max SPI before PLLs configured is ~4M

  179.     //this is called here to wake up the device (i.e. if it was in sleep mode before the restart)
  180.     devID = instancereaddeviceid() ;
  181.     if(DWT_DEVICE_ID != devID) //if the read of device ID fails, the DW1000 could be asleep
  182.     {
  183.         port_SPIx_clear_chip_select();  //CS low
  184.         Sleep(1);   //200 us to wake up then waits 5ms for DW1000 XTAL to stabilise
  185.         port_SPIx_set_chip_select();  //CS high
  186.         Sleep(7);
  187.         devID = instancereaddeviceid() ;
  188.         // SPI not working or Unsupported Device ID
  189.         if(DWT_DEVICE_ID != devID)
  190.             return(-1) ;
  191.         //clear the sleep bit - so that after the hard reset below the DW does not go into sleep
  192.         dwt_softreset();
  193.     }

  194.     //reset the DW1000 by driving the RSTn line low
  195.     reset_DW1000();

  196.     result = instance_init() ;
  197.     if (0 > result) return(-1) ; // Some failure has occurred

  198.     SPI_ConfigFastRate(SPI_BaudRatePrescaler_4); //increase SPI to max
  199.     devID = instancereaddeviceid() ;

  200.     if (DWT_DEVICE_ID != devID)   // Means it is NOT MP device
  201.     {
  202.         // SPI not working or Unsupported Device ID
  203.         return(-1) ;
  204.     }


  205.     if(s1switch & SWS1_ANC_MODE)
  206.     {
  207.         instance_mode = ANCHOR;

  208.         led_on(LED_PC6);

  209.     }
  210.     else
  211.     {
  212.         instance_mode = TAG;
  213.         led_on(LED_PC7);
  214.     }

  215.     instancesetrole(instance_mode) ;     // Set this instance role

  216.     instance_init_s(instance_mode);
  217.     dr_mode = decarangingmode(s1switch);

  218.     instConfig.channelNumber = chConfig[dr_mode].channel ;
  219.     instConfig.preambleCode = chConfig[dr_mode].preambleCode ;
  220.     instConfig.pulseRepFreq = chConfig[dr_mode].prf ;
  221.     instConfig.pacSize = chConfig[dr_mode].pacSize ;
  222.     instConfig.nsSFD = chConfig[dr_mode].nsSFD ;
  223.     instConfig.sfdTO = chConfig[dr_mode].sfdTO ;
  224.     instConfig.dataRate = chConfig[dr_mode].datarate ;
  225.     instConfig.preambleLen = chConfig[dr_mode].preambleLength ;


  226.     instance_config(&instConfig) ;                  // Set operating channel etc

  227.     instancesettagsleepdelay(POLL_SLEEP_DELAY, BLINK_SLEEP_DELAY); //set the Tag sleep time

  228.     instance_init_timings();

  229.     return devID;
  230. }
  231. /**
  232. **===========================================================================
  233. **
  234. **  Abstract: main program
  235. **
  236. **===========================================================================
  237. */
  238. void process_dwRSTn_irq(void)
  239. {
  240.     instance_notify_DW1000_inIDLE(1);
  241. }


  242. #if (DWINTERRUPT_EN == 1)
  243. void process_deca_irq(void)
  244. {
  245.     do{

  246.         instance_process_irq(0);

  247.     }while(port_CheckEXT_IRQ() == 1); //while IRQ line active (ARM can only do edge sensitive interrupts)

  248. }
  249. #else
  250. void process_deca_irq(void)
  251. {
  252.         while(dwt_checkIRQ() == 1)
  253.         {
  254.         instance_process_irq(0);
  255.     } //while IRQ line active

  256. }
  257. #endif

  258. void initLCD(void)
  259. {
  260.     uint8 initseq[9] = { 0x39, 0x14, 0x55, 0x6D, 0x78, 0x38 /*0x3C*/, 0x0C, 0x01, 0x06 };
  261.     uint8 command = 0x0;
  262.     int j = 100000;

  263.     writetoLCD( 9, 0,  initseq); //init seq
  264.     while(j--);

  265.     command = 0x2 ;  //return cursor home
  266.     writetoLCD( 1, 0,  &command);
  267.     command = 0x1 ;  //clear screen
  268.     writetoLCD( 1, 0,  &command);
  269. }

  270. /*
  271. * @brief switch_mask  - bitmask of testing switches (currently 7 switches)
  272. *        switchbuff[] - switch name to test
  273. *        *switch_fn[]() - corresponded to switch test function
  274. **/
  275. #define switch_mask   (0x7F)

  276. const uint8 switchbuf[]={0, TA_SW1_3 , TA_SW1_4 , TA_SW1_5 , TA_SW1_6 , TA_SW1_7 , TA_SW1_8 };
  277. typedef int (* switch_handler_t)(uint16) ;
  278. const switch_handler_t switch_fn[] ={ is_button_low, \
  279.                                 is_switch_on, is_switch_on, is_switch_on,\
  280.                                 is_switch_on, is_switch_on, is_switch_on };

  281. /*
  282. * @fn test_application_run
  283. * @brief   test application for production pre-test procedure
  284. **/
  285. void test_application_run(void)
  286. {
  287.     char  dataseq[2][40];
  288.     uint8 j, switchStateOn, switchStateOff;

  289.     switchStateOn=0;
  290.     switchStateOff=0;

  291.     led_on(LED_ALL);    // show all LED OK
  292.     Sleep(1000);

  293.     dataseq[0][0] = 0x1 ;  //clear screen
  294.     writetoLCD( 1, 0, (const uint8 *) &dataseq);
  295.     dataseq[0][0] = 0x2 ;  //return cursor home
  296.     writetoLCD( 1, 0, (const uint8 *) &dataseq);

  297. /* testing SPI to DW1000*/
  298.     writetoLCD( 40, 1, (const uint8 *) "TESTING         ");
  299.     writetoLCD( 40, 1, (const uint8 *) "SPI, U2, S2, S3 ");
  300.     Sleep(1000);

  301.     if(inittestapplication(s1switch) == (uint32)-1)
  302.     {
  303.         writetoLCD( 40, 1, (const uint8 *) "SPI, U2, S2, S3 ");
  304.         writetoLCD( 40, 1, (const uint8 *) "-- TEST FAILS --");
  305.         while(1); //stop
  306.     }

  307.     writetoLCD( 40, 1, (const uint8 *) "SPI, U2, S2, S3 ");
  308.     writetoLCD( 40, 1, (const uint8 *) "    TEST OK     ");
  309.     Sleep(1000);

  310. /* testing of switch S2 */
  311.     dataseq[0][0] = 0x1 ;  //clear screen
  312.     writetoLCD( 1, 0, (const uint8 *) &dataseq);

  313.     while( (switchStateOn & switchStateOff) != switch_mask )
  314.         {
  315.         memset(&dataseq, ' ', sizeof(dataseq));
  316.         strcpy(&dataseq[0][0], (const char *)"SWITCH");
  317.         strcpy(&dataseq[1][0], (const char *)"toggle");
  318. //switch 7-1
  319.         for (j=0;j<sizeof(switchbuf);j++)
  320.         {
  321.             if( switch_fn[j](switchbuf[j]) ) //execute current switch switch_fn
  322.             {
  323.                 dataseq[0][8+j]='O';
  324.                 switchStateOn |= 0x01<<j;
  325.                 switchStateOff &= ~(0x01<<j);//all switches finaly should be in off state
  326.             }else{
  327.                 dataseq[1][8+j]='O';
  328.                 switchStateOff |=0x01<<j;
  329.         }
  330.         }

  331.         writetoLCD(40, 1, (const uint8 *) &dataseq[0][0]);
  332.         writetoLCD(40, 1, (const uint8 *) &dataseq[1][0]);
  333.         Sleep(100);
  334.         }

  335.     led_off(LED_ALL);

  336.     writetoLCD( 40, 1, (const uint8 *) "  Preliminary   ");
  337.     writetoLCD( 40, 1, (const uint8 *) "   TEST OKAY    ");

  338.     while(1);
  339.     }


  340. void setLCDline1(uint8 s1switch)
  341. {
  342.         uint8 command = 0x2 ;  //return cursor home
  343.     writetoLCD( 1, 0,  &command);

  344.         sprintf((char*)&dataseq[0], "DecaRanging  %02x", s1switch);
  345.         writetoLCD( 40, 1, dataseq); //send some data

  346.         sprintf((char*)&dataseq1[0], "                 ");
  347.         writetoLCD( 16, 1, dataseq1); //send some data
  348. }

  349. /*
  350. * @fn      main()
  351. * @brief   main entry point
  352. **/
  353. int main(void)
  354. {
  355.     int i = 0;
  356.     int toggle = 1;
  357.     double range_result = 0;
  358.     double avg_result = 0;

  359.     led_off(LED_ALL); //turn off all the LEDs

  360.     peripherals_init();

  361.     spi_peripheral_init();

  362.     Sleep(1000); //wait for LCD to power on

  363.     initLCD();

  364.     memset(dataseq, 0, LCD_BUFF_LEN);
  365.     memcpy(dataseq, (const uint8 *) "DECAWAVE        ", 16);
  366.     writetoLCD( 40, 1, dataseq); //send some data
  367.     memcpy(dataseq, (const uint8 *) SOFTWARE_VER_STRING, 16); // Also set at line #26 (Should make this from single value !!!)
  368.     writetoLCD( 16, 1, dataseq); //send some data

  369.     Sleep(1000);
  370. #ifdef USB_SUPPORT
  371.     // enable the USB functionality
  372.     usb_init();
  373.     Sleep(1000);
  374. #endif

  375.     s1switch = is_button_low(0) << 1 // is_switch_on(TA_SW1_2) << 2
  376.                     | is_switch_on(TA_SW1_3) << 2
  377.                     | is_switch_on(TA_SW1_4) << 3
  378.                     | is_switch_on(TA_SW1_5) << 4
  379.                     | is_switch_on(TA_SW1_6) << 5
  380.                     | is_switch_on(TA_SW1_7) << 6
  381.                     | is_switch_on(TA_SW1_8) << 7;

  382.     port_DisableEXT_IRQ(); //disable ScenSor IRQ until we configure the device

  383.     //test EVB1000 - used in EVK1000 production
  384.     if((is_button_low(0) == S1_SWITCH_ON) && (is_switch_on(TA_SW1_8) == S1_SWITCH_ON)) //using BOOT1 switch for test
  385.     {
  386.         test_application_run(); //does not return....
  387.     }
  388.     else
  389.     if(is_switch_on(TA_SW1_3) == S1_SWITCH_OFF)
  390.     {
  391.         int j = 1000000;
  392.         uint8 command;

  393.         memset(dataseq, 0, LCD_BUFF_LEN);

  394.         while(j--);
  395.         //command = 0x1 ;  //clear screen
  396.         //writetoLCD( 1, 0,  &command);
  397.         command = 0x2 ;  //return cursor home
  398.         writetoLCD( 1, 0,  &command);

  399.         memcpy(dataseq, (const uint8 *) "DECAWAVE   ", 12);
  400.         writetoLCD( 40, 1, dataseq); //send some data
  401. #ifdef USB_SUPPORT //this is set in the port.h file
  402.         memcpy(dataseq, (const uint8 *) "USB to SPI ", 12);
  403. #else
  404. #endif
  405.         writetoLCD( 16, 1, dataseq); //send some data

  406.         j = 1000000;

  407.         while(j--);

  408.         command = 0x2 ;  //return cursor home
  409.         writetoLCD( 1, 0,  &command);
  410. #ifdef USB_SUPPORT //this is set in the port.h file
  411.         // enable the USB functionality
  412.         //usb_init();

  413.         NVIC_DisableDECAIRQ();

  414.         // Do nothing in foreground -- allow USB application to run, I guess on the basis of USB interrupts?
  415.         while (1)       // loop forever
  416.         {
  417.             usb_run();
  418.         }
  419. #endif
  420.         return 1;
  421.     }
  422.     else //run DecaRanging application
  423.     {
  424.         uint8 dataseq[LCD_BUFF_LEN];
  425.         uint8 command = 0x0;

  426.         command = 0x2 ;  //return cursor home
  427.         writetoLCD( 1, 0,  &command);
  428.         memset(dataseq, ' ', LCD_BUFF_LEN);
  429.         memcpy(dataseq, (const uint8 *) "DECAWAVE  RANGE", 15);
  430.         writetoLCD( 15, 1, dataseq); //send some data

  431.         led_off(LED_ALL);

  432. #ifdef USB_SUPPORT //this is set in the port.h file
  433.         usb_printconfig(16, (uint8 *)SOFTWARE_VER_STRING, s1switch);
  434. #endif

  435.         if(inittestapplication(s1switch) == (uint32)-1)
  436.         {
  437.             led_on(LED_ALL); //to display error....
  438.             dataseq[0] = 0x2 ;  //return cursor home
  439.             writetoLCD( 1, 0,  &dataseq[0]);
  440.             memset(dataseq, ' ', LCD_BUFF_LEN);
  441.             memcpy(dataseq, (const uint8 *) "ERROR   ", 12);
  442.             writetoLCD( 40, 1, dataseq); //send some data
  443.             memcpy(dataseq, (const uint8 *) "  INIT FAIL ", 12);
  444.             writetoLCD( 40, 1, dataseq); //send some data
  445.             return 0; //error
  446.         
  447. ……………………

  448. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲成人免费 | 欧美一级电影免费观看 | 日本欧美黄色片 | 一区二区三区国产好 | 精品亚洲视频在线 | 99视频免费在线 | 91精品国产一二三 | 欧美精品一区二区三区在线播放 | 日韩视频免费在线 | 在线三级电影 | 台湾a级理论片在线观看 | 无码一区二区三区视频 | 狠狠草视频 | 羞羞视频在线观看网站 | 草b视频| 日韩中文字幕av | 天天看片天天干 | 亚洲国产精品久久人人爱 | 手机av在线 | 黑人一级黄色大片 | 国产黄色网 | 国产精品久久久久久久久动漫 | 国产一级大片 | 国产网站在线播放 | 亚洲精品国产精品国自产在线 | 亚洲视频观看 | 91麻豆精品国产91久久久久久 | 国产中文一区二区三区 | 毛片一级片| 中文字幕精品视频在线观看 | 中文在线一区二区 | 成年人国产在线观看 | 伊人免费网 | 日韩一区二区三区av | 伊人伊成久久人综合网站 | 国产一区二区三区欧美 | 日韩在线看片 | 欧美伊人久久久久久久久影院 | 日韩亚洲视频在线 | 免费在线精品视频 | 国产一区二区精品在线 |