| Xmega IEC60730 Class B Library 1.0 |

All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Internal SRAM Test

## Detailed Description

This self-diagnostic test checks the internal SRAM memory for coupling faults.

The test classb_sram_test() divides the internal SRAM into CLASSB_NSECS sections that are tested in turns with a March algorithm (see March X). The simplest behavior of the test is when there is no overlap between memory sections. In this case all sections have the same size, except possibly the last one (see CLASSB_NSECS). The first memory section (referred to as the buffer) is reserved: it is used by the test to store the content of the other sections while they are being tested (for more details see classb_buffer).

If there is overlap (see CLASSB_OVERLAP), every time a memory section is tested a part of the previous section is tested as well. Note that this does not apply to the buffer, since it is the first section. The size of the buffer is then expanded with respect to the previous case. Further, the size of the second section is decreased correspondingly.

If there should be an error in internal SRAM the error handler CLASSB_ERROR_HANDLER_SRAM() would be called.

Note:
  Interrupts must be disabled during this test.

# March X

The chosen algorithm is March X. This consists on the following steps:

\[ \Updownarrow (w_\textbf{D}); \Uparrow(r_\textbf{D}, w_\bar{\textbf{D}}); \Downarrow (r_\bar{\textbf{D}}, w_\textbf{D}); \Updownarrow (r_\textbf{D}) \;,\]

where \(w\) denotes a write operation, \(r\) denotes a read operation, \(\textbf{D}\) is any data background, \(\bar{\textbf{D}}\) is the complement of \(\textbf{D}\) and the arrows refer to the addressing order. In our implementation we have chosen \(\textbf{D} = \text{0x00}\).

Under the restricted coupling faults (CFs) model, the interleaved organization of the memory in XMEGA avoids any kind of intra-word CFs. However, in order to detect some intra-word CFs that are not considered by this fault model, we have included the following optional march element:

\[ \Updownarrow (w_\textbf{D_0}, r_\textbf{D_0} \ldots w_\textbf{D_d}, r_\textbf{D_d}) \;,\]

where the background sequence is \(\text{{0x00, 0xFF, 0x55, 0xAA, 0x33, 0xCC, 0x0F, 0xF0}}\). This intra-word test is only executed if CLASSB_SRAM_INTRAWORD_TEST is defined. The elements that correspond to the first two data backgrounds are redundant because the first part of the test includes them. This optional test will detect all intra-word state CFs considered by the unrestricted CF model.

uint8_t | classb_buffer [CLASSB_SEC_SIZE+CLASSB_OVERLAP_SIZE]
| Buffer of SRAM memory that is used to store the information from sections that are tested.

## Configuration settings
#define | CLASSB_NSECS 8
| Number of sections the SRAM is divided into for testing.
#define | CLASSB_OVERLAP 25UL
| Overlap between memory sections (in % of `CLASSB_SEC_SIZE`).
#define | CLASSB_SRAM_INTRAWORD_TEST
| If defined an intra-word test will be added after the inter-word test.

## Class B Test
void | classb_sram_test (void)
| This function executes March X test for a memory section at a time.

## Macro Definition Documentation

#define CLASSB_NSECS 8

Number of sections the SRAM is divided into for testing.

It is advisable that `INTERNAL_SRAM_SIZE` is divisible by the number of sections and, therefore, recommended values are 2, 4, 8, 16, etc. Otherwise an extra section will be added with the remainder of the division as size. Note that the higher the number of sections the smaller the size of classb_buffer, i.e. the section of memory that is reserved for the test) and the faster each partial test is completed.

Definition at line 109 of file classb_sram.h.

Referenced by classb_sram_test().

#define CLASSB_OVERLAP 25UL

Overlap between memory sections (in % of `CLASSB_SEC_SIZE`).

This should be an unsigned long, i.e. <val>UL.

Definition at line 116 of file classb_sram.h.

#define CLASSB_SRAM_INTRAWORD_TEST

If defined an intra-word test will be added after the inter-word test.

Given the layout of the memory, the probability of intra-word coupling faults is greatly diminished. However, for extra safety the test can be expanded to check some intra word coupling faults.

Definition at line 124 of file classb_sram.h.

## Function Documentation

void classb_sram_test | ( | void |  | ) |

This function executes March X test for a memory section at a time.

The test behaves as follows for a general section:

- The size of the section is `CLASSB_SEC_SIZE`.
- In order to have overlap between sections, the total number of bytes to be tested is `CLASSB_SEC_SIZE + CLASSB_OVERLAP_SIZE`.
- The algorithm is set to start `CLASSB_OVERLAP_SIZE` bytes before the start of the current section, thus overlapping `CLASSB_OVERLAP_SIZE` bytes with the previous section.

Special cases of memory sections are:

- The first section to test is the buffer segment, which starts at `INTERNAL_SRAM_START` and ends at `CLASSB_SEC_SIZE + CLASSB_OVERLAP_SIZE`. In this case there is no previous segment, so no overlap is necessary. The total number of bytes tested is then the size of the buffer.
- The second section to test is the first "data" memory section (i.e. the one after the buffer). The size of this section is `CLASSB_SEC_SIZE - CLASSB_OVERLAP_SIZE` (i.e. the size of this section was reduced in `CLASSB_OVERLAP_SIZE` bytes in order to expand the buffer by the same size). The test starts `CLASSB_OVERLAP_SIZE` bytes before the beginning of the section, and the total number of bytes tested is then `CLASSB_SEC_SIZE`.
- The "remainder" segment, if any. This section has a size of `CLASSB_SEC_REM`, so the total number of bytes will be `CLASSB_SEC_REM + CLASSB_OVERLAP_SIZE`.

Definition at line 122 of file classb_sram.c.

References CLASSB_NSECS.

Referenced by main().

Here is the caller graph for this function:

## Variable Documentation

uint8_t classb_buffer[CLASSB_SEC_SIZE+CLASSB_OVERLAP_SIZE]

Buffer of SRAM memory that is used to store the information from sections that are tested.

The buffer is placed in the beginning of SRAM (see `INTERNAL_SRAM_START`). The size in bytes should be `INTERNAL_SRAM_SIZE/CLASSB_NSECS+CLASSB_OVERLAP_SIZE`. As an example, let us suppose the device has `INTERNAL_SRAM_SIZE=4096` Bytes of SRAM, CLASSB_NSECS = 8 and CLASSB_OVERLAP=25. Given that the number of sections is a divisor of `INTERNAL_SRAM_SIZE`, there would be in principle exactly 8 sections, each with a size of 512 Bytes. For 25% overlap we need to extend the first section (the buffer) by 128 Bytes, and the second section is shortened accordingly. Therefore, we would have to reserve 512+128=640 Bytes for the buffer.

The implementation depends on the compiler: For IAR it is easy because variables can be placed in a specific address using the a location pragma directive. For GCC the following steps should be followed:

- Firstly, it is necessary to define in AVR/GNU C linker > Memory settings a section that starts at `INTERNAL_SRAM_START`, for example: `.classb_sram_buffer=0x2000`.
- Secondly, the buffer variable has to be placed in that memory section. This can be done appending this to the definition of the variable: `__attribute__ ((section(".classb_sram_buffer")))`.
- Thirdly, the `.data` section has to be moved so that there is no overlap: the start should be `INTERNAL_SRAM_START + buffer_size`. For example 640=0x280 and then we would set `.data=0x2280`.

Definition at line 97 of file classb_sram.c.