1
+ #include <esp_types.h>
2
+ #include <stdio.h>
3
+
4
+ #include "freertos/FreeRTOS.h"
5
+ #include "freertos/task.h"
6
+ #include "freertos/semphr.h"
7
+ #include "freertos/queue.h"
8
+ #include "freertos/xtensa_api.h"
9
+ #include "esp_intr_alloc.h"
10
+ #include "xtensa/hal.h"
11
+ #include "unity.h"
12
+ #include "soc/cpu.h"
13
+ #include "test_utils.h"
14
+ #include "math.h"
15
+
16
+ #define SW_ISR_LEVEL_1 7
17
+
18
+ struct fp_test_context {
19
+ SemaphoreHandle_t sync ;
20
+ float expected ;
21
+ };
22
+
23
+ static void software_isr (void * arg ) {
24
+ (void )arg ;
25
+ BaseType_t yield ;
26
+ xt_set_intclear (1 << SW_ISR_LEVEL_1 );
27
+
28
+ struct fp_test_context * ctx = (struct fp_test_context * )arg ;
29
+
30
+ for (int i = 0 ; i < 10 ; i ++ ) {
31
+ ctx -> expected = ctx -> expected * 2.0f ;
32
+ }
33
+
34
+ xSemaphoreGiveFromISR (ctx -> sync , & yield );
35
+ if (yield ) {
36
+ portYIELD_FROM_ISR ();
37
+ }
38
+ }
39
+
40
+
41
+ TEST_CASE ("Floating point usage in ISR test" , "[freertos] [ignore]" )
42
+ {
43
+ struct fp_test_context ctx ;
44
+
45
+ intr_handle_t handle ;
46
+ esp_err_t err = esp_intr_alloc (ETS_INTERNAL_SW0_INTR_SOURCE , ESP_INTR_FLAG_LEVEL1 , & software_isr , & ctx , & handle );
47
+ TEST_ASSERT_EQUAL_HEX32 (ESP_OK , err );
48
+
49
+ ctx .sync = xSemaphoreCreateBinary ();
50
+ TEST_ASSERT (ctx .sync != NULL );
51
+ ctx .expected = 1.0f ;
52
+
53
+ xt_set_intset (1 << SW_ISR_LEVEL_1 );
54
+ xSemaphoreTake (ctx .sync , portMAX_DELAY );
55
+
56
+ esp_intr_free (handle );
57
+ vSemaphoreDelete (ctx .sync );
58
+
59
+ TEST_ASSERT_FLOAT_WITHIN (0.1f , ctx .expected , 1024.0f );
60
+ }
0 commit comments