diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2010-10-15 21:00:54 +0200 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2010-10-25 20:58:31 +0200 |
commit | e972e1c6b7f0777416e552e2e92c0f10511f67db (patch) | |
tree | e8dfa799da41a8f6e2a197fe4c6ec7b075ec2eda /src/target/firmware/calypso/dsp.c | |
parent | e6036a111f2a6c512c30ea73c63cbc6ea3139506 (diff) |
target/fw/dsp: Add utility function to memcpy to/from the API
Copying to/from the DSP API shared memory must be done using
16 bits word only. Using those method, we avoid the hassle of
repeating the code when we copy buffer back and forth.
API address must be 16 bits aligned but for our purpose, it's
good enough.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src/target/firmware/calypso/dsp.c')
-rw-r--r-- | src/target/firmware/calypso/dsp.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/target/firmware/calypso/dsp.c b/src/target/firmware/calypso/dsp.c index 0ceb179a..425682ac 100644 --- a/src/target/firmware/calypso/dsp.c +++ b/src/target/firmware/calypso/dsp.c @@ -200,6 +200,63 @@ void dsp_api_memset(uint16_t *ptr, int octets) *ptr++ = 0; } +/* memcpy from RAM to DSP API, 16 bits by 16 bits. If odd byte count, last word will + * be zero filled */ +void dsp_memcpy_to_api(volatile uint16_t *dsp_buf, const uint8_t *mcu_buf, int n, int be) +{ + int odd, i; + + odd = n & 1; + n >>= 1; + + if (be) { + for (i=0; i<n; i++) { + uint16_t w; + w = *(mcu_buf++) << 8; + w |= *(mcu_buf++); + *(dsp_buf++) = w; + } + if (odd) + *dsp_buf = *mcu_buf << 8; + } else { + for (i=0; i<n; i++) { + uint16_t w; + w = *(mcu_buf++); + w |= *(mcu_buf++) << 8; + *(dsp_buf++) = w; + } + if (odd) + *dsp_buf = *mcu_buf; + } +} + +/* memcpy from DSP API to RAM, accessing API 16 bits word at a time */ +void dsp_memcpy_from_api(uint8_t *mcu_buf, const volatile uint16_t *dsp_buf, int n, int be) +{ + int odd, i; + + odd = n & 1; + n >>= 1; + + if (be) { + for (i=0; i<n; i++) { + uint16_t w = *(dsp_buf++); + *(mcu_buf++) = w >> 8; + *(mcu_buf++) = w; + } + if (odd) + *mcu_buf = *(dsp_buf++) >> 8; + } else { + for (i=0; i<n; i++) { + uint16_t w = *(dsp_buf++); + *(mcu_buf++) = w; + *(mcu_buf++) = w >> 8; + } + if (odd) + *mcu_buf = *(dsp_buf++); + } +} + static void dsp_audio_init(void) { T_NDB_MCU_DSP *ndb = dsp_api.ndb; |