1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
|
/**
******************************************************************************
* @file stm32h7xx_hal_cordic.c
* @author MCD Application Team
* @brief CORDIC HAL module driver.
* This file provides firmware functions to manage the following
* functionalities of the CORDIC peripheral:
* + Initialization and de-initialization functions
* + Peripheral Control functions
* + Callback functions
* + IRQ handler management
* + Peripheral State functions
*
******************************************************************************
* @attention
*
* Copyright (c) 2017 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
@verbatim
================================================================================
##### How to use this driver #####
================================================================================
[..]
The CORDIC HAL driver can be used as follows:
(#) Initialize the CORDIC low level resources by implementing the HAL_CORDIC_MspInit():
(++) Enable the CORDIC interface clock using __HAL_RCC_CORDIC_CLK_ENABLE()
(++) In case of using interrupts (e.g. HAL_CORDIC_Calculate_IT())
(+++) Configure the CORDIC interrupt priority using HAL_NVIC_SetPriority()
(+++) Enable the CORDIC IRQ handler using HAL_NVIC_EnableIRQ()
(+++) In CORDIC IRQ handler, call HAL_CORDIC_IRQHandler()
(++) In case of using DMA to control data transfer (e.g. HAL_CORDIC_Calculate_DMA())
(+++) Enable the DMA2 interface clock using
__HAL_RCC_DMA2_CLK_ENABLE()
(+++) Configure and enable two DMA channels one for managing data transfer from
memory to peripheral (input channel) and another channel for managing data
transfer from peripheral to memory (output channel)
(+++) Associate the initialized DMA handle to the CORDIC DMA handle
using __HAL_LINKDMA()
(+++) Configure the priority and enable the NVIC for the transfer complete
interrupt on the two DMA channels.
Resort to HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
(#) Initialize the CORDIC HAL using HAL_CORDIC_Init(). This function
(++) resorts to HAL_CORDIC_MspInit() for low-level initialization,
(#) Configure CORDIC processing (calculation) using HAL_CORDIC_Configure().
This function configures:
(++) Processing functions: Cosine, Sine, Phase, Modulus, Arctangent,
Hyperbolic cosine, Hyperbolic sine, Hyperbolic arctangent,
Natural log, Square root
(++) Scaling factor: 1 to 2exp(-7)
(++) Width of input data: 32 bits input data size (Q1.31 format) or 16 bits
input data size (Q1.15 format)
(++) Width of output data: 32 bits output data size (Q1.31 format) or 16 bits
output data size (Q1.15 format)
(++) Number of 32-bit write expected for one calculation: One 32-bits write
or Two 32-bit write
(++) Number of 32-bit read expected after one calculation: One 32-bits read
or Two 32-bit read
(++) Precision: 1 to 15 cycles for calculation (the more cycles, the better precision)
(#) Four processing (calculation) functions are available:
(++) Polling mode: processing API is blocking function
i.e. it processes the data and wait till the processing is finished
API is HAL_CORDIC_Calculate
(++) Polling Zero-overhead mode: processing API is blocking function
i.e. it processes the data and wait till the processing is finished
A bit faster than standard polling mode, but blocking also AHB bus
API is HAL_CORDIC_CalculateZO
(++) Interrupt mode: processing API is not blocking functions
i.e. it processes the data under interrupt
API is HAL_CORDIC_Calculate_IT
(++) DMA mode: processing API is not blocking functions and the CPU is
not used for data transfer,
i.e. the data transfer is ensured by DMA
API is HAL_CORDIC_Calculate_DMA
(#) Call HAL_CORDIC_DeInit() to de-initialize the CORDIC peripheral. This function
(++) resorts to HAL_CORDIC_MspDeInit() for low-level de-initialization,
*** Callback registration ***
=============================================
The compilation define USE_HAL_CORDIC_REGISTER_CALLBACKS when set to 1
allows the user to configure dynamically the driver callbacks.
Use Function HAL_CORDIC_RegisterCallback() to register an interrupt callback.
Function HAL_CORDIC_RegisterCallback() allows to register following callbacks:
(+) ErrorCallback : Error Callback.
(+) CalculateCpltCallback : Calculate complete Callback.
(+) MspInitCallback : CORDIC MspInit.
(+) MspDeInitCallback : CORDIC MspDeInit.
This function takes as parameters the HAL peripheral handle, the Callback ID
and a pointer to the user callback function.
Use function HAL_CORDIC_UnRegisterCallback() to reset a callback to the default
weak function.
HAL_CORDIC_UnRegisterCallback takes as parameters the HAL peripheral handle,
and the Callback ID.
This function allows to reset following callbacks:
(+) ErrorCallback : Error Callback.
(+) CalculateCpltCallback : Calculate complete Callback.
(+) MspInitCallback : CORDIC MspInit.
(+) MspDeInitCallback : CORDIC MspDeInit.
By default, after the HAL_CORDIC_Init() and when the state is HAL_CORDIC_STATE_RESET,
all callbacks are set to the corresponding weak functions:
examples HAL_CORDIC_ErrorCallback(), HAL_CORDIC_CalculateCpltCallback().
Exception done for MspInit and MspDeInit functions that are
reset to the legacy weak function in the HAL_CORDIC_Init()/ HAL_CORDIC_DeInit() only when
these callbacks are null (not registered beforehand).
if not, MspInit or MspDeInit are not null, the HAL_CORDIC_Init()/ HAL_CORDIC_DeInit()
keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
Callbacks can be registered/unregistered in HAL_CORDIC_STATE_READY state only.
Exception done MspInit/MspDeInit that can be registered/unregistered
in HAL_CORDIC_STATE_READY or HAL_CORDIC_STATE_RESET state,
thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
In that case first register the MspInit/MspDeInit user callbacks
using HAL_CORDIC_RegisterCallback() before calling HAL_CORDIC_DeInit()
or HAL_CORDIC_Init() function.
When The compilation define USE_HAL_CORDIC_REGISTER_CALLBACKS is set to 0 or
not defined, the callback registration feature is not available and all callbacks
are set to the corresponding weak functions.
@endverbatim
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32h7xx_hal.h"
#if defined(CORDIC)
#ifdef HAL_CORDIC_MODULE_ENABLED
/** @addtogroup STM32H7xx_HAL_Driver
* @{
*/
/** @defgroup CORDIC CORDIC
* @brief CORDIC HAL driver modules.
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup CORDIC_Private_Functions CORDIC Private Functions
* @{
*/
static void CORDIC_WriteInDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, const int32_t **ppInBuff);
static void CORDIC_ReadOutDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, int32_t **ppOutBuff);
static void CORDIC_DMAInCplt(DMA_HandleTypeDef *hdma);
static void CORDIC_DMAOutCplt(DMA_HandleTypeDef *hdma);
static void CORDIC_DMAError(DMA_HandleTypeDef *hdma);
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup CORDIC_Exported_Functions CORDIC Exported Functions
* @{
*/
/** @defgroup CORDIC_Exported_Functions_Group1 Initialization and de-initialization functions
* @brief Initialization and Configuration functions.
*
@verbatim
==============================================================================
##### Initialization and de-initialization functions #####
==============================================================================
[..] This section provides functions allowing to:
(+) Initialize the CORDIC peripheral and the associated handle
(+) DeInitialize the CORDIC peripheral
(+) Initialize the CORDIC MSP (MCU Specific Package)
(+) De-Initialize the CORDIC MSP
[..]
@endverbatim
* @{
*/
/**
* @brief Initialize the CORDIC peripheral and the associated handle.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_Init(CORDIC_HandleTypeDef *hcordic)
{
/* Check the CORDIC handle allocation */
if (hcordic == NULL)
{
/* Return error status */
return HAL_ERROR;
}
/* Check the instance */
assert_param(IS_CORDIC_ALL_INSTANCE(hcordic->Instance));
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
if (hcordic->State == HAL_CORDIC_STATE_RESET)
{
/* Allocate lock resource and initialize it */
hcordic->Lock = HAL_UNLOCKED;
/* Reset callbacks to legacy functions */
hcordic->ErrorCallback = HAL_CORDIC_ErrorCallback; /* Legacy weak ErrorCallback */
hcordic->CalculateCpltCallback = HAL_CORDIC_CalculateCpltCallback; /* Legacy weak CalculateCpltCallback */
if (hcordic->MspInitCallback == NULL)
{
hcordic->MspInitCallback = HAL_CORDIC_MspInit; /* Legacy weak MspInit */
}
/* Initialize the low level hardware */
hcordic->MspInitCallback(hcordic);
}
#else
if (hcordic->State == HAL_CORDIC_STATE_RESET)
{
/* Allocate lock resource and initialize it */
hcordic->Lock = HAL_UNLOCKED;
/* Initialize the low level hardware */
HAL_CORDIC_MspInit(hcordic);
}
#endif /* (USE_HAL_CORDIC_REGISTER_CALLBACKS) */
/* Set CORDIC error code to none */
hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
/* Reset pInBuff and pOutBuff */
hcordic->pInBuff = NULL;
hcordic->pOutBuff = NULL;
/* Reset NbCalcToOrder and NbCalcToGet */
hcordic->NbCalcToOrder = 0U;
hcordic->NbCalcToGet = 0U;
/* Reset DMADirection */
hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
/* Change CORDIC peripheral state */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Return function status */
return HAL_OK;
}
/**
* @brief DeInitialize the CORDIC peripheral.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_DeInit(CORDIC_HandleTypeDef *hcordic)
{
/* Check the CORDIC handle allocation */
if (hcordic == NULL)
{
/* Return error status */
return HAL_ERROR;
}
/* Check the parameters */
assert_param(IS_CORDIC_ALL_INSTANCE(hcordic->Instance));
/* Change CORDIC peripheral state */
hcordic->State = HAL_CORDIC_STATE_BUSY;
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
if (hcordic->MspDeInitCallback == NULL)
{
hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit;
}
/* De-Initialize the low level hardware */
hcordic->MspDeInitCallback(hcordic);
#else
/* De-Initialize the low level hardware: CLOCK, NVIC, DMA */
HAL_CORDIC_MspDeInit(hcordic);
#endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
/* Set CORDIC error code to none */
hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
/* Reset pInBuff and pOutBuff */
hcordic->pInBuff = NULL;
hcordic->pOutBuff = NULL;
/* Reset NbCalcToOrder and NbCalcToGet */
hcordic->NbCalcToOrder = 0U;
hcordic->NbCalcToGet = 0U;
/* Reset DMADirection */
hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
/* Change CORDIC peripheral state */
hcordic->State = HAL_CORDIC_STATE_RESET;
/* Reset Lock */
hcordic->Lock = HAL_UNLOCKED;
/* Return function status */
return HAL_OK;
}
/**
* @brief Initialize the CORDIC MSP.
* @param hcordic CORDIC handle
* @retval None
*/
__weak void HAL_CORDIC_MspInit(CORDIC_HandleTypeDef *hcordic)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hcordic);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_CORDIC_MspInit can be implemented in the user file
*/
}
/**
* @brief DeInitialize the CORDIC MSP.
* @param hcordic CORDIC handle
* @retval None
*/
__weak void HAL_CORDIC_MspDeInit(CORDIC_HandleTypeDef *hcordic)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hcordic);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_CORDIC_MspDeInit can be implemented in the user file
*/
}
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
/**
* @brief Register a CORDIC CallBack.
* To be used instead of the weak predefined callback.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @param CallbackID ID of the callback to be registered
* This parameter can be one of the following values:
* @arg @ref HAL_CORDIC_ERROR_CB_ID error Callback ID
* @arg @ref HAL_CORDIC_CALCULATE_CPLT_CB_ID calculate complete Callback ID
* @arg @ref HAL_CORDIC_MSPINIT_CB_ID MspInit callback ID
* @arg @ref HAL_CORDIC_MSPDEINIT_CB_ID MspDeInit callback ID
* @param pCallback pointer to the Callback function
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_RegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID,
void (* pCallback)(CORDIC_HandleTypeDef *_hcordic))
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
/* Return error status */
return HAL_ERROR;
}
if (hcordic->State == HAL_CORDIC_STATE_READY)
{
switch (CallbackID)
{
case HAL_CORDIC_ERROR_CB_ID :
hcordic->ErrorCallback = pCallback;
break;
case HAL_CORDIC_CALCULATE_CPLT_CB_ID :
hcordic->CalculateCpltCallback = pCallback;
break;
case HAL_CORDIC_MSPINIT_CB_ID :
hcordic->MspInitCallback = pCallback;
break;
case HAL_CORDIC_MSPDEINIT_CB_ID :
hcordic->MspDeInitCallback = pCallback;
break;
default :
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
/* Return error status */
status = HAL_ERROR;
break;
}
}
else if (hcordic->State == HAL_CORDIC_STATE_RESET)
{
switch (CallbackID)
{
case HAL_CORDIC_MSPINIT_CB_ID :
hcordic->MspInitCallback = pCallback;
break;
case HAL_CORDIC_MSPDEINIT_CB_ID :
hcordic->MspDeInitCallback = pCallback;
break;
default :
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
/* Return error status */
status = HAL_ERROR;
break;
}
}
else
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
/* Return error status */
status = HAL_ERROR;
}
return status;
}
#endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
/**
* @brief Unregister a CORDIC CallBack.
* CORDIC callback is redirected to the weak predefined callback.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @param CallbackID ID of the callback to be unregistered
* This parameter can be one of the following values:
* @arg @ref HAL_CORDIC_ERROR_CB_ID error Callback ID
* @arg @ref HAL_CORDIC_CALCULATE_CPLT_CB_ID calculate complete Callback ID
* @arg @ref HAL_CORDIC_MSPINIT_CB_ID MspInit callback ID
* @arg @ref HAL_CORDIC_MSPDEINIT_CB_ID MspDeInit callback ID
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_UnRegisterCallback(CORDIC_HandleTypeDef *hcordic, HAL_CORDIC_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
if (hcordic->State == HAL_CORDIC_STATE_READY)
{
switch (CallbackID)
{
case HAL_CORDIC_ERROR_CB_ID :
hcordic->ErrorCallback = HAL_CORDIC_ErrorCallback;
break;
case HAL_CORDIC_CALCULATE_CPLT_CB_ID :
hcordic->CalculateCpltCallback = HAL_CORDIC_CalculateCpltCallback;
break;
case HAL_CORDIC_MSPINIT_CB_ID :
hcordic->MspInitCallback = HAL_CORDIC_MspInit;
break;
case HAL_CORDIC_MSPDEINIT_CB_ID :
hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit;
break;
default :
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
/* Return error status */
status = HAL_ERROR;
break;
}
}
else if (hcordic->State == HAL_CORDIC_STATE_RESET)
{
switch (CallbackID)
{
case HAL_CORDIC_MSPINIT_CB_ID :
hcordic->MspInitCallback = HAL_CORDIC_MspInit;
break;
case HAL_CORDIC_MSPDEINIT_CB_ID :
hcordic->MspDeInitCallback = HAL_CORDIC_MspDeInit;
break;
default :
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
/* Return error status */
status = HAL_ERROR;
break;
}
}
else
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_INVALID_CALLBACK;
/* Return error status */
status = HAL_ERROR;
}
return status;
}
#endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
/**
* @}
*/
/** @defgroup CORDIC_Exported_Functions_Group2 Peripheral Control functions
* @brief Control functions.
*
@verbatim
==============================================================================
##### Peripheral Control functions #####
==============================================================================
[..] This section provides functions allowing to:
(+) Configure the CORDIC peripheral: function, precision, scaling factor,
number of input data and output data, size of input data and output data.
(+) Calculate output data of CORDIC processing on input date, using the
existing CORDIC configuration
[..] Four processing functions are available for calculation:
(+) Polling mode
(+) Polling mode, with Zero-Overhead register access
(+) Interrupt mode
(+) DMA mode
@endverbatim
* @{
*/
/**
* @brief Configure the CORDIC processing according to the specified
parameters in the CORDIC_ConfigTypeDef structure.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @param sConfig pointer to a CORDIC_ConfigTypeDef structure that
* contains the CORDIC configuration information.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_Configure(CORDIC_HandleTypeDef *hcordic, const CORDIC_ConfigTypeDef *sConfig)
{
HAL_StatusTypeDef status = HAL_OK;
/* Check the parameters */
assert_param(IS_CORDIC_FUNCTION(sConfig->Function));
assert_param(IS_CORDIC_PRECISION(sConfig->Precision));
assert_param(IS_CORDIC_SCALE(sConfig->Scale));
assert_param(IS_CORDIC_NBWRITE(sConfig->NbWrite));
assert_param(IS_CORDIC_NBREAD(sConfig->NbRead));
assert_param(IS_CORDIC_INSIZE(sConfig->InSize));
assert_param(IS_CORDIC_OUTSIZE(sConfig->OutSize));
/* Check handle state is ready */
if (hcordic->State == HAL_CORDIC_STATE_READY)
{
/* Apply all configuration parameters in CORDIC control register */
MODIFY_REG(hcordic->Instance->CSR, \
(CORDIC_CSR_FUNC | CORDIC_CSR_PRECISION | CORDIC_CSR_SCALE | \
CORDIC_CSR_NARGS | CORDIC_CSR_NRES | CORDIC_CSR_ARGSIZE | CORDIC_CSR_RESSIZE), \
(sConfig->Function | sConfig->Precision | sConfig->Scale | \
sConfig->NbWrite | sConfig->NbRead | sConfig->InSize | sConfig->OutSize));
}
else
{
/* Set CORDIC error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
/* Return error status */
status = HAL_ERROR;
}
/* Return function status */
return status;
}
/**
* @brief Carry out data of CORDIC processing in polling mode,
* according to the existing CORDIC configuration.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module.
* @param pInBuff Pointer to buffer containing input data for CORDIC processing.
* @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
* @param NbCalc Number of CORDIC calculation to process.
* @param Timeout Specify Timeout value
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_Calculate(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
uint32_t NbCalc, uint32_t Timeout)
{
uint32_t tickstart;
uint32_t index;
const int32_t *p_tmp_in_buff = pInBuff;
int32_t *p_tmp_out_buff = pOutBuff;
/* Check parameters setting */
if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U))
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
/* Return error status */
return HAL_ERROR;
}
/* Check handle state is ready */
if (hcordic->State == HAL_CORDIC_STATE_READY)
{
/* Reset CORDIC error code */
hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_BUSY;
/* Get tick */
tickstart = HAL_GetTick();
/* Write of input data in Write Data register, and increment input buffer pointer */
CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
/* Calculation is started.
Provide next set of input data, until number of calculation is achieved */
for (index = (NbCalc - 1U); index > 0U; index--)
{
/* Write of input data in Write Data register, and increment input buffer pointer */
CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
/* Wait for RRDY flag to be raised */
do
{
/* Check for the Timeout */
if (Timeout != HAL_MAX_DELAY)
{
if ((HAL_GetTick() - tickstart) > Timeout)
{
/* Set CORDIC error code */
hcordic->ErrorCode = HAL_CORDIC_ERROR_TIMEOUT;
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Return function status */
return HAL_ERROR;
}
}
} while (HAL_IS_BIT_CLR(hcordic->Instance->CSR, CORDIC_CSR_RRDY));
/* Read output data from Read Data register, and increment output buffer pointer */
CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
}
/* Read output data from Read Data register, and increment output buffer pointer */
CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Return function status */
return HAL_OK;
}
else
{
/* Set CORDIC error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
/* Return function status */
return HAL_ERROR;
}
}
/**
* @brief Carry out data of CORDIC processing in Zero-Overhead mode (output data being read
* soon as input data are written), according to the existing CORDIC configuration.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module.
* @param pInBuff Pointer to buffer containing input data for CORDIC processing.
* @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
* @param NbCalc Number of CORDIC calculation to process.
* @param Timeout Specify Timeout value
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_CalculateZO(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
uint32_t NbCalc, uint32_t Timeout)
{
uint32_t tickstart;
uint32_t index;
const int32_t *p_tmp_in_buff = pInBuff;
int32_t *p_tmp_out_buff = pOutBuff;
/* Check parameters setting */
if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U))
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
/* Return error status */
return HAL_ERROR;
}
/* Check handle state is ready */
if (hcordic->State == HAL_CORDIC_STATE_READY)
{
/* Reset CORDIC error code */
hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_BUSY;
/* Get tick */
tickstart = HAL_GetTick();
/* Write of input data in Write Data register, and increment input buffer pointer */
CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
/* Calculation is started.
Provide next set of input data, until number of calculation is achieved */
for (index = (NbCalc - 1U); index > 0U; index--)
{
/* Write of input data in Write Data register, and increment input buffer pointer */
CORDIC_WriteInDataIncrementPtr(hcordic, &p_tmp_in_buff);
/* Read output data from Read Data register, and increment output buffer pointer
The reading is performed in Zero-Overhead mode:
reading is ordered immediately without waiting result ready flag */
CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
/* Check for the Timeout */
if (Timeout != HAL_MAX_DELAY)
{
if ((HAL_GetTick() - tickstart) > Timeout)
{
/* Set CORDIC error code */
hcordic->ErrorCode = HAL_CORDIC_ERROR_TIMEOUT;
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Return function status */
return HAL_ERROR;
}
}
}
/* Read output data from Read Data register, and increment output buffer pointer
The reading is performed in Zero-Overhead mode:
reading is ordered immediately without waiting result ready flag */
CORDIC_ReadOutDataIncrementPtr(hcordic, &p_tmp_out_buff);
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Return function status */
return HAL_OK;
}
else
{
/* Set CORDIC error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
/* Return function status */
return HAL_ERROR;
}
}
/**
* @brief Carry out data of CORDIC processing in interrupt mode,
* according to the existing CORDIC configuration.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module.
* @param pInBuff Pointer to buffer containing input data for CORDIC processing.
* @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
* @param NbCalc Number of CORDIC calculation to process.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_Calculate_IT(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
uint32_t NbCalc)
{
const int32_t *tmp_pInBuff = pInBuff;
/* Check parameters setting */
if ((pInBuff == NULL) || (pOutBuff == NULL) || (NbCalc == 0U))
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
/* Return error status */
return HAL_ERROR;
}
/* Check handle state is ready */
if (hcordic->State == HAL_CORDIC_STATE_READY)
{
/* Reset CORDIC error code */
hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_BUSY;
/* Store the buffers addresses and number of calculations in handle,
provisioning initial write of input data that will be done */
if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
{
/* Two writes of input data are expected */
tmp_pInBuff++;
tmp_pInBuff++;
}
else
{
/* One write of input data is expected */
tmp_pInBuff++;
}
hcordic->pInBuff = tmp_pInBuff;
hcordic->pOutBuff = pOutBuff;
hcordic->NbCalcToOrder = NbCalc - 1U;
hcordic->NbCalcToGet = NbCalc;
/* Enable Result Ready Interrupt */
__HAL_CORDIC_ENABLE_IT(hcordic, CORDIC_IT_IEN);
/* Set back pointer to start of input data buffer */
tmp_pInBuff = pInBuff;
/* Initiate the processing by providing input data
in the Write Data register */
WRITE_REG(hcordic->Instance->WDATA, (uint32_t)*tmp_pInBuff);
/* Check if second write of input data is expected */
if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
{
/* Increment pointer to input data */
tmp_pInBuff++;
/* Perform second write of input data */
WRITE_REG(hcordic->Instance->WDATA, (uint32_t)*tmp_pInBuff);
}
/* Return function status */
return HAL_OK;
}
else
{
/* Set CORDIC error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
/* Return function status */
return HAL_ERROR;
}
}
/**
* @brief Carry out input and/or output data of CORDIC processing in DMA mode,
* according to the existing CORDIC configuration.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module.
* @param pInBuff Pointer to buffer containing input data for CORDIC processing.
* @param pOutBuff Pointer to buffer where output data of CORDIC processing will be stored.
* @param NbCalc Number of CORDIC calculation to process.
* @param DMADirection Direction of DMA transfers.
* This parameter can be one of the following values:
* @arg @ref CORDIC_DMA_Direction CORDIC DMA direction
* @note pInBuff or pOutBuff is unused in case of unique DMADirection transfer, and can
* be set to NULL value in this case.
* @note pInBuff and pOutBuff buffers must be 32-bit aligned to ensure a correct
* DMA transfer to and from the Peripheral.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_CORDIC_Calculate_DMA(CORDIC_HandleTypeDef *hcordic, const int32_t *pInBuff, int32_t *pOutBuff,
uint32_t NbCalc, uint32_t DMADirection)
{
uint32_t sizeinbuff;
uint32_t sizeoutbuff;
uint32_t inputaddr;
uint32_t outputaddr;
/* Check the parameters */
assert_param(IS_CORDIC_DMA_DIRECTION(DMADirection));
/* Check parameters setting */
if (NbCalc == 0U)
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
/* Return error status */
return HAL_ERROR;
}
/* Check if CORDIC DMA direction "Out" is requested */
if ((DMADirection == CORDIC_DMA_DIR_OUT) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
{
/* Check parameters setting */
if (pOutBuff == NULL)
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
/* Return error status */
return HAL_ERROR;
}
}
/* Check if CORDIC DMA direction "In" is requested */
if ((DMADirection == CORDIC_DMA_DIR_IN) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
{
/* Check parameters setting */
if (pInBuff == NULL)
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_PARAM;
/* Return error status */
return HAL_ERROR;
}
}
if (hcordic->State == HAL_CORDIC_STATE_READY)
{
/* Reset CORDIC error code */
hcordic->ErrorCode = HAL_CORDIC_ERROR_NONE;
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_BUSY;
/* Get DMA direction */
hcordic->DMADirection = DMADirection;
/* Check if CORDIC DMA direction "Out" is requested */
if ((DMADirection == CORDIC_DMA_DIR_OUT) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
{
/* Set the CORDIC DMA transfer complete callback */
hcordic->hdmaOut->XferCpltCallback = CORDIC_DMAOutCplt;
/* Set the DMA error callback */
hcordic->hdmaOut->XferErrorCallback = CORDIC_DMAError;
/* Check number of output data at each calculation,
to retrieve the size of output data buffer */
if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NRES))
{
sizeoutbuff = 2U * NbCalc;
}
else
{
sizeoutbuff = NbCalc;
}
outputaddr = (uint32_t)pOutBuff;
/* Enable the DMA stream managing CORDIC output data read */
if (HAL_DMA_Start_IT(hcordic->hdmaOut, (uint32_t)&hcordic->Instance->RDATA, outputaddr, sizeoutbuff) != HAL_OK)
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA;
/* Return error status */
return HAL_ERROR;
}
/* Enable output data Read DMA requests */
SET_BIT(hcordic->Instance->CSR, CORDIC_DMA_REN);
}
/* Check if CORDIC DMA direction "In" is requested */
if ((DMADirection == CORDIC_DMA_DIR_IN) || (DMADirection == CORDIC_DMA_DIR_IN_OUT))
{
/* Set the CORDIC DMA transfer complete callback */
hcordic->hdmaIn->XferCpltCallback = CORDIC_DMAInCplt;
/* Set the DMA error callback */
hcordic->hdmaIn->XferErrorCallback = CORDIC_DMAError;
/* Check number of input data expected for each calculation,
to retrieve the size of input data buffer */
if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
{
sizeinbuff = 2U * NbCalc;
}
else
{
sizeinbuff = NbCalc;
}
inputaddr = (uint32_t)pInBuff;
/* Enable the DMA stream managing CORDIC input data write */
if (HAL_DMA_Start_IT(hcordic->hdmaIn, inputaddr, (uint32_t)&hcordic->Instance->WDATA, sizeinbuff) != HAL_OK)
{
/* Update the error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA;
/* Return error status */
return HAL_ERROR;
}
/* Enable input data Write DMA request */
SET_BIT(hcordic->Instance->CSR, CORDIC_DMA_WEN);
}
/* Return function status */
return HAL_OK;
}
else
{
/* Set CORDIC error code */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_NOT_READY;
/* Return function status */
return HAL_ERROR;
}
}
/**
* @}
*/
/** @defgroup CORDIC_Exported_Functions_Group3 Callback functions
* @brief Callback functions.
*
@verbatim
==============================================================================
##### Callback functions #####
==============================================================================
[..] This section provides Interruption and DMA callback functions:
(+) DMA or Interrupt calculate complete
(+) DMA or Interrupt error
@endverbatim
* @{
*/
/**
* @brief CORDIC error callback.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @retval None
*/
__weak void HAL_CORDIC_ErrorCallback(CORDIC_HandleTypeDef *hcordic)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hcordic);
/* NOTE : This function should not be modified; when the callback is needed,
the HAL_CORDIC_ErrorCallback can be implemented in the user file
*/
}
/**
* @brief CORDIC calculate complete callback.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @retval None
*/
__weak void HAL_CORDIC_CalculateCpltCallback(CORDIC_HandleTypeDef *hcordic)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hcordic);
/* NOTE : This function should not be modified; when the callback is needed,
the HAL_CORDIC_CalculateCpltCallback can be implemented in the user file
*/
}
/**
* @}
*/
/** @defgroup CORDIC_Exported_Functions_Group4 IRQ handler management
* @brief IRQ handler.
*
@verbatim
==============================================================================
##### IRQ handler management #####
==============================================================================
[..] This section provides IRQ handler function.
@endverbatim
* @{
*/
/**
* @brief Handle CORDIC interrupt request.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @retval None
*/
void HAL_CORDIC_IRQHandler(CORDIC_HandleTypeDef *hcordic)
{
/* Check if calculation complete interrupt is enabled and if result ready
flag is raised */
if (__HAL_CORDIC_GET_IT_SOURCE(hcordic, CORDIC_IT_IEN) != 0U)
{
if (__HAL_CORDIC_GET_FLAG(hcordic, CORDIC_FLAG_RRDY) != 0U)
{
/* Decrement number of calculations to get */
hcordic->NbCalcToGet--;
/* Read output data from Read Data register, and increment output buffer pointer */
CORDIC_ReadOutDataIncrementPtr(hcordic, &(hcordic->pOutBuff));
/* Check if calculations are still to be ordered */
if (hcordic->NbCalcToOrder > 0U)
{
/* Decrement number of calculations to order */
hcordic->NbCalcToOrder--;
/* Continue the processing by providing another write of input data
in the Write Data register, and increment input buffer pointer */
CORDIC_WriteInDataIncrementPtr(hcordic, &(hcordic->pInBuff));
}
/* Check if all calculations results are got */
if (hcordic->NbCalcToGet == 0U)
{
/* Disable Result Ready Interrupt */
__HAL_CORDIC_DISABLE_IT(hcordic, CORDIC_IT_IEN);
/* Change the CORDIC state */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Call calculation complete callback */
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
/*Call registered callback*/
hcordic->CalculateCpltCallback(hcordic);
#else
/*Call legacy weak (surcharged) callback*/
HAL_CORDIC_CalculateCpltCallback(hcordic);
#endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
}
}
}
}
/**
* @}
*/
/** @defgroup CORDIC_Exported_Functions_Group5 Peripheral State functions
* @brief Peripheral State functions.
*
@verbatim
==============================================================================
##### Peripheral State functions #####
==============================================================================
[..]
This subsection permits to get in run-time the status of the peripheral.
@endverbatim
* @{
*/
/**
* @brief Return the CORDIC handle state.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @retval HAL state
*/
HAL_CORDIC_StateTypeDef HAL_CORDIC_GetState(const CORDIC_HandleTypeDef *hcordic)
{
/* Return CORDIC handle state */
return hcordic->State;
}
/**
* @brief Return the CORDIC peripheral error.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module
* @note The returned error is a bit-map combination of possible errors
* @retval Error bit-map
*/
uint32_t HAL_CORDIC_GetError(const CORDIC_HandleTypeDef *hcordic)
{
/* Return CORDIC error code */
return hcordic->ErrorCode;
}
/**
* @}
*/
/**
* @}
*/
/** @addtogroup CORDIC_Private_Functions
* @{
*/
/**
* @brief Write input data for CORDIC processing, and increment input buffer pointer.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module.
* @param ppInBuff Pointer to pointer to input buffer.
* @retval none
*/
static void CORDIC_WriteInDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, const int32_t **ppInBuff)
{
/* First write of input data in the Write Data register */
WRITE_REG(hcordic->Instance->WDATA, (uint32_t) **ppInBuff);
/* Increment input data pointer */
(*ppInBuff)++;
/* Check if second write of input data is expected */
if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NARGS))
{
/* Second write of input data in the Write Data register */
WRITE_REG(hcordic->Instance->WDATA, (uint32_t) **ppInBuff);
/* Increment input data pointer */
(*ppInBuff)++;
}
}
/**
* @brief Read output data of CORDIC processing, and increment output buffer pointer.
* @param hcordic pointer to a CORDIC_HandleTypeDef structure that contains
* the configuration information for CORDIC module.
* @param ppOutBuff Pointer to pointer to output buffer.
* @retval none
*/
static void CORDIC_ReadOutDataIncrementPtr(const CORDIC_HandleTypeDef *hcordic, int32_t **ppOutBuff)
{
/* First read of output data from the Read Data register */
**ppOutBuff = (int32_t)READ_REG(hcordic->Instance->RDATA);
/* Increment output data pointer */
(*ppOutBuff)++;
/* Check if second read of output data is expected */
if (HAL_IS_BIT_SET(hcordic->Instance->CSR, CORDIC_CSR_NRES))
{
/* Second read of output data from the Read Data register */
**ppOutBuff = (int32_t)READ_REG(hcordic->Instance->RDATA);
/* Increment output data pointer */
(*ppOutBuff)++;
}
}
/**
* @brief DMA CORDIC Input Data process complete callback.
* @param hdma DMA handle.
* @retval None
*/
static void CORDIC_DMAInCplt(DMA_HandleTypeDef *hdma)
{
CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
/* Disable the DMA transfer for input request */
CLEAR_BIT(hcordic->Instance->CSR, CORDIC_DMA_WEN);
/* Check if DMA direction is CORDIC Input only (no DMA for CORDIC Output) */
if (hcordic->DMADirection == CORDIC_DMA_DIR_IN)
{
/* Change the CORDIC DMA direction to none */
hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
/* Change the CORDIC state to ready */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Call calculation complete callback */
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
/*Call registered callback*/
hcordic->CalculateCpltCallback(hcordic);
#else
/*Call legacy weak (surcharged) callback*/
HAL_CORDIC_CalculateCpltCallback(hcordic);
#endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
}
}
/**
* @brief DMA CORDIC Output Data process complete callback.
* @param hdma DMA handle.
* @retval None
*/
static void CORDIC_DMAOutCplt(DMA_HandleTypeDef *hdma)
{
CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
/* Disable the DMA transfer for output request */
CLEAR_BIT(hcordic->Instance->CSR, CORDIC_DMA_REN);
/* Change the CORDIC DMA direction to none */
hcordic->DMADirection = CORDIC_DMA_DIR_NONE;
/* Change the CORDIC state to ready */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Call calculation complete callback */
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
/*Call registered callback*/
hcordic->CalculateCpltCallback(hcordic);
#else
/*Call legacy weak (surcharged) callback*/
HAL_CORDIC_CalculateCpltCallback(hcordic);
#endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
}
/**
* @brief DMA CORDIC communication error callback.
* @param hdma DMA handle.
* @retval None
*/
static void CORDIC_DMAError(DMA_HandleTypeDef *hdma)
{
CORDIC_HandleTypeDef *hcordic = (CORDIC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
/* Set CORDIC handle state to error */
hcordic->State = HAL_CORDIC_STATE_READY;
/* Set CORDIC handle error code to DMA error */
hcordic->ErrorCode |= HAL_CORDIC_ERROR_DMA;
/* Call user callback */
#if USE_HAL_CORDIC_REGISTER_CALLBACKS == 1
/*Call registered callback*/
hcordic->ErrorCallback(hcordic);
#else
/*Call legacy weak (surcharged) callback*/
HAL_CORDIC_ErrorCallback(hcordic);
#endif /* USE_HAL_CORDIC_REGISTER_CALLBACKS */
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* HAL_CORDIC_MODULE_ENABLED */
#endif /* CORDIC */
|