Sat, 21 Oct 2023 19:04:52 +0200
Change colors and intensity.
1
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @file task_dcf.c |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * @brief DCF77 task. |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | */ |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | #include "dcf77tx.h" |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | static const char *TAG = "task_dcf"; |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | SemaphoreHandle_t xSemaphoreDCF = NULL; ///< Semaphore DCF task. |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | EventGroupHandle_t xEventGroupDCF; ///< Events DCF task. |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | DCF_State *dcf_state = NULL; ///< Public state for other tasks. |
2 | 16 | esp_timer_handle_t timerHandle; ///< Timer handler |
17 | int impulseCount = 0; ///< 100 mSec transmit slices. | |
18 | int8_t impulseArray[61]; ///< Pulses, 0 = no pulse, 1=100ms, 2=200ms | |
19 | int actualSecond = 0; ///< Current second to transmit. | |
20 | time_t dcf_now; ///< Current time to send. | |
21 | struct tm dcf_tm; ///< Local broken down time. | |
4
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
22 | |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
23 | |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
24 | ledc_timer_config_t ledc_timer = { |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
25 | .speed_mode = LEDC_LOW_SPEED_MODE, ///< Use high speed timer |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
26 | .timer_num = LEDC_TIMER_0, ///< Timer 0 |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
27 | .duty_resolution = LEDC_TIMER_10_BIT, ///< 10 bits resolution |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
28 | .freq_hz = 77500, ///< 77.5 KHz |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
29 | .clk_cfg = LEDC_AUTO_CLK ///< Auto select PWM clock |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
30 | }; |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
31 | |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
32 | ledc_channel_config_t dcf77_100tx = { ///< 100% Antenna power |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
33 | .channel = LEDC_CHANNEL_0, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
34 | .duty = 0, ///< Default 0% |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
35 | .gpio_num = CONFIG_ANTENNA_100_PIN, ///< Antenna pin 100% |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
36 | .speed_mode = LEDC_LOW_SPEED_MODE, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
37 | .hpoint = 0, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
38 | .intr_type = LEDC_INTR_DISABLE, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
39 | .timer_sel = LEDC_TIMER_0 ///< Timer 0 |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
40 | }; |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
41 | ledc_channel_config_t dcf77_15tx = { ///< 15% Antenna power |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
42 | .channel = LEDC_CHANNEL_1, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
43 | .duty = 0, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
44 | .gpio_num = CONFIG_ANTENNA_15_PIN, ///< Antenna pin 15% |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
45 | .speed_mode = LEDC_LOW_SPEED_MODE, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
46 | .hpoint = 0, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
47 | .intr_type = LEDC_INTR_DISABLE, |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
48 | .timer_sel = LEDC_TIMER_0 ///< Timer 0 |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
49 | }; |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
50 | |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
51 | |
2 | 52 | extern bool System_TimeOk; |
53 | ||
1
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | #define LED1 CONFIG_LED1_PIN |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | #define LED2 CONFIG_LED2_PIN |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | const int TASK_DCF_REQUEST_START = BIT0; |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | const int TASK_DCF_REQUEST_STOP = BIT1; |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | const int TASK_DCF_RUN = BIT2; |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | bool ready_DCF(void) |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | { |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | return dcf_state->DCF_running; |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | } |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | void request_DCF(bool run) |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | { |
2 | 74 | ESP_LOGI(TAG, "request_DCF(%s)", run ? "start":"stop"); |
75 | ||
76 | if (run) | |
77 | xEventGroupSetBits(xEventGroupDCF, TASK_DCF_REQUEST_START); | |
78 | else | |
79 | xEventGroupSetBits(xEventGroupDCF, TASK_DCF_REQUEST_STOP); | |
80 | } | |
81 | ||
82 | ||
83 | int bin2bcd(int data) | |
84 | { | |
85 | int msb, lsb; | |
86 | ||
87 | if (data < 10) | |
88 | return data; | |
89 | msb = (data / 10) << 4; | |
90 | lsb = data % 10; | |
91 | return msb + lsb; | |
92 | } | |
93 | ||
94 | ||
95 | static void DCFout(void* arg); | |
96 | void DCFout(void* arg) | |
97 | { | |
3 | 98 | int i; |
99 | static int tmp, tmpin, parity = 0; | |
2 | 100 | |
101 | switch (impulseCount++) { | |
102 | case 0: if (actualSecond == 0) { | |
103 | time(&dcf_now); | |
104 | dcf_now += 60; | |
105 | } | |
4
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
106 | /* Carrier to 15% */ |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
107 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
108 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
109 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 512); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
110 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
3 | 111 | if (impulseArray[actualSecond] == 1) { |
6 | 112 | set_ob_led(0, 5, 5); |
3 | 113 | } else if (impulseArray[actualSecond] == 2) { |
6 | 114 | set_ob_led(5, 5, 0); |
2 | 115 | } |
116 | break; | |
117 | case 1: if (impulseArray[actualSecond] == 1) { | |
4
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
118 | /* Carrier back to 100% */ |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
119 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 512); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
120 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
121 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
122 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
6 | 123 | set_ob_led(0, 1, 0); |
2 | 124 | } |
125 | break; | |
4
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
126 | case 2: /* Carrier back to 100% */ |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
127 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 512); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
128 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
129 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
130 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
6 | 131 | set_ob_led(0, 1, 0); |
2 | 132 | break; |
133 | case 9: impulseCount = 0; | |
134 | /* | |
135 | * To spread the CPU load, we set all bits during the first seconds | |
136 | * because we don't use these bits. | |
137 | */ | |
138 | switch (actualSecond) { | |
4
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
139 | case 0: /* |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
140 | * Bit 0 is always 0. |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
141 | * Bits 1..14 are used to transmit weather information. |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
142 | * Just some fixed values here. |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
143 | * Bit 15, Antenna bit. 0 = normal operation, 1 = fault |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
144 | */ |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
145 | for (i = 0; i < 16; i++) |
2 | 146 | impulseArray[i] = 1; |
147 | break; | |
148 | case 1: localtime_r(&dcf_now, &dcf_tm); | |
149 | char strftime_buf[64]; | |
150 | strftime(strftime_buf, sizeof(strftime_buf), "%c", &dcf_tm); | |
151 | ESP_LOGI(TAG, "The current date/time to send is: %s", strftime_buf); | |
152 | break; | |
153 | case 2: /* DST bits */ | |
154 | if (dcf_tm.tm_isdst == 0) { | |
3 | 155 | impulseArray[17] = 1; /* Set when DST is in effect. */ |
156 | impulseArray[18] = 2; /* Set when DST is not in effect. */ | |
2 | 157 | } else { |
158 | impulseArray[17] = 2; | |
159 | impulseArray[18] = 1; | |
160 | } | |
3 | 161 | /* Start of encoded time. Always set */ |
2 | 162 | impulseArray[20] = 2; |
163 | break; | |
3 | 164 | case 3: /* announce DST on-off bit 16 */ |
165 | int month = dcf_tm.tm_mon + 1; | |
166 | bool announce = false; | |
167 | if (dcf_tm.tm_mday >= 25 || dcf_tm.tm_wday == 0) { | |
168 | /* Last sunday in the month */ | |
169 | if (month == 3) { | |
170 | if (dcf_tm.tm_isdst == 0 && dcf_tm.tm_hour == 1 && dcf_tm.tm_min != 0) { | |
171 | announce = true; /* Wintertime to summertime */ | |
172 | } | |
173 | } else if (month == 10) { | |
174 | if (dcf_tm.tm_isdst > 0 && dcf_tm.tm_hour == 1 && dcf_tm.tm_min != 0) { | |
175 | announce = true; /* Summertime to wintertime */ | |
176 | } | |
177 | } | |
178 | } | |
179 | ESP_LOGI(TAG, "%d announce TZ change %s", dcf_tm.tm_isdst, announce ? "true":"false"); | |
180 | impulseArray[16] = (announce) ? 2:1; | |
181 | break; | |
182 | case 4: /* | |
183 | * We don't announce the leap second. It is not always sure when this will | |
184 | * happen, possible at end of 2023, but it is not sure. And the next? | |
185 | * SNTP timesync will deal with this and we will see a timejump. | |
186 | */ | |
187 | break; | |
188 | case 5: tmpin = bin2bcd(dcf_tm.tm_min); | |
2 | 189 | parity = 0; |
190 | for (i = 21; i < 28; i++) { | |
3 | 191 | tmp = tmpin & 1; |
192 | impulseArray[i] = tmp + 1; | |
193 | parity += tmp; | |
194 | tmpin >>= 1; | |
195 | } | |
196 | impulseArray[28] = (parity & 1) ? 2:1; | |
197 | ESP_LOGI(TAG, "minute %d%d%d%d%d%d%d P1 %d", impulseArray[21], impulseArray[22], impulseArray[23], | |
198 | impulseArray[24], impulseArray[25], impulseArray[26], impulseArray[27], impulseArray[28]); | |
199 | break; | |
200 | case 6: tmpin = bin2bcd(dcf_tm.tm_hour); | |
201 | parity = 0; | |
202 | for (i = 29; i < 35; i++) { | |
203 | tmp = tmpin & 1; | |
2 | 204 | impulseArray[i] = tmp + 1; |
205 | parity += tmp; | |
3 | 206 | tmpin >>= 1; |
207 | } | |
208 | impulseArray[35] = (parity & 1) ? 2:1; | |
209 | ESP_LOGI(TAG, "hour %d%d%d%d%d%d P2 %d", impulseArray[29], impulseArray[30], impulseArray[31], | |
210 | impulseArray[32], impulseArray[33], impulseArray[34], impulseArray[35]); | |
211 | break; | |
212 | case 7: tmpin = bin2bcd(dcf_tm.tm_mday); | |
213 | parity = 0; | |
214 | for (i = 36; i < 42; i++) { | |
215 | tmp = tmpin & 1; | |
216 | impulseArray[i] = tmp + 1; | |
217 | parity += tmp; | |
218 | tmpin >>= 1; | |
2 | 219 | } |
3 | 220 | ESP_LOGI(TAG, "mday %d%d%d%d%d%d", impulseArray[36], impulseArray[37], impulseArray[38], |
221 | impulseArray[39], impulseArray[40], impulseArray[41]); | |
222 | break; | |
223 | case 8: tmpin = bin2bcd(dcf_tm.tm_wday); | |
224 | if (tmpin == 0) | |
225 | tmpin = 7; | |
226 | for (i = 42; i < 45; i++) { | |
227 | tmp = tmpin & 1; | |
228 | impulseArray[i] = tmp + 1; | |
229 | parity += tmp; | |
230 | tmpin >>= 1; | |
231 | } | |
232 | ESP_LOGI(TAG, "wday %d%d%d", impulseArray[42], impulseArray[43], impulseArray[44]); | |
2 | 233 | break; |
3 | 234 | case 9: tmpin = bin2bcd(dcf_tm.tm_mon + 1); |
235 | for (i = 45; i < 50; i++) { | |
236 | tmp = tmpin & 1; | |
237 | impulseArray[i] = tmp + 1; | |
238 | parity += tmp; | |
239 | tmpin >>= 1; | |
240 | } | |
241 | ESP_LOGI(TAG, "month %d%d%d%d%d", impulseArray[45], impulseArray[46], impulseArray[47], | |
242 | impulseArray[48], impulseArray[49]); | |
243 | break; | |
244 | case 10: tmpin = bin2bcd(dcf_tm.tm_year - 100); | |
245 | for (int i = 50; i < 58; i++) { | |
246 | tmp = tmpin & 1; | |
247 | impulseArray[i] = tmp + 1; | |
248 | parity += tmp; | |
249 | tmpin >>= 1; | |
250 | } | |
251 | impulseArray[58] = (parity & 1) ? 2:1; | |
252 | ESP_LOGI(TAG, "year %d%d%d%d%d%d%d%d P3 %d", impulseArray[50], impulseArray[51], impulseArray[52], | |
253 | impulseArray[53], impulseArray[54], impulseArray[55], impulseArray[56], impulseArray[57], impulseArray[58]); | |
254 | break; | |
2 | 255 | } |
256 | if (actualSecond < 59) /* Can include leap second */ | |
257 | actualSecond++; | |
258 | break; | |
259 | } | |
260 | ||
261 | if (actualSecond >= 59) { | |
262 | time_t now = time(NULL); | |
263 | localtime_r(&now, &dcf_tm); | |
264 | if (dcf_tm.tm_sec == 0) { | |
265 | actualSecond = impulseCount = 0; | |
266 | } | |
267 | } | |
1
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
268 | } |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | void task_DCF(void *pvParameters) |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
273 | { |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | ESP_LOGI(TAG, "Starting DCF77"); |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
275 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | xEventGroupDCF = xEventGroupCreate(); |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
277 | xSemaphoreDCF = xSemaphoreCreateMutex(); |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
278 | dcf_state = malloc(sizeof(DCF_State)); |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | memset(dcf_state, 0x00, sizeof(DCF_State)); |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
280 | |
2 | 281 | esp_timer_create_args_t timerDCF = { |
282 | .callback = &DCFout, | |
283 | .name = "DCF timer" | |
284 | }; | |
4
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
285 | ESP_ERROR_CHECK(esp_timer_create(&timerDCF, &timerHandle)); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
286 | |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
287 | /* |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
288 | * Prepare the LEDC PWM channels |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
289 | */ |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
290 | ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer)); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
291 | ESP_ERROR_CHECK(ledc_channel_config(&dcf77_100tx)); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
292 | ESP_ERROR_CHECK(ledc_channel_config(&dcf77_15tx)); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
293 | ESP_LOGI(TAG, "DCF77 antennas at pins %d and %d", CONFIG_ANTENNA_100_PIN, CONFIG_ANTENNA_15_PIN); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
294 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
295 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
296 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); |
426defedd402
Added 77.5 KHz signal generation
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
297 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
2 | 298 | |
299 | for (int i = 0; i < 59; i++) | |
300 | impulseArray[i] = 1; | |
301 | impulseArray[59] = impulseArray[60] = 0; | |
302 | ||
1
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
303 | xEventGroupClearBits(xEventGroupDCF, TASK_DCF_RUN); |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
304 | EventBits_t uxBits; |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
305 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | for (;;) { |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | uxBits = xEventGroupWaitBits(xEventGroupDCF, TASK_DCF_REQUEST_START | TASK_DCF_REQUEST_STOP, pdFALSE, pdFALSE, portMAX_DELAY ); |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | if (uxBits & TASK_DCF_REQUEST_START) { |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | if (dcf_state->DCF_running) { |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | /* Already running */ |
2 | 312 | } else { |
313 | actualSecond = 0; | |
314 | impulseCount = 0; | |
315 | esp_timer_start_periodic(timerHandle, 100000); | |
316 | dcf_state->DCF_running = true; | |
1
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | } |
2 | 318 | xEventGroupClearBits(xEventGroupDCF, TASK_DCF_REQUEST_START); |
1
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | } else if (uxBits & TASK_DCF_REQUEST_STOP) { |
2 | 321 | esp_timer_stop(timerHandle); |
1
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
322 | } |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
323 | } /* for(;;) */ |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
324 | } |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
325 | |
86b275481021
Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
326 |