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

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