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
13#include "can.h"
14#include "can_hw.h"
15#include "can_dash.h"
16#include "obd2.h"
17#include "can_sensor.h"
18#include "can_bench_test.h"
19#include "rusefi_wideband.h"
20
22
23
25 : PeriodicController("CAN TX", PRIO_CAN_TX, CAN_CYCLE_FREQ)
26{
27}
28
29static CI roundTxPeriodToCycle(uint16_t period) {
30 if (period < 10) return CI::_5ms;
31 else if (period < 20) return CI::_10ms;
32 else if (period < 50) return CI::_20ms;
33 else if (period < 100) return CI::_50ms;
34 else if (period < 200) return CI::_100ms;
35 else if (period < 250) return CI::_200ms;
36 else if (period < 500) return CI::_250ms;
37 else if (period < 1000) return CI::_500ms;
38 else return CI::_1000ms;
39}
40
41PUBLIC_API_WEAK bool boardEnableSendWidebandInfo() { return true; }
42
43static uint16_t m_cycleCount = 0;
44
45/* public API for custom boards */ void resetCanWriteCycle() {
46 m_cycleCount = 0;
47}
48
49// this is invoked at CAN_CYCLE_FREQ frequency
50void CanWrite::PeriodicTask(efitick_t) {
53
54 //in case we have Verbose Can enabled, we should keep user configured period
56 // slow down verbose CAN while in serial CAN
57 int canSleepPeriodMs = (engine->pauseCANdueToSerial ? 5 : 1) * engineConfiguration->canSleepPeriodMs;
58
59 auto roundedInterval = roundTxPeriodToCycle(canSleepPeriodMs);
60 if (cycle.isInterval(roundedInterval)) {
61 void sendCanVerbose();
63 }
64 }
65
67
68 while (current) {
69 current = current->request();
70 }
71
72 if (cycle.isInterval(CI::_MAX_Cycle)) {
73 //we now reset cycleCount since we reached max cycle count
74 m_cycleCount = 0;
75 }
76
77 updateDash(cycle);
78
80 if (cycle.isInterval(CI::_100ms)) {
83#ifdef HW_HELLEN_8CHAN
86#endif
87 }
88
89 if (cycle.isInterval(CI::_250ms)) {
91#ifdef HW_HELLEN_8CHAN
92 sendQcBenchBoardStatus(/*bus*/1);
93#endif
96 }
97 }
98
101 }
102
103 m_cycleCount++;
104}
105
107 CanInterval cycleMask = CanInterval::_5ms;
108
109 if ((cycleCount % 2) == 0) {
110 cycleMask |= CI::_10ms;
111 }
112
113 if ((cycleCount % 4) == 0) {
114 cycleMask |= CI::_20ms;
115 }
116
117 if ((cycleCount % 10) == 0) {
118 cycleMask |= CI::_50ms;
119 }
120
121 if ((cycleCount % 20) == 0) {
122 cycleMask |= CI::_100ms;
123 }
124
125 if ((cycleCount % 40) == 0) {
126 cycleMask |= CI::_200ms;
127 }
128
129 if ((cycleCount % 50) == 0) {
130 cycleMask |= CI::_250ms;
131 }
132
133 if ((cycleCount % 100) == 0) {
134 cycleMask |= CI::_500ms;
135 }
136
137 if ((cycleCount % 200) == 0) {
138 cycleMask |= CI::_1000ms;
139 }
140
141 return cycleMask;
142}
143
144#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:616
beuint32_t period
CanListener * canListeners_head
Definition can_rx.cpp:69
static uint16_t m_cycleCount
Definition can_tx.cpp:43
PUBLIC_API_WEAK bool boardEnableSendWidebandInfo()
Definition can_tx.cpp:41
static CI roundTxPeriodToCycle(uint16_t period)
Definition can_tx.cpp:29
CanListener * canListeners_head
Definition can_rx.cpp:69
void resetCanWriteCycle()
Definition can_tx.cpp:45
void sendCanVerbose()
Definition can.h:83
bool isInterval(CanInterval interval)
Definition can.h:90
static CanInterval computeFlags(uint32_t cycleCount)
Definition can_tx.cpp:106
virtual CanListener * request()
CanWrite()
Definition can_tx.cpp:24
void PeriodicTask(efitick_t nowNt) override
Called periodically. Override this method to do work for your controller.
Definition can_tx.cpp:50
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()