spi mutex only blocked when gpio != NO_GPIO

This commit is contained in:
Jakob Meier 2021-05-12 10:22:23 +02:00
parent a85c01465b
commit 8a38c7958b
3 changed files with 18 additions and 9 deletions

View File

@ -82,7 +82,7 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular
chipname = regularGpio->chipname; chipname = regularGpio->chipname;
chip = gpiod_chip_open_by_name(chipname.c_str()); chip = gpiod_chip_open_by_name(chipname.c_str());
if (!chip) { if (!chip) {
sif::warning << "LinuxLibgpioIF::configureGpios: Failed to open chip " sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open chip "
<< chipname << ". Gpio ID: " << gpioId << std::endl; << chipname << ". Gpio ID: " << gpioId << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -90,9 +90,10 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular
lineNum = regularGpio->lineNum; lineNum = regularGpio->lineNum;
lineHandle = gpiod_chip_get_line(chip, lineNum); lineHandle = gpiod_chip_get_line(chip, lineNum);
if (!lineHandle) { if (!lineHandle) {
sif::warning << "LinuxLibgpioIF::configureGpios: Failed to open line for GPIO" << std::endl; sif::debug << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
sif::warning << "GPIO ID " << gpioId << "with line number " << lineNum << sif::debug << "GPIO ID: " << gpioId << ", line number: " << lineNum <<
" and chipname " << chipname << std::endl; ", chipname: " << chipname << std::endl;
sif::debug << "Check if linux GPIO configuration has changed. " << std::endl;
gpiod_chip_close(chip); gpiod_chip_close(chip);
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -105,7 +106,7 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular
result = gpiod_line_request_output(lineHandle, consumer.c_str(), result = gpiod_line_request_output(lineHandle, consumer.c_str(),
regularGpio->initValue); regularGpio->initValue);
if (result < 0) { if (result < 0) {
sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line " << lineNum << sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " << lineNum <<
" from GPIO instance with ID: " << gpioId << std::endl; " from GPIO instance with ID: " << gpioId << std::endl;
gpiod_line_release(lineHandle); gpiod_line_release(lineHandle);
return RETURN_FAILED; return RETURN_FAILED;

View File

@ -178,11 +178,10 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
bool fullDuplex = spiCookie->isFullDuplex(); bool fullDuplex = spiCookie->isFullDuplex();
gpioId_t gpioId = spiCookie->getChipSelectPin(); gpioId_t gpioId = spiCookie->getChipSelectPin();
/* GPIO access is mutex protected */
MutexGuard(spiMutex, timeoutType, timeoutMs);
/* Pull SPI CS low. For now, no support for active high given */ /* Pull SPI CS low. For now, no support for active high given */
if(gpioId != gpio::NO_GPIO) { if(gpioId != gpio::NO_GPIO) {
/* GPIO access is mutex protected */
MutexGuard(spiMutex, timeoutType, timeoutMs);
gpioComIF->pullLow(gpioId); gpioComIF->pullLow(gpioId);
} }
@ -263,8 +262,8 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe
} }
gpioId_t gpioId = spiCookie->getChipSelectPin(); gpioId_t gpioId = spiCookie->getChipSelectPin();
MutexGuard(spiMutex, timeoutType, timeoutMs);
if(gpioId != gpio::NO_GPIO) { if(gpioId != gpio::NO_GPIO) {
MutexGuard(spiMutex, timeoutType, timeoutMs);
gpioComIF->pullLow(gpioId); gpioComIF->pullLow(gpioId);
} }
@ -302,6 +301,10 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
MutexIF* SpiComIF::getMutex() {
return spiMutex;
}
ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) { ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
if(buffer == nullptr) { if(buffer == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;

View File

@ -39,6 +39,11 @@ public:
size_t requestLen) override; size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) override; size_t *size) override;
/**
* @brief This function returns the mutex which can be used to protect the spi bus when
* the chip select must be driven from outside of the com if.
*/
MutexIF* getMutex();
private: private:
struct SpiInstance { struct SpiInstance {