示例#1
0
文件: main.c 项目: ipTronix/SmartTool
int main(void) {

	if (GPIOGetPinValue( PIN_ISP ) == 0)
	{
		ReinvokeISP();
	}
	/* Prepare the hardware to run this demo. */
	prvSetupHardware();

	xTaskCreate(ui_task,                                /* The function that implements the task. */
				( signed char * ) "UI",                 /* The text name assigned to the task - for debug only as it is not used by the kernel. */
				200,                                    /* The size of the stack to allocate to the task. */
				NULL,                                   /* The parameter passed to the task - just to check the functionality. */
				tskIDLE_PRIORITY,                       /* The priority assigned to the task. */
				NULL );

	xTaskCreate(nfc_task,                                /* The function that implements the task. */
				( signed char * ) "NFC",                /* The text name assigned to the task - for debug only as it is not used by the kernel. */
				500,                                    /* The size of the stack to allocate to the task. */
				NULL,                                   /* The parameter passed to the task - just to check the functionality. */
				tskIDLE_PRIORITY,                       /* The priority assigned to the task. */
				NULL );

	xUIQueue = xQueueCreate(1,sizeof(secure_payload_sample_t));

	/* Start the tasks and timer running. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following
	line will never be reached.  If the following line does execute, then
	there was insufficient FreeRTOS heap memory available for the idle and/or
	timer tasks	to be created.  See the memory management section on the
	FreeRTOS web site for more details. */
	for( ;; );
}
示例#2
0
uint8_t Init_Flash(){
	read_flash();
	if(!CheckMagicCode()){
		reset_flash();
		write_flash();
	}else{
		if(option.isISP == true){
			option.isISP = false;
			write_flash();
			ReinvokeISP();
		}

	}
	return option.isOpposite;
}
示例#3
0
void ISPandReset(void){
#if CFG_USBMSC
    if(usbMSCenabled&USB_MSC_ENABLEFLAG){
        usbMSCOff();
        delayms(500);
    };
#endif
#if CFG_USBCDC
    if(1){
        USB_Connect(FALSE);
        delayms(500);
    };
#endif
    EnableWatchdog(1000*15);
    ReinvokeISP();
};
示例#4
0
文件: main.c 项目: andrmuel/r0ket
void main(void) {
    // Configure cpu and mandatory peripherals
    cpuInit();                                // Configure the CPU
// we do it later
//    systickInit(CFG_SYSTICK_DELAY_IN_MS);     // Start systick timer
// cpuInit already calls this
//    gpioInit();                               // Enable GPIO 
    pmuInit();                                // Configure power management
    adcInit();                                // Config adc pins to save power

    // initialise basic badge functions
    rbInit();

    initUUID(); // Cache UUID values.
  
    lcdInit(); // display

    lcdFill(0);
    lcdDisplay();
    
    switch(getInputRaw()){
        case BTN_ENTER:
            lcdPrint("ISP active");
            lcdRefresh();
            ReinvokeISP();
            break;
        case BTN_DOWN:
            lcdPrint("MSC active");
            lcdRefresh();
            usbMSCInit();
            while(1);
            break;
    };

    fsInit();

    if( getInputRaw() == BTN_UP ){ // Reset config
            saveConfig();
    }

	wrapper(); // see applications/ subdirectory
}
示例#5
0
文件: gpio.c 项目: redbear/DAPLink
void gpio_init(void)
{
    // enable clock for GPIO port 0
    LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 6);
#if defined(TARGET_POWER_HOLD)
    // Target PowerHOLD port
    PIN_PWH_IOCON = PIN_PWH_IOCON_INIT;
    LPC_GPIO->CLR[PIN_PWH_PORT] = PIN_PWH;
    LPC_GPIO->DIR[PIN_PWH_PORT] |= PIN_PWH;
#endif
    // configure GPIO-LED as output
#if defined(CONTROLLED_POWER_LED)
    // Power led (red)
    PIN_POW_LED_IOCON = PIN_POW_LED_IOCON_INIT;
    LPC_GPIO->CLR[PIN_POW_LED_PORT] = PIN_POW_LED;
    LPC_GPIO->DIR[PIN_POW_LED_PORT] |= PIN_POW_LED;
#endif
    // DAP led (green)
    PIN_DAP_LED_IOCON = PIN_DAP_LED_IOCON_INIT;
    LPC_GPIO->SET[PIN_DAP_LED_PORT] = PIN_DAP_LED;
    LPC_GPIO->DIR[PIN_DAP_LED_PORT] |= PIN_DAP_LED;
    // MSD led (red)
    PIN_MSD_LED_IOCON = PIN_MSD_LED_IOCON_INIT;
    LPC_GPIO->SET[PIN_MSD_LED_PORT] = PIN_MSD_LED;
    LPC_GPIO->DIR[PIN_MSD_LED_PORT] |= PIN_MSD_LED;
    // Serial LED (blue)
    PIN_CDC_LED_IOCON = PIN_CDC_LED_IOCON_INIT;
    LPC_GPIO->SET[PIN_CDC_LED_PORT] = PIN_CDC_LED;
    LPC_GPIO->DIR[PIN_CDC_LED_PORT] |= PIN_CDC_LED;
    // configure Button(s) as input
    PIN_RESET_IN_IOCON = PIN_RESET_IN_IOCON_INIT;
    LPC_GPIO->DIR[PIN_RESET_IN_PORT] &= ~PIN_RESET_IN;
    PIN_RESET_IN_FWRD_IOCON = PIN_RESET_IN_FWRD_IOCON_INIT;
    LPC_GPIO->DIR[PIN_RESET_IN_FWRD_PORT] &= ~PIN_RESET_IN_FWRD;
#if !defined(PIN_nRESET_FET_DRIVE)
    // open drain logic for reset button
    PIN_nRESET_IOCON = PIN_nRESET_IOCON_INIT;
    LPC_GPIO->CLR[PIN_nRESET_PORT] = PIN_nRESET;
    LPC_GPIO->DIR[PIN_nRESET_PORT] &= ~PIN_nRESET;
#else
    // FET drive logic for reset button
    PIN_nRESET_IOCON = PIN_nRESET_IOCON_INIT;
    LPC_GPIO->CLR[PIN_nRESET_PORT] = PIN_nRESET;
    LPC_GPIO->DIR[PIN_nRESET_PORT] |= PIN_nRESET;
#endif
    /* Enable AHB clock to the FlexInt, GroupedInt domain. */
    LPC_SYSCON->SYSAHBCLKCTRL |= ((1 << 19) | (1 << 23) | (1 << 24));
    // Give the cap on the reset button time to charge
    busy_wait(10000);

    if ((gpio_get_sw_reset() == 0) || config_ram_get_initial_hold_in_bl()) {
        IRQn_Type irq;
        // Disable SYSTICK timer and interrupt before calling into ISP
        SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);

        // Disable all nvic interrupts
        for (irq = (IRQn_Type)0; irq < (IRQn_Type)32; irq++) {
            NVIC_DisableIRQ(irq);
            NVIC_ClearPendingIRQ(irq);
        }

        // If switching to "bootloader" mode then setup the watchdog
        // so it will exit CRP mode after ~30 seconds
        if (config_ram_get_initial_hold_in_bl()) {
            LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 15); // Enable watchdog module
            LPC_SYSCON->PDRUNCFG &= ~(1 << 6);      // Enable watchdog clock (WDOSC)
            LPC_SYSCON->WDTOSCCTRL = (0xF << 5);    // Set max frequency - 2.3MHz
            LPC_WWDT->CLKSEL = (1 << 0);            // Select watchdog clock
            LPC_WWDT->TC = 0x00FFFFFF;              // Set time to reset to ~29s
            LPC_WWDT->MOD = (1 << 0) | (1 << 1);    // Enable watchdog and set reset
            LPC_WWDT->FEED = 0xAA;                  // Enable watchdog
            LPC_WWDT->FEED = 0x55;
        }

        ReinvokeISP();
    }
}