Ditch a bunch of superfluous lines that were always unused and made hex interpretatio...
[freeems-vanilla.git] / src / inc / counterTypes.h
blobcc256e22bee70aac42ff7da61e490f6fefd6607c
1 /* FreeEMS - the open source engine management system
3 * Copyright 2008-2011 Fred Cooke
5 * This file is part of the FreeEMS project.
7 * FreeEMS software is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * FreeEMS software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
20 * We ask that if you make any changes to this file you email them upstream to
21 * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
23 * Thank you for choosing FreeEMS to run your engine!
27 /** @file
29 * @ingroup allHeaders
30 * @ingroup globalHeaders
31 * @ingroup dataStructures
33 * @brief Counter struct typedefs
35 * This file contains all of the counter and statistic struct typedefs.
39 /* Header file multiple inclusion protection courtesy eclipse Header Template */
40 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
41 #ifndef FILE_COUNTER_TYPES_H_SEEN
42 #define FILE_COUNTER_TYPES_H_SEEN
45 // Some Fred Cooke cunning inspired by EssEss
46 #define FLAG_AND_INC_FLAGGABLE(OFFSET) \
47 (*(((unsigned char*)&Flaggables) + OFFSET))++; \
48 KeyUserDebugs.flaggableFlags |= (1 << OFFSET); // End of macro
50 /// These should all stay at zero, thus they are incremented through a mechanism that also sets a flag in a special variable
51 typedef struct {
52 // Error conditions
53 unsigned char callsToUISRs; ///< to ensure we aren't accidentally triggering unused ISRs.
54 unsigned char lowVoltageConditions; ///< low voltage conditions.
55 #define FLAG_CALLS_TO_UISRS_OFFSET 0
56 #define FLAG_LOW_VOLTATE_CONDITION_OFFSET 1
58 // RPM/Position input
59 unsigned char decoderSyncLosses; ///< Number of times cam, crank or combustion sync is lost.
60 unsigned char spare; ///< Spare.
61 unsigned char decoderSyncStateClears; ///< Sync loss called when not synced yet, thus discarding data and preventing sync.
62 #define FLAG_DECODER_SYNC_LOSSES_OFFSET 2
63 #define FLAG_SPARE_OFFSET 3
64 #define FLAG_DECODER_SYNC_STATE_CLEARS_OFFSET 4
66 // If you're getting these, then your serial hardware sucks
67 unsigned char serialNoiseErrors; ///< Incremented when noise is detected
68 unsigned char serialFramingErrors; ///< Incremented when a framing error occurs
69 unsigned char serialParityErrors; ///< Incremented when a parity error occurs
70 #define FLAG_SERIAL_NOISE_ERRORS_OFFSET 5
71 #define FLAG_SERIAL_FRAMING_ERRORS_OFFSET 6
72 #define FLAG_SERIAL_PARITY_ERRORS_OFFSET 7
74 // This is caused by heavy interrupt load delaying serial servicing, just a fact of life at high RPM.
75 unsigned char serialOverrunErrors; ///< Incremented when overrun occurs (duplicated in KeyUserDebug below)
76 #define FLAG_SERIAL_OVERRUN_ERRORS_OFFSET 8
78 // These can be caused by noise, but if there is no noise, then it's a code issue with the PC side application
79 unsigned char serialEscapePairMismatches; ///< Incremented when an escape is found but not followed by an escapee
80 unsigned char serialStartsInsideAPacket; ///< Incremented when a start byte is found inside a packet
81 unsigned char serialPacketsOverLength; ///< Incremented when the buffer fills up before the end
82 unsigned char serialChecksumMismatches; ///< Incremented when calculated checksum did not match the received one
83 unsigned char serialPacketsUnderLength; ///< Incremented when a packet is found that is too short
84 #define FLAG_SERIAL_ESCAPE_PAIR_MISMATCHES_OFFSET 9
85 #define FLAG_SERIAL_STARTS_INSIDE_A_PACKET_OFFSET 10
86 #define FLAG_SERIAL_PACKETS_OVER_LENGTH_OFFSET 11
87 #define FLAG_SERIAL_CHECKSUM_MISMATCHES_OFFSET 12
88 #define FLAG_SERIAL_PACKETS_UNDER_LENGTH_OFFSET 13
90 // Not currently used
91 unsigned char commsDebugMessagesNotSent; ///< Incremented when a debug message can't be sent due to the TX buffer
92 unsigned char commsErrorMessagesNotSent; ///< Incremented when an error message can't be sent due to the TX buffer
93 #define FLAG_COMMS_DEBUG_MESSAGES_NOT_SENT_OFFSET 14
94 #define FLAG_COMMS_ERROR_MESSAGES_NOT_SENT_OFFSET 15
95 } Flaggable;
98 /// Use this block to manage the various clocks kept.
99 typedef struct {
100 /* Real Time and other Clocks (all require init to zero) */
101 unsigned short realTimeClockMain; ///< Variable to count RTI executions, 0.125ms exactly
102 unsigned short realTimeClockMillis; ///< Variable to count milliseconds exactly
103 unsigned short realTimeClockTenths; ///< Variable to count tenths of a second exactly
104 unsigned short realTimeClockSeconds; ///< Variable to count seconds exactly
105 unsigned short realTimeClockMinutes; ///< Variable to count minutes exactly
107 unsigned short millisToTenths; ///< Roll-over variable for counting tenths
108 unsigned short tenthsToSeconds; ///< Roll-over variable for counting seconds
109 unsigned short secondsToMinutes; ///< Roll-over variable for counting minutes
111 unsigned short timeoutADCreadingClock; ///< Timeout clock/counter for synced ADC readings
112 } Clock;
115 /// Use this block to manage the execution count of various functions loops and ISRs etc. TODO break this up into smaller chunks
116 typedef struct {
117 // Scheduling
118 unsigned char normalSchedule; ///< times events were scheduled normally.
119 unsigned char timerStretchedToSchedule; ///< times timer needed to be extended to prevent not scheduling.
121 // Decoder scheduling
122 unsigned char pinScheduledToGoHigh; ///< Behaviour chosen from decoder based on register and pin state.
123 unsigned char pinScheduledAlready; ///< @copydoc pinScheduledToGoHigh
124 unsigned char pinScheduledToSelfSchedule; ///< @copydoc pinScheduledToGoHigh
125 unsigned char pinScheduledAgainToStayOn; ///< @copydoc pinScheduledToGoHigh
127 unsigned char pinScheduledToToggleError; ///< @copydoc pinScheduledToGoHigh
128 unsigned char pinScheduledToDoNothing; ///< @copydoc pinScheduledToGoHigh
129 unsigned char pinScheduledFromCold; ///< @copydoc pinScheduledToGoHigh
130 unsigned char pinScheduledWithTimerExtension; ///< @copydoc pinScheduledToGoHigh
132 // Outputs, refactor to not say "injector" later.
133 unsigned char injectorSwitchOns; ///< number of times the injector switched on
134 unsigned char injectorSwitchOffs; ///< number of times the injector switched off to stay off
135 unsigned char injectorTimerExtensions; ///< number of times the injector ISR fired and rescheduled itself to fire and do nothing again
136 unsigned char injectorTimerExtensionFinals; ///< number of times the injector ISR fired and scheduled the injector to switch on
138 unsigned char injectorSelfSchedules; ///< number of times the injector switched off and scheduled itself again
139 unsigned char injectorSelfScheduleExtensions; ///< number of times the injector switched off and scheduled itself again with timer extension
141 unsigned char syncedADCreadings; ///< Incremented each time a synchronous ADC reading is taken
142 unsigned char timeoutADCreadings; ///< Incremented for each ADC reading in RTC because of timeout
143 unsigned char calculationsPerformed; ///< Incremented for each time the fuel and ign calcs are done
145 unsigned char sparePadding; ///< Replace with something useful
146 } Counter;
149 #else
150 /* let us know if we are being untidy with headers */
151 #warning "Header file COUNTER_TYPES_H seen before, sort it out!"
152 /* end of the wrapper ifdef from the very top */
153 #endif