34 #include "dev/watchdog.h"
39 int msp430_dco_required;
42 #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
44 w_memcpy(
void *out,
const void *in,
size_t n)
48 dest = (uint8_t *) out;
56 #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
58 w_memset(
void *out,
int value,
size_t n)
61 dest = (uint8_t *) out;
63 *dest++ = value & 0xff;
73 #define DELTA ((MSP430_CPU_SPEED) / (32768 / 8))
75 unsigned int compare, oldcapture = 0;
85 BCSCTL1 |= DIVA1 + DIVA0;
86 for(i = 0xffff; i > 0; i--) {
90 CCTL2 = CCIS0 + CM0 + CAP;
91 TACTL = TASSEL1 + TACLR + MC1;
96 while((CCTL2 & CCIFG) != CCIFG);
99 compare = compare - oldcapture;
102 if(DELTA == compare) {
104 }
else if(DELTA < compare) {
121 BCSCTL1 &= ~(DIVA1 + DIVA0);
182 #if defined(__MSP430__) && defined(__GNUC__)
184 static char *cur_break = (
char *)&_end;
194 msp430_add_lpm_req(
int req)
196 if(req <= MSP430_REQUIRE_LPM1) {
197 msp430_dco_required++;
202 msp430_remove_lpm_req(
int req)
204 if(req <= MSP430_REQUIRE_LPM1) {
205 msp430_dco_required--;
210 msp430_cpu_init(
void)
217 #if defined(__MSP430__) && defined(__GNUC__)
218 if((uintptr_t)cur_break & 1) {
223 msp430_dco_required = 0;
227 #define STACK_EXTRA 32
228 #define asmv(arg) __asm__ __volatile__(arg)
236 #if defined(__MSP430__) && defined(__GNUC__)
242 asmv(
"mov r1, %0" :
"=r" (stack_pointer));
243 stack_pointer -= STACK_EXTRA;
244 if(incr > (stack_pointer - cur_break))
247 void *old_break = cur_break;
265 #ifdef __IAR_SYSTEMS_ICC__
266 sr = __get_SR_register();
267 __bic_SR_register(GIE);
269 asmv(
"mov r2, %0" :
"=r" (sr));
270 asmv(
"bic %0, r2" : :
"i" (GIE));
281 #ifdef __IAR_SYSTEMS_ICC__
282 __bis_SR_register(sr);
285 asmv(
"bis %0, r2" : :
"r" (sr));
291 msp430_sync_dco(
void) {
296 #define DELTA_2 ((MSP430_CPU_SPEED) / 32768)
299 TBCTL = TBSSEL1 | TBCLR;
300 TBCCTL6 = CCIS0 + CM0 + CAP;
306 while(!(TBCCTL6 & CCIFG));
311 while(!(TBCCTL6 & CCIFG));
312 diff = TBCCR6 - last;
328 }
else if (DELTA_2 > diff) {