Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

ftfl.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* Copyright (c) 2011,2012 Simon Schubert <[email protected]>.
  2. * Modifications by Jacob Alexander 2014 <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __FTFL_H
  18. #define __FTFL_H
  19. // ----- Local Includes -----
  20. #include "mchck-cdefs.h"
  21. // ----- Structs -----
  22. struct FTFL_FSTAT_t {
  23. UNION_STRUCT_START(8);
  24. uint8_t mgstat0 : 1;
  25. uint8_t _rsvd0 : 3;
  26. uint8_t fpviol : 1;
  27. uint8_t accerr : 1;
  28. uint8_t rdcolerr : 1;
  29. uint8_t ccif : 1;
  30. UNION_STRUCT_END;
  31. };
  32. CTASSERT_SIZE_BIT(struct FTFL_FSTAT_t, 8);
  33. struct FTFL_FCNFG_t {
  34. UNION_STRUCT_START(8);
  35. uint8_t eeerdy : 1;
  36. uint8_t ramrdy : 1;
  37. uint8_t pflsh : 1;
  38. uint8_t _rsvd0 : 1;
  39. uint8_t erssusp : 1;
  40. uint8_t ersareq : 1;
  41. uint8_t rdcollie : 1;
  42. uint8_t ccie : 1;
  43. UNION_STRUCT_END;
  44. };
  45. CTASSERT_SIZE_BIT(struct FTFL_FCNFG_t, 8);
  46. struct FTFL_FSEC_t {
  47. UNION_STRUCT_START(8);
  48. enum {
  49. FTFL_FSEC_SEC_UNSECURE = 2,
  50. FTFL_FSEC_SEC_SECURE = 3
  51. } sec : 2;
  52. enum {
  53. FTFL_FSEC_FSLACC_DENY = 1,
  54. FTFL_FSEC_FSLACC_GRANT = 3
  55. } fslacc : 2;
  56. enum {
  57. FTFL_FSEC_MEEN_DISABLE = 2,
  58. FTFL_FSEC_MEEN_ENABLE = 3
  59. } meen : 2;
  60. enum {
  61. FTFL_FSEC_KEYEN_DISABLE = 1,
  62. FTFL_FSEC_KEYEN_ENABLE = 2
  63. } keyen : 2;
  64. UNION_STRUCT_END;
  65. };
  66. CTASSERT_SIZE_BIT(struct FTFL_FSEC_t, 8);
  67. struct FTFL_FOPT_t {
  68. UNION_STRUCT_START(8);
  69. uint8_t lpboot : 1;
  70. uint8_t ezport_dis : 1;
  71. uint8_t nmi_dis : 1;
  72. uint8_t _rsvd0 : 5;
  73. UNION_STRUCT_END;
  74. };
  75. CTASSERT_SIZE_BIT(struct FTFL_FOPT_t, 8);
  76. /**
  77. * The FCOOB is a weird register file, because it is double big endian,
  78. * which makes for odd gaps and for some data that is big endian, and for
  79. * some that is little endian.
  80. */
  81. union FTFL_FCCOB_t {
  82. struct ftfl_generic {
  83. uint32_t addr : 24;
  84. enum FTFL_FCMD {
  85. FTFL_FCMD_READ_1s_BLOCK = 0x00,
  86. FTFL_FCMD_READ_1s_SECTION = 0x01,
  87. FTFL_FCMD_PROGRAM_CHECK = 0x02,
  88. FTFL_FCMD_READ_RESOURCE = 0x03,
  89. FTFL_FCMD_PROGRAM_LONGWORD = 0x06,
  90. FTFL_FCMD_ERASE_BLOCK = 0x08,
  91. FTFL_FCMD_ERASE_SECTOR = 0x09,
  92. FTFL_FCMD_PROGRAM_SECTION = 0x0b,
  93. FTFL_FCMD_READ_1s_ALL_BLOCKS = 0x40,
  94. FTFL_FCMD_READ_ONCE = 0x41,
  95. FTFL_FCMD_PROGRAM_ONCE = 0x43,
  96. FTFL_FCMD_ERASE_ALL_BLOCKS = 0x44,
  97. FTFL_FCMD_VERIFY_KEY = 0x45,
  98. FTFL_FCMD_PROGRAM_PARTITION = 0x80,
  99. FTFL_FCMD_SET_FLEXRAM = 0x81
  100. } fcmd : 8;
  101. uint8_t data_be[8];
  102. } generic;
  103. struct {
  104. uint32_t addr : 24;
  105. enum FTFL_FCMD fcmd : 8;
  106. uint8_t _rsvd0[3];
  107. enum FTFL_MARGIN_CHOICE {
  108. FTFL_MARGIN_NORMAL = 0x00,
  109. FTFL_MARGIN_USER = 0x01,
  110. FTFL_MARGIN_FACTORY = 0x02
  111. } margin : 8;
  112. } read_1s_block;
  113. struct ftfl_data_num_words {
  114. uint32_t addr : 24;
  115. enum FTFL_FCMD fcmd : 8;
  116. uint8_t _rsvd0;
  117. enum FTFL_MARGIN_CHOICE margin : 8;
  118. uint16_t num_words;
  119. } read_1s_section;
  120. struct {
  121. uint32_t addr : 24;
  122. enum FTFL_FCMD fcmd : 8;
  123. uint8_t _rsvd0[3];
  124. enum FTFL_MARGIN_CHOICE margin : 8;
  125. uint8_t data_be[4];
  126. } program_check;
  127. struct {
  128. uint32_t addr : 24;
  129. enum FTFL_FCMD fcmd : 8;
  130. uint32_t data;
  131. uint8_t _rsvd0[3];
  132. enum FTFL_RESOURCE_SELECT {
  133. FTFL_RESOURCE_IFR = 0x00,
  134. FTFL_RESOURCE_VERSION = 0x01
  135. } resource_select : 8;
  136. } read_resource;
  137. struct {
  138. uint32_t addr : 24;
  139. enum FTFL_FCMD fcmd : 8;
  140. uint8_t data_be[4];
  141. } program_longword;
  142. struct {
  143. uint32_t addr : 24;
  144. enum FTFL_FCMD fcmd : 8;
  145. } erase;
  146. struct ftfl_data_num_words program_section;
  147. struct {
  148. uint8_t _rsvd0[2];
  149. enum FTFL_MARGIN_CHOICE margin : 8;
  150. enum FTFL_FCMD fcmd : 8;
  151. } read_1s_all_blocks;
  152. struct ftfl_cmd_once {
  153. uint8_t _rsvd0[2];
  154. uint8_t idx;
  155. enum FTFL_FCMD fcmd : 8;
  156. uint8_t data_be[4];
  157. } read_once;
  158. struct ftfl_cmd_once program_once;
  159. struct {
  160. uint8_t _rsvd0[3];
  161. enum FTFL_FCMD fcmd : 8;
  162. } erase_all;
  163. struct {
  164. uint8_t _rsvd0[3];
  165. enum FTFL_FCMD fcmd : 8;
  166. uint8_t key_be[8];
  167. } verify_key;
  168. struct {
  169. uint8_t _rsvd0[3];
  170. enum FTFL_FCMD fcmd : 8;
  171. uint8_t _rsvd1[2];
  172. /* the following enum is analogous to enum
  173. * SIM_FLEXNVM_PARTITION in sim.h, but this one is padded
  174. * with four 1-bits to make an 8-bit value.
  175. */
  176. enum FTFL_FLEXNVM_PARTITION {
  177. FTFL_FLEXNVM_DATA_32_EEPROM_0 = 0xF0,
  178. FTFL_FLEXNVM_DATA_24_EEPROM_8 = 0xF1,
  179. FTFL_FLEXNVM_DATA_16_EEPROM_16 = 0xF2,
  180. FTFL_FLEXNVM_DATA_8_EEPROM_24 = 0xF9,
  181. FTFL_FLEXNVM_DATA_0_EEPROM_32 = 0xF3
  182. } flexnvm_partition : 8;
  183. enum FTFL_EEPROM_SIZE {
  184. FTFL_EEPROM_SIZE_0 = 0x3f,
  185. FTFL_EEPROM_SIZE_32 = 0x39,
  186. FTFL_EEPROM_SIZE_64 = 0x38,
  187. FTFL_EEPROM_SIZE_128 = 0x37,
  188. FTFL_EEPROM_SIZE_256 = 0x36,
  189. FTFL_EEPROM_SIZE_512 = 0x35,
  190. FTFL_EEPROM_SIZE_1024 = 0x34,
  191. FTFL_EEPROM_SIZE_2048 = 0x33
  192. } eeprom_size : 8;
  193. } program_partition;
  194. struct {
  195. uint8_t _rsvd0[2];
  196. enum FTFL_FLEXRAM_FUNCTION {
  197. FTFL_FLEXRAM_EEPROM = 0x00,
  198. FTFL_FLEXRAM_RAM = 0xff
  199. } flexram_function : 8;
  200. enum FTFL_FCMD fcmd : 8;
  201. } set_flexram;
  202. };
  203. CTASSERT_SIZE_BYTE(union FTFL_FCCOB_t, 12);
  204. struct FTFL_t {
  205. struct FTFL_FSTAT_t fstat;
  206. struct FTFL_FCNFG_t fcnfg;
  207. struct FTFL_FSEC_t fsec;
  208. struct FTFL_FOPT_t fopt;
  209. union FTFL_FCCOB_t fccob;
  210. uint8_t fprot_be[4];
  211. uint8_t feprot;
  212. uint8_t fdprot;
  213. };
  214. CTASSERT_SIZE_BYTE(struct FTFL_t, 0x18);
  215. /* Flash Configuration Field, see Sub-Family Reference Manual, section 28.3.1 */
  216. struct FTFL_CONFIG_t {
  217. uint8_t key[8];
  218. uint8_t fprot[4];
  219. struct FTFL_FSEC_t fsec;
  220. struct FTFL_FOPT_t fopt;
  221. uint8_t feprot;
  222. uint8_t fdprot;
  223. };
  224. CTASSERT_SIZE_BYTE(struct FTFL_CONFIG_t, 16);
  225. extern volatile struct FTFL_t FTFL;
  226. extern char FlexRAM[];
  227. extern struct FTFL_CONFIG_t FTFL_CONFIG;
  228. #endif