libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
cordic_common_v1.h
Go to the documentation of this file.
1/** @addtogroup cordic_defines
2
3@author @htmlonly &copy; @endhtmlonly 2022 Oskar H. Maier <ohma@posteo.de>
4
5 */
6
7/*
8 * This file is part of the libopencm3 project.
9 *
10 * Copyright (C) 2022 Oskar H. Maier <ohma@posteo.de>
11 *
12 * This library is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26/**@{*/
27
28/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA CORDIC.H
29The order of header inclusion is important. cordic.h includes the device
30specific memorymap.h header before including this header file.*/
31
32/** @cond */
33#ifdef LIBOPENCM3_CORDIC_H
34/** @endcond */
35#ifndef LIBOPENCM3_CORDIC_COMMON_V1_H
36#define LIBOPENCM3_CORDIC_COMMON_V1_H
37
38/** @defgroup cordic_registers CORDIC registers
39@{*/
40/* ----- CORDIC registers ----- */
41/** CORDIC control/status register */
42#define CORDIC_CSR MMIO32(CORDIC_BASE + 0x00)
43/** CORDIC argument register */
44#define CORDIC_WDATA MMIO32(CORDIC_BASE + 0x04)
45/** CORDIC result register */
46#define CORDIC_RDATA MMIO32(CORDIC_BASE + 0x08)
47/**@}*/
48
49/* ----- Register values ----- */
50
51/* ----- CORDIC_CSR Values ----- */
52/** @defgroup cordic_csr CSR CORDIC control/status register
53@{*/
54/** RRDY: result ready flag */
55#define CORDIC_CSR_RRDY (0x1 << 31)
56/** ARGSIZE: Width of input data */
57#define CORDIC_CSR_ARGSIZE (0x1 << 22)
58/** RESSIZE: Width of result data */
59#define CORDIC_CSR_RESSIZE (0x1 << 21)
60/** NARGS: Number of input data writes */
61#define CORDIC_CSR_NARGS (0x1 << 20)
62/** NRES: Number of result data reads */
63#define CORDIC_CSR_NRES (0x1 << 19)
64/** DMAWEN: DMA write enable */
65#define CORDIC_CSR_DMAWEN (0x1 << 18)
66/** DMAREN: DMA write enable */
67#define CORDIC_CSR_DMAREN (0x1 << 17)
68/** DMAREN: Interrupt enable */
69#define CORDIC_CSR_IEN (0x1 << 16)
70
71/** @defgroup cordic_csr_scale SCALE: Scaling factor
72@{*/
73#define CORDIC_CSR_SCALE_1 (0x0)
74#define CORDIC_CSR_SCALE_2 (0x1)
75#define CORDIC_CSR_SCALE_4 (0x2)
76#define CORDIC_CSR_SCALE_8 (0x3)
77#define CORDIC_CSR_SCALE_16 (0x4)
78#define CORDIC_CSR_SCALE_32 (0x5)
79#define CORDIC_CSR_SCALE_64 (0x6)
80#define CORDIC_CSR_SCALE_128 (0x7)
81/**@}*/
82#define CORDIC_CSR_SCALE_SHIFT (8)
83#define CORDIC_CSR_SCALE_MASK (0x7 << CORDIC_CSR_SCALE_SHIFT)
84
85/** @defgroup cordic_csr_precision PRECISION: Precision of CORDIC operation (number of iterations)
86@{*/
87#define CORDIC_CSR_PRECISION_ITER_04 (0x1)
88#define CORDIC_CSR_PRECISION_ITER_08 (0x2)
89#define CORDIC_CSR_PRECISION_ITER_12 (0x3)
90#define CORDIC_CSR_PRECISION_ITER_16 (0x4)
91#define CORDIC_CSR_PRECISION_ITER_20 (0x5)
92#define CORDIC_CSR_PRECISION_ITER_24 (0x6)
93#define CORDIC_CSR_PRECISION_ITER_28 (0x7)
94#define CORDIC_CSR_PRECISION_ITER_32 (0x8)
95#define CORDIC_CSR_PRECISION_ITER_36 (0x9)
96#define CORDIC_CSR_PRECISION_ITER_40 (0xA)
97#define CORDIC_CSR_PRECISION_ITER_44 (0xB)
98#define CORDIC_CSR_PRECISION_ITER_48 (0xC)
99#define CORDIC_CSR_PRECISION_ITER_52 (0xD)
100#define CORDIC_CSR_PRECISION_ITER_56 (0xE)
101#define CORDIC_CSR_PRECISION_ITER_60 (0xF)
102/**@}*/
103#define CORDIC_CSR_PRECISION_SHIFT (4)
104#define CORDIC_CSR_PRECISION_MASK (0xF << CORDIC_CSR_PRECISION_SHIFT)
105
106/** @defgroup cordic_csr_function FUNCTION: CORDIC operation to be performed
107@{*/
108#define CORDIC_CSR_FUNC_COS (0x0)
109#define CORDIC_CSR_FUNC_SIN (0x1)
110#define CORDIC_CSR_FUNC_PHASE (0x2)
111#define CORDIC_CSR_FUNC_MODULUS (0x3)
112#define CORDIC_CSR_FUNC_ATAN (0x4)
113#define CORDIC_CSR_FUNC_COSH (0x5)
114#define CORDIC_CSR_FUNC_SINH (0x6)
115#define CORDIC_CSR_FUNC_ATANH (0x7)
116#define CORDIC_CSR_FUNC_COSINE (0x8)
117#define CORDIC_CSR_FUNC_SQRT (0x9)
118/**@}*/
119#define CORDIC_CSR_FUNC_SHIFT (0)
120#define CORDIC_CSR_FUNC_MASK (0xF << CORDIC_CSR_FUNC_SHIFT)
121
122/**@}*/
123
124/* --- Function prototypes ------------------------------------------------- */
125
127
128bool cordic_is_result_ready(void);
137void cordic_enable_dma_write(void);
138void cordic_disable_dma_write(void);
139void cordic_enable_dma_read(void);
140void cordic_disable_dma_read(void);
141void cordic_enable_interrupt(void);
142void cordic_set_scaling_factor(uint8_t n);
143void cordic_set_precision(uint8_t precision);
144void cordic_set_function(uint8_t function);
145void cordic_write_16bit_argument(uint16_t argument);
146void cordic_write_16bit_arguments(uint16_t argument1, uint16_t argument2);
147void cordic_write_32bit_argument(uint32_t argument);
148uint16_t cordic_read_16bit_result(void);
149void cordic_read_16bit_results(uint16_t *result1, uint16_t *result2);
150uint32_t cordic_read_32bit_result(void);
155int16_t cordic_cos_16bit(int16_t x);
156int32_t cordic_cos_32bit(int32_t x);
157int16_t cordic_sin_16bit(int16_t x);
158int32_t cordic_sin_32bit(int32_t x);
159void cordic_cos_16bit_async(int16_t x);
160void cordic_cos_32bit_async(int32_t x);
161void cordic_sin_16bit_async(int16_t x);
162void cordic_sin_32bit_async(int32_t x);
164
165#endif
166/** @cond */
167#endif
168/** @endcond */
169/**@}*/
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
int32_t cordic_sin_32bit(int32_t x)
Compute 32 bit sine using CORDIC (blocking)
void cordic_configure_for_cos_16bit(void)
Configure cordic for 16 bit cosine.
void cordic_write_16bit_arguments(uint16_t argument1, uint16_t argument2)
Write two 16 bit arguments.
void cordic_configure_for_sin_16bit(void)
Configure cordic for 16 bit sine.
void cordic_set_number_of_arguments_2(void)
Set number of CORDIC arguments to two 32 bit arguments.
void cordic_configure_for_cos_32bit(void)
Configure cordic for 32 bit cosine.
void cordic_set_result_width_16bit(void)
Set CORDIC to 16 bit result data width.
int16_t cordic_cos_16bit(int16_t x)
Compute 16 bit cosine using CORDIC (blocking)
void cordic_set_number_of_results_2(void)
Set number of CORDIC results to two 32 bit results.
void cordic_enable_interrupt(void)
Enable interrupt when result is ready.
int32_t cordic_cos_32bit(int32_t x)
Compute 32 bit cosine using CORDIC (blocking)
void cordic_set_precision(uint8_t precision)
Set precision for CORDIC operations.
void cordic_cos_32bit_async(int32_t x)
Compute 32 bit cosine using CORDIC (non blocking)
void cordic_disable_dma_write(void)
Disable DMA for writes to CORDIC_WDATA.
void cordic_set_scaling_factor(uint8_t n)
Set scaling factor for CORDIC operations.
bool cordic_is_result_ready(void)
Read CORDIC result ready flag.
void cordic_set_number_of_results_1(void)
Set number of CORDIC results to one 32 bit result or two 16 bit results.
int16_t cordic_sin_16bit(int16_t x)
Compute 16 bit sine using CORDIC (blocking)
void cordic_enable_dma_read(void)
Enable DMA for read from CORDIC_RDATA.
uint16_t cordic_read_16bit_result(void)
Read single 16 bit result.
void cordic_write_32bit_argument(uint32_t argument)
Write single 32 bit argument.
void cordic_read_16bit_results(uint16_t *result1, uint16_t *result2)
Read two 16 bit results.
void cordic_configure_for_sin_32bit(void)
Configure cordic for 32 bit sine.
void cordic_set_argument_width_16bit(void)
Set CORDIC to 16 bit argument data width.
void cordic_set_function(uint8_t function)
Set CORDIC operation type.
void cordic_sin_16bit_async(int16_t x)
Compute 16 bit sine using CORDIC (non blocking)
void cordic_sin_32bit_async(int32_t x)
Compute 32 bit sine using CORDIC (non blocking)
void cordic_write_16bit_argument(uint16_t argument)
Write single 16 bit argument.
void cordic_disable_dma_read(void)
Disable DMA for read from CORDIC_RDATA.
void cordic_enable_dma_write(void)
Enable DMA for writes to CORDIC_WDATA.
void cordic_set_argument_width_32bit(void)
Set CORDIC to 32 bit argument data width.
void cordic_set_number_of_arguments_1(void)
Set number of CORDIC arguments to one 32 bit argument or two 16 bit arguments.
void cordic_cos_16bit_async(int16_t x)
Compute 16 bit cosine using CORDIC (non blocking)
void cordic_set_result_width_32bit(void)
Set CORDIC to 32 bit result data width.
uint32_t cordic_read_32bit_result(void)
Read 32 bit result.