# Development of a Datalogger for Submarine Glider: Integration of Fault-Tolerant Software Layers
## 2 Datalogger Design
### Data Writing  
For the writing operation is required to send a command to the datalogger in order to perform the desired operation. To perform a write in a page is necessary to erase the block's page. The erase operation is done out of the water when there is no more storage space. The erase time is not considered in the average performance because the memory chip is erased before the glider is submerged, then it is only written to NAND flash in which there will be no erase operations. In order for all data received by serial to be stored in the NAND flash memory chip, data encoding and writing operations in NAND flash must be performed in parallel with serial data reception. To achieve this, the DMA module is used for serial reception. Figure 9 shows the general DMA module diagram. There are three DMA channels. Initially, the datalogger used two modules: one for reception and the other for serial transmission. However, the bottleneck in reading NAND flash is decoding, and therefore we do not occupy DMA in serial transmission. Each DMA channel has three registers: the source address, the destination address, and the transfer size. For DMA channel 1, the source address is the serial UART RX buffer, the destination address is a vector where a message of k bytes is temporarily stored, which is the transfer size. Figure 8: The orientation of each code was done vertically as shown. A byte has 8 bits, therefore the number of codes is 64. Figure 7: Systematic cyclic encoder LFSR circuit. \(d(x)\) is the data input and \(c(x)\) is the coded word. The block diagram for the write protocol of the NAND flash unit is described in Figure 10. Concurrent operations are performed, the CPU controls the send of commands to NAND flash for writing, reading, and erasing operations. In the other hand, the DMA performs serial reception. In Figure 10, the source address of the DMA is the RX buffer and all data that are received by serial bus through the vector \(m\) of \(k\) bytes. At the same time, the BCH encoder adds parity bits to vector \(m\), the message and parity bytes are temporarily stored in a 255-byte vector \(c\) so that they are then stored in the \(m_{page}\) vector that corresponds to a complete page of 2040 bytes. Then, data are stored in a NAND Flash memory page. To write to the NAND flash memory chip first of all, the pointer that contains the last write address must be read. In case it is the first write operation, the pointer should be in the logical zero write address. In case there has been any loss of electrical power, the write address should have been updated during the last write cycle. After reading the pointer, the messages are received by the microcontroller by serial at 115200 baud. In order to receive the data and concurrently perform the encoding and writing in NAND Flash, the Direct Memory Access DMA module is required. Two states were used to activate channel 1 of the DMA: \(DMA1_{0}\) and \(DMA1_{1}\). These states are for the microcontroller to perform the function of activating channel 1 of the DMA, which has as its source a UART RX buffer, as its destination a message vector \(m\) and a size transfer of 223 bytes. For the underwater glider, there are two different write operations. The first operation is the configuration data of the glider, which are stored on the first page of the first block  
Figure 10: Data writing block diagram. The information is received via serial and stored in the vector \(m\) of the DMA module. In parallel, the information is encoded, and the NAND flash memory chip is written. Figure 9: DMA module diagram summary. The DMA module receives the data by serial. This data are stored in a vector (Address space). Moreover, the data can be used in parallel in the microcontroller CPU operations. of NAND flash memory chip. The other write operation corresponds to the storage of variables provided by mission. Metadata and regression coefficients that may be required for future maintenance of the submarine glider are also stored.