Data Structures | Typedefs | Functions

xpal_extmem.h File Reference

interface to external SRAM (init, check) More...

#include <stdlib.h>
#include "xpal_board.h"
#include "xpal_power.h"
#include "usb-fifo.h"

Go to the source code of this file.

Data Structures

struct  hlog_extmem_info_s
 describe external memory area More...

Typedefs

typedef struct hlog_extmem_info_s hlog_extmem_info_t
 describe external memory area

Functions

void ExtMemInit (void)
 make external RAM accessible to MCU
void ExtMemDisable (void)
 Disable and deactivate external RAM to save power.
void ExtMemEnable (void)
 Enable the external RAM eg. after power save.
void ExtMemReducePower (void)
 Deselect the external RAM - Depreciated, function has no effect.
hlog_extmem_info_textmem_test (uint8_t level)
 test external memory

Detailed Description

interface to external SRAM (init, check)


Function Documentation

hlog_extmem_info_t* extmem_test ( uint8_t  level  ) 

test external memory

Tests the external memory. The level argument can be used to select how good the memory will be tested. Better testing means the test will take longer.

Parameters:
level 0 - basic test, fast; 0xFF - most testing, slow
Returns:
pointer to description of area, NULL when testing fails completely (there is no chip installed or the installed chip is bad)

At the moment, level is not used

We use the ((address+i) % 0xFF) as fill byte, this should detect the most common aliasing problems as well as dead cells

{
  uint8_t * p;
  uint8_t * end = xmem.xmem_end;
  uint8_t i; /* start byte */
  uint8_t b; /* fill byte */

  /* testing all possible byte values takes too long,
   * this takes approx. 0.5 seconds
   */
  for (i=7*31; i; i-=31) {
    uint8_t good_found = 0;
    /* fill memory */
    for (p = xmem.xmem_start, b = test_baseval (p, i);
         p != end+1;
         p++, b = fold_ff(b+1)) {
      *p = b;
    }
    /* check it */
    for (p = xmem.xmem_start, b = test_baseval (p, i);
         p != end+1;
         p++, b = fold_ff(b+1)) {
      if (*p == b) {
        good_found = 1;
      } else {
        if (good_found) {
          xmem.xmem_end = end = p;
          break; /* abort test */
        } else {
          xmem.xmem_start = p+1;
        }
      }
    }
  }
  return (xmem.xmem_start <= xmem.xmem_end) ? &xmem : NULL;
}

void ExtMemDisable ( void   )  [inline]

Disable and deactivate external RAM to save power.

When disabled, the external RAM can not be accessed before enable was called again. This function does also switch the RAM chip select to high. It is required to deselect the RAM before power down. Otherwise the data retention is not guarantied.

{
        // disable RAM to enter data retention mode
        XMCRA &= ~(_BV(SRE));

};

void ExtMemEnable ( void   )  [inline]

Enable the external RAM eg. after power save.

The memory controler will get enabled by this function.

{
        // enable RAM to allow access
        XMCRA |= (_BV(SRE));

};

void ExtMemReducePower ( void   )  [inline]

Deselect the external RAM - Depreciated, function has no effect.

Deactivation by read outside the RAM addr. range has no effect. Hi Addr will get zero again after access. Bus keeper works for port A only.

{
        // Check if USB is active
        //if( ! (HL_PWR_USB_ACTIVE & (hl_pwr_GetState())) ){
        
                // USB is not active
                // volatile char x = *((char *)HL_USB_BASE_ADR);

                // silence compiler warning "unused variable 'x'"
                // __asm__ ("" : : "r" (x));
        //}
};