添加移除后自动重启 for stm32-netradio
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@416 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
bb4f74cd12
commit
7225a9234e
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
#include "platform_config.h"
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
#define USB_DISCONNECT_PIN GPIO_Pin_7
|
#define USB_DISCONNECT_PIN GPIO_Pin_7
|
||||||
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOG
|
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOG
|
||||||
|
|
||||||
|
/* use auto remove: 0-NO 1-YES */
|
||||||
|
#define USB_USE_AUTO_REMOVE 1
|
||||||
|
|
||||||
/* use led: 0-NO 1-YES */
|
/* use led: 0-NO 1-YES */
|
||||||
#define USB_USE_LED 1
|
#define USB_USE_LED 1
|
||||||
#define USB_LED_PORT GPIOE
|
#define USB_LED_PORT GPIOE
|
||||||
|
@ -91,8 +91,14 @@ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint1
|
|||||||
return MAL_OK;
|
return MAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (USB_USE_AUTO_REMOVE == 1)
|
||||||
|
unsigned long test_unit_ready_last = 0;
|
||||||
|
#endif
|
||||||
uint16_t MAL_GetStatus (uint8_t lun)
|
uint16_t MAL_GetStatus (uint8_t lun)
|
||||||
{
|
{
|
||||||
|
#if (USB_USE_AUTO_REMOVE == 1)
|
||||||
|
test_unit_ready_last = rt_tick_get();
|
||||||
|
#endif
|
||||||
switch(lun)
|
switch(lun)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -12,6 +12,23 @@ extern uint32_t Mass_Block_Count[3];
|
|||||||
extern rt_device_t dev_sdio;
|
extern rt_device_t dev_sdio;
|
||||||
extern rt_device_t dev_spi_flash;
|
extern rt_device_t dev_spi_flash;
|
||||||
|
|
||||||
|
#if (USB_USE_AUTO_REMOVE == 1)
|
||||||
|
extern unsigned long test_unit_ready_last;
|
||||||
|
void msc_thread_entry(void *parameter)
|
||||||
|
{
|
||||||
|
test_unit_ready_last = rt_tick_get();
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
rt_thread_delay( RT_TICK_PER_SECOND/2 );
|
||||||
|
if( rt_tick_get() - test_unit_ready_last > RT_TICK_PER_SECOND*2 )
|
||||||
|
{
|
||||||
|
rt_kprintf("\r\nCable removed!\r\nSystemReset\r\n\r\n");
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
void USB_cable(void)
|
void USB_cable(void)
|
||||||
@ -68,5 +85,18 @@ void USB_cable(void)
|
|||||||
Set_USBClock();
|
Set_USBClock();
|
||||||
USB_Interrupts_Config();
|
USB_Interrupts_Config();
|
||||||
USB_Init();
|
USB_Init();
|
||||||
|
|
||||||
|
#if (USB_USE_AUTO_REMOVE == 1)
|
||||||
|
/* delete the other thread */
|
||||||
|
|
||||||
|
/* create msc_thread */
|
||||||
|
{
|
||||||
|
rt_thread_t msc_thread;
|
||||||
|
msc_thread = rt_thread_create("msc_thread",
|
||||||
|
msc_thread_entry, RT_NULL,
|
||||||
|
1024, RT_THREAD_PRIORITY_MAX-1,1);
|
||||||
|
if (msc_thread != RT_NULL) rt_thread_startup(msc_thread);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT(USB_cable, cable_the_usb);
|
FINSH_FUNCTION_EXPORT(USB_cable, cable_the_usb);
|
||||||
|
@ -387,6 +387,12 @@ void function_action(void* parameter)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void USB_cable(void);
|
||||||
|
void function_cable(void)
|
||||||
|
{
|
||||||
|
USB_cable();
|
||||||
|
}
|
||||||
|
|
||||||
struct list_item function_list[] =
|
struct list_item function_list[] =
|
||||||
{
|
{
|
||||||
{"选择电台", RT_NULL, function_play_radio, RT_NULL},
|
{"选择电台", RT_NULL, function_play_radio, RT_NULL},
|
||||||
@ -394,6 +400,7 @@ struct list_item function_list[] =
|
|||||||
{"播放文件", RT_NULL, function_filelist, RT_NULL},
|
{"播放文件", RT_NULL, function_filelist, RT_NULL},
|
||||||
{"设备信息", RT_NULL, function_device, RT_NULL},
|
{"设备信息", RT_NULL, function_device, RT_NULL},
|
||||||
{"选项设置", RT_NULL, function_action, RT_NULL},
|
{"选项设置", RT_NULL, function_action, RT_NULL},
|
||||||
|
{"USB 联机", RT_NULL, function_cable, RT_NULL},
|
||||||
{"返回播放器", RT_NULL, function_player, RT_NULL},
|
{"返回播放器", RT_NULL, function_player, RT_NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user