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