Last active
August 29, 2015 14:00
-
-
Save spirilis/ddf4f743bd82de3c270e to your computer and use it in GitHub Desktop.
MSP430 20-bit read/write from 16-bit-only compiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Public domain software | |
* MSP430 20-bit data copy runnable from within a 16-bit-only compiler (e.g. mspgcc 4.6.3) | |
*/ | |
#include <msp430.h> | |
#include <stdint.h> | |
void highmem_write(uint32_t dstaddr, void *srcaddr, uint16_t len) | |
{ | |
// Copy <len> bytes in units of 2-bytes per transfer from srcaddr[] to dstaddr[] | |
len &= ~1; | |
if (!len) | |
return; | |
asm volatile( | |
"adda #65536, %B[dstaddr] \n\t" // Upper 16 bits need shifting | |
"adda %B[dstaddr], %A[dstaddr] \n\t" // Combine with lower 16 bits | |
" \n\t" | |
"movx.w @%[srcptr]+, @%A[dstaddr] \n\t" // Copy 2 bytes at a time, incrementing srcptr+=2 | |
"incda %A[dstaddr] \n\t" // Increment dstptr in step +=2 | |
"decdx.w %[len] \n\t" | |
"jz .+4 \n\t" | |
"jmp .-14 \n\t" | |
: [dstaddr] "+r" (dstaddr), [srcptr] "+r" (srcaddr), [len] "+r" (len) | |
: | |
: ); | |
} | |
void highmem_read(uint32_t srcaddr, void *dstaddr, uint16_t len) | |
{ | |
// Copy <len> bytes in units of 2-bytes per transfer from srcaddr[] to dstaddr[] | |
len &= ~1; | |
if (!len) | |
return; | |
asm volatile( | |
"adda #65536, %B[srcaddr] \n\t" // Upper 16 bits need shifting | |
"adda %B[srcaddr], %A[srcaddr] \n\t" // Combine with lower 16 bits | |
" \n\t" | |
"movx.w @%A[srcaddr]+, @%[dstptr] \n\t" // Copy 2 bytes at a time, incrementing srcptr+=2 | |
"incda %[dstptr] \n\t" // Increment dstptr in step +=2 | |
"decdx.w %[len] \n\t" | |
"jz .+4 \n\t" | |
"jmp .-14 \n\t" | |
: [dstptr] "+r" (dstaddr), [srcaddr] "+r" (srcaddr), [len] "+r" (len) | |
: | |
: ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment