int main (void) {
	//
	// Variables
	//
	char TCP_USER_i = 0;
	TCP_USER_INFO *TCP_USER;
	BOOL TCP_Connected = FALSE;
	int a = 0, b = 0;
	int RESET_VALUE_SEC = 0;

	//
	// Init
	//
  Init();

	// Play saved animation
	if (ANIMATION_PLAY) {
		Animation_Start();
	}

	//
	// While
	//

  while (1) {
    main_TcpNet();
    DHCP_Check();
		

		if (ftpFileClose == __TRUE && ftpFileWrite == __TRUE) {
			ftpFileClose = __FALSE;
			ftpFileWrite = __FALSE;

			if (strstr((char *)ftpFileOpen, "device.settings")) {
				Delay_ms(2000);
				NVIC_SystemReset();
			}
		}
		
		/*****************************************************************************
		** 1 ms timer
		*****************************************************************************/
		
		if (TICK_1MS == __TRUE) {
			TICK_1MS = __FALSE;
					
			if (ANIMATION_PLAY) {
				if (DelayValue >= ((currentEffect.delay+1) * getDelayUnitValue(currentEffect.delayUnit))) {
					DelayValue = 0;

					if (CurrentAnimationEffect >= AnimationEffectsCount - 1) {
						CurrentAnimationEffect = 0;
					} else {
						CurrentAnimationEffect++;
					}
					
					Animation_Read_Effect();
				} else {
					DelayValue++;
				}
			}	
		}
				
		/*****************************************************************************
		** 10 ms timer
		*****************************************************************************/
		
		if (TICK_10MS == __TRUE) {
			TICK_10MS = __FALSE;

		}
		
		/*****************************************************************************
		** 100 ms timer
		*****************************************************************************/
		
		if (TICK_100MS == __TRUE) {
			TICK_100MS = __FALSE;

			/*****************************************************************************
			** reset button
			*****************************************************************************/
			
			if (!(LPC_GPIO1->FIOPIN & (1<<RESET_BUTTON_PIN))) {		
				if (RESET_VALUE_SEC >= 5) {
					RESET_VALUE_SEC = 0;
					
					Status_LED1_Set(TRUE);
					Status_LED2_Set(TRUE);
				
					while (!(LPC_GPIO1->FIOPIN & (1<<RESET_BUTTON_PIN)));
					
					SPI_FLASH_Delete_All_Files();
					NVIC_SystemReset();
					
					Status_LED1_Set(FALSE);
					Status_LED2_Set(FALSE);
				}
			} else {
				RESET_VALUE_SEC = 0;
			}
		}
		
		/*****************************************************************************
		** 1 s timer
		*****************************************************************************/
		
		if (TICK_1S == __TRUE) {
			TICK_1S = __FALSE;

			if (ANIMATION_PLAY) {
				Status_LED2_Toggle();
			} else {
				Status_LED2_Set(FALSE);
			}
			
			if (TCP_Connected) {
				Status_LED1_Set(TRUE);
			} else {
				Status_LED1_Set(FALSE);
			}
			
			if (!(LPC_GPIO1->FIOPIN & (1<<RESET_BUTTON_PIN))) {
				RESET_VALUE_SEC++;
			}
		}
		
		/*****************************************************************************
		** UDP Socket Listener
		*****************************************************************************/
		
		if (UDP_Socket_Listener_Data_Received == TRUE) {
			UDP_Socket_Listener_Data_Received = FALSE; // Clear listener

			switch (UDP_Receive_Check(UDP_Socket_Buffer_Receive, UDP_Socket_Receive_Length)) {
				case PROTOCOL_UDP_ReceiveCheckWhich_search_device:	
					UDP_Socket_Send_Length = UDP_Send_Search_Device(UDP_Socket_Buffer_Send, (char *)DEVICE_IP, (char *)SETTINGS_DATA[DEVICE_NAME]);
					
					UDP_Socket_Send(UDP_Socket_Buffer_Send, UDP_Socket_Send_Length, UDP_Socket_Remote_IP);
					break;
				case PROTOCOL_UDP_ReceiveCheckWhich_cube_set:
					if (ANIMATION_PLAY == FALSE) {
						for (a=0; a<8; a++) {
							for (b=0; b<8; b++) {
								cube[a][b] = UDP_Socket_Buffer_Receive[(((a * 8) + b) + 6)];
							}
						}
					}
					break;
				case PROTOCOL_UDP_ReceiveCheckWhich_reset_device:
					NVIC_SystemReset();
					break;
				default:
					break;
			}
		}
		
		/*****************************************************************************
		** TCP Users Listener
		*****************************************************************************/
		
		TCP_Connected = FALSE;
		
		for (TCP_USER_i=0; TCP_USER_i<TCP_USER_NUMBER_OF_SESSIONS; TCP_USER_i++) {
			TCP_USER = &TCP_USER_SESSIONS[TCP_USER_i];
			
			if (TCP_USER->State == TCP_USER_STATE_CONNECTED) {
				TCP_Connected = TRUE;
			}
			
			/* ------------------- CONNECT ------------------ */
			if (TCP_USER->Connect_Flag == TRUE) {
				TCP_USER->Connect_Flag = FALSE; // Clear interrupt flag

			}

			/* ------------------- DISCONNECT --------------- */
			if (TCP_USER->Disconnect_Flag == TRUE) {
				TCP_USER->Disconnect_Flag = FALSE; // Clear interrupt flag

			}
			
			/* ------------------- RECEIVE ------------------ */
			if (TCP_USER->Received_Flag == TRUE) {
				TCP_USER->Received_Flag = FALSE; // Clear interrupt flag
				
				switch (TCP_Receive_Check(TCP_USER->Buffer_Receive, TCP_USER->Buffer_Receive_Length)) {
					case PROTOCOL_TCP_ReceiveCheckWhich_cube_set:
						if (ANIMATION_PLAY == FALSE) {
							for (a=0; a<8; a++) {
								for (b=0; b<8; b++) {
									cube[a][b] = TCP_USER->Buffer_Receive[(((a * 8) + b)+6)];
								}
							}
						}
						break;
					case PROTOCOL_TCP_ReceiveCheckWhich_start_animation:
						AnimationFileName = GetAnimationFileNameFromBuffer(TCP_USER->Buffer_Receive, TCP_USER->Buffer_Receive_Length);
						
						Animation_Start();
						break;
					case PROTOCOL_TCP_ReceiveCheckWhich_stop_animation:
						
						Animation_Stop();
						break;
					default:
						break;
				}
			}
		}
		
		/*****************************************************************************
		** UART CONSOLE Listener
		*****************************************************************************/
		
		if (UART_Count[UART_CONSOLE_NUMBER] > 0) {
			UART_RBR_Disable(UART_CONSOLE_NUMBER);
			
			// program


			// end
			
			UART_Count[UART_CONSOLE_NUMBER] = 0;
			
			UART_RBR_Enable(UART_CONSOLE_NUMBER);
		}
  }
}
Beispiel #2
0
static void reboot(uint8_t argc, char **argv) {
    NVIC_SystemReset();
}
/**@brief Function for bootloader main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool     dfu_start = false;
    bool     app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START);

    if (app_reset)
    {
        NRF_POWER->GPREGRET = 0;
    }
    
    leds_init();

    // This check ensures that the defined fields in the bootloader corresponds with actual
    // setting in the nRF51 chip.
    APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
    APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE);

    // Initialize.
    timers_init();
    buttons_init();

    (void)bootloader_init();

    if (bootloader_dfu_sd_in_progress())
    {
        nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED);

        err_code = bootloader_dfu_sd_update_continue();
        APP_ERROR_CHECK(err_code);

        ble_stack_init(!app_reset);
        scheduler_init();

        err_code = bootloader_dfu_sd_update_finalize();
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED);
    }
    else
    {
        // If stack is present then continue initialization of bootloader.
        ble_stack_init(!app_reset);
        scheduler_init();
    }

    dfu_start  = app_reset;
    dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false);
    
    if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START)))
    {
        nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED);

        // Initiate an update of the firmware.
        err_code = bootloader_dfu_start();
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED);
    }

    if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress())
    {
        // Select a bank region to use as application region.
        // @note: Only applications running from DFU_BANK_0_REGION_START is supported.
        bootloader_app_start(DFU_BANK_0_REGION_START);
    }
    
    NVIC_SystemReset();
}
Beispiel #4
0
void HID_ProcessCommand(uint8_t *request, uint8_t *response)
{
	uint8_t result   = DAP_OK;
	uint16_t data;
	uint16_t length;
	uint32_t address;
	uint8_t *p_address;

	if ((*request >= HID_Command0) && (*request <= HID_Command7))
	{
		*response++ = *request;
		switch (*request++)
		{
		case HID_Command0:		/* Get device info */
			address = DBGMCU->IDCODE;
			*response++ = (address >>  0) & 0xFF;
			*response++ = (address >>  8) & 0xFF;
			*response++ = (address >> 16) & 0xFF;
			*response++ = (address >> 24) & 0xFF;
			break;
		case HID_Command1:
			FLASH_Unlock();
			break;
		case HID_Command2:
			FLASH_Lock();
			break;
		case HID_Command3:
			address = PACK_DATA_LONG(0);
			if (FLASH_ErasePage(address) != FLASH_COMPLETE)
				result = DAP_ERROR;
			break;
		case HID_Command4:		/* Check for blank (0xFF) */
			{
				p_address = PACK_DATA_PBYTE(0);
				length  = PACK_DATA_WORD(4);
				while (length-- != 0)
				{
					if (*p_address++ != 0xFF)
					{
						result = DAP_ERROR;
						break;
					}
				}
			}
			break;
		case HID_Command5:		/* Write to flash */
			{
				address = PACK_DATA_LONG(0);
				length  = PACK_DATA_WORD(4);
				if (length > (DAP_PACKET_SIZE - (8+2)))	// Check for maximum data payload
					result = DAP_ERROR;
				else
				{
					request += 8;
					while (length-- != 0)
					{
						data = *request++;
						if (length != 0)
						{
							data |= ((uint16_t)(*request++) << 8);
							length--;
						}
						if (FLASH_ProgramHalfWord(address, data) != FLASH_COMPLETE)
						{
							result = DAP_ERROR;
							break;
						}
						address += 2;
					}
				}
			}
			break;
		case HID_Command6:		/* Read from flash */
			{
				p_address = PACK_DATA_PBYTE(0);
				length  = PACK_DATA_WORD(4);
				if (length > (DAP_PACKET_SIZE - (2)))	// Check for maximum data payload
					result = DAP_ERROR;
				else
					while (length-- != 0)
						*response++ = *p_address++;
			}
			break;
		case HID_Command7:		/* Reset device */
			NVIC_SystemReset();
			break;
		default:
			*(--response) = ID_DAP_Invalid;
			return;
		}
		*response++ = result;
		return;
	}
Beispiel #5
0
void SystemInit(void)
{
    /* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product
       Specification to see which one). Only available if the developing environment is an nRF52832 device. */
    #if defined (DEVELOP_IN_NRF52832) && defined (ENABLE_SWO)
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos;
        NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
    #endif
    
    /* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product
       Specification to see which ones). Only available if the developing environment is an nRF52832 device. */
    #if defined (DEVELOP_IN_NRF52832) && defined (ENABLE_TRACE)
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos;
        NRF_P0->PIN_CNF[14] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[15] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[16] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[20] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
    #endif
    
    #if defined (DEVELOP_IN_NRF52832)
    /* Workaround for Errata 12 "COMP: Reference ladder not correctly calibrated" found at the Errata document
       for nRF52832 device located at https://www.nordicsemi.com/DocLib */
    if (errata_12()){
        *(volatile uint32_t *)0x40013540 = (*(uint32_t *)0x10000324 & 0x00001F00) >> 8;
    }
    #endif
    
    #if defined (DEVELOP_IN_NRF52832)
    /* Workaround for Errata 16 "System: RAM may be corrupt on wakeup from CPU IDLE" found at the Errata document
       for nRF52832 device located at https://www.nordicsemi.com/DocLib */
    if (errata_16()){
        *(volatile uint32_t *)0x4007C074 = 3131961357ul;
    }
    #endif
    
    /* Workaround for Errata 31 "CLOCK: Calibration values are not correctly loaded from FICR at reset" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib */
    if (errata_31()){
        *(volatile uint32_t *)0x4000053C = ((*(volatile uint32_t *)0x10000244) & 0x0000E000) >> 13;
    }

    #if defined (DEVELOP_IN_NRF52832)
    /* Workaround for Errata 32 "DIF: Debug session automatically enables TracePort pins" found at the Errata document
       for nRF52832 device located at https://www.nordicsemi.com/DocLib */
    if (errata_32()){
        CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
    }
    #endif
    
    /* Workaround for Errata 36 "CLOCK: Some registers are not reset when expected" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_36()){
        NRF_CLOCK->EVENTS_DONE = 0;
        NRF_CLOCK->EVENTS_CTTO = 0;
        NRF_CLOCK->CTIV = 0;
    }
    
    #if defined (DEVELOP_IN_NRF52832)
    /* Workaround for Errata 37 "RADIO: Encryption engine is slow by default" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_37()){
        *(volatile uint32_t *)0x400005A0 = 0x3;
    }
    #endif

    #if defined (DEVELOP_IN_NRF52832)
    /* Workaround for Errata 57 "NFCT: NFC Modulation amplitude" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_57()){
        *(volatile uint32_t *)0x40005610 = 0x00000005;
        *(volatile uint32_t *)0x40005688 = 0x00000001;
        *(volatile uint32_t *)0x40005618 = 0x00000000;
        *(volatile uint32_t *)0x40005614 = 0x0000003F;
    }
    #endif
    
    /* Workaround for Errata 66 "TEMP: Linearity specification not met with default settings" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_66()){
        NRF_TEMP->A0 = NRF_FICR->TEMP.A0;
        NRF_TEMP->A1 = NRF_FICR->TEMP.A1;
        NRF_TEMP->A2 = NRF_FICR->TEMP.A2;
        NRF_TEMP->A3 = NRF_FICR->TEMP.A3;
        NRF_TEMP->A4 = NRF_FICR->TEMP.A4;
        NRF_TEMP->A5 = NRF_FICR->TEMP.A5;
        NRF_TEMP->B0 = NRF_FICR->TEMP.B0;
        NRF_TEMP->B1 = NRF_FICR->TEMP.B1;
        NRF_TEMP->B2 = NRF_FICR->TEMP.B2;
        NRF_TEMP->B3 = NRF_FICR->TEMP.B3;
        NRF_TEMP->B4 = NRF_FICR->TEMP.B4;
        NRF_TEMP->B5 = NRF_FICR->TEMP.B5;
        NRF_TEMP->T0 = NRF_FICR->TEMP.T0;
        NRF_TEMP->T1 = NRF_FICR->TEMP.T1;
        NRF_TEMP->T2 = NRF_FICR->TEMP.T2;
        NRF_TEMP->T3 = NRF_FICR->TEMP.T3;
        NRF_TEMP->T4 = NRF_FICR->TEMP.T4;
    }
    
    /* Workaround for Errata 103 "CCM: Wrong reset value of CCM MAXPACKETSIZE" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_103()){
        NRF_CCM->MAXPACKETSIZE = 0xFBul;
    }
    
    #if defined (DEVELOP_IN_NRF52832)
    /* Workaround for Errata 108 "RAM: RAM content cannot be trusted upon waking up from System ON Idle or System OFF mode" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_108()){
        *(volatile uint32_t *)0x40000EE4 = *(volatile uint32_t *)0x10000258 & 0x0000004F;
    }
    #endif
    
    /* Workaround for Errata 136 "System: Bits in RESETREAS are set when they should not be" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_136()){
        if (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk){
            NRF_POWER->RESETREAS =  ~POWER_RESETREAS_RESETPIN_Msk;
        }
    }
    
    #if defined (DEVELOP_IN_NRF52832)
    /* Workaround for Errata 182 "RADIO: Fixes for anomalies #102, #106, and #107 do not take effect" found at the Errata document
       for your device located at https://www.nordicsemi.com/DocLib  */
    if (errata_182()){
        *(volatile uint32_t *) 0x4000173C |= (0x1 << 10);
    }
    #endif

    /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not
      defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be
      reserved for PinReset and not available as normal GPIO. */
    #if defined (CONFIG_GPIO_AS_PINRESET)
        if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
            ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->PSELRESET[0] = 21;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->PSELRESET[1] = 21;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NVIC_SystemReset();
        }
    #endif

    SystemCoreClockUpdate();
}
Beispiel #6
0
/// \function hard_reset()
/// Resets the pyboard in a manner similar to pushing the external RESET
/// button.
STATIC mp_obj_t pyb_hard_reset(void) {
    NVIC_SystemReset();
    return mp_const_none;
}
Beispiel #7
0
int
main (void)
{
/* accelerometer readings fifo */
		TFifoEntry acc_lowpass;
		TFifoEntry fifo_buf[FIFO_DEPTH];
		int fifo_pos;
		TFifoEntry *fifo;

		uint32_t SSPdiv;
		uint16_t oid_last_seen;
		uint8_t cmd_buffer[64], cmd_pos, c;
		uint8_t volatile *uart;
		int x, y, z, moving;
		volatile int t;
		int i;

		/* wait on boot - debounce */
		for (t = 0; t < 2000000; t++);

		/* Initialize GPIO (sets up clock) */
		GPIOInit ();

		/* initialize pins */
		pin_init ();

		/* fire up LED 1 */
		GPIOSetValue (1, 1, 1);

		/* initialize SPI */
		spi_init ();

		/* read device UUID */
		bzero (&device_uuid, sizeof (device_uuid));
		iap_read_uid (&device_uuid);
		tag_id = crc16 ((uint8_t *) & device_uuid, sizeof (device_uuid));
		random_seed =
				device_uuid[0] ^ device_uuid[1] ^ device_uuid[2] ^ device_uuid[3];

		/************ IF Plugged to computer upon reset ? ******************/
		if (GPIOGetValue (0, 3))
		{
			/* wait some time till Bluetooth is off */
			for (t = 0; t < 2000000; t++);

			/* Init 3D acceleration sensor */
			acc_init (1);
			/* Init Flash Storage with USB */
			storage_init (TRUE, tag_id);
			g_storage_items = storage_items ();

			/* Init Bluetooth */
			bt_init (TRUE, tag_id);

			/* switch to LED 2 */
			GPIOSetValue (1, 1, 0);
			GPIOSetValue (1, 2, 1);

			/* set command buffer to empty */
			cmd_pos = 0;

			/* spin in loop */
			while (1)
			{
				/* reset after USB unplug */
				if (!GPIOGetValue (0, 3))
					NVIC_SystemReset ();

				/* if UART rx send to menue */
				if (UARTCount)
				{
					/* blink LED1 upon Bluetooth command */
					GPIOSetValue (1, 1, 1);
					/* execute menue command with last character received */

					/* scan through whole UART buffer */
					uart = UARTBuffer;
					for (i = UARTCount; i > 0; i--)
					{
						UARTCount--;
						c = *uart++;
						if ((c < ' ') && cmd_pos)
						{
							/* if one-character command - execute */
							if (cmd_pos == 1)
								main_menue (cmd_buffer[0]);
							else
							{
								cmd_buffer[cmd_pos] = 0;
								debug_printf
								("Unknown command '%s' - please press H+[Enter] for help\n# ",
										cmd_buffer);
							}

							/* set command buffer to empty */
							cmd_pos = 0;
						}
						else if (cmd_pos < (sizeof (cmd_buffer) - 2))
							cmd_buffer[cmd_pos++] = c;
					}

					/* reset UART buffer */
					UARTCount = 0;
					/* un-blink LED1 */
					GPIOSetValue (1, 1, 0);
				}
			}
		} /* End of if plugged to computer*/


		/***************** IF UNPLUGGED TO PC ........********/

		/* Init Bluetooth */
		bt_init (FALSE, tag_id);

		/* shut down up LED 1 */
		GPIOSetValue (1, 1, 0);

		/* Init Flash Storage without USB */
		storage_init (FALSE, tag_id);

		/* get current FLASH storage write postition */
		g_storage_items = storage_items ();

		/* initialize power management */
		pmu_init ();

		/* blink once to show initialized flash */
		blink (1);

		/* Init 3D acceleration sensor */
		acc_init (0);
		blink (2);

		/* Initialize OpenBeacon nRF24L01 interface */
		if (!nRFAPI_Init(CONFIG_TRACKER_CHANNEL, broadcast_mac, sizeof (broadcast_mac), 0))
			for (;;)
			{
				GPIOSetValue (1, 2, 1);
				pmu_sleep_ms (500);
				GPIOSetValue (1, 2, 0);
				pmu_sleep_ms (500);
			}
		/* set tx power power to high */
		nRFCMD_Power (1);

		/* blink three times to show flash initialized RF interface */
		blink (3);

		/* blink LED for 1s to show readyness */
		GPIOSetValue (1, 1, 0);
		GPIOSetValue (1, 2, 1);
		pmu_sleep_ms (1000);
		GPIOSetValue (1, 2, 0);

		/* disable unused jobs */
		SSPdiv = LPC_SYSCON->SSPCLKDIV;
		i = 0;
		oid_last_seen = 0;

		/* reset proximity buffer */
		prox_head = prox_tail = 0;
		bzero (&prox, sizeof (prox));

		/*initialize FIFO */
		fifo_pos = 0;
		bzero (&acc_lowpass, sizeof (acc_lowpass));
		bzero (&fifo_buf, sizeof (fifo_buf));

		moving = 0;
		g_sequence = 0;

		while (1)
		{
			
			pmu_sleep_ms (500);

			LPC_SYSCON->SSPCLKDIV = SSPdiv;
			acc_power (1);
			pmu_sleep_ms (20);
			acc_xyz_read (&x, &y, &z);
			acc_power (0);

			fifo = &fifo_buf[fifo_pos];
			if (fifo_pos >= (FIFO_DEPTH - 1))
				fifo_pos = 0;
			else
				fifo_pos++;

			acc_lowpass.x += x - fifo->x;
			fifo->x = x;
			acc_lowpass.y += y - fifo->y;
			fifo->y = y;
			acc_lowpass.z += z - fifo->z;
			fifo->z = z;


			nRFAPI_SetRxMode (0);

			bzero (&g_Beacon, sizeof (g_Beacon));
			g_Beacon.pkt.proto = RFBPROTO_BEACONTRACKER_EXT;
			g_Beacon.pkt.flags = moving ? RFBFLAGS_MOVING : 0;
			g_Beacon.pkt.oid = htons (tag_id);
			g_Beacon.pkt.p.tracker.strength = (i & 1) + TX_STRENGTH_OFFSET;
			g_Beacon.pkt.p.tracker.seq = htonl (LPC_TMR32B0->TC);
			g_Beacon.pkt.p.tracker.oid_last_seen = oid_last_seen;
			g_Beacon.pkt.p.tracker.time = htons ((uint16_t)g_sequence++);
			g_Beacon.pkt.p.tracker.battery = 0;
			g_Beacon.pkt.crc = htons (
					crc16(g_Beacon.byte, sizeof (g_Beacon) - sizeof (g_Beacon.pkt.crc))
					);

			nRFCMD_Power (0);
			nRF_tx (g_Beacon.pkt.p.tracker.strength);
			nRFCMD_Power (1);
			nRFAPI_PowerDown ();
			LPC_SYSCON->SSPCLKDIV = 0x00;
			blink (10);
		}
		

	
	return 0;
}
Beispiel #8
0
static void sldReviveCallback(WM_MESSAGE* pMsg)
{
   const WM_KEY_INFO* pKeyInfo;
   
   WM_MESSAGE  myMsg;
   
   switch(pMsg->MsgId)
   {
      case WM_KEY:
           pKeyInfo  = (WM_KEY_INFO*)pMsg->Data.p;
           switch(pKeyInfo->Key)
           {
              case GUI_KEY_RIGHT:
              case GUI_KEY_ENTER:
                   myMsg.hWin      = WM_GetClientWindow(confirmWin);            
                   myMsg.hWinSrc   = pMsg->hWin;
                   myMsg.MsgId     = USER_MSG_CHOOSE;
                   myMsg.Data.v    = SYS_REVIVE;
                   WM_SendMessage(myMsg.hWin, &myMsg);
 
                   WM_BringToTop(confirmWin);
                   WM_SetFocus(WM_GetDialogItem(confirmWin, GUI_ID_BUTTON0));
                   break;
              
              case GUI_KEY_BACKSPACE:
                   if(Mem_isEqual(&SysConf, &agentConf, sizeof(SysConf)) )
                   {
                      WM_SetFocus(Slideres[0]);
                      WM_SetFocus(menuWin);                      
                   }
                   else
                   {
                      myMsg.hWin  = WM_GetClientWindow(confirmWin);
                      myMsg.hWinSrc  = subWins[3];
                      myMsg.MsgId  = USER_MSG_CHOOSE;
                      myMsg.Data.v  = SYS_SETTING;
                      WM_SendMessage(myMsg.hWin, &myMsg);
                      
                      WM_BringToTop(confirmWin);
                      WM_SetFocus(WM_GetDialogItem (confirmWin,GUI_ID_BUTTON0));                    
                   }
                   break;
                   
             default:
                   HSD_SLIDER_Callback(pMsg);
                   break;
           }
           break;
           
      case USER_MSG_REPLY:
           WM_SetFocus(Slideres[0]);
           WM_BringToTop(subWins[3]);
           if(pMsg->Data.v == REPLY_OK )
           {
              if(SysConf.Skin != DEFAULT_SKIN) 
              {
                 myMsg.MsgId  = USER_MSG_SKIN;
                 myMsg.Data.v  = DEFAULT_SKIN;
                 WM_BroadcastMessage(&myMsg);
                 agentConf.Skin  = SysConf.Skin;
              }
              
              if(SysConf.Shape != DEFAULT_SHAPE)
              {
                 myMsg.hWin  = mapWin;
                 myMsg.MsgId  = USER_MSG_SHAPE;
                 myMsg.Data.v  = DEFAULT_SHAPE;
                 WM_SendMessage(myMsg.hWin, &myMsg);
                 agentConf.Shape  = SysConf.Shape;
              } 
              sysRevive();
              
              HSD_SLIDER_SetValue(Slideres[0], SysConf.Skin);
              HSD_SLIDER_SetValue(Slideres[5], 0);
              GUI_Delay(1000);
              HSD_SLIDER_SetValue(Slideres[1], SysConf.Brt);
              HSD_SLIDER_SetValue(Slideres[5], 1);
              GUI_Delay(1000);
              
              HSD_SLIDER_SetValue(Slideres[2], SysConf.Vol);
              HSD_SLIDER_SetValue(Slideres[5], 2);
              GUI_Delay(1000);
              
              HSD_SLIDER_SetValue(Slideres[3], SysConf.Unit);
              HSD_SLIDER_SetValue(Slideres[5], 3);
              GUI_Delay(1000);
              
              HSD_SLIDER_SetValue(Slideres[4], SysConf.Shape);
              HSD_SLIDER_SetValue(Slideres[5], 4);
              GUI_Delay(1000);
              
              HSD_SLIDER_SetValue(Slideres[5], 0);
              
              NVIC_SystemReset();
              
           } 

           break;
           
    default:
           HSD_SLIDER_Callback(pMsg);
           break;
   }
}
Beispiel #9
0
/***************************************************************************//**
 * @brief
 *   AT command parser.
 *
 * @details
 *   This function is the main AT parser function to call when a new input
 *   character is received from the main idle loop.
 *
 *   It will perform lexical analysis, argument collection and call the piece of
 *   code in charge of handling the corresponding AT command.
 *
 * @param[in] c
 *   The new character to parse.
 ******************************************************************************/
void AT_Parse(char c)
{
	uint32_t x, y;
	int extension, i;
	char td_serial[13];

#if defined(__ICCARM__)
	extern unsigned char CSTACK$$Base;
	extern unsigned char CSTACK$$Limit;
	unsigned char *memptr;
#elif defined(__GNUC__)
	extern unsigned char __end;
	extern unsigned char __cs3_region_end_ram;
	unsigned char *memptr;
#endif

	uint8_t token = AT_PARSE;
	int8_t result = AT_OK, extension_result = AT_PARSE;
	uint8_t echo, verbosity, quiet_result, extended_result, banner;
	TD_DEVICE device = {0, 0, 0, 0, 0};
	TD_DEVICE_EXT device_ext = {
		1,
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	};

	for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
		if (AT_extension[extension] == 0) {
			break;
		}
		if (AT_extension[extension]->tokenize != 0) {
			token = AT_extension[extension]->tokenize(c);
			if (token == AT_ESCAPE) {
				return;
			}
			if (token > AT_BASE_LAST) {
				break;
			}
		}
	}
	if (AT_echo) {
		switch (AT_state) {
		case AT_A:
			if (c == 'A' || c == 'a') {
				tfp_printf("%c", c);
			}
			break;

		case AT_AT:
			if (c == 'T' || c == 't' || c == '/') {
				tfp_printf("%c", c);
			} else {
				tfp_printf("\b \b");
			}
			break;

		default:
			if (c == '\b' || c == 0x7f) {
				if (AT_last > &AT_buffer[2]) {
					tfp_printf("\b \b");
				}
			} else if (c == '\r' || c == '\n') {
				tfp_printf("\r");
			} else {
				tfp_printf("%c", c);
			}
			break;
		}
	}
	if (token == AT_PARSE) {
		token = AT_Tokenize(c, &extension);
	}
	if (token > AT_BASE_LAST && extension < AT_EXTENSION_NUMBER && AT_extension[extension]->parse != 0) {
		extension_result = AT_extension[extension]->parse(token);
		if (extension_result != AT_NOTHING) {
			AT_PrintResult(extension_result);
		}
		return;
	}
	switch (token) {
	case AT_PARSE:
		result = AT_NOTHING;
		break;

	case AT_UNKNOWN:
		result = AT_ERROR;
		break;

	case AT:
		break;

	case AT_DISPLAY_CONFIG:
		for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
			if (AT_extension[extension] == 0) {
				break;
			}
			if (AT_extension[extension]->status != 0) {
				AT_extension[extension]->status(false);
			}
		}
		AT_printf("%s\r\n", CONFIG_MANUFACTURER);
		tfp_printf("Hardware Version: %s\r\n", CONFIG_HARDWARE_VERSION);
		tfp_printf("Software Version: %s\r\n", CONFIG_SOFTWARE_VERSION);
		TD_FLASH_DeviceRead(&device);
		tfp_printf("S/N: %08X\r\n", device.Serial);
		if (TD_FLASH_DeviceReadExtended(&device, &device_ext) == true) {
			for (i = 0; i < 12; i++) {
				td_serial[i] = device_ext.TDSerial[i];
			}
			td_serial[12] = '\0';
			if (td_serial[0] != '?') {
				tfp_printf("TDID: %12s\r\n", td_serial);
			}
		}
		tfp_printf("ACTIVE PROFILE\r\n");
		tfp_printf("E%d V%d Q%d",
				   AT_echo,
				   AT_verbose,
				   AT_quietResult);
		tfp_printf(" X%d S200:%d",
				   AT_extended,
				   AT_banner
				  );
		for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
			if (AT_extension[extension] == 0) {
				break;
			}
			if (AT_extension[extension]->status != 0) {
				AT_extension[extension]->status(true);
			}
		}
		tfp_printf("\r\n");
		break;

	case AT_FACTORY:
		AT_verbose = true;
		AT_extended = true;
		AT_echo = true;
		AT_quietResult = false;
		AT_banner = AT_FORCE_BANNER ? true : false;
		for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
			if (AT_extension[extension] == 0) {
				break;
			}
			if (AT_extension[extension]->init != 0) {
				AT_extension[extension]->init();
			}
		}
		break;

	case AT_GET_BANNER:
		if (AT_argc == 0) {
			AT_printf("%d\r\n", AT_banner);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_HARDWARE_REV:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_HARDWARE_VERSION);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_HELP:
		if (AT_argc == 0) {
			AT_printf("%s", AT_help);
			for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
				if (AT_extension[extension] == 0) {
					break;
				}
				if (AT_extension[extension]->help != 0) {
					AT_extension[extension]->help();
				}
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_MANUFACTURER:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_MANUFACTURER);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_PRODUCT_REV:
		if (AT_argc == 0) {
			if (TD_FLASH_DeviceRead(&device)) {
				AT_printf("%02X\r\n", device.ProdResult);
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_QUERY_BANNER:
		if (AT_argc != 0) {
			result = AT_ERROR;
		} else {
			AT_printf("0..1\r\n");
		}
		break;

	case AT_RELEASE_DATE:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_RELEASE_DATE);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_RESET:
		if (AT_argc == 0) {
			AT_PrintResult(result);
			TD_RTC_Delay(T100MS);
			NVIC_SystemReset();
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SERIAL_NUMBER:
		if (AT_argc == 0) {
			TD_FLASH_DeviceRead(&device);
			AT_printf("%04X\r\n", device.Serial);
			if (TD_FLASH_DeviceReadExtended(&device, &device_ext) == true) {
				for (i = 0; i < 12; i++) {
					td_serial[i] = device_ext.TDSerial[i];
				}
				td_serial[12] = '\0';
				tfp_printf("TDID: %12s\r\n", td_serial);
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_BANNER:
		if (AT_argc == 1) {
			banner = AT_atoll(AT_argv[0]);
			if (banner > 1) {
				result = AT_ERROR;
			} else {
				AT_banner = banner;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_ECHO:
		if (AT_argc == 0) {
			AT_echo = false;
		} else if (AT_argc == 1) {
			echo = AT_atoll(AT_argv[0]);
			if (echo < 2) {
				AT_echo = echo ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_EXTENDED_RESULTS:
		if (AT_argc == 0) {
			AT_extended = true;
		} else if (AT_argc == 1) {
			extended_result = AT_atoll(AT_argv[0]);
			if (extended_result < 2) {
				AT_extended =  extended_result ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_QUIET:
		if (AT_argc == 0) {
			AT_quietResult = true;
		} else if (AT_argc == 1) {
			quiet_result = AT_atoll(AT_argv[0]);
			if (quiet_result < 2) {
				AT_quietResult = quiet_result ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_VERBOSITY:
		if (AT_argc == 0) {
			AT_verbose =  true;
		} else if (AT_argc == 1) {
			verbosity = AT_atoll(AT_argv[0]);
			if (verbosity < 2) {
				AT_verbose = verbosity ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SOFTWARE_REV:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_SOFTWARE_VERSION);
		} else {
			result = AT_ERROR;
		}
		break;

#if defined(__ICCARM__)
	case AT_FREE_STACK:
		memptr = &CSTACK$$Base;
		while (memptr < &CSTACK$$Limit) {
			if (*memptr++ != 0xCD) {
				break;
			}
		}
		AT_printf("Free Stack: %d bytes", memptr - &CSTACK$$Base);
		break;
#elif defined(__GNUC__)
	case AT_FREE_STACK:
		memptr = &__end;
		while (memptr < &__cs3_region_end_ram) {
			if (*memptr++ != 0xCD) {
				break;
			}
		}
		AT_printf("Free Stack: %d bytes", memptr - &__end);
		break;
#endif

	case AT_UNIQUE_ID:
		if (AT_argc == 0) {
			x = DEVINFO->UNIQUEH;
			y = DEVINFO->UNIQUEL;
			AT_printf("%08X%08X\r\n", x, y);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_WRITE_CONFIG:
		if (AT_argc == 0) {
			AT_SavePersistBuffer();
			TD_FLASH_WriteVariables();
		} else {
			result = AT_ERROR;
		}
		break;

	default:
		result = AT_ERROR;
		break;
	}
	AT_PrintResult(result);
}
Beispiel #10
0
/**
  * @brief  IAP jump to user program
  * @param  None
  * @retval None
  */
void COMMAND_JUMP(void)
{
  /* Software reset */
  NVIC_SystemReset();
}
Beispiel #11
0
__reset_hardware()
{
	NVIC_SystemReset();
}
Beispiel #12
0
void bootloader_restart( void )
{
    NVIC_SystemReset();
    while(1){}
}
Beispiel #13
0
/************************************************************************************
*************************************************************************************
* Public functions
*************************************************************************************
************************************************************************************/
void ResetMCU(void)
{
  NVIC_SystemReset();
  while(1);
}
Beispiel #14
0
vsf_err_t stm32_interface_reset(void *p)
{
	NVIC_SystemReset();
	return VSFERR_NONE;
}
Beispiel #15
0
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
    nrf_gpio_pin_clear(ASSERT_LED_PIN_NO);

    NVIC_SystemReset();
}
Beispiel #16
0
void SystemInit(void)
{
    /* Workaround for Errata 16 "System: RAM may be corrupt on wakeup from CPU IDLE" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/ */
    if (errata_16()){
        *(volatile uint32_t *)0x4007C074 = 3131961357ul;
    }

    /* Workaround for Errata 31 "CLOCK: Calibration values are not correctly loaded from FICR at reset" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/ */
    if (errata_31()){
        *(volatile uint32_t *)0x4000053C = ((*(volatile uint32_t *)0x10000244) & 0x0000E000) >> 13;
    }

    /* Workaround for Errata 32 "DIF: Debug session automatically enables TracePort pins" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/ */
    if (errata_32()){
        CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
    }

    /* Workaround for Errata 36 "CLOCK: Some registers are not reset when expected" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_36()){
        NRF_CLOCK->EVENTS_DONE = 0;
        NRF_CLOCK->EVENTS_CTTO = 0;
        NRF_CLOCK->CTIV = 0;
    }

    /* Workaround for Errata 37 "RADIO: Encryption engine is slow by default" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_37()){
        *(volatile uint32_t *)0x400005A0 = 0x3;
    }

    /* Workaround for Errata 57 "NFCT: NFC Modulation amplitude" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_57()){
        *(volatile uint32_t *)0x40005610 = 0x00000005;
        *(volatile uint32_t *)0x40005688 = 0x00000001;
        *(volatile uint32_t *)0x40005618 = 0x00000000;
        *(volatile uint32_t *)0x40005614 = 0x0000003F;
    }

    /* Workaround for Errata 66 "TEMP: Linearity specification not met with default settings" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_66()){
        NRF_TEMP->A0 = NRF_FICR->TEMP.A0;
        NRF_TEMP->A1 = NRF_FICR->TEMP.A1;
        NRF_TEMP->A2 = NRF_FICR->TEMP.A2;
        NRF_TEMP->A3 = NRF_FICR->TEMP.A3;
        NRF_TEMP->A4 = NRF_FICR->TEMP.A4;
        NRF_TEMP->A5 = NRF_FICR->TEMP.A5;
        NRF_TEMP->B0 = NRF_FICR->TEMP.B0;
        NRF_TEMP->B1 = NRF_FICR->TEMP.B1;
        NRF_TEMP->B2 = NRF_FICR->TEMP.B2;
        NRF_TEMP->B3 = NRF_FICR->TEMP.B3;
        NRF_TEMP->B4 = NRF_FICR->TEMP.B4;
        NRF_TEMP->B5 = NRF_FICR->TEMP.B5;
        NRF_TEMP->T0 = NRF_FICR->TEMP.T0;
        NRF_TEMP->T1 = NRF_FICR->TEMP.T1;
        NRF_TEMP->T2 = NRF_FICR->TEMP.T2;
        NRF_TEMP->T3 = NRF_FICR->TEMP.T3;
        NRF_TEMP->T4 = NRF_FICR->TEMP.T4;
    }

    /* Enable the FPU if the compiler used floating point unit instructions. __FPU_USED is a MACRO defined by the
     * compiler. Since the FPU consumes energy, remember to disable FPU use in the compiler if floating point unit
     * operations are not used in your code. */
    #if (__FPU_USED == 1)
        SCB->CPACR |= (3UL << 20) | (3UL << 22);
        __DSB();
        __ISB();
    #endif

    /* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined,
       two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available as
       normal GPIOs. */
    #if defined (CONFIG_NFCT_PINS_AS_GPIOS)
        if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NVIC_SystemReset();
        }
    #endif

    /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not
      defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be
      reserved for PinReset and not available as normal GPIO. */
    #if defined (CONFIG_GPIO_AS_PINRESET)
        if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
            ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->PSELRESET[0] = 21;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->PSELRESET[1] = 21;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NVIC_SystemReset();
        }
    #endif

    /* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product
       Specification to see which one). */
    #if defined (ENABLE_SWO)
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos;
        NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
    #endif

    /* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product
       Specification to see which ones). */
    #if defined (ENABLE_TRACE)
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos;
        NRF_P0->PIN_CNF[14] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[15] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[16] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[20] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
    #endif

    SystemCoreClockUpdate();
}
/**
 * \brief Main application
 */
int main(void)
{
	uint32_t len;
	uint32_t curr_prog_addr;
	uint32_t tmp_len;
	uint8_t buff[NVMCTRL_PAGE_SIZE];
	struct nvm_config config;

	/* Check switch state to enter boot mode or application mode */
	check_boot_mode();

	/*
	 * Application to be programmed from APP_START_ADDRESS defined in
	 * conf_bootloader.h
	 */
	curr_prog_addr = APP_START_ADDRESS;

	/* Initialize system */
	system_init();


	/* Configure the SPI slave module */
	configure_spi();

	/* Get NVM default configuration and load the same */
	nvm_get_config_defaults(&config);
	config.manual_page_write = false;
	nvm_set_config(&config);

	/* Turn on LED */
	port_pin_set_output_level(BOOT_LED, false);
	/* Get the length to be programmed */
	len = get_length();

	do {
		/* Get remaining or NVMCTRL_PAGE_SIZE as block length */
		tmp_len = min(NVMCTRL_PAGE_SIZE, len);

		/* Acknowledge last received data */
		send_ack();

		/* Read data from SPI master */
		fetch_data(buff, tmp_len);

		/* Program the data into Flash */
		program_memory(curr_prog_addr, buff, tmp_len);

		/* Increment the current programming address */
		curr_prog_addr += tmp_len;

		/* Update the length to remaining length to be programmed */
		len -= tmp_len;

		/* Do this for entire length */
	} while (len != 0);

	/* Acknowledge last block */
	send_ack();

	/* Reset module and boot into application */
	NVIC_SystemReset();

	while (1) {
		/* Inf loop */
	}

}
Beispiel #18
0
// Resets the pyboard in a manner similar to pushing the external RESET button.
STATIC mp_obj_t machine_reset(void) {
    NVIC_SystemReset();
    return mp_const_none;
}
/*
 * 系统软件复位
 */
void Soft_Reset(void)
{
  __set_FAULTMASK(1);   /* 关闭所有中断 */  
  NVIC_SystemReset();   /* 系统复位 */
}
Beispiel #20
0
Datei: scb.c Projekt: kraj/zephyr
void __weak sys_arch_reboot(int type)
{
	ARG_UNUSED(type);

	NVIC_SystemReset();
}
Beispiel #21
0
void LTK_Sys_Soft_Reset(void)
{   
    NVIC_SystemReset();
}
Beispiel #22
0
void SystemInit(void)
{
    /* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product
       Specification to see which one). */
#if defined (ENABLE_SWO)
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos;
        NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
#endif

    /* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product
       Specification to see which ones). */
#if defined (ENABLE_TRACE)
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos;
        NRF_P0->PIN_CNF[14] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[15] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[16] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
        NRF_P0->PIN_CNF[20] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
#endif
    
    /* Workaround for Errata 12 "COMP: Reference ladder not correctly calibrated" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/ */
    if (errata_12()){
        *(volatile uint32_t *)0x40013540 = (*(uint32_t *)0x10000324 & 0x00001F00) >> 8;
    }
    
    /* Workaround for Errata 16 "System: RAM may be corrupt on wakeup from CPU IDLE" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/ */
    if (errata_16()){
        *(volatile uint32_t *)0x4007C074 = 3131961357ul;
    }

    /* Workaround for Errata 31 "CLOCK: Calibration values are not correctly loaded from FICR at reset" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/ */
    if (errata_31()){
        *(volatile uint32_t *)0x4000053C = ((*(volatile uint32_t *)0x10000244) & 0x0000E000) >> 13;
    }

    /* Workaround for Errata 32 "DIF: Debug session automatically enables TracePort pins" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/ */
    if (errata_32()){
        CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
    }

    /* Workaround for Errata 36 "CLOCK: Some registers are not reset when expected" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_36()){
        NRF_CLOCK->EVENTS_DONE = 0;
        NRF_CLOCK->EVENTS_CTTO = 0;
        NRF_CLOCK->CTIV = 0;
    }

    /* Workaround for Errata 37 "RADIO: Encryption engine is slow by default" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_37()){
        *(volatile uint32_t *)0x400005A0 = 0x3;
    }

    /* Workaround for Errata 57 "NFCT: NFC Modulation amplitude" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_57()){
        *(volatile uint32_t *)0x40005610 = 0x00000005;
        *(volatile uint32_t *)0x40005688 = 0x00000001;
        *(volatile uint32_t *)0x40005618 = 0x00000000;
        *(volatile uint32_t *)0x40005614 = 0x0000003F;
    }

    /* Workaround for Errata 66 "TEMP: Linearity specification not met with default settings" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_66()){
        NRF_TEMP->A0 = NRF_FICR->TEMP.A0;
        NRF_TEMP->A1 = NRF_FICR->TEMP.A1;
        NRF_TEMP->A2 = NRF_FICR->TEMP.A2;
        NRF_TEMP->A3 = NRF_FICR->TEMP.A3;
        NRF_TEMP->A4 = NRF_FICR->TEMP.A4;
        NRF_TEMP->A5 = NRF_FICR->TEMP.A5;
        NRF_TEMP->B0 = NRF_FICR->TEMP.B0;
        NRF_TEMP->B1 = NRF_FICR->TEMP.B1;
        NRF_TEMP->B2 = NRF_FICR->TEMP.B2;
        NRF_TEMP->B3 = NRF_FICR->TEMP.B3;
        NRF_TEMP->B4 = NRF_FICR->TEMP.B4;
        NRF_TEMP->B5 = NRF_FICR->TEMP.B5;
        NRF_TEMP->T0 = NRF_FICR->TEMP.T0;
        NRF_TEMP->T1 = NRF_FICR->TEMP.T1;
        NRF_TEMP->T2 = NRF_FICR->TEMP.T2;
        NRF_TEMP->T3 = NRF_FICR->TEMP.T3;
        NRF_TEMP->T4 = NRF_FICR->TEMP.T4;
    }

    /* Workaround for Errata 108 "RAM: RAM content cannot be trusted upon waking up from System ON Idle or System OFF mode" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_108()){
        *(volatile uint32_t *)0x40000EE4 = *(volatile uint32_t *)0x10000258 & 0x0000004F;
    }
    
    /* Workaround for Errata 136 "System: Bits in RESETREAS are set when they should not be" found at the Errata document
       for your device located at https://infocenter.nordicsemi.com/  */
    if (errata_136()){
        if (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk){
            NRF_POWER->RESETREAS =  ~POWER_RESETREAS_RESETPIN_Msk;
        }
    }
    
    /* Enable the FPU if the compiler used floating point unit instructions. __FPU_USED is a MACRO defined by the
     * compiler. Since the FPU consumes energy, remember to disable FPU use in the compiler if floating point unit
     * operations are not used in your code. */
#if (__FPU_USED == 1)
        SCB->CPACR |= (3UL << 20) | (3UL << 22);
        __DSB();
        __ISB();
#endif

    /* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined,
       two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available as
       normal GPIOs. */
#if defined (CONFIG_NFCT_PINS_AS_GPIOS)
        if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NVIC_SystemReset();
        }
#endif

    /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not
      defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be
      reserved for PinReset and not available as normal GPIO. */
#if defined (CONFIG_GPIO_AS_PINRESET)
        if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
            ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->PSELRESET[0] = 21;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_UICR->PSELRESET[1] = 21;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
            NVIC_SystemReset();
        }
#endif

    SystemCoreClockUpdate();

    // Start the LF oscilator according to the mbed configuration (over the nrf5x_lf_clk_helper.h file)
    NRF_CLOCK->LFCLKSRC             = (CLOCK_LFCLKSRC_SRC_TO_USE << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED  = 0;
    NRF_CLOCK->TASKS_LFCLKSTART     = 1;

    // Wait for the external oscillator to start up.
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
        // Do nothing.
    }

    /**
     * Mbed HAL specific code section.
     *
     * The ITM has to be initialized before the SoftDevice which weren't guaranteed using the normal API.
     */
#if defined (DEVICE_ITM)
        /* Enable SWO trace functionality */
        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
        NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos;

        /* set SWO clock speed to 4 MHz */
        NRF_CLOCK->TRACECONFIG = (NRF_CLOCK->TRACECONFIG & ~CLOCK_TRACECONFIG_TRACEPORTSPEED_Msk) |
                                 (CLOCK_TRACECONFIG_TRACEPORTSPEED_4MHz << CLOCK_TRACECONFIG_TRACEPORTSPEED_Pos);

        /* set SWO pin */
        NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
                              (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
                              (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);

        /* set prescaler */
        TPI->ACPR = 0;
#endif
}
Beispiel #23
0
void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
{
    cmd = (enum usbdbg_cmd) request;
    switch (cmd) {
        case USBDBG_FW_VERSION:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_FRAME_SIZE:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_FRAME_DUMP:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_ARCH_STR:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_SCRIPT_EXEC:
            xfer_bytes = 0;
            xfer_length = length;
            vstr_reset(&script_buf);
            break;

        case USBDBG_SCRIPT_STOP:
            if (script_running) {
                // Set script running flag
                script_running = false;

                // Disable IDE IRQ (re-enabled by pyexec or main).
                usbdbg_set_irq_enabled(false);

                // interrupt running code by raising an exception
                mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
                pendsv_nlr_jump(mp_const_ide_interrupt);
            }
            cmd = USBDBG_NONE;
            break;

        case USBDBG_SCRIPT_SAVE:
            /* save running script */
            // TODO
            break;

        case USBDBG_SCRIPT_RUNNING:
            xfer_bytes = 0;
            xfer_length =length;
            break;

        case USBDBG_TEMPLATE_SAVE:
        case USBDBG_DESCRIPTOR_SAVE:
            /* save template */
            xfer_bytes = 0;
            xfer_length =length;
            break;

        case USBDBG_ATTR_WRITE: {
            /* write sensor attribute */
            int16_t attr= *((int16_t*)buffer);
            int16_t val = *((int16_t*)buffer+1);
            switch (attr) {
                case ATTR_CONTRAST:
                    sensor_set_contrast(val);
                    break;
                case ATTR_BRIGHTNESS:
                    sensor_set_brightness(val);
                    break;
                case ATTR_SATURATION:
                    sensor_set_saturation(val);
                    break;
                case ATTR_GAINCEILING:
                    sensor_set_gainceiling(val);
                    break;
                default:
                    break;
            }
            cmd = USBDBG_NONE;
            break;
        }

        case USBDBG_SYS_RESET:
            NVIC_SystemReset();
            break;

        case USBDBG_FB_ENABLE: {
            int16_t enable = *((int16_t*)buffer);
            JPEG_FB()->enabled = enable;
            if (enable == 0) {
                // When disabling framebuffer, the IDE might still be holding FB lock.
                // If the IDE is not the current lock owner, this operation is ignored.
                mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE);
            }
            cmd = USBDBG_NONE;
            break;
        }

        case USBDBG_TX_BUF:
        case USBDBG_TX_BUF_LEN:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        default: /* error */
            cmd = USBDBG_NONE;
            break;
    }
}
/**
 * @brief  Main program.
 * @param  None
 * @retval None
 */
int main(void) {
	/*!< At this stage the microcontroller clock setting is already configured to
	 168 MHz, this is done through SystemInit() function which is called from
	 startup file (startup_stm32f4xx.s) before to branch to application main.
	 To reconfigure the default setting of SystemInit() function, refer to
	 system_stm32f4xx.c file
	 */

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

#ifdef SERIAL_DEBUG /* Configure serial debugging. */
	DebugComPort_Init();
#endif
#ifdef DEBUG
	printf("\n\rSerial Port Initialized.\n\r");
#endif

	/* Enable the PWR APB1 Clock Interface */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

	/* Allow access to BKP Domain */
	PWR_BackupAccessCmd(ENABLE);

	if ((RTC_ReadBackupRegister(RTC_CONFIGURED_REG ) & RTC_CONFIGURED)
			!= RTC_CONFIGURED) {
#ifdef DEBUG
		printf("[Main] Configuring the RTC domain.\n\r");
#endif
		/* Initialize the RTC and Backup registers */
		/* RTC_Config(); */

		/* Setup date and time */
		/* TODO: Set up date and time */
	} else {
		/* Wait for RTC APB registers synchronization */
		RTC_WaitForSynchro();
	}

	/* Setup Watchdog debug leds */

	/**
	 * Check if the system has resumed from a WWDG reset
	 */
	if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST ) != RESET) {
		/* This is a watchdog reset */

		/* Clear the reset flags */
		RCC_ClearFlag();

		/* Do any watchdog reset specific stuff here */
		/* TODO: Watchdog reset specific handling */
	} else {
		/* This is not a watchdog reset */
		/* Do any normal reset stuff here */
		if (RCC_GetFlagStatus(RCC_FLAG_SFTRST )) {
			/* Software reset */
		} else if (RCC_GetFlagStatus(RCC_FLAG_PORRST )) {
			/* Power on Reset/Power down reset */
		} else if (RCC_GetFlagStatus(RCC_FLAG_PINRST )) {
			/* Reset pin reset */
		} else {
			/* Some other reset */
		}
	}

	/* Clear the reset flags */
	RCC_ClearFlag();

	/* Initialize the Tekdaqc's peripheral hardware */
	Tekdaqc_Init();

	Init_Locator();

	if (InitializeTelnetServer() == TELNET_OK) {
		CreateCommandInterpreter();
		program_loop();
	} else {
		/* We have a fatal error */
		/* Reset the board */
		NVIC_SystemReset();
	}
	return 0;
}
Beispiel #25
0
/**
  * @brief  Initiates a system reset request to reset the MCU.
  * @retval None
  */
void HAL_NVIC_SystemReset(void)
{
  /* System Reset */
  NVIC_SystemReset();
}
Beispiel #26
0
static void hdl_mrst(void)
{
	CMD_CLEAR();
	cmd_resp(RET_OK, VAL_NONE);
	NVIC_SystemReset();
}
/**@brief Error handlers.
 *
 * @details
 */
void ble_app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name) {
  jsiConsolePrintf("NRF ERROR 0x%x at %s:%d\n", error_code, p_file_name, line_num);
  jsiConsolePrint("REBOOTING.\n");
  jshTransmitFlush();
  NVIC_SystemReset();
}
Beispiel #28
0
void usbdbg_data_out(void *buffer, int length)
{
    switch (cmd) {
        case USBDBG_SCRIPT_EXEC:
            // check if GC is locked before allocating memory for vstr. If GC was locked
            // at least once before the script is fully uploaded xfer_bytes will be less
            // than the total length (xfer_length) and the script will Not be executed.
            if (usbdbg_get_irq_enabled() && !gc_is_locked()) {
                vstr_add_strn(&script_buf, buffer, length);
                xfer_bytes += length;
                if (xfer_bytes == xfer_length) {
                    // Set script ready flag
                    script_ready = 1;
                    // Disable IDE IRQ (re-enabled by pyexec or main).
                    usbdbg_set_irq_enabled(false);
                    // interrupt running script/REPL
                    mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
                    pendsv_nlr_jump_hard(mp_const_ide_interrupt);
                }
            }
            break;

        case USBDBG_TEMPLATE_SAVE: {
            image_t image ={
                .w = fb->w,
                .h = fb->h,
                .bpp = fb->bpp,
                .pixels = fb->pixels
            };

            // null terminate the path
            length = (length == 64) ? 63:length; 
            ((char*)buffer)[length] = 0;

            rectangle_t *roi = (rectangle_t*)buffer;
            char *path = (char*)buffer+sizeof(rectangle_t);

            int res=imlib_save_image(&image, path, roi);
            if (res != FR_OK) {
                nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
            }
            // raise a flash IRQ to flush image
            //NVIC->STIR = FLASH_IRQn;
            break;
        }

        case USBDBG_DESCRIPTOR_SAVE: {
            image_t image ={
                .w = fb->w,
                .h = fb->h,
                .bpp = fb->bpp,
                .pixels = fb->pixels
            };

            // null terminate the path
            length = (length == 64) ? 63:length; 
            ((char*)buffer)[length] = 0;

            rectangle_t *roi = (rectangle_t*)buffer;
            char *path = (char*)buffer+sizeof(rectangle_t);

            py_image_descriptor_from_roi(&image, path, roi);
            break;
        }
        default: /* error */
            break;
    }
}

void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
{
    cmd = (enum usbdbg_cmd) request;
    switch (cmd) {
        case USBDBG_FW_VERSION:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_FRAME_SIZE:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_FRAME_DUMP:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_FRAME_LOCK:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        case USBDBG_FRAME_UPDATE:
            sensor_snapshot(NULL);
            cmd = USBDBG_NONE;
            break;

        case USBDBG_SCRIPT_EXEC:
            xfer_bytes = 0;
            xfer_length =length;
            vstr_reset(&script_buf);
            break;

        case USBDBG_SCRIPT_STOP:
            if (usbdbg_get_irq_enabled()) {
                // Disable IDE IRQ (re-enabled by pyexec or main).
                usbdbg_set_irq_enabled(false);
                // interrupt running code by raising an exception
                mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
                pendsv_nlr_jump_hard(mp_const_ide_interrupt);
            }
            cmd = USBDBG_NONE;
            break;

        case USBDBG_SCRIPT_SAVE:
            /* save running script */
            break;

        case USBDBG_TEMPLATE_SAVE:
        case USBDBG_DESCRIPTOR_SAVE:
            /* save template */
            xfer_bytes = 0;
            xfer_length =length;
            break;

        case USBDBG_ATTR_WRITE: {
            /* write sensor attribute */
            int16_t attr= *((int16_t*)buffer);
            int16_t val = *((int16_t*)buffer+1);
            switch (attr) {
                case ATTR_CONTRAST:
                    sensor_set_contrast(val);
                    break;
                case ATTR_BRIGHTNESS:
                    sensor_set_brightness(val);
                    break;
                case ATTR_SATURATION:
                    sensor_set_saturation(val);
                    break;
                case ATTR_GAINCEILING:
                    sensor_set_gainceiling(val);
                    break;
                default:
                    break;
            }
            cmd = USBDBG_NONE;
            break;
        }

        case USBDBG_SYS_RESET:
            NVIC_SystemReset();
            break;

        case USBDBG_BOOT:
            *((uint32_t *)0x20002000) = 0xDEADBEEF;
            NVIC_SystemReset();
            break;

        case USBDBG_TX_BUF:
        case USBDBG_TX_BUF_LEN:
            xfer_bytes = 0;
            xfer_length = length;
            break;

        default: /* error */
            cmd = USBDBG_NONE;
            break;
    }
}
Beispiel #29
0
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
    NVIC_SystemReset();
}
void DataTerminal::processByte(uint8_t byte)
{
    switch(mState) {
        case STATE_WAITING:
            if ( byte == START_TRANSFER_CMD ) {
                mState = STATE_IN_TRANSFER_HEADER;
                mByteCount = 0;
                trace_printf("Receiving metadata\n");
                GPIO_SetBits(GPIOB, GPIO_Pin_14);
                writeCmd(ACK);
            }
            else {
                trace_printf("Bad command: %.2x\n", byte);
                fail();
            }
            break;
        case STATE_IN_TRANSFER_HEADER: {
            //trace_printf("1 byte\n");
            char *p = (char*)&mMetadata;
            memcpy(p + mByteCount, &byte, 1);
            ++mByteCount;
            if ( mByteCount == sizeof mMetadata ) {
                trace_printf("Magick: %.8x\n", mMetadata.magic);
                // Is the metadata sane?
                if ( mMetadata.magic == METADATA_MAGIC ) {
                    mState = STATE_IN_TRANSFER_BLOCK;
                    trace_printf("Expecting %d bytes\n", mMetadata.size);
                    printmd5(mMetadata.md5);
                    GPIO_SetBits(GPIOB, GPIO_Pin_14);
                    mByteCount = 0;
                    mWriteAddress = APPLICATION_ADDRESS;
                    MD5Init(&mMD5);
                    unlockFlash();
                    writeCmd(ACK);
                }
                else {
                    trace_printf("Bad metadata \n");
                    fail();
                }
            }
            }
            break;
        case STATE_IN_TRANSFER_BLOCK:
            MD5Update(&mMD5, &byte, 1);
            if ( mByteCount == 0 ) {
                GPIO_SetBits(GPIOB, GPIO_Pin_15);
            }

            size_t offset = mByteCount % FLASH_PAGE_SIZE;
            assert(offset < sizeof mCurrPage);
            memcpy(mCurrPage + offset, &byte, 1);

            ++mByteCount;

            if ( mByteCount % FLASH_PAGE_SIZE == 0 ) {
                flushPage();
            }

            // Acknowledge every 1K
            if ( mByteCount % 1024 == 0 ) {
                trace_printf("Sending ACK\n");
                writeCmd(ACK);
            }


            if ( mByteCount == mMetadata.size ) {
                if ( mMetadata.size % 1024 ) {
                    // We have a partial page to write
                    flushPage();
                    writeCmd(ACK);
                }

                // Last byte!
                trace_printf("Received %d bytes\n", mMetadata.size);
                GPIO_ResetBits(GPIOB, GPIO_Pin_14);
                mState = STATE_WAITING;

                uint8_t d[16];
                MD5Final(d, &mMD5);
                printmd5(d);
                if ( memcmp(d, mMetadata.md5, 16) ) {
                    // Bad MD5
                    trace_printf("MD5 mismatch :( \n");
                    fail();
                }
                else {
                    // Good transfer
                    trace_printf("MD5 match :) \n");
                    writeCmd(ACK);


                    flushMetadata();
                    lockFlash();
                    NVIC_SystemReset();
                }
            }
            break;
    }
}