Point to Next Address

This is a discussion on Point to Next Address within the C Programming forums, part of the General Programming Boards category; Code: #define SRAM_ENDERECO_INICIAL 0xE0084000lu // Enderešo Inicial da SRAM typedef struct stRede { unsigned int iIP[4]; unsigned int iMascara[4]; unsigned ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    158

    Point to Next Address

    Code:
    #define SRAM_ENDERECO_INICIAL	0xE0084000lu		// Enderešo Inicial da SRAM
    
    typedef struct stRede
    {
    	unsigned int iIP[4];
    	unsigned int iMascara[4];
    	unsigned int iGateway[4];
    	unsigned int iDns[4];
    	unsigned int iPorta;
    	unsigned char MacAddress[6];
    } SYSCONFIG_REDE;
    
    typedef struct stSerial
    {
    	unsigned int iSerialID[4];
    	long lBaudRate[4];
    	unsigned int iDataBits[4];
    	unsigned int iStopBits[4];
    	unsigned int iParity[4];
    } SYSCONFIG_SERIAL;
    
    typedef struct stDiversos
    {
    	unsigned int iContrasteDisplay;
    	long iSenhaOperador;
    	long iSenhaServico;
    	long iSenhaManutencao;
    	unsigned int iIdioma;
    } SYSCONFIG_DIVERSOS;
    
    typedef struct stPesagem
    {
    	unsigned int iModeloPlaca;
    	unsigned int iFilterMode;
    	unsigned int iFiltroASF;
    	unsigned int iVelocidadeICR;
    	unsigned int iResolucaoRSN;
    	unsigned int iZeraAutomatico;
    	unsigned int iUtilizaTrigger;
    	long lPesoCalibracao;
    	long lPesoMaximo ;
    	unsigned char cUnidadeMedida[3];
    } SYSCONFIG_PESAGEM;
    
    SYSCONFIG_REDE *CONFIG_REDE;
    SYSCONFIG_SERIAL *CONFIG_SERIAL;
    SYSCONFIG_DIVERSOS *CONFIG_DIVERSOS;
    SYSCONFIG_PESAGEM *CONFIG_PESAGEM;
    
    // HERE CALCULATE ADDRESS
    
    CONFIG_REDE = (SYSCONFIG_REDE *) SRAM_ENDERECO_INICIAL;
    	//
    	CONFIG_SERIAL = (SYSCONFIG_SERIAL *) (SRAM_ENDERECO_INICIAL + sizeof(CONFIG_REDE));
    	//
    	CONFIG_DIVERSOS = (SYSCONFIG_DIVERSOS *) (SRAM_ENDERECO_INICIAL + sizeof(CONFIG_SERIAL));
    	//
    	CONFIG_PESAGEM = (SYSCONFIG_PESAGEM *) (SRAM_ENDERECO_INICIAL + sizeof(CONFIG_DIVERSOS));
    My program write data to fixed memory positions..
    I need point each variable to a point, whats the correct way to calc the next addres

    Another question, how to show the address of variable in printf ?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ummmm.... in modern systems you generally DO NOT want to write to fixed addresses... ever.
    Fixed addresses are not fixed... memory is allocated and deallocated to programs dynamically and has to be correctly reserved. Memory that is not correctly reserved (with malloc(), calloc() or realloc() ) is very likely to be overwritten at any moment and you have no control over that.

    Well... unless you're writing for a 6502 running ROM Basic that is... (circa 1974)


    It looks like you are trying to build a data base in memory... you would do that with malloc() and access it with pointers. A linked list is probably your best bet... Linked Lists

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    #define SRAM_ENDERECO_INICIAL	0xE0084000lu		// Enderešo Inicial da SRAM
    Care to elaborate what one would get from here??
    Is it a port or ..?
    You can use printf %p format specifier.
    Correct (standard) way is
    printf(" pointer pointing %p\n", (void*)p );

    You should take note that sizeof(struct) >= sizeof(field1) + sizeof(field2)+...
    Since there may be padding between struct fields.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    158
    this address refer to SRAM in a LPC2468 processor (ARM 7).

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,512
    There's no magic way to have it all just fit in there. I would probably do something like:
    Code:
    CONFIG_REDE = (SYSCONFIG_REDE *) SRAM_ENDERECO_INICIAL;
    CONFIG_REDE_SIZE = sizeof(SYSCONFIG_REDE);
    
    CONFIG_SERIAL = (SYSCONFIG_SERIAL *) (CONFIG_REDE + CONFIG_REDE_SIZE);
    CONFIG_SERIAL_SIZE = sizeof(SYSCONFIG_SERIAL);
    ...

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    158
    Thanks for all

    Final Code:

    Code:
    CONFIG_REDE = (SYSCONFIG_REDE *) SRAM_ENDERECO_INICIAL;
    
    CONFIG_SERIAL = (SYSCONFIG_SERIAL *) (SRAM_ENDERECO_INICIAL + sizeof(CONFIG_REDE));
    
    CONFIG_DIVERSOS = (SYSCONFIG_DIVERSOS *) (SRAM_ENDERECO_INICIAL + sizeof(CONFIG_REDE) + sizeof(CONFIG_SERIAL));
    
    CONFIG_PESAGEM = (SYSCONFIG_PESAGEM *) (SRAM_ENDERECO_INICIAL + + sizeof(CONFIG_REDE) + sizeof(CONFIG_SERIAL) + sizeof(CONFIG_DIVERSOS));

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,512
    Your sizeof is incorrect. CONFIG_REDE, CONFIG_SERIAL, et al. are pointers. Their sizes are all 4 on your 32-bit ARM proc. I really don't recommend basing all of the CONFIG addresses off of SRAM_ENDERECO_INICIAL. Apart from the long, ugly list of sizeof's you will end up with, you will have problems if you want to insert a new CONFIG_ somewhere in the middle of your SRAM. Make the next one be based off of the previous CONFIG_ block only. You don't have to use the CONFIG_XXX_SIZE variables like I did, but at least do:
    Code:
    CONFIG_REDE = (SYSCONFIG_REDE *) CONFIG_ENDERCO_INICIAL;
    CONFIG_SERIAL = (SYSCONFIG_SERIAL *) (CONFIG_REDE + sizeof(SYSCONFIG_REDE));
    CONFIG_DIVERSOS = (SYSCONFIG_DIVERSOS *) (CONFIG_SERIAL + sizeof(SYSCONFIG_SERIAL));
    CONFIG_PESAGEM = (SYSCONFIG_PESAGEM *) (CONFIG_DIVERSOS + sizeof(SYSCONFIG_DIVERSOS));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock problem
    By Wolf` in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2010, 04:55 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  3. trouble with overloaded operator
    By kkurz in forum C++ Programming
    Replies: 2
    Last Post: 10-31-2003, 11:59 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21