37 #include <px4_platform_common/px4_config.h> 38 #include <px4_platform_common/log.h> 39 #include <px4_platform_common/tasks.h> 48 #include <arch/board/board.h> 49 #include <arch/chip/chip.h> 80 .major_version = APP_VERSION_MAJOR,
81 .minor_version = APP_VERSION_MINOR,
82 .reserved = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
93 _node(can_driver, system_clock),
95 _fw_update_listner(_node),
98 const int res = pthread_mutex_init(&
_node_mutex,
nullptr);
104 px4_sem_init(&
_sem, 0, 0);
106 px4_sem_setprotocol(&
_sem, SEM_PRIO_NONE);
128 }
while (
_task != -1);
132 px4_sem_destroy(&
_sem);
140 PX4_WARN(
"Already started");
148 static bool can_initialized =
false;
150 if (!can_initialized) {
151 const int can_init_res = can.
init(bitrate);
153 if (can_init_res < 0) {
154 PX4_WARN(
"CAN driver init failed %i", can_init_res);
158 can_initialized =
true;
167 PX4_WARN(
"Out of memory");
174 if (node_init_res < 0) {
177 PX4_WARN(
"Node init failed %i", node_init_res);
178 return node_init_res;
189 static auto run_trampoline = [](int,
char *[]) {
return UavcanEsc::_instance->
run();};
191 static_cast<main_t>(run_trampoline),
nullptr);
194 PX4_WARN(
"start failed: %d", errno);
204 uavcan::protocol::SoftwareVersion swver;
207 char fw_git_short[9] = {};
210 swver.vcs_commit = std::strtol(fw_git_short, &end, 16);
211 swver.optional_field_flags |= swver.OPTIONAL_FIELD_FLAG_VCS_COMMIT;
216 PX4_WARN(
"SW version vcs_commit: 0x%08x",
unsigned(swver.vcs_commit));
218 _node.setSoftwareVersion(swver);
221 uavcan::protocol::HardwareVersion hwver;
223 hwver.major = HW_VERSION_MAJOR;
224 hwver.minor = HW_VERSION_MINOR;
227 board_get_mfguid(mfgid);
228 uavcan::copy(mfgid, mfgid +
sizeof(mfgid), hwver.unique_id.begin());
230 _node.setHardwareVersion(hwver);
235 px4_systemreset(
false);
241 uavcan::ServiceResponseDataStructure<UavcanEsc::BeginFirmwareUpdate::Response> &rsp)
243 static bool inprogress =
false;
245 rsp.error = rsp.ERROR_UNKNOWN;
247 if (req.image_file_remote_path.path.size()) {
248 rsp.error = rsp.ERROR_IN_PROGRESS;
258 _reset_timer.startOneShotWithDelay(uavcan::MonotonicDuration::fromMSec(1000));
259 rsp.error = rsp.ERROR_OK;
275 _node.setName(HW_UAVCAN_NAME);
277 _node.setNodeID(node_id);
284 if (srv_start_res < 0) {
290 return _node.start();
301 ::syslog(LOG_INFO,
"UAVCAN: Restarting by request from %i\n",
int(request_source.get()));
302 ::usleep(20 * 1000 * 1000);
303 px4_systemreset(
false);
310 const int spin_res =
_node.spin(uavcan::MonotonicTime());
313 PX4_WARN(
"node spin error %i", spin_res);
320 px4_sem_t *sem = (px4_sem_t *)arg;
323 if (px4_sem_getvalue(sem, &semaphore_value) == 0 && semaphore_value > 1) {
345 ::syslog(LOG_INFO,
"UAVCAN: Indication controller init failed\n");
351 _node.setModeOperational();
360 while (px4_sem_wait(&
_sem) != 0);
403 if (ret == -ENOTTY) {
404 ret = CDev::ioctl(filp, cmd, arg);
414 PX4_WARN(
"not running, start first");
429 "\tuavcanesc {start|status|stop}");
462 if (node_id < 0 || node_id > uavcan::NodeID::Max || !uavcan::NodeID(node_id).isUnicast()) {
463 PX4_WARN(
"Invalid Node ID %i", node_id);
468 PX4_WARN(
"Node ID %u, bitrate %u", node_id, bitrate);
482 if (!std::strcmp(argv[1],
"start")) {
485 errx(1,
"already started");
495 PX4_ERR(
"application not running");
500 if (!std::strcmp(argv[1],
"status") || !std::strcmp(argv[1],
"info")) {
505 if (!std::strcmp(argv[1],
"stop")) {
uavcan::ServiceServer< BeginFirmwareUpdate, BeginFirmwareUpdateCallBack > _fw_update_listner
__EXPORT void bootloader_app_shared_invalidate(void)
static void cb_reboot(const uavcan::TimerEvent &)
#define UAVCAN_DEVICE_PATH
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
UavcanEsc(uavcan::ICanDriver &can_driver, uavcan::ISystemClock &system_clock)
void lock()
Take the driver lock.
static SystemClock & instance()
Calls clock::init() as needed.
int init(uavcan::uint32_t bitrate)
This overload simply configures the provided bitrate.
static int start(uavcan::NodeID node_id, uint32_t bitrate)
__EXPORT int bootloader_app_shared_read(bootloader_app_shared_t *shared, eRole_t role)
High-resolution timer with callouts and timekeeping.
__EXPORT int uavcanesc_main(int argc, char *argv[])
Global flash based parameter store.
static void print_usage()
void init()
Activates/configures the hardware registers.
bool handleRestartRequest(uavcan::NodeID request_source) override
__EXPORT void bootloader_app_shared_write(bootloader_app_shared_t *shared, eRole_t role)
Node _node
library instance
static void busevent_signal_trampoline()
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
uavcan::MethodBinder< UavcanEsc *, void(UavcanEsc::*)(const uavcan::ReceivedDataStructure< UavcanEsc::BeginFirmwareUpdate::Request > &, uavcan::ServiceResponseDataStructure< UavcanEsc::BeginFirmwareUpdate::Response > &)> BeginFirmwareUpdateCallBack
__EXPORT int uavcannode_start(int argc, char *argv[])
__EXPORT void hrt_call_every(struct hrt_call *entry, hrt_abstime delay, hrt_abstime interval, hrt_callout callout, void *arg)
Call callout(arg) after delay, and then after every interval.
virtual int ioctl(file *filp, int cmd, unsigned long arg)
int init(uavcan::NodeID node_id, uavcan_stm32::BusEvent &bus_events)
#define APP_DESCRIPTOR_SIGNATURE
const char * px4_firmware_version_string(void)
Firmware version as human readable string (git tag)
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
Tools for system version detection.
uavcan::TimerEventForwarder< void(*)(const uavcan::TimerEvent &)> _reset_timer
static UavcanEsc * _instance
singleton pointer
int init_indication_controller(uavcan::INode &node)
void cb_beginfirmware_update(const uavcan::ReceivedDataStructure< UavcanEsc::BeginFirmwareUpdate::Request > &req, uavcan::ServiceResponseDataStructure< UavcanEsc::BeginFirmwareUpdate::Response > &rsp)
static constexpr unsigned StackSize
struct @83::@85::@87 file
static UavcanEsc * instance()
pthread_mutex_t _node_mutex
#define boot_app_shared_section
static void signal_callback(void *arg)
boot_app_shared_section app_descriptor_t AppDescriptor
Implements basic functionality of UAVCAN esc.
int _task
handle to the OS task
bool _task_should_exit
flag to indicate to tear down the CAN driver
void rgb_led(int r, int g, int b, int freqs)
uint8_t signature[sizeof(uint64_t)]
void unlock()
Release the driver lock.
__EXPORT void hrt_cancel(struct hrt_call *entry)
Remove the entry from the callout list.
px4_sem_t _sem
semaphore for scheduling the task
RestartRequestHandler restart_request_handler