Skip to content

Commit

Permalink
add boot() and bootln() methods to always get boot messages
Browse files Browse the repository at this point in the history
  • Loading branch information
joeroback committed Jul 16, 2023
1 parent 67395a9 commit ef1d9c2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
28 changes: 14 additions & 14 deletions src/canbus/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ void controller::stats() noexcept

bool controller::install() noexcept
{
infoln("CAN bus starting...");
bootln("CAN bus starting...");

ENTER_CRITICAL();

verboseln("CAN bus creating frame queue...");
bootln("CAN bus creating frame queue...");
_queue = xQueueCreateStatic(_queue_length, _queue_item_size, _queue_storage, &_static_queue);
verboseln("CAN bus frame queue created...");
bootln("CAN bus frame queue created...");

// enable APB CLK to TWAI peripheral
periph_module_reset(PERIPH_TWAI_MODULE);
periph_module_enable(PERIPH_TWAI_MODULE);
verboseln("CAN bus peripheral enabled...");
bootln("CAN bus peripheral enabled...");

twai_ll_enter_reset_mode(dev);
if (!twai_ll_is_in_reset_mode(dev))
Expand All @@ -127,7 +127,7 @@ bool controller::install() noexcept
twai_ll_set_tec(dev, 0);
twai_ll_set_err_warn_lim(dev, 96);

verboseln("CAN bus mode reset...");
bootln("CAN bus mode reset...");

// configure bus timing, acceptance filter, CLKOUT, and interrupts
// get timing and filter from car specific decoder
Expand All @@ -145,23 +145,23 @@ bool controller::install() noexcept

EXIT_CRITICAL();

verboseln("CAN bus timings reset...");
verboseln(" BRP: %3u", t_config.brp);
verboseln(" SJW: %3u", t_config.sjw);
verboseln(" TSEG1: %3u", t_config.tseg_1);
verboseln(" TSEG2: %3u", t_config.tseg_2);
verboseln(" 3x Sampling: %3s", t_config.triple_sampling == 0 ? "No" : "Yes");
bootln("CAN bus timings reset...");
bootln(" BRP: %3u", t_config.brp);
bootln(" SJW: %3u", t_config.sjw);
bootln(" TSEG1: %3u", t_config.tseg_1);
bootln(" TSEG2: %3u", t_config.tseg_2);
bootln(" 3x Sampling: %3s", t_config.triple_sampling == 0 ? "No" : "Yes");

// only setup RX pin, we aren't transmitting any CAN messages on bus
gpio_set_pull_mode(CAN_RX_PIN, GPIO_FLOATING);
esp_rom_gpio_connect_in_signal(CAN_RX_PIN, TWAI_RX_IDX, false);
esp_rom_gpio_pad_select_gpio(CAN_RX_PIN);
gpio_set_direction(CAN_RX_PIN, GPIO_MODE_INPUT);
verboseln("CAN bus GPIO pins reset...");
bootln("CAN bus GPIO pins reset...");

// setup interrupt service routine
esp_intr_alloc(ETS_TWAI_INTR_SOURCE, ESP_INTR_FLAG_LEVEL1, isr, this, &_isr_handle);
verboseln("CAN bus interrupt handler installed...");
bootln("CAN bus interrupt handler installed...");

return true;
}
Expand All @@ -186,7 +186,7 @@ bool controller::start() noexcept

EXIT_CRITICAL();

infoln("CAN bus started!");
bootln("CAN bus started!");

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ logger& logger::get() noexcept
}

logger::logger() noexcept
: _log_level(log_level::off)
: _log_level(log_level::boot)
, _lock(portMUX_INITIALIZER_UNLOCKED)
{
}
Expand Down
13 changes: 13 additions & 0 deletions src/logging/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace logging
enum class log_level
{
off,
boot,
error,
warn,
info,
Expand Down Expand Up @@ -112,6 +113,18 @@ class logger final

} // namespace logging

template <typename ...TArgs>
void boot(const char* fmt, TArgs&& ...args) noexcept
{
logging::logger::get().log(logging::log_level::boot, fmt, std::forward<TArgs>(args)...);
}

template <typename ...TArgs>
void bootln(const char* fmt, TArgs&& ...args) noexcept
{
logging::logger::get().logln(logging::log_level::boot, fmt, std::forward<TArgs>(args)...);
}

template <typename ...TArgs>
void error(const char* fmt, TArgs&& ...args) noexcept
{
Expand Down
3 changes: 0 additions & 3 deletions src/racechrono-canbus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
// SOFTWARE.
#pragma once

// no assertions
#define NDEBUG

#include <Arduino.h>

#include <cstdint>
Expand Down
8 changes: 4 additions & 4 deletions src/racechrono/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ device& device::get() noexcept

bool device::start(BLECharacteristicCallbacks* callbacks) noexcept
{
infoln("Bluetooth LE starting...");
bootln("Bluetooth LE starting...");

char name[32];

Expand All @@ -46,13 +46,13 @@ bool device::start(BLECharacteristicCallbacks* callbacks) noexcept

if (ret == ESP_OK)
{
infoln("Bluetooth LE MAC: %02x:%02x:%02x:%02x:%02x:%02x",
bootln("Bluetooth LE MAC: %02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
snprintf(name, sizeof(name), "RaceChrono %02X:%02X:%02X", mac[3], mac[4], mac[5]);
}
else
{
errorln("ERROR: Unable to determine bluetooth MAC address! reason: %d", ret);
bootln("ERROR: Unable to determine bluetooth MAC address! reason: %d", ret);
snprintf(name, sizeof(name), "RaceChrono DIY");
}

Expand All @@ -75,7 +75,7 @@ bool device::start(BLECharacteristicCallbacks* callbacks) noexcept
advertising->setScanResponse(false);
BLEDevice::startAdvertising();

infoln("Bluetooth LE started!");
bootln("Bluetooth LE started!");

return true;
}
Expand Down

0 comments on commit ef1d9c2

Please sign in to comment.