Last active
August 29, 2015 14:00
-
-
Save spirilis/86647fb215d47c3f7441 to your computer and use it in GitHub Desktop.
MSP430 20-bit read/write from 16-bit-only compiler; inline-able form
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 */ | |
#ifndef HIGHMEM_INLINE_H | |
#define HIGHMEM_INLINE_H | |
#include <msp430.h> | |
#include <stdint.h> | |
__attribute__((always_inline)) | |
inline static 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) | |
: | |
: ); | |
} | |
__attribute__((always_inline)) | |
inline static 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) | |
: | |
: ); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment