rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
can_tx.cpp
Go to the documentation of this file.
1/**
2 * @file can_tx.cpp
3 *
4 * CAN transmission handling. This file handles the dispatch of various outgoing regularly scheduled CAN message types.
5 *
6 * @date Mar 19, 2020
7 * @author Matthew Kennedy, (c) 2020
8 */
9
10#include "pch.h"
11
12#if EFI_CAN_SUPPORT || EFI_UNIT_TEST
13#include "can.h"
14#include "can_dash.h"
15#endif
16
17#if EFI_CAN_SUPPORT
18#include "can_hw.h"
19#include "obd2.h"
20#include "can_sensor.h"
21#include "can_bench_test.h"
22#include "rusefi_wideband.h"
23
25
26
28 : PeriodicController("CAN TX", PRIO_CAN_TX, CAN_CYCLE_FREQ)
29{
30}
31
32static CI roundTxPeriodToCycle(uint16_t period) {
33 if (period < 10) return CI::_5ms;
34 else if (period < 20) return CI::_10ms;
35 else if (period < 50) return CI::_20ms;
36 else if (period < 100) return CI::_50ms;
37 else if (period < 200) return CI::_100ms;
38 else if (period < 250) return CI::_200ms;
39 else if (period < 500) return CI::_250ms;
40 else if (period < 1000) return CI::_500ms;
41 else return CI::_1000ms;
42}
43
44PUBLIC_API_WEAK bool boardEnableSendWidebandInfo() { return true; }
45
46static uint16_t m_cycleCount = 0;
47
48/* public API for custom boards */ void resetCanWriteCycle() {
49 m_cycleCount = 0;
50}
51
52// this is invoked at CAN_CYCLE_FREQ frequency
53void CanWrite::PeriodicTask(efitick_t) {
56
57 //in case we have Verbose Can enabled, we should keep user configured period
59 // slow down verbose CAN while in serial CAN
60 int canSleepPeriodMs = (engine->pauseCANdueToSerial ? 5 : 1) * engineConfiguration->canSleepPeriodMs;
61
62 auto roundedInterval = roundTxPeriodToCycle(canSleepPeriodMs);
63 if (cycle.isInterval(roundedInterval)) {
64 void sendCanVerbose();
66 }
67 }
68
70
71 while (current) {
72 current = current->request();
73 }
74
75 if (cycle.isInterval(CI::_MAX_Cycle)) {
76 //we now reset cycleCount since we reached max cycle count
77 m_cycleCount = 0;
78 }
79
80 updateDash(cycle);
81
83 if (cycle.isInterval(CI::_100ms)) {
86#ifdef HW_HELLEN_8CHAN
89#endif
90 }
91
92 if (cycle.isInterval(CI::_250ms)) {
94#ifdef HW_HELLEN_8CHAN
95 sendQcBenchBoardStatus(/*bus*/1);
96#endif
99 }
100 }
101
104 }
105
106 m_cycleCount++;
107}
108
109#endif
110
111#if EFI_CAN_SUPPORT || EFI_UNIT_TEST
112
114 CanInterval cycleMask = CanInterval::_5ms;
115
116 if ((cycleCount % 2) == 0) {
117 cycleMask |= CI::_10ms;
118 }
119
120 if ((cycleCount % 4) == 0) {
121 cycleMask |= CI::_20ms;
122 }
123
124 if ((cycleCount % 10) == 0) {
125 cycleMask |= CI::_50ms;
126 }
127
128 if ((cycleCount % 20) == 0) {
129 cycleMask |= CI::_100ms;
130 }
131
132 if ((cycleCount % 40) == 0) {
133 cycleMask |= CI::_200ms;
134 }
135
136 if ((cycleCount % 50) == 0) {
137 cycleMask |= CI::_250ms;
138 }
139
140 if ((cycleCount % 100) == 0) {
141 cycleMask |= CI::_500ms;
142 }
143
144 if ((cycleCount % 200) == 0) {
145 cycleMask |= CI::_1000ms;
146 }
147
148 return cycleMask;
149}
150
151#endif // EFI_CAN_SUPPORT
CanInterval
Definition can.h:29
void sendQcBenchButtonCounters()
bool isHwQcMode()
void sendQcBenchRawAnalogValues(size_t bus)
void sendQcBenchBoardStatus(size_t bus)
void sendQcBenchAuxDigitalCounters()
void sendQcBenchEventCounters(size_t bus)
void updateDash(CanCycle cycle)
Definition can_dash.cpp:622
beuint32_t period
CanListener * canListeners_head
Definition can_rx.cpp:69
static uint16_t m_cycleCount
Definition can_tx.cpp:46
PUBLIC_API_WEAK bool boardEnableSendWidebandInfo()
Definition can_tx.cpp:44
static CI roundTxPeriodToCycle(uint16_t period)
Definition can_tx.cpp:32
CanListener * canListeners_head
Definition can_rx.cpp:69
void resetCanWriteCycle()
Definition can_tx.cpp:48
void sendCanVerbose()
Definition can.h:86
bool isInterval(CanInterval interval)
Definition can.h:93
static CanInterval computeFlags(uint32_t cycleCount)
Definition can_tx.cpp:113
virtual CanListener * request()
CanWrite()
Definition can_tx.cpp:27
void PeriodicTask(efitick_t nowNt) override
Called periodically. Override this method to do work for your controller.
Definition can_tx.cpp:53
bool pauseCANdueToSerial
Definition engine.h:123
Base class for a controller that needs to run periodically to perform work.
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
bool boardEnableSendWidebandInfo()
@ CanThreadTx
void sendWidebandInfo()