Exemplo n.º 1
0
int	main(void)
{
	CPU_INT08U  os_err;

	NVIC_Configuration( );
	
	gpio_init( ) ;
	uart1_init( ); //console port

	rtc_init();

	ADCTEMP_Configuration( );

	/* Enable CRC clock */
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);

	led_init_all( );
	led_on(POWER_LED);

	//GSM_PM_ON;
	//while ( 1 ) ;//for upgrade GSM fw
	GSM_PM_OFF;
	GPS_PM_OFF;
	CAN_PM_OFF;

	/*	Initialize "uC/OS-II, The Real-Time	Kernel".		 */
	OSInit(); //include: OSTime = 0L;

	os_err = OSTaskCreateExt((void (*)(void *)) app_task_manager,  /* Create the start task.*/
						   (void		  *	) 0,
						   (OS_STK		  *	)&app_task_manager_stk[APP_TASK_MANAGER_STK_SIZE - 1],
						   (INT8U			) APP_TASK_MANAGER_PRIO,
						   (INT16U			) APP_TASK_MANAGER_PRIO,
						   (OS_STK		  *	)&app_task_manager_stk[0],
						   (INT32U			) APP_TASK_MANAGER_STK_SIZE,
						   (void		  *	) 0,
						   (INT16U			)(OS_TASK_OPT_STK_CLR |	OS_TASK_OPT_STK_CHK));

#if	(OS_TASK_NAME_SIZE >= 11)
	OSTaskNameSet(APP_TASK_MANAGER_PRIO,	(CPU_INT08U	*)"Start Task",	&os_err);
#endif

	OSStart();	/* Start multitasking (i.e.	give control to	uC/OS-II).	*/

	return (0);  
}
Exemplo n.º 2
0
void dfu_main(void)
{
    int send_report;
    uint8_t kbd_report_loc[KBD_SIZE];

#if defined (USE_STM32L152D_EVAL)
    FLASH_Unlock();
    FLASH_ClearFlag(FLASH_FLAG_OPTVERRUSR);
#endif

    Pointer = (uint32_t)&_application_start;

    DeviceState = STATE_dfuERROR;
    DeviceStatus[0] = STATUS_ERRFIRMWARE;
    DeviceStatus[4] = DeviceState;

    usb_cable_reset();

    Set_System();

    matrix_init_all();
    led_init_all();
    matrix_scan_init();

    leds_override = LEDS_OVERRIDE_STARTUP;
    usb_report_sent = 1;
    Set_USBClock();
    USB_Init();

    matrix_scan_start();

    /* Main loop */
    send_report = 0;
    while (1){

	if (unlikely(do_usb_resume)){
	    /* Check if the remote wakeup feature is enabled (it could be disabled
	     * by the host through ClearFeature request)
	     */
	    if (bDeviceState != SUSPENDED) {
		/* do nothing */
		do_usb_resume = 0;
	    } else
	    if (usb_remote_wakeup_enabled()) {
		Resume(RESUME_INTERNAL);
		do_usb_resume = 0;
	    } else {
		/* resume disabled, disable kbd-triggered wakeup and go to the suspend state */
		matrix_idle_wakeup_event_leave();
		/* clear flag before suspend
		 * because the flag can be set again on resume
		 */
		do_usb_resume = 0; 
		Suspend_Low();
	    }
	    continue;
	}

	if (bDeviceState != CONFIGURED){
	    __WFI(); /* Wait for interrupt */
	    continue;
	}

	if (unlikely(leds_override)){
	    handle_leds_override();
	}

	__disable_irq();
	if ((kbd_report_status & REPORT_STATUS_DONE) && usb_report_sent){
	    kbd_report_status &= ~REPORT_STATUS_DONE;
	    send_report = 1;
	    memcpy((void*)kbd_report_loc, (void*)kbd_report_fullscan, KBD_SIZE);
	}
	if (unlikely((usb_report_idle_timer == 0) && (usb_report_idle != 0))){
	    send_report = 1;
	    usb_report_idle_timer = usb_report_idle;
	}
	__enable_irq();

	if (send_report){
	    usb_report_sent = 0;
	    send_report = 0;
	    USB_SIL_Write(EP1_IN, kbd_report_loc, KBD_SIZE);
	    SetEPTxCount(ENDP1, KBD_SIZE);
	    SetEPTxValid(ENDP1);
	}

	__WFI(); /* Wait for interrupt */
    }
}