summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut2010-10-15 21:00:54 +0200
committerSylvain Munaut2010-10-25 20:58:31 +0200
commite972e1c6b7f0777416e552e2e92c0f10511f67db (patch)
treee8dfa799da41a8f6e2a197fe4c6ec7b075ec2eda
parentlayer23/vty_interface: Fix typos, AMR is v3 not v1 (diff)
downloadosmocom-e972e1c6b7f0777416e552e2e92c0f10511f67db.tar.gz
osmocom-e972e1c6b7f0777416e552e2e92c0f10511f67db.tar.xz
osmocom-e972e1c6b7f0777416e552e2e92c0f10511f67db.zip
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>
-rw-r--r--src/target/firmware/calypso/dsp.c57
-rw-r--r--src/target/firmware/include/calypso/dsp.h2
2 files changed, 59 insertions, 0 deletions
diff --git a/src/target/firmware/calypso/dsp.c b/src/target/firmware/calypso/dsp.c
index 0ceb179..425682a 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;
diff --git a/src/target/firmware/include/calypso/dsp.h b/src/target/firmware/include/calypso/dsp.h
index e232c32..e4801cb 100644
--- a/src/target/firmware/include/calypso/dsp.h
+++ b/src/target/firmware/include/calypso/dsp.h
@@ -25,6 +25,8 @@ void dsp_dump_version(void);
void dsp_dump(void);
void dsp_checksum_task(void);
void dsp_api_memset(uint16_t *ptr, int octets);
+void dsp_memcpy_to_api(volatile uint16_t *dsp_buf, const uint8_t *mcu_buf, int n, int be);
+void dsp_memcpy_from_api(uint8_t *mcu_buf, const volatile uint16_t *dsp_buf, int n, int be);
void dsp_load_afc_dac(uint16_t afc);
void dsp_load_apc_dac(uint16_t apc);
void dsp_load_tch_param(struct gsm_time *next_time,