const char *getmfgstr(int speed, long *len){ //This will be turned off by another thread, //but when we call it often the light becomes visible. green_led(1); //Hook the USB DNLOAD handler. hookusb(); static long adr=0; long val; char *usbstring=(char*) 0x2001c080; //2.032 char buffer[]="@________ : ________"; //Read four bytes from SPI Flash. spiflash_read(&val,adr,4); //Print them into the manufacturer string. strhex(buffer+1, adr); strhex(buffer+12, val); //Look forward a bit. adr+=4; //Return the string as our value. return loadusbstr(usbstring,buffer,len); }
void get_tz_data(int timezone, struct pulse_time_tm *time, char *city_buffer) { char city_name[TIMEZONE_FIELD_WIDTH]; pulse_get_time_date(time); time_add_hours(time, timezone - LOCAL_TIMEZONE); spiflash_read(TIMEZONE_TABLE_OFFSET + ((timezone + 11) * TIMEZONE_FIELD_WIDTH), city_name, TIMEZONE_FIELD_WIDTH); sprintf(city_buffer, "%+d %s", timezone, city_name); }
/* Displays a startup demo on the device's screen, including some of the setting information and a picture or two. */ void demo(){ drawtext(L"MD380Tools ", 160,20); drawtext(L"by KK4VCZ ", 160,60); drawtext(L"and Friends", 160,100); sleep(1000); //Make the welcome image scroll across the screen. for(int i=0;i<0x60;i+=3){ gfx_drawbmp(welcomebmp,0,i); sleep(30); } //Restore the bottom line of text before we return. spiflash_read(botlinetext, 0x2054, 20); }
/* All user database data is accessed through this function. * This makes it easier to adapt to different kinds of sources. */ static char * getdata(char * dest, const char * src, int count) { spiflash_read(dest, (long) src, count); return dest; }
/***************************************************************************//** * @brief * Serial Output Demo, Prints out Data Wrote and Read back from Device * ******************************************************************************/ void demo_serial(void) { int i; int hex_dump_size = 256; CMU_ClockEnable(cmuClock_CORELE, true); CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO); CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO); serial_init(9600, raw_serial_rx_buf, sizeof(raw_serial_rx_buf), raw_serial_tx_buf, sizeof(raw_serial_tx_buf)); printf("\r\nEmbedded Masters SPI Flash Demo\r\n"); if (! spiflash_init(2000000)) { printf("SPI flash failed to initialize\r\n"); while(true) ; } get_status(); printf("reading\r\n"); spiflash_read(0x00000, sizeof(buf1), buf1, NULL, NULL); printf("read done\r\n"); serial_tx_flush(); printf("data read"); if (hex_dump_size != sizeof(buf1)) printf(", first %d bytes", hex_dump_size); printf (":\r\n"); hex_dump(buf1, hex_dump_size, 0); serial_tx_flush(); printf("erasing\r\n"); spiflash_erase(0x00000, sizeof(buf1), 0, true, NULL, NULL); printf("erase done\r\n"); serial_tx_flush(); get_status(); printf("setting buffer to increment from %02x\r\n", buf1[0]+1); buf2[0]++; for (i = 1; i < sizeof(buf2); i++) buf2[i] = buf2[i-1] + 1; serial_tx_flush(); write_enable(); printf("setting sector unprotect\r\n"); spiflash_set_sector_protection(false, 0x00000, NULL, NULL); get_status(); printf("writing\r\n"); serial_tx_flush(); spiflash_write(0x00000, sizeof(buf2), buf2, true, NULL, NULL); printf("write done\r\n"); serial_tx_flush(); get_status(); printf("reading\r\n"); serial_tx_flush(); spiflash_read(0x00000, sizeof(buf3), buf3, NULL, NULL); printf("read done\r\n"); serial_tx_flush(); printf("data read"); if (hex_dump_size != sizeof(buf1)) printf(", first %d bytes", hex_dump_size); printf (":\r\n"); serial_tx_flush(); hex_dump(buf3, hex_dump_size, 0); spiflash_ultra_deep_power_down(true, NULL, NULL); serial_tx_flush(); serial_close(); }