spi_common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <string.h>
  14. #include "driver/spi_master.h"
  15. #include "soc/gpio_sig_map.h"
  16. #include "soc/spi_reg.h"
  17. #include "soc/dport_reg.h"
  18. #include "soc/spi_struct.h"
  19. #include "rom/ets_sys.h"
  20. #include "esp_types.h"
  21. #include "esp_attr.h"
  22. #include "esp_intr.h"
  23. #include "esp_intr_alloc.h"
  24. #include "esp_log.h"
  25. #include "esp_err.h"
  26. #include "soc/soc.h"
  27. #include "soc/dport_reg.h"
  28. #include "rom/lldesc.h"
  29. #include "driver/gpio.h"
  30. #include "driver/periph_ctrl.h"
  31. #include "esp_heap_caps.h"
  32. #include "driver/spi_common.h"
  33. static const char *SPI_TAG = "spi";
  34. #define SPI_CHECK(a, str, ret_val) \
  35. if (!(a)) { \
  36. ESP_LOGE(SPI_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
  37. return (ret_val); \
  38. }
  39. typedef struct spi_device_t spi_device_t;
  40. /*
  41. Stores a bunch of per-spi-peripheral data.
  42. */
  43. typedef struct {
  44. const uint8_t spiclk_out; //GPIO mux output signals
  45. const uint8_t spiclk_in;
  46. const uint8_t spid_out;
  47. const uint8_t spiq_out;
  48. const uint8_t spiwp_out;
  49. const uint8_t spihd_out;
  50. const uint8_t spid_in; //GPIO mux input signals
  51. const uint8_t spiq_in;
  52. const uint8_t spiwp_in;
  53. const uint8_t spihd_in;
  54. const uint8_t spics_out[3]; // /CS GPIO output mux signals
  55. const uint8_t spics_in;
  56. const uint8_t spiclk_native; //IO pins of IO_MUX muxed signals
  57. const uint8_t spid_native;
  58. const uint8_t spiq_native;
  59. const uint8_t spiwp_native;
  60. const uint8_t spihd_native;
  61. const uint8_t spics0_native;
  62. const uint8_t irq; //irq source for interrupt mux
  63. const uint8_t irq_dma; //dma irq source for interrupt mux
  64. const periph_module_t module; //peripheral module, for enabling clock etc
  65. spi_dev_t *hw; //Pointer to the hardware registers
  66. } spi_signal_conn_t;
  67. /*
  68. Bunch of constants for every SPI peripheral: GPIO signals, irqs, hw addr of registers etc
  69. */
  70. static const spi_signal_conn_t io_signal[3] = {
  71. {
  72. .spiclk_out = SPICLK_OUT_IDX,
  73. .spiclk_in = SPICLK_IN_IDX,
  74. .spid_out = SPID_OUT_IDX,
  75. .spiq_out = SPIQ_OUT_IDX,
  76. .spiwp_out = SPIWP_OUT_IDX,
  77. .spihd_out = SPIHD_OUT_IDX,
  78. .spid_in = SPID_IN_IDX,
  79. .spiq_in = SPIQ_IN_IDX,
  80. .spiwp_in = SPIWP_IN_IDX,
  81. .spihd_in = SPIHD_IN_IDX,
  82. .spics_out = {SPICS0_OUT_IDX, SPICS1_OUT_IDX, SPICS2_OUT_IDX},
  83. .spics_in = SPICS0_IN_IDX,
  84. .spiclk_native = 6,
  85. .spid_native = 8,
  86. .spiq_native = 7,
  87. .spiwp_native = 10,
  88. .spihd_native = 9,
  89. .spics0_native = 11,
  90. .irq = ETS_SPI1_INTR_SOURCE,
  91. .irq_dma = ETS_SPI1_DMA_INTR_SOURCE,
  92. .module = PERIPH_SPI_MODULE,
  93. .hw = &SPI1
  94. }, {
  95. .spiclk_out = HSPICLK_OUT_IDX,
  96. .spiclk_in = HSPICLK_IN_IDX,
  97. .spid_out = HSPID_OUT_IDX,
  98. .spiq_out = HSPIQ_OUT_IDX,
  99. .spiwp_out = HSPIWP_OUT_IDX,
  100. .spihd_out = HSPIHD_OUT_IDX,
  101. .spid_in = HSPID_IN_IDX,
  102. .spiq_in = HSPIQ_IN_IDX,
  103. .spiwp_in = HSPIWP_IN_IDX,
  104. .spihd_in = HSPIHD_IN_IDX,
  105. .spics_out = {HSPICS0_OUT_IDX, HSPICS1_OUT_IDX, HSPICS2_OUT_IDX},
  106. .spics_in = HSPICS0_IN_IDX,
  107. .spiclk_native = 14,
  108. .spid_native = 13,
  109. .spiq_native = 12,
  110. .spiwp_native = 2,
  111. .spihd_native = 4,
  112. .spics0_native = 15,
  113. .irq = ETS_SPI2_INTR_SOURCE,
  114. .irq_dma = ETS_SPI2_DMA_INTR_SOURCE,
  115. .module = PERIPH_HSPI_MODULE,
  116. .hw = &SPI2
  117. }, {
  118. .spiclk_out = VSPICLK_OUT_IDX,
  119. .spiclk_in = VSPICLK_IN_IDX,
  120. .spid_out = VSPID_OUT_IDX,
  121. .spiq_out = VSPIQ_OUT_IDX,
  122. .spiwp_out = VSPIWP_OUT_IDX,
  123. .spihd_out = VSPIHD_OUT_IDX,
  124. .spid_in = VSPID_IN_IDX,
  125. .spiq_in = VSPIQ_IN_IDX,
  126. .spiwp_in = VSPIWP_IN_IDX,
  127. .spihd_in = VSPIHD_IN_IDX,
  128. .spics_out = {VSPICS0_OUT_IDX, VSPICS1_OUT_IDX, VSPICS2_OUT_IDX},
  129. .spics_in = VSPICS0_IN_IDX,
  130. .spiclk_native = 18,
  131. .spid_native = 23,
  132. .spiq_native = 19,
  133. .spiwp_native = 22,
  134. .spihd_native = 21,
  135. .spics0_native = 5,
  136. .irq = ETS_SPI3_INTR_SOURCE,
  137. .irq_dma = ETS_SPI3_DMA_INTR_SOURCE,
  138. .module = PERIPH_VSPI_MODULE,
  139. .hw = &SPI3
  140. }
  141. };
  142. #define DMA_CHANNEL_ENABLED(dma_chan) (BIT(dma_chan-1))
  143. //Periph 1 is 'claimed' by SPI flash code.
  144. static bool spi_periph_claimed[3] = {true, false, false};
  145. static uint8_t spi_dma_chan_enabled = 0;
  146. static portMUX_TYPE spi_dma_spinlock = portMUX_INITIALIZER_UNLOCKED;
  147. //Returns true if this peripheral is successfully claimed, false if otherwise.
  148. bool spicommon_periph_claim(spi_host_device_t host)
  149. {
  150. bool ret = __sync_bool_compare_and_swap(&spi_periph_claimed[host], false, true);
  151. if (ret) periph_module_enable(io_signal[host].module);
  152. return ret;
  153. }
  154. //Returns true if this peripheral is successfully freed, false if otherwise.
  155. bool spicommon_periph_free(spi_host_device_t host)
  156. {
  157. bool ret = __sync_bool_compare_and_swap(&spi_periph_claimed[host], true, false);
  158. if (ret) periph_module_disable(io_signal[host].module);
  159. return ret;
  160. }
  161. int spicommon_irqsource_for_host(spi_host_device_t host)
  162. {
  163. return io_signal[host].irq;
  164. }
  165. spi_dev_t *spicommon_hw_for_host(spi_host_device_t host)
  166. {
  167. return io_signal[host].hw;
  168. }
  169. bool spicommon_dma_chan_claim (int dma_chan)
  170. {
  171. bool ret = false;
  172. assert( dma_chan == 1 || dma_chan == 2 );
  173. portENTER_CRITICAL(&spi_dma_spinlock);
  174. if ( !(spi_dma_chan_enabled & DMA_CHANNEL_ENABLED(dma_chan)) ) {
  175. // get the channel only when it's not claimed yet.
  176. spi_dma_chan_enabled |= DMA_CHANNEL_ENABLED(dma_chan);
  177. ret = true;
  178. }
  179. periph_module_enable( PERIPH_SPI_DMA_MODULE );
  180. portEXIT_CRITICAL(&spi_dma_spinlock);
  181. return ret;
  182. }
  183. bool spicommon_dma_chan_free(int dma_chan)
  184. {
  185. assert( dma_chan == 1 || dma_chan == 2 );
  186. assert( spi_dma_chan_enabled & DMA_CHANNEL_ENABLED(dma_chan) );
  187. portENTER_CRITICAL(&spi_dma_spinlock);
  188. spi_dma_chan_enabled &= ~DMA_CHANNEL_ENABLED(dma_chan);
  189. if ( spi_dma_chan_enabled == 0 ) {
  190. //disable the DMA only when all the channels are freed.
  191. periph_module_disable( PERIPH_SPI_DMA_MODULE );
  192. }
  193. portEXIT_CRITICAL(&spi_dma_spinlock);
  194. return true;
  195. }
  196. /*
  197. Do the common stuff to hook up a SPI host to a bus defined by a bunch of GPIO pins. Feed it a host number and a
  198. bus config struct and it'll set up the GPIO matrix and enable the device. It will set is_native to 1 if the bus
  199. config can be done using the IOMUX instead of using the GPIO matrix.
  200. */
  201. esp_err_t spicommon_bus_initialize_io(spi_host_device_t host, const spi_bus_config_t *bus_config, int dma_chan, int flags, bool *is_native)
  202. {
  203. bool native = true;
  204. bool use_quad = (flags & SPICOMMON_BUSFLAG_QUAD) != 0;
  205. SPI_CHECK(bus_config->mosi_io_num < 0 || GPIO_IS_VALID_OUTPUT_GPIO(bus_config->mosi_io_num), "spid pin invalid", ESP_ERR_INVALID_ARG);
  206. SPI_CHECK(bus_config->sclk_io_num < 0 || GPIO_IS_VALID_OUTPUT_GPIO(bus_config->sclk_io_num), "spiclk pin invalid", ESP_ERR_INVALID_ARG);
  207. SPI_CHECK(bus_config->miso_io_num < 0 || GPIO_IS_VALID_GPIO(bus_config->miso_io_num), "spiq pin invalid", ESP_ERR_INVALID_ARG);
  208. if (use_quad) {
  209. SPI_CHECK(bus_config->quadwp_io_num < 0 || GPIO_IS_VALID_OUTPUT_GPIO(bus_config->quadwp_io_num), "spiwp pin invalid", ESP_ERR_INVALID_ARG);
  210. SPI_CHECK(bus_config->quadhd_io_num < 0 || GPIO_IS_VALID_OUTPUT_GPIO(bus_config->quadhd_io_num), "spihd pin invalid", ESP_ERR_INVALID_ARG);
  211. }
  212. //Check if the selected pins correspond to the native pins of the peripheral
  213. if (bus_config->mosi_io_num >= 0 && bus_config->mosi_io_num != io_signal[host].spid_native) native = false;
  214. if (bus_config->miso_io_num >= 0 && bus_config->miso_io_num != io_signal[host].spiq_native) native = false;
  215. if (bus_config->sclk_io_num >= 0 && bus_config->sclk_io_num != io_signal[host].spiclk_native) native = false;
  216. if (use_quad) {
  217. if (bus_config->quadwp_io_num >= 0 && bus_config->quadwp_io_num != io_signal[host].spiwp_native) native = false;
  218. if (bus_config->quadhd_io_num >= 0 && bus_config->quadhd_io_num != io_signal[host].spihd_native) native = false;
  219. }
  220. *is_native = native;
  221. if ( native ) {
  222. ESP_LOGD(SPI_TAG, "SPI%d use native pins.", host );
  223. } else {
  224. ESP_LOGD(SPI_TAG, "SPI%d use gpio matrix.", host );
  225. }
  226. if (native) {
  227. //All SPI native pin selections resolve to 1, so we put that here instead of trying to figure
  228. //out which FUNC_GPIOx_xSPIxx to grab; they all are defined to 1 anyway.
  229. if (bus_config->mosi_io_num >= 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->mosi_io_num], 1);
  230. if (bus_config->miso_io_num >= 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->miso_io_num], 1);
  231. if (use_quad && bus_config->quadwp_io_num >= 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadwp_io_num], 1);
  232. if (use_quad && bus_config->quadhd_io_num >= 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadhd_io_num], 1);
  233. if (bus_config->sclk_io_num >= 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->sclk_io_num], 1);
  234. } else {
  235. //Use GPIO
  236. if (bus_config->mosi_io_num >= 0) {
  237. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->mosi_io_num], PIN_FUNC_GPIO);
  238. gpio_set_direction(bus_config->mosi_io_num, GPIO_MODE_INPUT_OUTPUT);
  239. gpio_matrix_out(bus_config->mosi_io_num, io_signal[host].spid_out, false, false);
  240. gpio_matrix_in(bus_config->mosi_io_num, io_signal[host].spid_in, false);
  241. }
  242. if (bus_config->miso_io_num >= 0) {
  243. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->miso_io_num], PIN_FUNC_GPIO);
  244. gpio_set_direction(bus_config->miso_io_num, GPIO_MODE_INPUT_OUTPUT);
  245. gpio_matrix_out(bus_config->miso_io_num, io_signal[host].spiq_out, false, false);
  246. gpio_matrix_in(bus_config->miso_io_num, io_signal[host].spiq_in, false);
  247. }
  248. if (use_quad && bus_config->quadwp_io_num >= 0) {
  249. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadwp_io_num], PIN_FUNC_GPIO);
  250. gpio_set_direction(bus_config->quadwp_io_num, GPIO_MODE_INPUT_OUTPUT);
  251. gpio_matrix_out(bus_config->quadwp_io_num, io_signal[host].spiwp_out, false, false);
  252. gpio_matrix_in(bus_config->quadwp_io_num, io_signal[host].spiwp_in, false);
  253. }
  254. if (use_quad && bus_config->quadhd_io_num >= 0) {
  255. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadhd_io_num], PIN_FUNC_GPIO);
  256. gpio_set_direction(bus_config->quadhd_io_num, GPIO_MODE_INPUT_OUTPUT);
  257. gpio_matrix_out(bus_config->quadhd_io_num, io_signal[host].spihd_out, false, false);
  258. gpio_matrix_in(bus_config->quadhd_io_num, io_signal[host].spihd_in, false);
  259. }
  260. if (bus_config->sclk_io_num >= 0) {
  261. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->sclk_io_num], PIN_FUNC_GPIO);
  262. gpio_set_direction(bus_config->sclk_io_num, GPIO_MODE_INPUT_OUTPUT);
  263. gpio_matrix_out(bus_config->sclk_io_num, io_signal[host].spiclk_out, false, false);
  264. gpio_matrix_in(bus_config->sclk_io_num, io_signal[host].spiclk_in, false);
  265. }
  266. }
  267. //Select DMA channel.
  268. DPORT_SET_PERI_REG_BITS(DPORT_SPI_DMA_CHAN_SEL_REG, 3, dma_chan, (host * 2));
  269. return ESP_OK;
  270. }
  271. //Find any pin with output muxed to ``func`` and reset it to GPIO
  272. static void reset_func_to_gpio(int func)
  273. {
  274. for (int x = 0; x < GPIO_PIN_COUNT; x++) {
  275. if (GPIO_IS_VALID_GPIO(x) && (READ_PERI_REG(GPIO_FUNC0_OUT_SEL_CFG_REG + (x * 4))&GPIO_FUNC0_OUT_SEL_M) == func) {
  276. gpio_matrix_out(x, SIG_GPIO_OUT_IDX, false, false);
  277. }
  278. }
  279. }
  280. esp_err_t spicommon_bus_free_io(spi_host_device_t host)
  281. {
  282. if (REG_GET_FIELD(GPIO_PIN_MUX_REG[io_signal[host].spid_native], MCU_SEL) == 1) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_signal[host].spid_native], PIN_FUNC_GPIO);
  283. if (REG_GET_FIELD(GPIO_PIN_MUX_REG[io_signal[host].spiq_native], MCU_SEL) == 1) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_signal[host].spiq_native], PIN_FUNC_GPIO);
  284. if (REG_GET_FIELD(GPIO_PIN_MUX_REG[io_signal[host].spiclk_native], MCU_SEL) == 1) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_signal[host].spiclk_native], PIN_FUNC_GPIO);
  285. if (REG_GET_FIELD(GPIO_PIN_MUX_REG[io_signal[host].spiwp_native], MCU_SEL) == 1) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_signal[host].spiwp_native], PIN_FUNC_GPIO);
  286. if (REG_GET_FIELD(GPIO_PIN_MUX_REG[io_signal[host].spihd_native], MCU_SEL) == 1) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_signal[host].spihd_native], PIN_FUNC_GPIO);
  287. reset_func_to_gpio(io_signal[host].spid_out);
  288. reset_func_to_gpio(io_signal[host].spiq_out);
  289. reset_func_to_gpio(io_signal[host].spiclk_out);
  290. reset_func_to_gpio(io_signal[host].spiwp_out);
  291. reset_func_to_gpio(io_signal[host].spihd_out);
  292. return ESP_OK;
  293. }
  294. void spicommon_cs_initialize(spi_host_device_t host, int cs_io_num, int cs_num, int force_gpio_matrix)
  295. {
  296. if (!force_gpio_matrix && cs_io_num == io_signal[host].spics0_native && cs_num == 0) {
  297. //The cs0s for all SPI peripherals map to pin mux source 1, so we use that instead of a define.
  298. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[cs_io_num], 1);
  299. } else {
  300. //Use GPIO matrix
  301. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[cs_io_num], PIN_FUNC_GPIO);
  302. gpio_matrix_out(cs_io_num, io_signal[host].spics_out[cs_num], false, false);
  303. if (cs_num == 0) gpio_matrix_in(cs_io_num, io_signal[host].spics_in, false);
  304. }
  305. }
  306. void spicommon_cs_free(spi_host_device_t host, int cs_io_num)
  307. {
  308. if (cs_io_num == 0 && REG_GET_FIELD(GPIO_PIN_MUX_REG[io_signal[host].spics0_native], MCU_SEL) == 1) {
  309. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_signal[host].spics0_native], PIN_FUNC_GPIO);
  310. }
  311. reset_func_to_gpio(io_signal[host].spics_out[cs_io_num]);
  312. }
  313. //Set up a list of dma descriptors. dmadesc is an array of descriptors. Data is the buffer to point to.
  314. void spicommon_setup_dma_desc_links(lldesc_t *dmadesc, int len, const uint8_t *data, bool isrx)
  315. {
  316. int n = 0;
  317. while (len) {
  318. int dmachunklen = len;
  319. if (dmachunklen > SPI_MAX_DMA_LEN) dmachunklen = SPI_MAX_DMA_LEN;
  320. if (isrx) {
  321. //Receive needs DMA length rounded to next 32-bit boundary
  322. dmadesc[n].size = (dmachunklen + 3) & (~3);
  323. dmadesc[n].length = (dmachunklen + 3) & (~3);
  324. } else {
  325. dmadesc[n].size = dmachunklen;
  326. dmadesc[n].length = dmachunklen;
  327. }
  328. dmadesc[n].buf = (uint8_t *)data;
  329. dmadesc[n].eof = 0;
  330. dmadesc[n].sosf = 0;
  331. dmadesc[n].owner = 1;
  332. dmadesc[n].qe.stqe_next = &dmadesc[n + 1];
  333. len -= dmachunklen;
  334. data += dmachunklen;
  335. n++;
  336. }
  337. dmadesc[n - 1].eof = 1; //Mark last DMA desc as end of stream.
  338. dmadesc[n - 1].qe.stqe_next = NULL;
  339. }
  340. /*
  341. Code for workaround for DMA issue in ESP32 v0/v1 silicon
  342. */
  343. static volatile int dmaworkaround_channels_busy[2] = {0, 0};
  344. static dmaworkaround_cb_t dmaworkaround_cb;
  345. static void *dmaworkaround_cb_arg;
  346. static portMUX_TYPE dmaworkaround_mux = portMUX_INITIALIZER_UNLOCKED;
  347. static int dmaworkaround_waiting_for_chan = 0;
  348. bool IRAM_ATTR spicommon_dmaworkaround_req_reset(int dmachan, dmaworkaround_cb_t cb, void *arg)
  349. {
  350. int otherchan = (dmachan == 1) ? 2 : 1;
  351. bool ret;
  352. portENTER_CRITICAL(&dmaworkaround_mux);
  353. if (dmaworkaround_channels_busy[otherchan-1]) {
  354. //Other channel is busy. Call back when it's done.
  355. dmaworkaround_cb = cb;
  356. dmaworkaround_cb_arg = arg;
  357. dmaworkaround_waiting_for_chan = otherchan;
  358. ret = false;
  359. } else {
  360. //Reset DMA
  361. periph_module_reset( PERIPH_SPI_DMA_MODULE );
  362. ret = true;
  363. }
  364. portEXIT_CRITICAL(&dmaworkaround_mux);
  365. return ret;
  366. }
  367. bool IRAM_ATTR spicommon_dmaworkaround_reset_in_progress()
  368. {
  369. return (dmaworkaround_waiting_for_chan != 0);
  370. }
  371. void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan)
  372. {
  373. portENTER_CRITICAL(&dmaworkaround_mux);
  374. dmaworkaround_channels_busy[dmachan-1] = 0;
  375. if (dmaworkaround_waiting_for_chan == dmachan) {
  376. //Reset DMA
  377. periph_module_reset( PERIPH_SPI_DMA_MODULE );
  378. dmaworkaround_waiting_for_chan = 0;
  379. //Call callback
  380. dmaworkaround_cb(dmaworkaround_cb_arg);
  381. }
  382. portEXIT_CRITICAL(&dmaworkaround_mux);
  383. }
  384. void IRAM_ATTR spicommon_dmaworkaround_transfer_active(int dmachan)
  385. {
  386. portENTER_CRITICAL(&dmaworkaround_mux);
  387. dmaworkaround_channels_busy[dmachan-1] = 1;
  388. portEXIT_CRITICAL(&dmaworkaround_mux);
  389. }