256B for a SPI instance!!!???

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just saw that a SPI definition from spi_192.h that would take 256B out of memory:

typedef struct avr32_spi_t {
  union {
          unsigned long                  cr        ;//0x0000
          avr32_spi_cr_t                 CR        ;
  };
  union {
          unsigned long                  mr        ;//0x0004
          avr32_spi_mr_t                 MR        ;
  };
  union {
    const unsigned long                  rdr       ;//0x0008
    const avr32_spi_rdr_t                RDR       ;
  };
  union {
          unsigned long                  tdr       ;//0x000c
          avr32_spi_tdr_t                TDR       ;
  };
  union {
    const unsigned long                  sr        ;//0x0010
    const avr32_spi_sr_t                 SR        ;
  };
  union {
          unsigned long                  ier       ;//0x0014
          avr32_spi_ier_t                IER       ;
  };
  union {
          unsigned long                  idr       ;//0x0018
          avr32_spi_idr_t                IDR       ;
  };
  union {
    const unsigned long                  imr       ;//0x001c
    const avr32_spi_imr_t                IMR       ;
  };
          unsigned int                   :32       ;//0x0020
          unsigned int                   :32       ;//0x0024
          unsigned int                   :32       ;//0x0028
          unsigned int                   :32       ;//0x002c
  union {
          unsigned long                  csr0      ;//0x0030
          avr32_spi_csr0_t               CSR0      ;
  };
  union {
          unsigned long                  csr1      ;//0x0034
          avr32_spi_csr1_t               CSR1      ;
  };
  union {
          unsigned long                  csr2      ;//0x0038
          avr32_spi_csr2_t               CSR2      ;
  };
  union {
          unsigned long                  csr3      ;//0x003c
          avr32_spi_csr3_t               CSR3      ;
  };
          unsigned int                   :32       ;//0x0040
          unsigned int                   :32       ;//0x0044
          unsigned int                   :32       ;//0x0048
          unsigned int                   :32       ;//0x004c
          unsigned int                   :32       ;//0x0050
          unsigned int                   :32       ;//0x0054
          unsigned int                   :32       ;//0x0058
          unsigned int                   :32       ;//0x005c
          unsigned int                   :32       ;//0x0060
          unsigned int                   :32       ;//0x0064
          unsigned int                   :32       ;//0x0068
          unsigned int                   :32       ;//0x006c
          unsigned int                   :32       ;//0x0070
          unsigned int                   :32       ;//0x0074
          unsigned int                   :32       ;//0x0078
          unsigned int                   :32       ;//0x007c
          unsigned int                   :32       ;//0x0080
          unsigned int                   :32       ;//0x0084
          unsigned int                   :32       ;//0x0088
          unsigned int                   :32       ;//0x008c
          unsigned int                   :32       ;//0x0090
          unsigned int                   :32       ;//0x0094
          unsigned int                   :32       ;//0x0098
          unsigned int                   :32       ;//0x009c
          unsigned int                   :32       ;//0x00a0
          unsigned int                   :32       ;//0x00a4
          unsigned int                   :32       ;//0x00a8
          unsigned int                   :32       ;//0x00ac
          unsigned int                   :32       ;//0x00b0
          unsigned int                   :32       ;//0x00b4
          unsigned int                   :32       ;//0x00b8
          unsigned int                   :32       ;//0x00bc
          unsigned int                   :32       ;//0x00c0
          unsigned int                   :32       ;//0x00c4
          unsigned int                   :32       ;//0x00c8
          unsigned int                   :32       ;//0x00cc
          unsigned int                   :32       ;//0x00d0
          unsigned int                   :32       ;//0x00d4
          unsigned int                   :32       ;//0x00d8
          unsigned int                   :32       ;//0x00dc
          unsigned int                   :32       ;//0x00e0
          unsigned int                   :32       ;//0x00e4
          unsigned int                   :32       ;//0x00e8
          unsigned int                   :32       ;//0x00ec
          unsigned int                   :32       ;//0x00f0
          unsigned int                   :32       ;//0x00f4
          unsigned int                   :32       ;//0x00f8
  union {
    const unsigned long                  version   ;//0x00fc
    const avr32_spi_version_t            VERSION   ;
  };
} avr32_spi_t;

Is this a little bit ... wasting?

Why?

Cheng

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, got it, it's defined by the SPI register mapping from its datahseet.

But still, defining an SPI instance like this in memeory, is wasting too much...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These registers are not in your application-ram. normally they waste nothing.
Ok.. if you want to backup a complete spi-config, you might be right. but... it depends on your backup-system. It is not nessesary, that you backup i.e. the register used by the pdca. (0x40-0xf8)

greets.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes, right.

thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

now i'm confused again.

any instances of this struct avr32_spi_t should occupy the SRAM, right? Even if there is just one of it.

for example this function from spi.c:

int spi_initMaster(volatile avr32_spi_t *spi, const spi_options_t *options)
{
  u_avr32_spi_mr_t u_avr32_spi_mr;

  if (options->fdiv > 1 ||
      options->modfdis > 1) {
    return SPI_ERROR_ARGUMENT;
  }

  // Reset.
  spi->cr = AVR32_SPI_CR_SWRST_MASK;

  // Master Mode.
  u_avr32_spi_mr.mr = spi->mr;
  u_avr32_spi_mr.MR.mstr = 1;
  u_avr32_spi_mr.MR.fdiv = options->fdiv;
  u_avr32_spi_mr.MR.modfdis = options->modfdis;
  u_avr32_spi_mr.MR.llb = 0;
  u_avr32_spi_mr.MR.pcs = (1 << AVR32_SPI_MR_PCS_SIZE) - 1;
  spi->mr = u_avr32_spi_mr.mr;

  return SPI_OK;
}

or does the AVR32 compiler acutally recongize the name spi->mr in this example code as a register rather than a variable in memory?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The spi pointer would usually be an address in I/O memory area, and thus, should not consume any of your SRAM.

Hans-Christian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so, normally there should be just one spi pointer in program, right?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes!! :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, get it. Thanks.