cpu_core.h 44 KB

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