air105_cache.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __AIR105_CACHE_H
  22. #define __AIR105_CACHE_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "air105.h"
  28. #define CACHE_REFRESH ((uint32_t)0x80000000)
  29. #define CACHE_REFRESH_ALLTAG ((uint32_t)0x40000000)
  30. #define CACHE_KEY_GEN_START ((uint32_t)0x80000000)
  31. #define CACHE_IS_BUSY ((uint32_t)0x20000000)
  32. #define CACHE_SIZE ((uint32_t)0x8000)
  33. #define CACHE_PARTICLE_SIZE (0x20)
  34. #define CACHE_ADDRESS_START ((uint32_t)0x01000000)
  35. #define CACHE_ADDRESS_MAX ((uint32_t)0x00FFFFFF)
  36. #define IS_CACHE_ADDR_VALID(addr) (((addr) & CACHE_ADDRESS_START) == CACHE_ADDRESS_START)
  37. #define CACHE_AES_BYPASS (0xA5)
  38. #define CACHE_KEY_GEN (0xA5)
  39. #define CACHE_WRAP_ENABLE (0xA5)
  40. #define CACHE_ZONE_ENCRYPT ((uint32_t)0xA5000000)
  41. #define CACHE_CODE_BUS_OFFSET_POS (0)
  42. #define CACHE_CODE_BUS_OFFSET_WIDTH (5)
  43. #define CACHE_CODE_BUS_OFFSET_MASK ((uint32_t)0x001F)
  44. #define CACHE_CODE_BUS_SET_POS (5)
  45. #define CACHE_CODE_BUS_SET_WIDTH (8)
  46. #define CACHE_CODE_BUS_SET_MASK ((uint32_t)0x00FF)
  47. #define CACHE_CODE_BUS_TAG_POS (13)
  48. #define CACHE_CODE_BUS_TAG_WIDTH (11)
  49. #define CACHE_CODE_BUS_TAG_MASK ((uint32_t)0x07FF)
  50. #define CHCHE_ALGORITHM_SET_POS (28)
  51. #define CACHE_BUILD_INDEX_OFFSET(x) (((x) & CACHE_CODE_BUS_OFFSET_MASK) << CACHE_CODE_BUS_OFFSET_POS)
  52. #define CACHE_BUILD_INDEX_SET(x) (((x) & CACHE_CODE_BUS_SET_MASK) << CACHE_CODE_BUS_SET_POS)
  53. #define CACHE_BUILD_INDEX_TAG(x) (((x) & CACHE_CODE_BUS_TAG_MASK) << CACHE_CODE_BUS_TAG_POS)
  54. #define CACHE_ADDRESS_BUILD(base,index_set,tag_way,offset) ((base) | CACHE_BUILD_INDEX_SET(index_set) | CACHE_BUILD_INDEX_TAG(tag_way) | CACHE_BUILD_INDEX_OFFSET(offset))
  55. #define CACHE_TAG_NUM(x) ((x >> CACHE_CODE_BUS_TAG_POS) & CACHE_CODE_BUS_TAG_MASK)
  56. #define CACHE_SET_NUM(x) ((x >> CACHE_CODE_BUS_SET_POS) & CACHE_CODE_BUS_SET_MASK)
  57. #define CACHE_OFF_NUM(x) ((x >> CACHE_CODE_BUS_OFFSET_POS) & CACHE_CODE_BUS_OFFSET_MASK)
  58. typedef enum
  59. {
  60. CACHE_Encrypt_Mode_All = 0x0,
  61. CACHE_Encrypt_Mode_Zone,
  62. }CACHE_EncryptModeTypeDef;
  63. #define IS_CACHE_ENCRYPT_MODE(MODE) (((MODE) == CACHE_Encrypt_Mode_All) || \
  64. ((MODE) == CACHE_Encrypt_Mode_Zone))
  65. typedef struct
  66. {
  67. uint32_t I[4];
  68. uint32_t K[4];
  69. uint32_t AES_CS;
  70. uint32_t CONFIG;
  71. uint32_t aes_enable;
  72. uint32_t Address;
  73. uint32_t size;
  74. uint32_t algorithm;
  75. uint32_t encrypt_mode;
  76. uint32_t encrypt_saddr;
  77. uint32_t encrypt_eaddr;
  78. }CACHE_InitTypeDef;
  79. void CACHE_Init(CACHE_TypeDef *Cache, CACHE_InitTypeDef *CACHE_InitStruct);
  80. void CACHE_Clean(CACHE_TypeDef *Cache, CACHE_InitTypeDef *CACHE_InitStruct);
  81. void CACHE_CleanAll(CACHE_TypeDef *Cache);
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif
  86. /************************** (C) COPYRIGHT Megahunt *****END OF FILE****/