HWA
Bare metal programming with style
corea_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
66
#define hwa_configure__corea , _hwa_cfcorea
67
68
/* TODO use a list of wake-up sources instead (or in addition)?
69
*/
70
71
/* Optionnal parameter `sleep`
72
*/
73
#define _hwa_cfcorea(o,a,k,...) \
74
do { \
75
HW_B(_hwa_cfcorea_ksleep_,_hw_is_sleep_##k)(o,k,__VA_ARGS__,,); \
76
} while(0)
77
78
#define _hwa_cfcorea_ksleep_0(o,v,...) \
79
HW_G2(_hwa_cfcorea_ksleepmode,HW_IS(sleep_mode,v))(o,v,__VA_ARGS__)
80
81
#define _hwa_cfcorea_ksleep_1(o,k,v,...) \
82
HW_B(_hwa_cfcorea_vsleep_,_hw_state_##v)(o,v,__VA_ARGS__)
83
84
#define _hwa_cfcorea_vsleep_0(o,v,...) \
85
HW_E(HW_EM_VOAST(v,sleep))
86
87
#define _hwa_cfcorea_vsleep_1(o,v,k,...) \
88
_hwa_write( o, se, HW_A1(_hw_state_##v) ); \
89
HW_G2(_hwa_cfcorea_ksleepmode,HW_IS(sleep_mode,k))(o,k,__VA_ARGS__)
90
91
/* Optionnal parameter `sleep_mode`
92
*/
93
#define hw_sleepmode_idle , 0
94
#define hw_sleepmode_adc_noise_reduction , 1
95
#define hw_sleepmode_power_down , 2
96
#define hw_sleepmode_standby , 3
97
98
#define _hwa_cfcorea_ksleepmode_0(o,...) HW_EOL(__VA_ARGS__)
99
100
#define _hwa_cfcorea_ksleepmode_1(o,k,v,...) \
101
HW_B(_hwa_cfcorea_vsleepmode_,hw_sleepmode_##v)(o,v,__VA_ARGS__)
102
103
#define _hwa_cfcorea_vsleepmode_0(o,v,...) \
104
HW_E(HW_EM_VAL(v,sleep_mode,(idle,adc_noise_reduction,power_down,standby)))
105
106
#define _hwa_cfcorea_vsleepmode_1(o,v,...) \
107
_hwa_write( o, sm, HW_A1(hw_sleepmode_##v) ); \
108
HW_EOL(__VA_ARGS__)
109
110
143
#define hw_stat__corea , _hw_stat_corea
144
145
/* FIXME intf0 should be there
146
*/
147
typedef
union
{
148
uint8_t byte ;
149
struct
{
150
unsigned
int
porf: 1 ;
151
unsigned
int
extrf: 1 ;
152
unsigned
int
borf: 1 ;
153
unsigned
int
wdrf: 1 ;
154
unsigned
int
__4to7: 4 ;
155
};
156
struct
{
157
unsigned
int
reset_by_power_on: 1 ;
158
unsigned
int
reset_by_reset_pin: 1 ;
159
unsigned
int
reset_by_brown_out: 1 ;
160
unsigned
int
reset_by_watchdog: 1 ;
161
unsigned
int
__4to7_2: 4 ;
162
};
163
} _hw_corea_stat_t ;
164
165
166
#define _hw_stat_corea(o,a,...) _hw_corea_stat(_hw_read(o, mcusr)) HW_EOL(__VA_ARGS__)
167
168
HW_INLINE _hw_corea_stat_t _hw_corea_stat( uint8_t
byte
)
169
{
170
_hw_corea_stat_t st ;
171
st.byte = byte ;
172
return
st ;
173
}
174
175
186
#define hwa_clear__corea , _hwa_clear_corea
187
188
#define _hwa_clear_corea(o,a,...) _hwa_write(o,allrf,0)
189
190
191
192
/*******************************************************************************
193
* *
194
* Context management *
195
* *
196
*******************************************************************************/
197
198
#define _hwa_setup__corea(o,a) \
199
_hwa_setup_r( o, mcucr ); \
200
_hwa_setup_r( o, mcusr ); \
201
_hwa_setup_r( o, osccal )
202
203
/* mcusr is not initialized as its status is not known after RESET
204
*/
205
#define _hwa_init__corea(o,a) \
206
_hwa_init_r( o, mcucr, 0x00 ); \
207
_hwa_init_r( o, osccal, 0x00 )
208
209
#define _hwa_commit__corea(o,a) \
210
_hwa_commit_r( o, mcucr ); \
211
_hwa_commit_r( o, mcusr ); \
212
_hwa_commit_r( o, osccal )
Generated for HWA by
1.8.6