mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-10 03:44:22 +00:00
clean up main
This commit is contained in:
parent
d68f882a25
commit
fdd98e2fa9
@ -64,19 +64,38 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
void print_greeting(void);
|
|
||||||
|
|
||||||
OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para);
|
OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para);
|
||||||
OSAL_TASK_DEF(led_blinking_task_def, "led blinking", led_blinking_task, 128, LED_BLINKING_APP_TASK_PRIO);
|
OSAL_TASK_DEF(led_blinking_task_def, "led blinking", led_blinking_task, 128, LED_BLINKING_APP_TASK_PRIO);
|
||||||
|
|
||||||
|
void print_greeting(void);
|
||||||
|
static inline void wait_blocking_ms(uint32_t ms);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
#if TUSB_CFG_OS == TUSB_OS_NONE
|
||||||
|
// like a real RTOS, this function is a main loop invoking each task in application and never return
|
||||||
|
void os_none_start_scheduler(void)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
tusb_task_runner();
|
||||||
|
keyboard_app_task(NULL);
|
||||||
|
mouse_app_task(NULL);
|
||||||
|
led_blinking_task(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
board_init();
|
board_init();
|
||||||
|
|
||||||
|
// TODO blocking wait --> systick handler --> ...... freeRTOS hardfault
|
||||||
|
//wait_blocking_ms(1000); // wait a bit for power stable
|
||||||
|
|
||||||
// print_greeting(); TODO uart output before freeRTOS scheduler start will lead to hardfault
|
// print_greeting(); TODO uart output before freeRTOS scheduler start will lead to hardfault
|
||||||
// find a way to fix this as tusb_init can output to uart when an error occurred
|
// find a way to fix this as tusb_init can output to uart when an error occurred
|
||||||
|
|
||||||
@ -98,15 +117,7 @@ int main(void)
|
|||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
|
|
||||||
#elif TUSB_CFG_OS == TUSB_OS_NONE
|
#elif TUSB_CFG_OS == TUSB_OS_NONE
|
||||||
print_greeting();
|
os_none_start_scheduler();
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
tusb_task_runner();
|
|
||||||
keyboard_app_task(NULL);
|
|
||||||
mouse_app_task(NULL);
|
|
||||||
led_blinking_task(NULL);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#error need to start RTOS schduler
|
#error need to start RTOS schduler
|
||||||
#endif
|
#endif
|
||||||
@ -121,6 +132,33 @@ int main(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// BLINKING TASK
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para)
|
||||||
|
{
|
||||||
|
// task init, only executed exactly one time, real RTOS does not need this but none OS does
|
||||||
|
{
|
||||||
|
static bool is_init = false;
|
||||||
|
if (!is_init)
|
||||||
|
{
|
||||||
|
is_init = true;
|
||||||
|
print_greeting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t led_on_mask = 0;
|
||||||
|
|
||||||
|
OSAL_TASK_LOOP_BEGIN
|
||||||
|
|
||||||
|
osal_task_delay(1000);
|
||||||
|
|
||||||
|
board_leds(led_on_mask, 1 - led_on_mask);
|
||||||
|
led_on_mask = 1 - led_on_mask; // toggle
|
||||||
|
|
||||||
|
OSAL_TASK_LOOP_END
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// HELPER FUNCTION
|
// HELPER FUNCTION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -135,20 +173,14 @@ void print_greeting(void)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para)
|
static inline void wait_blocking_us(volatile uint32_t us)
|
||||||
{
|
{
|
||||||
static uint32_t led_on_mask = 0;
|
us *= (SystemCoreClock / 1000000) / 3;
|
||||||
|
while(us--);
|
||||||
#if TUSB_CFG_OS != TUSB_OS_NONE // TODO abstract to approriate place
|
|
||||||
print_greeting();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
OSAL_TASK_LOOP_BEGIN
|
|
||||||
|
|
||||||
osal_task_delay(1000);
|
|
||||||
|
|
||||||
board_leds(led_on_mask, 1 - led_on_mask);
|
|
||||||
led_on_mask = 1 - led_on_mask; // toggle
|
|
||||||
|
|
||||||
OSAL_TASK_LOOP_END
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void wait_blocking_ms(uint32_t ms)
|
||||||
|
{
|
||||||
|
wait_blocking_us(ms * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -111,16 +111,6 @@ void test_usbh_init_enum_queue_create_failed(void)
|
|||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init());
|
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_usbh_init_reporter_taks_create_failed(void)
|
|
||||||
{
|
|
||||||
TEST_IGNORE();
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_usbh_init_reporter_queue_create_failed(void)
|
|
||||||
{
|
|
||||||
TEST_IGNORE();
|
|
||||||
}
|
|
||||||
|
|
||||||
void class_init_expect(void)
|
void class_init_expect(void)
|
||||||
{
|
{
|
||||||
hidh_init_Expect();
|
hidh_init_Expect();
|
||||||
|
@ -482,7 +482,8 @@ void port_connect_status_change_isr(uint8_t hostid)
|
|||||||
{
|
{
|
||||||
ehci_registers_t* const regs = get_operational_register(hostid);
|
ehci_registers_t* const regs = get_operational_register(hostid);
|
||||||
|
|
||||||
if (regs->portsc_bit.current_connect_status) // device plugged
|
// NOTE There is an sequence plug->unplug->…..-> plug if device is powering with pre-plugged device
|
||||||
|
if (regs->portsc_bit.current_connect_status)
|
||||||
{
|
{
|
||||||
usbh_device_plugged_isr(hostid);
|
usbh_device_plugged_isr(hostid);
|
||||||
}else // device unplugged
|
}else // device unplugged
|
||||||
|
Loading…
x
Reference in New Issue
Block a user