annotate Small_CPU/Src/wireless.c @ 92:be35821a4974 kittz

Stable to test. button sensitiveness fix. + global_constants.
author Dmitry Romanov <kitt@bk.ru>
date Mon, 26 Nov 2018 10:50:39 +0300
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file wireless.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @date 02-July-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @version V0.0.2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @since 24-March-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @brief Data transfer via magnetic field using Manchester code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 history:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 160324 V 0.0.2 für Bonex Sender (Only in old hardware. No longer supported)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 PA2 triggers to falling edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 PA1 triggers to rising edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 see baseCPU2.c definitions of ports for details
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 time base is the systick of CMSIS with SysTick->VAL for sub ms info
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 start id is 4 ms low (fall to rise time)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 old: followed by 2 ms high (but can continue with high on sending '0' next (Hi->Lo)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 160324: followed by bit 0: high to low of byte 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 even index numbers are falling edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 odd index numbers are rising edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 first bit ('1' or '0' can be evaluated with triggerTimeDiffArray[2] (falling edge)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 if it is much longer than 2ms than the first bit is '0'
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 if it is 2ms than it is '1'
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 // Manchester code: 1 = low to high; 0 = high to low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 bits are either
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 rising edge at the middle of the bit transfer -> 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 falling edge at the middle of the bit transfer -> 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 an array is used with even index for falling and odd for rising
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 the next time difference array entry is set to 0 to identify the loss of any edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 the time index is stored as microseconds
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 and generated by systick and SysTick->VAL (that is counting down from ->LOAD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 old: startTime is the first falling edge, hence the ver first falling edge of the start byte)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 160324: startTime is the first rising edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 160324: total transfer time (excluding start with 8 ms) 10*8*2ms + 2ms (stop bit) = 162 ms
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 Definition: first bit is always '0'
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 old: to recognize second start bit easily!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 old: hence after 2 ms there is a falling edge!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 160324: after 1 ms is a falling edge of first bit with value 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 160324:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 Measurement of send data: length 162 ms including stop bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 81 bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 * <h2><center>&copy; COPYRIGHT(c) 2016 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 #include "wireless.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 #include "scheduler.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 /* array starts with first falling edge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 * old: beginning of first start byte,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 * old: data starts on 3
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 * new: beginning of first bit that is always 0 -> high->low
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 * new: data starts on 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 #define ttdaSize (1200)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 #define TIMEOUTSIZE (20000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 #define WIRELESS_OK (0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 #define WIRELESS_FAIL (1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 #define FALLING (0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 #define RISING (1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 //#define STEP_HALFBIT (1010)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 #define STEP_HALFBIT (1000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 #define LIMIT_STARTBIT (5000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 #define MIN_TIME_STARTBIT (3800)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 #define MAX_TIME_FIRST_STARTBIT (5200)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 #define MIN_TIME_BOTH_STARTBITS (MIN_TIME_STARTBIT + MIN_TIME_STARTBIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 #define MAX_TIME_BOTH_STARTBITS (MAX_TIME_FIRST_STARTBIT + 4200)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 // includes necessary start bit (2000 us) and timing issues
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 #define HELPER_MAX_DATA_LENGTH_TOLERANCE (10*STEP_HALFBIT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 #define HELPER_MAX_DATA_BYTES (10) ///< 160324: 10, before 8
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 #define MAX_DATA_BITS (HELPER_MAX_DATA_BYTES*8)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 #define MAX_DATA_LENGTH ((STEP_HALFBIT*2*MAX_DATA_BITS) + HELPER_MAX_DATA_LENGTH_TOLERANCE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 #define MAX_DIFF_IN_MS ((MAX_DATA_LENGTH+999)/1000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 void wireless_reset(uint32_t timeMain, uint32_t timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 /* triggerTimeDiffArray in us with max 65 ms */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 int32_t triggerNewArray[ttdaSize][2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 int32_t triggerNewArrayDebugStartBits[20][2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 //uint16_t triggerTimeDiffArray[ttdaSize];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 uint16_t ttdaPointer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 uint32_t startTimeMain;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 uint32_t subDivisorX1000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 uint8_t blockDataCapture = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 uint8_t evaluateRequest = 0; ///<
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 uint8_t found_first_4ms_high = 0; ///<
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 uint8_t found_second_4ms_low = 0; ///<
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 // wireless_init
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 /// @brief has to be called once to initialize the variables
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 void wireless_init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 subDivisorX1000 = SysTick->LOAD; ///< never changes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 wireless_reset(0,0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 ttdaPointer = 0; ///< is set back again by timeout or on error
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 blockDataCapture = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 //triggerTimeDiffArray[0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * @brief RECORDING functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * @date 03-July-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * @since 03-July-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 // wireless_getTime
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 void wireless_getTime(uint32_t *timeMain, uint32_t *timeSub)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 uint32_t timeSub2, timeMain2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 *timeSub = SysTick->VAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 *timeMain = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 timeSub2 = SysTick->VAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 timeMain2 = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 static uint32_t difference = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 if(ttdaPointer == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 difference = 7; //& breakpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 if((timeSub2 > *timeSub) && (timeMain2 == *timeMain))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 *timeMain -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 *timeSub = subDivisorX1000 - *timeSub;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 *timeSub *= 1000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 *timeSub /= subDivisorX1000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 /* stored value _could be_ in multiples of 2 us
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 * to have 1000 for each byte
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 * 0000 is beginning of start bit (always 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 * 1000 is beginning of first bit (if timing is perfect, otherwise less or more)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 * ...
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 * XXXX000 is beginning of XXXX bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 // wireless_time0keeper
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 /// @return still in us
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 int32_t wireless_time0keeper(uint8_t store1_or_diffOut0, uint32_t timeMain, uint32_t timeSub)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 static uint32_t storeMain = 0, storeSub = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 /* store time0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 if(store1_or_diffOut0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 storeMain = timeMain;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 storeSub = timeSub;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 /* evaluate time difference */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 int32_t diff = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 if((timeMain < storeMain) || ((timeMain - storeMain) > MAX_DIFF_IN_MS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 return -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 diff = timeMain - storeMain;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 diff *= 1000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 diff += timeSub;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 diff -= storeSub;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 return diff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 // wireless_save_time0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 void wireless_save_time0(uint32_t timeMain, uint32_t timeSub)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 wireless_time0keeper(1, timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 // wireless_get_time_since_time0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 int32_t wireless_get_time_since_time0(uint32_t timeMain, uint32_t timeSub)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 return wireless_time0keeper(0, timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 // wireless_get_time_since_previous
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 int32_t wireless_get_time_since_previous(uint8_t fallingOrRising, uint32_t timeMain, uint32_t timeSub)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 int32_t absoluteTimeDiff = wireless_time0keeper(0, timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 if(fallingOrRising == FALLING) // same array
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 return (absoluteTimeDiff - triggerNewArray[ttdaPointer][FALLING]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 if(ttdaPointer > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 return (absoluteTimeDiff - triggerNewArray[ttdaPointer - 1][RISING]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 else // not possible
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 return -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 // wireless_reset
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 void wireless_reset(uint32_t timeMain, uint32_t timeSub)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 found_first_4ms_high = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 found_second_4ms_low = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 ttdaPointer = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 startTimeMain = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 evaluateRequest = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 wireless_save_time0(timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 triggerNewArray[ttdaPointer][FALLING] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 triggerNewArray[ttdaPointer][RISING] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 // wireless_trigger_FallingEdgeSignalHigh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 void wireless_trigger_FallingEdgeSignalHigh(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 uint32_t timeSub, timeMain;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 int32_t timeDifference;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 wireless_getTime(&timeMain, &timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 if((blockDataCapture) || (evaluateRequest == 1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 if(evaluateRequest == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 wireless_reset(0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 if(!found_first_4ms_high) // trying to get first start 4ms
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 if(ttdaPointer == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 wireless_reset(timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 if((timeDifference > 0) && (timeDifference <= LIMIT_STARTBIT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 triggerNewArray[ttdaPointer][0] = timeDifference;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 wireless_reset(timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 else // here comes the very important time0 for all following data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 if(!found_second_4ms_low) ///< the beginning of the very first is recorded here :-)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 if((timeDifference > 0) && (timeDifference >= MIN_TIME_BOTH_STARTBITS) && (timeDifference <= MAX_TIME_BOTH_STARTBITS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 // now we are ready for data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 for(int i=0;i<20;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 if(i <= ttdaPointer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 triggerNewArrayDebugStartBits[i][FALLING] = triggerNewArray[i][FALLING];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 triggerNewArrayDebugStartBits[i][RISING] = triggerNewArray[i][FALLING];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 triggerNewArrayDebugStartBits[i][FALLING] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 triggerNewArrayDebugStartBits[i][RISING] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 wireless_reset(timeMain, timeSub); ///< reset all including ttdaPointer and more
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 startTimeMain = timeMain; ///< set again
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 found_first_4ms_high = 1; ///< set again
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 found_second_4ms_low = 1; ///< set now: ready for recording
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 if((timeDifference > MAX_DATA_LENGTH) || (ttdaPointer > (ttdaSize - 2)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 evaluateRequest = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 triggerNewArray[ttdaPointer][FALLING] = timeDifference;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 triggerNewArray[ttdaPointer][RISING] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 // wireless_trigger_RisingEdgeSilence
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 void wireless_trigger_RisingEdgeSilence(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 uint32_t timeSub, timeMain;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 int32_t timeDifference;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 wireless_getTime(&timeMain, &timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 if((blockDataCapture) || (evaluateRequest == 1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 if(evaluateRequest == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 wireless_reset(0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 return; // Falling Edge first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 if(!found_first_4ms_high)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 if((timeDifference > 0) && (timeDifference <= MAX_TIME_FIRST_STARTBIT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 triggerNewArray[ttdaPointer++][RISING] = timeDifference;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 triggerNewArray[ttdaPointer][FALLING] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 if(timeDifference >= MIN_TIME_STARTBIT) ///< start bit is the 4 ms
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 found_first_4ms_high = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 found_second_4ms_low = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 if((timeDifference > MAX_DATA_LENGTH) || (ttdaPointer > (ttdaSize - 2)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 evaluateRequest = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 triggerNewArray[ttdaPointer++][RISING] = timeDifference;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 triggerNewArray[ttdaPointer][FALLING] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 // wireless_position_next
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 uint8_t wireless_position_next(uint16_t *ttdaPointerNow, uint8_t *typeNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 if(*typeNow == FALLING)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 *typeNow = RISING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 else if(*ttdaPointerNow < (ttdaSize - 1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 *ttdaPointerNow += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 *typeNow = FALLING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 return WIRELESS_FAIL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 return WIRELESS_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 // wireless_position_previous
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 uint8_t wireless_position_previous(uint16_t *ttdaPointerNow, uint8_t *typeNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 if(*typeNow == RISING)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 *typeNow = FALLING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 else if(*ttdaPointerNow > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 *ttdaPointerNow -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 *typeNow = RISING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 return WIRELESS_FAIL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 return WIRELESS_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 // wireless_position_compare
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 /// @brief RECORDING
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 int8_t wireless_position_compare(uint16_t ttdaPointerLeft, uint8_t typeLeft, uint16_t ttdaPointerRight, uint8_t typeRight)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 if(ttdaPointerLeft < ttdaPointerRight)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 return -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 if(ttdaPointerLeft > ttdaPointerRight)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 if(typeLeft < typeRight)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 return -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 if(typeLeft > typeRight)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 // wireless_debug
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 /// @brief
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 /* outlined because of errors while compiling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 void wireless_debug(int8_t *adcData, uint16_t max_size_adc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 // debug
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 uint32_t dataVisual[201];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 uint8_t dataVisualValue[201];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 int8_t dataVisualResult[201];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 dataVisualValue[0] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 for(int i=0;i<201;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 dataVisualResult[i] = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 for(int i=0;i<201-4;i +=4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 dataVisualValue[i] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 dataVisualValue[i+1] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 dataVisualValue[i+2] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 dataVisualValue[i+3] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 dataVisual[0] = triggerNewArray[0][FALLING];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 int j = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 uint32_t valueStore = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 for(int i=0;i<50;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 valueStore = triggerNewArray[i][FALLING];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 dataVisual[j++] = valueStore;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 dataVisual[j++] = valueStore + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 valueStore = triggerNewArray[i][RISING];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 dataVisual[j++] = valueStore;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 dataVisual[j++] = valueStore + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 if(max_size_adc > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 int jStep = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 int jData = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 for(int i=0;i<201;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 if(dataVisual[i] >= jStep)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 if(adcData[jData] > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 dataVisualResult[i] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 dataVisualResult[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 jStep += STEP_HALFBIT + STEP_HALFBIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 jData++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 if(jData >= max_size_adc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 // wireless_debug_test_failed_AACCF1010203
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 /// @brief
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 uint8_t wireless_debug_test_failed_AACCF1010203(uint8_t *data)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 if(data[0] != 0xAA)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 if(data[1] != 0xCC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 if(data[2] != 0xF1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 if(data[3] != 0x01)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 if(data[4] != 0x02)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 if(data[5] != 0x03)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 // wireless_check_crc_failed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 /// @brief
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 uint8_t wireless_check_crc_failed(uint8_t *dataOut, uint8_t maxData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 return (wireless_debug_test_failed_AACCF1010203(dataOut));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 * @brief EVALUATION functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 * @date 03-July-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 * @version V0.0.2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 * @since 14-July-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 // wireless_time0keeper
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 /// @brief EVALUATION
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 uint8_t wireless_evaluate_internal_loop(uint8_t *dataOut, uint8_t maxData, int32_t shift, uint8_t *confidence)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 // variables
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 int iOut = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 int jAdc = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 int8_t adcData[MAX_DATA_BITS];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 uint16_t adcPointer = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 int8_t bitLeft = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 int8_t bitRight = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 uint16_t ttdaPointerStart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 uint16_t ttdaPointerEnd = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 uint8_t typeStart = RISING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 uint8_t typeEnd = RISING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 int32_t startTimeHalfBit = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 int32_t endTimeHalfBit = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 int32_t startOfThisPeak = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 int32_t endOfThisPeak = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 uint8_t wirelessErrorStatus = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 uint8_t timeToStop = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 int32_t valueSingle = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 int32_t halfbitTemp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 int confidenceTemp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 // safety end for all loops coming
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 triggerNewArray[ttdaPointer][RISING] = INT32_MAX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 ttdaPointerStart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 ttdaPointerEnd = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 typeStart = RISING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 typeEnd = RISING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 startTimeHalfBit = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 endTimeHalfBit = shift;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 adcPointer = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 while(!timeToStop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 // start is latest start
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 ttdaPointerEnd = ttdaPointerStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 typeEnd = typeStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 for(int doItTwice=0;doItTwice<2;doItTwice++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 startTimeHalfBit = endTimeHalfBit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 endTimeHalfBit += STEP_HALFBIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 // find the end for this half bit; this will include values that continue to the next halfbit and negative values
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 while(triggerNewArray[ttdaPointerEnd][typeEnd] < endTimeHalfBit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 wireless_position_next(&ttdaPointerEnd,&typeEnd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 if(triggerNewArray[ttdaPointerEnd][typeEnd] == INT32_MAX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 timeToStop = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 startOfThisPeak = startTimeHalfBit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 wirelessErrorStatus = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 halfbitTemp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 while(!wirelessErrorStatus && (wireless_position_compare(ttdaPointerStart,typeStart, ttdaPointerEnd,typeEnd) <= 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 endOfThisPeak = triggerNewArray[ttdaPointerStart][typeStart];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 if(endOfThisPeak <= startOfThisPeak)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 wireless_position_next(&ttdaPointerStart,&typeStart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 // TODO: what about time difference errors?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 if(endOfThisPeak >= endTimeHalfBit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 valueSingle = endTimeHalfBit - startOfThisPeak;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 valueSingle = endOfThisPeak - startOfThisPeak;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 if(typeStart == RISING)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 halfbitTemp += valueSingle;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 // next, also valid for every next halfbit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 if(endOfThisPeak <= endTimeHalfBit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 startOfThisPeak = endOfThisPeak;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 wireless_position_next(&ttdaPointerStart,&typeStart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 startOfThisPeak = endTimeHalfBit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 // should not be necessary, anyway
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 if(startOfThisPeak == endTimeHalfBit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 // store
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 halfbitTemp *= 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 halfbitTemp /= STEP_HALFBIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 if(halfbitTemp > 100) halfbitTemp = 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 if(doItTwice == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 bitLeft = halfbitTemp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 bitRight = halfbitTemp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 // Gewichtung und Bit Generierung
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 adcData[adcPointer++] = (int8_t)((bitLeft - bitRight)); // possitive value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 if(adcPointer >= MAX_DATA_BITS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 timeToStop = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 // Auswertung
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 jAdc = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 iOut = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 for(int i=0;i<maxData;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 dataOut[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 for(int j=0;j<8;j++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 dataOut[i] *= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 if((adcData[jAdc++] > 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 dataOut[i] |= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 if(jAdc >= adcPointer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 j++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 while(j<8)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 jAdc = adcPointer + 1; // end signal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 dataOut[i] *= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 j++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 if(jAdc > adcPointer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 iOut++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 confidenceTemp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 for(int i=0;i<adcPointer;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 if(adcData[i] < 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 confidenceTemp -= adcData[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 confidenceTemp += adcData[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 // confidence in adcData is 0 to 127 only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 confidenceTemp *= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 *confidence = (uint8_t)(confidenceTemp/adcPointer);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 if( (iOut>= 5) && wireless_debug_test_failed_AACCF1010203(dataOut))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 wireless_debug(adcData,MAX_DATA_BITS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 return iOut;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 // wireless_evaluate_crc_error
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 /// @brief EVALUATION
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 uint8_t wireless_evaluate_crc_error(uint8_t *dataIn, uint8_t maxData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 uint8_t crcTest = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 for(int i=0; i< maxData; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 crcTest ^= dataIn[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 return crcTest;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 // wireless_evaluate
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 /// @brief EVALUATION
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 /// @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 /// @return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 uint8_t wireless_evaluate(uint8_t *dataOut, uint8_t maxData, uint8_t *confidence)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 uint32_t timeTick;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 uint32_t timeElapsed;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 timeTick = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 timeElapsed = time_elapsed_ms(startTimeMain,timeTick);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 uint8_t start = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 int iOut = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 // check condition for start
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 if(evaluateRequest == 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 if(evaluateRequest == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 start = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 if((ttdaPointer > 10) && (timeElapsed > (MAX_DATA_LENGTH/1000)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 start = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 if(!start)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 // start
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 blockDataCapture = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 // evaluate
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 iOut = wireless_evaluate_internal_loop(dataOut, maxData, 0, confidence);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 for(int i=0; i>=-500; i -= 100)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 iOut = wireless_evaluate_internal_loop(dataOut, maxData, i, confidence);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 if(iOut < 5)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 if(wireless_check_crc_failed(dataOut,iOut) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 // end
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 evaluateRequest = 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 blockDataCapture = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 return iOut;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/