2626#include "dev_spi.h"
2727#include "board.h"
2828#include "embARC_error.h"
29+ //#define DEBUG
2930#include "embARC_debug.h"
31+ #include "arc_exception.h"
3032
3133/**
3234 * Global Variables
3335 */
3436#define RSI_CHECK_EXP (EXPR , ERROR_CODE ) CHECK_EXP(EXPR, ercd, ERROR_CODE, error_exit)
3537
36- // int32_t rsi_spi_open(uint32_t freq, uint32_t clk_mode)
37- // {
38- // int32_t ercd = E_OK;
39- // DEV_SPI_PTR rsi_spi_ptr;
40-
41- // rsi_spi_ptr = spi_get_dev(BOARD_RSI_SPI_ID);
42- // RSI_CHECK_EXP(rsi_spi_ptr != NULL, E_OBJ);
43-
44- // DBG("rsi_spi_open DEV_MASTER_MODE= 0x%x (%d),freq= 0x%x (%d) \r\n", DEV_MASTER_MODE, DEV_MASTER_MODE, freq, freq);
45- // ercd = rsi_spi_ptr->spi_open(DEV_MASTER_MODE, freq);
46- // if ((ercd == E_OPNED) || (ercd == E_OK)) {
47- // ercd = rsi_spi_ptr->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(clk_mode));
48- // }
49- // error_exit:
50- // return ercd;
51- // }
52-
5338int32_t rsi_spi_close (void )
5439{
5540 int32_t ercd = E_OK ;
@@ -76,56 +61,27 @@ int32_t rsi_spi_close(void)
7661 * @section description
7762 * This API is used to tranfer/receive data to the Wi-Fi module through the SPI interface.
7863 */
79- int16_t rsi_spi_transfer (uint8_t * tx_buff , uint8_t * rx_buff , uint16_t transfer_length ,uint8_t mode )
64+ int16_t rsi_spi_transfer (uint8_t * tx_buff , uint8_t * rx_buff , uint16_t transfer_length , uint8_t mode )
8065{
8166 int32_t ercd = E_OK ;
82- uint32_t tx_cnt = transfer_length ;
83- uint32_t rx_cnt = transfer_length ;
8467 uint32_t cs_line = BOARD_RSI_SPI_CS ;
8568 DEV_SPI_PTR rsi_spi_ptr = spi_get_dev (BOARD_RSI_SPI_ID );
8669 RSI_CHECK_EXP (rsi_spi_ptr != NULL , E_OBJ );
8770
8871 if (mode != RSI_MODE_8BIT ){
8972 DBG ("rsi_spi_transfer mode = %d\r\n" , mode );
9073 }
91- if (tx_buff == NULL ){
92- tx_cnt = 0 ;
93- }
94- if (rx_buff == NULL ){
95- rx_cnt = 0 ;
96- }
97- // //! Assert the chip select pin
98- // rsi_spi_cs(1);
99-
100- // for(i=0; i<transfer_length; i++)
101- // {
102- // //! Transfer the data
103- // if(tx_buff!=NULL){
104- // ercd = rsi_spi_ptr -> spi_write(tx_buff+i, 1);
105- // RSI_CHECK_EXP(ercd >= E_OK, ercd);
106- // } else {
107- // //tx_buff is NULL, send dummy data instead
108- // ercd = rsi_spi_ptr -> spi_write(0x00, 1);
109- // }
110- // //! Receive the data
111- // if(rx_buff!=NULL){
112- // ercd = rsi_spi_ptr -> spi_read(rx_buff+i, 1);
113- // RSI_CHECK_EXP(ercd >= E_OK, ercd);
114- // }
115- // }
116-
117- // //! Deassert the chip select pin
118- // rsi_spi_cs(0);
119- // ercd = E_OK;
12074
12175 DEV_SPI_TRANSFER spi_xfer ;
12276 /* Master and Slave transmit */
123- DEV_SPI_XFER_SET_TXBUF (& spi_xfer , tx_buff , 0 , tx_cnt );
124- DEV_SPI_XFER_SET_RXBUF (& spi_xfer , rx_buff , 0 , rx_cnt );
77+ DEV_SPI_XFER_SET_TXBUF (& spi_xfer , tx_buff , 0 , ( tx_buff == NULL ) ? 0 : transfer_length );
78+ DEV_SPI_XFER_SET_RXBUF (& spi_xfer , rx_buff , 0 , ( rx_buff == NULL ) ? 0 : transfer_length );
12579 DEV_SPI_XFER_SET_NEXT (& spi_xfer , NULL );
12680
12781 ercd = rsi_spi_ptr -> spi_control (SPI_CMD_MST_SEL_DEV , CONV2VOID (cs_line ));
82+ uint32_t status = cpu_lock_save ();
12883 ercd = rsi_spi_ptr -> spi_control (SPI_CMD_TRANSFER_POLLING , CONV2VOID (& spi_xfer ));
84+ cpu_unlock_restore (status );
12985 ercd = rsi_spi_ptr -> spi_control (SPI_CMD_MST_DSEL_DEV , CONV2VOID (cs_line ));
13086
13187error_exit :
0 commit comments