# Fast Task State Detection - Just 'if running' detection

**URL:** <https://forums.freertos.org/t/fast-task-state-detection-just-if-running-detection/7429>\
**Category:** Kernel\
**Created:** [September 19, 2018, 1:03pm UTC](https://forums.freertos.org/t/fast-task-state-detection-just-if-running-detection/7429 "2018-09-19T13:03:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwestmoreland](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jwestmoreland](https://forums.freertos.org/u/jwestmoreland)\
**Post date:** [September 19, 2018, 1:03pm UTC](https://forums.freertos.org/t/fast-task-state-detection-just-if-running-detection/7429/1 "2018-09-19T13:03:59Z")

</div>

**[westmorelandeng](https://sourceforge.net/u/westmorelandeng/)** wrote on [Wednesday, September 19, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/94bfb25c/#5a60):

Hello All,

I need to be able to detect (will be assembly as I have to put this into the tick ISR) the task status - what will make this ‘fast’ is that I only need to know if:

```
if( pxTCB == pxCurrentTCB )
{
		/* The task calling this function is querying its own state. */
		eReturn = eRunning;
	}

```

that’s true and I see that’s in the eTaskState funtion.

I guess I can start by implementing the assembly version of eTaskState up to that point - but I was wondering if there is any other quicker way to do this and if there’s some other function/macro someplace that does that.

Thanks!  
John W.

---

<div class="post-metadata">

**Author:** ![jwestmoreland](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jwestmoreland](https://forums.freertos.org/u/jwestmoreland)\
**Post date:** [September 20, 2018, 12:49am UTC](https://forums.freertos.org/t/fast-task-state-detection-just-if-running-detection/7429/2 "2018-09-20T00:49:43Z")

</div>

**[westmorelandeng](https://sourceforge.net/u/westmorelandeng/)** wrote on [Thursday, September 20, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/94bfb25c/#1a16):

Hello All,

Well, I figured out a way to do this:  
…  
mov xar7, dbl (_(#\_save\_xar7)) ; save xar7  
mov xar6, dbl (_(#\_save\_xar6)) ; save xar6  
amov #0x000000, xar7 ; must be cleared  
amov #0x000000, xar6  
mov \*sp(#1), ar7 ;; sp+3  
mov ar7, \*(#\_save\_new\_pxcode)  
mov ssp, ar6  
mov \*ar6(#1), ar7 ;; ssp+3  
mov ar7, \*(#\_save\_new\_pxlcode) ; ==\> now we have our new return address, and if a task, it’s where we are

```
                    mov dbl (*(#_pxCurrentTCB)), xar7
                    mov xar7, dbl(*(#_xCompareTCB))
                    mov dbl (*(#_save_xar7)), xar7 ; restore xar7
                    mov dbl (*(#_save_xar6)), xar6 ; restore xar6

```

And:  
…  
.if 1  
mov dbl (\*(\_xCompareTCB)), xar6 ; need to restore our return address   
mov xar7, ac0  
mov xar6, ac1  
CMPU AC1 != AC0, TC1  
BCC $5,TC1  
amov #0x000000, xar7  
amov #0x000000, xar6  
mov \*(#\_save\_new\_pxcode), ar7  
mov ar7, \*sp(#0)  
mov \*(#\_save\_new\_pxlcode) , ar7  
mov ssp, ar6  
mov ar7, \*ar6(#0)

```
                    mov dbl (*(#_save_xar6)), xar6
					.endif

```

$5:

So, that’s not too bad.

Regards,  
John W.
