Lines Matching refs:spi

88 int32_t hal_ch395_spi_init(spi_dev_t *spi)  in hal_ch395_spi_init()  argument
91 spi_config_t cfg_spi = spi->config; in hal_ch395_spi_init()
93 if (spi->port >= (sizeof(spi_ctx) / sizeof(spi_ctx_obj_t))) { in hal_ch395_spi_init()
103 pinmux_spi[0].pin = spi_ctx[spi->port].spi_pin_DI0; in hal_ch395_spi_init()
104 pinmux_spi[1].pin = spi_ctx[spi->port].spi_pin_CLK; in hal_ch395_spi_init()
105 pinmux_spi[2].pin = spi_ctx[spi->port].spi_pin_CS0; in hal_ch395_spi_init()
106 pinmux_spi[3].pin = spi_ctx[spi->port].spi_pin_DIO; in hal_ch395_spi_init()
108 pinmux_spi[0].function = spi_ctx[spi->port].spi_fun_DI0; in hal_ch395_spi_init()
109 pinmux_spi[1].function = spi_ctx[spi->port].spi_fun_CLK; in hal_ch395_spi_init()
110 pinmux_spi[2].function = spi_ctx[spi->port].spi_fun_CS0; in hal_ch395_spi_init()
111 pinmux_spi[3].function = spi_ctx[spi->port].spi_fun_DIO; in hal_ch395_spi_init()
155 ret = spi_ctx[spi->port].spi_open(&spi_cfg); in hal_ch395_spi_init()
158 TRACE("spi %d open error", spi->port); in hal_ch395_spi_init()
162 TRACE("spi %d open succ", spi->port); in hal_ch395_spi_init()
164 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) { in hal_ch395_spi_init()
165 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 1); in hal_ch395_spi_init()
168 if (!spi_ctx[spi->port].spi_dma_semaphore) in hal_ch395_spi_init()
170 …spi_ctx[spi->port].spi_dma_semaphore = osSemaphoreCreate(osSemaphore(ch395_spi1_dma_semaphore), 0); in hal_ch395_spi_init()
173 if (!spi_ctx[spi->port].spi_dma_semaphore) in hal_ch395_spi_init()
175 TRACE("spi%d_dma_semaphore create failed!", spi->port); in hal_ch395_spi_init()
179 if (!spi_ctx[spi->port].spi_mutex_id) in hal_ch395_spi_init()
181 spi_ctx[spi->port].spi_mutex_id = osMutexCreate((osMutex(ch395_spi1_mutex))); in hal_ch395_spi_init()
184 if (!spi_ctx[spi->port].spi_mutex_id) in hal_ch395_spi_init()
186 TRACE("spi%d_mutex create failed!", spi->port); in hal_ch395_spi_init()
212 int32_t hal_spi_send_ch395(spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t timeout) in hal_spi_send_ch395() argument
220 if (NULL == spi || NULL == data || 0 == size) in hal_spi_send_ch395()
226 status = osMutexWait(spi_ctx[spi->port].spi_mutex_id, osWaitForever); in hal_spi_send_ch395()
235 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_ch395()
237 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 0); in hal_spi_send_ch395()
241 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_ch395()
243 ret = spi_ctx[spi->port].spi_dma_send(data, 1, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_ch395()
244 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_ch395()
252 ret = spi_ctx[spi->port].spi_send(data, 1); in hal_spi_send_ch395()
257 TRACE("spi mode %d send fail %d, size %d", spi->config.t_mode, ret, size); in hal_spi_send_ch395()
264 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_ch395()
266 ret = spi_ctx[spi->port].spi_dma_send(data + 1, size - 1, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_ch395()
267 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_ch395()
275 ret = spi_ctx[spi->port].spi_send(data + 1, size - 1); in hal_spi_send_ch395()
280 TRACE("spi mode %d send fail %d, size %d", spi->config.t_mode, ret, size); in hal_spi_send_ch395()
288 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_ch395()
290 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 1); in hal_spi_send_ch395()
292 osMutexRelease(spi_ctx[spi->port].spi_mutex_id); in hal_spi_send_ch395()
307 int32_t hal_spi_send_ch395_sockdata(spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t ti… in hal_spi_send_ch395_sockdata() argument
315 if (NULL == spi || NULL == data || size <=4 ) in hal_spi_send_ch395_sockdata()
321 status = osMutexWait(spi_ctx[spi->port].spi_mutex_id, osWaitForever); in hal_spi_send_ch395_sockdata()
330 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_ch395_sockdata()
332 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 0); in hal_spi_send_ch395_sockdata()
336 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_ch395_sockdata()
338 ret = spi_ctx[spi->port].spi_dma_send(data, 1, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_ch395_sockdata()
339 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_ch395_sockdata()
347 ret = spi_ctx[spi->port].spi_send(data, 1); in hal_spi_send_ch395_sockdata()
352 TRACE("spi mode %d send fail %d, size %d", spi->config.t_mode, ret, size); in hal_spi_send_ch395_sockdata()
357 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_ch395_sockdata()
359 ret = spi_ctx[spi->port].spi_dma_send(data + 1, 3, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_ch395_sockdata()
360 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_ch395_sockdata()
368 ret = spi_ctx[spi->port].spi_send(data + 1, 3); in hal_spi_send_ch395_sockdata()
373 TRACE("spi mode %d send fail %d, size %d", spi->config.t_mode, ret, size); in hal_spi_send_ch395_sockdata()
378 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_ch395_sockdata()
380 ret = spi_ctx[spi->port].spi_dma_send(data + 4, size - 4, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_ch395_sockdata()
381 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_ch395_sockdata()
389 ret = spi_ctx[spi->port].spi_send(data + 4, size - 4); in hal_spi_send_ch395_sockdata()
394 TRACE("spi mode %d send fail %d, size %d", spi->config.t_mode, ret, size); in hal_spi_send_ch395_sockdata()
400 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_ch395_sockdata()
402 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 1); in hal_spi_send_ch395_sockdata()
404 osMutexRelease(spi_ctx[spi->port].spi_mutex_id); in hal_spi_send_ch395_sockdata()
409 int32_t hal_spi_send_and_recv_ch395_normal(spi_dev_t *spi, uint8_t *tx_data, uint16_t tx_size, uint… in hal_spi_send_and_recv_ch395_normal() argument
418 if (NULL == spi || NULL == tx_data || 0 == tx_size || NULL == rx_data || 0 == rx_size) in hal_spi_send_and_recv_ch395_normal()
433 status = osMutexWait(spi_ctx[spi->port].spi_mutex_id, osWaitForever); in hal_spi_send_and_recv_ch395_normal()
442 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_and_recv_ch395_normal()
444 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 0); in hal_spi_send_and_recv_ch395_normal()
449 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_and_recv_ch395_normal()
451 ret = spi_ctx[spi->port].spi_dma_send(tx_data, 1, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_and_recv_ch395_normal()
452 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_and_recv_ch395_normal()
460 ret = spi_ctx[spi->port].spi_send(tx_data, 1); in hal_spi_send_and_recv_ch395_normal()
465 TRACE("spi mode %d send fail %d, size %d", spi->config.t_mode, ret, tx_size); in hal_spi_send_and_recv_ch395_normal()
471 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_and_recv_ch395_normal()
473 ret = spi_ctx[spi->port].spi_dma_send(tx_data + 1, tx_size - 1, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_and_recv_ch395_normal()
474 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_and_recv_ch395_normal()
482 ret = spi_ctx[spi->port].spi_send(tx_data + 1, tx_size - 1); in hal_spi_send_and_recv_ch395_normal()
487 TRACE("spi mode %d send fail %d, size %d", spi->config.t_mode, ret, tx_size); in hal_spi_send_and_recv_ch395_normal()
498 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_and_recv_ch395_normal()
500 ret = spi_ctx[spi->port].spi_dma_recv(cmd, rx_data, remainder, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_and_recv_ch395_normal()
501 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_and_recv_ch395_normal()
509 ret = spi_ctx[spi->port].spi_recv(cmd, rx_data, remainder); in hal_spi_send_and_recv_ch395_normal()
516 TRACE("spi mode %d recv fail %d, size %d", spi->config.t_mode, ret, rx_size); in hal_spi_send_and_recv_ch395_normal()
523 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_and_recv_ch395_normal()
525 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 1); in hal_spi_send_and_recv_ch395_normal()
528 osMutexRelease(spi_ctx[spi->port].spi_mutex_id); in hal_spi_send_and_recv_ch395_normal()
533 int32_t hal_spi_send_and_recv_ch395_exist(spi_dev_t *spi, uint8_t *tx_data, uint16_t tx_size, uint8… in hal_spi_send_and_recv_ch395_exist() argument
541 if (NULL == spi || NULL == tx_data || 2 != tx_size || NULL == rx_data || 1 != rx_size) in hal_spi_send_and_recv_ch395_exist()
547 status = osMutexWait(spi_ctx[spi->port].spi_mutex_id, osWaitForever); in hal_spi_send_and_recv_ch395_exist()
555 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_and_recv_ch395_exist()
557 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 0); in hal_spi_send_and_recv_ch395_exist()
561 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_and_recv_ch395_exist()
563 ret = spi_ctx[spi->port].spi_dma_send(&tx_data[0], 1, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_and_recv_ch395_exist()
564 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_and_recv_ch395_exist()
572 ret = spi_ctx[spi->port].spi_send(&tx_data[0], 1); in hal_spi_send_and_recv_ch395_exist()
577 spi->config.t_mode, ret, tx_size); in hal_spi_send_and_recv_ch395_exist()
583 if (spi->config.t_mode == SPI_TRANSFER_DMA) in hal_spi_send_and_recv_ch395_exist()
585 ret = spi_ctx[spi->port].spi_dma_recv(&tx_data[1], rx_data, 1, spi_ctx[spi->port].spi_dma_irq); in hal_spi_send_and_recv_ch395_exist()
586 if (osSemaphoreWait(spi_ctx[spi->port].spi_dma_semaphore, timeout) <= 0) in hal_spi_send_and_recv_ch395_exist()
594 ret = spi_ctx[spi->port].spi_recv(&tx_data[1], rx_data, 1); in hal_spi_send_and_recv_ch395_exist()
599 if (spi_ctx[spi->port].spi_fun_CS0 == HAL_IOMUX_FUNC_AS_GPIO) in hal_spi_send_and_recv_ch395_exist()
601 hal_gpio_pin_set_dir(spi_ctx[spi->port].spi_pin_CS0, HAL_GPIO_DIR_OUT, 1); in hal_spi_send_and_recv_ch395_exist()
604 osMutexRelease(spi_ctx[spi->port].spi_mutex_id); in hal_spi_send_and_recv_ch395_exist()