⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drx3973d.lst

📁 用于DRX3973或DRX39系列的芯片的控制
💻 LST
📖 第 1 页 / 共 5 页
字号:
 530          {
 531   1      
 532   1         u8_t i = 0;
 533   1      
 534   1         *l =0;
 535   1         *h =0;
 536   1         for ( i=0 ; i<32 ; i++)
 537   1         {
 538   2            if ( a & 1)
 539   2            {
 540   3               *h += b;
 541   3            }
 542   2            /* shift [h:l] one right */
 543   2            (*l) >>= 1;
C51 COMPILER V8.02   DRX3973D                                                              02/11/2009 09:42:41 PAGE 10  

 544   2            if ( (*h) & 1)
 545   2            {
 546   3               *l |= 0x80000000UL;
 547   3            }
 548   2            (*h) >>=1;
 549   2            /* shift multiplicant one right */
 550   2            a >>=1;
 551   2         }
 552   1      }
 553          
 554          /*============================================================================*/
 555          
 556          static u32_t Frac28(u32_t N, u32_t D)
 557          /*
 558             This function is used to avoid floating-point calculations as they may
 559             not be present on the target platform.
 560          
 561             Frac28 performs an unsigned 28/28 bits division to 32-bit fixed point
 562             fraction used for setting the Frequency Shifter registers.
 563             N and D can hold numbers up to width: 28-bits.
 564             The 4 bits integer part and the 28 bits fractional part are calculated.
 565          
 566             Effectually calculates: (1<<28)*N/D
 567          
 568             N: 0...(1<<28)-1 = 268435454
 569             D: 0...(1<<28)-1
 570             Q: 0...(1<<32)-1
 571          */
 572          {
 573   1         u8_t   i=0;
 574   1         u32_t Q1=0;
 575   1         u32_t R0=0;
 576   1      
 577   1         R0 = (N%D)<<4; /* 32-28 == 4 shifts possible at max */
 578   1         Q1 = N/D;      /* integer part, only the 4 least significant bits
 579   1                           will be visible in the result */
 580   1      
 581   1         /* division using radix 16, 7 nibbles in the result */
 582   1         for (i=0; i<7; i++) {
 583   2            Q1 = (Q1 << 4) | R0/D;
 584   2            R0 = (R0%D)<<4;
 585   2         }
 586   1         /* rounding */
 587   1         if ((R0>>3) >= D) Q1++;
 588   1      
 589   1         return Q1;
 590   1      }
 591          
 592          /*============================================================================*/
 593          
 594          /**
 595          * \fn u32_t FracTimes1e6( u16_t N, u32_t D)
 596          * \brief Compute: (N/D) * 1000000.
 597          * \param N nominator 16-bits.
 598          * \param D denominator 32-bits.
 599          * \return u32_t
 600          * \retval ((N/D) * 1000000), 32 bits
 601          *
 602          * No check on D=0!
 603          */
 604          static u32_t
 605          FracTimes1e6( u16_t N, u32_t D)
C51 COMPILER V8.02   DRX3973D                                                              02/11/2009 09:42:41 PAGE 11  

 606          {
 607   1         u32_t remainder = 0;
 608   1         u32_t frac = 0;
 609   1      
 610   1         /*
 611   1            frac = (N * 1000000) / D
 612   1            To let it fit in a 32 bits computation:
 613   1            frac = (N * (1000000 >> 4)) / (D >> 4)
 614   1            This would result in a problem in case D < 16 (div by 0).
 615   1            So we do it more elaborate as shown below.
 616   1         */
 617   1      
 618   1         frac =  ( ((u32_t)N) * (1000000UL >> 4) ) / D ;
 619   1         frac <<=  4 ;
 620   1         remainder  =  ( ((u32_t)N) * (1000000UL >> 4) ) % D ;
 621   1         remainder <<= 4;
 622   1         frac += remainder / D;
 623   1         remainder  = remainder % D ;
 624   1         if( (remainder * 2) > D )
 625   1         {
 626   2            frac++;
 627   2         }
 628   1      
 629   1         return ( frac );
 630   1      }
 631          
 632          /*============================================================================*/
 633          
 634          /**
 635          * \fn u32_t Log10Times100( u32_t x)
 636          * \brief Compute: 100*log10(x)
 637          * \param x 32 bits
 638          * \return 100*log10(x)
 639          *
 640          * 100*log10(x)
 641          * = 100*(log2(x)/log2(10)))
 642          * = (100*(2^15)*log2(x))/((2^15)*log2(10))
 643          * = ((200*(2^15)*log2(x))/((2^15)*log2(10)))/2
 644          * = ((200*(2^15)*(log2(x/y)+log2(y)))/((2^15)*log2(10)))/2
 645          * = ((200*(2^15)*log2(x/y))+(200*(2^15)*log2(y)))/((2^15)*log2(10)))/2
 646          *
 647          * where y = 2^k and 1<= (x/y) < 2
 648          */
 649          
 650          u32_t Log10Times100( u32_t x)
 651          {
 652   1         static const u8_t scale=15;
 653   1         static const u8_t indexWidth=5;
 654   1         /*
 655   1         log2lut[n] = (1<<scale) * 200 * log2( 1.0 + ( (1.0/(1<<INDEXWIDTH)) * n ))
 656   1         0 <= n < ((1<<INDEXWIDTH)+1)
 657   1         */
 658   1      
 659   1         static const u32_t log2lut[] = {
 660   1            0, /* 0.000000 */
 661   1            290941, /* 290941.300628 */
 662   1            573196, /* 573196.476418 */
 663   1            847269, /* 847269.179851 */
 664   1            1113620, /* 1113620.489452 */
 665   1            1372674, /* 1372673.576986 */
 666   1            1624818, /* 1624817.752104 */
 667   1            1870412, /* 1870411.981536 */
C51 COMPILER V8.02   DRX3973D                                                              02/11/2009 09:42:41 PAGE 12  

 668   1            2109788, /* 2109787.962654 */
 669   1            2343253, /* 2343252.817465 */
 670   1            2571091, /* 2571091.461923 */
 671   1            2793569, /* 2793568.696416 */
 672   1            3010931, /* 3010931.055901 */
 673   1            3223408, /* 3223408.452106 */
 674   1            3431216, /* 3431215.635215 */
 675   1            3634553, /* 3634553.498355 */
 676   1            3833610, /* 3833610.244726 */
 677   1            4028562, /* 4028562.434393 */
 678   1            4219576, /* 4219575.925308 */
 679   1            4406807, /* 4406806.721144 */
 680   1            4590402, /* 4590401.736809 */
 681   1            4770499, /* 4770499.491025 */
 682   1            4947231, /* 4947230.734179 */
 683   1            5120719, /* 5120719.018555 */
 684   1            5291081, /* 5291081.217197 */
 685   1            5458428, /* 5458427.996830 */
 686   1            5622864, /* 5622864.249668 */
 687   1            5784489, /* 5784489.488298 */
 688   1            5943398, /* 5943398.207380 */
 689   1            6099680, /* 6099680.215452 */
 690   1            6253421, /* 6253420.939751 */
 691   1            6404702, /* 6404701.706649 */
 692   1            6553600, /* 6553600.000000 */
 693   1         };
 694   1      
 695   1      
 696   1         u8_t  i = 0;
 697   1         u32_t y = 0;
 698   1         u32_t d = 0;
 699   1         u32_t k = 0;
 700   1         u32_t r = 0;
 701   1      
 702   1         if (x==0) return (0);
 703   1      
 704   1         /* Scale x (normalize) */
 705   1         /* computing y in log(x/y) = log(x) - log(y) */
 706   1         if ( (x & (((u32_t)(-1))<<(scale+1)) ) == 0 )
 707   1         {
 708   2            for (k = scale; k>0 ; k--)
 709   2            {
 710   3              if (x & (((u32_t)1)<<scale)) break;
 711   3              x <<= 1;
 712   3            }
 713   2         } else {
 714   2            for (k = scale; k<31 ; k++)
 715   2            {
 716   3              if ((x & (((u32_t)(-1))<<(scale+1)))==0) break;
 717   3              x >>= 1;
 718   3            }
 719   2         }
 720   1         /*
 721   1           Now x has binary point between bit[scale] and bit[scale-1]
 722   1           and 1.0 <= x < 2.0 */
 723   1      
 724   1         /* correction for divison: log(x) = log(x/y)+log(y) */
 725   1         y = k * ( ( ((u32_t)1) << scale ) * 200 );
 726   1      
 727   1         /* remove integer part */
 728   1         x &= ((((u32_t)1) << scale)-1);
 729   1         /* get index */
C51 COMPILER V8.02   DRX3973D                                                              02/11/2009 09:42:41 PAGE 13  

 730   1         i = (u8_t) (x >> (scale -indexWidth));
 731   1         /* compute delta (x-a) */
 732   1         d = x & ((((u32_t)1) << (scale-indexWidth))-1);
 733   1         /* compute log, multiplication ( d* (.. )) must be within range ! */
 734   1         y += log2lut[i] + (( d*( log2lut[i+1]-log2lut[i] ))>>(scale-indexWidth));
 735   1         /* Conver to log10() */
 736   1         y /= 108853; /* (log2(10) << scale) */
 737   1         r = (y>>1);
 738   1         /* rounding */
 739   1         if (y&((u32_t)1)) r++;
 740   1      
 741   1         return (r);
 742   1      
 743   1      }
 744          
 745          /*=============================================================================
 746            ===== Atomic data access related stuff ======================================
 747            ===========================================================================*/
 748          
 749          #define HI_TR_FUNC_ADDR HI_IF_RAM_USR_BEGIN__A
 750          
 751          static
 752          DRXStatus_t InitAtomicRead ( pI2CDeviceAddr_t devAddr )
 753          {
 754   1         static u8_t instructions[] =
 755   1         {
 756   1           0x26, 0x00,  /* 0         -> ring.rdy;           */
 757   1           0x60, 0x04,  /* r0rami.dt -> ring.xba;           */
 758   1           0x61, 0x04,  /* r0rami.dt -> ring.xad;           */
 759   1           0xE3, 0x07,  /* HI_RA_RAM_USR_BEGIN -> ring.iad; */
 760   1           0x40, 0x00,  /* (long immediate)                 */
 761   1           0x64, 0x04,  /* r0rami.dt -> ring.len;           */
 762   1           0x65, 0x04,  /* r0rami.dt -> ring.ctl;           */
 763   1           0x26, 0x00,  /* 0         -> ring.rdy;           */
 764   1           0x38, 0x00   /* 0         -> jumps.ad;           */
 765   1         };
 766   1      
 767   1         WRBLOCK( devAddr, HI_TR_FUNC_ADDR , sizeof(instructions), instructions );
 768   1      
 769   1         return DRX_STS_OK;
 770   1      
 771   1       rw_error:
 772   1         return (DRX_STS_ERROR);
 773   1      }
 774          
 775          /**
 776          * \fn DRXStatus_t AtomicReadBlock()
 777          * \brief Atomic read of n bytes
 778          *
 779          * Flags are ignored for now ...
 780          */
 781          
 782          #define HI_TR_WRITE      0x9
 783          #define HI_TR_READ       0xA
 784          #define HI_TR_READ_WRITE 0xB
 785          #define HI_TR_BROADCAST  0x4
 786          
 787          static
 788          DRXStatus_t AtomicReadBlock (
 789              pI2CDeviceAddr_t devAddr,
 790              DRXaddr_t        addr,
 791              u16_t            datasize,
C51 COMPILER V8.02   DRX3973D                                                              02/11/2009 09:42:41 PAGE 14  

 792              pu8_t            data,
 793              DRXflags_t       flags)
 794          {
 795   1         DRX3973DHiCmd_t hiCmd;
 796   1      
 797   1         u16_t dummy=0;
 798   1         u16_t i=0;
 799   1      
 800   1         /* Parameter check */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -