---
# System prepended metadata

title: Thermal_Vacuum
tags: [Gemini, Read Code, Thermal_Vacuum]

---

# Thermal_Vacuum
###### tags: `Read Code`,`Thermal_Vacuum`
###### src: **task_thermal_vacuum.c**,  **nand_flash.c**
---
## 相關package
```C=
#include <stdio.h>
```
```C=
#include "FreeRTOS.h"
#include "os_task.h"
```
```C=
#include "HL_sys_common.h"
#include "HL_system.h"
#include "HL_sci.h"
#include "HL_adc.h"
#include "HL_reg_adc.h"
```
```C=
#include "utils.h"
#include "global.h"
#include "nand_flash.h"
```
```C=
#include "task_thermal_vacuum.h"
```
## 變數
- nand flash variables
    ```C=
    typedef enum
    {
        NAND_SUCCESS,
        NAND_FAIL,
        NAND_IOFAIL,
        NAND_ECC_ERROR,
        NAND_TIMEOUT,
    }NAND_STATUS;
    
    typedef struct nand_device {
        int is_initialized;

        // parameters
        uint32_t sector_size; // 512B , software define
        uint32_t page_size; // 2048B
        uint32_t block_size; // 128KB
        uint32_t spare_size; // 64B not include ECC area
        uint32_t pages_per_block; // 64
        uint32_t num_pages; // 1024 * 64
        uint32_t num_blocks; // 1024

        // spi
        spiBASE_t *spi;
        spiDAT1_t dc;
        SemaphoreHandle_t sem;
        uint32_t timeout;

        // functions
        nand_read_fp read;
        nand_write_fp write;
        nand_erase_fp erase;
    } nand_device_t;
    
    uint8_t spiRWCS(nand_device_t *h, uint32_t blocksize, uint8_t * srcbuff, uint8_t * destbuff, boolean last_cshold)
    nand_device_t * NANDFLASH_Init(int id);
    
    //length: 1 ~ 2176
    NAND_STATUS NANDFLASH_Read(nand_device_t *h, uint32_t address, uint8_t * destbuff, uint32_t length)
    
    NAND_STATUS NANDFLASH_Write(nand_device_t *h, uint32_t address, uint8_t * srcbuff, uint32_t length)
    
    NAND_STATUS NANDFLASH_Erase(nand_device_t *h, uint32_t address, uint32_t length)
    ```
    
- utils variables
    ```C=
    typedef struct rti {
        uint32_t frc;
       //uint32_t uc;
    }rti_t ;
    
    void save_rti_time(rti_t *buf);
    uint32_t diff_rti(rti_t *now, rti_t *past);
    uint32_t compare_memory_pattern_uint16(const uint16_t *start, int len, uint16_t pattern)
    ```
- HL_reg_adc.h variables
    ```C=
    #define adcREG1 ((adcBASE_t *)0xFFF7C000U)
    #define adcREG2 ((adcBASE_t *)0xFFF7C200U)
    ```
- HL_adc.h variables
    ```C=
    typedef struct adcData
    typedef struct adcData
    {
        uint32 id;     /**< Channel/Pin Id        */
        uint16 value;  /**< Conversion data value */
    } adcData_t;

    #define adcGROUP0 0U
    #define adcGROUP1 1U
    #define adcGROUP2 2U
    
    uint32  adcGetData(adcBASE_t *adc, uint32 group, adcData_t *data);
    ```
- else
    ```C=
    #define ADC_CHANNELS 10
    ```

## pre-designed function
- uint32_t **get_current_time**()
    - save_rti_time()
    - diff_rti()
    - rti_to_microsecond()
- int **thermal_vacuum_test_adc**()
    > use my_adcStartConversion() to convert and adcGetData() get the adcdata.

- int **thermal_vacuum_test_sram**(uint32_t pattern)
    > test the sram memory is equal to pattern or not.

- int **thermal_vacuum_test_flash**(uint32_t pattern)
    - check those are executed successfully or not
    > NAND_STATUS NANDFLASH_Read
    > NAND_STATUS NANDFLASH_Write
    > NAND_STATUS NANDFLASH_Erase
    
        

- void **vTask_thermal_vacuum**(void *param)
    > use loop to print the information of above function.

---
###### tags: `Gemini`, `Thermal_Vacuum`