-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor platform specific functions and restart request (#25)
- Loading branch information
1 parent
937de75
commit 2e63e03
Showing
22 changed files
with
75 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "cyphal.hpp" | ||
#include "main.h" | ||
#include "cyphal_subscribers.hpp" | ||
#include "cyphal_registers.hpp" | ||
#include "uavcan/node/Heartbeat_1_0.h" | ||
|
@@ -18,7 +17,6 @@ static const constexpr size_t TX_QUEUE_FRAME_SIZE = 320; ///< we need 314 bytes | |
///< wrappers | ||
static void* memAllocate(CanardInstance* const canard, const size_t amount); | ||
static void memFree(CanardInstance* const canard, void* const pointer); | ||
static uint32_t getCurrentMicroseconds(); | ||
|
||
|
||
O1HeapInstance* Cyphal::my_allocator; | ||
|
@@ -58,7 +56,7 @@ int Cyphal::init(uint8_t id) { | |
|
||
void Cyphal::process() { | ||
// 1. spin recv | ||
uint32_t crnt_time_ms = HAL_GetTick(); | ||
uint32_t crnt_time_ms = platformSpecificGetTimeMs(); | ||
for (uint_fast8_t frame_idx = 0; frame_idx < transport.get_rx_queue_size(); frame_idx++) { | ||
CanardFrame rx_frame; | ||
if (transport.receive(&rx_frame)) { | ||
|
@@ -132,7 +130,7 @@ void Cyphal::processReceivedTransfer([[maybe_unused]] const uint8_t redundant_in | |
} | ||
|
||
bool Cyphal::isTxQueueItemFresh(const CanardTxQueueItem* ti) const { | ||
return (0U == ti->tx_deadline_usec) || (ti->tx_deadline_usec > getCurrentMicroseconds()); | ||
return (0U == ti->tx_deadline_usec) || (ti->tx_deadline_usec > platformSpecificGetTimeMs()); | ||
} | ||
|
||
void Cyphal::spinTransmit() { | ||
|
@@ -201,8 +199,5 @@ static void memFree(CanardInstance* const canard, void* const pointer) { | |
(void) canard; | ||
o1heapFree(Cyphal::my_allocator, pointer); | ||
} | ||
static uint32_t getCurrentMicroseconds() { | ||
return HAL_GetTick(); | ||
} | ||
|
||
} // namespace cyphal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2024 Dmitry Ponomarev <[email protected]> | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef CYPHAL_PLATFORM_SPECIFIC_H_ | ||
#define CYPHAL_PLATFORM_SPECIFIC_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @return the time in milliseconds since the application started. | ||
* @note This function must be provided by a user! | ||
*/ | ||
uint32_t platformSpecificGetTimeMs(); | ||
|
||
/** | ||
* @return whether the request will be processed | ||
* True - the application will be restarted soon. | ||
* False - the restarted is not supported or can't be handled at the moment. | ||
* @note Implementation is recommended, but optional. | ||
*/ | ||
bool platformSpecificRequestRestart(); | ||
|
||
/** | ||
* @param[out] out_id - hardware Unique ID | ||
* @note Implementation is recommended, but optional. | ||
*/ | ||
void platformSpecificReadUniqueID(uint8_t out_uid[16]); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // CYPHAL_PLATFORM_SPECIFIC_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,13 @@ | |
/// Copyright (c) 2022 Dmitry Ponomarev. | ||
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include <stdint.h> | ||
#include "platform_specific.h" | ||
#include <string.h> | ||
|
||
/// Functions below are auxiliary. | ||
/// You may provide their implementation outside if you need. | ||
__attribute__ ((weak)) uint32_t HAL_GetUIDw0() { return 0; } | ||
__attribute__ ((weak)) uint32_t HAL_GetUIDw1() { return 0; } | ||
__attribute__ ((weak)) uint32_t HAL_GetUIDw2() { return 0; } | ||
__attribute__ ((weak)) void HAL_NVIC_SystemReset() { } | ||
__attribute__((weak)) bool platformSpecificRequestRestart() { | ||
return false; // because not implemented | ||
} | ||
|
||
__attribute__((weak)) void platformSpecificReadUniqueID(uint8_t out_uid[16]) { | ||
memset(out_uid, 0x00, 16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
# Distributed under the MIT License, available in the file LICENSE. | ||
# Author: Dmitry Ponomarev <[email protected]> | ||
|
||
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) | ||
LIBPARAMS_DIR:=${ROOT_DIR}/Libs/libparams | ||
|
||
all: ubuntu_minimal ubuntu_publisher_example | ||
|
||
define build_example | ||
|
@@ -22,6 +25,10 @@ generage_dsdl: | |
mkdir -p build/nunavut_out | ||
./scripts/nnvg_generate_c_headers.sh build/nunavut_out | ||
|
||
clone_dependencies: | ||
mkdir -p build | ||
if [ ! -d "${LIBPARAMS_DIR}" ]; then git clone --depth 1 --branch v0.8.4 https://github.com/PonomarevDA/libparams.git ${LIBPARAMS_DIR}; fi | ||
|
||
clean: | ||
rm -rf build/examples/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "actuator.hpp" | ||
#include "main.h" | ||
#include "params.hpp" | ||
|
||
namespace cyphal { | ||
|
@@ -61,7 +60,7 @@ int8_t ReadinessSubscriber::init() { | |
} | ||
|
||
uint8_t ReadinessSubscriber::get_readiness() { | ||
if (_last_recv_time_ms == 0 || HAL_GetTick() > _last_recv_time_ms + 500) { | ||
if (_last_recv_time_ms == 0 || platformSpecificGetTimeMs() > _last_recv_time_ms + 500) { | ||
return reg_udral_service_common_Readiness_0_1_SLEEP; | ||
} | ||
|
||
|
@@ -72,7 +71,7 @@ void ReadinessSubscriber::callback(const CanardRxTransfer& transfer) { | |
auto payload = static_cast<const uint8_t*>(transfer.payload); | ||
size_t payload_len = transfer.payload_size; | ||
reg_udral_service_common_Readiness_0_1_deserialize_(&msg, payload, &payload_len); | ||
_last_recv_time_ms = HAL_GetTick(); | ||
_last_recv_time_ms = platformSpecificGetTimeMs(); | ||
} | ||
|
||
} // namespace cyphal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "airspeed.hpp" | ||
#include "main.h" | ||
#include "params.hpp" | ||
|
||
namespace cyphal { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "barometer.hpp" | ||
#include "main.h" | ||
#include "cyphal.hpp" | ||
#include "params.hpp" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "battery.hpp" | ||
#include "main.h" | ||
#include "params.hpp" | ||
|
||
#define WH_TO_JOULE 3600 | ||
|
@@ -16,7 +15,7 @@ void UdralBatteryPublisher::set_nominal_data(float design_capacity_ah, uint64_t | |
} | ||
|
||
void UdralBatteryPublisher::publish(float voltage, float current, float temperature_kelvin, float full_capacity_ah, float remaining_capacity_ah) { | ||
uint32_t crnt_time_ms = HAL_GetTick(); | ||
uint32_t crnt_time_ms = platformSpecificGetTimeMs(); | ||
|
||
if (crnt_time_ms > _next_source_pub_time_ms) { | ||
_next_source_pub_time_ms = crnt_time_ms + 10; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "imu.hpp" | ||
#include "main.h" | ||
#include "params.hpp" | ||
|
||
namespace cyphal { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "rangefinder.hpp" | ||
#include "main.h" | ||
|
||
namespace cyphal { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "rgbled.hpp" | ||
#include "main.h" | ||
#include "params.hpp" | ||
|
||
namespace cyphal { | ||
|
@@ -35,7 +34,7 @@ void HighColorSubscriber::callback(const CanardRxTransfer& transfer) { | |
auto payload = static_cast<const uint8_t*>(transfer.payload); | ||
size_t payload_len = transfer.payload_size; | ||
reg_udral_physics_optics_HighColor_0_1_deserialize_(&_msg, payload, &payload_len); | ||
_last_recv_ts_ms = HAL_GetTick(); | ||
_last_recv_ts_ms = platformSpecificGetTimeMs(); | ||
} | ||
|
||
} // namespace cyphal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "compact_feedback.hpp" | ||
#include "main.h" | ||
#include "params.hpp" | ||
|
||
namespace zubax::telega { | ||
|