ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
isf_util.c
Go to the documentation of this file.
1 /*
2  * util.c
3  *
4  * Created on: May 1, 2013
5  * Author: B39109
6  */
7 
8 #include "isf_util.h"
9 #include "mqxlite.h" // MQX_TICK_STRUCT_PTR
10 #include "isf_types.h" // uint64
11 //#include "isf_bsp_config.h"
12 
13 uint32 bitrev(uint32 doubleword)
14 {
15  doubleword = (((doubleword & 0xaaaaaaaa) >> 1) | ((doubleword & 0x55555555) << 1));
16  doubleword = (((doubleword & 0xcccccccc) >> 2) | ((doubleword & 0x33333333) << 2));
17  doubleword = (((doubleword & 0xf0f0f0f0) >> 4) | ((doubleword & 0x0f0f0f0f) << 4));
18  doubleword = (((doubleword & 0xff00ff00) >> 8) | ((doubleword & 0x00ff00ff) << 8));
19  return (( doubleword >> 16) | (doubleword << 16));
20 }
21 
22 
23 uint32 ff1(uint32 doubleword) {
24 
25  uint32 index = 0;
26 
27  if (0 == doubleword) return 32;
28 
29  if (0 == (doubleword & 0xFFFF0000) ){ index += 16; doubleword <<= 16;}
30  if (0 == (doubleword & 0xFF000000) ){ index += 8; doubleword <<= 8;}
31  if (0 == (doubleword & 0xF0000000) ){ index += 4; doubleword <<= 4;}
32  if (0 == (doubleword & 0xC0000000) ){ index += 2, doubleword <<= 2;}
33  if (0 == (doubleword & 0x80000000) ){ index += 1, doubleword <<= 1;}
34  return index;
35 }
36 
37 uint32 ff1_lsb(uint32 doubleword){
38  uint32 index = 0;
39  if( 0 == doubleword) return 0;
40  if (0 == (doubleword & 0x0000FFFF) ){ index += 16; doubleword >>= 16;}
41  if (0 == (doubleword & 0x000000FF) ){ index += 8; doubleword >>= 8;}
42  if (0 == (doubleword & 0x0000000F) ){ index += 4; doubleword >>= 4;}
43  if (0 == (doubleword & 0x00000003) ){ index += 2, doubleword >>= 2;}
44  if (0 == (doubleword & 0x00000001) ){ index += 1, doubleword >>= 1;}
45  return index;
46 }
47 
48 
49 
50 
51 // This is a top level API exposed in isf.h. See that file for function description.
53 {
54 
55  uint64 time_in_increments_of_rtos_ticks_usec64;
56  uint32 time_since_last_rtos_tick_usec;
57  uint32 time_usec;
58 
59  MQX_TICK_STRUCT tick;
60  uint32 usec_per_rtos_tick;
61 
62  static float nsec_per_hw_tick = 0; // isf_get_nsec_per_hw_tick();
63 
64  if (nsec_per_hw_tick == 0)
65  nsec_per_hw_tick = (float)((float)1 / (float)( (float)_time_get_ticks_per_sec() * (float)_time_get_hwticks_per_tick() ) );
66 
67 
68  // Retrieve the rtos ticks and the hw systick counter value.
69  _time_get_elapsed_ticks(&tick);
70 
71  // Need to know the time per rtos tick.
72  usec_per_rtos_tick = (uint32)1000000 / (uint32)_time_get_ticks_per_sec();
73 
74  // NOTE: This is the 64bit version that can handle longer elapsed time.
75  //time_in_increments_of_rtos_ticks_usec64 = ( ((uint32)tick.TICKS[1] << 32) | (uint32)tick.TICKS[0] ) * (uint32)usec_per_rtos_tick;
76 
77 
78  // Get the usec time based upon the lower rtos tick count. Note that we disregard the upper tick time, tick.TICKS[1]
79  // for 32bit version. We do need to store the result in a 64bit variable because we are multiplying two 32bit values.
80  time_in_increments_of_rtos_ticks_usec64 = (uint64)tick.TICKS[0] * (uint64)usec_per_rtos_tick;
81 
82  // Get the time since the last rtos tick.
83  // Note here that we assume systick is counting down (systick reload - hw ticks).
84  time_since_last_rtos_tick_usec = (uint32)( ( (SYST_RVR - tick.HW_TICKS) * nsec_per_hw_tick) * 1000000);
85 
86  // Add elapsed rtos time and time since last rtos tick. Then truncate to 32bit.
87  time_usec = (uint32)((uint64)time_in_increments_of_rtos_ticks_usec64 + (uint64)time_since_last_rtos_tick_usec);
88 
89  return time_usec;
90 }
91 
92 
93 /***********************************************************************
94  *
95  * Function Name : isf_mem_copy
96  * Description : This function copy the data from destination to scr. This does not support overlayed memory.
97  *
98  ***************************************************************************/
99 void isf_mem_copy(void *src, void* dest, uint32 size)
100 {
101  uint8 *pSource = (uint8 *)src;
102  uint8 *pDestination = (uint8 *)dest;
103  while (size--) {
104  *pDestination++ = *pSource++;
105  }
106 
107 }
108 
109 
110 
111 
112 
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
uint32 isf_time_util_get_usec(void)
This API returns the time in microseconds.
Definition: isf_util.c:52
unsigned long long uint64
This defines uint64 as unsigned long long.
Definition: isf_types.h:45
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
uint32 ff1(uint32 doubleword)
find first-in.
Definition: isf_util.c:23
uint32 bitrev(uint32 doubleword)
This function reverse the bits of a double word.
Definition: isf_util.c:13
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
uint32 ff1_lsb(uint32 doubleword)
find first-in form LSB.
Definition: isf_util.c:37
The isf_util.h file contains the utility method declarations and macros.
void isf_mem_copy(void *src, void *dest, uint32 size)
memory copy
Definition: isf_util.c:99