Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists