PX4 Firmware
PX4 Autopilot Software http://px4.io
internal.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #pragma once
6 
8 
9 #if UAVCAN_STM32_NUTTX
10 # include <nuttx/arch.h>
11 # include <arch/board/board.h>
12 # include <hardware/stm32_tim.h>
13 # include <syslog.h>
14 #else
15 # error "Unknown OS"
16 #endif
17 
18 /**
19  * Debug output
20  */
21 #ifndef UAVCAN_STM32_LOG
22 // syslog() crashes the system in this context
23 // # if UAVCAN_STM32_NUTTX && CONFIG_ARCH_LOWPUTC
24 # if 0
25 # define UAVCAN_STM32_LOG(fmt, ...) syslog("uavcan_stm32: " fmt "\n", ##__VA_ARGS__)
26 # else
27 # define UAVCAN_STM32_LOG(...) ((void)0)
28 # endif
29 #endif
30 
31 /**
32  * IRQ handler macros
33  */
34 #if UAVCAN_STM32_NUTTX
35 # define UAVCAN_STM32_IRQ_HANDLER(id) int id(int irq, FAR void* context, FAR void *arg)
36 # define UAVCAN_STM32_IRQ_PROLOGUE()
37 # define UAVCAN_STM32_IRQ_EPILOGUE() return 0;
38 #endif
39 
40 /**
41  * Glue macros
42  */
43 #define UAVCAN_STM32_GLUE2_(A, B) A##B
44 #define UAVCAN_STM32_GLUE2(A, B) UAVCAN_STM32_GLUE2_(A, B)
45 
46 #define UAVCAN_STM32_GLUE3_(A, B, C) A##B##C
47 #define UAVCAN_STM32_GLUE3(A, B, C) UAVCAN_STM32_GLUE3_(A, B, C)
48 
49 namespace uavcan_stm32
50 {
51 #if UAVCAN_STM32_NUTTX
52 
53 struct CriticalSectionLocker {
54  const irqstate_t flags_;
55 
56  CriticalSectionLocker()
57  : flags_(enter_critical_section())
58  { }
59 
60  ~CriticalSectionLocker()
61  {
62  leave_critical_section(flags_);
63  }
64 };
65 
66 #endif
67 
68 namespace clock
69 {
70 uavcan::uint64_t getUtcUSecFromCanInterrupt();
71 }
72 }
uavcan::uint64_t getUtcUSecFromCanInterrupt()