-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
800 lines (731 loc) · 24.6 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <avr/interrupt.h>
#include "led.h"
#include "memtest.h"
#include "m128_hal.h"
#include "uart.h"
#include "timer.h"
#include "timer1.h"
#include "cmd.h"
#include "1wire.h"
#include <avr/wdt.h>
#include "fan.h"
#include "ds3234.h"
#include "settings.h"
#include "ipc.h"
#include "hw_channel.h"
#include "reset.h"
#include "list.h"
#include "storage.h"
#include "spi.h"
#include "aaps_a.h"
static uint8_t clind_led_event = 0;
static uint8_t remote_temp_event = 0;
static uint8_t event = 0;
static uint8_t temp_event = 0;
static uint8_t temp_fetch_event = 0;
static uint8_t pdetect_event = 0;
//static struct system_settings sys_settings;
#define CON4 12
#define CON5 6
#define CON6 7
#define CON7 4
#define CON8 5
#define CON9 2
#define CON10 3
#define CON11 0
#define CON12 1
#define CON13 8
#define CON15 9
#define CON16 10
#define CON17 11
#define CON18 13
uint64_t vm30_voltage;
uint8_t sys_analog = CON11;
uint8_t sys_gui = CON9;
int enable_led1(void)
{
led_ctrl(LED1, LED_ON);
return 0;
}
int disable_led1(void)
{
led_ctrl(LED1, LED_OFF);
return 0;
}
int enable_led0(void)
{
led_ctrl(LED0, LED_ON);
return 0;
}
int disable_led0(void)
{
led_ctrl(LED0, LED_OFF);
return 0;
}
#define INPUT_CURRENT false
#define INPUT_VOLTAGE true
/* System control */
uint32_t dac_current_limit = 0;
uint32_t dac_current_limit_calc = 0;
uint32_t dac_voltage = 0;
uint32_t dac_voltage_calc = 0;
uint16_t scale = 1;
bool display_calculated_values = 0;
static uint8_t relay_status = 0;
static uint8_t rled_status = 0;
static bool sys_ilimit_active = false;
static bool which_input = INPUT_CURRENT;
void send_scale(uint16_t scale, uint8_t input);
void change_scale(void)
{
switch (scale)
{
case 1:
scale = 10;
break;
case 10:
scale = 100;
break;
case 100:
scale = 500;
break;
case 500:
scale = 1;
break;
}
printk("scale: %u\n", scale);
}
#define MAX_VOLTAGE 0xdb0f //Approximately calibrated max voltage
int trigger_remote_temp_event(void)
{
remote_temp_event = 1;
return 0;
}
int activate_clind_led(void)
{
clind_led_event = 1;
return 0;
}
int trigger_event(void)
{
event = 1;
return 0;
}
int start_temp_event(void)
{
temp_event = 1;
return 0;
}
int get_temp_event(void)
{
temp_fetch_event = 1;
return 0;
}
int perip_detect_event(void)
{
static uint8_t cnt = 0;
pdetect_event = ++cnt;
return 0;
}
void send_scale(uint16_t scale, uint8_t input)
{
struct ipc_packet_t pkt =
{
.len = 6,
.cmd = IPC_CMD_DISPLAY_SCALE,
};
pkt.data = malloc(3);
if (pkt.data == NULL)
printk("send scale malloc failed\n");
pkt.data[0] = scale >> 8;
pkt.data[1] = scale & 0xff;
pkt.data[2] = which_input;
pkt.crc = crc8(pkt.data, 3);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_scale failed\n");
free(pkt.data);
}
void send_set_led(uint8_t led, uint8_t on)
{
struct ipc_packet_t pkt =
{
.len = 5,
.cmd = IPC_CMD_SET_LED,
};
pkt.data = malloc(2);
if (pkt.data == NULL)
printk("malloc0 failed\n");
pkt.data[0] = led;
pkt.data[1] = on;
pkt.crc = crc8(pkt.data, 2);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("Set led failed\n");
free(pkt.data);
}
static void send_temp(ow_temp_t *temp, uint8_t sensor)
{
struct ipc_packet_t pkt =
{
.len = 6,
.cmd = IPC_CMD_DISPLAY_THERMO,
};
pkt.data = malloc(3);
if (pkt.data == NULL)
printk("malloc0 failed\n");
pkt.data[0] = sensor;
pkt.data[1] = temp->temp;
pkt.data[2] = temp->dec;
pkt.crc = crc8(pkt.data, 3);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("Send temp failed\n");
free(pkt.data);
}
void adc_voltage(uint8_t msb, uint8_t lsb, uint8_t ch, uint64_t *res)
{
uint16_t value = (msb << 8) | lsb;
switch(ch)
{
case 1:
*res = 6250000 * (uint64_t)value / 66129;
break;
case 2:
*res = 62500 * (uint64_t)value;
break;
case 0:
case 3:
*res = 62500 * (uint64_t)value / 1279;
break;
}
}
static uint32_t calculate_current(uint8_t msb, uint8_t lsb, uint8_t ch)
{
/*
* Vc=uppmätt värde på ADC ingången
* där 5A ger Vc=5*40mohm*20=4V
* Rs=40mohm
* Gc=20
* 5.12A max ?
*
* Vc=Iut*Rs*Gc => Iut=Vc/(Rs*Gc)
*/
uint64_t tmp_adc;
const uint8_t Gc = 20;
const uint8_t Rs = 40;
uint32_t Iout = 0;
adc_voltage(msb, lsb, ch, &tmp_adc);
Iout = tmp_adc / (Rs * Gc); /*Add factor 10 to get back to correct base */
return Iout;
}
static void send_current(uint8_t msb, uint8_t lsb, uint8_t ch, uint8_t type)
{
if (ch == 2)
{
uint32_t Iout = calculate_current(msb, lsb, ch);
//printk("Iout: %u\n", Iout);
struct ipc_packet_t pkt =
{
.len = 8,
.cmd = IPC_CMD_DISPLAY_CURRENT,
};
pkt.data = malloc(4);
if (pkt.data == NULL)
printk("send_voltage malloc failed\n");
/* Voltage in mV */
pkt.data[0] = type;
pkt.data[1] = ch;
pkt.data[2] = Iout >> 8;
pkt.data[3] = Iout & 0xff;
pkt.data[4] = Iout >> 16;
pkt.crc = crc8(pkt.data, 5);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_current failed!\n");
free(pkt.data);
}
}
/* TODO: Remove type? */
static void send_voltage(uint8_t msb, uint8_t lsb, uint8_t ch, uint8_t type)
{
uint64_t adc;
adc_voltage(msb, lsb, ch, &adc);
struct ipc_packet_t pkt =
{
.len = 8,
.cmd = IPC_CMD_DISPLAY_VOLTAGE,
};
pkt.data = malloc(5);
if (pkt.data == NULL)
printk("send_voltage malloc failed\n");
/* Voltage in mV */
pkt.data[0] = type;
pkt.data[1] = ch;
pkt.data[2] = adc & 0xff;
pkt.data[3] = (adc >> 8) & 0xff;
pkt.data[4] = adc >> 16;
pkt.crc = crc8(pkt.data, 5);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_voltage failed!\n");
free(pkt.data);
}
static void send_power(uint8_t msb, uint8_t lsb, uint8_t ch)
{
#define Q1 0
#define Q2 1
#define R22 2
#define RS 3
#define RCB 4
#define UIN 34 /* <-- Measured voltage */
if (ch == 2)
{
uint32_t Iout = calculate_current(msb, lsb, ch);
Iout /= 1000;
uint32_t power_q1_2 = (UIN - vm30_voltage / 1000) * Iout / 2;
uint32_t power_r22 = (22 * pow(0.5 * Iout, 2)) / 100;
uint32_t power_rs = (40 * Iout * Iout) / 1000;
uint32_t power_rcb = (1 * Iout);
//printk("Iout: %u\n", Iout);
//printk("power_q1_2: %lu\n", power_q1_2);
//printk("power_r22: %lu\n", power_r22);
//printk("power_rs: %lu\n", power_rs);
//printk("power_rcb %lu\n", power_rcb);
struct ipc_packet_t pkt =
{
.len = 7,
.cmd = IPC_CMD_DISPLAY_POWER,
};
pkt.data = malloc(5);
if (pkt.data == NULL)
printk("send_voltage malloc failed\n");
/* Voltage in mV */
pkt.data[0] = Q1;
pkt.data[1] = power_q1_2 & 0xff;
pkt.data[2] = (power_q1_2 >> 8) & 0xff;
pkt.data[3] = power_q1_2 >> 16;
pkt.crc = crc8(pkt.data, 4);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_power q1 failed!\n");
/* Next packet */
pkt.data[0] = Q2;
pkt.data[1] = power_q1_2 & 0xff;
pkt.data[2] = (power_q1_2 >> 8) & 0xff;
pkt.data[3] = power_q1_2 >> 16;
pkt.crc = crc8(pkt.data, 4);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_power q2 failed!\n");
/* Next packet */
pkt.data[0] = R22;
pkt.data[1] = power_r22 & 0xff;
pkt.data[2] = (power_r22 >> 8) & 0xff;
pkt.data[3] = power_r22 >> 16;
pkt.crc = crc8(pkt.data, 4);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_power r22 failed!\n");
/* Next packet */
pkt.data[0] = RS;
pkt.data[1] = power_rs & 0xff;
pkt.data[2] = (power_rs >> 8) & 0xff;
pkt.data[3] = power_rs >> 16;
pkt.crc = crc8(pkt.data, 4);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_power rs failed!\n");
/* Next packet */
pkt.data[0] = RCB;
pkt.data[1] = power_rcb & 0xff;
pkt.data[2] = (power_rcb >> 8) & 0xff;
pkt.data[3] = power_rcb >> 16;
pkt.crc = crc8(pkt.data, 4);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_power rcb failed!\n");
free(pkt.data);
}
}
static void send_dac(uint32_t value, uint8_t type)
{
struct ipc_packet_t pkt =
{
.len = 8,
.cmd = IPC_CMD_DISPLAY_DAC,
};
pkt.data = malloc(5);
if (pkt.data == NULL)
printk("dac malloc failed\n");
pkt.data[0] = type;
pkt.data[1] = value & 0xff;
pkt.data[2] = value >> 8;
pkt.data[3] = value >> 16;;
pkt.data[4] = value >> 24;
pkt.crc = crc8(pkt.data, 5);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_dac failed\n");
free(pkt.data);
}
static void send_adc(uint8_t msb, uint8_t lsb, uint8_t ch, uint8_t type)
{
struct ipc_packet_t pkt =
{
.len = 7,
.cmd = IPC_CMD_DISPLAY_ADC,
};
pkt.data = malloc(4);
if (pkt.data == NULL)
printk("malloc1 failed\n");
pkt.data[0] = type;
pkt.data[1] = ch;
pkt.data[2] = msb;
pkt.data[3] = lsb;
pkt.crc = crc8(pkt.data, 4);
if (ipc_put_pkt(sys_gui, &pkt) != IPC_RET_OK)
printk("send_adc failed\n");
free(pkt.data);
}
static ipc_ret_t ipc_periph_detect(uint8_t slave)
{
ipc_ret_t ret = IPC_RET_OK;
struct ipc_packet_t pkt =
{
.len = 4,
.cmd = IPC_CMD_PERIPH_DETECT,
};
pkt.data = malloc(1);
if (pkt.data == NULL)
return IPC_RET_ERROR_OUT_OF_MEMORY;
pkt.data[0] = 0xff; /* Dummy data, not sure if it's needed */
pkt.crc = crc8(pkt.data, 1);
ret = ipc_put_pkt(slave, &pkt);
free(pkt.data);
return ret;
}
int main(void)
{
/* This is a temporary configuration of the system */
//TODO: Channel initialization can't be hard coded like this
gui.hw_ch = system_channel[sys_gui];
analog.hw_ch = system_channel[sys_analog];
/* End temporary configuration of the system */
ow_temp_t core_temp;
#define CS_SDM PJ4 //CS for SD card flash must be low (controls buffer U11)
#define CS_FLASH PD6 //CS for flash set low
DDRD |= (1<<PD6);
DDRJ |= (1<<PJ4);
PORTD &= ~(1<<CS_FLASH);
PORTJ &= ~(1<<CS_SDM);
/* Enable external SRAM early */
XMCRA |= (1<<SRE);
rst_save_reason();
led_init();
wdt_enable(WDTO_8S);
uint8_t ow_num_sensors = ow_num_devices();
ow_devices = malloc(sizeof(ow_device_t)*ow_num_sensors);
ow_get_devices(ow_devices);
//ow_convert_temp_async(&(ow_devices[0]));
DDRE |= (1<<PE2);
fan_init();
STATUS_REGISTER |= (1<<STATUS_REGISTER_IT);
uart_init();
rst_print_reason();
cmd_init();
timer_init();
ds3234_init();
timer1_init();
printk("DS3234 ctrl reg: 0x%x\n", ds3234_read_ctrl_reg());
ow_print_device_addr(&(ow_devices[0]));
mem_test();
printk("Found %u sensors\n", ow_num_sensors);
//temp.temp = 0;
//temp.dec = 0;
timer1_create_timer(trigger_remote_temp_event, 750, PERIODIC, 500);
timer1_create_timer(trigger_event, 100, PERIODIC, 0);
timer1_create_timer(activate_clind_led, 150, PERIODIC, 20);
timer1_create_timer(start_temp_event, 1000, PERIODIC, 0);
timer1_create_timer(get_temp_event, 1000, PERIODIC, 200);
// timer1_create_timer(card_detect, 500, PERIODIC, 0);
// timer1_create_timer(send_packet1, 100, PERIODIC, 5100);
// timer1_create_timer(send_packet2, 2000, ONE_SHOT, 0 );
// timer1_create_timer(send_packet1, 2000, ONE_SHOT, 1000);
/* Detect peripherals */
timer1_create_timer(perip_detect_event, 500, ONE_SHOT, 0);
uint16_t cnt = 0;
uint8_t slave = NO_IRQ;
static uint8_t temp_sensors_id = 0;
static uint8_t num_aaps_a_sensors = 0;
init_aaps_a(gui.hw_ch);
init_aaps_a(analog.hw_ch);
struct ipc_packet_t pkt;
while(1)
{
wdt_reset();
pending_cmd();
if (pdetect_event)
{
ipc_ret_t ret = ipc_periph_detect(pdetect_event-1);
if (ret != IPC_RET_OK)
;//printk("CH%u not connected.\n", pdetect_event-1);
if (pdetect_event <= HW_NBR_OF_CHANNELS)
timer1_create_timer(perip_detect_event, 10, ONE_SHOT, 0);
pdetect_event = 0;
}
if (temp_fetch_event)
{
if (get_temp(&core_temp) == OW_RET_OK)
{
send_temp(&core_temp, 5);
send_scale(scale, which_input);
}
temp_fetch_event = 0;
}
if (temp_event)
{
trigger_conv_t();
temp_event = 0;
}
if (remote_temp_event)
{
get_aaps_a_temp(temp_sensors_id, sys_analog);
temp_sensors_id++;
temp_sensors_id %= num_aaps_a_sensors;
remote_temp_event = 0;
}
if (event)
{
/* Handle IRQ events */
static uint8_t ch = 0;
get_adc(ch++ % 8, sys_analog);
event = 0;
}
if (clind_led_event && sys_ilimit_active)
{
rled_status ^= 1;
send_set_led(IPC_LED_RED, rled_status);
clind_led_event = 0;
}
slave = ipc_which_irq(irq_from_slave);
if (slave != NO_IRQ) {
cnt++;
//printk("irq from slave %u\n", slave);
ipc_ret_t result = ipc_get_pkt(slave, &pkt);
if (result == IPC_RET_OK)
{
if (crc8(pkt.data, pkt.len - IPC_PKT_OVERHEAD) == pkt.crc)
{ ow_temp_t t;
switch (pkt.cmd)
{
case IPC_DATA_PERIPH_DETECT:
printk("CH%u detected\n", slave);
printk(" %u sensors\n", pkt.data[2]);
if (pkt.data[2] != 0)
{
num_aaps_a_sensors = pkt.data[2];
}
break;
case IPC_DATA_THERMO:
t.temp = pkt.data[1]; t.dec = pkt.data[2];
send_temp(&t, pkt.data[0]);
break;
case IPC_DATA_CURRENT:
send_adc(pkt.data[2], pkt.data[3],
pkt.data[1], pkt.data[0]);
send_current(pkt.data[2], pkt.data[3],
pkt.data[1], pkt.data[0]);
send_power(pkt.data[2], pkt.data[3],
pkt.data[1]);
if(display_calculated_values)
send_dac(dac_current_limit_calc, pkt.data[0]);
else
send_dac(dac_current_limit, pkt.data[0]);
break;
case IPC_DATA_VOLTAGE:
send_adc(pkt.data[2], pkt.data[3],
pkt.data[1], pkt.data[0]);
send_voltage(pkt.data[2], pkt.data[3],
pkt.data[1], pkt.data[0]);
if (pkt.data[1] == 0)
{
adc_voltage(pkt.data[2], pkt.data[3],
pkt.data[1], &vm30_voltage);
vm30_voltage /= 100;
}
if (display_calculated_values)
send_dac(dac_voltage_calc, pkt.data[0]);
else
send_dac(dac_voltage, pkt.data[0]);
break;
case IPC_DATA_ENC_BTN:
change_scale();
break;
case IPC_DATA_ENC_DB_BTN:
which_input = which_input ? INPUT_CURRENT :
INPUT_VOLTAGE;
printk("Changed input to %s\n",
which_input ? "voltage" : "current");
break;
case IPC_DATA_ENC_LONGPRESS:
relay_status ^= 1;
set_relay(relay_status, sys_analog);
break;
case IPC_DATA_ENC_CW:
if (which_input)
{
if (display_calculated_values)
{
if (dac_voltage_calc + scale < 32000000)
{
printk("V: %lu\n", dac_voltage_calc);
voltage(dac_voltage_calc, sys_analog);
dac_voltage_calc += scale;
}
}
else
{
if ((uint16_t)dac_voltage + scale >
dac_voltage)
{
if (display_calculated_values)
voltage(dac_voltage, sys_analog);
else
raw_v(dac_voltage, sys_analog);
dac_voltage += scale;
printk("rot+ %lu\n", dac_voltage);
}
}
}
else
{
if (display_calculated_values)
{
current(dac_current_limit_calc, sys_analog);
dac_current_limit_calc += scale;
}
else
{
if ((uint16_t)dac_current_limit + scale >
dac_current_limit)
{
raw_c(dac_current_limit, sys_analog);
dac_current_limit += scale;
printk("rot+ %lu\n", dac_current_limit);
}
}
}
break;
case IPC_DATA_ENC_CCW:
if (which_input)
{
if (display_calculated_values)
{
if (dac_voltage_calc - scale < dac_voltage_calc)
{
printk("V: %lu\n", dac_voltage_calc);
voltage(dac_voltage_calc, sys_analog);
dac_voltage_calc -= scale;
}
}
else
{
if (dac_voltage - scale < dac_voltage)
{
raw_v(dac_voltage, sys_analog);
dac_voltage -= scale;
printk("rot- %lu\n", dac_voltage);
} else printk("bottom\n");
}
}
else
{
if (display_calculated_values)
{
current(dac_current_limit_calc, sys_analog);
dac_current_limit_calc -= scale;
}
else
{
if (dac_current_limit - scale < dac_current_limit)
{
raw_c(dac_current_limit, sys_analog);
dac_current_limit -= scale;
printk("rot- %lu\n", dac_current_limit);
} else printk("top\n");
}
}
break;
case IPC_DATA_ENC_SW0:
printk("Changed display page\n");
break;
case IPC_DATA_ENC_SW0_LONGPRESS:
printk("SW0 Longpress\n");
display_calculated_values =
display_calculated_values ? false : true;
printk("Display calculated: %u\n",
display_calculated_values);
if (display_calculated_values)
{
dac_voltage_calc = dac_voltage * 575;
dac_current_limit_calc = dac_current_limit * 78;
printk("To calculated values\n");
}
else
{
dac_current_limit = dac_current_limit_calc / 78;
printk("Back to raw\n");
}
break;
case IPC_DATA_ENC_SW1:
dac_current_limit_calc = dac_current_limit = 0;
current(dac_current_limit, sys_analog);
break;
case IPC_DATA_ENC_SW1_LONGPRESS:
printk("SW1 Longpress\n");
dac_voltage_calc = dac_voltage = 0;
raw_v(dac_voltage, sys_analog);
break;
case IPC_DATA_ENC_SW2:
break;
case IPC_DATA_CLIND:
sys_ilimit_active = pkt.data[0] ? true : false;
if (sys_ilimit_active)
{
if (relay_status)
send_set_led(IPC_LED_GREEN, !pkt.data[0]);
else
send_set_led(IPC_LED_RED, 0);
}
else
{
if (relay_status)
{
send_set_led(IPC_LED_GREEN, 1);
send_set_led(IPC_LED_RED, 0);
}
else
send_set_led(IPC_LED_RED, 0);
}
printk("CLIND: %u\n", sys_ilimit_active);
break;
default:
printk("Unknown data type: 0x%x\n", pkt.cmd);
}
//printk("len: %u\n", pkt.len);
//printk("cmd: 0x%02x\n", pkt.cmd);
//printk("crc: 0x%02x\n", pkt.crc);
//for (uint8_t i = 0; i < pkt.len - IPC_PKT_OVERHEAD; i++)
// printk("d%02u: 0x%x\n", i, pkt.data[i]);
//printk("pkts: %u\n", cnt);
}
else
printk("CRC failed from slave %u", slave);
free(pkt.data);
pkt.data = NULL;
}
else
{
printk("get failed err:%u\n", result);
}
}
}
//fatal:
printk("Fatal error!\n");
while(1);
return 0;
}