sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
moat_internal.h
Go to the documentation of this file.
1 #ifndef MOAT_I_H
2 #define MOAT_I_H
3 
4 /*
5  * Copyright © 2010-2015, Matthias Urlichs <matthias@urlichs.de>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License (included; see the file LICENSE)
16  * for more details.
17  */
18 
19 #include "moat.h"
20 
21 #define MAXBUF 32
22 
23 /* transmit the CRC, check that its complement is received correctly.
24  If it is not, this will not return to the caller.
25  */
26 void end_transmission(uint16_t crc);
27 
28 typedef void init_fn(void);
29 typedef void poll_fn(void);
30 typedef uint8_t read_len_fn(uint8_t chan);
31 typedef void read_fn(uint8_t chan, uint8_t *buf);
32 typedef void read_done_fn(uint8_t chan);
33 typedef char alert_check_fn(void);
34 typedef void alert_fill_fn(uint8_t *buf);
35 typedef void write_check_fn(uint8_t chan, uint8_t *buf, uint8_t len);
36 typedef void write_fn(uint8_t chan, uint8_t *buf, uint8_t len);
37 
38 #define DEFS(_s) \
39  init_fn init_ ## _s; \
40  poll_fn poll_ ## _s; \
41  read_len_fn read_ ## _s ## _len; \
42  read_fn read_ ## _s; \
43  read_done_fn read_ ## _s ## _done; \
44  write_check_fn write_ ## _s ## _check; \
45  write_fn write_ ## _s; \
46  ADEFS(_s)
47 
48 #ifdef CONDITIONAL_SEARCH
49 #define ADEFS(_s) \
50  alert_check_fn alert_ ## _s ## _check; \
51  alert_fill_fn alert_ ## _s ## _fill;
52 #else
53 #define ADEFS(_s) // nothing
54 #endif
55 
56 #define ALIASDEFS(_s) \
57  init_fn init_ ## _s __attribute__((weak,alias("dummy_init_fn"))); \
58  poll_fn poll_ ## _s __attribute__((weak,alias("dummy_poll_fn"))); \
59  read_len_fn read_ ## _s ## _len __attribute__((weak,alias("dummy_read_len_fn"))); \
60  read_fn read_ ## _s __attribute__((weak,alias("dummy_read_fn"))); \
61  read_done_fn read_ ## _s ## _done __attribute__((weak,alias("dummy_read_done_fn"))); \
62  write_check_fn write_ ## _s ## _check __attribute__((weak,alias("dummy_write_check_fn"))); \
63  write_fn write_ ## _s __attribute__((weak,alias("dummy_write_fn"))); \
64  ALERT_ALIASDEF(_s)
65 #ifdef CONDITIONAL_SEARCH
66 #define ALERT_ALIASDEF(_s) \
67  alert_check_fn alert_ ## _s ## _check __attribute__((weak,alias("dummy_alert_check_fn"))); \
68  alert_fill_fn alert_ ## _s ## _fill __attribute__((weak,alias("dummy_alert_fill_fn")));
69 #else
70 #define ALERT_ALIASDEF(x) // nothing
71 #endif
72 
73 #define FUNCPTRS(_s) \
74 { \
75  &init_ ## _s, \
76  &poll_ ## _s, \
77  &read_ ## _s ## _len, \
78  &read_ ## _s, \
79  &read_ ## _s ## _done, \
80  &write_ ## _s ## _check, \
81  &write_ ## _s, \
82  ALERTPTRS(_s) \
83 }
84 #ifdef CONDITIONAL_SEARCH
85 #define ALERTPTRS(_s) \
86  &alert_ ## _s ## _check, \
87  &alert_ ## _s ## _fill,
88 #else
89 #define ALERTPTRS(x) // nothing
90 #endif
91 
92 typedef struct {
100 #ifdef CONDITIONAL_SEARCH
101  alert_check_fn *alert_check;
102  alert_fill_fn *alert_fill;
103 #endif
104 } moat_call_t;
105 extern const moat_call_t moat_calls[TC_MAX] __attribute__ ((progmem));
106 
107 extern const uint8_t moat_sizes[TC_MAX] __attribute__ ((progmem));
108 
109 #if defined(IS_BOOTLOADER) || defined(USE_BOOTLOADER)
110 typedef struct {
111  char sig[2]; // 'ML'
112  init_fn *init;
113  const moat_call_t *calls;
114  uint8_t n_types;
115 } moat_loader_t;
116 #endif
117 
118 #define TC_DEFINE(x) \
119  DEFS(x)
120 #include "_def.h"
121 #undef TC_DEFINE
122 
123 extern uint8_t moat_buf[MAXBUF];
124 extern uint8_t moat_alert_present;
125 
126 #endif // moat_internal.h
void read_fn(uint8_t chan, uint8_t *buf)
Definition: moat_internal.h:31
write_check_fn * write_check
Definition: moat_internal.h:98
void write_check_fn(uint8_t chan, uint8_t *buf, uint8_t len)
Definition: moat_internal.h:35
read_done_fn * read_done
Definition: moat_internal.h:97
void init_fn(void)
Definition: moat_internal.h:28
poll_fn * poll
Definition: moat_internal.h:94
const moat_call_t moat_calls[TC_MAX] __attribute__((progmem))
void read_done_fn(uint8_t chan)
Definition: moat_internal.h:32
void alert_fill_fn(uint8_t *buf)
Definition: moat_internal.h:34
char alert_check_fn(void)
Definition: moat_internal.h:33
void poll_fn(void)
Definition: moat_internal.h:29
tuple buf
Definition: DeviceGeneric.py:119
init_fn * init
Definition: moat_internal.h:93
void end_transmission(uint16_t crc)
Definition: moat.c:49
uint8_t moat_alert_present
uint8_t moat_buf[MAXBUF]
Definition: moat.c:72
read_len_fn * read_len
Definition: moat_internal.h:95
void write_fn(uint8_t chan, uint8_t *buf, uint8_t len)
Definition: moat_internal.h:36
Definition: moat_internal.h:92
read_fn * read
Definition: moat_internal.h:96
write_fn * write
Definition: moat_internal.h:99
def init
Definition: ow-slave-test.py:11
#define MAXBUF
Definition: moat_internal.h:21
uint8_t read_len_fn(uint8_t chan)
Definition: moat_internal.h:30