Library Functions.
More...
Library Functions.
| #define TM_GENERAL_DWTCounterDisable |
( |
| ) |
(DWT->CTRL &= ~0x00000001) |
Disables DWT counter in Cortex-M4 core.
- Parameters
-
- Return values
-
- Note
- Defined as macro for faster execution
| #define TM_GENERAL_DWTCounterGetValue |
( |
| ) |
(DWT->CYCCNT) |
Gets current DWT counter value.
- Parameters
-
- Return values
-
- Note
- Defined as macro for faster execution
| #define TM_GENERAL_DWTCounterSetValue |
( |
|
x | ) |
(DWT->CYCCNT = (x)) |
Sets DWT counter value.
- Parameters
-
| x | Value to be set to DWT counter |
- Return values
-
- Note
- Defined as macro for faster execution
| #define TM_GENERAL_GetSystemClockMHz |
( |
| ) |
((uint16_t)(SystemCoreClock * (float)0.000001)) |
Gets system clock speed in units of MHz.
- Parameters
-
- Return values
-
- Note
- Defined as macro for faster execution
| #define TM_GENERAL_IsIRQMode |
( |
| ) |
(SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) |
Checks if code execution is inside active IRQ.
- Parameters
-
- Return values
-
| IRQ | Execution status:
- 0: Code execution is not inside IRQ, thread mode
- > 0: Code execution is inside IRQ, IRQ mode
|
- Note
- Defines as macro for faster execution
| #define TM_GENERAL_IsNumberEven |
( |
|
number | ) |
((number & 1) == 0) |
Checks if number is odd or even.
- Parameters
-
| number | Number to check if it is odd or even |
- Return values
-
| Is | number even status:
- 0: Number is odd
- > 0: Number is even
|
- Note
- Defined as macro for faster execution
| #define TM_GENERAL_IsNumberPowerOfTwo |
( |
|
number | ) |
(number && !(number & (number - 1))) |
Checks if number is power of 2.
- Note
- It can be used to determine if number has more than just one bit set If only one bit is set, function will return > 0 because this is power of 2.
- Parameters
-
| number | Number to check if it is power of 2 |
- Return values
-
| Is | power of 2 status:
- 0: Number if not power of 2
- > 0: Number is power of 2
|
- Note
- Defined as macro for faster execution
| void TM_GENERAL_ConvertFloat |
( |
TM_GENERAL_Float_t * |
Float_Struct, |
|
|
float |
Number, |
|
|
uint8_t |
decimals |
|
) |
| |
Converts float coded number into integer and decimal part.
- Parameters
-
| *Float_Struct | Pointer to empty TM_GENERAL_Float_t to store result into |
| Number | Float number to convert |
| decimals | Number of decimal places for conversion, maximum 9 decimal places |
- Return values
-
- Note
- Example: You have number 15.002 in float format.
- You want to split this to integer and decimal part with 6 decimal places.
- Call TM_GENERAL_ConvertFloat(&Float_Struct, 15.002, 6);
- Result will be: Integer: 15; Decimal: 2000 (0.002 * 10^6)
| void TM_GENERAL_DisableInterrupts |
( |
void |
| ) |
|
Disables all interrupts in system.
- Parameters
-
- Return values
-
| static __INLINE void TM_GENERAL_DWTCounterDelayms |
( |
uint32_t |
millis | ) |
|
|
static |
Delays for amount of milliseconds using DWT counter.
- Parameters
-
| millis | Number of micro seconds for delay |
- Return values
-
- Note
- DWT Counter HAVE to be initialized first using TM_GENERAL_EnableDWTCounter()
| static __INLINE void TM_GENERAL_DWTCounterDelayus |
( |
uint32_t |
micros | ) |
|
|
static |
Delays for amount of microseconds using DWT counter.
- Parameters
-
| micros | Number of micro seconds for delay |
- Return values
-
- Note
- DWT Counter HAVE to be initialized first using TM_GENERAL_EnableDWTCounter()
| uint8_t TM_GENERAL_DWTCounterEnable |
( |
void |
| ) |
|
Enables DWT counter in Cortex-M4 core.
- Parameters
-
- Return values
-
| DWT | Status:
- 0: DWT has not started, hardware/software reset is required
- > 0: DWT has started and is ready to use
|
- Note
- It may happen, that DWT counter won't start after reprogramming device. This happened to me when I use onboard ST-Link on Discovery or Nucleo boards. When I used external debugger (J-Link or ULINK2) it worked always without problems. If your DWT doesn't start, you should perform software/hardware reset by yourself.
| uint8_t TM_GENERAL_EnableInterrupts |
( |
void |
| ) |
|
Enables interrupts in system.
- Note
- This function has nesting support. This means that if you call TM_GENERAL_DisableInterrupts() 4 times, then you have to call this function also 4 times to enable interrupts.
- Parameters
-
- Return values
-
| Interrupt | enabled status:
- 0: Interrupts were not enabled
- > 0: Interrupts were enabled
|
| void TM_GENERAL_ForceHardFaultError |
( |
void |
| ) |
|
Forces processor to jump to Hard-fault handler.
- Note
- Function tries to call function at zero location in memory which causes hard-fault
- Parameters
-
- Return values
-
Gets specific clock speed value from STM32F4xx device.
- Parameters
-
| clock | Clock type you want to know speed for. This parameter can be a value of TM_GENERAL_Clock_t enumeration |
- Return values
-
| Clock | speed in units of hertz |
Gets reset source why system was reset.
- Parameters
-
| reset_flags | After read, clear reset flags
- 0: Flags will stay untouched
- > 0: All reset flags will reset
|
- Return values
-
| uint32_t TM_GENERAL_NextPowerOf2 |
( |
uint32_t |
number | ) |
|
Calculates next power of 2 from given number.
- Parameters
-
| number | Input number to be calculated |
- Return values
-
| Number | with next power of 2 Example:
- Input number: 450
- Next power of 2 is: 512 = 2^9
|
| float TM_GENERAL_RoundFloat |
( |
float |
Number, |
|
|
uint8_t |
decimals |
|
) |
| |
Round float number to nearest number with custom number of decimal places.
- Parameters
-
| Number | Float number to round |
| decimals | Number of decimal places to round, maximum 9 decimal places |
- Return values
-
| void TM_GENERAL_SystemReset |
( |
void |
| ) |
|
Performs a system reset.
- Note
- Before system will be reset, TM_GENERAL_SoftwareResetCallback() will be called, where you can do important stuff if necessary
- Parameters
-
- Return values
-
| void TM_GENERAL_SystemResetCallback |
( |
void |
| ) |
|
System reset callback.
- Note
- Function is called before software reset occurs.
- Parameters
-
- Return values
-
- Note
- With __weak parameter to prevent link errors if not defined by user