@@ -45,7 +45,7 @@ typedef struct {
45
45
return (ret_val); \
46
46
}
47
47
48
- esp_err_t spi_ram_fifo_write (spi_ram_fifo_handle_t handle , uint8_t * data , int len )
48
+ esp_err_t spi_ram_fifo_write (spi_ram_fifo_handle_t handle , uint8_t * data , int len , uint32_t timeout_ticks )
49
49
{
50
50
spi_ram_fifo_obj_t * obj = (spi_ram_fifo_obj_t * )handle ;
51
51
int n ;
@@ -69,7 +69,10 @@ esp_err_t spi_ram_fifo_write(spi_ram_fifo_handle_t handle, uint8_t *data, int le
69
69
// Not enough free room in FIFO. Wait till there's some read and try again.
70
70
obj -> overflow_num ++ ;
71
71
xSemaphoreGive (obj -> mux );
72
- xSemaphoreTake (obj -> write_sem , portMAX_DELAY );
72
+ if (pdFALSE == xSemaphoreTake (obj -> write_sem , timeout_ticks )) {
73
+ xSemaphoreGive (obj -> mux );
74
+ return ESP_ERR_TIMEOUT ;
75
+ }
73
76
} else {
74
77
//Write the data.
75
78
spi_ram_write (obj -> ram_num , obj -> start_addr + obj -> write_pos , data , n );
@@ -90,7 +93,7 @@ esp_err_t spi_ram_fifo_write(spi_ram_fifo_handle_t handle, uint8_t *data, int le
90
93
return ESP_OK ;
91
94
}
92
95
93
- esp_err_t spi_ram_fifo_read (spi_ram_fifo_handle_t handle , uint8_t * data , int len )
96
+ esp_err_t spi_ram_fifo_read (spi_ram_fifo_handle_t handle , uint8_t * data , int len , uint32_t timeout_ticks )
94
97
{
95
98
spi_ram_fifo_obj_t * obj = (spi_ram_fifo_obj_t * )handle ;
96
99
int n ;
@@ -114,7 +117,10 @@ esp_err_t spi_ram_fifo_read(spi_ram_fifo_handle_t handle, uint8_t *data, int len
114
117
// Not enough data in FIFO. Wait till there's some written and try again.
115
118
obj -> underrun_num ++ ;
116
119
xSemaphoreGive (obj -> mux );
117
- xSemaphoreTake (obj -> read_sem , portMAX_DELAY );
120
+ if (pdFALSE == xSemaphoreTake (obj -> read_sem , timeout_ticks )) {
121
+ xSemaphoreGive (obj -> mux );
122
+ return ESP_ERR_TIMEOUT ;
123
+ }
118
124
} else {
119
125
// Read the data.
120
126
spi_ram_read (obj -> ram_num , obj -> start_addr + obj -> read_pos , data , n );
0 commit comments