Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

pic33f in-line assembly in Task

Posted 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 Task

Posted 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 Task

Posted 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 */ );

~~~~


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner