Skip to content

Commit

Permalink
Direct code import
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Jun 29, 2018
1 parent c843f8d commit ac5298f
Show file tree
Hide file tree
Showing 48 changed files with 12,142 additions and 27 deletions.
50 changes: 24 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
# Build outputs
*.o
*.obj
*.d
lib*.so
lib*.so.*
*.a
build*/
.dep
__pycache__
*.pyc

# Precompiled Headers
*.gch
*.pch
# Eclipse
.metadata
.settings
.project
.cproject
.pydevproject
.gdbinit

# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# vsstudio code
.vscode

# Fortran module files
*.mod
*.smod
# vagrant
.vagrant

# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# libuavcan DSDL compiler default output directory
dsdlc_generated

# Executables
*.exe
*.out
*.app
# Log files
*.log
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# libuavcan_lpc11c24
Libuavcan platform driver for NXP LPC11C24
==========================================

See <https://uavcan.org/Implementations/Libuavcan/Platforms/LPC11C24>.
9 changes: 9 additions & 0 deletions driver/include.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
#

LIBUAVCAN_LPC11C24_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

LIBUAVCAN_LPC11C24_SRC := $(shell find $(LIBUAVCAN_LPC11C24_DIR)/src -type f -name '*.cpp')

LIBUAVCAN_LPC11C24_INC := $(LIBUAVCAN_LPC11C24_DIR)/include/
93 changes: 93 additions & 0 deletions driver/include/uavcan_lpc11c24/can.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/

#pragma once

#include <uavcan/driver/can.hpp>

namespace uavcan_lpc11c24
{
/**
* This class implements CAN driver interface for libuavcan.
* No configuration needed other than CAN baudrate.
* This class is a singleton.
*/
class CanDriver
: public uavcan::ICanDriver
, public uavcan::ICanIface
, uavcan::Noncopyable
{
static CanDriver self;

CanDriver() { }

public:
/**
* Returns the singleton reference.
* No other copies can be created.
*/
static CanDriver& instance() { return self; }

/**
* Attempts to detect bit rate of the CAN bus.
* This function may block for up to X seconds, where X is the number of bit rates to try.
* This function is NOT guaranteed to reset the CAN controller upon return.
* @return On success: detected bit rate, in bits per second.
* On failure: zero.
*/
static uavcan::uint32_t detectBitRate(void (*idle_callback)() = nullptr);

/**
* Returns negative value if the requested baudrate can't be used.
* Returns zero if OK.
*/
int init(uavcan::uint32_t bitrate);

bool hasReadyRx() const;
bool hasEmptyTx() const;

/**
* This method will return true only if there was any CAN bus activity since previous call of this method.
* This is intended to be used for LED iface activity indicators.
*/
bool hadActivity();

/**
* Returns the number of times the RX queue was overrun.
*/
uavcan::uint32_t getRxQueueOverflowCount() const;

/**
* Whether the controller is currently in bus off state.
* Note that the driver recovers the CAN controller from the bus off state automatically!
* Therefore, this method serves only monitoring purposes and is not necessary to use.
*/
bool isInBusOffState() const;

uavcan::int16_t send(const uavcan::CanFrame& frame,
uavcan::MonotonicTime tx_deadline,
uavcan::CanIOFlags flags) override;

uavcan::int16_t receive(uavcan::CanFrame& out_frame,
uavcan::MonotonicTime& out_ts_monotonic,
uavcan::UtcTime& out_ts_utc,
uavcan::CanIOFlags& out_flags) override;

uavcan::int16_t select(uavcan::CanSelectMasks& inout_masks,
const uavcan::CanFrame* (&)[uavcan::MaxCanIfaces],
uavcan::MonotonicTime blocking_deadline) override;

uavcan::int16_t configureFilters(const uavcan::CanFilterConfig* filter_configs,
uavcan::uint16_t num_configs) override;

uavcan::uint64_t getErrorCount() const override;

uavcan::uint16_t getNumFilters() const override;

uavcan::ICanIface* getIface(uavcan::uint8_t iface_index) override;

uavcan::uint8_t getNumIfaces() const override;
};

}
65 changes: 65 additions & 0 deletions driver/include/uavcan_lpc11c24/clock.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/

#pragma once

#include <uavcan/driver/system_clock.hpp>

namespace uavcan_lpc11c24
{
namespace clock
{
/**
* Starts the clock.
* Can be called multiple times, only the first call will be effective.
*/
void init();

/**
* Returns current monotonic time passed since the moment when clock::init() was called.
* Note that both monotonic and UTC clocks are implemented using SysTick timer.
*/
uavcan::MonotonicTime getMonotonic();

/**
* Returns UTC time if it has been set, otherwise returns zero time.
* Note that both monotonic and UTC clocks are implemented using SysTick timer.
*/
uavcan::UtcTime getUtc();

/**
* Performs UTC time adjustment.
* The UTC time will be zero until first adjustment has been performed.
*/
void adjustUtc(uavcan::UtcDuration adjustment);

/**
* Returns clock error sampled at previous UTC adjustment.
* Positive if the hardware timer is slower than reference time.
*/
uavcan::UtcDuration getPrevUtcAdjustment();

}

/**
* Adapter for uavcan::ISystemClock.
*/
class SystemClock : public uavcan::ISystemClock, uavcan::Noncopyable
{
static SystemClock self;

SystemClock() { }

uavcan::MonotonicTime getMonotonic() const override { return clock::getMonotonic(); }
uavcan::UtcTime getUtc() const override { return clock::getUtc(); }
void adjustUtc(uavcan::UtcDuration adjustment) override { clock::adjustUtc(adjustment); }

public:
/**
* Calls clock::init() as needed.
*/
static SystemClock& instance();
};

}
9 changes: 9 additions & 0 deletions driver/include/uavcan_lpc11c24/uavcan_lpc11c24.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/

#pragma once

#include <uavcan/uavcan.hpp>
#include <uavcan_lpc11c24/can.hpp>
#include <uavcan_lpc11c24/clock.hpp>
Loading

0 comments on commit ac5298f

Please sign in to comment.