Ejemplo n.º 1
0
void putValue(void* aAdr, uint8_t aPType, int32_t* aValue)
{
    union {
        void*     adr; 
        uint8_t*  u8Adr;
        uint16_t* u16Adr;
        //        uint32_t* u32Adr;
    } a;

    a.adr = aAdr;
    if (ISEEADR(aPType))
    {
        if (IS8BIT(aPType))
            eeprom_update_byte(aAdr, ISSIGNED(aPType) ? (int8_t) *aValue : (uint8_t) *aValue);
        else if(IS16BIT(aPType))
            eeprom_update_word(aAdr, ISSIGNED(aPType) ? (int16_t) *aValue : (uint16_t) *aValue);
#ifdef WITH_EE32VALUES
        else if(IS32BIT(aPType))
            eeprom_update_dword(aAdr, ISSIGNED(aPType) ? *aValue : (uint32_t) *aValue);
#endif
    } else if (ISRAMADR(aPType))
    {
        if (IS8BIT(aPType))
            *a.u8Adr = ISSIGNED(aPType) ? (int8_t) *aValue : (uint8_t) *aValue;
        else if(IS16BIT(aPType))
            *a.u16Adr = ISSIGNED(aPType) ? (int16_t) *aValue : (uint32_t) *aValue;
#ifdef WITH_EE32VALUES
        else if(IS32BIT(aPType))
            *a.u32Adr = ISSIGNED(aPType) ?  *aValue : (uint32_t) *aValue;
#endif
    }
    feedback(1, BLINK_MEDIUM, WITH_LED1);
} // getValue
Ejemplo n.º 2
0
void ecb_encrypt(ecb_state_t *state, aes_ctx_t *ctx, uint8_t *output) {
  state->message_id++;
  if (state->message_id % MESSAGE_ID_UPDATE_INTERVAL == 0) {
    eeprom_update_dword(get_msg_id_addr(state->device_id), state->message_id);
  }
  state->checksum = calc_checksum16((uint8_t*)state, sizeof(ecb_state_t)-sizeof(uint16_t));

  memcpy(output, state, AES_BUF_LEN);
  // encrypt the data
  aes128_enc(output, ctx);
}
Ejemplo n.º 3
0
bool StoreEEPROM()
{
	wdt_reset();
	DEBUG("Storing settings\n");

	if (!storage_selftest())
	{
		DEBUG("Error: Storage not available\n");
		return false;
	}

	FIL * ee_file;
	ee_file = new FIL;

	if (f_open(ee_file, "CFG.EE", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
	{
		DEBUG("Unable to create file\n");
		delete ee_file;

		return false;
	}
	uint16_t wd = 0;

	eeprom_busy_wait();
	eeprom_update_dword(&config_ee.build_number, BUILD_NUMBER);

	uint16_t i = 0;
	do
	{
		uint8_t buf[256];
		uint16_t rwd;

		if (i + sizeof(buf) < sizeof(cfg_t))
			wd = sizeof(buf);
		else
			wd = sizeof(cfg_t) - i;


		eeprom_busy_wait();
		eeprom_read_block(buf, (uint8_t *)(APP_INFO_EE_offset + i), wd);


		assert(f_write(ee_file, buf, wd, &rwd) == FR_OK);

		i += wd;
	} while (i < sizeof(cfg_t));

	f_close(ee_file);
	DEBUG("File closed\n");

	delete ee_file;
	return true;
}
Ejemplo n.º 4
0
bool StoreEEPROM()
{
	wdt_reset();
	DEBUG("Storing settings\n");

	FIL * ee_file;
	ee_file = new FIL;

	if (f_open(ee_file, "CFG.EE", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
	{
		DEBUG("Unable to create file\n");
		return false;
		delete ee_file;
	}
	uint16_t wd = 0;

	eeprom_busy_wait();
	eeprom_update_dword(&config.build_number, BUILD_NUMBER);

	uint16_t res;

	uint16_t i = 0;
	do
	{
		uint8_t buf[256];
		uint16_t rwd;

		if (i + sizeof(buf) < sizeof(config))
			wd = sizeof(buf);
		else
			wd = sizeof(config) - i;

		DEBUG(" >> i %d s %d rwd %d\n", i, wd, rwd);

		eeprom_busy_wait();
		eeprom_read_block(buf, (uint8_t *)(APP_INFO_EE_offset + i), wd);

		DEBUG(" << \n");

		res = f_write(ee_file, buf, wd, &rwd);

		i += wd;
		DEBUG("i %d s %d rwd %d\n", i, wd, rwd);
	} while (i < sizeof(config));

	f_close(ee_file);
	DEBUG("File closed\n");

	delete ee_file;
	return true;
}
Ejemplo n.º 5
0
void reset_saved_tick_count(void)
{
    uint32_t dispensing;

    // Don't reset the tick count while we're counting!
    cli();
    dispensing = g_is_dispensing;
    sei();
    if (dispensing)
        return;

    cli();
    g_ticks = 0;
    sei();

    eeprom_update_dword((uint32_t *)ee_run_time_ticks_offset, 0);
}
Ejemplo n.º 6
0
void eeconfig_init(void)
{
    eeprom_update_word(EECONFIG_MAGIC,          EECONFIG_MAGIC_NUMBER);
    eeprom_update_byte(EECONFIG_DEBUG,          0);
    eeprom_update_byte(EECONFIG_DEFAULT_LAYER,  0);
    eeprom_update_byte(EECONFIG_KEYMAP,         0);
    eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
#ifdef BACKLIGHT_ENABLE
    eeprom_update_byte(EECONFIG_BACKLIGHT,      0);
#endif
#ifdef AUDIO_ENABLE
    eeprom_update_byte(EECONFIG_AUDIO,             0xFF); // On by default
#endif
#ifdef RGBLIGHT_ENABLE
    eeprom_update_dword(EECONFIG_RGBLIGHT,      0);
#endif
}
Ejemplo n.º 7
0
/** \brief function for incrementing the value of msgAuthoritativeEngineBoots, called at startup */
u8t incMsgAuthoritativeEngineBoots()
{
	/*Increments the Value of MsgAuthoritativeEngineBoots when booting.*/
	/*Checks if the maximum value of 2147483647 (RFC3414) is reached.*/
	if((eeprom_read_dword(&MsgAuthoritativeEngineBoots))<2147483647)
	{
		eeprom_update_dword(&MsgAuthoritativeEngineBoots, (eeprom_read_dword(&MsgAuthoritativeEngineBoots)+1));
	}
	else
	{
#if PDEBUG
		printf("Maximum Number of MsgAuthoritativeEngineBoots reached, please reconfigure all secret values and reinstall SNMP Agent\n");
#endif
	}
#if PDEBUG
	printf("MsgAuthoritativeEngineBoots = %lu\n",eeprom_read_dword(&MsgAuthoritativeEngineBoots));
#endif

	return 0;
}
Ejemplo n.º 8
0
void flush_saved_tick_count(uint8_t force)
{
    uint8_t is_dispensing;
    uint32_t ticks_to_save;

    cli();
    is_dispensing = g_is_dispensing;
    ticks_to_save = g_ticks;
    sei();

    if (is_dispensing && !force)
        return;

    if (ticks_to_save > TICKS_SAVE_THRESHOLD || (force && ticks_to_save > 0))
    {
        cli();
        g_ticks = 0;
        sei();

        ticks_to_save += eeprom_read_dword((uint32_t *)ee_run_time_ticks_offset);
        eeprom_update_dword((uint32_t *)ee_run_time_ticks_offset, ticks_to_save);
    }
}
Ejemplo n.º 9
0
int main()
{
    // Disable, configure, and start the watchdog timer
    wdt_disable();
    wdt_reset();
    wdt_enable(WDTO_8S);

    // Start and configure all hardware peripherals
    sei();
    led_init();
    radio_init();
    gps_init();
    radio_enable();

    // Set the radio shift and baud rate
    _radio_dac_write(RADIO_COARSE, RADIO_CENTER_FREQ);
    _radio_dac_write(RADIO_FINE, 0);
    radio_set_shift(RADIO_SHIFT_425);
    radio_set_baud(RADIO_BAUD_50);

    // Radio chatter
    for(uint8_t i = 0; i < 5; i++)
    {
        radio_chatter();
        wdt_reset();
    }
    
    int32_t lat = 0, lon = 0, alt = 0;
    uint8_t hour = 0, minute = 0, second = 0, lock = 0, sats = 0;

    while(true)
    {
        led_set(LED_GREEN, 1);

        // Get the current system tick and increment
        uint32_t tick = eeprom_read_dword(&ticks) + 1;

        // Check that we're in airborne <1g mode
        if( gps_check_nav() != 0x06 ) led_set(LED_RED, 1);

        // Get information from the GPS
        gps_check_lock(&lock, &sats);
        if( lock == 0x02 || lock == 0x03 || lock == 0x04 )
        {
            gps_get_position(&lat, &lon, &alt);
            gps_get_time(&hour, &minute, &second);
        }

        led_set(LED_GREEN, 0);

        // Format the telemetry string & transmit
        double lat_fmt = (double)lat / 10000000.0;
        double lon_fmt = (double)lon / 10000000.0;
        alt /= 1000;

        sprintf(s, "$$" CALLSIGN ",%lu,%02u:%02u:%02u,%02.7f,%03.7f,%ld,%u,%x",
            tick, hour, minute, second, lat_fmt, lon_fmt, alt,
            sats, lock);
        radio_chatter();
        radio_transmit_sentence(s);
        radio_chatter();

        led_set(LED_RED, 0);
        eeprom_update_dword(&ticks, tick);
        wdt_reset();
        _delay_ms(500);
    }

    return 0;
}
Ejemplo n.º 10
0
void eeconfig_update_rgblight(uint32_t val) {
  #ifdef __AVR__
    eeprom_update_dword(EECONFIG_RGBLIGHT, val);
  #endif
}
Ejemplo n.º 11
0
void eeconfig_update_rgb_matrix(uint32_t val) {
  eeprom_update_dword(EECONFIG_RGB_MATRIX, val);
}
Ejemplo n.º 12
0
void eeconfig_update_rgblight(uint32_t val) {
  eeprom_update_dword(EECONFIG_RGBLIGHT, val);
}
Ejemplo n.º 13
0
int main ()
{
    void *p;

    /* Fill all EEPROM.	*/
    for (p = 0; p <= (void *)E2END; p++)
	eeprom_write_byte (p, (int)(p + 1));
    
    /* Update a byte.	*/
    {
	unsigned char *p = (unsigned char *)1;
	
	eeprom_update_byte (p, 2);	/* the same value	*/
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_byte (p) != 2) exit (__LINE__);

	eeprom_update_byte (p, 0x12);	/* different value	*/
	if (eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_byte (p) != 0x12) exit (__LINE__);
    }

    /* Update a word.	*/
    {
	unsigned int *p = (unsigned int *)2;

	eeprom_update_word (p, 0x0403);		/* the same value	*/
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_word (p) != 0x0403) exit (__LINE__);

	eeprom_update_word (p, 0x0413);
	if (eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_word (p) != 0x0413) exit (__LINE__);

	eeprom_update_word (p, 0x1413);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_word (p) != 0x1413) exit (__LINE__);
    }

    /* Update a double word.	*/
    {
	unsigned long *p = (unsigned long *)4;

	eeprom_update_dword (p, 0x08070605);	/* the same value	*/
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08070605) exit (__LINE__);

	eeprom_update_dword (p, 0x08070615);
	if (eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08070615) exit (__LINE__);

	eeprom_update_dword (p, 0x08071615);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08071615) exit (__LINE__);

	eeprom_update_dword (p, 0x08171615);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08171615) exit (__LINE__);

	eeprom_update_dword (p, 0x18171615);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x18171615) exit (__LINE__);
    }

    /* Update a block.	*/
    {
	unsigned char *p = (unsigned char *)8;
	unsigned char s[5];
	
	memcpy_P (s, PSTR ("\x09\x0A\x0B\x0C\x0D"), 5);
	eeprom_update_block (s, p, 5);
	if (!eeprom_is_ready ()) exit (__LINE__);
	memset (s, 0, sizeof (s));
	eeprom_read_block (s, p, 5);
	if (memcmp_P (s, PSTR ("\x09\x0A\x0B\x0C\x0D"), 5)) exit (__LINE__);

	memcpy_P (s, PSTR ("\x19\x0A\x0B\x0C\x0D"), 5);
	eeprom_update_block (s, p, 5);
	if (eeprom_is_ready ()) exit (__LINE__);
	memset (s, 0, sizeof (s));
	eeprom_read_block (s, p, 5);
	if (memcmp_P (s, PSTR ("\x19\x0A\x0B\x0C\x0D"), 5)) exit (__LINE__);

	memcpy_P (s, PSTR ("\x19\x0A\x0B\x0C\x1D"), 5);
	eeprom_update_block (s, p, 5);
	if (!eeprom_is_ready ()) exit (__LINE__);
	memset (s, 0, sizeof (s));
	eeprom_read_block (s, p, 5);
	if (memcmp_P (s, PSTR ("\x19\x0A\x0B\x0C\x1D"), 5)) exit (__LINE__);
	
	memcpy_P (s, PSTR ("\x1A\x1B\x1C"), 3);
	eeprom_update_block (s, p + 1, 1);
	eeprom_update_block (s + 1, p + 2, 2);
    }

    /* Check all EEPROM.	*/
    for (p = 0; p <= (void *)E2END; p++) {
	unsigned char c;
	c = (int)p + ((p && (p < (void *)13)) ? 0x11 : 1);
	if (eeprom_read_byte (p) != c)
	    exit (__LINE__);
    }

    return 0;
}
Ejemplo n.º 14
0
/**
 @brief	Analyse HTTP request and then services WEB.
*/
void process_HTTP(
	SOCKET s, 			/**< http server socket */
	uint8_t * buffer, 	/**< buffer pointer included http request */
	uint16_t length		/**< length of http request */
	)
{
	uint8_t * name;
	uint16_t bytes_read;
	TickType_t wait_send;
	FIL source_file;	/* File object for the source file */

	parse_HTTP_request(pHTTPRequest, buffer);			// After analysing request, convert into pHTTPRequest

	/* method Analyse */
	switch (pHTTPRequest->METHOD)
	{
		case METHOD_HEAD:
		case METHOD_GET :
		case METHOD_POST :

			name = get_HTTP_URI_name(pHTTPRequest->URI);

			if (!strcmp((const char *)name, "/")) strcpy((char *)name,"index.htm");	// If URI is "/", respond by index.htm

#ifdef WEB_DEBUG
			if(strlen( (const char *)name) < MAX_INT_STR ) xSerialPrintf_P(PSTR("\r\nPAGE : %s "), name);
			else xSerialPrint_P(PSTR("\r\nFILENAME TOO LONG"));
#endif

			find_HTTP_URI_type(&pHTTPRequest->TYPE, name);	//Check file type (HTML, TEXT, ICO, GIF, JPEG, ZIP are included)

			// OK now we start to respond to the info we've decoded.

			/* Open the specified file stored in the SD card FAT32 */
			if (f_open(&source_file, (const TCHAR *)name, FA_OPEN_EXISTING | FA_READ))
			{	// if file open failure

				memcpy_P( (char *)pHTTPResponse, ERROR_HTML_PAGE, strnlen_P(ERROR_HTML_PAGE, FILE_BUFFER_SIZE) );

#ifdef WEB_DEBUG
				xSerialPrint_P(PSTR("HTTP Unknown file or page.\r\n"));
				xSerialPrintf_P(PSTR("HTTP Response...\r\n%s\r\nResponse Size: %u \r\n"), pHTTPResponse, strlen_P(ERROR_HTML_PAGE));
#endif

				send( s, (const uint8_t*)pHTTPResponse, strlen_P(ERROR_HTML_PAGE));

			}
			else
			{	// if file open success

				make_HTTP_response_header( pHTTPResponse, pHTTPRequest->TYPE, source_file.fsize);

#ifdef WEB_DEBUG
				xSerialPrintf_P(PSTR("HTTP Opened file: %s  Source Size: %u \r\n"), name, source_file.fsize);
				xSerialPrintf_P(PSTR("HTTP Response Header...\r\n%s\r\nResponse Header Size: %u \r\n"), pHTTPResponse, strlen((char*)pHTTPResponse ));
#endif

				send(s, (const uint8_t*)pHTTPResponse, strlen((char*)pHTTPResponse ));

				wait_send = xTaskGetTickCount();

				while(getSn_TX_FSR(s)!= WIZCHIP_getTxMAX(s))

				{
					if( (xTaskGetTickCount() - wait_send) > (WEBSERVER_SOCKET_TIMEOUT / portTICK_PERIOD_MS) ) // wait up to 1.5 Sec
					{
#ifdef WEB_DEBUG
						xSerialPrint_P(PSTR("HTTP Response head send fail\r\n"));
#endif
						break;
					}
					vTaskDelay( 0 ); // yield until next tick.
				}

				for (;;)
				{
					if ( f_read(&source_file, pHTTPResponse, (sizeof(uint8_t)*(FILE_BUFFER_SIZE) ), &bytes_read) || bytes_read == 0 )
						break;   // read error or reached end of file

					if(pHTTPRequest->TYPE == PTYPE_HTML) // if we've got a html document, there might be some system variables to set
					{
						*(pHTTPResponse + bytes_read + 1) = 0; // make the buffer a string, null terminated
						bytes_read = replace_sys_env_value(pHTTPResponse, bytes_read); // Replace html system environment value to real value
					}

					if (send(s, (const uint8_t*)pHTTPResponse, bytes_read) != bytes_read)
						break;  // TCP/IP send error

					wait_send = xTaskGetTickCount();

					while(getSn_TX_FSR(s)!= WIZCHIP_getTxMAX(s))

					{
						if( (xTaskGetTickCount() - wait_send) > (WEBSERVER_SOCKET_TIMEOUT / portTICK_PERIOD_MS) ) // wait up to 1.5 Sec
						{
#ifdef WEB_DEBUG
							xSerialPrint_P(PSTR("HTTP Response body send fail\r\n"));
#endif
							break;
						}
						vTaskDelay( 0 ); // yield until next tick.
					}
				}
				f_close(&source_file);

				eeprom_busy_wait();
				eeprom_update_dword( &pagesServed, eeprom_read_dword(&pagesServed) +1 );
			}
			break;

		case METHOD_ERR :

			memcpy_P( (char *)pHTTPResponse, ERROR_REQUEST_PAGE, strnlen_P(ERROR_REQUEST_PAGE, FILE_BUFFER_SIZE) );

#ifdef WEB_DEBUG
			xSerialPrint_P(PSTR("HTTP Method Error.\r\n"));
			xSerialPrintf_P(PSTR("HTTP Response...\r\n%s\r\nResponse Size: %u \r\n"), pHTTPResponse, strlen_P(ERROR_REQUEST_PAGE));
#endif

			send( s, (const uint8_t*)pHTTPResponse, strlen_P(ERROR_REQUEST_PAGE));

			break;

		default :
			break;
	}
}
Ejemplo n.º 15
0
void eeconfig_update_rgblight(uint32_t val) {
  #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
    rgblight_check_config();
    eeprom_update_dword(EECONFIG_RGBLIGHT, val);
  #endif
}