 // Файл с определениями форматов пакетов низкоуровневых коммандами для AT45DB161E.
 // v 1.0 от 16/07/15
 // Автор: Сычев А.

#ifndef W25Q16JV_LL_H
#define W25Q16JV_LL_H

#if (!defined(W25Q16JV_LOWLEVEL) && !defined(W25Q16JV_APILEVEL))
#error FLASH HAL: вы подключили заголовочный файл для низкоуровневых операций.
#endif

#if (defined(W25Q16JV_LOWLEVEL) || defined(W25Q16JV_APILEVEL))

      #include "drivers\flash\base\flash_api_types.h"
      #include "drivers\flash\w25q\lowlevel\W25Q16JV_GLOB.h"           // определения для AT45DB161E

      __flash_protectionregister_t * __flash_internal_getbuffer_protect();
      //__FLASH_BYTE * __flash_internal_getbuffer_page();
#endif

#ifdef  W25Q16JV_LOWLEVEL
      #define __FLASH_LL_FILLADDRESS(pack, addr)\
      {     pack->addr_23_16 = (addr)>>16;    \
            pack->addr_15_8  = (addr)>>8;     \
            pack->addr_7_0   = (addr)&0xFF;   }
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE   opcode;           // команда ПОСЛЕДОВАТЕЛЬНОЕ ЧТЕНИЕ (БЫСТРОЕ)
          __FLASH_BYTE   addr_23_16;       // Адрес A23..A16
          __FLASH_BYTE   addr_15_8;        // Адрес A15..A08
          __FLASH_BYTE   addr_7_0;         // Адрес A07..A00
      }
      __flash_packet_arrayreadfast_t;  // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE   opcode;           // команда ПОСЛЕДОВАТЕЛЬНОЕ ЧТЕНИЕ
          __FLASH_BYTE   addr_23_16;       // Адрес A23..A16
          __FLASH_BYTE   addr_15_8;        // Адрес A15..A08
          __FLASH_BYTE   addr_7_0;         // Адрес A07..A00
      }
      __flash_packet_arrayread_t;  // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$      
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE   opcode;           // команда ЗАПИСЬ СТРАНИЦЫ
          __FLASH_BYTE   addr_23_16;       // Адрес A23..A16
          __FLASH_BYTE   addr_15_8;        // Адрес A15..A08
          __FLASH_BYTE   addr_7_0;         // Адрес A07..A00
      }
      __flash_packet_page_program_t;  // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE   opcode;           // команда СТИРАНИЕ СТРАНИЦЫ
          __FLASH_BYTE   addr_23_16;       // Адрес A23..A16
          __FLASH_BYTE   addr_15_8;        // Адрес A15..A08
          __FLASH_BYTE   addr_7_0;         // Адрес A07..A00        
      }
      __flash_packet_pageerase_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE   opcode;           // команда СТИРАНИЕ БЛОКА (=СТРАНИЦА)
          __FLASH_BYTE   addr_23_16;       // Адрес A23..A16
          __FLASH_BYTE   addr_15_8;        // Адрес A15..A08
          __FLASH_BYTE   addr_7_0;         // Адрес A07..A00  
      }
      __flash_packet_blockerase_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE   opcode;           // команда СТИРАНИЕ СЕКТОРА
          __FLASH_BYTE   addr_23_16;       // Адрес A23..A16
          __FLASH_BYTE   addr_15_8;        // Адрес A15..A08
          __FLASH_BYTE   addr_7_0;         // Адрес A07..A00  
      }
      __flash_packet_sectorerase_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE    opcode;           // команда блокировки/разблокировки всех Lock-битов секторов
      }
      __flash_packet_globallockcontrol_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE    opcode;           // команда разрешения/запрещения записи
      }
      __flash_packet_writecontrol_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE    opcode;           // команда ЧТЕНИЕ СТАТУСА
      }
      __flash_packet_statusread_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE    opcode;           // команда ЗАПИСЬ СТАТУСА
          __FLASH_BYTE    status;           // команда ЗАПИСЬ СТАТУСА
      }
      __flash_packet_statuswrite_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE    opcode;           // команда ПЕРЕХОД в спящий режим
      }
      __flash_packet_powerdown_t; // [W25Q OK]
      #pragma pack( pop )

    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
          __FLASH_BYTE    opcode;           // команда ВОЗВРАТ из спящего режима
      }
      __flash_packet_powerup_t; // [W25Q OK]
      #pragma pack( pop )

    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
         __FLASH_BYTE     opcode;           // команда ПОЛУЧИТЬ идентификатор производителя
      }
      __flash_packet_manufactureridread_t; // [W25Q OK]
      #pragma pack( pop )

    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
         __FLASH_BYTE     opcode;           // команда ПОЛУЧИТЬ SFDP регистр
         __FLASH_BYTE     zero1;            // =0
         __FLASH_BYTE     zero2;            // =0
         __FLASH_BYTE     offset;           // смещение в байтах регистра SDFP
         __FLASH_BYTE     dummy;            // требуется передать фиктивный байт
      }
      __flash_packet_sfdp_read_t; // [W25Q OK]
      #pragma pack( pop )

    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
         __FLASH_BYTE     opcode;           // команда ПОЛУЧИТЬ Unique ID
         __FLASH_BYTE     zero1;            // требуется передать фиктивный байт
         __FLASH_BYTE     zero2;            // требуется передать фиктивный байт
         __FLASH_BYTE     zero3;            // требуется передать фиктивный байт
         __FLASH_BYTE     zero4;            // требуется передать фиктивный байт
      }
      __flash_packet_uid_read_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
         __FLASH_BYTE    opcode;            // команда СТЕРЕТЬ РЕГИСТР БЕЗОПАСНОСТИ
         __FLASH_BYTE    zero;              // =0
         __FLASH_BYTE    zero_2      : 4;   // =0
         __FLASH_BYTE    regSelector : 4;   // выбор регистра: 0x1 = Register #1, ... 0x3 = Register #3
         __FLASH_BYTE    zero_3;            // =0
      }
      __flash_packet_securityregistererase_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
         __FLASH_BYTE    opcode;            // команда ЗАПИСАТЬ РЕГИСТР БЕЗОПАСНОСТИ
         __FLASH_BYTE    zero;              // =0
         __FLASH_BYTE    zero_2      : 4;   // =0
         __FLASH_BYTE    regSelector : 4;   // выбор регистра: 0x1 = Register #1, ... 0x3 = Register #3
         __FLASH_BYTE    byteSelector;      // =0
      }
      __flash_packet_securityregisterwrite_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
         __FLASH_BYTE   opcode;            // команда ПРОЧИТАТЬ РЕГИСТР БЕЗОПАСНОСТИ
         __FLASH_BYTE   zero;              // =0
         __FLASH_BYTE   zero_2      : 4;   // =0
         __FLASH_BYTE   regSelector : 4;   // выбор регистра: 0x1 = Register #1, ... 0x3 = Register #3
         __FLASH_BYTE   byteSelector;      // начальный адрес байта регистра
      }
      __flash_packet_securityregisterread_t; // [W25Q OK]
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      #pragma pack( push, 1 )
      typedef struct
      {
         __FLASH_BYTE   opcode;           // команда ЗАПИСАТЬ ИНДИВИДУАЛЬНУЮ БЛОКИРОВКУ
         __FLASH_BYTE   addr_23_16;       // Адрес A23..A16
         __FLASH_BYTE   addr_15_8;        // Адрес A15..A08
         __FLASH_BYTE   addr_7_0;         // Адрес A07..A00  
      }
      __flash_packet_protectregister_rw_t;
      #pragma pack( pop )
    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#endif
#endif