spi_common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. //All SPI native pin selections resolve to 1, so we put that here instead of trying to figure
  223. //out which FUNC_GPIOx_xSPIxx to grab; they all are defined to 1 anyway.
  224. if (bus_config->mosi_io_num > 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->mosi_io_num], 1);
  225. if (bus_config->miso_io_num > 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->miso_io_num], 1);
  226. if (use_quad && bus_config->quadwp_io_num > 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadwp_io_num], 1);
  227. if (use_quad && bus_config->quadhd_io_num > 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadhd_io_num], 1);
  228. if (bus_config->sclk_io_num > 0) PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->sclk_io_num], 1);
  229. } else {
  230. //Use GPIO
  231. if (bus_config->mosi_io_num > 0) {
  232. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->mosi_io_num], PIN_FUNC_GPIO);
  233. gpio_set_direction(bus_config->mosi_io_num, GPIO_MODE_INPUT_OUTPUT);
  234. gpio_matrix_out(bus_config->mosi_io_num, io_signal[host].spid_out, false, false);
  235. gpio_matrix_in(bus_config->mosi_io_num, io_signal[host].spid_in, false);
  236. }
  237. if (bus_config->miso_io_num > 0) {
  238. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->miso_io_num], PIN_FUNC_GPIO);
  239. gpio_set_direction(bus_config->miso_io_num, GPIO_MODE_INPUT_OUTPUT);
  240. gpio_matrix_out(bus_config->miso_io_num, io_signal[host].spiq_out, false, false);
  241. gpio_matrix_in(bus_config->miso_io_num, io_signal[host].spiq_in, false);
  242. }
  243. if (use_quad && bus_config->quadwp_io_num > 0) {
  244. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadwp_io_num], PIN_FUNC_GPIO);
  245. gpio_set_direction(bus_config->quadwp_io_num, GPIO_MODE_INPUT_OUTPUT);
  246. gpio_matrix_out(bus_config->quadwp_io_num, io_signal[host].spiwp_out, false, false);
  247. gpio_matrix_in(bus_config->quadwp_io_num, io_signal[host].spiwp_in, false);
  248. }
  249. if (use_quad && bus_config->quadhd_io_num > 0) {
  250. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->quadhd_io_num], PIN_FUNC_GPIO);
  251. gpio_set_direction(bus_config->quadhd_io_num, GPIO_MODE_INPUT_OUTPUT);
  252. gpio_matrix_out(bus_config->quadhd_io_num, io_signal[host].spihd_out, false, false);
  253. gpio_matrix_in(bus_config->quadhd_io_num, io_signal[host].spihd_in, false);
  254. }
  255. if (bus_config->sclk_io_num > 0) {
  256. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[bus_config->sclk_io_num], PIN_FUNC_GPIO);
  257. gpio_set_direction(bus_config->sclk_io_num, GPIO_MODE_INPUT_OUTPUT);
  258. gpio_matrix_out(bus_config->sclk_io_num, io_signal[host].spiclk_out, false, false);
  259. gpio_matrix_in(bus_config->sclk_io_num, io_signal[host].spiclk_in, false);
  260. }
  261. }
  262. //Select DMA channel.
  263. DPORT_SET_PERI_REG_BITS(DPORT_SPI_DMA_CHAN_SEL_REG, 3, dma_chan, (host * 2));
  264. return ESP_OK;
  265. }
  266. //Find any pin with output muxed to ``func`` and reset it to GPIO
  267. static void reset_func_to_gpio(int func)
  268. {
  269. for (int x = 0; x < GPIO_PIN_COUNT; x++) {
  270. if (GPIO_IS_VALID_GPIO(x) && (READ_PERI_REG(GPIO_FUNC0_OUT_SEL_CFG_REG + (x * 4))&GPIO_FUNC0_OUT_SEL_M) == func) {
  271. gpio_matrix_out(x, SIG_GPIO_OUT_IDX, false, false);
  272. }
  273. }
  274. }
  275. esp_err_t spicommon_bus_free_io(spi_host_device_t host)
  276. {
  277. 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);
  278. 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);
  279. 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);
  280. 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);
  281. 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);
  282. reset_func_to_gpio(io_signal[host].spid_out);
  283. reset_func_to_gpio(io_signal[host].spiq_out);
  284. reset_func_to_gpio(io_signal[host].spiclk_out);
  285. reset_func_to_gpio(io_signal[host].spiwp_out);
  286. reset_func_to_gpio(io_signal[host].spihd_out);
  287. return ESP_OK;
  288. }
  289. void spicommon_cs_initialize(spi_host_device_t host, int cs_io_num, int cs_num, int force_gpio_matrix)
  290. {
  291. if (!force_gpio_matrix && cs_io_num == io_signal[host].spics0_native && cs_num == 0) {
  292. //The cs0s for all SPI peripherals map to pin mux source 1, so we use that instead of a define.
  293. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[cs_io_num], 1);
  294. } else {
  295. //Use GPIO matrix
  296. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[cs_io_num], PIN_FUNC_GPIO);
  297. gpio_matrix_out(cs_io_num, io_signal[host].spics_out[cs_num], false, false);
  298. if (cs_num == 0) gpio_matrix_in(cs_io_num, io_signal[host].spics_in, false);
  299. }
  300. }
  301. void spicommon_cs_free(spi_host_device_t host, int cs_io_num)
  302. {
  303. if (cs_io_num == 0 && REG_GET_FIELD(GPIO_PIN_MUX_REG[io_signal[host].spics0_native], MCU_SEL) == 1) {
  304. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_signal[host].spics0_native], PIN_FUNC_GPIO);
  305. }
  306. reset_func_to_gpio(io_signal[host].spics_out[cs_io_num]);
  307. }
  308. //Set up a list of dma descriptors. dmadesc is an array of descriptors. Data is the buffer to point to.
  309. void spicommon_setup_dma_desc_links(lldesc_t *dmadesc, int len, const uint8_t *data, bool isrx)
  310. {
  311. int n = 0;
  312. while (len) {
  313. int dmachunklen = len;
  314. if (dmachunklen > SPI_MAX_DMA_LEN) dmachunklen = SPI_MAX_DMA_LEN;
  315. if (isrx) {
  316. //Receive needs DMA length rounded to next 32-bit boundary
  317. dmadesc[n].size = (dmachunklen + 3) & (~3);
  318. dmadesc[n].length = (dmachunklen + 3) & (~3);
  319. } else {
  320. dmadesc[n].size = dmachunklen;
  321. dmadesc[n].length = dmachunklen;
  322. }
  323. dmadesc[n].buf = (uint8_t *)data;
  324. dmadesc[n].eof = 0;
  325. dmadesc[n].sosf = 0;
  326. dmadesc[n].owner = 1;
  327. dmadesc[n].qe.stqe_next = &dmadesc[n + 1];
  328. len -= dmachunklen;
  329. data += dmachunklen;
  330. n++;
  331. }
  332. dmadesc[n - 1].eof = 1; //Mark last DMA desc as end of stream.
  333. dmadesc[n - 1].qe.stqe_next = NULL;
  334. }
  335. /*
  336. Code for workaround for DMA issue in ESP32 v0/v1 silicon
  337. */
  338. static volatile int dmaworkaround_channels_busy[2] = {0, 0};
  339. static dmaworkaround_cb_t dmaworkaround_cb;
  340. static void *dmaworkaround_cb_arg;
  341. static portMUX_TYPE dmaworkaround_mux = portMUX_INITIALIZER_UNLOCKED;
  342. static int dmaworkaround_waiting_for_chan = 0;
  343. bool IRAM_ATTR spicommon_dmaworkaround_req_reset(int dmachan, dmaworkaround_cb_t cb, void *arg)
  344. {
  345. int otherchan = (dmachan == 1) ? 2 : 1;
  346. bool ret;
  347. portENTER_CRITICAL(&dmaworkaround_mux);
  348. if (dmaworkaround_channels_busy[otherchan-1]) {
  349. //Other channel is busy. Call back when it's done.
  350. dmaworkaround_cb = cb;
  351. dmaworkaround_cb_arg = arg;
  352. dmaworkaround_waiting_for_chan = otherchan;
  353. ret = false;
  354. } else {
  355. //Reset DMA
  356. periph_module_reset( PERIPH_SPI_DMA_MODULE );
  357. ret = true;
  358. }
  359. portEXIT_CRITICAL(&dmaworkaround_mux);
  360. return ret;
  361. }
  362. bool IRAM_ATTR spicommon_dmaworkaround_reset_in_progress()
  363. {
  364. return (dmaworkaround_waiting_for_chan != 0);
  365. }
  366. void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan)
  367. {
  368. portENTER_CRITICAL(&dmaworkaround_mux);
  369. dmaworkaround_channels_busy[dmachan-1] = 0;
  370. if (dmaworkaround_waiting_for_chan == dmachan) {
  371. //Reset DMA
  372. periph_module_reset( PERIPH_SPI_DMA_MODULE );
  373. dmaworkaround_waiting_for_chan = 0;
  374. //Call callback
  375. dmaworkaround_cb(dmaworkaround_cb_arg);
  376. }
  377. portEXIT_CRITICAL(&dmaworkaround_mux);
  378. }
  379. void IRAM_ATTR spicommon_dmaworkaround_transfer_active(int dmachan)
  380. {
  381. portENTER_CRITICAL(&dmaworkaround_mux);
  382. dmaworkaround_channels_busy[dmachan-1] = 1;
  383. portEXIT_CRITICAL(&dmaworkaround_mux);
  384. }