#ifndef __UTILS_H #define __UTILS_H #ifdef __cplusplus extern "C" { #endif #include /** * @brief Unique ID register address location */ #define ID_UNIQUE_ADDRESS (0x1FFF7A10) /** * @brief Flash size register address */ #define ID_FLASH_ADDRESS (0x1FFF7A22) /** * @brief Device ID register address */ #define ID_DBGMCU_IDCODE (0xE0042000) /** * "Returns" the device signature * * Possible returns: * - 0x0413: STM32F405xx/07xx and STM32F415xx/17xx) * - 0x0419: STM32F42xxx and STM32F43xxx * - 0x0423: STM32F401xB/C * - 0x0433: STM32F401xD/E * - 0x0431: STM32F411xC/E * * Returned data is in 16-bit mode, but only bits 11:0 are valid, bits 15:12 are always 0. * Defined as macro */ #define STM_ID_GetSignature() ((*(uint16_t *)(ID_DBGMCU_IDCODE)) & 0x0FFF) /** * "Returns" the device revision * * Revisions possible: * - 0x1000: Revision A * - 0x1001: Revision Z * - 0x1003: Revision Y * - 0x1007: Revision 1 * - 0x2001: Revision 3 * * Returned data is in 16-bit mode. */ #define STM_ID_GetRevision() (*(uint16_t *)(ID_DBGMCU_IDCODE + 2)) /** * "Returns" the Flash size * * Returned data is in 16-bit mode, returned value is flash size in kB (kilo bytes). */ #define STM_ID_GetFlashSize() (*(uint16_t *)(ID_FLASH_ADDRESS)) /** * "Returns" the given 32-bit value of the UUID. * * Parameters: * - uint8_t x: * Value between 0 and 2, corresponding to 4-bytes you want to read from 96bits (12bytes) * * Returned data is 32-bit */ #define STM_ID_GetUUID(x) ((x >= 0 && x < 3) ? (*(uint32_t *)(ID_UNIQUE_ADDRESS + 4 * (x))) : 0) #ifdef M_PI #undef M_PI #endif #define M_PI 3.14159265358979323846f #define MACRO_MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MACRO_MIN(x, y) (((x) < (y)) ? (x) : (y)) // Compute rising edge timings (0.0 - 1.0) as a function of alpha-beta // as per the magnitude invariant clarke transform // The magnitude of the alpha-beta vector may not be larger than sqrt(3)/2 // Returns 0 on success, and -1 if the input was out of range int SVM(float alpha, float beta, float* tA, float* tB, float* tC); //beware of inserting large angles! float wrap_pm_pi(float theta); float fast_atan2(float y, float x); int mod(int dividend, int divisor); uint32_t deadline_to_timeout(uint32_t deadline_ms); uint32_t timeout_to_deadline(uint32_t timeout_ms); uint32_t micros(void); void delay_us(uint32_t us); #ifdef __cplusplus } #endif #endif //__UTILS_H