Prechádzať zdrojové kódy

update according to lwip 1.3.2

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@309 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 15 rokov pred
rodič
commit
201113c5d4

+ 7 - 40
bsp/stm32_radio/application.c

@@ -39,34 +39,13 @@
 #ifdef RT_USING_LWIP
 #include <lwip/sys.h>
 #include <lwip/api.h>
+#include <netif/ethernetif.h>
 #endif
 
 #ifdef RT_USING_RTGUI
 extern void radio_rtgui_init(void);
 #endif
 
-void sram_test_entry(void* parameter)
-{
-	rt_uint32_t *ptr;
-	rt_uint32_t index;
-	
-	ptr = (rt_uint32_t*)STM32_EXT_SRAM_BEGIN;
-	index = 0;
-	while (1)
-	{
-		*ptr = index;
-		ptr ++; index ++;
-		
-		if (ptr == (rt_uint32_t*)STM32_EXT_SRAM_END)
-		{
-			ptr = (rt_uint32_t*)STM32_EXT_SRAM_BEGIN;
-			rt_kprintf("test passed\n");
-			
-			rt_thread_delay(50);
-		}
-	}
-}
-
 /* thread phase init */
 void rt_init_thread_entry(void *parameter)
 {
@@ -112,15 +91,14 @@ void rt_init_thread_entry(void *parameter)
     {
         extern void lwip_sys_init(void);
 		extern void rt_hw_dm9000_init(void);
-		extern 
 
-		eth_system_device_init();
-	
-		/* register ethernetif device */
+		eth_system_device_init();
+
+		/* register ethernetif device */
 		rt_hw_dm9000_init();
-		/* init all device */
-		rt_device_init_all();
-
+		/* init all device */
+		rt_device_init_all();
+
         /* init lwip system */
         lwip_sys_init();
         rt_kprintf("TCP/IP initialized!\n");
@@ -131,17 +109,6 @@ void rt_init_thread_entry(void *parameter)
 	/* init netbuf worker */
 	net_buf_init(320 * 1024);
 #endif
-
-#if 0
-	{
-		rt_thread_t tid;
-		
-		tid = rt_thread_create("sram",
-			sram_test_entry, RT_NULL,
-			512, 30, 5);
-		if (tid != RT_NULL) rt_thread_startup(tid);
-	}
-#endif
 }
 
 int rt_application_init()

+ 7 - 0
bsp/stm32_radio/board.c

@@ -94,6 +94,13 @@ void NVIC_Configuration(void)
     /* Set the Vector Table base location at 0x08000000 */
     NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
 #endif
+
+	/* 
+	 * set priority group: 
+	 * 2 bits for pre-emption priority
+     * 2 bits for subpriority
+     */
+	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
 }
 
 /*******************************************************************************

+ 1 - 4
bsp/stm32_radio/dm9000.c

@@ -568,12 +568,9 @@ static void NVIC_Configuration(void)
 {
     NVIC_InitTypeDef NVIC_InitStructure;
 
-    /* Configure one bit for preemption priority */
-    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
-
     /* Enable the EXTI0 Interrupt */
     NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
-    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);

+ 281 - 4
bsp/stm32_radio/http.c

@@ -14,6 +14,8 @@ const char _http_getend[] = " HTTP/1.0\r\n";
 const char _http_user_agent[] = "User-Agent: RT-Thread HTTP Agent\r\n";
 const char _http_endheader[] = "\r\n";
 
+const char _shoutcast_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\nIcy-MetaData: 1\r\nConnection: close\r\n\r\n";
+
 extern long int strtol(const char *nptr, char **endptr, int base);
 
 //
@@ -62,6 +64,32 @@ int http_is_error_header(char *mime_buf)
 		return code;
 }
 
+int shoutcast_is_error_header(char *mime_buf)
+{
+	char *line;
+	int i;
+	int code;
+
+	line = strstr(mime_buf, "ICY");
+	line += strlen("ICY");
+
+	// Advance past minor protocol version number
+	line++;
+
+	// Advance past any whitespace characters
+	while((*line == ' ') || (*line == '\t')) line++;
+
+	// Terminate string after status code
+	for(i = 0; ((line[i] != ' ') && (line[i] != '\t')); i++);
+	line[i] = '\0';
+
+	code = (int)strtol(line, RT_NULL, 10);
+	if( code == 200 )
+		return 0;
+	else
+		return code;
+}
+
 //
 // When a request has been sent, we can expect mime headers to be
 // before the data.  We need to read exactly to the end of the headers
@@ -77,10 +105,14 @@ int http_read_line( int socket, char * buffer, int size )
 	while ( count < size )
 	{
 		rc = recv( socket, ptr, 1, 0 );
-
 		if ( rc <= 0 ) return rc;
 
-		if ( (*ptr == '\n') ) break;
+		if ((*ptr == '\n'))
+		{
+			ptr ++;
+			count++;
+			break;
+		}
 
 		// increment after check for cr.  Don't want to count the cr.
 		count++;
@@ -251,8 +283,8 @@ static int http_connect(struct http_session* session,
 		if ( rc < 0 ) return rc;
 
 		// End of headers is a blank line.  exit.
-		if ( rc == 0 ) break;
-		if ( (rc == 1) && (mimeBuffer[0] == '\r') ) break;
+		if (rc == 0) break;
+		if ((rc == 2) && (mimeBuffer[0] == '\r')) break;
 
 		// Convert mimeBuffer to upper case, so we can do string comps
 		for(i = 0; i < strlen(mimeBuffer); i++)
@@ -366,6 +398,236 @@ int http_session_close(struct http_session* session)
 	return 0;
 }
 
+//
+// This is the main HTTP client connect work.  Makes the connection
+// and handles the protocol and reads the return headers.  Needs
+// to leave the stream at the start of the real data.
+//
+static int shoutcast_connect(struct shoutcast_session* session,
+    struct sockaddr_in* server, char *host_addr, const char * url)
+{
+	int socket_handle;
+	int peer_handle;
+	int rc;
+	char mimeBuffer[100];
+
+	if((socket_handle = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP )) < 0)
+	{
+		rt_kprintf( "ICY: SOCKET FAILED\n" );
+		return -1;
+	}
+
+	peer_handle = connect( socket_handle, (struct sockaddr *) server, sizeof(*server));
+	if ( peer_handle < 0 )
+	{
+		rt_kprintf( "ICY: CONNECT FAILED %i\n", peer_handle );
+		return -1;
+	}
+
+	{
+		rt_uint8_t *buf;
+		rt_uint32_t length;
+
+		buf = rt_malloc (512);
+		length = rt_snprintf(buf, 512, _shoutcast_get, url, host_addr, server->sin_port);
+
+		rc = send(peer_handle, buf, length, 0);
+		rt_kprintf("SHOUTCAST request:\n%s", buf);
+		
+		/* release buffer */
+		rt_free(buf);
+	}
+
+	/* read the header information */
+	while ( 1 )
+	{
+		// read a line from the header information.
+		rc = http_read_line(peer_handle, mimeBuffer, 100);
+		rt_kprintf(">>%s", mimeBuffer);
+
+		if ( rc < 0 ) return rc;
+
+		// End of headers is a blank line.  exit.
+		if (rc == 0) break;
+		if ((rc == 2) && (mimeBuffer[0] == '\r')) break;
+
+		if(strstr(mimeBuffer, "ICY")) // First line of header, contains status code. Check for an error code
+		{
+			rc = shoutcast_is_error_header(mimeBuffer);
+			if(rc)
+			{
+				rt_kprintf("ICY: status code = %d!\n", rc);
+				return -rc;
+			}
+		}
+		
+		if (strstr(mimeBuffer, "HTTP/1."))
+		{
+			rc = http_is_error_header(mimeBuffer);
+			if(rc)
+			{
+				rt_kprintf("HTTP: status code = %d!\n", rc);
+				return -rc;
+			}
+		}
+
+		if (strstr(mimeBuffer, "icy-name:"))
+		{
+			/* get name */
+			char* name;
+
+			name = mimeBuffer + strlen("icy-name:");
+			session->station_name = rt_strdup(name);
+			rt_kprintf("station name: %s\n", session->station_name);
+		}
+
+		if (strstr(mimeBuffer, "icy-br:"))
+		{
+			/* get bitrate */
+			session->bitrate = strtol(mimeBuffer + strlen("icy-br:"), RT_NULL, 10);
+			rt_kprintf("bitrate: %d\n", session->bitrate);
+		}
+
+		if (strstr(mimeBuffer, "icy-metaint:"))
+		{
+			/* get metaint */
+			session->metaint = strtol(mimeBuffer + strlen("icy-metaint:"), RT_NULL, 10);
+			rt_kprintf("metaint: %d\n", session->metaint);
+		}
+		
+		if (strstr(mimeBuffer, "content-type:"))
+		{
+			/* check content-type */
+			if (strstr(mimeBuffer, "content-type:audio/mpeg") == RT_NULL)
+			{
+				rt_kprintf("ICY content is not audio/mpeg.\n");
+				return -1;
+			}
+		}
+
+		if (strstr(mimeBuffer, "Content-Type:"))
+		{
+			/* check content-type */
+			if (strstr(mimeBuffer, "Content-Type: audio/mpeg") == RT_NULL)
+			{
+				rt_kprintf("ICY content is not audio/mpeg.\n");
+				return -1;
+			}
+		}
+	}
+
+	// We've sent the request, and read the headers.  SockHandle is
+	// now at the start of the main data read for a file io read.
+	return peer_handle;
+}
+
+struct shoutcast_session* shoutcast_session_open(char* url)
+{
+	int peer_handle = 0;
+	struct sockaddr_in server;
+	const char *get_name;
+	char host_addr[32];
+	struct shoutcast_session* session;
+
+    session = (struct shoutcast_session*) rt_malloc(sizeof(struct shoutcast_session));
+	if(session == RT_NULL) return RT_NULL;
+
+	session->metaint = 0;
+	session->current_meta_chunk = 0;
+	session->bitrate = 0;
+	session->station_name = RT_NULL;
+
+	/* Check valid IP address and URL */
+	get_name = http_resolve_address(&server, url, &host_addr[0]);
+	if(get_name == NULL)
+	{
+		rt_free(session);
+		return RT_NULL;
+	}
+
+	// Now we connect and initiate the transfer by sending a
+	// request header to the server, and receiving the response header
+	if((peer_handle = shoutcast_connect(session, &server, host_addr, get_name)) < 0)
+	{
+        rt_kprintf("SHOUTCAST: failed to connect to '%s'!\n", host_addr);
+		if (session->station_name != RT_NULL)
+			rt_free(session->station_name);
+		rt_free(session);
+		return RT_NULL;
+	}
+
+	// http connect returns valid socket.  Save in handle list.
+	session->socket = peer_handle;
+
+	/* open successfully */
+	return session;
+}
+
+rt_size_t shoutcast_session_read(struct shoutcast_session* session, rt_uint8_t *buffer, rt_size_t length)
+{
+	int bytesRead = 0;
+	int totalRead = 0;
+	int left = length;
+
+	// Read until: there is an error, we've read "size" bytes or the remote
+	//             side has closed the connection.
+	do
+	{
+		bytesRead = recv(session->socket, buffer + totalRead, left, 0);
+		if(bytesRead <= 0) break;
+
+		left -= bytesRead;
+		totalRead += bytesRead;
+	} while(left);
+
+	/* handle meta */
+	if (session->current_meta_chunk + totalRead >= session->metaint)
+	{
+		int meta_length, next_chunk_length;
+
+		// rt_kprintf("c: %d, total: %d\n", session->current_meta_chunk, totalRead);
+
+		/* get the length of meta data */
+		meta_length = buffer[session->metaint - session->current_meta_chunk] * 16;
+		next_chunk_length = totalRead - (session->metaint - session->current_meta_chunk) - 
+			(meta_length + 1);
+
+		// rt_kprintf("l: %d, n: %d\n", meta_length, next_chunk_length);
+
+		/* skip meta data */
+		memmove(&buffer[session->metaint - session->current_meta_chunk], 
+			&buffer[session->metaint - session->current_meta_chunk + meta_length + 1],
+			next_chunk_length);
+
+		/* set new current meta chunk */
+		session->current_meta_chunk = next_chunk_length;
+		totalRead = totalRead - (meta_length + 1);
+		// rt_kprintf("total: %d\n", totalRead);
+	}
+	else 
+	{
+		session->current_meta_chunk += totalRead;
+	}
+
+	return totalRead;
+}
+
+rt_off_t shoutcast_session_seek(struct shoutcast_session* session, rt_off_t offset, int mode)
+{
+	/* not support seek yet */
+	return 0;
+}
+
+int shoutcast_session_close(struct shoutcast_session* session)
+{
+   	lwip_close(session->socket);
+	if (session->station_name != RT_NULL)
+		rt_free(session->station_name);
+	rt_free(session);
+
+	return 0;
+}
+
 #include <finsh.h>
 void http_test(char* url)
 {
@@ -391,3 +653,18 @@ void http_test(char* url)
 	http_session_close(session);
 }
 FINSH_FUNCTION_EXPORT(http_test, http client test);
+
+void shoutcast_test(char* url)
+{
+	struct shoutcast_session* session;
+
+	session = shoutcast_session_open(url);
+	if (session == RT_NULL)
+	{
+		rt_kprintf("open shoutcast session failed\n");
+		return;
+	}
+
+	shoutcast_session_close(session);
+}
+FINSH_FUNCTION_EXPORT(shoutcast_test, shoutcast client test);

+ 18 - 3
bsp/stm32_radio/http.h

@@ -5,9 +5,6 @@
 
 struct http_session
 {
-    char* host;
-    int   port;
-
     char* user_agent;
 	int   socket;
 
@@ -16,9 +13,27 @@ struct http_session
     rt_off_t  position;
 };
 
+struct shoutcast_session
+{
+	int   socket;
+
+	/* shoutcast name and bitrate */
+	char* station_name;
+	int   bitrate;
+
+	/* size of meta data */
+	rt_size_t metaint;
+	rt_size_t current_meta_chunk;
+};
+
 struct http_session* http_session_open(char* url);
 rt_size_t http_session_read(struct http_session* session, rt_uint8_t *buffer, rt_size_t length);
 rt_off_t http_session_seek(struct http_session* session, rt_off_t offset, int mode);
 int http_session_close(struct http_session* session);
+
+struct shoutcast_session* shoutcast_session_open(char* url);
+rt_size_t shoutcast_session_read(struct shoutcast_session* session, rt_uint8_t *buffer, rt_size_t length);
+rt_off_t shoutcast_session_seek(struct shoutcast_session* session, rt_off_t offset, int mode);
+int shoutcast_session_close(struct shoutcast_session* session);
 
 #endif

+ 90 - 60
bsp/stm32_radio/mp3.c

@@ -158,46 +158,26 @@ int mp3_decoder_run(struct mp3_decoder* decoder)
 	decoder->read_offset = MP3FindSyncWord(decoder->read_ptr, decoder->bytes_left);
 	if (decoder->read_offset < 0)
 	{
-		rt_kprintf("Error: MP3FindSyncWord returned <0");
+		/* discard this data */
+		rt_kprintf("outof sync\n");
 
-		if(mp3_decoder_fill_buffer(decoder) != 0)
-			return -1;
+		decoder->bytes_left = 0;
+		return 0;
 	}
-	// rt_kprintf("sync position: %x\n", decoder->read_offset);
 
 	decoder->read_ptr += decoder->read_offset;
 	delta = decoder->read_offset;
 	decoder->bytes_left -= decoder->read_offset;
-	decoder->bytes_left_before_decoding = decoder->bytes_left;
-
-#if 0
-	// check if this is really a valid frame
-	// (the decoder does not seem to calculate CRC, so make some plausibility checks)
-	if (!(MP3GetNextFrameInfo(decoder->decoder, &decoder->frame_info, decoder->read_ptr) == 0 &&
-			decoder->frame_info.nChans == 2 &&
-			decoder->frame_info.version == 0))
-	{
-		rt_kprintf("this is an invalid frame\n");
-		// advance data pointer
-		// TODO: handle bytes_left == 0
-		RT_ASSERT(decoder->bytes_left > 0);
-
-		decoder->bytes_left --;
-		decoder->read_ptr ++;
-		return 0;
-	}
-
 	if (decoder->bytes_left < 1024)
 	{
+		/* fill more data */
 		if(mp3_decoder_fill_buffer(decoder) != 0)
 			return -1;
 	}
-#endif
 
     /* get a decoder buffer */
     buffer = (rt_uint16_t*)sbuf_alloc();
-
-	// rt_kprintf("bytes left before decode: %d\n", decoder->bytes_left);
+	decoder->bytes_left_before_decoding = decoder->bytes_left;
 
 	err = MP3Decode(decoder->decoder, &decoder->read_ptr,
         (int*)&decoder->bytes_left, (short*)buffer, 0);
@@ -218,7 +198,11 @@ int mp3_decoder_run(struct mp3_decoder* decoder)
 			rt_kprintf("ERR_MP3_INDATA_UNDERFLOW\n");
 			decoder->bytes_left = 0;
 			if(mp3_decoder_fill_buffer(decoder) != 0)
+			{
+				/* release this memory block */
+				sbuf_release(buffer);
 				return -1;
+			}
 			break;
 
 		case ERR_MP3_MAINDATA_UNDERFLOW:
@@ -226,32 +210,9 @@ int mp3_decoder_run(struct mp3_decoder* decoder)
 			rt_kprintf("ERR_MP3_MAINDATA_UNDERFLOW\n");
 			break;
 
-		case ERR_MP3_INVALID_FRAMEHEADER:
-			rt_kprintf("ERR_MP3_INVALID_FRAMEHEADER\n");
-			rt_kprintf("current offset: 0x%08x, frames: %d\n", current_offset, decoder->frames);
-			/* dump sector */
-			{
-				rt_uint8_t *ptr;
-				rt_size_t   size = 0, col = 0;
-
-				ptr = decoder->read_buffer;
-				rt_kprintf("   00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
-				rt_kprintf("00 ");
-				while (size ++ < 512)
-				{
-					rt_kprintf("%02x ", *ptr ++);
-					if (size % 16 == 0) rt_kprintf("\n%02x ", ++col);
-				}
-			}
-			RT_ASSERT(0);
-			// break;
-
-		case ERR_MP3_INVALID_HUFFCODES:
-			rt_kprintf("ERR_MP3_INVALID_HUFFCODES\n");
-			break;
-
 		default:
-			rt_kprintf("unknown error: %i\n", err);
+			rt_kprintf("unknown error: %d, left: %d\n", err, decoder->bytes_left);
+
 			// skip this frame
 			if (decoder->bytes_left > 0)
 			{
@@ -274,18 +235,18 @@ int mp3_decoder_run(struct mp3_decoder* decoder)
 		/* no error */
 		MP3GetLastFrameInfo(decoder->decoder, &decoder->frame_info);
 
-#ifdef MP3_DECODER_TRACE
-		rt_kprintf("Bitrate: %i\n", decoder->frame_info.bitrate);
-		rt_kprintf("%i samples\n", decoder->frame_info.outputSamps);
-
-		rt_kprintf("%lu Hz, %i kbps\n", decoder->frame_info.samprate,
-            decoder->frame_info.bitrate/1000);
-#endif
-
         /* set sample rate */
 
 		/* write to sound device */
-		rt_device_write(decoder->snd_device, 0, buffer, decoder->frame_info.outputSamps * 2);
+		if (decoder->frame_info.outputSamps > 0)
+		{
+			rt_device_write(decoder->snd_device, 0, buffer, decoder->frame_info.outputSamps * 2);
+		}
+		else
+		{
+			/* no output */
+			sbuf_release(buffer);
+		}
 	}
 
 	return 0;
@@ -457,6 +418,9 @@ void http_mp3(char* url)
 {
     struct http_session* session;
 	struct mp3_decoder* decoder;
+	extern rt_bool_t is_playing;
+	
+	is_playing = RT_TRUE;
 
 	session = http_session_open(url);
 	if (session != RT_NULL)
@@ -480,4 +444,70 @@ void http_mp3(char* url)
 	}
 }
 FINSH_FUNCTION_EXPORT(http_mp3, http mp3 decode test);
+
+/* http mp3 */
+#include "http.h"
+static rt_size_t ice_fetch(rt_uint8_t* ptr, rt_size_t len, void* parameter)
+{
+	struct shoutcast_session* session = (struct shoutcast_session*)parameter;
+	RT_ASSERT(session != RT_NULL);
+
+	return shoutcast_session_read(session, ptr, len);
+}
+
+static void ice_close(void* parameter)
+{
+	struct shoutcast_session* session = (struct shoutcast_session*)parameter;
+	RT_ASSERT(session != RT_NULL);
+
+	shoutcast_session_close(session);
+}
+
+rt_size_t ice_data_fetch(void* parameter, rt_uint8_t *buffer, rt_size_t length)
+{
+	return net_buf_read(buffer, length);
+}
+
+void ice_mp3(char* url)
+{
+    struct shoutcast_session* session;
+	struct mp3_decoder* decoder;
+	extern rt_bool_t is_playing;
+
+	is_playing = RT_TRUE;
+
+	session = shoutcast_session_open(url);
+	if (session != RT_NULL)
+	{
+		/* add a job to netbuf worker */
+		net_buf_add_job(ice_fetch, ice_close, (void*)session);
+
+		decoder = mp3_decoder_create();
+		if (decoder != RT_NULL)
+		{
+			decoder->fetch_data = ice_data_fetch;
+			decoder->fetch_parameter = RT_NULL;
+
+			current_offset = 0;
+			while (mp3_decoder_run(decoder) != -1);
+
+			/* delete decoder object */
+			mp3_decoder_delete(decoder);
+		}
+		session = RT_NULL;
+	}
+}
+FINSH_FUNCTION_EXPORT(ice_mp3, shoutcast mp3 decode test);
+
+char ice_url[] = "http://192.168.1.5:8000/stream";
+void ice()
+{
+	rt_thread_t tid;
+	
+	tid = rt_thread_create("ice", ice_mp3, (void*)ice_url,
+		4096, 0x08, 5);
+	if (tid != RT_NULL) rt_thread_startup(tid);
+}
+FINSH_FUNCTION_EXPORT(ice, shoutcast thread test);
+
 #endif

+ 1 - 1
bsp/stm32_radio/netbuffer.c

@@ -265,7 +265,7 @@ static void net_buf_do_job(struct net_buffer_job* job)
 			rt_hw_interrupt_enable(level);
 		}
 
-		rt_kprintf("buffering ... %d %c\n", (data_length * 100) / _netbuf.size, '%');
+		// rt_kprintf("buffering ... %d %c\n", (data_length * 100) / _netbuf.size, '%');
 
 		if ((_netbuf.stat == NETBUF_STAT_BUFFERING) && (data_length >= _netbuf.ready_wm))
 		{

+ 36 - 36
bsp/stm32_radio/project.Opt

@@ -72,7 +72,7 @@ OPTFFF 3,45,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\interrupt.c><interrupt.c>
 OPTFFF 3,46,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\cpu.c><cpu.c> 
 OPTFFF 3,47,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\serial.c><serial.c> 
 OPTFFF 3,48,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\context_rvds.S><context_rvds.S> 
-OPTFFF 3,49,2,385875968,0,0,0,0,<..\..\libcpu\arm\stm32\start_rvds.s><start_rvds.s> 
+OPTFFF 3,49,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\start_rvds.s><start_rvds.s> 
 OPTFFF 3,50,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\fault.c><fault.c> 
 OPTFFF 3,51,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\fault_rvds.S><fault_rvds.S> 
 OPTFFF 4,52,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\misc.c><misc.c> 
@@ -92,7 +92,7 @@ OPTFFF 4,65,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_iw
 OPTFFF 4,66,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_pwr.c><stm32f10x_pwr.c> 
 OPTFFF 4,67,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_rcc.c><stm32f10x_rcc.c> 
 OPTFFF 4,68,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_rtc.c><stm32f10x_rtc.c> 
-OPTFFF 4,69,1,16777216,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_sdio.c><stm32f10x_sdio.c> 
+OPTFFF 4,69,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_sdio.c><stm32f10x_sdio.c> 
 OPTFFF 4,70,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_spi.c><stm32f10x_spi.c> 
 OPTFFF 4,71,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_tim.c><stm32f10x_tim.c> 
 OPTFFF 4,72,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_usart.c><stm32f10x_usart.c> 
@@ -142,39 +142,39 @@ OPTFFF 8,115,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_cache.c><dfs_cache.c>
 OPTFFF 9,116,1,0,0,0,0,0,<..\..\net\lwip\src\core\dhcp.c><dhcp.c> 
 OPTFFF 9,117,1,0,0,0,0,0,<..\..\net\lwip\src\core\dns.c><dns.c> 
 OPTFFF 9,118,1,0,0,0,0,0,<..\..\net\lwip\src\core\init.c><init.c> 
-OPTFFF 9,119,1,0,0,0,0,0,<..\..\net\lwip\src\core\netif.c><netif.c> 
-OPTFFF 9,120,1,0,0,0,0,0,<..\..\net\lwip\src\core\pbuf.c><pbuf.c> 
-OPTFFF 9,121,1,0,0,0,0,0,<..\..\net\lwip\src\core\raw.c><raw.c> 
-OPTFFF 9,122,1,0,0,0,0,0,<..\..\net\lwip\src\core\stats.c><stats.c> 
-OPTFFF 9,123,1,0,0,0,0,0,<..\..\net\lwip\src\core\sys.c><sys.c> 
-OPTFFF 9,124,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp.c><tcp.c> 
-OPTFFF 9,125,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_in.c><tcp_in.c> 
-OPTFFF 9,126,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_out.c><tcp_out.c> 
-OPTFFF 9,127,1,0,0,0,0,0,<..\..\net\lwip\src\core\udp.c><udp.c> 
-OPTFFF 9,128,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\autoip.c><autoip.c> 
-OPTFFF 9,129,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\icmp.c><icmp.c> 
-OPTFFF 9,130,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\igmp.c><igmp.c> 
-OPTFFF 9,131,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet.c><inet.c> 
-OPTFFF 9,132,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet_chksum.c><inet_chksum.c> 
-OPTFFF 9,133,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip.c><ip.c> 
-OPTFFF 9,134,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_addr.c><ip_addr.c> 
-OPTFFF 9,135,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_frag.c><ip_frag.c> 
-OPTFFF 9,136,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_in.c><msg_in.c> 
-OPTFFF 9,137,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_out.c><msg_out.c> 
-OPTFFF 9,138,1,0,0,0,0,0,<..\..\net\lwip\src\api\api_lib.c><api_lib.c> 
-OPTFFF 9,139,1,0,0,0,0,0,<..\..\net\lwip\src\api\api_msg.c><api_msg.c> 
-OPTFFF 9,140,1,0,0,0,0,0,<..\..\net\lwip\src\api\err.c><err.c> 
-OPTFFF 9,141,1,0,0,0,0,0,<..\..\net\lwip\src\api\netbuf.c><netbuf.c> 
-OPTFFF 9,142,1,0,0,0,0,0,<..\..\net\lwip\src\api\netdb.c><netdb.c> 
-OPTFFF 9,143,1,0,0,0,0,0,<..\..\net\lwip\src\api\netifapi.c><netifapi.c> 
-OPTFFF 9,144,1,0,0,0,0,0,<..\..\net\lwip\src\api\tcpip.c><tcpip.c> 
-OPTFFF 9,145,1,0,0,0,0,0,<..\..\net\lwip\src\netif\etharp.c><etharp.c> 
-OPTFFF 9,146,1,0,0,0,0,0,<..\..\net\lwip\src\netif\ethernetif.c><ethernetif.c> 
-OPTFFF 9,147,1,0,0,0,0,0,<..\..\net\lwip\src\netif\loopif.c><loopif.c> 
-OPTFFF 9,148,1,0,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch_init.c><sys_arch_init.c> 
-OPTFFF 9,149,1,0,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch.c><sys_arch.c> 
-OPTFFF 9,150,1,0,0,0,0,0,<..\..\net\lwip\src\api\sockets.c><sockets.c> 
-OPTFFF 9,151,1,0,0,0,0,0,<..\..\net\lwip\src\core\memp_tiny.c><memp_tiny.c> 
+OPTFFF 9,119,1,0,0,0,0,0,<..\..\net\lwip\src\core\memp.c><memp.c> 
+OPTFFF 9,120,1,0,0,0,0,0,<..\..\net\lwip\src\core\netif.c><netif.c> 
+OPTFFF 9,121,1,0,0,0,0,0,<..\..\net\lwip\src\core\pbuf.c><pbuf.c> 
+OPTFFF 9,122,1,0,0,0,0,0,<..\..\net\lwip\src\core\raw.c><raw.c> 
+OPTFFF 9,123,1,0,0,0,0,0,<..\..\net\lwip\src\core\stats.c><stats.c> 
+OPTFFF 9,124,1,0,0,0,0,0,<..\..\net\lwip\src\core\sys.c><sys.c> 
+OPTFFF 9,125,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp.c><tcp.c> 
+OPTFFF 9,126,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_in.c><tcp_in.c> 
+OPTFFF 9,127,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_out.c><tcp_out.c> 
+OPTFFF 9,128,1,0,0,0,0,0,<..\..\net\lwip\src\core\udp.c><udp.c> 
+OPTFFF 9,129,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\autoip.c><autoip.c> 
+OPTFFF 9,130,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\icmp.c><icmp.c> 
+OPTFFF 9,131,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\igmp.c><igmp.c> 
+OPTFFF 9,132,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet.c><inet.c> 
+OPTFFF 9,133,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet_chksum.c><inet_chksum.c> 
+OPTFFF 9,134,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip.c><ip.c> 
+OPTFFF 9,135,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_addr.c><ip_addr.c> 
+OPTFFF 9,136,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_frag.c><ip_frag.c> 
+OPTFFF 9,137,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_in.c><msg_in.c> 
+OPTFFF 9,138,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_out.c><msg_out.c> 
+OPTFFF 9,139,1,0,0,0,0,0,<..\..\net\lwip\src\api\api_lib.c><api_lib.c> 
+OPTFFF 9,140,1,0,0,0,0,0,<..\..\net\lwip\src\api\api_msg.c><api_msg.c> 
+OPTFFF 9,141,1,0,0,0,0,0,<..\..\net\lwip\src\api\err.c><err.c> 
+OPTFFF 9,142,1,0,0,0,0,0,<..\..\net\lwip\src\api\netbuf.c><netbuf.c> 
+OPTFFF 9,143,1,0,0,0,0,0,<..\..\net\lwip\src\api\netdb.c><netdb.c> 
+OPTFFF 9,144,1,0,0,0,0,0,<..\..\net\lwip\src\api\netifapi.c><netifapi.c> 
+OPTFFF 9,145,1,0,0,0,0,0,<..\..\net\lwip\src\api\tcpip.c><tcpip.c> 
+OPTFFF 9,146,1,0,0,0,0,0,<..\..\net\lwip\src\netif\etharp.c><etharp.c> 
+OPTFFF 9,147,1,0,0,0,0,0,<..\..\net\lwip\src\netif\ethernetif.c><ethernetif.c> 
+OPTFFF 9,148,1,0,0,0,0,0,<..\..\net\lwip\src\netif\loopif.c><loopif.c> 
+OPTFFF 9,149,1,0,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch_init.c><sys_arch_init.c> 
+OPTFFF 9,150,1,0,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch.c><sys_arch.c> 
+OPTFFF 9,151,1,0,0,0,0,0,<..\..\net\lwip\src\api\sockets.c><sockets.c> 
 OPTFFF 10,152,1,0,0,0,0,0,<.\mp3\mp3dec.c><mp3dec.c> 
 OPTFFF 10,153,1,0,0,0,0,0,<.\mp3\mp3tabs.c><mp3tabs.c> 
 OPTFFF 10,154,1,0,0,0,0,0,<.\mp3\real\bitstream.c><bitstream.c> 
@@ -218,7 +218,7 @@ OPTFFF 11,191,1,0,0,0,0,0,<..\..\rtgui\widgets\button.c><button.c>
 OPTFFF 11,192,1,0,0,0,0,0,<..\..\rtgui\widgets\container.c><container.c> 
 OPTFFF 11,193,1,0,0,0,0,0,<..\..\rtgui\widgets\iconbox.c><iconbox.c> 
 OPTFFF 11,194,1,0,0,0,0,0,<..\..\rtgui\widgets\label.c><label.c> 
-OPTFFF 11,195,1,369098752,0,0,0,0,<..\..\rtgui\widgets\textbox.c><textbox.c> 
+OPTFFF 11,195,1,0,0,0,0,0,<..\..\rtgui\widgets\textbox.c><textbox.c> 
 OPTFFF 11,196,1,0,0,0,0,0,<..\..\rtgui\widgets\title.c><title.c> 
 OPTFFF 11,197,1,0,0,0,0,0,<..\..\rtgui\widgets\toplevel.c><toplevel.c> 
 OPTFFF 11,198,1,0,0,0,0,0,<..\..\rtgui\server\mouse.c><mouse.c> 

+ 2 - 2
bsp/stm32_radio/project.Uv2

@@ -134,6 +134,7 @@ File 8,1,<..\..\filesystem\dfs\src\dfs_cache.c><dfs_cache.c>
 File 9,1,<..\..\net\lwip\src\core\dhcp.c><dhcp.c>
 File 9,1,<..\..\net\lwip\src\core\dns.c><dns.c>
 File 9,1,<..\..\net\lwip\src\core\init.c><init.c>
+File 9,1,<..\..\net\lwip\src\core\memp.c><memp.c>
 File 9,1,<..\..\net\lwip\src\core\netif.c><netif.c>
 File 9,1,<..\..\net\lwip\src\core\pbuf.c><pbuf.c>
 File 9,1,<..\..\net\lwip\src\core\raw.c><raw.c>
@@ -166,7 +167,6 @@ File 9,1,<..\..\net\lwip\src\netif\loopif.c><loopif.c>
 File 9,1,<..\..\net\lwip\src\arch\sys_arch_init.c><sys_arch_init.c>
 File 9,1,<..\..\net\lwip\src\arch\sys_arch.c><sys_arch.c>
 File 9,1,<..\..\net\lwip\src\api\sockets.c><sockets.c>
-File 9,1,<..\..\net\lwip\src\core\memp_tiny.c><memp_tiny.c>
 File 10,1,<.\mp3\mp3dec.c><mp3dec.c>
 File 10,1,<.\mp3\mp3tabs.c><mp3tabs.c>
 File 10,1,<.\mp3\real\bitstream.c><bitstream.c>
@@ -286,7 +286,7 @@ Options 1,0,0  // Target 'RT-Thread STM32 Radio'
  OCMADSXRAM { 0,0,0,0,0,0,0,0,0 }
  OCR_RVCT { 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,8,0,0,8,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,1,0,0,0,0,0,0,0,0,0,0 }
  RV_STAVEC ()
- ADSCCFLG { 5,32,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
+ ADSCCFLG { 17,34,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
  ADSCMISC ()
  ADSCDEFN (USE_STDPERIPH_DRIVER, STM32F10X_HD,)
  ADSCUDEF ()

+ 8 - 5
bsp/stm32_radio/rtconfig.h

@@ -76,11 +76,11 @@
 /* Using C++ support*/
 /* #define RT_USING_CPLUSPLUS */
 
-/* #define RT_USING_RTGUI */
-
 #define RT_USING_DFS
 #define RT_USING_DFS_EFSL
-// #define RT_USING_DFS_ELMFAT
+/* byte alignment for EFSL */
+#define BYTE_ALIGNMENT
+// #define RT_USING_DFS_ELMFAT
 #define DFS_EFLS_USING_STATIC_CACHE
 /* SECTION: DFS options */
 /* the max number of mounted filesystem */
@@ -97,6 +97,9 @@
 /* Trace LwIP protocol */
 /* #define RT_LWIP_DEBUG */
 
+/* LwIP uses RT-Thread Memory Management */
+#define RT_LWIP_USING_RT_MEM
+
 /* Enable ICMP protocol */
 #define RT_LWIP_ICMP
 
@@ -113,7 +116,7 @@
 #define RT_LWIP_TCP_PCB_NUM	3
 
 /* TCP sender buffer space */
-#define RT_LWIP_TCP_SND_BUF	1500
+#define RT_LWIP_TCP_SND_BUF	2048
 
 /* Enable SNMP protocol */
 /* #define RT_LWIP_SNMP */
@@ -153,6 +156,6 @@
 #define RT_LWIP_ETHTHREAD_STACKSIZE		512
 
 /* SECTION: RT-Thread/GUI */
-#define RT_USING_RTGUI
+#define RT_USING_RTGUI
 
 #endif

+ 5 - 5
bsp/stm32_radio/sdcard.c

@@ -2958,10 +2958,10 @@ static void DMA_RxConfiguration(uint32_t *BufferDST, uint32_t BufferSize)
   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
-  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
+  DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
-  DMA_Init(DMA2_Channel4, &DMA_InitStructure);
-
+  DMA_Init(DMA2_Channel4, &DMA_InitStructure);
+
   /* DMA2 Channel4 enable */
   DMA_Cmd(DMA2_Channel4, ENABLE);
 }
@@ -2997,8 +2997,8 @@ static rt_err_t rt_sdcard_init(rt_device_t dev)
 	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
-	NVIC_Init(&NVIC_InitStructure);
-
+	NVIC_Init(&NVIC_InitStructure);
+
 	if (rt_sem_init(&sd_lock, "sdlock", 1, RT_IPC_FLAG_FIFO) != RT_EOK)
 	{
 		rt_kprintf("init sd lock semaphore failed\n");

+ 3 - 4
bsp/stm32_radio/wm8753.c

@@ -105,7 +105,6 @@ struct wm8753_device wm8753;
 static void NVIC_Configuration(void)
 {
     NVIC_InitTypeDef NVIC_InitStructure;
-    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
 
     /* SPI2 IRQ Channel configuration */
     NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
@@ -116,7 +115,7 @@ static void NVIC_Configuration(void)
 
     /* DMA1 IRQ Channel configuration */
     NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn;
-    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
+    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);
@@ -166,7 +165,7 @@ static void DMA_Configuration(rt_uint32_t addr, rt_size_t size)
     DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
     DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
     DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
-    DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
+    DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
     DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
     DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
     DMA_Init(DMA1_Channel5, &DMA_InitStructure);
@@ -468,7 +467,7 @@ void wm8753_dma_isr()
     if (wm8753.parent.tx_complete != RT_NULL)
     {
         wm8753.parent.tx_complete (&wm8753.parent, data_ptr);
-        // rt_kprintf("-\n");
+		// rt_kprintf("<-0x%08x\n", data_ptr);
     }
 }