2017年10月2日 星期一

NANO100: Use CMSIS DSP library in NANO100 series microcontroler

1.Build the arm_cortexM0l_math.lib
   The source project is located on
   After build you will find the arm_cortexM0l_math.lib in
2.Use the arm_cortexM0l_math.lib copy the Template project. And add ARM_MATH_CM0 in 
   Preprocessor Symbols

3.Add the #include "arm_math.h"  and  arm_cortexM0l_math.lib in Template project.

4.Now you can use the CMSIS DSP library to optimized the math function!







2017年9月13日 星期三

Some little trick in C.


1.Exchange two variable without extra memory space.
    Since A xor A = 0 , so A xor A xor B = B thus we can change this two variable by use xor op.
2.String compose.
   By use #define fun(a,b) a##b  we can easily to compose a in a string.
3.Use union to transform float to 4-char raw data
   union define two different data type in same memory space(Ref 3)
4.Counting the number of args
 
    If we call NUM_VA_ARGS(1, 2, 3) will turn out to 

    NUM_VA_ARGS_IMPL( 1, 2,  3, 63, 62, 61,  \
             60, 59, 58, 57, 56, 55, 54, 53, 52, 51,                         \
             50, 49, 48, 47, 46, 45, 44, 43, 42, 41,                         \
             40, 39, 38, 37, 36, 35, 34, 33, 32, 31,                         \
             30, 29, 28, 27, 26, 25, 24, 23, 22, 21,                         \
             20, 19, 18, 17, 16, 15, 14, 13, 12, 11,                         \
             10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
     The blue part is the ... variable and the red part is the N so that we can get the count of args.
5.Define how many bits use to represent the variable in struct.
   Consider we have a struct represent 32 bits register and have 0~7 bits for data transfer, 8~31 bits
   for reserve.We can declare a struct like
So that if we give the data value above 255 than compiler will warning us the value is over the range of this variable can represent.

6.Compare unsigned value to constant value use minus replace compare

7.Define constant in struct and integer trick.

Ref:
      1.Linux C编程一站式学习
      2.C語言:浮點數通信傳輸
      3.Union型別 (討論在C&C++中的差異)
      4.nRF52 SDK/nrf_log.h
      5.C - Bit Fields
      6.https://stackoverflow.com/questions/514118/how-does-duffs-device-work


   

2017年9月5日 星期二

A fast method to round a double to a 32-bit int explained note

Quote:

Between 2^52=4,503,599,627,370,496 and ^253=9,007,199,254,740,992 the representable numbers are exactly the integers
This follows from the fact that the mantissa is 52 bits wide.

The other interesting fact about adding 2^51+2^52 is that it affects the mantissa only in the two highest bits - which are discarded anyway, since we are taking only its lowest 32 bits.



IEEE 754 Double Floating Point Format.svg








So we add 2^51+2^52 and get the lowest 32 bits via a cast than we can get the integer from double.

#define double2int(i, d) \
    {double t = ((d) + 6755399441055744.0); i = *((int *)(&t));}

Ref:
      1. A fast method to round a double to a 32-bit int explained
      2. Double-precision floating-point format

2017年8月27日 星期日

SVE:new set of vector instructions for ARMV8

SVE introduce new set of register
• 32 Z registers, z0, z1, . . . , z31;

Data register multiple of 128 bits up to 2048 bits, support 8-bit bytes, 16-bit halfwords, 32-bit words or 64-bit doublewords.

• 16 P registers, p0, p1, . . . , p15;

Predicate registers hold one bit for each byte available.

• 1 FFR register.

Special predicate register that differs from regular predicate registers by way of being used
implicitly by some dedicated instructions, called first faulting loads.


SVE is more flexible and efficient than the neon instruction . Target on the multi vector computation such as: machine learning and the graphic .



Ref:
     1.A sneak peek into SVE and VLA programming
     2.ARMv8-A SVE technology Hot Chips v12
     3.The ARM Scalable Vector Extension
     4.SIMD Programmingwith Larrabee
     5.Using SVE intrinsics directly in your C code

2017年7月16日 星期日

Competitive Programmer’s Handbook Note.

1.g++ compiler provide __int128_t type 128 bits interger

2.Because the precision errors it's better use subtraction and compare with a small number like(1e-9) than use == to indicate two floating point numbers is equal.

3.page 16 book list

4.Computers and Intractability: A Guide to the Theory of NP-Completeness

5.Kadane’s algorithm.

6.Chapter 7 DP

2017年6月11日 星期日

NANO100:Using data flash without the external 12M HZ crystal.

The data flash start address is set by register so it need a reset after update the address, but in default it will use  the external 12M HZ crystal.It's need to modify the CFOSC .



Modify the \SampleCode\StdDriver\FMC_RW set_data_flash_base() function



Ref:
     Nano100 Series Technical Reference Manual

NANO100:Enable printf use Nu-Link to send massage

1.Add #define DEBUG_ENABLE_SEMIHOST in Library\StdDriver\src\retarget.c .
 

2.Start Keil C IDE debug session and enable the View\Serial Windows\UART #1.


3. Now you can see the printf massage in Keil C IDE.

Ref:
   2. Semihosting

Linux driver: How to enable dynamic debug at booting time for built-in driver.

 Dynamic debug is useful for debug driver, and can be enable by: 1. Mount debug fs #>mount -t debugfs none /sys/kernel/debug 2. Enable dy...