FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [March 2016 Threads] pic33f in-line assembly in TaskPosted by ltran2016 on March 16, 2016 I know this probably isn't a relevant disucssion, but it might be helpful for someone else later on. I'm attempting to use the the pic33 dsp operation, but I'm encountering some issues using the the built in function multiply-accumulate function. It is really general and does very stupid things that hinder the speed of the mac operation. I know this because I looked at the compiler output assembly listing. To get around this, I'm attempting to use inline assembly in a task. Microchip has a lot of documentation, but in this area it seems to gloss over some important details.
Any help is appreciate. Microchip's forum is really thin and there doesn't seem to be anyone who has encountered my problem. Apparently, very few people use mix C and assembly. I've exhausted all my options.
How do I access a variable defined on the task stack? I keep getting "variable undefined". This only happens at
Thanks.
~~~~
//-------------------------------------------------------------------------
static portTASKFUNCTION( ADCMatchFilterTask, pvParam ) {
//-------------------------------------------------------------------------
ADCt *pADC = (ADCt *)pvParam;
UINTt idxdma;
asm volatile (
"mov refbuf, W8 ;n"
"mov W8, W9 ;n"
"add #8, W9 ;n"
"mov dmabuf, W12 ;n" <--- no problem here (defined global)
"mov #psvoffset(idx_dma), W2 ;n" <--- problem here
. . .
. . . );
~~~~
pic33f in-line assembly in TaskPosted by rtel on March 17, 2016 This basically GCC, right?
The GCC inline assembler is extremely powerful, but like all things, the more powerful the more complex. This is really more a GCC question than a Microchip question.
There is lots of documentation online, but to find it you first need to know what to search for. Here is an example, which just goes to show how complex it can get: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html .... so often it is easier to find a worked example and copy that.
Here is an example taken from the FreeRTOS Cortex-M port, it uses the extended asm syntax to copy a register value into a stack variable. Doing the opposite (reading from a stack variable rather than writing to it) requires different but very similar syntax you will find on the link above:
~~~~
void vPortValidateInterruptPriority( void )
{
uint32t ulCurrentInterrupt;
uint8t ucCurrentPriority;
/* Obtain the number of the currently executing interrupt. */
__asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) );
/* rest of code here */
}
~~~~
pic33f in-line assembly in TaskPosted by ltran2016 on March 18, 2016 Thanks for the pointer. I dug somewhat deeper and here's what I found FYI in case someone asks in the future.
The has to be a modifier at the start of each operand (variable) passed in to and/or out of the inline assembly listing. The value of the operand is relative to the first variable. In my case I'm not passing anything out, so 0% will start with the input operands.
%0 = idx_dma
%1 = idx
%2 = pA
%3 = pB
constraints/modifiers
"g" - indicates general register, memory or immediate integer operand
"T" - indicates near/far data operand
~~~~
static portTASKFUNCTION( MFTask, pvParam ) {
SINTt *pA, *pB;
UINTt idx, idxdma;
SINTt A [256];
SINT_t B [256];
pI = A;
pQ = B;
asm volatile (
" mov #refbuf, w8 ;n"
" mov w8, w9 ;n"
" add #8, w9 ;n"
" mov #dmabuf, w3 ;n"
" mov %0, w2 ; copy "idx" variable to w2 n"
" sl w2, w0 ;n"
...
...
...
" mov %1, w2 ; copy "idx" variable to w2 n"
" sl w2, w0 ;n"
" mov %2, w2 ; copy "pA" variable to w2 n"
" sac a, [w0+w2] ;n"
" mov %3, w2 ;copy "pB" variable to w2 n"
" sac b, [w0+w2] ;n"
: /* output: none /
: "gT" (idx_dma), "gT" (idx), "gT" (pA), "gT" (pB) / input : %0 - %3 */
);
~~~~
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|