HWA
Bare metal programming with style
ocb_2.h
Go to the documentation of this file.
1
2
/* This file is part of the HWA project.
3
* Copyright (c) 2012,2015 Christophe Duparquet.
4
* All rights reserved. Read LICENSE.TXT for details.
5
*/
6
36
#define hwa_configure__ocb , _hwa_cfocb
37
38
39
/* Optionnal argument `update`
40
*
41
* Add a second void argument to the end of the list so that there are always
42
* at least 2 arguments following the last non-void argument.
43
*/
44
#define _hwa_cfocb(o,ct,oc,k,...) \
45
do { \
46
HW_B(_hwa_cfocb_kupdate_,_hw_is_update_##k)(ct,oc,k,__VA_ARGS__,) \
47
} while(0)
48
49
#define _hwa_cfocb_kupdate_1(ct,oc,kw,v,...) \
50
HW_G2(_hwa_cfocb_vupdate,HW_IS(after_top,v))(ct,oc,v,__VA_ARGS__)
51
52
#define _hwa_cfocb_vupdate_0(ct,oc,v,...) \
53
HW_E(HW_EM_VAL(v,update,(after_top)))
54
55
#define _hwa_cfocb_vupdate_1(ct,oc,v,...) \
56
_hwa_cfocb_kupdate_0(ct,oc,__VA_ARGS__)
57
58
#define _hwa_cfocb_kupdate_0(ct,oc,kw,...) \
59
HW_B(_hwa_cfocb_koutputh_,_hw_ocb_koutputh_##kw)(ct,oc,kw,__VA_ARGS__)
60
61
62
/* Optionnal argument `output` (or `output_h`)
63
*/
64
#define _hw_ocb_koutputh_output , 1
65
#define _hw_ocb_koutputh_output_h , 1
66
67
/* // COM PWM
68
*/
69
#define _hw_ocb_voutputh_disconnected , 0 // 0 0
70
#define _hw_ocb_voutputh_toggle_after_match , 1 // 1 0
71
#define _hw_ocb_voutputh_clear_after_match , 2 // 2 0
72
#define _hw_ocb_voutputh_set_after_match , 3 // 3 0
73
#define _hw_ocb_voutputh_set_at_bottom_clear_after_match , 4 // 1,2 1
74
#define _hw_ocb_voutputh_clear_at_bottom_set_after_match , 5 // 3 1
75
76
77
#define _hwa_cfocb_koutputh_1(ct,oc,kw,v,...) \
78
HW_B(_hwa_cfocb_voutputh_,_hw_ocb_voutputh_##v)(ct,oc,v,__VA_ARGS__)
79
80
#define _hwa_cfocb_voutputh_0(ct,oc,v,...) \
81
HW_E(HW_EM_VAL(v,output,(disconnected,toggle_after_match,clear_after_match,set_after_match,set_at_bottom_clear_after_match,clear_at_bottom_set_after_match)))
82
83
#define _hwa_cfocb_voutputh_1(ct,oc,v,...) \
84
hwa->ct.compare##oc.config.outputh = HW_A1(_hw_ocb_voutputh_##v); \
85
_hwa_cfocb_koutputh_0(ct,oc,__VA_ARGS__)
86
87
#define _hwa_cfocb_koutputh_0(ct,oc,kw,...) \
88
HW_G2(_hwa_cfocb_koutputl,HW_IS(output_l,kw))(ct,oc,kw,__VA_ARGS__)
89
90
91
/* Optionnal argument `output_l`
92
*/
93
/* // COM PWM
94
*/
95
#define _hw_ocb_voutputl_disconnected , 0 // 0,2,3 0,1
96
#define _hw_ocb_voutputl_clear_at_bottom_set_after_match , 1 // 1 1
97
98
#define _hwa_cfocb_koutputl_1(ct,oc,kw,v,...) \
99
HW_B(_hwa_cfocb_voutputl_,_hw_ocb_voutputl_##v)(ct,oc,v,__VA_ARGS__)
100
101
#define _hwa_cfocb_voutputl_0(ct,oc,v,...) \
102
HW_E(HW_EM_VAL( v,output_l,(disconnected,clear_at_bottom_set_after_match)))
103
104
#define _hwa_cfocb_voutputl_1(ct,oc,v,...) \
105
hwa->ct.compare##oc.config.outputl = HW_A1(_hw_ocb_voutputl_##v); \
106
HW_EOL(__VA_ARGS__)
107
108
#define _hwa_cfocb_koutputl_0(ct,oc,...) \
109
HW_EOL(__VA_ARGS__)
110
111
131
#define hw_write__ocb , _hw_write_ocb
132
#define _hw_write_ocb(o,ct,oc,v,...) _hw_write(ct,ocr##oc,v) HW_EOL(__VA_ARGS__)
133
134
#define hwa_write__ocb , _hwa_write_ocb
135
#define _hwa_write_ocb(o,ct,oc,v,...) _hwa_write(ct,ocr##oc,v) HW_EOL(__VA_ARGS__)
136
137
#define hw_read__ocb , _hw_read_ocb
138
#define _hw_read_ocb(o,ct,oc,...) _hw_read(ct,ocr##oc) HW_EOL(__VA_ARGS__)
139
140
141
/*******************************************************************************
142
* *
143
* Context management *
144
* *
145
*******************************************************************************/
146
147
#define _hwa_solve_ocb(counter,oc) \
148
if ( hwa->counter.compare##oc.config.outputh != 0xFF || hwa->counter.compare##oc.config.outputl != 0xFF ) { \
149
if ( hwa->counter.compare##oc.config.outputl == HW_A1(_hw_ocb_voutputl_clear_at_bottom_set_after_match) ) { \
150
if ( hwa->counter.compare##oc.config.outputh != HW_A1(_hw_ocb_voutputh_set_at_bottom_clear_after_match) ) \
151
HWA_E(HW_EM_3((o,oc))); \
152
_hwa_write(counter,pwm##oc,1); \
153
_hwa_write(counter,com##oc,1); \
154
} \
155
else if ( hwa->counter.compare##oc.config.outputh == HW_A1(_hw_ocb_voutputh_disconnected) ) { \
156
_hwa_write(counter,pwm##oc,0); \
157
_hwa_write(counter,com##oc,0); \
158
} \
159
else if ( hwa->counter.compare##oc.config.outputh == HW_A1(_hw_ocb_voutputh_toggle_after_match) ) { \
160
_hwa_write(counter,pwm##oc,0); \
161
_hwa_write(counter,com##oc,1); \
162
} \
163
else if ( hwa->counter.compare##oc.config.outputh == HW_A1(_hw_ocb_voutputh_clear_after_match) ) { \
164
_hwa_write(counter,pwm##oc,0); \
165
_hwa_write(counter,com##oc,2); \
166
} \
167
else if ( hwa->counter.compare##oc.config.outputh == HW_A1(_hw_ocb_voutputh_set_after_match) ) { \
168
_hwa_write(counter,pwm##oc,0); \
169
_hwa_write(counter,com##oc,3); \
170
} \
171
else if ( hwa->counter.compare##oc.config.outputh == HW_A1(_hw_ocb_voutputh_set_at_bottom_clear_after_match) ) { \
172
_hwa_write(counter,pwm##oc,1); \
173
_hwa_write(counter,com##oc,2); \
174
} \
175
else if ( hwa->counter.compare##oc.config.outputh == HW_A1(_hw_ocb_voutputh_clear_at_bottom_set_after_match) ) { \
176
_hwa_write(counter,pwm##oc,1); \
177
_hwa_write(counter,com##oc,3); \
178
} \
179
if ( hwa->counter.compare##oc.config.outputh != 0xFF && hwa->counter.compare##oc.config.outputh != 0 ) \
180
_hwa( configure, (counter,compare##oc##_pin_h), mode, digital_output ); \
181
if ( hwa->counter.compare##oc.config.outputl != 0xFF && hwa->counter.compare##oc.config.outputl != 0 ) \
182
_hwa( configure, (counter,compare##oc##_pin_l), mode, digital_output ); \
183
}
184
185
Generated for HWA by
1.8.6