cancel
Showing results for 
Search instead for 
Did you mean: 

Program code.

AVI-crak
Senior

Difficult and stupid question.

There is an interrupt SVC_Handler written in assembly language. There are many internal addresses in the function body, which for convenience of use are collected in a table in the function header. The table is used to navigate to the address using the TBH assembler command.

The contents of the SVC_Handler interrupt does not change at compile time. I can read the table through a direct link to the link. But this method increases the amount of software code, and deprives the meaning of its application.

Since the SVC_Handler interrupt does not change, it is likely that you can write a static structure and assign the function address to it.

But I do not understand how to do this in C.

4 REPLIES 4

You could presumably create an array of function pointers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AVI-crak
Senior

Function pointers cannot have a const modifier, nor can content. This means that the compiler will consistently read the data at the address each time it is accessed. It will work, but slowly. You will need to address the new address in flash memory, which will give a delay.

I need speed.

Option - the union of the function body (not links !!!) with the structure under the const modifier. In this case, the preprocessor should work, the data from the structure will be precomputed, and reading at the address will not be required.

At the assembly level, you get a very simple MOV operation.

But how to do that?

I'm not sure I understand the circumstances you think something wouldn't get read. Immediates tend to be of limited scope, and then it has to pull from literal pools.

I'd expect one could create a const array, and cast other attributes from there.

Perhaps you can illustrate what the assembler would look like for what you think you need in C. The table branches then to be localized and self-relative.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AVI-crak
Senior
.align 2
 .section  .text.SVC_Handler
 .globl     SVC_Handler
 .type    SVC_Handler, %function
 
SVC_Handler:
            tbh     [pc, r3, lsl #1]
SVC_Table:
    .hword   ((__EnableIRQS - SVC_Table)/2)      //0
    .hword   ((__DisableIRQS - SVC_Table)/2)     //1
    .hword   ((__Enabling_FPU - SVC_Table)/2)    //2
    .hword   ((___sRandom - SVC_Table)/2)        //3
    .hword   ((__sTask_new - SVC_Table)/2)       //4
    .hword   ((__Delete_Task - SVC_Table)/2)     //5
    .hword   ((__sTask_wake_mc - SVC_Table)/2)   //6
    .hword   ((__sDelay_new - SVC_Table)/2)      //7
    .hword   ((__sTask_wait - SVC_Table)/2)      //8
    .hword   ((__sTask_wake - SVC_Table)/2)      //9
    .hword   ((__nil_in - SVC_Table)/2)            //A
    .hword   ((__nil_exit - SVC_Table)/2)          //B
    .hword   ((__sTask_list - SVC_Table)/2)      //C
    .hword   ((__memory_donate - SVC_Table)/2)   //D
    .hword   ((__memory_get - SVC_Table)/2)      //E
    .hword   ((__nil_step - SVC_Table)/2)          //F
    .hword   ((__switch - SVC_Table)/2)          //10  переглючатель
 
 
 .align 2
__EnableIRQS: // ("r0") = IRQn, ("r1") = priority; ++

Cap interrupt SVC_Handler.

struct
{
    uint32_t nc;
    uint16_t EnableIRQS;
    uint16_t DisableIRQS;
    uint16_t Enabling_FPU;
    uint16_t sRandom;
    uint16_t sTask_new;
    uint16_t Delete_Task;
    uint16_t sTask_wake_mc;
    uint16_t sDelay_new;
    uint16_t sTask_wait;
    uint16_t sTask_wake;
    uint16_t nil_in;
    uint16_t nil_exit;
    uint16_t sTask_list;
    uint16_t memory_donate;
    uint16_t memory_get;
    uint16_t nil_step;
    uint16_t swits;
};

A variant of the structure intended for union with the body of the function SVC_Handler.

The task is to get constants available for the preprocessor. The use of const union elements in the program code (functions and structures) is in the native form.