Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Writing s-record file to an emulated eeprom

Status
Not open for further replies.

minis

Newbie level 4
Newbie level 4
Joined
Jul 24, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
Hi everone!

I have a .c file which I'd like to write into the emulated eeprom in Freescale MC9S12P128 microcontroller from computer using SCI (bluetooth module). I should be able read and wirte this data during running program on uC. I emulate eeprom using Data-Flash which is dedicated to such appilactions. And I figured out that maybe I should receive .19 file from .c file and then write into eeprom as normal data set. And now I have two questions. Is this thinking proper and if it is, what should I write into eeprom - whole s-record file or just a data sequence without any records, descriptions, addresses, etc?
Or maybe there are other ways to write .c file (with defines and structures within) into eeprom.

Please excuse me English, it's been a long time since I've used this language.

Best regards,
Minis
 

Are you trying to store the compiled executable (binary) in Flash?
Or a text representation (.s19 file)?
Or the original source files (.c, .h, with defines, structures as you say).

.c, .h files --> Compiler --> assembler file .asm --> Assembler --> obj file --> linker --> .s19 record file --> programmer --> executable bytes to the microcontroller
 

I see I didn't explain clearly. I've already programmed Flash with my program. But there is small part (one file with few structures) that I'd like to produce later on PC and then write them to the emulated eeprom while original program is still running. And main program is supposed to use this new structures. Is that a little bit more undestandable? :)

Best regards,
Minis
 

Not really. By structure do you mean data (such as a data-set) that you'd like the running program to be able to use?
Or by structure do you mean new software functions that you'd like the running program to be able to execute?
 

Not really. By structure do you mean data (such as a data-set) that you'd like the running program to be able to use?
Or by structure do you mean new software functions that you'd like the running program to be able to execute?

Data! This is example of file_to_add.c content:

Code:
#define RULES_N     5 

const t_base_param BaseParam =
     {
       USE_WEIGHTS,   /* UseWeights */
       USE_NOTS,      /* UseNots    */
       IN_VAR_N,      /* InVarN     */
       IN_TERMS_N,    /* InTermsN   */
       IN_VAR_O,      /* InVarOff   */
       INPUTS_O,      /* InputsOff  */
       OUT_VAR_N,     /* OutVarN    */
       OUT_TERMS_N,   /* OutTermsN  */
       OUT_VAR_O,     /* OutVarOff  */
       OUTPUTS_O,     /* OutputsOff */
       RULES_N,       /* RulesN     */
       WEIGHTS_O,     /* WeightsOff */
       RULES_O        /* RulesOff   */
      };

const t_var_info InpVar[IN_VAR_N] = 
      {
        {    5,     0,     1 },    /* acc          */
        {    4,     0,     1 },    /* rot          */
        {    4,     0,     1 },    /* press        */
        {    4,     0,     1 },    /* touch        */
        {    4,     0,     1 },    /* iacc         */
        {    4,     0,     1 },    /* irot         */
        {    4,     0,     1 },    /* ipress       */
        {    4,     0,     1 },    /* itouch       */
        {    5,    -1,     1 },    /* dacc         */
        {    5,    -1,     1 },    /* drot         */
        {    5,    -1,     1 },    /* dpress       */
        {    5,    -1,     1 }     /* dtouch       */
      };


const t_term_info InVar1 [4] = {
         {   0,  13,   0,  26 },    /* zero         */
         {   3,  31,  26,  51 },    /* small        */
         {  26,  64,  51,  20 },    /* medium       */
         {  51, 255,  20,   0 }     /* large        */
      };

#if USE_WEIGHTS

const unsigned char Weights[RULES_N] = {
      255, 
      255, 
      255, 
      255, 
      255
    };

    };

#else /* USE_WEIGHTS */

const unsigned char Rules[] = {
            /* IF */ 
      0x0A, /* iacc IS zero */ 
      0x24, /* irot IS zero */ 
      0x3E, /* ipress IS zero */ 
      0x58, /* itouch IS zero */ 
      0xFE, /* THEN */ 
      0x75, /* dvol IS n_small */ 
      0x79, /* mvol IS limit */ 
      0x8A, /* mton IS limit */ 
      0x86, /* dton IS n_small */ 
      0xFE, 
            /* IF */ 
      0x27, /* irot IS NOT small */ 
      0xFE, /* THEN */ 
      0x8D, /* hue IS yellow */ 
      0xBC, /* dval IS small */ 
      0x87, /* dton IS small */ 
      0xFE, 
            /* IF */ 
      0x3A, /* press IS medium */ 
      0xFE, /* THEN */ 
      0xA1, /* sat IS large */ 
      0xFE, 
            /* IF */ 
      0x3B, /* press IS NOT medium */ 
      0xFE, /* THEN */ 
      0xBC, /* dval IS small */ 
      0xBE, /* mval IS toggle */ 
      0xFE, 
            /* IF */ 
      0x08, /* acc IS any */ 
      0xFE, /* THEN */ 
      0xBE, /* mval IS toggle */ 
      0xAE, /* msat IS limit */ 
      0x9E, /* mhue IS cycle */ 
      0x8B, /* mton IS cycle */ 
      0x78, /* mvol IS toggle */ 
      0xFF  /* End Of Rules */
    };

#endif /* USE_WEIGHTS */

And I'd like to write this into the eeprom while the main program is running and use those tables after that.

Best regards,
Minis
 

That was a very long and complicated way to describe your requirement!
Writing a .s19 file is not a good way. It doesn't have many redeeming features for this application (data).
There are many other methods, ranging from super-complex (ASN) to complex (XML) to simple (CSV) to simpler
raw byte sequence. And maybe a 100 methods in-between those. It is up to you what format you want to send
the data bearing in mind that the easiest is a simple raw binary sequence.
After you're done processing/decoding (from say XML) then you can store it as a raw binary set of data.

When you want to use the data, you can just set a pointer to the memory location where you've
stored the bytes. The pointer can be a pointer to a 'typedef struct' for instance.
Here is an example that does exactly that. Pretend that buf is a pointer to the location in EEPROM or
FLASH or whatever (it doesn't matter) where the data is stored.
Code:
#include <stdio.h>

unsigned char buf[]={0xfc, 0xfd, 0xfe, 0xff};

typedef struct bob_s{
	unsigned char aparam;
	signed char bparam;
} bob;

int
main(void)
{
	bob* myptr;
	
	myptr=(bob*)buf;
	
	printf("aparam=%d, bparam=%d\n", myptr->aparam, myptr->bparam);
	
	myptr++;
	
	printf("aparam=%d, bparam=%d\n", myptr->aparam, myptr->bparam);
	

	return(0);
}
 
  • Like
Reactions: minis

    minis

    Points: 2
    Helpful Answer Positive Rating
Sorry for such complications. I couldn't express what I meant :)

I think I'll choose a raw byte format but I have another question... How from .c and .h files one can receive file with byte record adequate to source file? Maybe it is a stupid question but I don't get it.

Best regards,
Minis
 

It's quite easy to do it manually if you are using simple types, e.g. char, int.
If I was using XML I would have used an XML encoder/decoder.

The code example that I pasted was done manually, because I knew an unsigned char will take up exactly one byte, and
the same with signed char.
You could write a simple script or C program to automate it for you, for example to read the data-set from an Excel CSV
file and convert to a byte stream.
For the example I pasted, you can see it was a simple (trivial) exercise for my very simple typedef struct.
 
  • Like
Reactions: minis

    minis

    Points: 2
    Helpful Answer Positive Rating
Thank you for our help! I think I understand this issue. If don't know something I'll write here once again :)
Thanks!

Best regards,
Minis

- - - Updated - - -

I found software that converts file to c-style array representation. It seems that it works. But I was suprised by one thing - produced file weight over 70 KB while .s19 received from the same c-file - only 2KB. And after all they both have the same data within. I've got only 4KB of memory. Did I miss something?

Best regards,
Minis
 

Could you, please, explain it to me? I'd be grateful.

Best regards,
Minis
 

You could open the generate file using Notepad, to see what it did.

C code (i.e. a .c file) is of course larger than an .s19 file, since C code
is uncompiled. C code may have auto-generated comments, formatting and all sorts of stuff.

Anyway, you're not going to be transmitting a C file, you're going to be transmitting a bytestream
of the dataset in the same format as it will be stored in memory (which is clearly not an uncompiled
C file).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top