cpu_core.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. /*
  2. *********************************************************************************************************
  3. * uC/CPU
  4. * CPU CONFIGURATION & PORT LAYER
  5. *
  6. * (c) Copyright 2004-2015; Micrium, Inc.; Weston, FL
  7. *
  8. * All rights reserved. Protected by international copyright laws.
  9. *
  10. * uC/CPU is provided in source form to registered licensees ONLY. It is
  11. * illegal to distribute this source code to any third party unless you receive
  12. * written permission by an authorized Micrium representative. Knowledge of
  13. * the source code may NOT be used to develop a similar product.
  14. *
  15. * Please help us continue to provide the Embedded community with the finest
  16. * software available. Your honesty is greatly appreciated.
  17. *
  18. * You can find our product's user manual, API reference, release notes and
  19. * more information at https://doc.micrium.com.
  20. * You can contact us at www.micrium.com.
  21. *********************************************************************************************************
  22. */
  23. /*
  24. *********************************************************************************************************
  25. *
  26. * CORE CPU MODULE
  27. *
  28. * Filename : cpu_core.h
  29. * Version : V1.30.02
  30. * Programmer(s) : SR
  31. * ITJ
  32. *********************************************************************************************************
  33. * Note(s) : (1) Assumes the following versions (or more recent) of software modules are included in
  34. * the project build :
  35. *
  36. * (a) uC/LIB V1.35.00
  37. *********************************************************************************************************
  38. */
  39. /*
  40. *********************************************************************************************************
  41. * MODULE
  42. *
  43. * Note(s) : (1) This core CPU header file is protected from multiple pre-processor inclusion through use of
  44. * the core CPU module present pre-processor macro definition.
  45. *********************************************************************************************************
  46. */
  47. #ifndef CPU_CORE_MODULE_PRESENT /* See Note #1. */
  48. #define CPU_CORE_MODULE_PRESENT
  49. /*
  50. *********************************************************************************************************
  51. * EXTERNS
  52. *********************************************************************************************************
  53. */
  54. #ifdef CPU_CORE_MODULE
  55. #define CPU_CORE_EXT
  56. #else
  57. #define CPU_CORE_EXT extern
  58. #endif
  59. /*
  60. *********************************************************************************************************
  61. * INCLUDE FILES
  62. *
  63. * Note(s) : (1) CPU-configuration software files are located in the following directories :
  64. *
  65. * (a) \<Your Product Application>\cpu_cfg.h
  66. *
  67. * (b) (1) \<CPU-Compiler Directory>\cpu_*.*
  68. * (2) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  69. *
  70. * where
  71. * <Your Product Application> directory path for Your Product's Application
  72. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  73. * <cpu> directory name for specific processor (CPU)
  74. * <compiler> directory name for specific compiler
  75. *
  76. * (2) NO compiler-supplied standard library functions SHOULD be used.
  77. *
  78. * (a) Standard library functions are implemented in the custom library module(s) :
  79. *
  80. * \<Custom Library Directory>\lib_*.*
  81. *
  82. * where
  83. * <Custom Library Directory> directory path for custom library software
  84. *
  85. * (3) Compiler MUST be configured to include as additional include path directories :
  86. *
  87. * (a) '\<Your Product Application>\' directory See Note #1a
  88. *
  89. * (b) (1) '\<CPU-Compiler Directory>\' directory See Note #1b1
  90. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #1b2
  91. *
  92. * (c) '\<Custom Library Directory>\' directory See Note #2a
  93. *********************************************************************************************************
  94. */
  95. #include <cpu.h>
  96. #include <lib_def.h>
  97. #include <cpu_cfg.h>
  98. #if (CPU_CFG_NAME_EN == DEF_ENABLED)
  99. #include <lib_mem.h>
  100. #include <lib_str.h>
  101. #endif
  102. /*
  103. *********************************************************************************************************
  104. * CPU CONFIGURATION
  105. *
  106. * Note(s) : (1) The following pre-processor directives correctly configure CPU parameters. DO NOT MODIFY.
  107. *
  108. * (2) CPU timestamp timer feature is required for :
  109. *
  110. * (a) CPU timestamps
  111. * (b) CPU interrupts disabled time measurement
  112. *
  113. * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  114. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1'.
  115. *********************************************************************************************************
  116. */
  117. #ifdef CPU_CFG_TS_EN
  118. #undef CPU_CFG_TS_EN
  119. #endif
  120. #if ((CPU_CFG_TS_32_EN == DEF_ENABLED) || \
  121. (CPU_CFG_TS_64_EN == DEF_ENABLED))
  122. #define CPU_CFG_TS_EN DEF_ENABLED
  123. #else
  124. #define CPU_CFG_TS_EN DEF_DISABLED
  125. #endif
  126. #if ((CPU_CFG_TS_EN == DEF_ENABLED) || \
  127. (defined(CPU_CFG_INT_DIS_MEAS_EN)))
  128. #define CPU_CFG_TS_TMR_EN DEF_ENABLED
  129. #else
  130. #define CPU_CFG_TS_TMR_EN DEF_DISABLED
  131. #endif
  132. /*
  133. *********************************************************************************************************
  134. * DEFINES
  135. *********************************************************************************************************
  136. */
  137. #define CPU_TIME_MEAS_NBR_MIN 1u
  138. #define CPU_TIME_MEAS_NBR_MAX 128u
  139. /*
  140. *********************************************************************************************************
  141. * DATA TYPES
  142. *********************************************************************************************************
  143. */
  144. /*
  145. *********************************************************************************************************
  146. * CPU ERROR CODES
  147. *********************************************************************************************************
  148. */
  149. typedef enum cpu_err {
  150. CPU_ERR_NONE = 0u,
  151. CPU_ERR_NULL_PTR = 10u,
  152. CPU_ERR_NAME_SIZE = 1000u,
  153. CPU_ERR_TS_FREQ_INVALID = 2000u
  154. } CPU_ERR;
  155. /*
  156. *********************************************************************************************************
  157. * CPU TIMESTAMP DATA TYPES
  158. *
  159. * Note(s) : (1) CPU timestamp timer data type defined to the binary-multiple of 8-bit octets as configured
  160. * by 'CPU_CFG_TS_TMR_SIZE' (see 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2').
  161. *********************************************************************************************************
  162. */
  163. typedef CPU_INT32U CPU_TS32;
  164. typedef CPU_INT64U CPU_TS64;
  165. typedef CPU_TS32 CPU_TS; /* Req'd for backwards-compatibility. */
  166. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED) /* CPU ts tmr defined to cfg'd word size (see Note #1). */
  167. #if (CPU_CFG_TS_TMR_SIZE == CPU_WORD_SIZE_08)
  168. typedef CPU_INT08U CPU_TS_TMR;
  169. #elif (CPU_CFG_TS_TMR_SIZE == CPU_WORD_SIZE_16)
  170. typedef CPU_INT16U CPU_TS_TMR;
  171. #elif (CPU_CFG_TS_TMR_SIZE == CPU_WORD_SIZE_64)
  172. typedef CPU_INT64U CPU_TS_TMR;
  173. #else /* CPU ts tmr dflt size = 32-bits. */
  174. typedef CPU_INT32U CPU_TS_TMR;
  175. #endif
  176. #endif
  177. /*
  178. *********************************************************************************************************
  179. * CPU TIMESTAMP TIMER FREQUENCY DATA TYPE
  180. *********************************************************************************************************
  181. */
  182. typedef CPU_INT32U CPU_TS_TMR_FREQ;
  183. /*
  184. *********************************************************************************************************
  185. * GLOBAL VARIABLES
  186. *********************************************************************************************************
  187. */
  188. #if (CPU_CFG_NAME_EN == DEF_ENABLED)
  189. CPU_CORE_EXT CPU_CHAR CPU_Name[CPU_CFG_NAME_SIZE]; /* CPU host name. */
  190. #endif
  191. #if ((CPU_CFG_TS_32_EN == DEF_ENABLED) && \
  192. (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_32))
  193. CPU_CORE_EXT CPU_TS32 CPU_TS_32_Accum; /* 32-bit accum'd ts (in ts tmr cnts). */
  194. CPU_CORE_EXT CPU_TS_TMR CPU_TS_32_TmrPrev; /* 32-bit ts prev tmr (in ts tmr cnts). */
  195. #endif
  196. #if ((CPU_CFG_TS_64_EN == DEF_ENABLED) && \
  197. (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_64))
  198. CPU_CORE_EXT CPU_TS64 CPU_TS_64_Accum; /* 64-bit accum'd ts (in ts tmr cnts). */
  199. CPU_CORE_EXT CPU_TS_TMR CPU_TS_64_TmrPrev; /* 64-bit ts prev tmr (in ts tmr cnts). */
  200. #endif
  201. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  202. CPU_CORE_EXT CPU_TS_TMR_FREQ CPU_TS_TmrFreq_Hz; /* CPU ts tmr freq (in Hz). */
  203. #endif
  204. #ifdef CPU_CFG_INT_DIS_MEAS_EN
  205. CPU_CORE_EXT CPU_INT16U CPU_IntDisMeasCtr; /* Nbr tot ints dis'd ctr. */
  206. CPU_CORE_EXT CPU_INT16U CPU_IntDisNestCtr; /* Nbr nested ints dis'd ctr. */
  207. /* Ints dis'd time (in ts tmr cnts) : ... */
  208. CPU_CORE_EXT CPU_TS_TMR CPU_IntDisMeasStart_cnts; /* ... start time. */
  209. CPU_CORE_EXT CPU_TS_TMR CPU_IntDisMeasStop_cnts; /* ... stop time. */
  210. CPU_CORE_EXT CPU_TS_TMR CPU_IntDisMeasOvrhd_cnts; /* ... time meas ovrhd. */
  211. CPU_CORE_EXT CPU_TS_TMR CPU_IntDisMeasMaxCur_cnts; /* ... resetable max time dis'd. */
  212. CPU_CORE_EXT CPU_TS_TMR CPU_IntDisMeasMax_cnts; /* ... non-resetable max time dis'd. */
  213. #endif
  214. /*
  215. *********************************************************************************************************
  216. * MACRO'S
  217. *********************************************************************************************************
  218. */
  219. /*
  220. *********************************************************************************************************
  221. * CPU_SW_EXCEPTION()
  222. *
  223. * Description : Trap unrecoverable software exception.
  224. *
  225. * Argument(s) : err_rtn_val Error type &/or value of the calling function to return (see Note #2b).
  226. *
  227. * Return(s) : none.
  228. *
  229. * Caller(s) : various.
  230. *
  231. * Note(s) : (1) CPU_SW_EXCEPTION() deadlocks the current code execution -- whether multi-tasked/
  232. * -processed/-threaded or single-threaded -- when the current code execution cannot
  233. * gracefully recover or report a fault or exception condition.
  234. *
  235. * Example CPU_SW_EXCEPTION() call :
  236. *
  237. * void Fnct (CPU_ERR *p_err)
  238. * {
  239. * :
  240. *
  241. * if (p_err == (CPU_ERR *)0) { If 'p_err' NULL, cannot return error ...
  242. * CPU_SW_EXCEPTION(;); ... so trap invalid argument exception.
  243. * }
  244. *
  245. * :
  246. * }
  247. *
  248. * See also 'cpu_core.c CPU_SW_Exception() Note #1'.
  249. *
  250. * (2) (a) CPU_SW_EXCEPTION() MAY be developer-implemented to output &/or handle any error or
  251. * exception conditions; but since CPU_SW_EXCEPTION() is intended to trap unrecoverable
  252. * software conditions, it is recommended that developer-implemented versions prevent
  253. * execution of any code following calls to CPU_SW_EXCEPTION() by deadlocking the code
  254. * (see Note #1).
  255. *
  256. * Example CPU_SW_EXCEPTION() :
  257. *
  258. * #define CPU_SW_EXCEPTION(err_rtn_val) do { \
  259. * Log(__FILE__, __LINE__); \
  260. * CPU_SW_Exception(); \
  261. * } while (0)
  262. *
  263. * (b) (1) However, if execution of code following calls to CPU_SW_EXCEPTION() is required
  264. * (e.g. for automated testing); it is recommended that the last statement in
  265. * developer-implemented versions be to return from the current function to prevent
  266. * possible software exception(s) in the current function from triggering CPU &/or
  267. * hardware exception(s).
  268. *
  269. * Example CPU_SW_EXCEPTION() :
  270. *
  271. * #define CPU_SW_EXCEPTION(err_rtn_val) do { \
  272. * Log(__FILE__, __LINE__); \
  273. * return err_rtn_val; \
  274. * } while (0)
  275. *
  276. * (A) Note that 'err_rtn_val' in the return statement MUST NOT be enclosed in
  277. * parentheses. This allows CPU_SW_EXCEPTION() to return from functions that
  278. * return 'void', i.e. NO return type or value (see also Note #2b2A).
  279. *
  280. * (2) In order for CPU_SW_EXCEPTION() to return from functions with various return
  281. * types/values, each caller function MUST pass an appropriate error return type
  282. * & value to CPU_SW_EXCEPTION().
  283. *
  284. * (A) Note that CPU_SW_EXCEPTION() MUST NOT be passed any return type or value
  285. * for functions that return 'void', i.e. NO return type or value; but SHOULD
  286. * instead be passed a single semicolon. This prevents possible compiler
  287. * warnings that CPU_SW_EXCEPTION() is passed too few arguments. However,
  288. * the compiler may warn that CPU_SW_EXCEPTION() does NOT prevent creating
  289. * null statements on lines with NO other code statements.
  290. *
  291. * Example CPU_SW_EXCEPTION() calls :
  292. *
  293. * void Fnct (CPU_ERR *p_err)
  294. * {
  295. * :
  296. *
  297. * if (p_err == (CPU_ERR *)0) {
  298. * CPU_SW_EXCEPTION(;); Exception macro returns NO value
  299. * } (see Note #2b2A)
  300. *
  301. * :
  302. * }
  303. *
  304. * CPU_BOOLEAN Fnct (CPU_ERR *p_err)
  305. * {
  306. * :
  307. *
  308. * if (p_err == (CPU_ERR *)0) {
  309. * CPU_SW_EXCEPTION(DEF_FAIL); Exception macro returns 'DEF_FAIL'
  310. * }
  311. *
  312. * :
  313. * }
  314. *
  315. * OBJ *Fnct (CPU_ERR *p_err)
  316. * {
  317. * :
  318. *
  319. * if (p_err == (CPU_ERR *)0) {
  320. * CPU_SW_EXCEPTION((OBJ *)0); Exception macro returns NULL 'OBJ *'
  321. * }
  322. *
  323. * :
  324. * }
  325. *
  326. *********************************************************************************************************
  327. */
  328. #ifndef CPU_SW_EXCEPTION /* See Note #2. */
  329. #define CPU_SW_EXCEPTION(err_rtn_val) do { \
  330. CPU_SW_Exception(); \
  331. } while (0)
  332. #endif
  333. /*
  334. *********************************************************************************************************
  335. * CPU_VAL_UNUSED()
  336. *
  337. * Description :
  338. *
  339. * Argument(s) : none.
  340. *
  341. * Return(s) : none.
  342. *
  343. * Caller(s) : #### various.
  344. *
  345. * Note(s) : none.
  346. *********************************************************************************************************
  347. */
  348. #define CPU_VAL_UNUSED(val) ((void)&(val));
  349. #define CPU_VAL_IGNORED(val) CPU_VAL_UNUSED(val)
  350. /*
  351. *********************************************************************************************************
  352. * CPU_TYPE_CREATE()
  353. *
  354. * Description : Creates a generic type value.
  355. *
  356. * Argument(s) : char_1 1st ASCII character to create generic type value.
  357. *
  358. * char_2 2nd ASCII character to create generic type value.
  359. *
  360. * char_3 3rd ASCII character to create generic type value.
  361. *
  362. * char_4 4th ASCII character to create generic type value.
  363. *
  364. * Return(s) : 32-bit generic type value.
  365. *
  366. * Caller(s) : various.
  367. *
  368. * Note(s) : (1) (a) Generic type values should be #define'd with large, non-trivial values to trap
  369. * & discard invalid/corrupted objects based on type value.
  370. *
  371. * In other words, by assigning large, non-trivial values to valid objects' type
  372. * fields; the likelihood that an object with an unassigned &/or corrupted type
  373. * field will contain a value is highly improbable & therefore the object itself
  374. * will be trapped as invalid.
  375. *
  376. * (b) (1) CPU_TYPE_CREATE() creates a 32-bit type value from four values.
  377. *
  378. * (2) Ideally, generic type values SHOULD be created from 'CPU_CHAR' characters to
  379. * represent ASCII string abbreviations of the specific object types. Memory
  380. * displays of object type values will display the specific object types with
  381. * their chosen ASCII names.
  382. *
  383. * Examples :
  384. *
  385. * #define FILE_TYPE CPU_TYPE_CREATE('F', 'I', 'L', 'E')
  386. * #define BUF_TYPE CPU_TYPE_CREATE('B', 'U', 'F', ' ')
  387. *********************************************************************************************************
  388. */
  389. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  390. #define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1)) << (3u * DEF_OCTET_NBR_BITS)) | \
  391. ((CPU_INT32U)((CPU_INT08U)(char_2)) << (2u * DEF_OCTET_NBR_BITS)) | \
  392. ((CPU_INT32U)((CPU_INT08U)(char_3)) << (1u * DEF_OCTET_NBR_BITS)) | \
  393. ((CPU_INT32U)((CPU_INT08U)(char_4))))
  394. #else
  395. #if ((CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_64) || \
  396. (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32))
  397. #define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1))) | \
  398. ((CPU_INT32U)((CPU_INT08U)(char_2)) << (1u * DEF_OCTET_NBR_BITS)) | \
  399. ((CPU_INT32U)((CPU_INT08U)(char_3)) << (2u * DEF_OCTET_NBR_BITS)) | \
  400. ((CPU_INT32U)((CPU_INT08U)(char_4)) << (3u * DEF_OCTET_NBR_BITS)))
  401. #elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
  402. #define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1)) << (2u * DEF_OCTET_NBR_BITS)) | \
  403. ((CPU_INT32U)((CPU_INT08U)(char_2)) << (3u * DEF_OCTET_NBR_BITS)) | \
  404. ((CPU_INT32U)((CPU_INT08U)(char_3))) | \
  405. ((CPU_INT32U)((CPU_INT08U)(char_4)) << (1u * DEF_OCTET_NBR_BITS)))
  406. #else /* Dflt CPU_WORD_SIZE_08. */
  407. #define CPU_TYPE_CREATE(char_1, char_2, char_3, char_4) (((CPU_INT32U)((CPU_INT08U)(char_1)) << (3u * DEF_OCTET_NBR_BITS)) | \
  408. ((CPU_INT32U)((CPU_INT08U)(char_2)) << (2u * DEF_OCTET_NBR_BITS)) | \
  409. ((CPU_INT32U)((CPU_INT08U)(char_3)) << (1u * DEF_OCTET_NBR_BITS)) | \
  410. ((CPU_INT32U)((CPU_INT08U)(char_4))))
  411. #endif
  412. #endif
  413. /*
  414. *********************************************************************************************************
  415. * FUNCTION PROTOTYPES
  416. *
  417. * Note(s) : (1) CPU interrupts disabled time measurement functions prototyped/defined only if
  418. * CPU_CFG_INT_DIS_MEAS_EN #define'd in 'cpu_cfg.h'.
  419. *
  420. * (2) (a) CPU_CntLeadZeros() defined in :
  421. *
  422. * (1) 'cpu_a.asm', if CPU_CFG_LEAD_ZEROS_ASM_PRESENT #define'd in 'cpu.h'/
  423. * 'cpu_cfg.h' to enable assembly-optimized function(s)
  424. *
  425. * (2) 'cpu_core.c', if CPU_CFG_LEAD_ZEROS_ASM_PRESENT NOT #define'd in 'cpu.h'/
  426. * 'cpu_cfg.h' to enable C-source-optimized function(s)
  427. *
  428. * (b) CPU_CntTrailZeros() defined in :
  429. *
  430. * (1) 'cpu_a.asm', if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT #define'd in 'cpu.h'/
  431. * 'cpu_cfg.h' to enable assembly-optimized function(s)
  432. *
  433. * (2) 'cpu_core.c', if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT NOT #define'd in 'cpu.h'/
  434. * 'cpu_cfg.h' to enable C-source-optimized function(s)
  435. *********************************************************************************************************
  436. */
  437. void CPU_Init (void);
  438. void CPU_SW_Exception (void);
  439. #if (CPU_CFG_NAME_EN == DEF_ENABLED) /* -------------- CPU NAME FNCTS -------------- */
  440. void CPU_NameClr (void);
  441. void CPU_NameGet ( CPU_CHAR *p_name,
  442. CPU_ERR *p_err);
  443. void CPU_NameSet (const CPU_CHAR *p_name,
  444. CPU_ERR *p_err);
  445. #endif
  446. /* --------------- CPU TS FNCTS --------------- */
  447. #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
  448. CPU_TS32 CPU_TS_Get32 (void);
  449. #endif
  450. #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
  451. CPU_TS64 CPU_TS_Get64 (void);
  452. #endif
  453. #if (CPU_CFG_TS_EN == DEF_ENABLED)
  454. void CPU_TS_Update (void);
  455. #endif
  456. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED) /* ------------- CPU TS TMR FNCTS ------------- */
  457. CPU_TS_TMR_FREQ CPU_TS_TmrFreqGet (CPU_ERR *p_err);
  458. void CPU_TS_TmrFreqSet (CPU_TS_TMR_FREQ freq_hz);
  459. #endif
  460. #ifdef CPU_CFG_INT_DIS_MEAS_EN /* -------- CPU INT DIS TIME MEAS FNCTS ------- */
  461. /* See Note #1. */
  462. CPU_TS_TMR CPU_IntDisMeasMaxCurReset(void);
  463. CPU_TS_TMR CPU_IntDisMeasMaxCurGet (void);
  464. CPU_TS_TMR CPU_IntDisMeasMaxGet (void);
  465. void CPU_IntDisMeasStart (void);
  466. void CPU_IntDisMeasStop (void);
  467. #endif
  468. /* ----------- CPU CNT ZEROS FNCTS ------------ */
  469. #ifdef CPU_CFG_LEAD_ZEROS_ASM_PRESENT
  470. #ifdef __cplusplus
  471. extern "C" {
  472. #endif
  473. #endif
  474. CPU_DATA CPU_CntLeadZeros (CPU_DATA val);
  475. #ifdef CPU_CFG_LEAD_ZEROS_ASM_PRESENT
  476. #ifdef __cplusplus
  477. }
  478. #endif
  479. #endif
  480. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_08)
  481. CPU_DATA CPU_CntLeadZeros08 (CPU_INT08U val);
  482. #endif
  483. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_16)
  484. CPU_DATA CPU_CntLeadZeros16 (CPU_INT16U val);
  485. #endif
  486. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_32)
  487. CPU_DATA CPU_CntLeadZeros32 (CPU_INT32U val);
  488. #endif
  489. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_64)
  490. CPU_DATA CPU_CntLeadZeros64 (CPU_INT64U val);
  491. #endif
  492. #ifdef CPU_CFG_LEAD_ZEROS_ASM_PRESENT
  493. #ifdef __cplusplus
  494. extern "C" {
  495. #endif
  496. #endif
  497. CPU_DATA CPU_CntTrailZeros (CPU_DATA val);
  498. #ifdef CPU_CFG_LEAD_ZEROS_ASM_PRESENT
  499. #ifdef __cplusplus
  500. }
  501. #endif
  502. #endif
  503. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_08)
  504. CPU_DATA CPU_CntTrailZeros08 (CPU_INT08U val);
  505. #endif
  506. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_16)
  507. CPU_DATA CPU_CntTrailZeros16 (CPU_INT16U val);
  508. #endif
  509. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_32)
  510. CPU_DATA CPU_CntTrailZeros32 (CPU_INT32U val);
  511. #endif
  512. #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_64)
  513. CPU_DATA CPU_CntTrailZeros64 (CPU_INT64U val);
  514. #endif
  515. CPU_INT08U CPU_PopCnt32 (CPU_INT32U value);
  516. /*
  517. *********************************************************************************************************
  518. * FUNCTION PROTOTYPES
  519. * DEFINED IN PRODUCT'S BSP
  520. *********************************************************************************************************
  521. */
  522. /*
  523. *********************************************************************************************************
  524. * CPU_TS_TmrInit()
  525. *
  526. * Description : Initialize & start CPU timestamp timer.
  527. *
  528. * Argument(s) : none.
  529. *
  530. * Return(s) : none.
  531. *
  532. * Caller(s) : CPU_TS_Init().
  533. *
  534. * This function is an INTERNAL CPU module function & MUST be implemented by application/
  535. * BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
  536. *
  537. * Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
  538. * if either of the following CPU features is enabled :
  539. *
  540. * (a) CPU timestamps
  541. * (b) CPU interrupts disabled time measurements
  542. *
  543. * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  544. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
  545. *
  546. * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
  547. * data type.
  548. *
  549. * (1) If timer has more bits, truncate timer values' higher-order bits greater
  550. * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
  551. *
  552. * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
  553. * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
  554. * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
  555. *
  556. * In other words, if timer size is not a binary-multiple of 8-bit octets
  557. * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
  558. * octet word size SHOULD be configured (e.g. to 16-bits). However, the
  559. * minimum supported word size for CPU timestamp timers is 8-bits.
  560. *
  561. * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
  562. * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
  563. *
  564. * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
  565. *
  566. * (c) When applicable, timer period SHOULD be less than the typical measured time
  567. * but MUST be less than the maximum measured time; otherwise, timer resolution
  568. * inadequate to measure desired times.
  569. *
  570. * See also 'CPU_TS_TmrRd() Note #2'.
  571. *********************************************************************************************************
  572. */
  573. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  574. void CPU_TS_TmrInit(void);
  575. #endif
  576. /*
  577. *********************************************************************************************************
  578. * CPU_TS_TmrRd()
  579. *
  580. * Description : Get current CPU timestamp timer count value.
  581. *
  582. * Argument(s) : none.
  583. *
  584. * Return(s) : Timestamp timer count (see Notes #2a & #2b).
  585. *
  586. * Caller(s) : CPU_TS_Init(),
  587. * CPU_TS_Get32(),
  588. * CPU_TS_Get64(),
  589. * CPU_IntDisMeasStart(),
  590. * CPU_IntDisMeasStop().
  591. *
  592. * This function is an INTERNAL CPU module function & MUST be implemented by application/
  593. * BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
  594. *
  595. * Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
  596. * if either of the following CPU features is enabled :
  597. *
  598. * (a) CPU timestamps
  599. * (b) CPU interrupts disabled time measurements
  600. *
  601. * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  602. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
  603. *
  604. * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
  605. * data type.
  606. *
  607. * (1) If timer has more bits, truncate timer values' higher-order bits greater
  608. * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
  609. *
  610. * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
  611. * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
  612. * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
  613. *
  614. * In other words, if timer size is not a binary-multiple of 8-bit octets
  615. * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
  616. * octet word size SHOULD be configured (e.g. to 16-bits). However, the
  617. * minimum supported word size for CPU timestamp timers is 8-bits.
  618. *
  619. * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
  620. * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
  621. *
  622. * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
  623. *
  624. * (1) If timer is a 'down' counter whose values decrease with each time count,
  625. * then the returned timer value MUST be ones-complemented.
  626. *
  627. * (c) (1) When applicable, the amount of time measured by CPU timestamps is
  628. * calculated by either of the following equations :
  629. *
  630. * (A) Time measured = Number timer counts * Timer period
  631. *
  632. * where
  633. *
  634. * Number timer counts Number of timer counts measured
  635. * Timer period Timer's period in some units of
  636. * (fractional) seconds
  637. * Time measured Amount of time measured, in same
  638. * units of (fractional) seconds
  639. * as the Timer period
  640. *
  641. * Number timer counts
  642. * (B) Time measured = ---------------------
  643. * Timer frequency
  644. *
  645. * where
  646. *
  647. * Number timer counts Number of timer counts measured
  648. * Timer frequency Timer's frequency in some units
  649. * of counts per second
  650. * Time measured Amount of time measured, in seconds
  651. *
  652. * (2) Timer period SHOULD be less than the typical measured time but MUST be less
  653. * than the maximum measured time; otherwise, timer resolution inadequate to
  654. * measure desired times.
  655. *********************************************************************************************************
  656. */
  657. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  658. CPU_TS_TMR CPU_TS_TmrRd(void);
  659. #endif
  660. /*
  661. *********************************************************************************************************
  662. * CPU_TSxx_to_uSec()
  663. *
  664. * Description : Convert a 32-/64-bit CPU timestamp from timer counts to microseconds.
  665. *
  666. * Argument(s) : ts_cnts CPU timestamp (in timestamp timer counts [see Note #2aA]).
  667. *
  668. * Return(s) : Converted CPU timestamp (in microseconds [see Note #2aD]).
  669. *
  670. * Caller(s) : Application.
  671. *
  672. * This function is an (optional) CPU module application programming interface (API)
  673. * function which MAY be implemented by application/BSP function(s) [see Note #1] &
  674. * MAY be called by application function(s).
  675. *
  676. * Note(s) : (1) CPU_TS32_to_uSec()/CPU_TS64_to_uSec() are application/BSP functions that MAY be
  677. * optionally defined by the developer when either of the following CPU features is
  678. * enabled :
  679. *
  680. * (a) CPU timestamps
  681. * (b) CPU interrupts disabled time measurements
  682. *
  683. * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  684. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
  685. *
  686. * (2) (a) The amount of time measured by CPU timestamps is calculated by either of
  687. * the following equations :
  688. *
  689. * 10^6 microseconds
  690. * (1) Time measured = Number timer counts * ------------------- * Timer period
  691. * 1 second
  692. *
  693. * Number timer counts 10^6 microseconds
  694. * (2) Time measured = --------------------- * -------------------
  695. * Timer frequency 1 second
  696. *
  697. * where
  698. *
  699. * (A) Number timer counts Number of timer counts measured
  700. * (B) Timer frequency Timer's frequency in some units
  701. * of counts per second
  702. * (C) Timer period Timer's period in some units of
  703. * (fractional) seconds
  704. * (D) Time measured Amount of time measured,
  705. * in microseconds
  706. *
  707. * (b) Timer period SHOULD be less than the typical measured time but MUST be less
  708. * than the maximum measured time; otherwise, timer resolution inadequate to
  709. * measure desired times.
  710. *
  711. * (c) Specific implementations may convert any number of CPU_TS32 or CPU_TS64 bits
  712. * -- up to 32 or 64, respectively -- into microseconds.
  713. *********************************************************************************************************
  714. */
  715. #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
  716. CPU_INT64U CPU_TS32_to_uSec(CPU_TS32 ts_cnts);
  717. #endif
  718. #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
  719. CPU_INT64U CPU_TS64_to_uSec(CPU_TS64 ts_cnts);
  720. #endif
  721. /*
  722. *********************************************************************************************************
  723. * CONFIGURATION ERRORS
  724. *********************************************************************************************************
  725. */
  726. #ifndef CPU_CFG_NAME_EN
  727. #error "CPU_CFG_NAME_EN not #define'd in 'cpu_cfg.h'"
  728. #error " [MUST be DEF_ENABLED ] "
  729. #error " [ || DEF_DISABLED] "
  730. #elif ((CPU_CFG_NAME_EN != DEF_ENABLED ) && \
  731. (CPU_CFG_NAME_EN != DEF_DISABLED))
  732. #error "CPU_CFG_NAME_EN illegally #define'd in 'cpu_cfg.h'"
  733. #error " [MUST be DEF_ENABLED ] "
  734. #error " [ || DEF_DISABLED] "
  735. #elif (CPU_CFG_NAME_EN == DEF_ENABLED)
  736. #ifndef CPU_CFG_NAME_SIZE
  737. #error "CPU_CFG_NAME_SIZE not #define'd in 'cpu_cfg.h'"
  738. #error " [MUST be >= 1] "
  739. #error " [ && <= 255] "
  740. #elif (DEF_CHK_VAL(CPU_CFG_NAME_SIZE, \
  741. 1, \
  742. DEF_INT_08U_MAX_VAL) != DEF_OK)
  743. #error "CPU_CFG_NAME_SIZE illegally #define'd in 'cpu_cfg.h'"
  744. #error " [MUST be >= 1] "
  745. #error " [ && <= 255] "
  746. #endif
  747. #endif
  748. #ifndef CPU_CFG_TS_32_EN
  749. #error "CPU_CFG_TS_32_EN not #define'd in 'cpu_cfg.h'"
  750. #error " [MUST be DEF_DISABLED] "
  751. #error " [ || DEF_ENABLED ] "
  752. #elif ((CPU_CFG_TS_32_EN != DEF_DISABLED) && \
  753. (CPU_CFG_TS_32_EN != DEF_ENABLED ))
  754. #error "CPU_CFG_TS_32_EN illegally #define'd in 'cpu_cfg.h'"
  755. #error " [MUST be DEF_DISABLED] "
  756. #error " [ || DEF_ENABLED ] "
  757. #endif
  758. #ifndef CPU_CFG_TS_64_EN
  759. #error "CPU_CFG_TS_64_EN not #define'd in 'cpu_cfg.h'"
  760. #error " [MUST be DEF_DISABLED] "
  761. #error " [ || DEF_ENABLED ] "
  762. #elif ((CPU_CFG_TS_64_EN != DEF_DISABLED) && \
  763. (CPU_CFG_TS_64_EN != DEF_ENABLED ))
  764. #error "CPU_CFG_TS_64_EN illegally #define'd in 'cpu_cfg.h'"
  765. #error " [MUST be DEF_DISABLED] "
  766. #error " [ || DEF_ENABLED ] "
  767. #endif
  768. /* Correctly configured in 'cpu_core.h'; DO NOT MODIFY. */
  769. #ifndef CPU_CFG_TS_EN
  770. #error "CPU_CFG_TS_EN not #define'd in 'cpu_core.h'"
  771. #error " [MUST be DEF_DISABLED] "
  772. #error " [ || DEF_ENABLED ] "
  773. #elif ((CPU_CFG_TS_EN != DEF_DISABLED) && \
  774. (CPU_CFG_TS_EN != DEF_ENABLED ))
  775. #error "CPU_CFG_TS_EN illegally #define'd in 'cpu_core.h'"
  776. #error " [MUST be DEF_DISABLED] "
  777. #error " [ || DEF_ENABLED ] "
  778. #endif
  779. /* Correctly configured in 'cpu_core.h'; DO NOT MODIFY. */
  780. #ifndef CPU_CFG_TS_TMR_EN
  781. #error "CPU_CFG_TS_TMR_EN not #define'd in 'cpu_core.h'"
  782. #error " [MUST be DEF_DISABLED] "
  783. #error " [ || DEF_ENABLED ] "
  784. #elif ((CPU_CFG_TS_TMR_EN != DEF_DISABLED) && \
  785. (CPU_CFG_TS_TMR_EN != DEF_ENABLED ))
  786. #error "CPU_CFG_TS_TMR_EN illegally #define'd in 'cpu_core.h'"
  787. #error " [MUST be DEF_DISABLED] "
  788. #error " [ || DEF_ENABLED ] "
  789. #elif (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  790. #ifndef CPU_CFG_TS_TMR_SIZE
  791. #error "CPU_CFG_TS_TMR_SIZE not #define'd in 'cpu_cfg.h' "
  792. #error " [MUST be CPU_WORD_SIZE_08 8-bit timer]"
  793. #error " [ || CPU_WORD_SIZE_16 16-bit timer]"
  794. #error " [ || CPU_WORD_SIZE_32 32-bit timer]"
  795. #error " [ || CPU_WORD_SIZE_64 64-bit timer]"
  796. #elif ((CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_08) && \
  797. (CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_16) && \
  798. (CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_32) && \
  799. (CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_64))
  800. #error "CPU_CFG_TS_TMR_SIZE illegally #define'd in 'cpu_cfg.h' "
  801. #error " [MUST be CPU_WORD_SIZE_08 8-bit timer]"
  802. #error " [ || CPU_WORD_SIZE_16 16-bit timer]"
  803. #error " [ || CPU_WORD_SIZE_32 32-bit timer]"
  804. #error " [ || CPU_WORD_SIZE_64 64-bit timer]"
  805. #endif
  806. #endif
  807. #ifndef CPU_CFG_INT_DIS_MEAS_EN
  808. #if 0 /* Optionally configured in 'cpu_cfg.h'; DO NOT MODIFY. */
  809. #error "CPU_CFG_INT_DIS_MEAS_EN not #define'd in 'cpu_cfg.h'"
  810. #endif
  811. #else
  812. #ifndef CPU_CFG_INT_DIS_MEAS_OVRHD_NBR
  813. #error "CPU_CFG_INT_DIS_MEAS_OVRHD_NBR not #define'd in 'cpu_cfg.h' "
  814. #error " [MUST be >= CPU_TIME_MEAS_NBR_MIN]"
  815. #error " [ || <= CPU_TIME_MEAS_NBR_MAX]"
  816. #elif (DEF_CHK_VAL(CPU_CFG_INT_DIS_MEAS_OVRHD_NBR, \
  817. CPU_TIME_MEAS_NBR_MIN, \
  818. CPU_TIME_MEAS_NBR_MAX) != DEF_OK)
  819. #error "CPU_CFG_INT_DIS_MEAS_OVRHD_NBR illegally #define'd in 'cpu_cfg.h' "
  820. #error " [MUST be >= CPU_TIME_MEAS_NBR_MIN]"
  821. #error " [ || <= CPU_TIME_MEAS_NBR_MAX]"
  822. #endif
  823. #endif
  824. #ifndef CPU_CFG_LEAD_ZEROS_ASM_PRESENT
  825. #if 0 /* Optionally configured in 'cpu_cfg.h'; DO NOT MODIFY. */
  826. #error "CPU_CFG_LEAD_ZEROS_ASM_PRESENT not #define'd in 'cpu.h'/'cpu_cfg.h'"
  827. #endif
  828. #endif
  829. #ifndef CPU_CFG_TRAIL_ZEROS_ASM_PRESENT
  830. #if 0 /* Optionally configured in 'cpu_cfg.h'; DO NOT MODIFY. */
  831. #error "CPU_CFG_TRAIL_ZEROS_ASM_PRESENT not #define'd in 'cpu.h'/'cpu_cfg.h'"
  832. #endif
  833. #endif
  834. /*
  835. *********************************************************************************************************
  836. * CPU PORT CONFIGURATION ERRORS
  837. *********************************************************************************************************
  838. */
  839. #ifndef CPU_CFG_ADDR_SIZE
  840. #error "CPU_CFG_ADDR_SIZE not #define'd in 'cpu.h'"
  841. #endif
  842. #ifndef CPU_CFG_DATA_SIZE
  843. #error "CPU_CFG_DATA_SIZE not #define'd in 'cpu.h'"
  844. #endif
  845. #ifndef CPU_CFG_DATA_SIZE_MAX
  846. #error "CPU_CFG_DATA_SIZE_MAX not #define'd in 'cpu.h'"
  847. #endif
  848. /*
  849. *********************************************************************************************************
  850. * LIBRARY CONFIGURATION ERRORS
  851. *********************************************************************************************************
  852. */
  853. /* See 'cpu_core.h Note #1a'. */
  854. #if (LIB_VERSION < 13500u)
  855. #error "LIB_VERSION [SHOULD be >= V1.35.00]"
  856. #endif
  857. /*
  858. *********************************************************************************************************
  859. * MODULE END
  860. *
  861. * Note(s) : (1) See 'cpu_core.h MODULE'.
  862. *********************************************************************************************************
  863. */
  864. #endif /* End of CPU core module include. */