训练营PLSR题目
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.
 
 
 
 
 
 

1032 line
46 KiB

  1. /*
  2. *********************************************************************************************************
  3. * uC/CPU
  4. * CPU CONFIGURATION & PORT LAYER
  5. *
  6. * (c) Copyright 2004-2013; 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.01
  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)) << (0u * DEF_OCTET_NBR_BITS)))
  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)) << (0u * DEF_OCTET_NBR_BITS)) | \
  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)) << (0u * DEF_OCTET_NBR_BITS)) | \
  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)) << (0u * DEF_OCTET_NBR_BITS)))
  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. /*
  516. *********************************************************************************************************
  517. * FUNCTION PROTOTYPES
  518. * DEFINED IN PRODUCT'S BSP
  519. *********************************************************************************************************
  520. */
  521. /*
  522. *********************************************************************************************************
  523. * CPU_TS_TmrInit()
  524. *
  525. * Description : Initialize & start CPU timestamp timer.
  526. *
  527. * Argument(s) : none.
  528. *
  529. * Return(s) : none.
  530. *
  531. * Caller(s) : CPU_TS_Init().
  532. *
  533. * This function is an INTERNAL CPU module function & MUST be implemented by application/
  534. * BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
  535. *
  536. * Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
  537. * if either of the following CPU features is enabled :
  538. *
  539. * (a) CPU timestamps
  540. * (b) CPU interrupts disabled time measurements
  541. *
  542. * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  543. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
  544. *
  545. * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
  546. * data type.
  547. *
  548. * (1) If timer has more bits, truncate timer values' higher-order bits greater
  549. * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
  550. *
  551. * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
  552. * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
  553. * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
  554. *
  555. * In other words, if timer size is not a binary-multiple of 8-bit octets
  556. * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
  557. * octet word size SHOULD be configured (e.g. to 16-bits). However, the
  558. * minimum supported word size for CPU timestamp timers is 8-bits.
  559. *
  560. * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
  561. * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
  562. *
  563. * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
  564. *
  565. * (c) When applicable, timer period SHOULD be less than the typical measured time
  566. * but MUST be less than the maximum measured time; otherwise, timer resolution
  567. * inadequate to measure desired times.
  568. *
  569. * See also 'CPU_TS_TmrRd() Note #2'.
  570. *********************************************************************************************************
  571. */
  572. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  573. void CPU_TS_TmrInit(void);
  574. #endif
  575. /*
  576. *********************************************************************************************************
  577. * CPU_TS_TmrRd()
  578. *
  579. * Description : Get current CPU timestamp timer count value.
  580. *
  581. * Argument(s) : none.
  582. *
  583. * Return(s) : Timestamp timer count (see Notes #2a & #2b).
  584. *
  585. * Caller(s) : CPU_TS_Init(),
  586. * CPU_TS_Get32(),
  587. * CPU_TS_Get64(),
  588. * CPU_IntDisMeasStart(),
  589. * CPU_IntDisMeasStop().
  590. *
  591. * This function is an INTERNAL CPU module function & MUST be implemented by application/
  592. * BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
  593. *
  594. * Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
  595. * if either of the following CPU features is enabled :
  596. *
  597. * (a) CPU timestamps
  598. * (b) CPU interrupts disabled time measurements
  599. *
  600. * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  601. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
  602. *
  603. * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
  604. * data type.
  605. *
  606. * (1) If timer has more bits, truncate timer values' higher-order bits greater
  607. * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
  608. *
  609. * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
  610. * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
  611. * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
  612. *
  613. * In other words, if timer size is not a binary-multiple of 8-bit octets
  614. * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
  615. * octet word size SHOULD be configured (e.g. to 16-bits). However, the
  616. * minimum supported word size for CPU timestamp timers is 8-bits.
  617. *
  618. * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
  619. * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
  620. *
  621. * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
  622. *
  623. * (1) If timer is a 'down' counter whose values decrease with each time count,
  624. * then the returned timer value MUST be ones-complemented.
  625. *
  626. * (c) (1) When applicable, the amount of time measured by CPU timestamps is
  627. * calculated by either of the following equations :
  628. *
  629. * (A) Time measured = Number timer counts * Timer period
  630. *
  631. * where
  632. *
  633. * Number timer counts Number of timer counts measured
  634. * Timer period Timer's period in some units of
  635. * (fractional) seconds
  636. * Time measured Amount of time measured, in same
  637. * units of (fractional) seconds
  638. * as the Timer period
  639. *
  640. * Number timer counts
  641. * (B) Time measured = ---------------------
  642. * Timer frequency
  643. *
  644. * where
  645. *
  646. * Number timer counts Number of timer counts measured
  647. * Timer frequency Timer's frequency in some units
  648. * of counts per second
  649. * Time measured Amount of time measured, in seconds
  650. *
  651. * (2) Timer period SHOULD be less than the typical measured time but MUST be less
  652. * than the maximum measured time; otherwise, timer resolution inadequate to
  653. * measure desired times.
  654. *********************************************************************************************************
  655. */
  656. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  657. CPU_TS_TMR CPU_TS_TmrRd(void);
  658. #endif
  659. /*
  660. *********************************************************************************************************
  661. * CPU_TSxx_to_uSec()
  662. *
  663. * Description : Convert a 32-/64-bit CPU timestamp from timer counts to microseconds.
  664. *
  665. * Argument(s) : ts_cnts CPU timestamp (in timestamp timer counts [see Note #2aA]).
  666. *
  667. * Return(s) : Converted CPU timestamp (in microseconds [see Note #2aD]).
  668. *
  669. * Caller(s) : Application.
  670. *
  671. * This function is an (optional) CPU module application programming interface (API)
  672. * function which MAY be implemented by application/BSP function(s) [see Note #1] &
  673. * MAY be called by application function(s).
  674. *
  675. * Note(s) : (1) CPU_TS32_to_uSec()/CPU_TS64_to_uSec() are application/BSP functions that MAY be
  676. * optionally defined by the developer when either of the following CPU features is
  677. * enabled :
  678. *
  679. * (a) CPU timestamps
  680. * (b) CPU interrupts disabled time measurements
  681. *
  682. * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
  683. * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
  684. *
  685. * (2) (a) The amount of time measured by CPU timestamps is calculated by either of
  686. * the following equations :
  687. *
  688. * 10^6 microseconds
  689. * (1) Time measured = Number timer counts * ------------------- * Timer period
  690. * 1 second
  691. *
  692. * Number timer counts 10^6 microseconds
  693. * (2) Time measured = --------------------- * -------------------
  694. * Timer frequency 1 second
  695. *
  696. * where
  697. *
  698. * (A) Number timer counts Number of timer counts measured
  699. * (B) Timer frequency Timer's frequency in some units
  700. * of counts per second
  701. * (C) Timer period Timer's period in some units of
  702. * (fractional) seconds
  703. * (D) Time measured Amount of time measured,
  704. * in microseconds
  705. *
  706. * (b) Timer period SHOULD be less than the typical measured time but MUST be less
  707. * than the maximum measured time; otherwise, timer resolution inadequate to
  708. * measure desired times.
  709. *
  710. * (c) Specific implementations may convert any number of CPU_TS32 or CPU_TS64 bits
  711. * -- up to 32 or 64, respectively -- into microseconds.
  712. *********************************************************************************************************
  713. */
  714. #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
  715. CPU_INT64U CPU_TS32_to_uSec(CPU_TS32 ts_cnts);
  716. #endif
  717. #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
  718. CPU_INT64U CPU_TS64_to_uSec(CPU_TS64 ts_cnts);
  719. #endif
  720. /*
  721. *********************************************************************************************************
  722. * CONFIGURATION ERRORS
  723. *********************************************************************************************************
  724. */
  725. #ifndef CPU_CFG_NAME_EN
  726. #error "CPU_CFG_NAME_EN not #define'd in 'cpu_cfg.h'"
  727. #error " [MUST be DEF_ENABLED ] "
  728. #error " [ || DEF_DISABLED] "
  729. #elif ((CPU_CFG_NAME_EN != DEF_ENABLED ) && \
  730. (CPU_CFG_NAME_EN != DEF_DISABLED))
  731. #error "CPU_CFG_NAME_EN illegally #define'd in 'cpu_cfg.h'"
  732. #error " [MUST be DEF_ENABLED ] "
  733. #error " [ || DEF_DISABLED] "
  734. #elif (CPU_CFG_NAME_EN == DEF_ENABLED)
  735. #ifndef CPU_CFG_NAME_SIZE
  736. #error "CPU_CFG_NAME_SIZE not #define'd in 'cpu_cfg.h'"
  737. #error " [MUST be >= 1] "
  738. #error " [ && <= 255] "
  739. #elif (DEF_CHK_VAL(CPU_CFG_NAME_SIZE, \
  740. 1, \
  741. DEF_INT_08U_MAX_VAL) != DEF_OK)
  742. #error "CPU_CFG_NAME_SIZE illegally #define'd in 'cpu_cfg.h'"
  743. #error " [MUST be >= 1] "
  744. #error " [ && <= 255] "
  745. #endif
  746. #endif
  747. #ifndef CPU_CFG_TS_32_EN
  748. #error "CPU_CFG_TS_32_EN not #define'd in 'cpu_cfg.h'"
  749. #error " [MUST be DEF_DISABLED] "
  750. #error " [ || DEF_ENABLED ] "
  751. #elif ((CPU_CFG_TS_32_EN != DEF_DISABLED) && \
  752. (CPU_CFG_TS_32_EN != DEF_ENABLED ))
  753. #error "CPU_CFG_TS_32_EN illegally #define'd in 'cpu_cfg.h'"
  754. #error " [MUST be DEF_DISABLED] "
  755. #error " [ || DEF_ENABLED ] "
  756. #endif
  757. #ifndef CPU_CFG_TS_64_EN
  758. #error "CPU_CFG_TS_64_EN not #define'd in 'cpu_cfg.h'"
  759. #error " [MUST be DEF_DISABLED] "
  760. #error " [ || DEF_ENABLED ] "
  761. #elif ((CPU_CFG_TS_64_EN != DEF_DISABLED) && \
  762. (CPU_CFG_TS_64_EN != DEF_ENABLED ))
  763. #error "CPU_CFG_TS_64_EN illegally #define'd in 'cpu_cfg.h'"
  764. #error " [MUST be DEF_DISABLED] "
  765. #error " [ || DEF_ENABLED ] "
  766. #endif
  767. /* Correctly configured in 'cpu_core.h'; DO NOT MODIFY. */
  768. #ifndef CPU_CFG_TS_EN
  769. #error "CPU_CFG_TS_EN not #define'd in 'cpu_core.h'"
  770. #error " [MUST be DEF_DISABLED] "
  771. #error " [ || DEF_ENABLED ] "
  772. #elif ((CPU_CFG_TS_EN != DEF_DISABLED) && \
  773. (CPU_CFG_TS_EN != DEF_ENABLED ))
  774. #error "CPU_CFG_TS_EN illegally #define'd in 'cpu_core.h'"
  775. #error " [MUST be DEF_DISABLED] "
  776. #error " [ || DEF_ENABLED ] "
  777. #endif
  778. /* Correctly configured in 'cpu_core.h'; DO NOT MODIFY. */
  779. #ifndef CPU_CFG_TS_TMR_EN
  780. #error "CPU_CFG_TS_TMR_EN not #define'd in 'cpu_core.h'"
  781. #error " [MUST be DEF_DISABLED] "
  782. #error " [ || DEF_ENABLED ] "
  783. #elif ((CPU_CFG_TS_TMR_EN != DEF_DISABLED) && \
  784. (CPU_CFG_TS_TMR_EN != DEF_ENABLED ))
  785. #error "CPU_CFG_TS_TMR_EN illegally #define'd in 'cpu_core.h'"
  786. #error " [MUST be DEF_DISABLED] "
  787. #error " [ || DEF_ENABLED ] "
  788. #elif (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  789. #ifndef CPU_CFG_TS_TMR_SIZE
  790. #error "CPU_CFG_TS_TMR_SIZE not #define'd in 'cpu_cfg.h' "
  791. #error " [MUST be CPU_WORD_SIZE_08 8-bit timer]"
  792. #error " [ || CPU_WORD_SIZE_16 16-bit timer]"
  793. #error " [ || CPU_WORD_SIZE_32 32-bit timer]"
  794. #error " [ || CPU_WORD_SIZE_64 64-bit timer]"
  795. #elif ((CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_08) && \
  796. (CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_16) && \
  797. (CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_32) && \
  798. (CPU_CFG_TS_TMR_SIZE != CPU_WORD_SIZE_64))
  799. #error "CPU_CFG_TS_TMR_SIZE illegally #define'd in 'cpu_cfg.h' "
  800. #error " [MUST be CPU_WORD_SIZE_08 8-bit timer]"
  801. #error " [ || CPU_WORD_SIZE_16 16-bit timer]"
  802. #error " [ || CPU_WORD_SIZE_32 32-bit timer]"
  803. #error " [ || CPU_WORD_SIZE_64 64-bit timer]"
  804. #endif
  805. #endif
  806. #ifndef CPU_CFG_INT_DIS_MEAS_EN
  807. #if 0 /* Optionally configured in 'cpu_cfg.h'; DO NOT MODIFY. */
  808. #error "CPU_CFG_INT_DIS_MEAS_EN not #define'd in 'cpu_cfg.h'"
  809. #endif
  810. #else
  811. #ifndef CPU_CFG_INT_DIS_MEAS_OVRHD_NBR
  812. #error "CPU_CFG_INT_DIS_MEAS_OVRHD_NBR not #define'd in 'cpu_cfg.h' "
  813. #error " [MUST be >= CPU_TIME_MEAS_NBR_MIN]"
  814. #error " [ || <= CPU_TIME_MEAS_NBR_MAX]"
  815. #elif (DEF_CHK_VAL(CPU_CFG_INT_DIS_MEAS_OVRHD_NBR, \
  816. CPU_TIME_MEAS_NBR_MIN, \
  817. CPU_TIME_MEAS_NBR_MAX) != DEF_OK)
  818. #error "CPU_CFG_INT_DIS_MEAS_OVRHD_NBR illegally #define'd in 'cpu_cfg.h' "
  819. #error " [MUST be >= CPU_TIME_MEAS_NBR_MIN]"
  820. #error " [ || <= CPU_TIME_MEAS_NBR_MAX]"
  821. #endif
  822. #endif
  823. #ifndef CPU_CFG_LEAD_ZEROS_ASM_PRESENT
  824. #if 0 /* Optionally configured in 'cpu_cfg.h'; DO NOT MODIFY. */
  825. #error "CPU_CFG_LEAD_ZEROS_ASM_PRESENT not #define'd in 'cpu.h'/'cpu_cfg.h'"
  826. #endif
  827. #endif
  828. #ifndef CPU_CFG_TRAIL_ZEROS_ASM_PRESENT
  829. #if 0 /* Optionally configured in 'cpu_cfg.h'; DO NOT MODIFY. */
  830. #error "CPU_CFG_TRAIL_ZEROS_ASM_PRESENT not #define'd in 'cpu.h'/'cpu_cfg.h'"
  831. #endif
  832. #endif
  833. /*
  834. *********************************************************************************************************
  835. * CPU PORT CONFIGURATION ERRORS
  836. *********************************************************************************************************
  837. */
  838. #ifndef CPU_CFG_ADDR_SIZE
  839. #error "CPU_CFG_ADDR_SIZE not #define'd in 'cpu.h'"
  840. #endif
  841. #ifndef CPU_CFG_DATA_SIZE
  842. #error "CPU_CFG_DATA_SIZE not #define'd in 'cpu.h'"
  843. #endif
  844. #ifndef CPU_CFG_DATA_SIZE_MAX
  845. #error "CPU_CFG_DATA_SIZE_MAX not #define'd in 'cpu.h'"
  846. #endif
  847. /*
  848. *********************************************************************************************************
  849. * LIBRARY CONFIGURATION ERRORS
  850. *********************************************************************************************************
  851. */
  852. /* See 'cpu_core.h Note #1a'. */
  853. #if (LIB_VERSION < 13500u)
  854. #error "LIB_VERSION [SHOULD be >= V1.35.00]"
  855. #endif
  856. /*
  857. *********************************************************************************************************
  858. * MODULE END
  859. *
  860. * Note(s) : (1) See 'cpu_core.h MODULE'.
  861. *********************************************************************************************************
  862. */
  863. #endif /* End of CPU core module include. */