Skip to content
Snippets Groups Projects
Commit 4bfbd23d authored by Davide Mor's avatar Davide Mor
Browse files

[cc3135] Added guards to installAsServiceThread

parent 95a31bf7
Branches
No related tags found
No related merge requests found
...@@ -49,9 +49,6 @@ CC3135::CC3135(std::unique_ptr<ICC3135Iface> &&iface) : iface(std::move(iface)) ...@@ -49,9 +49,6 @@ CC3135::CC3135(std::unique_ptr<ICC3135Iface> &&iface) : iface(std::move(iface))
CC3135::Error CC3135::init(bool wait_for_init) CC3135::Error CC3135::init(bool wait_for_init)
{ {
if (iface->is_spi())
dummyDeviceRead();
if (wait_for_init) if (wait_for_init)
{ {
DeviceInitInfo init_info = {}; DeviceInitInfo init_info = {};
...@@ -193,7 +190,7 @@ void CC3135::run() ...@@ -193,7 +190,7 @@ void CC3135::run()
{ {
// Lock the device interface // Lock the device interface
Lock<FastMutex> lock(iface_mutex); Lock<FastMutex> iface_lock(iface_mutex);
ResponseHeader header; ResponseHeader header;
Error result = readHeader(&header); Error result = readHeader(&header);
...@@ -217,16 +214,13 @@ CC3135::Error CC3135::inoutPacketSync(CC3135Defs::OpCode tx_opcode, ...@@ -217,16 +214,13 @@ CC3135::Error CC3135::inoutPacketSync(CC3135Defs::OpCode tx_opcode,
CC3135::Buffer rx_command, CC3135::Buffer rx_command,
CC3135::Buffer rx_payload) CC3135::Buffer rx_payload)
{ {
installAsServiceThread(); ServiceThreadLock service_thread_lock(this);
// Lock the device interface // Lock the device interface
Lock<FastMutex> lock(iface_mutex); Lock<FastMutex> iface_lock(iface_mutex);
TRY(writePacket(tx_opcode, tx_command, tx_payload)); TRY(writePacket(tx_opcode, tx_command, tx_payload));
TRY(readPacket(rx_opcode, rx_command, rx_payload)); TRY(readPacket(rx_opcode, rx_command, rx_payload));
restoreDefaultServiceThread();
return Error::NO_ERROR; return Error::NO_ERROR;
} }
...@@ -234,14 +228,12 @@ CC3135::Error CC3135::readPacketSync(CC3135Defs::OpCode opcode, ...@@ -234,14 +228,12 @@ CC3135::Error CC3135::readPacketSync(CC3135Defs::OpCode opcode,
CC3135::Buffer command, CC3135::Buffer command,
CC3135::Buffer payload) CC3135::Buffer payload)
{ {
installAsServiceThread(); ServiceThreadLock service_thread_lock(this);
// Lock the device interface // Lock the device interface
Lock<FastMutex> lock(iface_mutex); Lock<FastMutex> iface_lock(iface_mutex);
TRY(readPacket(opcode, command, payload)); TRY(readPacket(opcode, command, payload));
restoreDefaultServiceThread();
return Error::NO_ERROR; return Error::NO_ERROR;
} }
...@@ -250,7 +242,7 @@ CC3135::Error CC3135::writePacketSync(CC3135Defs::OpCode opcode, ...@@ -250,7 +242,7 @@ CC3135::Error CC3135::writePacketSync(CC3135Defs::OpCode opcode,
CC3135::Buffer payload) CC3135::Buffer payload)
{ {
// Lock the device interface // Lock the device interface
Lock<FastMutex> lock(iface_mutex); Lock<FastMutex> iface_lock(iface_mutex);
TRY(writePacket(opcode, command, payload)); TRY(writePacket(opcode, command, payload));
return Error::NO_ERROR; return Error::NO_ERROR;
......
...@@ -76,6 +76,20 @@ private: ...@@ -76,6 +76,20 @@ private:
static Buffer null() { return {nullptr, 0}; } static Buffer null() { return {nullptr, 0}; }
}; };
class ServiceThreadLock
{
public:
ServiceThreadLock(CC3135 *parent) : parent(parent)
{
parent->installAsServiceThread();
}
~ServiceThreadLock() { parent->restoreDefaultServiceThread(); }
private:
CC3135 *parent;
};
//! Function for servicing async messages. //! Function for servicing async messages.
void run() override; void run() override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment