mirror of https://github.com/ARMmbed/mbed-os.git
Added modifications in SDK drivers needed for mbed HAL implementation.
parent
082fd409ce
commit
52b9563e56
|
@ -80,6 +80,7 @@ typedef struct
|
||||||
|
|
||||||
bool tx_done : 1;
|
bool tx_done : 1;
|
||||||
bool rx_done : 1;
|
bool rx_done : 1;
|
||||||
|
bool abort : 1;
|
||||||
} spi_control_block_t;
|
} spi_control_block_t;
|
||||||
static spi_control_block_t m_cb[SPI_COUNT];
|
static spi_control_block_t m_cb[SPI_COUNT];
|
||||||
|
|
||||||
|
@ -202,7 +203,7 @@ ret_code_t nrf_drv_spi_init(nrf_drv_spi_t const * const p_instance,
|
||||||
|
|
||||||
CODE_FOR_SPIM
|
CODE_FOR_SPIM
|
||||||
(
|
(
|
||||||
NRF_SPIM_Type * p_spim = p_instance->p_registers;
|
NRF_SPIM_Type * p_spim = (NRF_SPIM_Type * ) p_instance->p_registers;
|
||||||
nrf_spim_pins_set(p_spim, p_config->sck_pin, mosi_pin, miso_pin);
|
nrf_spim_pins_set(p_spim, p_config->sck_pin, mosi_pin, miso_pin);
|
||||||
nrf_spim_frequency_set(p_spim,
|
nrf_spim_frequency_set(p_spim,
|
||||||
(nrf_spim_frequency_t)p_config->frequency);
|
(nrf_spim_frequency_t)p_config->frequency);
|
||||||
|
@ -221,7 +222,7 @@ ret_code_t nrf_drv_spi_init(nrf_drv_spi_t const * const p_instance,
|
||||||
)
|
)
|
||||||
CODE_FOR_SPI
|
CODE_FOR_SPI
|
||||||
(
|
(
|
||||||
NRF_SPI_Type * p_spi = p_instance->p_registers;
|
NRF_SPI_Type * p_spi = (NRF_SPI_Type * ) p_instance->p_registers;
|
||||||
nrf_spi_pins_set(p_spi, p_config->sck_pin, mosi_pin, miso_pin);
|
nrf_spi_pins_set(p_spi, p_config->sck_pin, mosi_pin, miso_pin);
|
||||||
nrf_spi_frequency_set(p_spi,
|
nrf_spi_frequency_set(p_spi,
|
||||||
(nrf_spi_frequency_t)p_config->frequency);
|
(nrf_spi_frequency_t)p_config->frequency);
|
||||||
|
@ -264,7 +265,7 @@ void nrf_drv_spi_uninit(nrf_drv_spi_t const * const p_instance)
|
||||||
|
|
||||||
CODE_FOR_SPIM
|
CODE_FOR_SPIM
|
||||||
(
|
(
|
||||||
NRF_SPIM_Type * p_spim = p_instance->p_registers;
|
NRF_SPIM_Type * p_spim = (NRF_SPIM_Type * ) p_instance->p_registers;
|
||||||
if (p_cb->handler)
|
if (p_cb->handler)
|
||||||
{
|
{
|
||||||
nrf_spim_int_disable(p_spim, DISABLE_ALL);
|
nrf_spim_int_disable(p_spim, DISABLE_ALL);
|
||||||
|
@ -280,7 +281,7 @@ void nrf_drv_spi_uninit(nrf_drv_spi_t const * const p_instance)
|
||||||
)
|
)
|
||||||
CODE_FOR_SPI
|
CODE_FOR_SPI
|
||||||
(
|
(
|
||||||
NRF_SPI_Type * p_spi = p_instance->p_registers;
|
NRF_SPI_Type * p_spi = (NRF_SPI_Type * ) p_instance->p_registers;
|
||||||
if (p_cb->handler)
|
if (p_cb->handler)
|
||||||
{
|
{
|
||||||
nrf_spi_int_disable(p_spi, DISABLE_ALL);
|
nrf_spi_int_disable(p_spi, DISABLE_ALL);
|
||||||
|
@ -352,6 +353,19 @@ static bool transfer_byte(NRF_SPI_Type * p_spi, spi_control_block_t * p_cb)
|
||||||
// see how the transfer is started in the 'nrf_drv_spi_transfer'
|
// see how the transfer is started in the 'nrf_drv_spi_transfer'
|
||||||
// function.
|
// function.
|
||||||
uint16_t bytes_used = p_cb->bytes_transferred + 1;
|
uint16_t bytes_used = p_cb->bytes_transferred + 1;
|
||||||
|
|
||||||
|
if (p_cb->abort)
|
||||||
|
{
|
||||||
|
if (bytes_used < p_cb->evt.data.done.tx_length)
|
||||||
|
{
|
||||||
|
p_cb->evt.data.done.tx_length = bytes_used;
|
||||||
|
}
|
||||||
|
if (bytes_used < p_cb->evt.data.done.rx_length)
|
||||||
|
{
|
||||||
|
p_cb->evt.data.done.rx_length = bytes_used;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bytes_used < p_cb->evt.data.done.tx_length)
|
if (bytes_used < p_cb->evt.data.done.tx_length)
|
||||||
{
|
{
|
||||||
nrf_spi_txd_set(p_spi, p_cb->evt.data.done.p_tx_buffer[bytes_used]);
|
nrf_spi_txd_set(p_spi, p_cb->evt.data.done.p_tx_buffer[bytes_used]);
|
||||||
|
@ -371,8 +385,8 @@ static void spi_xfer(NRF_SPI_Type * p_spi,
|
||||||
spi_control_block_t * p_cb,
|
spi_control_block_t * p_cb,
|
||||||
nrf_drv_spi_xfer_desc_t const * p_xfer_desc)
|
nrf_drv_spi_xfer_desc_t const * p_xfer_desc)
|
||||||
{
|
{
|
||||||
p_cb->bytes_transferred = 0;
|
|
||||||
nrf_spi_int_disable(p_spi, NRF_SPI_INT_READY_MASK);
|
nrf_spi_int_disable(p_spi, NRF_SPI_INT_READY_MASK);
|
||||||
|
p_cb->bytes_transferred = 0;
|
||||||
|
|
||||||
nrf_spi_event_clear(p_spi, NRF_SPI_EVENT_READY);
|
nrf_spi_event_clear(p_spi, NRF_SPI_EVENT_READY);
|
||||||
|
|
||||||
|
@ -516,8 +530,8 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
|
||||||
{
|
{
|
||||||
spi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
|
spi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
|
||||||
ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
|
ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
|
||||||
ASSERT(p_tx_buffer != NULL || tx_buffer_length == 0);
|
ASSERT(p_xfer_desc->p_tx_buffer != NULL || p_xfer_desc->tx_length == 0);
|
||||||
ASSERT(p_rx_buffer != NULL || rx_buffer_length == 0);
|
ASSERT(p_xfer_desc->p_rx_buffer != NULL || p_xfer_desc->rx_length == 0);
|
||||||
|
|
||||||
if (p_cb->transfer_in_progress)
|
if (p_cb->transfer_in_progress)
|
||||||
{
|
{
|
||||||
|
@ -534,6 +548,7 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
|
||||||
p_cb->evt.data.done = *p_xfer_desc;
|
p_cb->evt.data.done = *p_xfer_desc;
|
||||||
p_cb->tx_done = false;
|
p_cb->tx_done = false;
|
||||||
p_cb->rx_done = false;
|
p_cb->rx_done = false;
|
||||||
|
p_cb->abort = false;
|
||||||
|
|
||||||
if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
|
if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
|
||||||
{
|
{
|
||||||
|
@ -541,7 +556,7 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
|
||||||
}
|
}
|
||||||
CODE_FOR_SPIM
|
CODE_FOR_SPIM
|
||||||
(
|
(
|
||||||
return spim_xfer(p_instance->p_registers, p_cb, p_xfer_desc, flags);
|
return spim_xfer((NRF_SPIM_Type * ) p_instance->p_registers, p_cb, p_xfer_desc, flags);
|
||||||
)
|
)
|
||||||
CODE_FOR_SPI
|
CODE_FOR_SPI
|
||||||
(
|
(
|
||||||
|
@ -550,10 +565,28 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
|
||||||
p_cb->transfer_in_progress = false;
|
p_cb->transfer_in_progress = false;
|
||||||
return NRF_ERROR_NOT_SUPPORTED;
|
return NRF_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
spi_xfer(p_instance->p_registers, p_cb, p_xfer_desc);
|
spi_xfer((NRF_SPI_Type * ) p_instance->p_registers, p_cb, p_xfer_desc);
|
||||||
return NRF_SUCCESS;
|
return NRF_SUCCESS;
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nrf_drv_spi_abort(nrf_drv_spi_t const * p_instance)
|
||||||
|
{
|
||||||
|
spi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
|
||||||
|
ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
|
||||||
|
|
||||||
|
CODE_FOR_SPIM
|
||||||
|
(
|
||||||
|
nrf_spim_task_trigger(p_spim, NRF_SPIM_TASK_STOP);
|
||||||
|
while (!nrf_spim_event_check(p_spim, NRF_SPIM_EVENT_STOPPED)) {}
|
||||||
|
p_cb->transfer_in_progress = false;
|
||||||
|
)
|
||||||
|
CODE_FOR_SPI
|
||||||
|
(
|
||||||
|
p_cb->abort = true;
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SPIM_IN_USE
|
#ifdef SPIM_IN_USE
|
||||||
static void irq_handler_spim(NRF_SPIM_Type * p_spim, spi_control_block_t * p_cb)
|
static void irq_handler_spim(NRF_SPIM_Type * p_spim, spi_control_block_t * p_cb)
|
||||||
{
|
{
|
||||||
|
|
|
@ -363,6 +363,9 @@ uint32_t nrf_drv_spi_start_task_get(nrf_drv_spi_t const * p_instance);
|
||||||
* @return END event address.
|
* @return END event address.
|
||||||
*/
|
*/
|
||||||
uint32_t nrf_drv_spi_end_event_get(nrf_drv_spi_t const * p_instance);
|
uint32_t nrf_drv_spi_end_event_get(nrf_drv_spi_t const * p_instance);
|
||||||
|
|
||||||
|
void nrf_drv_spi_abort(nrf_drv_spi_t const * p_instance);
|
||||||
|
|
||||||
#endif // NRF_DRV_SPI_H__
|
#endif // NRF_DRV_SPI_H__
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -737,6 +737,12 @@ ret_code_t nrf_drv_twi_xfer(nrf_drv_twi_t const * p_instance,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nrf_drv_twi_is_busy(nrf_drv_twi_t const * p_instance)
|
||||||
|
{
|
||||||
|
twi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
|
||||||
|
return p_cb->busy;
|
||||||
|
}
|
||||||
|
|
||||||
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
|
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
|
||||||
uint8_t address,
|
uint8_t address,
|
||||||
uint8_t const * p_data,
|
uint8_t const * p_data,
|
||||||
|
|
|
@ -342,6 +342,16 @@ ret_code_t nrf_drv_twi_xfer(nrf_drv_twi_t const * p_instance,
|
||||||
nrf_drv_twi_xfer_desc_t const * p_xfer_desc,
|
nrf_drv_twi_xfer_desc_t const * p_xfer_desc,
|
||||||
uint32_t flags);
|
uint32_t flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Function for checking the TWI driver state.
|
||||||
|
*
|
||||||
|
* @param[in] p_instance TWI instance.
|
||||||
|
*
|
||||||
|
* @retval true If the TWI driver is currently busy performing a transfer.
|
||||||
|
* @retval false If the TWI driver is ready for a new transfer.
|
||||||
|
*/
|
||||||
|
bool nrf_drv_twi_is_busy(nrf_drv_twi_t const * p_instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Function for getting the transferred data count.
|
* @brief Function for getting the transferred data count.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue