-
Notifications
You must be signed in to change notification settings - Fork 20
/
moat_config.c
99 lines (91 loc) · 2.25 KB
/
moat_config.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
/*
* Copyright © 2014-2015, Matthias Urlichs <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License (included; see the file LICENSE)
* for more details.
*/
/* This code implements the main code of MoaT slaves.
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "pgm.h"
#include <string.h>
#include "onewire.h"
#include "features.h"
#include "moat.h"
#include "dev_data.h"
#include "debug.h"
#include "moat_internal.h"
#include "bug.h"
uint8_t read_config_len(uint8_t chan)
{
cfg_addr_t off;
uint8_t len;
if (chan == CfgID_nums) {
len = TC_MAX;
} else if (chan == CfgID_list) {
len = (CFG_MAX+7)>>3;
} else {
off = cfg_addr(&len, chan);
if (!off)
next_idle('i');
}
return len;
}
void read_config(uint8_t chan, uint8_t *buf)
{
cfg_addr_t off;
uint8_t len;
if (chan == CfgID_nums) {
uint8_t i;
for(i=0;i<TC_MAX;i++)
*buf++ = pgm_read_byte(&moat_sizes[i]);
} else if (chan == CfgID_list) {
/* Return a bitmap of known types. Note that `b` may be zero for
* deleted blocks, but so is CfgID_list, thus that doesn't matter.
*/
uint8_t b;
memset(buf,0,(CFG_MAX+7)>>3);
BUILD_BUG_ON(CfgID_list != 0);
BUILD_BUG_ON(CfgID_nums > 7);
buf[0] = (1<<CfgID_list) | (1<<CfgID_nums);
len = cfg_count(&off);
while(len--) {
b = cfg_type(&off);
buf[b>>3] |= 1<<(b&7);
}
} else if (chan) {
off = cfg_addr(&len, chan);
if (!off)
next_idle(('i'));
while(len--)
*buf++ = cfg_byte(off++);
}
}
#ifdef USE_EEPROM
void write_config_check(uint8_t chan, uint8_t *buf, uint8_t len)
{
if (chan == 0 || chan == CfgID_list || chan > CFG_MAX)
next_idle('w');
}
void write_config(uint8_t chan, uint8_t *buf, uint8_t len)
{
buf[len]=0;
DBG_P("W_");
DBG_X(chan);
DBG_S((const char *)buf);
if (_cfg_write(buf, len, chan))
DBG_C('+');
else
DBG_C('-');
DBG_C('\n');
}
#endif