main/task_dcf.c

Fri, 20 Oct 2023 20:29:52 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 20 Oct 2023 20:29:52 +0200
changeset 2
053649608c09
parent 1
86b275481021
child 3
849ca14d4a2f
permissions
-rw-r--r--

Begin coding transmit bits.

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
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
16 esp_timer_handle_t timerHandle; ///< Timer handler
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
17 int impulseCount = 0; ///< 100 mSec transmit slices.
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
18 int8_t impulseArray[61]; ///< Pulses, 0 = no pulse, 1=100ms, 2=200ms
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
19 int actualSecond = 0; ///< Current second to transmit.
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
20 time_t dcf_now; ///< Current time to send.
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
21 struct tm dcf_tm; ///< Local broken down time.
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
22 ///
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
23 extern bool System_TimeOk;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
24
1
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 #define LED1 CONFIG_LED1_PIN
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #define LED2 CONFIG_LED2_PIN
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 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
31 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
32
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 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
34
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 bool ready_DCF(void)
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 {
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 return dcf_state->DCF_running;
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 }
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 void request_DCF(bool run)
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 {
2
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
45 ESP_LOGI(TAG, "request_DCF(%s)", run ? "start":"stop");
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
46
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
47 if (run)
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
48 xEventGroupSetBits(xEventGroupDCF, TASK_DCF_REQUEST_START);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
49 else
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
50 xEventGroupSetBits(xEventGroupDCF, TASK_DCF_REQUEST_STOP);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
51 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
52
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
53
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
54 int bin2bcd(int data)
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
55 {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
56 int msb, lsb;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
57
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
58 if (data < 10)
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
59 return data;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
60 msb = (data / 10) << 4;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
61 lsb = data % 10;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
62 return msb + lsb;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
63 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
64
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
65
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
66 static void DCFout(void* arg);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
67 void DCFout(void* arg)
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
68 {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
69 int i, tmp, parity;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
70
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
71 switch (impulseCount++) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
72 case 0: if (actualSecond == 0) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
73 time(&dcf_now);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
74 dcf_now += 60;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
75 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
76 if (impulseArray[actualSecond] != 0) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
77 gpio_set_level(CONFIG_LED1_PIN, 1);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
78 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
79 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
80 case 1: if (impulseArray[actualSecond] == 1) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
81 gpio_set_level(CONFIG_LED1_PIN, 0);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
82 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
83 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
84 case 2: gpio_set_level(CONFIG_LED1_PIN, 0);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
85 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
86 case 9: impulseCount = 0;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
87 /*
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
88 * To spread the CPU load, we set all bits during the first seconds
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
89 * because we don't use these bits.
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
90 */
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
91 switch (actualSecond) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
92 case 0: /* the first 20 bits of each minute at a logical zero value */
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
93 for (i = 0; i < 20; i++)
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
94 impulseArray[i] = 1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
95 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
96 case 1: localtime_r(&dcf_now, &dcf_tm);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
97 char strftime_buf[64];
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
98 strftime(strftime_buf, sizeof(strftime_buf), "%c", &dcf_tm);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
99 ESP_LOGI(TAG, "The current date/time to send is: %s", strftime_buf);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
100 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
101 case 2: /* DST bits */
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
102 if (dcf_tm.tm_isdst == 0) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
103 impulseArray[17] = 1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
104 impulseArray[18] = 2;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
105 } else {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
106 impulseArray[17] = 2;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
107 impulseArray[18] = 1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
108 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
109 /* bit 20 must be 1 to indicate active time */
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
110 impulseArray[20] = 2;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
111 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
112 case 3: int minute = bin2bcd(dcf_tm.tm_min);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
113 parity = 0;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
114 for (i = 21; i < 28; i++) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
115 tmp = minute & 1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
116 impulseArray[i] = tmp + 1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
117 parity += tmp;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
118 minute >>= 1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
119 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
120 impulseArray[28] = (parity & 1) ? 2:1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
121 ESP_LOGI(TAG, "minute %d%d%d%d%d%d%d %d", impulseArray[21], impulseArray[22], impulseArray[23],
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
122 impulseArray[24], impulseArray[25], impulseArray[26], impulseArray[27], impulseArray[28]);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
123 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
124
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
125
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
126 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
127 if (actualSecond < 59) /* Can include leap second */
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
128 actualSecond++;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
129 break;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
130 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
131
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
132 if (actualSecond >= 59) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
133 time_t now = time(NULL);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
134 localtime_r(&now, &dcf_tm);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
135 if (dcf_tm.tm_sec == 0) {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
136 actualSecond = impulseCount = 0;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
137 }
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
138 }
1
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 }
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 void task_DCF(void *pvParameters)
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 {
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 ESP_LOGI(TAG, "Starting DCF77");
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 xEventGroupDCF = xEventGroupCreate();
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 xSemaphoreDCF = xSemaphoreCreateMutex();
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 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
150 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
151
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 gpio_reset_pin(LED1);
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 gpio_reset_pin(LED2);
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 gpio_set_direction(LED1, GPIO_MODE_OUTPUT);
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 gpio_set_direction(LED2, GPIO_MODE_OUTPUT);
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156
2
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
157 esp_timer_create_args_t timerDCF = {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
158 .callback = &DCFout,
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
159 .name = "DCF timer"
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
160 };
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
161 esp_timer_create(&timerDCF, &timerHandle);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
162
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
163 for (int i = 0; i < 59; i++)
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
164 impulseArray[i] = 1;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
165 impulseArray[59] = impulseArray[60] = 0;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
166
1
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 xEventGroupClearBits(xEventGroupDCF, TASK_DCF_RUN);
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 EventBits_t uxBits;
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 for (;;) {
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 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
172
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 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
174 if (dcf_state->DCF_running) {
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 /* Already running */
2
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
176 } else {
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
177 actualSecond = 0;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
178 impulseCount = 0;
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
179 esp_timer_start_periodic(timerHandle, 100000);
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
180 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
181 }
2
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
182 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
183
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 } else if (uxBits & TASK_DCF_REQUEST_STOP) {
2
053649608c09 Begin coding transmit bits.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
185 esp_timer_stop(timerHandle);
1
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 }
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 } /* for(;;) */
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 }
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189
86b275481021 Added framework for the DCF77 transmitter. Added two debug LEDs.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190

mercurial