#include "sr_sunrise.h"


#if 1
/*********************************************************************************************************
			led使用示例-操作系统环境下
*********************************************************************************************************/
static int LedExample(int argc, char *argv[])
{
    gShellThreadRun = 1;

    SR_LedSwitch(LED0, SR_LED_ON);  //LED0亮
	osDelay(1000);
	SR_LedSwitch(LED0, SR_LED_OFF); //LED0灭
    osDelay(1000);

	SR_LedSwitch(LED1, SR_LED_ON);  //LED1亮
	osDelay(1000);
	SR_LedSwitch(LED1, SR_LED_OFF); //LED1灭
    osDelay(1000);
		
    while (gShellThreadRun)
    {
        //LED0 闪烁4次，每次亮500ms，灭500ms
        SR_LedBlink(LED0, 4, 500, 500, 0);
        osDelay(5000);
	
        //LED1 闪烁10次，每次亮200ms，灭200ms
		SR_LedBlink(LED1, 3, 300, 300, 0);
		osDelay(5000);
		
    }

    osThreadExit();  //退出线程

    return 0;
}
SR_SHELL_CMD_EXPORT(led_exmp, LedExample);

#elif 
/*********************************************************************************************************
			led使用示例-裸机环境下
*********************************************************************************************************/
static SR_THD_RET _LedThd(void *arg)
{
    SR_GET_CT(); 				// 获取当前上下文
	SR_CT_BEGIN();			   // 上下文环境起始

	SR_LedSwitch(LED0, SR_LED_ON);  //LED0亮
	osDelay(1000);
	SR_LedSwitch(LED0, SR_LED_OFF); //LED0灭
    osDelay(1000);

	SR_LedSwitch(LED1, SR_LED_ON);  //LED1亮
	osDelay(1000);
	SR_LedSwitch(LED1, SR_LED_OFF); //LED1灭
    osDelay(1000);
		
    while (gShellThreadRun)
    {
        //LED0 闪烁4次，每次亮500ms，灭500ms
        SR_LedBlink(LED0, 4, 500, 500, 0);
        osDelay(5000);
	
        //LED1 闪烁10次，每次亮200ms，灭200ms
		SR_LedBlink(LED1, 3, 300, 300, 0);
		osDelay(5000);
		
    }

    osThreadExit();  //退出线程
    SR_CT_END(); 			// 上下文环境结束
}

static int LedExample(int argc, char *argv[])
{
    osThreadId_t ledThread = SR_NULL;

    gShellThreadRun = 1;

    ledThread = osThreadNew(_LedThd, SR_NULL, SR_NULL);

    return 0;
}
SR_SHELL_CMD_EXPORT(led_exmp, LedExample);

#endif