Memory Sharing Clause Samples

Memory Sharing. For VM mode, unless Senselock ELis reset (for example, the device is unplugged or the S4Control()function is used to send COTROL_RESET_DEVICE control code); otherwise after Senselock ELEXF is executed, the system will not clear automatically the contents of external RAM while the contents of internal RAM will be cleared each time. For XA mode, all the memory will not be cleared automatically. Using this feature, we can use the memory ―that is not cleared automatically‖ as ―shared memory‖. This can help share data between different EXFs and can also use them to buffer data among consecutive calls. For instance, if a program in Senselock ELneeds to receive data larger than 250 bytes, it can be done through a process similar to the following sample: #include “ses_v3.h” typedef struct { unsigned short offset; unsigned ▇▇▇▇ ▇▇▇; unsigned char buff[1]; } IO_PACKAGE; DEFINE_AT(unsigned char, big_buff[512], 0x400, RAM_EXT); IO_PACKAGE *input = NULL; void main() { input = (IO_PACKAGE *)pbInBuff; LE16_TO_CC(&input->len); if (input->len != 0) { memcpy(big_buff + input->offset, input->buff, input->len); _exit(); } /* now got enough data and you can add operations here… */ _exit(); } In the codes, we use two macros: DEFINE_AT and LE16_TO_CC. The former can define a variable at the specified address of the specified memory area while the use of the latter will be explained later in the topic of ―Big-Endian and Little-Endian‖, so you can temporarily think of it as useless. In this sample, we have defined a 512-byte array of unsigned char at 0x400 of the external memory. Furthermore, we have also declared a structure where offset is designed to specify the location where the data input this time are stored in the variable big_buff. len indicates the length of the data input this time while buff saves the inputted data. Suppose the 512-byte data shall be transported to Senselock ELbefore they are operated, the above codes can be executed four times. At each execution, the following offsets: 0, 128, 256, 384 and their corresponding 128-byte data are transmitted in respectively. At the fifth execution, the variable len is set to 0, indicating no additional data can be transmitted in. At this point, the codes have acquired sufficient 512-byte data and can continue to execute the required functions.