From 22e802e80048defd401462e062afcb10093ac793 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 30 May 2013 11:24:16 +0200 Subject: playback,talk: Share audiobuffer via core_alloc_maximum(). This fixes the radioart crash that was the result of buffering.c working on a freed buffer at the same time as buflib (radioart uses buffering.c for the images). With this change the buffer is owned by buflib exclusively so this cannot happen. As a result, audio_get_buffer() doesn't exist anymore. Callers should call core_alloc_maximum() directly. This buffer needs to be protected as usual against movement if necessary (previously it was not protected at all which cased the radioart crash), To get most of it they can adjust the willingness of the talk engine to give its buffer away (at the expense of disabling voice interface) with the new talk_buffer_set_policy() function. Change-Id: I52123012208d04967876a304451d634e2bef3a33 --- firmware/export/audio.h | 4 ---- firmware/target/arm/pp/usb-fw-pp502x.c | 15 --------------- firmware/usbstack/usb_storage.c | 17 ++++++++++++----- 3 files changed, 12 insertions(+), 24 deletions(-) (limited to 'firmware') diff --git a/firmware/export/audio.h b/firmware/export/audio.h index 8108f50939..57f7981b34 100644 --- a/firmware/export/audio.h +++ b/firmware/export/audio.h @@ -75,10 +75,6 @@ void audio_error_clear(void); int audio_get_file_pos(void); void audio_beep(int duration); -/* Required call when audio buffer is required for some other purpose */ -/* implemented in apps but called from firmware(!) */ -unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size); - #if CONFIG_CODEC == SWCODEC void audio_next_dir(void); void audio_prev_dir(void); diff --git a/firmware/target/arm/pp/usb-fw-pp502x.c b/firmware/target/arm/pp/usb-fw-pp502x.c index 44cce14389..acbb221cfd 100644 --- a/firmware/target/arm/pp/usb-fw-pp502x.c +++ b/firmware/target/arm/pp/usb-fw-pp502x.c @@ -230,21 +230,6 @@ void usb_insert_int(void) } #endif /* USB_STATUS_BY_EVENT */ -#ifdef HAVE_BOOTLOADER_USB_MODE -/* Replacement function that returns all unused memory after the bootloader - * because the storage driver uses the audio buffer */ -extern unsigned char freebuffer[]; -extern unsigned char freebufferend[]; -unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) -{ - if (buffer_size) - *buffer_size = freebufferend - freebuffer + 1; - - return freebuffer; - (void)talk_buf; -} -#endif /* HAVE_BOOTLOADER_USB_MODE */ - void usb_drv_int_enable(bool enable) { /* enable/disable USB IRQ in CPU */ diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index d1279d0ee1..a3b867319d 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c @@ -34,6 +34,7 @@ #if CONFIG_RTC #include "timefuncs.h" #endif +#include "core_alloc.h" #ifdef USB_USE_RAMDISK #define RAMDISK_SIZE 2048 @@ -430,6 +431,7 @@ int usb_storage_get_config_descriptor(unsigned char *dest,int max_packet_size) return (dest - orig_dest); } +static int usb_handle; void usb_storage_init_connection(void) { logf("ums: set config"); @@ -452,13 +454,17 @@ void usb_storage_init_connection(void) #else /* TODO : check if bufsize is at least 32K ? */ size_t bufsize; - unsigned char * audio_buffer; + unsigned char * buffer; + /* dummy ops with no callbacks, needed because by + * default buflib buffers can be moved around which must be avoided */ + static struct buflib_callbacks dummy_ops; - audio_buffer = audio_get_buffer(false,&bufsize); + usb_handle = core_alloc_maximum("usb storage", &bufsize, &dummy_ops); + buffer = core_get_data(usb_handle); #if defined(UNCACHED_ADDR) && CONFIG_CPU != AS3525 - cbw_buffer = (void *)UNCACHED_ADDR((unsigned int)(audio_buffer+31) & 0xffffffe0); + cbw_buffer = (void *)UNCACHED_ADDR((unsigned int)(buffer+31) & 0xffffffe0); #else - cbw_buffer = (void *)((unsigned int)(audio_buffer+31) & 0xffffffe0); + cbw_buffer = (void *)((unsigned int)(buffer+31) & 0xffffffe0); #endif tb.transfer_buffer = cbw_buffer + MAX_CBW_SIZE; commit_discard_dcache(); @@ -478,7 +484,8 @@ void usb_storage_init_connection(void) void usb_storage_disconnect(void) { - /* Empty for now */ + if (usb_handle > 0) + usb_handle = core_free(usb_handle); } /* called by usb_core_transfer_complete() */ -- cgit v1.2.3