Merge pull request #829 from kwagyeman/kwabena/stop_disabling_interrupts

Remove disabling interrupts
This commit is contained in:
Ibrahim Abd Elkader 2020-06-15 16:07:55 +02:00 committed by GitHub
commit 981b3bbe0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 34 deletions

View File

@ -74,12 +74,9 @@ int cambus_deinit(I2C_HandleTypeDef *i2c)
int cambus_scan(I2C_HandleTypeDef *i2c) int cambus_scan(I2C_HandleTypeDef *i2c)
{ {
for (uint8_t addr=0x09; addr<=0x77; addr++) { for (uint8_t addr=0x09; addr<=0x77; addr++) {
__disable_irq();
if (HAL_I2C_IsDeviceReady(i2c, addr << 1, 10, I2C_TIMEOUT) == HAL_OK) { if (HAL_I2C_IsDeviceReady(i2c, addr << 1, 10, I2C_TIMEOUT) == HAL_OK) {
__enable_irq();
return (addr << 1); return (addr << 1);
} }
__enable_irq();
} }
return 0; return 0;
@ -97,12 +94,10 @@ int cambus_readb(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint8_t reg_addr, uin
{ {
int ret = 0; int ret = 0;
__disable_irq();
if((HAL_I2C_Master_Transmit(i2c, slv_addr, &reg_addr, 1, I2C_TIMEOUT) != HAL_OK) if((HAL_I2C_Master_Transmit(i2c, slv_addr, &reg_addr, 1, I2C_TIMEOUT) != HAL_OK)
|| (HAL_I2C_Master_Receive (i2c, slv_addr, reg_data, 1, I2C_TIMEOUT) != HAL_OK)) { || (HAL_I2C_Master_Receive (i2c, slv_addr, reg_data, 1, I2C_TIMEOUT) != HAL_OK)) {
ret = -1; ret = -1;
} }
__enable_irq();
return ret; return ret;
} }
@ -111,47 +106,39 @@ int cambus_writeb(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint8_t reg_addr, ui
int ret=0; int ret=0;
uint8_t buf[] = {reg_addr, reg_data}; uint8_t buf[] = {reg_addr, reg_data};
__disable_irq();
if(HAL_I2C_Master_Transmit(i2c, slv_addr, buf, 2, I2C_TIMEOUT) != HAL_OK) { if(HAL_I2C_Master_Transmit(i2c, slv_addr, buf, 2, I2C_TIMEOUT) != HAL_OK) {
ret = -1; ret = -1;
} }
__enable_irq();
return ret; return ret;
} }
int cambus_readb2(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint16_t reg_addr, uint8_t *reg_data) int cambus_readb2(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint16_t reg_addr, uint8_t *reg_data)
{ {
int ret=0; int ret=0;
__disable_irq();
if (HAL_I2C_Mem_Read(i2c, slv_addr, reg_addr, if (HAL_I2C_Mem_Read(i2c, slv_addr, reg_addr,
I2C_MEMADD_SIZE_16BIT, reg_data, 1, I2C_TIMEOUT) != HAL_OK) { I2C_MEMADD_SIZE_16BIT, reg_data, 1, I2C_TIMEOUT) != HAL_OK) {
ret = -1; ret = -1;
} }
__enable_irq();
return ret; return ret;
} }
int cambus_writeb2(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint16_t reg_addr, uint8_t reg_data) int cambus_writeb2(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint16_t reg_addr, uint8_t reg_data)
{ {
int ret=0; int ret=0;
__disable_irq();
if (HAL_I2C_Mem_Write(i2c, slv_addr, reg_addr, if (HAL_I2C_Mem_Write(i2c, slv_addr, reg_addr,
I2C_MEMADD_SIZE_16BIT, &reg_data, 1, I2C_TIMEOUT) != HAL_OK) { I2C_MEMADD_SIZE_16BIT, &reg_data, 1, I2C_TIMEOUT) != HAL_OK) {
ret = -1; ret = -1;
} }
__enable_irq();
return ret; return ret;
} }
int cambus_readw(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint8_t reg_addr, uint16_t *reg_data) int cambus_readw(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint8_t reg_addr, uint16_t *reg_data)
{ {
int ret=0; int ret=0;
__disable_irq();
if (HAL_I2C_Mem_Read(i2c, slv_addr, reg_addr, if (HAL_I2C_Mem_Read(i2c, slv_addr, reg_addr,
I2C_MEMADD_SIZE_8BIT, (uint8_t*) reg_data, 2, I2C_TIMEOUT) != HAL_OK) { I2C_MEMADD_SIZE_8BIT, (uint8_t*) reg_data, 2, I2C_TIMEOUT) != HAL_OK) {
ret = -1; ret = -1;
} }
__enable_irq();
*reg_data = (*reg_data >> 8) | (*reg_data << 8); *reg_data = (*reg_data >> 8) | (*reg_data << 8);
return ret; return ret;
} }
@ -160,24 +147,20 @@ int cambus_writew(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint8_t reg_addr, ui
{ {
int ret=0; int ret=0;
reg_data = (reg_data >> 8) | (reg_data << 8); reg_data = (reg_data >> 8) | (reg_data << 8);
__disable_irq();
if (HAL_I2C_Mem_Write(i2c, slv_addr, reg_addr, if (HAL_I2C_Mem_Write(i2c, slv_addr, reg_addr,
I2C_MEMADD_SIZE_8BIT, (uint8_t*) &reg_data, 2, I2C_TIMEOUT) != HAL_OK) { I2C_MEMADD_SIZE_8BIT, (uint8_t*) &reg_data, 2, I2C_TIMEOUT) != HAL_OK) {
ret = -1; ret = -1;
} }
__enable_irq();
return ret; return ret;
} }
int cambus_readw2(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint16_t reg_addr, uint16_t *reg_data) int cambus_readw2(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint16_t reg_addr, uint16_t *reg_data)
{ {
int ret=0; int ret=0;
__disable_irq();
if (HAL_I2C_Mem_Read(i2c, slv_addr, reg_addr, if (HAL_I2C_Mem_Read(i2c, slv_addr, reg_addr,
I2C_MEMADD_SIZE_16BIT, (uint8_t*) reg_data, 2, I2C_TIMEOUT) != HAL_OK) { I2C_MEMADD_SIZE_16BIT, (uint8_t*) reg_data, 2, I2C_TIMEOUT) != HAL_OK) {
ret = -1; ret = -1;
} }
__enable_irq();
*reg_data = (*reg_data >> 8) | (*reg_data << 8); *reg_data = (*reg_data >> 8) | (*reg_data << 8);
return ret; return ret;
} }
@ -186,12 +169,10 @@ int cambus_writew2(I2C_HandleTypeDef *i2c, uint8_t slv_addr, uint16_t reg_addr,
{ {
int ret=0; int ret=0;
reg_data = (reg_data >> 8) | (reg_data << 8); reg_data = (reg_data >> 8) | (reg_data << 8);
__disable_irq();
if (HAL_I2C_Mem_Write(i2c, slv_addr, reg_addr, if (HAL_I2C_Mem_Write(i2c, slv_addr, reg_addr,
I2C_MEMADD_SIZE_16BIT, (uint8_t*) &reg_data, 2, I2C_TIMEOUT) != HAL_OK) { I2C_MEMADD_SIZE_16BIT, (uint8_t*) &reg_data, 2, I2C_TIMEOUT) != HAL_OK) {
ret = -1; ret = -1;
} }
__enable_irq();
return ret; return ret;
} }

View File

@ -48,7 +48,6 @@
#include "conf_winc.h" #include "conf_winc.h"
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "irq.h"
#include "pin.h" #include "pin.h"
#include "genhdr/pins.h" #include "genhdr/pins.h"
#include "extint.h" #include "extint.h"
@ -92,30 +91,22 @@ static sint8 nm_i2c_write_special(uint8 *wb1, uint16 sz1, uint8 *wb2, uint16 sz2
#endif #endif
#ifdef CONF_WINC_USE_SPI #ifdef CONF_WINC_USE_SPI
static sint8 spi_rw(uint8 *tx_buf, uint8 *rx_buf, uint16 u16Sz) static sint8 spi_rw(uint8 *tx_buf, uint8 *rx_buf, uint16 u16Sz)
{ {
uint32_t basepri; sint8 result = M2M_SUCCESS;
sint8 result = M2M_SUCCESS;
// Allow systick to run.
basepri = raise_irq_pri(IRQ_PRI_UART);
WINC_CS_LOW(); WINC_CS_LOW();
if (tx_buf != 0) { if (tx_buf != 0) {
if (HAL_SPI_Transmit(&SPI_HANDLE, tx_buf, u16Sz, WINC_SPI_TIMEOUT) != HAL_OK) { if (HAL_SPI_Transmit(&SPI_HANDLE, tx_buf, u16Sz, WINC_SPI_TIMEOUT) != HAL_OK) {
result = M2M_ERR_BUS_FAIL; result = M2M_ERR_BUS_FAIL;
} }
} else { } else {
tx_buf = rx_buf; memset(rx_buf, 0, u16Sz);
memset(tx_buf, 0, u16Sz); if (HAL_SPI_TransmitReceive(&SPI_HANDLE, rx_buf, rx_buf, u16Sz, WINC_SPI_TIMEOUT) != HAL_OK) {
if (HAL_SPI_TransmitReceive(&SPI_HANDLE, tx_buf, rx_buf, u16Sz, WINC_SPI_TIMEOUT) != HAL_OK) {
result = M2M_ERR_BUS_FAIL; result = M2M_ERR_BUS_FAIL;
} }
} }
WINC_CS_HIGH(); WINC_CS_HIGH();
restore_irq_pri(basepri); return result;
return result;
} }
#endif #endif