Hi David, Firstly the buff in writeDone was for someother purpose which I did not use. It could be ignored. (I would surely be in trouble later thinking why I wrote it. :-) )
With respect to EEPROMWrite.write - The first parameter is the offset or as the interface files quotes "@param line address of the line to be written". Finally with the stack being cleared, that is a perfect analysis. I changed the variable buff to static variable and of course now the stack doesnt get cleared. Though this is not my application I will use the same analysis for my application. I tried the global variable as well. That works perfectly too. Thanks a lot. Regards, Santosh. > Hi Santosh, > > I was reading your email earlier, and one thing came to mind at first: If > your code works on the mica2, then your code can't be broken. I'm also not > sure that TOSSIM supports EEPROM? Maybe someone else could fill in those > details for me? > > But... let's take a look at your code. I'll also be referring to a previous > email you sent today. > > I think the main issue you're running into is stack vs. heap allocation for > the "buff" variable, and how you're accessing it. You define uint8_t > buff[255] as a local variable to Timer1.fired(). Then, you call > EEPROMWrite.write(0, buff). This is a split-phase operation, so your > Timer1.fired() event returns SUCCESS before the write (probably) proceeds > and the buff[255] array gets cleared off the stack. Your memory is then > corrupted on EEPROM because whatever you told it to write no longer exists. > > Then, in the EEPROMWrite.writeDone() event, you define a pointer called > *buff, and don't initialize it - but then again, you don't use it either. > Just be careful with leaving it in there because you might get confused when > you look at the code a year from now. > > One more question I have: I'm not entirely familiar with the > EEPROMWrite.write interface - what is the first argument? Is that the > offset in EEPROM to write (and assume you're writing only one byte), or the > length of data to write (and assume you're writing at a constant offset each > time)? > > > To solve all these issues, put buff[256] in global memory (below). The *buf > pointer passed back as an argument in writeDone(..) should be equivalent of > the &buff address. writeDone() is just telling you what you passed in. > > After the writeDone() event, it's then safe to call Read if you want to. > > Hope that helps, > -David > > > uint8_t buff[255]; > > event result_t Timer1.fired() > { > memset(&buff, 11, sizeof(buff)); > if(call EEPROMWrite.write(0, &buff)) > dbg(DBG_USR1,"Write Successful %d\n",buff[0]); > return SUCCESS; > } > > event result_t EEPROMWrite.writeDone(uint8_t *buf) > { > if(call EEPROMWrite.endWrite() == FAIL) > dbg(DBG_USR1,"End Write Failed\n"); > > call Leds.yellowOn(); > dbg(DBG_USR1, "Write Done %d\n",buf[0]); > if(buf[0] == 11) > > call Leds.greenOn(); > else > call Leds.redOn(); > return SUCCESS; > } > > event result_t EEPROMWrite.endWriteDone(result_t success) > { > return SUCCESS; > } > > event result_t EEPROMRead.readDone(uint8_t *buf, result_t success) > { > > return SUCCESS; > } > > > > -----Original Message----- > From: SANTOSH KUMAR [mailto:[EMAIL PROTECTED] > Sent: Monday, March 26, 2007 2:50 PM > To: [EMAIL PROTECTED] > Subject: Question regardin EEPROM. > > Hi David, > > I hope you are doing great there. > > I am stuck with another memory/flash related issue. I am using the > EEPROMWrite > and EEPROMRead interface to write to the EEPROM. My code works on the mica2 > mote > and doesnt work on TOSSIM. This is what I have done in my program > > event result_t Timer1.fired() > { > uint8_t buff[255]; > memset((void*)buff,11,1); > if(call EEPROMWrite.write(0,buff)) > dbg(DBG_USR1,"Write Successful %d\n",buff[0]); > return SUCCESS; > } > > event result_t EEPROMWrite.writeDone(uint8_t *buf) > { > uint8_t *buff; > if(call EEPROMWrite.endWrite() == FAIL) > dbg(DBG_USR1,"End Write Failed\n"); > > call Leds.yellowOn(); > dbg(DBG_USR1, "Write Done %d\n",buf[0]); > if(buf[0] == 11) > > call Leds.greenOn(); > else > call Leds.redOn(); > return SUCCESS; > } > > event result_t EEPROMWrite.endWriteDone(result_t success) > { > return SUCCESS; > } > > event result_t EEPROMRead.readDone(uint8_t *buf, result_t success) > { > > return SUCCESS; > } > > The place where I compare the buf[0] value to 11 fails in the TOSSIM. > Basically > the correct value is not getting written. > > Can you help me on this as I need to test my code and I am running it on > tossim? > > Thanks in advance. > > Regards, > Santosh. > > > > _______________________________________________ Tinyos-help mailing list Tinyos-help@Millennium.Berkeley.EDU https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help