Today's the day. Renamed platform to framework.
This commit is contained in:
54
watchdog/Watchdog.cpp
Normal file
54
watchdog/Watchdog.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <framework/watchdog/Watchdog.h>
|
||||
|
||||
extern "C" {
|
||||
#include <bsp_flp/hw_timer/hw_timer.h>
|
||||
}
|
||||
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <ostream>
|
||||
|
||||
Watchdog::Watchdog(object_id_t objectId, uint32_t interval_us, uint32_t initial_interval_us) :
|
||||
SystemObject(objectId), commandQueue(3,
|
||||
WatchdogMessage::WATCHDOG_MESSAGE_SIZE) {
|
||||
hw_timer_set_reload_value(hw_timer_watchdog, interval_us);
|
||||
hw_timer_start_(hw_timer_watchdog, initial_interval_us);
|
||||
hw_timer_watchdog ->control_register |= 8;
|
||||
|
||||
hw_gpio_port ->direction |= (HW_GPIO_DDR_OUT << HW_GPIO_LEON_WD_EN);
|
||||
hw_gpio_port ->output |= (HW_GPIO_DDR_OUT << HW_GPIO_LEON_WD_EN);
|
||||
}
|
||||
|
||||
Watchdog::~Watchdog() {
|
||||
}
|
||||
|
||||
ReturnValue_t Watchdog::performOperation() {
|
||||
WatchdogMessage message;
|
||||
ReturnValue_t result = commandQueue.receiveMessage(&message);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
hw_timer_reload(hw_timer_watchdog );
|
||||
} else {
|
||||
debug << "Watchdog::performOperation: Object 0x" << std::hex
|
||||
<< message.getSender() << std::dec << " requested ";
|
||||
switch (message.getCommand()) {
|
||||
case WatchdogMessage::ENABLE:
|
||||
debug << "watchdog enable" << std::endl;
|
||||
hw_timer_reload(hw_timer_watchdog );
|
||||
hw_timer_start(hw_timer_watchdog );
|
||||
break;
|
||||
case WatchdogMessage::DISABLE:
|
||||
debug << "watchdog disable" << std::endl;
|
||||
hw_timer_stop(hw_timer_watchdog );
|
||||
break;
|
||||
case WatchdogMessage::RESET_CPU:
|
||||
debug << "CPU reset" << std::endl;
|
||||
hw_timer_start_(hw_timer_watchdog, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueId_t Watchdog::getCommandQueue() {
|
||||
return commandQueue.getId();
|
||||
}
|
||||
|
20
watchdog/Watchdog.h
Normal file
20
watchdog/Watchdog.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef WATCHDOG_H_
|
||||
#define WATCHDOG_H_
|
||||
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <framework/watchdog/WatchdogMessage.h>
|
||||
|
||||
class Watchdog: public ExecutableObjectIF, public SystemObject {
|
||||
public:
|
||||
Watchdog(object_id_t objectId, uint32_t interval_us, uint32_t initial_interval_us);
|
||||
virtual ~Watchdog();
|
||||
virtual ReturnValue_t performOperation();
|
||||
|
||||
MessageQueueId_t getCommandQueue();
|
||||
protected:
|
||||
MessageQueue commandQueue;
|
||||
};
|
||||
|
||||
#endif /* WATCHDOG_H_ */
|
43
watchdog/WatchdogMessage.cpp
Normal file
43
watchdog/WatchdogMessage.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include <framework/watchdog/WatchdogMessage.h>
|
||||
#include <cstring>
|
||||
|
||||
WatchdogMessage::WatchdogMessage() {
|
||||
messageSize = WATCHDOG_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
WatchdogMessage::WatchdogMessage(object_id_t sender,
|
||||
WatchdogCommand_t command) {
|
||||
messageSize = WATCHDOG_MESSAGE_SIZE;
|
||||
setSender(sender);
|
||||
setCommand(command);
|
||||
}
|
||||
|
||||
WatchdogMessage::WatchdogCommand_t WatchdogMessage::getCommand() {
|
||||
WatchdogCommand_t command;
|
||||
memcpy(&command, getData() + sizeof(object_id_t),
|
||||
sizeof(WatchdogCommand_t));
|
||||
return command;
|
||||
}
|
||||
|
||||
void WatchdogMessage::setCommand(WatchdogCommand_t command) {
|
||||
memcpy(getData() + sizeof(object_id_t), &command,
|
||||
sizeof(WatchdogCommand_t));
|
||||
}
|
||||
|
||||
object_id_t WatchdogMessage::getSender() {
|
||||
object_id_t sender;
|
||||
memcpy(&sender, getData(), sizeof(object_id_t));
|
||||
return sender;
|
||||
}
|
||||
|
||||
void WatchdogMessage::setSender(object_id_t sender) {
|
||||
memcpy(getData(), &sender, sizeof(object_id_t));
|
||||
}
|
||||
|
||||
WatchdogMessage::~WatchdogMessage() {
|
||||
|
||||
}
|
||||
|
||||
size_t WatchdogMessage::getMinimumMessageSize() {
|
||||
return WATCHDOG_MESSAGE_SIZE;
|
||||
}
|
32
watchdog/WatchdogMessage.h
Normal file
32
watchdog/WatchdogMessage.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef WATCHDOGMESSAGE_H_
|
||||
#define WATCHDOGMESSAGE_H_
|
||||
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
|
||||
class WatchdogMessage: public MessageQueueMessage {
|
||||
public:
|
||||
/**
|
||||
* Commands that can be sent to the watchdog
|
||||
*/
|
||||
enum WatchdogCommand_t{
|
||||
ENABLE, //!< Enables the Watchdog (it is enabled by default)
|
||||
DISABLE,//!< Disables the watchdog
|
||||
RESET_CPU //!< Causes a reset of the Processor
|
||||
};
|
||||
|
||||
static const uint8_t WATCHDOG_MESSAGE_SIZE = HEADER_SIZE + sizeof(object_id_t) + sizeof(WatchdogCommand_t);
|
||||
|
||||
WatchdogMessage();
|
||||
WatchdogMessage(object_id_t sender, WatchdogCommand_t command);
|
||||
virtual ~WatchdogMessage();
|
||||
WatchdogCommand_t getCommand();
|
||||
void setCommand(WatchdogCommand_t command);
|
||||
object_id_t getSender();
|
||||
void setSender(object_id_t sender);
|
||||
|
||||
protected:
|
||||
virtual size_t getMinimumMessageSize();
|
||||
};
|
||||
|
||||
#endif /* WATCHDOGMESSAGE_H_ */
|
Reference in New Issue
Block a user