libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
HW accelerated maths trig/hyperbolic operations. More...
Functions | |
bool | cordic_is_result_ready (void) |
Read CORDIC result ready flag. More... | |
void | cordic_set_argument_width_32bit (void) |
Set CORDIC to 32 bit argument data width. More... | |
void | cordic_set_argument_width_16bit (void) |
Set CORDIC to 16 bit argument data width. More... | |
void | cordic_set_result_width_32bit (void) |
Set CORDIC to 32 bit result data width. More... | |
void | cordic_set_result_width_16bit (void) |
Set CORDIC to 16 bit result data width. More... | |
void | cordic_set_number_of_arguments_1 (void) |
Set number of CORDIC arguments to one 32 bit argument or two 16 bit arguments. More... | |
void | cordic_set_number_of_arguments_2 (void) |
Set number of CORDIC arguments to two 32 bit arguments. More... | |
void | cordic_set_number_of_results_1 (void) |
Set number of CORDIC results to one 32 bit result or two 16 bit results. More... | |
void | cordic_set_number_of_results_2 (void) |
Set number of CORDIC results to two 32 bit results. More... | |
void | cordic_enable_dma_write (void) |
Enable DMA for writes to CORDIC_WDATA. More... | |
void | cordic_disable_dma_write (void) |
Disable DMA for writes to CORDIC_WDATA. More... | |
void | cordic_enable_dma_read (void) |
Enable DMA for read from CORDIC_RDATA. More... | |
void | cordic_disable_dma_read (void) |
Disable DMA for read from CORDIC_RDATA. More... | |
void | cordic_enable_interrupt (void) |
Enable interrupt when result is ready. More... | |
void | cordic_set_scaling_factor (uint8_t n) |
Set scaling factor for CORDIC operations. More... | |
void | cordic_set_precision (uint8_t precision) |
Set precision for CORDIC operations. More... | |
void | cordic_set_function (uint8_t function) |
Set CORDIC operation type. More... | |
void | cordic_write_16bit_argument (uint16_t argument) |
Write single 16 bit argument. More... | |
void | cordic_write_16bit_arguments (uint16_t argument1, uint16_t argument2) |
Write two 16 bit arguments. More... | |
void | cordic_write_32bit_argument (uint32_t argument) |
Write single 32 bit argument. More... | |
uint16_t | cordic_read_16bit_result (void) |
Read single 16 bit result. More... | |
void | cordic_read_16bit_results (uint16_t *result1, uint16_t *result2) |
Read two 16 bit results. More... | |
uint32_t | cordic_read_32bit_result (void) |
Read 32 bit result. More... | |
void | cordic_configure_for_cos_16bit (void) |
Configure cordic for 16 bit cosine. More... | |
void | cordic_configure_for_cos_32bit (void) |
Configure cordic for 32 bit cosine. More... | |
void | cordic_configure_for_sin_16bit (void) |
Configure cordic for 16 bit sine. More... | |
void | cordic_configure_for_sin_32bit (void) |
Configure cordic for 32 bit sine. More... | |
int16_t | cordic_cos_16bit (int16_t x) |
Compute 16 bit cosine using CORDIC (blocking) More... | |
void | cordic_cos_16bit_async (int16_t x) |
Compute 16 bit cosine using CORDIC (non blocking) More... | |
int32_t | cordic_cos_32bit (int32_t x) |
Compute 32 bit cosine using CORDIC (blocking) More... | |
void | cordic_cos_32bit_async (int32_t x) |
Compute 32 bit cosine using CORDIC (non blocking) More... | |
int16_t | cordic_sin_16bit (int16_t x) |
Compute 16 bit sine using CORDIC (blocking) More... | |
void | cordic_sin_16bit_async (int16_t x) |
Compute 16 bit sine using CORDIC (non blocking) More... | |
int32_t | cordic_sin_32bit (int32_t x) |
Compute 32 bit sine using CORDIC (blocking) More... | |
void | cordic_sin_32bit_async (int32_t x) |
Compute 32 bit sine using CORDIC (non blocking) More... | |
HW accelerated maths trig/hyperbolic operations.
This library supports the CORDIC co-processor in the STM32 series of ARM Cortex Microcontrollers by ST Microelectronics. This peripheral computes trigonometric and hyperbolic functions and converts between cartesian and polar coordinates.
LGPL License Terms libopencm3 License
void cordic_configure_for_cos_16bit | ( | void | ) |
Configure cordic for 16 bit cosine.
Configures cordic peripheral to perform 16 bit cosine operation without triggering it
Definition at line 296 of file cordic_common_v1.c.
References CORDIC_CSR_FUNC_COS, CORDIC_CSR_PRECISION_ITER_20, cordic_set_argument_width_16bit(), cordic_set_function(), cordic_set_number_of_arguments_1(), cordic_set_number_of_results_1(), cordic_set_precision(), and cordic_set_result_width_16bit().
Referenced by cordic_cos_16bit(), and cordic_cos_16bit_async().
void cordic_configure_for_cos_32bit | ( | void | ) |
Configure cordic for 32 bit cosine.
Configures cordic peripheral to perform 32 bit cosine operation without triggering it
Definition at line 311 of file cordic_common_v1.c.
References CORDIC_CSR_FUNC_COS, CORDIC_CSR_PRECISION_ITER_28, cordic_set_argument_width_32bit(), cordic_set_function(), cordic_set_number_of_arguments_1(), cordic_set_number_of_results_1(), cordic_set_precision(), and cordic_set_result_width_32bit().
Referenced by cordic_cos_32bit(), and cordic_cos_32bit_async().
void cordic_configure_for_sin_16bit | ( | void | ) |
Configure cordic for 16 bit sine.
Configures cordic peripheral to perform 16 bit sine operation without triggering it
Definition at line 326 of file cordic_common_v1.c.
References CORDIC_CSR_FUNC_SIN, CORDIC_CSR_PRECISION_ITER_20, cordic_set_argument_width_16bit(), cordic_set_function(), cordic_set_number_of_arguments_1(), cordic_set_number_of_results_1(), cordic_set_precision(), and cordic_set_result_width_16bit().
Referenced by cordic_sin_16bit(), and cordic_sin_16bit_async().
void cordic_configure_for_sin_32bit | ( | void | ) |
Configure cordic for 32 bit sine.
Configures cordic peripheral to perform 32 bit sine operation without triggering it
Definition at line 341 of file cordic_common_v1.c.
References CORDIC_CSR_FUNC_SIN, CORDIC_CSR_PRECISION_ITER_28, cordic_set_argument_width_32bit(), cordic_set_function(), cordic_set_number_of_arguments_1(), cordic_set_number_of_results_1(), cordic_set_precision(), and cordic_set_result_width_32bit().
Referenced by cordic_sin_32bit(), and cordic_sin_32bit_async().
int16_t cordic_cos_16bit | ( | int16_t | x | ) |
Compute 16 bit cosine using CORDIC (blocking)
Convenience function to calculate 32767*cos(x/32767*pi). This implementation can be sped up in most applications by configuring the peripheral only once and then trigger subsequent operations by writing new arguments to the CORDIC_WDATA register. Additionally, sine and cosine are always computed in a single operation. Read the second result to obtain the other value.
[in] | x | argument |
Definition at line 362 of file cordic_common_v1.c.
References cordic_configure_for_cos_16bit(), cordic_is_result_ready(), cordic_read_16bit_result(), and cordic_write_16bit_arguments().
void cordic_cos_16bit_async | ( | int16_t | x | ) |
Compute 16 bit cosine using CORDIC (non blocking)
Convenience function to calculate 32767*cos(x/32767*pi). Result can be obtained from result register using cordic_read_16bit_result().
[in] | x | argument |
Definition at line 381 of file cordic_common_v1.c.
References cordic_configure_for_cos_16bit(), and cordic_write_16bit_arguments().
int32_t cordic_cos_32bit | ( | int32_t | x | ) |
Compute 32 bit cosine using CORDIC (blocking)
Convenience function to calculate 2147483647*cos(x/2147483647*pi). This implementation can be sped up in most applications by configuring the peripheral only once and then trigger subsequent operations by writing new arguments to the CORDIC_WDATA register. Additionally, sine and cosine are always computed in a single operation. Read the second result to obtain the other value.
[in] | x | argument |
Definition at line 397 of file cordic_common_v1.c.
References cordic_configure_for_cos_32bit(), cordic_is_result_ready(), cordic_read_32bit_result(), and cordic_write_32bit_argument().
void cordic_cos_32bit_async | ( | int32_t | x | ) |
Compute 32 bit cosine using CORDIC (non blocking)
Convenience function to calculate 2147483647*cos(x/2147483647*pi). Result can be obtained from result register using cordic_read_32bit_result().
[in] | x | argument |
Definition at line 414 of file cordic_common_v1.c.
References cordic_configure_for_cos_32bit(), and cordic_write_32bit_argument().
void cordic_disable_dma_read | ( | void | ) |
Disable DMA for read from CORDIC_RDATA.
When disabled, the peripheral will not generate DMA requests when new results can be read from the CORDIC_RDATA register.
Definition at line 175 of file cordic_common_v1.c.
References CORDIC_CSR.
void cordic_disable_dma_write | ( | void | ) |
Disable DMA for writes to CORDIC_WDATA.
When disabled, the peripheral will not generate DMA requests when new arguments can be loaded into the CORDIC_WDATA register.
Definition at line 155 of file cordic_common_v1.c.
References CORDIC_CSR.
void cordic_enable_dma_read | ( | void | ) |
Enable DMA for read from CORDIC_RDATA.
When enabled, the peripheral will continue to generate DMA requests when new results can be read from the CORDIC_RDATA register.
Definition at line 165 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_DMAREN.
void cordic_enable_dma_write | ( | void | ) |
Enable DMA for writes to CORDIC_WDATA.
When enabled, the peripheral will continue to generate DMA requests when new arguments can be loaded into the CORDIC_WDATA register.
Definition at line 145 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_DMAWEN.
void cordic_enable_interrupt | ( | void | ) |
Enable interrupt when result is ready.
When enabled, the peripheral will generate an interrupt when the CORDIC_CSR_RRDY flag is set.
Definition at line 185 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_IEN.
bool cordic_is_result_ready | ( | void | ) |
Read CORDIC result ready flag.
This flag is set by hardware when a CORDIC operation completes. It is automatically cleared when all results have been read.
Definition at line 49 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_RRDY.
Referenced by cordic_cos_16bit(), cordic_cos_32bit(), cordic_sin_16bit(), and cordic_sin_32bit().
uint16_t cordic_read_16bit_result | ( | void | ) |
Read single 16 bit result.
Use this function to read one single 16 bit result contained in the lower 16 bit of the CORDIC_RDATA register.
Definition at line 263 of file cordic_common_v1.c.
References CORDIC_RDATA.
Referenced by cordic_cos_16bit(), and cordic_sin_16bit().
void cordic_read_16bit_results | ( | uint16_t * | result1, |
uint16_t * | result2 | ||
) |
Read two 16 bit results.
Use this function to read both 16 bit results contained in the 32 bit CORDIC_RDATA register.
[out] | result1 | First result is written to this address |
[out] | result2 | Second result is written to this address |
Definition at line 275 of file cordic_common_v1.c.
References CORDIC_RDATA.
uint32_t cordic_read_32bit_result | ( | void | ) |
Read 32 bit result.
Use this function to read the 32 bit CORDIC_RDATA register.
Definition at line 287 of file cordic_common_v1.c.
References CORDIC_RDATA.
Referenced by cordic_cos_32bit(), and cordic_sin_32bit().
void cordic_set_argument_width_16bit | ( | void | ) |
Set CORDIC to 16 bit argument data width.
When configured this way, argument(s) are expected with 16 bit width. Only one 32 bit write operation is required even for operations with two arguments (in this case lower 16 bits contain argument 1, higher 16 bits contain argument 2).
Definition at line 70 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_ARGSIZE.
Referenced by cordic_configure_for_cos_16bit(), and cordic_configure_for_sin_16bit().
void cordic_set_argument_width_32bit | ( | void | ) |
Set CORDIC to 32 bit argument data width.
When configured this way, argument(s) are expected with 32 bit width. Two write operations are required for operations with two arguments.
Definition at line 59 of file cordic_common_v1.c.
References CORDIC_CSR.
Referenced by cordic_configure_for_cos_32bit(), and cordic_configure_for_sin_32bit().
void cordic_set_function | ( | uint8_t | function | ) |
Set CORDIC operation type.
Select what operation the CORDIC peripheral performs.
[in] | function | function of type FUNCTION: CORDIC operation to be performed |
Definition at line 217 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_FUNC_SHIFT.
Referenced by cordic_configure_for_cos_16bit(), cordic_configure_for_cos_32bit(), cordic_configure_for_sin_16bit(), and cordic_configure_for_sin_32bit().
void cordic_set_number_of_arguments_1 | ( | void | ) |
Set number of CORDIC arguments to one 32 bit argument or two 16 bit arguments.
Use this option for CORDIC operations with only one argument and CORDIC operations with two 16 bit arguments. In this case the operation is triggered as soon as one 32bit write to the CORDIC_WDATA register occurred.
Definition at line 102 of file cordic_common_v1.c.
References CORDIC_CSR.
Referenced by cordic_configure_for_cos_16bit(), cordic_configure_for_cos_32bit(), cordic_configure_for_sin_16bit(), and cordic_configure_for_sin_32bit().
void cordic_set_number_of_arguments_2 | ( | void | ) |
Set number of CORDIC arguments to two 32 bit arguments.
Use this option for CORDIC operations with two 32 bit arguments. In this case the operation is triggered as soon as two 32bit writes to the CORDIC_WDATA register occurred.
Definition at line 113 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_NARGS.
void cordic_set_number_of_results_1 | ( | void | ) |
Set number of CORDIC results to one 32 bit result or two 16 bit results.
Use this option for CORDIC operations with only one result and CORDIC operations with two 16 bit results. In this case the result ready flag is cleared and a new operation can be started as soon as one 32bit read from the CORDIC_RDATA register occurred.
Definition at line 124 of file cordic_common_v1.c.
References CORDIC_CSR.
Referenced by cordic_configure_for_cos_16bit(), cordic_configure_for_cos_32bit(), cordic_configure_for_sin_16bit(), and cordic_configure_for_sin_32bit().
void cordic_set_number_of_results_2 | ( | void | ) |
Set number of CORDIC results to two 32 bit results.
Use this option for CORDIC operations with two 32 bit results. In this case the result ready flag is cleared and a new operation can be started as soon as two 32 bit reads from the CORDIC_RDATA register occurred.
Definition at line 135 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_NRES.
void cordic_set_precision | ( | uint8_t | precision | ) |
Set precision for CORDIC operations.
The speed of CORDIC operations can be increased by lowering the number of iterations. This will decrease precision.
[in] | precision | precision of type PRECISION: Precision of CORDIC operation (number of iterations) |
Definition at line 207 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_PRECISION_SHIFT.
Referenced by cordic_configure_for_cos_16bit(), cordic_configure_for_cos_32bit(), cordic_configure_for_sin_16bit(), and cordic_configure_for_sin_32bit().
void cordic_set_result_width_16bit | ( | void | ) |
Set CORDIC to 16 bit result data width.
When configured this way, results are written with 16 bit width. Only one 32 bit read operation is required even for operations with two results (in this case lower 16 bits contain result 1, higher 16 bits contain result 2).
Definition at line 91 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_RESSIZE.
Referenced by cordic_configure_for_cos_16bit(), and cordic_configure_for_sin_16bit().
void cordic_set_result_width_32bit | ( | void | ) |
Set CORDIC to 32 bit result data width.
When configured this way, results(s) are written with 32 bit width. Two read operations are required for operations with two results.
Definition at line 80 of file cordic_common_v1.c.
References CORDIC_CSR.
Referenced by cordic_configure_for_cos_32bit(), and cordic_configure_for_sin_32bit().
void cordic_set_scaling_factor | ( | uint8_t | n | ) |
Set scaling factor for CORDIC operations.
For some operations, the arguments can be multiplied by a factor of 2^-n to fit in the argument range. The result must then be multiplied by 2^n.
[in] | n | scaling factor of type SCALE: Scaling factor |
Definition at line 196 of file cordic_common_v1.c.
References CORDIC_CSR, and CORDIC_CSR_SCALE_SHIFT.
int16_t cordic_sin_16bit | ( | int16_t | x | ) |
Compute 16 bit sine using CORDIC (blocking)
Convenience function to calculate 32767*sin(x/32767*pi). This implementation can be sped up in most applications by configuring the peripheral only once and then trigger subsequent operations by writing new arguments to the CORDIC_WDATA register. Additionally, sine and cosine are always computed in a single operation. Read the second result to obtain the other value.
[in] | x | argument |
Definition at line 430 of file cordic_common_v1.c.
References cordic_configure_for_sin_16bit(), cordic_is_result_ready(), cordic_read_16bit_result(), and cordic_write_16bit_arguments().
void cordic_sin_16bit_async | ( | int16_t | x | ) |
Compute 16 bit sine using CORDIC (non blocking)
Convenience function to calculate 32767*sin(x/32767*pi). Result can be obtained from result register using cordic_read_16bit_result().
[in] | x | argument |
Definition at line 449 of file cordic_common_v1.c.
References cordic_configure_for_sin_16bit(), and cordic_write_16bit_arguments().
int32_t cordic_sin_32bit | ( | int32_t | x | ) |
Compute 32 bit sine using CORDIC (blocking)
Convenience function to calculate 2147483647*sin(x/2147483647*pi). This implementation can be sped up in most applications by configuring the peripheral only once and then trigger subsequent operations by writing new arguments to the CORDIC_WDATA register. Additionally, sine and cosine are always computed in a single operation. Read the second result to obtain the other value.
[in] | x | argument |
Definition at line 465 of file cordic_common_v1.c.
References cordic_configure_for_sin_32bit(), cordic_is_result_ready(), cordic_read_32bit_result(), and cordic_write_32bit_argument().
void cordic_sin_32bit_async | ( | int32_t | x | ) |
Compute 32 bit sine using CORDIC (non blocking)
Convenience function to calculate 2147483647*sin(x/2147483647*pi). Result can be obtained from result register using cordic_read_32bit_result().
[in] | x | argument |
Definition at line 484 of file cordic_common_v1.c.
References cordic_configure_for_sin_32bit(), and cordic_write_32bit_argument().
void cordic_write_16bit_argument | ( | uint16_t | argument | ) |
Write single 16 bit argument.
Use this function to set one single 16 bit argument. The upper 16 bit of the 32 bit result register (that is the second argument) will be set to zero.
[in] | argument | argument |
Definition at line 229 of file cordic_common_v1.c.
References CORDIC_WDATA.
void cordic_write_16bit_arguments | ( | uint16_t | argument1, |
uint16_t | argument2 | ||
) |
Write two 16 bit arguments.
Use this function to set write 16 bit arguments to the 32 bit CORDIC_WDATA register.
[in] | argument1 | argument1 |
[in] | argument2 | argument2 |
Definition at line 240 of file cordic_common_v1.c.
References CORDIC_WDATA.
Referenced by cordic_cos_16bit(), cordic_cos_16bit_async(), cordic_sin_16bit(), and cordic_sin_16bit_async().
void cordic_write_32bit_argument | ( | uint32_t | argument | ) |
Write single 32 bit argument.
Use this function to write a 32 bit argument to the CORDIC_WDATA register. If the operation needs two arguments call cordic_set_number_of_arguments_2() before and then use this function twice to write both arguments.
[in] | argument | argument |
Definition at line 252 of file cordic_common_v1.c.
References CORDIC_WDATA.
Referenced by cordic_cos_32bit(), cordic_cos_32bit_async(), cordic_sin_32bit(), and cordic_sin_32bit_async().