36 #ifdef __IAR_SYSTEMS_ICC__
41 #include <sys/unistd.h>
42 #define asmv(arg) __asm__ __volatile__(arg)
45 #include "msp430def.h"
46 #include "dev/watchdog.h"
50 #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
52 w_memcpy(
void *out,
const void *in,
size_t n)
56 dest = (uint8_t *) out;
64 #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
66 w_memset(
void *out,
int value,
size_t n)
69 dest = (uint8_t *) out;
71 *dest++ = value & 0xff;
80 if(CALBC1_8MHZ != 0xFF) {
82 BCSCTL1 = CALBC1_8MHZ;
100 msp430_quick_synch_dco(
void) {
103 uint16_t dco_reg = 0x0fff;
104 uint8_t current_bit = 12;
107 #define DELTA_2 ((MSP430_CPU_SPEED) / 32768)
110 TBCTL = TBSSEL1 | TBCLR;
111 TBCCTL6 = CCIS0 + CM0 + CAP;
120 while(current_bit--) {
123 dco_reg = dco_reg ^ (1 << current_bit);
126 DCOCTL = dco_reg & 0xff;
127 BCSCTL1 = (BCSCTL1 & 0xf8) | (dco_reg >> 8);
131 for(i=0; i < 1000; i++) {
137 while(!(TBCCTL6 & CCIFG));
142 while(!(TBCCTL6 & CCIFG));
143 diff = TBCCR6 - last;
150 if (diff < DELTA_2) {
152 dco_reg = dco_reg ^ (1 << current_bit);
158 msp430_init_dco_old(
void)
161 #define DELTA ((MSP430_CPU_SPEED) / (32768 / 8))
163 unsigned int compare, oldcapture = 0;
173 BCSCTL1 |= DIVA1 + DIVA0;
174 for(i = 0xffff; i > 0; i--) {
178 CCTL2 = CCIS0 + CM0 + CAP;
179 TACTL = TASSEL1 + TACLR + MC1;
184 while((CCTL2 & CCIFG) != CCIFG);
187 compare = compare - oldcapture;
190 if(DELTA == compare) {
192 }
else if(DELTA < compare) {
209 BCSCTL1 &= ~(DIVA1 + DIVA0);
273 static char *cur_break = (
char *)&_end;
277 msp430_cpu_init(
void)
282 msp430_quick_synch_dco();
285 if((uintptr_t)cur_break & 1) {
292 #define STACK_EXTRA 32
303 #ifdef __IAR_SYSTEMS_ICC__
304 sr = __get_SR_register();
305 __bic_SR_register(GIE);
307 asmv(
"mov r2, %0" :
"=r" (sr));
308 asmv(
"bic %0, r2" : :
"i" (GIE));
319 #ifdef __IAR_SYSTEMS_ICC__
320 __bis_SR_register(sr);
323 asmv(
"bis %0, r2" : :
"r" (sr));
329 msp430_sync_dco(
void) {
334 #define DELTA_2 ((MSP430_CPU_SPEED) / 32768)
337 TBCTL = TBSSEL1 | TBCLR;
338 TBCCTL6 = CCIS0 + CM0 + CAP;
344 while(!(TBCCTL6 & CCIFG));
349 while(!(TBCCTL6 & CCIFG));
350 diff = TBCCR6 - last;
366 }
else if (DELTA_2 > diff) {