12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387 |
- /*
- *********************************************************************************************************
- * uC/CPU
- * CPU CONFIGURATION & PORT LAYER
- *
- * (c) Copyright 2004-2015; Micrium, Inc.; Weston, FL
- *
- * All rights reserved. Protected by international copyright laws.
- *
- * uC/CPU is provided in source form to registered licensees ONLY. It is
- * illegal to distribute this source code to any third party unless you receive
- * written permission by an authorized Micrium representative. Knowledge of
- * the source code may NOT be used to develop a similar product.
- *
- * Please help us continue to provide the Embedded community with the finest
- * software available. Your honesty is greatly appreciated.
- *
- * You can find our product's user manual, API reference, release notes and
- * more information at https://doc.micrium.com.
- * You can contact us at www.micrium.com.
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- *
- * CORE CPU MODULE
- *
- * Filename : cpu_core.c
- * Version : V1.30.02
- * Programmer(s) : SR
- * ITJ
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * INCLUDE FILES
- *********************************************************************************************************
- */
- #define MICRIUM_SOURCE
- #define CPU_CORE_MODULE
- #include "cpu_core.h"
- #if defined(CPU_CFG_CACHE_MGMT_EN)
- #if (CPU_CFG_CACHE_MGMT_EN == DEF_ENABLED)
- #include "cpu_cache.h"
- #endif
- #endif
- /*
- *********************************************************************************************************
- * LOCAL DEFINES
- *********************************************************************************************************
- */
- /* Pop cnt algorithm csts. */
- #define CRC_UTIL_POPCNT_MASK01010101_32 0x55555555u
- #define CRC_UTIL_POPCNT_MASK00110011_32 0x33333333u
- #define CRC_UTIL_POPCNT_MASK00001111_32 0x0F0F0F0Fu
- #define CRC_UTIL_POPCNT_POWERSOF256_32 0x01010101u
- /*
- *********************************************************************************************************
- * LOCAL CONSTANTS
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * LOCAL DATA TYPES
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * LOCAL TABLES
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * CPU COUNT LEAD ZEROs LOOKUP TABLE
- *
- * Note(s) : (1) Index into bit pattern table determines the number of leading zeros in an 8-bit value :
- *
- * b07 b06 b05 b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * 0 0 0 1 x x x x 3
- * 0 0 0 0 1 x x x 4
- * 0 0 0 0 0 1 x x 5
- * 0 0 0 0 0 0 1 x 6
- * 0 0 0 0 0 0 0 1 7
- * 0 0 0 0 0 0 0 0 8
- *********************************************************************************************************
- */
- #if (!(defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) || \
- (CPU_CFG_DATA_SIZE_MAX > CPU_CFG_DATA_SIZE))
- static const CPU_INT08U CPU_CntLeadZerosTbl[256] = { /* Data vals : */
- /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
- 8u, 7u, 6u, 6u, 5u, 5u, 5u, 5u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, /* 0x00 to 0x0F */
- 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, 3u, /* 0x10 to 0x1F */
- 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, /* 0x20 to 0x2F */
- 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, 2u, /* 0x30 to 0x3F */
- 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, /* 0x40 to 0x4F */
- 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, /* 0x50 to 0x5F */
- 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, /* 0x60 to 0x6F */
- 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, /* 0x70 to 0x7F */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, /* 0x80 to 0x8F */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, /* 0x90 to 0x9F */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, /* 0xA0 to 0xAF */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, /* 0xB0 to 0xBF */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, /* 0xC0 to 0xCF */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, /* 0xD0 to 0xDF */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, /* 0xE0 to 0xEF */
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u /* 0xF0 to 0xFF */
- };
- #endif
- /*
- *********************************************************************************************************
- * LOCAL GLOBAL VARIABLES
- *********************************************************************************************************
- */
- CPU_INT32U const CPU_EndiannessTest = 0x12345678LU; /* Variable to test CPU endianness. */
- /*
- *********************************************************************************************************
- * LOCAL FUNCTION PROTOTYPES
- *********************************************************************************************************
- */
- #if (CPU_CFG_NAME_EN == DEF_ENABLED) /* ---------------- CPU NAME FNCTS ---------------- */
- static void CPU_NameInit (void);
- #endif
- /* ----------------- CPU TS FNCTS ----------------- */
- #if ((CPU_CFG_TS_EN == DEF_ENABLED) || \
- (CPU_CFG_TS_TMR_EN == DEF_ENABLED))
- static void CPU_TS_Init (void);
- #endif
- #ifdef CPU_CFG_INT_DIS_MEAS_EN /* ---------- CPU INT DIS TIME MEAS FNCTS --------- */
- static void CPU_IntDisMeasInit (void);
- static CPU_TS_TMR CPU_IntDisMeasMaxCalc(CPU_TS_TMR time_tot_cnts);
- #endif
- /*
- *********************************************************************************************************
- * LOCAL CONFIGURATION ERRORS
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * CPU_Init()
- *
- * Description : (1) Initialize CPU module :
- *
- * (a) Initialize CPU timestamps
- * (b) Initialize CPU interrupts disabled time measurements
- * (c) Initialize CPU host name
- *
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : Your Product's Application.
- *
- * This function is a CPU initialization function & MAY be called by application/
- * initialization function(s).
- *
- * Note(s) : (2) CPU_Init() MUST be called ... :
- *
- * (a) ONLY ONCE from a product's application; ...
- * (b) BEFORE product's application calls any core CPU module function(s)
- *
- * (3) The following initialization functions MUST be sequenced as follows :
- *
- * (a) CPU_TS_Init() SHOULD precede ALL calls to other CPU timestamp functions
- *
- * (b) CPU_IntDisMeasInit() SHOULD precede ALL calls to CPU_CRITICAL_ENTER()/CPU_CRITICAL_EXIT()
- * & other CPU interrupts disabled time measurement functions
- *********************************************************************************************************
- */
- void CPU_Init (void)
- {
- /* --------------------- INIT TS ---------------------- */
- #if ((CPU_CFG_TS_EN == DEF_ENABLED) || \
- (CPU_CFG_TS_TMR_EN == DEF_ENABLED))
- CPU_TS_Init(); /* See Note #3a. */
- #endif
- /* -------------- INIT INT DIS TIME MEAS -------------- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- CPU_IntDisMeasInit(); /* See Note #3b. */
- #endif
- /* ------------------ INIT CPU NAME ------------------- */
- #if (CPU_CFG_NAME_EN == DEF_ENABLED)
- CPU_NameInit();
- #endif
- #if (CPU_CFG_CACHE_MGMT_EN == DEF_ENABLED)
- CPU_Cache_Init();
- #endif
- }
- /*
- *********************************************************************************************************
- * CPU_SW_Exception()
- *
- * Description : Trap unrecoverable software exception.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : various.
- *
- * Note(s) : (1) CPU_SW_Exception() deadlocks the current code execution -- whether multi-tasked/
- * -processed/-threaded or single-threaded -- when the current code execution cannot
- * gracefully recover or report a fault or exception condition.
- *
- * See also 'cpu_core.h CPU_SW_EXCEPTION() Note #1'.
- *********************************************************************************************************
- */
- void CPU_SW_Exception (void)
- {
- while (DEF_ON) {
- ;
- }
- }
- /*
- *********************************************************************************************************
- * CPU_NameClr()
- *
- * Description : Clear CPU Name.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_NameInit(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- #if (CPU_CFG_NAME_EN == DEF_ENABLED)
- void CPU_NameClr (void)
- {
- CPU_SR_ALLOC();
- CPU_CRITICAL_ENTER();
- Mem_Clr((void *)&CPU_Name[0],
- (CPU_SIZE_T) CPU_CFG_NAME_SIZE);
- CPU_CRITICAL_EXIT();
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_NameGet()
- *
- * Description : Get CPU host name.
- *
- * Argument(s) : p_name Pointer to an ASCII character array that will receive the return CPU host
- * name ASCII string from this function (see Note #1).
- *
- * p_err Pointer to variable that will receive the return error code from this function :
- *
- * CPU_ERR_NONE CPU host name successfully returned.
- * CPU_ERR_NULL_PTR Argument 'p_name' passed a NULL pointer.
- *
- * Return(s) : none.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY
- * be called by application function(s).
- *
- * Note(s) : (1) The size of the ASCII character array that will receive the return CPU host name
- * ASCII string :
- *
- * (a) MUST be greater than or equal to the current CPU host name's ASCII string
- * size including the terminating NULL character;
- * (b) SHOULD be greater than or equal to CPU_CFG_NAME_SIZE
- *********************************************************************************************************
- */
- #if (CPU_CFG_NAME_EN == DEF_ENABLED)
- void CPU_NameGet (CPU_CHAR *p_name,
- CPU_ERR *p_err)
- {
- CPU_SR_ALLOC();
- if (p_err == (CPU_ERR *)0) {
- CPU_SW_EXCEPTION(;);
- }
- if (p_name == (CPU_CHAR *)0) {
- *p_err = CPU_ERR_NULL_PTR;
- return;
- }
- CPU_CRITICAL_ENTER();
- (void)Str_Copy_N(p_name,
- &CPU_Name[0],
- CPU_CFG_NAME_SIZE);
- CPU_CRITICAL_EXIT();
- *p_err = CPU_ERR_NONE;
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_NameSet()
- *
- * Description : Set CPU host name.
- *
- * Argument(s) : p_name Pointer to CPU host name to set.
- *
- * p_err Pointer to variable that will receive the return error code from this function :
- *
- * CPU_ERR_NONE CPU host name successfully set.
- * CPU_ERR_NULL_PTR Argument 'p_name' passed a NULL pointer.
- * CPU_ERR_NAME_SIZE Invalid CPU host name size (see Note #1).
- *
- * Return(s) : none.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) 'p_name' ASCII string size, including the terminating NULL character, MUST be less
- * than or equal to CPU_CFG_NAME_SIZE.
- *********************************************************************************************************
- */
- #if (CPU_CFG_NAME_EN == DEF_ENABLED)
- void CPU_NameSet (const CPU_CHAR *p_name,
- CPU_ERR *p_err)
- {
- CPU_SIZE_T len;
- CPU_SR_ALLOC();
- if (p_err == (CPU_ERR *)0) {
- CPU_SW_EXCEPTION(;);
- }
- if (p_name == (const CPU_CHAR *)0) {
- *p_err = CPU_ERR_NULL_PTR;
- return;
- }
- len = Str_Len_N(p_name,
- CPU_CFG_NAME_SIZE);
- if (len < CPU_CFG_NAME_SIZE) { /* If cfg name len < max name size, ... */
- CPU_CRITICAL_ENTER();
- (void)Str_Copy_N(&CPU_Name[0], /* ... copy cfg name to CPU host name. */
- p_name,
- CPU_CFG_NAME_SIZE);
- CPU_CRITICAL_EXIT();
- *p_err = CPU_ERR_NONE;
- } else {
- *p_err = CPU_ERR_NAME_SIZE;
- }
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_TS_Get32()
- *
- * Description : Get current 32-bit CPU timestamp.
- *
- * Argument(s) : none.
- *
- * Return(s) : Current 32-bit CPU timestamp (in timestamp timer counts).
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY
- * be called by application function(s).
- *
- * Note(s) : (1) When applicable, the amount of time measured by CPU timestamps is calculated by
- * either of the following equations :
- *
- * (a) Time measured = Number timer counts * Timer period
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer period Timer's period in some units of
- * (fractional) seconds
- * Time measured Amount of time measured, in same
- * units of (fractional) seconds
- * as the Timer period
- *
- * Number timer counts
- * (b) Time measured = ---------------------
- * Timer frequency
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer frequency Timer's frequency in some units
- * of counts per second
- * Time measured Amount of time measured, in seconds
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c1'.
- *
- * (2) In case the CPU timestamp timer has lower precision than the 32-bit CPU timestamp;
- * its precision is extended via periodic updates by accumulating the deltas of the
- * timestamp timer count values into the higher-precision 32-bit CPU timestamp.
- *
- * (3) After initialization, 'CPU_TS_32_Accum' & 'CPU_TS_32_TmrPrev' MUST ALWAYS
- * be accessed AND updated exclusively with interrupts disabled -- but NOT
- * with critical sections.
- *********************************************************************************************************
- */
- #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
- CPU_TS32 CPU_TS_Get32 (void)
- {
- CPU_TS32 ts;
- #if (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_32)
- CPU_TS_TMR tmr_cur;
- CPU_TS_TMR tmr_delta;
- CPU_SR_ALLOC();
- #endif
- #if (CPU_CFG_TS_TMR_SIZE >= CPU_WORD_SIZE_32)
- ts = (CPU_TS32)CPU_TS_TmrRd(); /* Get cur ts tmr val (in 32-bit ts cnts). */
- #else
- CPU_INT_DIS();
- tmr_cur = (CPU_TS_TMR) CPU_TS_TmrRd(); /* Get cur ts tmr val (in ts tmr cnts). */
- tmr_delta = (CPU_TS_TMR)(tmr_cur - CPU_TS_32_TmrPrev); /* Calc delta ts tmr cnts. */
- CPU_TS_32_Accum += (CPU_TS32 ) tmr_delta; /* Inc ts by delta ts tmr cnts (see Note #2). */
- CPU_TS_32_TmrPrev = (CPU_TS_TMR) tmr_cur; /* Save cur ts tmr cnts for next update. */
- ts = (CPU_TS32 ) CPU_TS_32_Accum;
- CPU_INT_EN();
- #endif
- return (ts);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_TS_Get64()
- *
- * Description : Get current 64-bit CPU timestamp.
- *
- * Argument(s) : none.
- *
- * Return(s) : Current 64-bit CPU timestamp (in timestamp timer counts).
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY
- * be called by application function(s).
- *
- * Note(s) : (1) When applicable, the amount of time measured by CPU timestamps is calculated by
- * either of the following equations :
- *
- * (a) Time measured = Number timer counts * Timer period
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer period Timer's period in some units of
- * (fractional) seconds
- * Time measured Amount of time measured, in same
- * units of (fractional) seconds
- * as the Timer period
- *
- * Number timer counts
- * (b) Time measured = ---------------------
- * Timer frequency
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer frequency Timer's frequency in some units
- * of counts per second
- * Time measured Amount of time measured, in seconds
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c1'.
- *
- * (2) In case the CPU timestamp timer has lower precision than the 64-bit CPU timestamp;
- * its precision is extended via periodic updates by accumulating the deltas of the
- * timestamp timer count values into the higher-precision 64-bit CPU timestamp.
- *
- * (3) After initialization, 'CPU_TS_64_Accum' & 'CPU_TS_64_TmrPrev' MUST ALWAYS
- * be accessed AND updated exclusively with interrupts disabled -- but NOT
- * with critical sections.
- *********************************************************************************************************
- */
- #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
- CPU_TS64 CPU_TS_Get64 (void)
- {
- CPU_TS64 ts;
- #if (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_64)
- CPU_TS_TMR tmr_cur;
- CPU_TS_TMR tmr_delta;
- CPU_SR_ALLOC();
- #endif
- #if (CPU_CFG_TS_TMR_SIZE >= CPU_WORD_SIZE_64)
- ts = (CPU_TS64)CPU_TS_TmrRd(); /* Get cur ts tmr val (in 64-bit ts cnts). */
- #else
- CPU_INT_DIS();
- tmr_cur = (CPU_TS_TMR) CPU_TS_TmrRd(); /* Get cur ts tmr val (in ts tmr cnts). */
- tmr_delta = (CPU_TS_TMR)(tmr_cur - CPU_TS_64_TmrPrev); /* Calc delta ts tmr cnts. */
- CPU_TS_64_Accum += (CPU_TS64 ) tmr_delta; /* Inc ts by delta ts tmr cnts (see Note #2). */
- CPU_TS_64_TmrPrev = (CPU_TS_TMR) tmr_cur; /* Save cur ts tmr cnts for next update. */
- ts = (CPU_TS64 ) CPU_TS_64_Accum;
- CPU_INT_EN();
- #endif
- return (ts);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_TS_Update()
- *
- * Description : Update current CPU timestamp(s).
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : Application/BSP periodic time handler (see Note #1).
- *
- * This function is a CPU timestamp BSP function & SHOULD be called only by appropriate
- * application/BSP function(s).
- *
- * Note(s) : (1) (a) CPU timestamp(s) MUST be updated periodically by some application (or BSP) time
- * handler in order to (adequately) maintain CPU timestamp(s)' time.
- *
- * (b) CPU timestamp(s) MUST be updated more frequently than the CPU timestamp timer
- * overflows; otherwise, CPU timestamp(s) will lose time.
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c2'.
- *********************************************************************************************************
- */
- #if (CPU_CFG_TS_EN == DEF_ENABLED)
- void CPU_TS_Update (void)
- {
- #if ((CPU_CFG_TS_32_EN == DEF_ENABLED) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_32))
- (void)CPU_TS_Get32();
- #endif
- #if ((CPU_CFG_TS_64_EN == DEF_ENABLED) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_64))
- (void)CPU_TS_Get64();
- #endif
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_TS_TmrFreqGet()
- *
- * Description : Get CPU timestamp's timer frequency.
- *
- * Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
- *
- * CPU_ERR_NONE CPU timestamp's timer frequency successfully
- * returned.
- * CPU_ERR_TS_FREQ_INVALID CPU timestamp's timer frequency invalid &/or
- * NOT yet configured.
- *
- * Return(s) : CPU timestamp's timer frequency (in Hertz), if NO error(s).
- *
- * 0, otherwise.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
- CPU_TS_TMR_FREQ CPU_TS_TmrFreqGet (CPU_ERR *p_err)
- {
- CPU_TS_TMR_FREQ freq_hz;
- if (p_err == (CPU_ERR *)0) {
- CPU_SW_EXCEPTION(;);
- }
- freq_hz = CPU_TS_TmrFreq_Hz;
- *p_err = (freq_hz != 0u) ? CPU_ERR_NONE : CPU_ERR_TS_FREQ_INVALID;
- return (freq_hz);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_TS_TmrFreqSet()
- *
- * Description : Set CPU timestamp's timer frequency.
- *
- * Argument(s) : freq_hz Frequency (in Hertz) to set for CPU timestamp's timer.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_TS_TmrInit(),
- * Application/BSP initialization function(s).
- *
- * This function is a CPU module BSP function & SHOULD be called only by appropriate
- * application/BSP function(s) [see Note #1].
- *
- * Note(s) : (1) (a) (1) CPU timestamp timer frequency is NOT required for internal CPU timestamp
- * operations but may OPTIONALLY be configured by CPU_TS_TmrInit() or other
- * application/BSP initialization functions.
- *
- * (2) CPU timestamp timer frequency MAY be used with optional CPU_TSxx_to_uSec()
- * to convert CPU timestamps from timer counts into microseconds.
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2a'.
- *
- * (b) CPU timestamp timer period SHOULD be less than the typical measured time but MUST
- * be less than the maximum measured time; otherwise, timer resolution inadequate to
- * measure desired times.
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2b'.
- *********************************************************************************************************
- */
- #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
- void CPU_TS_TmrFreqSet (CPU_TS_TMR_FREQ freq_hz)
- {
- CPU_TS_TmrFreq_Hz = freq_hz;
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_IntDisMeasMaxCurReset()
- *
- * Description : Reset current maximum interrupts disabled time.
- *
- * Argument(s) : none.
- *
- * Return(s) : Maximum interrupts disabled time (in CPU timestamp timer counts) before resetting.
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c'
- * & 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2'.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function
- * & MAY be called by application function(s).
- *
- * Note(s) : (1) After initialization, 'CPU_IntDisMeasMaxCur_cnts' MUST ALWAYS be accessed
- * exclusively with interrupts disabled -- but NOT with critical sections.
- *********************************************************************************************************
- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- CPU_TS_TMR CPU_IntDisMeasMaxCurReset (void)
- {
- CPU_TS_TMR time_max_cnts;
- CPU_SR_ALLOC();
- time_max_cnts = CPU_IntDisMeasMaxCurGet();
- CPU_INT_DIS();
- CPU_IntDisMeasMaxCur_cnts = 0u;
- CPU_INT_EN();
- return (time_max_cnts);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_IntDisMeasMaxCurGet()
- *
- * Description : Get current maximum interrupts disabled time.
- *
- * Argument(s) : none.
- *
- * Return(s) : Current maximum interrupts disabled time (in CPU timestamp timer counts).
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c'
- * & 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2'.
- *
- * Caller(s) : CPU_IntDisMeasMaxCurReset(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function
- * & MAY be called by application function(s).
- *
- * Note(s) : (1) After initialization, 'CPU_IntDisMeasMaxCur_cnts' MUST ALWAYS be accessed
- * exclusively with interrupts disabled -- but NOT with critical sections.
- *********************************************************************************************************
- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- CPU_TS_TMR CPU_IntDisMeasMaxCurGet (void)
- {
- CPU_TS_TMR time_tot_cnts;
- CPU_TS_TMR time_max_cnts;
- CPU_SR_ALLOC();
- CPU_INT_DIS();
- time_tot_cnts = CPU_IntDisMeasMaxCur_cnts;
- CPU_INT_EN();
- time_max_cnts = CPU_IntDisMeasMaxCalc(time_tot_cnts);
- return (time_max_cnts);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_IntDisMeasMaxGet()
- *
- * Description : Get (non-resetable) maximum interrupts disabled time.
- *
- * Argument(s) : none.
- *
- * Return(s) : (Non-resetable) maximum interrupts disabled time (in CPU timestamp timer counts).
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c'
- * & 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2'.
- *
- * Caller(s) : CPU_IntDisMeasInit(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function
- * & MAY be called by application function(s).
- *
- * Note(s) : (1) After initialization, 'CPU_IntDisMeasMax_cnts' MUST ALWAYS be accessed
- * exclusively with interrupts disabled -- but NOT with critical sections.
- *********************************************************************************************************
- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- CPU_TS_TMR CPU_IntDisMeasMaxGet (void)
- {
- CPU_TS_TMR time_tot_cnts;
- CPU_TS_TMR time_max_cnts;
- CPU_SR_ALLOC();
- CPU_INT_DIS();
- time_tot_cnts = CPU_IntDisMeasMax_cnts;
- CPU_INT_EN();
- time_max_cnts = CPU_IntDisMeasMaxCalc(time_tot_cnts);
- return (time_max_cnts);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_IntDisMeasStart()
- *
- * Description : Start interrupts disabled time measurement.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_CRITICAL_ENTER().
- *
- * This function is an INTERNAL CPU module function & MUST NOT be called by application
- * function(s).
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- void CPU_IntDisMeasStart (void)
- {
- CPU_IntDisMeasCtr++;
- if (CPU_IntDisNestCtr == 0u) { /* If ints NOT yet dis'd, ... */
- CPU_IntDisMeasStart_cnts = CPU_TS_TmrRd(); /* ... get ints dis'd start time. */
- }
- CPU_IntDisNestCtr++;
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_IntDisMeasStop()
- *
- * Description : Stop interrupts disabled time measurement.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_CRITICAL_EXIT().
- *
- * This function is an INTERNAL CPU module function & MUST NOT be called by application
- * function(s).
- *
- * Note(s) : (1) (a) The total amount of time interrupts are disabled by system &/or application code
- * during critical sections is calculated by the following equations :
- *
- * (1) When interrupts disabled time measurements are disabled :
- *
- *
- * | CRITICAL | | CRITICAL |
- * |<- SECTION ->| |<- SECTION ->|
- * | ENTER | | EXIT |
- *
- * Disable Enable
- * Interrupts Interrupts
- *
- * || || || ||
- * || || || ||
- * || | ||<------------------------->|| | ||
- * || |<->|| | ||<----->| ||
- * || | | || | || | | ||
- * | | | | |
- * interrupts time interrupts
- * disabled interrupts |enabled
- * | disabled |
- * | (via application) |
- * time time
- * interrupts interrupts
- * disabled ovrhd enabled ovrhd
- *
- *
- * (A) time = [ time - time ] - time
- * interrupts [ interrupts interrupts ] total
- * disabled [ enabled disabled ] ovrhd
- * (via application)
- *
- *
- * (B) time = time + time
- * total interrupts interrupts
- * ovrhd enabled ovrhd disabled ovrhd
- *
- *
- * where
- *
- * time time interrupts are disabled between
- * interrupts first critical section enter &
- * disabled last critical section exit (i.e.
- * (via application) minus total overhead time)
- *
- * time time when interrupts are disabled
- * interrupts
- * disabled
- *
- * time time when interrupts are enabled
- * interrupts
- * enabled
- *
- *
- * time total overhead time to disable/enable
- * total interrupts during critical section
- * ovrhd enter & exit
- *
- * time total overhead time to disable interrupts
- * interrupts during critical section enter
- * disabled ovrhd
- *
- * time total overhead time to enable interrupts
- * interrupts during critical section exit
- * enabled ovrhd
- *
- *
- * (2) When interrupts disabled time measurements are enabled :
- *
- *
- * | | | |
- * |<----- CRITICAL SECTION ENTER ----->| |<------- CRITICAL SECTION EXIT ------->|
- * | | | |
- *
- * Time Time
- * Disable Measurement Measurement Enable
- * Interrupts Start Stop Interrupts
- *
- * || | || || | ||
- * || | || || | ||
- * || | | ||<------------------------->|| | | ||
- * || | | |<----------->|| | ||<------------->| | | ||
- * || | | | | || | || | | | | ||
- * | | | | | | |
- * interrupts get | time | get interrupts
- * disabled start time | interrupts | stop time enabled
- * meas | disabled | meas
- * time (via application) time
- * start meas stop meas
- * ovrhd ovrhd
- *
- *
- * (A) time = [ time - time ] - time
- * interrupts [ stop start ] total meas
- * disabled [ meas meas ] ovrhd
- * (via application)
- *
- *
- * (B) time = time + time
- * total meas start meas stop meas
- * ovrhd ovrhd ovrhd
- *
- *
- * where
- *
- * time time interrupts are disabled between first
- * interrupts critical section enter & last critical
- * disabled section exit (i.e. minus measurement
- * (via application) overhead time; however, this does NOT
- * include any overhead time to disable
- * or enable interrupts during critical
- * section enter & exit)
- *
- * time time of disable interrupts start time
- * start measurement (in timer counts)
- * meas
- *
- * time time of disable interrupts stop time
- * stop measurement (in timer counts)
- * meas
- *
- *
- * time total overhead time to start/stop disabled
- * total meas interrupts time measurements (in timer
- * ovrhd counts)
- *
- * time total overhead time after getting start
- * start meas time until end of start measurement
- * ovrhd function (in timer counts)
- *
- * time total overhead time from beginning of stop
- * stop meas measurement function until after getting
- * ovrhd stop time (in timer counts)
- *
- *
- * (b) (1) (A) In order to correctly handle unsigned subtraction overflows of start times
- * from stop times, CPU timestamp timer count values MUST be returned via
- * word-size-configurable 'CPU_TS_TMR' data type.
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2a'.
- *
- * (B) Since unsigned subtraction of start times from stop times assumes increasing
- * values, timestamp timer count values MUST increase with each time count.
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2b'.
- *
- * (2) (A) To expedite & reduce interrupts disabled time measurement overhead; only the
- * subtraction of start times from stop times is performed.
- *
- * (B) The final calculations to subtract the interrupts disabled time measurement
- * overhead is performed asynchronously in appropriate API functions.
- *
- * See also 'CPU_IntDisMeasMaxCalc() Note #1b'.
- *********************************************************************************************************
- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- void CPU_IntDisMeasStop (void)
- {
- CPU_TS_TMR time_ints_disd_cnts;
- CPU_IntDisNestCtr--;
- if (CPU_IntDisNestCtr == 0u) { /* If ints NO longer dis'd, ... */
- CPU_IntDisMeasStop_cnts = CPU_TS_TmrRd(); /* ... get ints dis'd stop time & ... */
- /* ... calc ints dis'd tot time (see Note #1b2A). */
- time_ints_disd_cnts = CPU_IntDisMeasStop_cnts -
- CPU_IntDisMeasStart_cnts;
- /* Calc max ints dis'd times. */
- if (CPU_IntDisMeasMaxCur_cnts < time_ints_disd_cnts) {
- CPU_IntDisMeasMaxCur_cnts = time_ints_disd_cnts;
- }
- if (CPU_IntDisMeasMax_cnts < time_ints_disd_cnts) {
- CPU_IntDisMeasMax_cnts = time_ints_disd_cnts;
- }
- }
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntLeadZeros()
- *
- * Description : Count the number of contiguous, most-significant, leading zero bits in a data value.
- *
- * Argument(s) : val Data value to count leading zero bits.
- *
- * Return(s) : Number of contiguous, most-significant, leading zero bits in 'val', if NO error(s).
- *
- * DEF_INT_CPU_U_MAX_VAL, otherwise.
- *
- * Caller(s) : CPU_CntTrailZeros(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY
- * be called by application function(s).
- *
- * Note(s) : (1) (a) Supports the following data value sizes :
- *
- * (1) 8-bits
- * (2) 16-bits
- * (3) 32-bits
- * (4) 64-bits
- *
- * See also 'cpu_def.h CPU WORD CONFIGURATION Note #1'.
- *
- * (b) (1) For 8-bit values :
- *
- * b07 b06 b05 b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * 0 0 0 1 x x x x 3
- * 0 0 0 0 1 x x x 4
- * 0 0 0 0 0 1 x x 5
- * 0 0 0 0 0 0 1 x 6
- * 0 0 0 0 0 0 0 1 7
- * 0 0 0 0 0 0 0 0 8
- *
- *
- * (2) For 16-bit values :
- *
- * b15 b14 b13 ... b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * : : : : : : : : :
- * : : : : : : : : :
- * 0 0 0 1 x x x x 11
- * 0 0 0 0 1 x x x 12
- * 0 0 0 0 0 1 x x 13
- * 0 0 0 0 0 0 1 x 14
- * 0 0 0 0 0 0 0 1 15
- * 0 0 0 0 0 0 0 0 16
- *
- * (3) For 32-bit values :
- *
- * b31 b30 b29 ... b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * : : : : : : : : :
- * : : : : : : : : :
- * 0 0 0 1 x x x x 27
- * 0 0 0 0 1 x x x 28
- * 0 0 0 0 0 1 x x 29
- * 0 0 0 0 0 0 1 x 30
- * 0 0 0 0 0 0 0 1 31
- * 0 0 0 0 0 0 0 0 32
- *
- *
- * (4) For 64-bit values :
- *
- * b63 b62 b61 ... b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * : : : : : : : : :
- * : : : : : : : : :
- * 0 0 0 1 x x x x 59
- * 0 0 0 0 1 x x x 60
- * 0 0 0 0 0 1 x x 61
- * 0 0 0 0 0 0 1 x 62
- * 0 0 0 0 0 0 0 1 63
- * 0 0 0 0 0 0 0 0 64
- *
- *
- * See also 'CPU COUNT LEAD ZEROs LOOKUP TABLE Note #1'.
- *********************************************************************************************************
- */
- #ifndef CPU_CFG_LEAD_ZEROS_ASM_PRESENT
- CPU_DATA CPU_CntLeadZeros (CPU_DATA val)
- {
- CPU_DATA nbr_lead_zeros;
- #if (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_08)
- nbr_lead_zeros = CPU_CntLeadZeros08((CPU_INT08U)val);
- #elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
- nbr_lead_zeros = CPU_CntLeadZeros16((CPU_INT16U)val);
- #elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32)
- nbr_lead_zeros = CPU_CntLeadZeros32((CPU_INT32U)val);
- #elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_64)
- nbr_lead_zeros = CPU_CntLeadZeros64((CPU_INT64U)val);
- #else /* See Note #1a. */
- nbr_lead_zeros = DEF_INT_CPU_U_MAX_VAL;
- #endif
- return (nbr_lead_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntLeadZeros08()
- *
- * Description : Count the number of contiguous, most-significant, leading zero bits in an 8-bit data value.
- *
- * Argument(s) : val Data value to count leading zero bits.
- *
- * Return(s) : Number of contiguous, most-significant, leading zero bits in 'val'.
- *
- * Caller(s) : CPU_CntLeadZeros(),
- * CPU_CntTrailZeros08(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 8-bit values :
- *
- * b07 b06 b05 b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * 0 0 0 1 x x x x 3
- * 0 0 0 0 1 x x x 4
- * 0 0 0 0 0 1 x x 5
- * 0 0 0 0 0 0 1 x 6
- * 0 0 0 0 0 0 0 1 7
- * 0 0 0 0 0 0 0 0 8
- *
- *
- * See also 'CPU COUNT LEAD ZEROs LOOKUP TABLE Note #1'.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_08)
- CPU_DATA CPU_CntLeadZeros08 (CPU_INT08U val)
- {
- #if (!((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_08)))
- CPU_DATA ix;
- #endif
- CPU_DATA nbr_lead_zeros;
- /* ---------- ASM-OPTIMIZED ----------- */
- #if ((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_08))
- nbr_lead_zeros = CPU_CntLeadZeros((CPU_DATA)val);
- nbr_lead_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_08) * DEF_OCTET_NBR_BITS;
- #else /* ----------- C-OPTIMIZED ------------ */
- /* Chk bits [07:00] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)(val); /* .. lookup tbl ix = 'val' >> 0 bits */
- nbr_lead_zeros = (CPU_DATA)(CPU_CntLeadZerosTbl[ix]); /* .. plus nbr msb lead zeros = 0 bits.*/
- #endif
- return (nbr_lead_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntLeadZeros16()
- *
- * Description : Count the number of contiguous, most-significant, leading zero bits in a 16-bit data value.
- *
- * Argument(s) : val Data value to count leading zero bits.
- *
- * Return(s) : Number of contiguous, most-significant, leading zero bits in 'val'.
- *
- * Caller(s) : CPU_CntLeadZeros(),
- * CPU_CntTrailZeros16(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 16-bit values :
- *
- * b15 b14 b13 ... b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * : : : : : : : : :
- * : : : : : : : : :
- * 0 0 0 1 x x x x 11
- * 0 0 0 0 1 x x x 12
- * 0 0 0 0 0 1 x x 13
- * 0 0 0 0 0 0 1 x 14
- * 0 0 0 0 0 0 0 1 15
- * 0 0 0 0 0 0 0 0 16
- *
- *
- * See also 'CPU COUNT LEAD ZEROs LOOKUP TABLE Note #1'.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_16)
- CPU_DATA CPU_CntLeadZeros16 (CPU_INT16U val)
- {
- #if (!((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_16)))
- CPU_DATA ix;
- #endif
- CPU_DATA nbr_lead_zeros;
- /* ---------- ASM-OPTIMIZED ----------- */
- #if ((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_16))
- nbr_lead_zeros = CPU_CntLeadZeros((CPU_DATA)val);
- nbr_lead_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_16) * DEF_OCTET_NBR_BITS;
- #else /* ----------- C-OPTIMIZED ------------ */
- if (val > 0x00FFu) { /* Chk bits [15:08] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_DATA)val >> 8u); /* .. lookup tbl ix = 'val' >> 8 bits */
- nbr_lead_zeros = (CPU_DATA)(CPU_CntLeadZerosTbl[ix]); /* .. plus nbr msb lead zeros = 0 bits.*/
- } else { /* Chk bits [07:00] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)(val); /* .. lookup tbl ix = 'val' >> 0 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_DATA)CPU_CntLeadZerosTbl[ix] + 8u); /* .. plus nbr msb lead zeros = 8 bits.*/
- }
- #endif
- return (nbr_lead_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntLeadZeros32()
- *
- * Description : Count the number of contiguous, most-significant, leading zero bits in a 32-bit data value.
- *
- * Argument(s) : val Data value to count leading zero bits.
- *
- * Return(s) : Number of contiguous, most-significant, leading zero bits in 'val'.
- *
- * Caller(s) : CPU_CntLeadZeros(),
- * CPU_CntTrailZeros32(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 32-bit values :
- *
- * b31 b30 b29 ... b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * : : : : : : : : :
- * : : : : : : : : :
- * 0 0 0 1 x x x x 27
- * 0 0 0 0 1 x x x 28
- * 0 0 0 0 0 1 x x 29
- * 0 0 0 0 0 0 1 x 30
- * 0 0 0 0 0 0 0 1 31
- * 0 0 0 0 0 0 0 0 32
- *
- *
- * See also 'CPU COUNT LEAD ZEROs LOOKUP TABLE Note #1'.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_32)
- CPU_DATA CPU_CntLeadZeros32 (CPU_INT32U val)
- {
- #if (!((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_32)))
- CPU_DATA ix;
- #endif
- CPU_DATA nbr_lead_zeros;
- /* ---------- ASM-OPTIMIZED ----------- */
- #if ((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_32))
- nbr_lead_zeros = CPU_CntLeadZeros((CPU_DATA)val);
- nbr_lead_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_32) * DEF_OCTET_NBR_BITS;
- #else /* ----------- C-OPTIMIZED ------------ */
- if (val > 0x0000FFFFu) {
- if (val > 0x00FFFFFFu) { /* Chk bits [31:24] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_DATA)(val >> 24u)); /* .. lookup tbl ix = 'val' >> 24 bits */
- nbr_lead_zeros = (CPU_DATA)(CPU_CntLeadZerosTbl[ix]); /* .. plus nbr msb lead zeros = 0 bits.*/
- } else { /* Chk bits [23:16] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_DATA)(val >> 16u)); /* .. lookup tbl ix = 'val' >> 16 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_DATA)CPU_CntLeadZerosTbl[ix] + 8u);/* .. plus nbr msb lead zeros = 8 bits.*/
- }
- } else {
- if (val > 0x000000FFu) { /* Chk bits [15:08] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_DATA)(val >> 8u)); /* .. lookup tbl ix = 'val' >> 8 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_DATA)CPU_CntLeadZerosTbl[ix] + 16u);/* .. plus nbr msb lead zeros = 16 bits.*/
- } else { /* Chk bits [07:00] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_DATA)(val >> 0u)); /* .. lookup tbl ix = 'val' >> 0 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_DATA)CPU_CntLeadZerosTbl[ix] + 24u);/* .. plus nbr msb lead zeros = 24 bits.*/
- }
- }
- #endif
- return (nbr_lead_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntLeadZeros64()
- *
- * Description : Count the number of contiguous, most-significant, leading zero bits in a 64-bit data value.
- *
- * Argument(s) : val Data value to count leading zero bits.
- *
- * Return(s) : Number of contiguous, most-significant, leading zero bits in 'val'.
- *
- * Caller(s) : CPU_CntLeadZeros(),
- * CPU_CntTrailZeros64(),
- * Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 64-bit values :
- *
- * b63 b62 b61 ... b04 b03 b02 b01 b00 # Leading Zeros
- * --- --- --- --- --- --- --- --- ---------------
- * 1 x x x x x x x 0
- * 0 1 x x x x x x 1
- * 0 0 1 x x x x x 2
- * : : : : : : : : :
- * : : : : : : : : :
- * 0 0 0 1 x x x x 59
- * 0 0 0 0 1 x x x 60
- * 0 0 0 0 0 1 x x 61
- * 0 0 0 0 0 0 1 x 62
- * 0 0 0 0 0 0 0 1 63
- * 0 0 0 0 0 0 0 0 64
- *
- *
- * See also 'CPU COUNT LEAD ZEROs LOOKUP TABLE Note #1'.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_64)
- CPU_DATA CPU_CntLeadZeros64 (CPU_INT64U val)
- {
- #if (!((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_64)))
- CPU_DATA ix;
- #endif
- CPU_DATA nbr_lead_zeros;
- /* ---------- ASM-OPTIMIZED ----------- */
- #if ((defined(CPU_CFG_LEAD_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_64))
- nbr_lead_zeros = CPU_CntLeadZeros((CPU_DATA)val);
- nbr_lead_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_64) * DEF_OCTET_NBR_BITS;
- #else /* ----------- C-OPTIMIZED ------------ */
- if (val > 0x00000000FFFFFFFFu) {
- if (val > 0x0000FFFFFFFFFFFFu) {
- if (val > 0x00FFFFFFFFFFFFFFu) { /* Chk bits [63:56] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_INT64U)val >> 56u); /* .. lookup tbl ix = 'val' >> 56 bits */
- nbr_lead_zeros = (CPU_DATA)(CPU_CntLeadZerosTbl[ix]); /* .. plus nbr msb lead zeros = 0 bits.*/
- } else { /* Chk bits [55:48] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_INT64U)val >> 48u); /* .. lookup tbl ix = 'val' >> 48 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_INT64U)CPU_CntLeadZerosTbl[ix] + 8u);/* .. plus nbr msb lead zeros = 8 bits.*/
- }
- } else {
- if (val > 0x000000FFFFFFFFFFu) { /* Chk bits [47:40] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_INT64U)val >> 40u); /* .. lookup tbl ix = 'val' >> 40 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_INT64U)CPU_CntLeadZerosTbl[ix] + 16u);/* .. plus nbr msb lead zeros = 16 bits.*/
- } else { /* Chk bits [39:32] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_INT64U)val >> 32u); /* .. lookup tbl ix = 'val' >> 32 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_INT64U)CPU_CntLeadZerosTbl[ix] + 24u);/* .. plus nbr msb lead zeros = 24 bits.*/
- }
- }
- } else {
- if (val > 0x000000000000FFFFu) {
- if (val > 0x0000000000FFFFFFu) { /* Chk bits [31:24] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_INT64U)val >> 24u); /* .. lookup tbl ix = 'val' >> 24 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_INT64U)CPU_CntLeadZerosTbl[ix] + 32u);/* .. plus nbr msb lead zeros = 32 bits.*/
- } else { /* Chk bits [23:16] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_INT64U)val >> 16u); /* .. lookup tbl ix = 'val' >> 16 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_INT64U)CPU_CntLeadZerosTbl[ix] + 40u);/* .. plus nbr msb lead zeros = 40 bits.*/
- }
- } else {
- if (val > 0x00000000000000FFu) { /* Chk bits [15:08] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)((CPU_INT64U)val >> 8u); /* .. lookup tbl ix = 'val' >> 8 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_INT64U)CPU_CntLeadZerosTbl[ix] + 48u);/* .. plus nbr msb lead zeros = 48 bits.*/
- } else { /* Chk bits [07:00] : */
- /* .. Nbr lead zeros = .. */
- ix = (CPU_DATA)(val); /* .. lookup tbl ix = 'val' >> 0 bits */
- nbr_lead_zeros = (CPU_DATA)((CPU_INT64U)CPU_CntLeadZerosTbl[ix] + 56u);/* .. plus nbr msb lead zeros = 56 bits.*/
- }
- }
- }
- #endif
- return (nbr_lead_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntTrailZeros()
- *
- * Description : Count the number of contiguous, least-significant, trailing zero bits in a data value.
- *
- * Argument(s) : val Data value to count trailing zero bits.
- *
- * Return(s) : Number of contiguous, least-significant, trailing zero bits in 'val'.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY
- * be called by application function(s).
- *
- * Note(s) : (1) (a) Supports the following data value sizes :
- *
- * (1) 8-bits
- * (2) 16-bits
- * (3) 32-bits
- * (4) 64-bits
- *
- * See also 'cpu_def.h CPU WORD CONFIGURATION Note #1'.
- *
- * (b) (1) For 8-bit values :
- *
- * b07 b06 b05 b04 b03 b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * x x x x 1 0 0 0 3
- * x x x 1 0 0 0 0 4
- * x x 1 0 0 0 0 0 5
- * x 1 0 0 0 0 0 0 6
- * 1 0 0 0 0 0 0 0 7
- * 0 0 0 0 0 0 0 0 8
- *
- *
- * (2) For 16-bit values :
- *
- * b15 b14 b13 b12 b11 ... b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * : : : : : : : : :
- * : : : : : : : : :
- * x x x x 1 0 0 0 11
- * x x x 1 0 0 0 0 12
- * x x 1 0 0 0 0 0 13
- * x 1 0 0 0 0 0 0 14
- * 1 0 0 0 0 0 0 0 15
- * 0 0 0 0 0 0 0 0 16
- *
- *
- * (3) For 32-bit values :
- *
- * b31 b30 b29 b28 b27 ... b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * : : : : : : : : :
- * : : : : : : : : :
- * x x x x 1 0 0 0 27
- * x x x 1 0 0 0 0 28
- * x x 1 0 0 0 0 0 29
- * x 1 0 0 0 0 0 0 30
- * 1 0 0 0 0 0 0 0 31
- * 0 0 0 0 0 0 0 0 32
- *
- *
- * (4) For 64-bit values :
- *
- * b63 b62 b61 b60 b59 ... b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * : : : : : : : : :
- * : : : : : : : : :
- * x x x x 1 0 0 0 59
- * x x x 1 0 0 0 0 60
- * x x 1 0 0 0 0 0 61
- * x 1 0 0 0 0 0 0 62
- * 1 0 0 0 0 0 0 0 63
- * 0 0 0 0 0 0 0 0 64
- *
- * (2) For non-zero values, the returned number of contiguous, least-significant, trailing
- * zero bits is also equivalent to the bit position of the least-significant set bit.
- *
- * (3) 'val' SHOULD be validated for non-'0' PRIOR to all other counting zero calculations :
- *
- * (a) CPU_CntTrailZeros()'s final conditional statement calculates 'val's number of
- * trailing zeros based on its return data size, 'CPU_CFG_DATA_SIZE', & 'val's
- * calculated number of lead zeros ONLY if the initial 'val' is non-'0' :
- *
- * if (val != 0u) {
- * nbr_trail_zeros = ((CPU_CFG_DATA_SIZE * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- * } else {
- * nbr_trail_zeros = nbr_lead_zeros;
- * }
- *
- * Therefore, initially validating all non-'0' values avoids having to conditionally
- * execute the final 'if' statement.
- *********************************************************************************************************
- */
- #ifndef CPU_CFG_TRAIL_ZEROS_ASM_PRESENT
- CPU_DATA CPU_CntTrailZeros (CPU_DATA val)
- {
- CPU_DATA val_bit_mask;
- CPU_DATA nbr_lead_zeros;
- CPU_DATA nbr_trail_zeros;
- if (val == 0u) { /* Rtn ALL val bits as zero'd (see Note #3). */
- return (CPU_CFG_DATA_SIZE * DEF_OCTET_NBR_BITS);
- }
- val_bit_mask = val & ((CPU_DATA)~val + 1u); /* Zero/clr all bits EXCEPT least-sig set bit. */
- nbr_lead_zeros = CPU_CntLeadZeros(val_bit_mask); /* Cnt nbr lead 0s. */
- /* Calc nbr trail 0s = (nbr val bits - 1) - nbr lead 0s.*/
- nbr_trail_zeros = ((CPU_CFG_DATA_SIZE * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- return (nbr_trail_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntTrailZeros08()
- *
- * Description : Count the number of contiguous, least-significant, trailing zero bits in an 8-bit data value.
- *
- * Argument(s) : val Data value to count trailing zero bits.
- *
- * Return(s) : Number of contiguous, least-significant, trailing zero bits in 'val'.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 8-bit values :
- *
- * b07 b06 b05 b04 b03 b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * x x x x 1 0 0 0 3
- * x x x 1 0 0 0 0 4
- * x x 1 0 0 0 0 0 5
- * x 1 0 0 0 0 0 0 6
- * 1 0 0 0 0 0 0 0 7
- * 0 0 0 0 0 0 0 0 8
- *
- *
- * (2) For non-zero values, the returned number of contiguous, least-significant, trailing
- * zero bits is also equivalent to the bit position of the least-significant set bit.
- *
- * (3) 'val' SHOULD be validated for non-'0' PRIOR to all other counting zero calculations :
- *
- * (a) For assembly-optimized implementations, CPU_CntTrailZeros() returns 'val's
- * number of trailing zeros via CPU's native data size, 'CPU_CFG_DATA_SIZE'.
- * If the returned number of zeros exceeds CPU_CntTrailZeros08()'s 8-bit return
- * data size, then the returned number of zeros must be offset by the difference
- * between CPU_CntTrailZeros()'s & CPU_CntTrailZeros08()'s return data size :
- *
- * nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- * if (nbr_trail_zeros > (CPU_WORD_SIZE_08 * DEF_OCTET_NBR_BITS)) {
- * nbr_trail_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_08) * DEF_OCTET_NBR_BITS;
- * }
- *
- * However, this ONLY occurs for an initial 'val' of '0' since all non-'0' 8-bit
- * values would return a number of trailing zeros less than or equal to 8 bits.
- *
- * Therefore, initially validating all non-'0' values prior to calling assembly-
- * optimized CPU_CntTrailZeros() avoids having to offset the number of returned
- * trailing zeros by the difference in CPU data size and 8-bit data value bits.
- *
- * (b) For CPU_CntTrailZeros08()'s C implementation, the final conditional statement
- * calculates 'val's number of trailing zeros based on CPU_CntTrailZeros08()'s
- * 8-bit return data size & 'val's calculated number of lead zeros ONLY if the
- * initial 'val' is non-'0' :
- *
- * if (val != 0u) {
- * nbr_trail_zeros = ((CPU_WORD_SIZE_08 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- * } else {
- * nbr_trail_zeros = nbr_lead_zeros;
- * }
- *
- * Therefore, initially validating all non-'0' values avoids having to conditionally
- * execute the final 'if' statement.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_08)
- CPU_DATA CPU_CntTrailZeros08 (CPU_INT08U val)
- {
- #if (!((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_08)))
- CPU_INT08U val_bit_mask;
- CPU_DATA nbr_lead_zeros;
- #endif
- CPU_DATA nbr_trail_zeros;
- if (val == 0u) { /* Rtn ALL val bits as zero'd (see Note #3). */
- return (CPU_WORD_SIZE_08 * DEF_OCTET_NBR_BITS);
- }
- /* ------------------ ASM-OPTIMIZED ------------------- */
- #if ((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_08))
- nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- #else /* ------------------- C-OPTIMIZED -------------------- */
- val_bit_mask = val & ((CPU_INT08U)~val + 1u); /* Zero/clr all bits EXCEPT least-sig set bit. */
- nbr_lead_zeros = CPU_CntLeadZeros08(val_bit_mask); /* Cnt nbr lead 0s. */
- /* Calc nbr trail 0s = (nbr val bits - 1) - nbr lead 0s.*/
- nbr_trail_zeros = ((CPU_WORD_SIZE_08 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- #endif
- return (nbr_trail_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntTrailZeros16()
- *
- * Description : Count the number of contiguous, least-significant, trailing zero bits in a 16-bit data value.
- *
- * Argument(s) : val Data value to count trailing zero bits.
- *
- * Return(s) : Number of contiguous, least-significant, trailing zero bits in 'val'.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 16-bit values :
- *
- * b15 b14 b13 b12 b11 ... b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * : : : : : : : : :
- * : : : : : : : : :
- * x x x x 1 0 0 0 11
- * x x x 1 0 0 0 0 12
- * x x 1 0 0 0 0 0 13
- * x 1 0 0 0 0 0 0 14
- * 1 0 0 0 0 0 0 0 15
- * 0 0 0 0 0 0 0 0 16
- *
- *
- * (2) For non-zero values, the returned number of contiguous, least-significant, trailing
- * zero bits is also equivalent to the bit position of the least-significant set bit.
- *
- * (3) 'val' SHOULD be validated for non-'0' PRIOR to all other counting zero calculations :
- *
- * (a) For assembly-optimized implementations, CPU_CntTrailZeros() returns 'val's
- * number of trailing zeros via CPU's native data size, 'CPU_CFG_DATA_SIZE'.
- * If the returned number of zeros exceeds CPU_CntTrailZeros16()'s 16-bit return
- * data size, then the returned number of zeros must be offset by the difference
- * between CPU_CntTrailZeros()'s & CPU_CntTrailZeros16()'s return data size :
- *
- * nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- * if (nbr_trail_zeros > (CPU_WORD_SIZE_16 * DEF_OCTET_NBR_BITS)) {
- * nbr_trail_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_16) * DEF_OCTET_NBR_BITS;
- * }
- *
- * However, this ONLY occurs for an initial 'val' of '0' since all non-'0' 16-bit
- * values would return a number of trailing zeros less than or equal to 16 bits.
- *
- * Therefore, initially validating all non-'0' values prior to calling assembly-
- * optimized CPU_CntTrailZeros() avoids having to offset the number of returned
- * trailing zeros by the difference in CPU data size and 16-bit data value bits.
- *
- * (b) For CPU_CntTrailZeros16()'s C implementation, the final conditional statement
- * calculates 'val's number of trailing zeros based on CPU_CntTrailZeros16()'s
- * 16-bit return data size & 'val's calculated number of lead zeros ONLY if the
- * initial 'val' is non-'0' :
- *
- * if (val != 0u) {
- * nbr_trail_zeros = ((CPU_WORD_SIZE_16 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- * } else {
- * nbr_trail_zeros = nbr_lead_zeros;
- * }
- *
- * Therefore, initially validating all non-'0' values avoids having to conditionally
- * execute the final 'if' statement.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_16)
- CPU_DATA CPU_CntTrailZeros16 (CPU_INT16U val)
- {
- #if (!((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_16)))
- CPU_INT16U val_bit_mask;
- CPU_DATA nbr_lead_zeros;
- #endif
- CPU_DATA nbr_trail_zeros;
- if (val == 0u) { /* Rtn ALL val bits as zero'd (see Note #3). */
- return (CPU_WORD_SIZE_16 * DEF_OCTET_NBR_BITS);
- }
- /* ------------------ ASM-OPTIMIZED ------------------- */
- #if ((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_16))
- nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- #else /* ------------------- C-OPTIMIZED -------------------- */
- val_bit_mask = val & ((CPU_INT16U)~val + 1u); /* Zero/clr all bits EXCEPT least-sig set bit. */
- nbr_lead_zeros = CPU_CntLeadZeros16(val_bit_mask); /* Cnt nbr lead 0s. */
- /* Calc nbr trail 0s = (nbr val bits - 1) - nbr lead 0s.*/
- nbr_trail_zeros = ((CPU_WORD_SIZE_16 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- #endif
- return (nbr_trail_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntTrailZeros32()
- *
- * Description : Count the number of contiguous, least-significant, trailing zero bits in a 32-bit data value.
- *
- * Argument(s) : val Data value to count trailing zero bits.
- *
- * Return(s) : Number of contiguous, least-significant, trailing zero bits in 'val'.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 32-bit values :
- *
- * b31 b30 b29 b28 b27 ... b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * : : : : : : : : :
- * : : : : : : : : :
- * x x x x 1 0 0 0 27
- * x x x 1 0 0 0 0 28
- * x x 1 0 0 0 0 0 29
- * x 1 0 0 0 0 0 0 30
- * 1 0 0 0 0 0 0 0 31
- * 0 0 0 0 0 0 0 0 32
- *
- *
- * (2) For non-zero values, the returned number of contiguous, least-significant, trailing
- * zero bits is also equivalent to the bit position of the least-significant set bit.
- *
- * (3) 'val' SHOULD be validated for non-'0' PRIOR to all other counting zero calculations :
- *
- * (a) For assembly-optimized implementations, CPU_CntTrailZeros() returns 'val's
- * number of trailing zeros via CPU's native data size, 'CPU_CFG_DATA_SIZE'.
- * If the returned number of zeros exceeds CPU_CntTrailZeros32()'s 32-bit return
- * data size, then the returned number of zeros must be offset by the difference
- * between CPU_CntTrailZeros()'s & CPU_CntTrailZeros32()'s return data size :
- *
- * nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- * if (nbr_trail_zeros > (CPU_WORD_SIZE_32 * DEF_OCTET_NBR_BITS)) {
- * nbr_trail_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_32) * DEF_OCTET_NBR_BITS;
- * }
- *
- * However, this ONLY occurs for an initial 'val' of '0' since all non-'0' 32-bit
- * values would return a number of trailing zeros less than or equal to 32 bits.
- *
- * Therefore, initially validating all non-'0' values prior to calling assembly-
- * optimized CPU_CntTrailZeros() avoids having to offset the number of returned
- * trailing zeros by the difference in CPU data size and 32-bit data value bits.
- *
- * (b) For CPU_CntTrailZeros32()'s C implementation, the final conditional statement
- * calculates 'val's number of trailing zeros based on CPU_CntTrailZeros32()'s
- * 32-bit return data size & 'val's calculated number of lead zeros ONLY if the
- * initial 'val' is non-'0' :
- *
- * if (val != 0u) {
- * nbr_trail_zeros = ((CPU_WORD_SIZE_32 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- * } else {
- * nbr_trail_zeros = nbr_lead_zeros;
- * }
- *
- * Therefore, initially validating all non-'0' values avoids having to conditionally
- * execute the final 'if' statement.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_32)
- CPU_DATA CPU_CntTrailZeros32 (CPU_INT32U val)
- {
- #if (!((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_32)))
- CPU_INT32U val_bit_mask;
- CPU_DATA nbr_lead_zeros;
- #endif
- CPU_DATA nbr_trail_zeros;
- if (val == 0u) { /* Rtn ALL val bits as zero'd (see Note #3). */
- return (CPU_WORD_SIZE_32 * DEF_OCTET_NBR_BITS);
- }
- /* ------------------ ASM-OPTIMIZED ------------------- */
- #if ((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_32))
- nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- #else /* ------------------- C-OPTIMIZED -------------------- */
- val_bit_mask = val & ((CPU_INT32U)~val + 1u); /* Zero/clr all bits EXCEPT least-sig set bit. */
- nbr_lead_zeros = CPU_CntLeadZeros32(val_bit_mask); /* Cnt nbr lead 0s. */
- /* Calc nbr trail 0s = (nbr val bits - 1) - nbr lead 0s.*/
- nbr_trail_zeros = ((CPU_WORD_SIZE_32 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- #endif
- return (nbr_trail_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_CntTrailZeros64()
- *
- * Description : Count the number of contiguous, least-significant, trailing zero bits in a 64-bit data value.
- *
- * Argument(s) : val Data value to count trailing zero bits.
- *
- * Return(s) : Number of contiguous, least-significant, trailing zero bits in 'val'.
- *
- * Caller(s) : Application.
- *
- * This function is a CPU module application programming interface (API) function & MAY be
- * called by application function(s).
- *
- * Note(s) : (1) Supports 64-bit values :
- *
- * b63 b62 b61 b60 b59 ... b02 b01 b00 # Trailing Zeros
- * --- --- --- --- --- --- --- --- ----------------
- * x x x x x x x 1 0
- * x x x x x x 1 0 1
- * x x x x x 1 0 0 2
- * : : : : : : : : :
- * : : : : : : : : :
- * x x x x 1 0 0 0 59
- * x x x 1 0 0 0 0 60
- * x x 1 0 0 0 0 0 61
- * x 1 0 0 0 0 0 0 62
- * 1 0 0 0 0 0 0 0 63
- * 0 0 0 0 0 0 0 0 64
- *
- *
- * (2) For non-zero values, the returned number of contiguous, least-significant, trailing
- * zero bits is also equivalent to the bit position of the least-significant set bit.
- *
- * (3) 'val' SHOULD be validated for non-'0' PRIOR to all other counting zero calculations :
- *
- * (a) For assembly-optimized implementations, CPU_CntTrailZeros() returns 'val's
- * number of trailing zeros via CPU's native data size, 'CPU_CFG_DATA_SIZE'.
- * If the returned number of zeros exceeds CPU_CntTrailZeros64()'s 64-bit return
- * data size, then the returned number of zeros must be offset by the difference
- * between CPU_CntTrailZeros()'s & CPU_CntTrailZeros64()'s return data size :
- *
- * nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- * if (nbr_trail_zeros > (CPU_WORD_SIZE_64 * DEF_OCTET_NBR_BITS)) {
- * nbr_trail_zeros -= (CPU_CFG_DATA_SIZE - CPU_WORD_SIZE_64) * DEF_OCTET_NBR_BITS;
- * }
- *
- * However, this ONLY occurs for an initial 'val' of '0' since all non-'0' 64-bit
- * values would return a number of trailing zeros less than or equal to 64 bits.
- *
- * Therefore, initially validating all non-'0' values prior to calling assembly-
- * optimized CPU_CntTrailZeros() avoids having to offset the number of returned
- * trailing zeros by the difference in CPU data size and 64-bit data value bits.
- *
- * (b) For CPU_CntTrailZeros64()'s C implementation, the final conditional statement
- * calculates 'val's number of trailing zeros based on CPU_CntTrailZeros64()'s
- * 64-bit return data size & 'val's calculated number of lead zeros ONLY if the
- * initial 'val' is non-'0' :
- *
- * if (val != 0u) {
- * nbr_trail_zeros = ((CPU_WORD_SIZE_64 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- * } else {
- * nbr_trail_zeros = nbr_lead_zeros;
- * }
- *
- * Therefore, initially validating all non-'0' values avoids having to conditionally
- * execute the final 'if' statement.
- *********************************************************************************************************
- */
- #if (CPU_CFG_DATA_SIZE_MAX >= CPU_WORD_SIZE_64)
- CPU_DATA CPU_CntTrailZeros64 (CPU_INT64U val)
- {
- #if (!((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_64)))
- CPU_INT64U val_bit_mask;
- CPU_DATA nbr_lead_zeros;
- #endif
- CPU_DATA nbr_trail_zeros;
- if (val == 0u) { /* Rtn ALL val bits as zero'd (see Note #3). */
- return (CPU_WORD_SIZE_64 * DEF_OCTET_NBR_BITS);
- }
- /* ------------------ ASM-OPTIMIZED ------------------- */
- #if ((defined(CPU_CFG_TRAIL_ZEROS_ASM_PRESENT)) && \
- (CPU_CFG_DATA_SIZE >= CPU_WORD_SIZE_64))
- nbr_trail_zeros = CPU_CntTrailZeros((CPU_DATA)val);
- #else /* ------------------- C-OPTIMIZED -------------------- */
- val_bit_mask = val & ((CPU_INT64U)~val + 1u); /* Zero/clr all bits EXCEPT least-sig set bit. */
- nbr_lead_zeros = CPU_CntLeadZeros64(val_bit_mask); /* Cnt nbr lead 0s. */
- /* Calc nbr trail 0s = (nbr val bits - 1) - nbr lead 0s.*/
- nbr_trail_zeros = ((CPU_WORD_SIZE_64 * DEF_OCTET_NBR_BITS) - 1u) - nbr_lead_zeros;
- #endif
- return (nbr_trail_zeros);
- }
- #endif
- /*
- *********************************************************************************************************
- * CRCUtil_PopCnt_32()
- *
- * Description : Compute population count (hamming weight) for value (number of bits set).
- *
- * Argument(s) : value Value to compute population count on.
- *
- *
- * Return(s) : value's population count.
- *
- * Caller(s) : various.
- *
- * Note(s) : (1) Algorithm taken from http://en.wikipedia.org/wiki/Hamming_weight
- *********************************************************************************************************
- */
- CPU_INT08U CPU_PopCnt32 (CPU_INT32U value)
- {
- CPU_INT32U even_cnt;
- CPU_INT32U odd_cnt;
- CPU_INT32U result;
- odd_cnt = (value >> 1u) & CRC_UTIL_POPCNT_MASK01010101_32; /* 2-bits pieces. */
- result = value - odd_cnt; /* Same result as result=odd_cnt+(value & 0x55555555). */
- even_cnt = result & CRC_UTIL_POPCNT_MASK00110011_32; /* 4-bits pieces. */
- odd_cnt = (result >> 2u) & CRC_UTIL_POPCNT_MASK00110011_32;
- result = even_cnt + odd_cnt;
- even_cnt = result & CRC_UTIL_POPCNT_MASK00001111_32; /* 8-bits pieces. */
- odd_cnt = (result >> 4u) & CRC_UTIL_POPCNT_MASK00001111_32;
- result = even_cnt + odd_cnt;
- result = (result * CRC_UTIL_POPCNT_POWERSOF256_32) >> 24u;
- return (result);
- }
- /*
- *********************************************************************************************************
- *********************************************************************************************************
- * LOCAL FUNCTIONS
- *********************************************************************************************************
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * CPU_NameInit()
- *
- * Description : Initialize CPU Name.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_Init().
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- #if (CPU_CFG_NAME_EN == DEF_ENABLED)
- static void CPU_NameInit (void)
- {
- CPU_NameClr();
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_TS_Init()
- *
- * Description : (1) Initialize CPU timestamp :
- *
- * (a) Initialize/start CPU timestamp timer See Note #1
- * (b) Initialize CPU timestamp controls
- *
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_Init().
- *
- * Note(s) : (1) The following initialization MUST be sequenced as follows :
- *
- * (a) CPU_TS_TmrFreq_Hz MUST be initialized prior to CPU_TS_TmrInit()
- * (b) CPU_TS_TmrInit() SHOULD precede calls to all other CPU timestamp functions;
- * otherwise, invalid time measurements may be calculated/
- * returned.
- *
- * See also 'CPU_Init() Note #3a'.
- *********************************************************************************************************
- */
- #if ((CPU_CFG_TS_EN == DEF_ENABLED) || \
- (CPU_CFG_TS_TMR_EN == DEF_ENABLED))
- static void CPU_TS_Init (void)
- {
- #if (((CPU_CFG_TS_32_EN == DEF_ENABLED ) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_32)) || \
- ((CPU_CFG_TS_64_EN == DEF_ENABLED ) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_64)))
- CPU_TS_TMR ts_tmr_cnts;
- #endif
- /* ----------------- INIT CPU TS TMR ------------------ */
- #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
- CPU_TS_TmrFreq_Hz = 0u; /* Init/clr ts tmr freq (see Note #1a). */
- CPU_TS_TmrInit(); /* Init & start ts tmr (see Note #1b). */
- #endif
- /* ------------------- INIT CPU TS -------------------- */
- #if (((CPU_CFG_TS_32_EN == DEF_ENABLED ) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_32)) || \
- ((CPU_CFG_TS_64_EN == DEF_ENABLED ) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_64)))
- ts_tmr_cnts = CPU_TS_TmrRd(); /* Get init ts tmr val (in ts tmr cnts). */
- #endif
- #if ((CPU_CFG_TS_32_EN == DEF_ENABLED) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_32))
- CPU_TS_32_Accum = 0u; /* Init 32-bit accum'd ts. */
- CPU_TS_32_TmrPrev = ts_tmr_cnts; /* Init 32-bit ts prev tmr val. */
- #endif
- #if ((CPU_CFG_TS_64_EN == DEF_ENABLED) && \
- (CPU_CFG_TS_TMR_SIZE < CPU_WORD_SIZE_64))
- CPU_TS_64_Accum = 0u; /* Init 64-bit accum'd ts. */
- CPU_TS_64_TmrPrev = ts_tmr_cnts; /* Init 64-bit ts prev tmr val. */
- #endif
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_IntDisMeasInit()
- *
- * Description : (1) Initialize interrupts disabled time measurements feature :
- *
- * (a) Initialize interrupts disabled time measurement controls
- * (b) Calculate interrupts disabled time measurement overhead
- *
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_Init().
- *
- * Note(s) : (2) CPU_IntDisMeasInit() SHOULD precede ALL calls to CPU_CRITICAL_ENTER()/CPU_CRITICAL_EXIT()
- * & other CPU interrupts disabled time measurement functions; otherwise, invalid interrupts
- * disabled time measurements may be calculated/returned.
- *
- * See also 'CPU_Init() Note #3b'.
- *
- * (3) (a) (1) Interrupts disabled time measurement overhead performed multiple times to calculate
- * a rounded average with better accuracy, hopefully of +/- one timer count.
- *
- * (2) However, a single overhead time measurement is recommended, even for instruction-
- * cache-enabled CPUs, since critical sections are NOT typically called within
- * instruction-cached loops. Thus a single non-cached/non-averaged time measurement
- * is a more realistic overhead for the majority of non-cached interrupts disabled
- * time measurements.
- *
- * (b) Interrupts MUST be disabled while measuring the interrupts disabled time measurement
- * overhead; otherwise, overhead measurements could be interrupted which would incorrectly
- * calculate an inflated overhead time which would then incorrectly calculate deflated
- * interrupts disabled times.
- *********************************************************************************************************
- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- static void CPU_IntDisMeasInit (void)
- {
- CPU_TS_TMR time_meas_tot_cnts;
- CPU_INT16U i;
- CPU_SR_ALLOC();
- /* ----------- INIT INT DIS TIME MEAS CTRLS ----------- */
- CPU_IntDisMeasCtr = 0u;
- CPU_IntDisNestCtr = 0u;
- CPU_IntDisMeasStart_cnts = 0u;
- CPU_IntDisMeasStop_cnts = 0u;
- CPU_IntDisMeasMaxCur_cnts = 0u;
- CPU_IntDisMeasMax_cnts = 0u;
- CPU_IntDisMeasOvrhd_cnts = 0u;
- /* ----------- CALC INT DIS TIME MEAS OVRHD ----------- */
- time_meas_tot_cnts = 0u;
- CPU_INT_DIS(); /* Ints MUST be dis'd for ovrhd calc (see Note #3b). */
- for (i = 0u; i < CPU_CFG_INT_DIS_MEAS_OVRHD_NBR; i++) {
- CPU_IntDisMeasMaxCur_cnts = 0u;
- CPU_IntDisMeasStart(); /* Perform multiple consecutive start/stop time meas's */
- CPU_IntDisMeasStop();
- time_meas_tot_cnts += CPU_IntDisMeasMaxCur_cnts; /* ... & sum time meas max's ... */
- }
- /* ... to calc avg time meas ovrhd (see Note #3a). */
- CPU_IntDisMeasOvrhd_cnts = (time_meas_tot_cnts + (CPU_CFG_INT_DIS_MEAS_OVRHD_NBR / 2u))
- / CPU_CFG_INT_DIS_MEAS_OVRHD_NBR;
- CPU_IntDisMeasMaxCur_cnts = 0u; /* Reset max ints dis'd times. */
- CPU_IntDisMeasMax_cnts = 0u;
- CPU_INT_EN();
- }
- #endif
- /*
- *********************************************************************************************************
- * CPU_IntDisMeasMaxCalc()
- *
- * Description : Calculate maximum interrupts disabled time.
- *
- * Argument(s) : time_tot_cnts Total interrupt disabled time, in timer counts.
- *
- * Return(s) : Maximum interrupts disabled time (in CPU timestamp timer counts).
- *
- * Caller(s) : CPU_IntDisMeasMaxCurGet(),
- * CPU_IntDisMeasMaxGet().
- *
- * Note(s) : (1) (a) The total amount of time interrupts are disabled by system &/or application code
- * during critical sections is calculated by the following equations :
- *
- * (1) time = [ time - time ] - time
- * interrupts [ stop start ] total meas
- * disabled [ meas meas ] ovrhd
- * (via application)
- *
- *
- * (2) time = time + time
- * total meas start meas stop meas
- * ovrhd ovrhd ovrhd
- *
- *
- * where
- *
- * time time interrupts are disabled between
- * interrupts first critical section enter &
- * disabled last critical section exit minus
- * (via application) time measurement overhead
- *
- * time time of disable interrupts start time
- * start measurement (in timer counts)
- * meas
- *
- * time time of disable interrupts stop time
- * stop measurement (in timer counts)
- * meas
- *
- * time total overhead time to start/stop disabled
- * total meas interrupts time measurements (in timer
- * ovrhd counts)
- *
- * time total overhead time after getting start
- * start meas time until end of start measurement
- * ovrhd function (in timer counts)
- *
- * time total overhead time from beginning of stop
- * stop meas measurement function until after getting
- * ovrhd stop time (in timer counts)
- *
- *
- * (b) To expedite & reduce interrupts disabled time measurement overhead, the final
- * calculations to subtract the interrupts disabled time measurement overhead is
- * performed asynchronously in API functions.
- *
- * See also 'CPU_IntDisMeasStop() Note #1b2'.
- *
- * (c) The amount of time interrupts are disabled is calculated by either of the
- * following equations :
- *
- * (1) Interrupts disabled time = Number timer counts * Timer period
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer period Timer's period in some units of
- * (fractional) seconds
- * Interrupts disabled time Amount of time interrupts are
- * disabled, in same units of
- * (fractional) seconds as the
- * Timer period
- *
- * Number timer counts
- * (2) Interrupts disabled time = ---------------------
- * Timer frequency
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer frequency Timer's frequency in some units
- * of counts per second
- * Interrupts disabled time Amount of time interrupts are
- * disabled, in seconds
- *
- * See also 'cpu_core.h FUNCTION PROTOTYPES CPU_TS_TmrRd() Note #2c'
- * & 'cpu_core.h FUNCTION PROTOTYPES CPU_TSxx_to_uSec() Note #2'.
- *
- * (2) Although it is not typical, it is possible for an interrupts disabled time
- * measurement to be less than the interrupts disabled time measurement overhead;
- * especially if the overhead was calculated with a single, non-cached measurement
- * & critical sections are called within instruction-cached loops.
- *********************************************************************************************************
- */
- #ifdef CPU_CFG_INT_DIS_MEAS_EN
- static CPU_TS_TMR CPU_IntDisMeasMaxCalc (CPU_TS_TMR time_tot_cnts)
- {
- CPU_TS_TMR time_max_cnts;
- time_max_cnts = time_tot_cnts;
- if (time_max_cnts > CPU_IntDisMeasOvrhd_cnts) { /* If max ints dis'd time > ovrhd time, ... */
- time_max_cnts -= CPU_IntDisMeasOvrhd_cnts; /* ... adj max ints dis'd time by ovrhd time; ... */
- } else { /* ... else max ints dis'd time < ovrhd time, ... */
- time_max_cnts = 0u; /* ... clr max ints dis'd time (see Note #2). */
- }
- return (time_max_cnts);
- }
- #endif
|