11ca3442bSMatthias Ringwald /*
21ca3442bSMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH
31ca3442bSMatthias Ringwald *
41ca3442bSMatthias Ringwald * Redistribution and use in source and binary forms, with or without
51ca3442bSMatthias Ringwald * modification, are permitted provided that the following conditions
61ca3442bSMatthias Ringwald * are met:
71ca3442bSMatthias Ringwald *
81ca3442bSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright
91ca3442bSMatthias Ringwald * notice, this list of conditions and the following disclaimer.
101ca3442bSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright
111ca3442bSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the
121ca3442bSMatthias Ringwald * documentation and/or other materials provided with the distribution.
131ca3442bSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of
141ca3442bSMatthias Ringwald * contributors may be used to endorse or promote products derived
151ca3442bSMatthias Ringwald * from this software without specific prior written permission.
161ca3442bSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for
171ca3442bSMatthias Ringwald * personal benefit and not for any commercial purpose or for
181ca3442bSMatthias Ringwald * monetary gain.
191ca3442bSMatthias Ringwald *
201ca3442bSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
211ca3442bSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221ca3442bSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
251ca3442bSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
261ca3442bSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
271ca3442bSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
281ca3442bSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
291ca3442bSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
301ca3442bSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311ca3442bSMatthias Ringwald * SUCH DAMAGE.
321ca3442bSMatthias Ringwald *
331ca3442bSMatthias Ringwald * Please inquire about commercial licensing options at
341ca3442bSMatthias Ringwald * [email protected]
351ca3442bSMatthias Ringwald *
361ca3442bSMatthias Ringwald */
37ab2c6ae4SMatthias Ringwald
38*bc6a318fSMatthias Ringwald #define BTSTACK_FILE__ "hal_compat.c"
391ca3442bSMatthias Ringwald
401ca3442bSMatthias Ringwald /**
411ca3442bSMatthias Ringwald * various functions to deal with flaws and portability issues
421ca3442bSMatthias Ringwald */
431ca3442bSMatthias Ringwald
441ca3442bSMatthias Ringwald #include "hal_compat.h"
451ca3442bSMatthias Ringwald #include <msp430x54x.h>
461ca3442bSMatthias Ringwald
471ca3442bSMatthias Ringwald // __delay_cycles is limited
waitAboutOneSecond(void)481ca3442bSMatthias Ringwald void waitAboutOneSecond(void){
491ca3442bSMatthias Ringwald int i;
501ca3442bSMatthias Ringwald for (i=0;i<1000;i++) __delay_cycles(16000);
511ca3442bSMatthias Ringwald }
521ca3442bSMatthias Ringwald
531ca3442bSMatthias Ringwald // access far text for MSP430X platform
541ca3442bSMatthias Ringwald #if defined(__GNUC__) && (__MSP430X__ > 0)
551ca3442bSMatthias Ringwald
FlashReadByte(uint32_t addr)561ca3442bSMatthias Ringwald uint8_t FlashReadByte (uint32_t addr){
571ca3442bSMatthias Ringwald
581ca3442bSMatthias Ringwald uint8_t result;
591ca3442bSMatthias Ringwald uint32_t register sr, flash;
601ca3442bSMatthias Ringwald
611ca3442bSMatthias Ringwald __asm__ __volatile__ (
621ca3442bSMatthias Ringwald "mov r2 , %1 \n"
631ca3442bSMatthias Ringwald "bic %3 , r2 \n"
641ca3442bSMatthias Ringwald "nop \n"
651ca3442bSMatthias Ringwald "movx.a %4 , %2 \n"
661ca3442bSMatthias Ringwald "movx.b @%2, %0 \n"
671ca3442bSMatthias Ringwald "mov %1 , r2 \n"
681ca3442bSMatthias Ringwald :"=X"(result),"=r"(sr),"=r"(flash)
691ca3442bSMatthias Ringwald :"i"(GIE),"m"(addr));
701ca3442bSMatthias Ringwald
711ca3442bSMatthias Ringwald return result;
721ca3442bSMatthias Ringwald }
731ca3442bSMatthias Ringwald
741ca3442bSMatthias Ringwald // argument order matches memcpy
FlashReadBlock(uint8_t * buffer,uint32_t addr,uint16_t len)751ca3442bSMatthias Ringwald void FlashReadBlock(uint8_t *buffer, uint32_t addr, uint16_t len){
761ca3442bSMatthias Ringwald while (len){
771ca3442bSMatthias Ringwald *buffer++ = FlashReadByte(addr++);
781ca3442bSMatthias Ringwald len--;
791ca3442bSMatthias Ringwald }
801ca3442bSMatthias Ringwald }
811ca3442bSMatthias Ringwald
821ca3442bSMatthias Ringwald #endif
83