This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I got the following issue. When I copy one int my main code it works fine. only when the data is a struct then result is zero
struct CLA_Estdata_
{
MOSPROF_State state;
int speed_hz;
motorpos_t position_cnt;
float Torque;
int counter;
};
typedef struct CLA_RESdata_ volatile CLA_RESdata_t;
Cla:
#pragma DATA_SECTION(CLA_estdata,"Cla1ToCpuMsgRAM")
volatile CLA_Estdata_t CLA_estdata;
#pragma DATA_SECTION(CLA_test,"Cla1ToCpuMsgRAM")
volatile int CLA_test;
__interrupt void Cla1Task4 ( void )
{ CLA_estdata.counter++;
CLA_test++;
}
Main code:
static inline CLA_Update_clafreq (void)
{
extern volatile CLA_Estdata_t CLA_estdata;
extern volatile int CLA_test;
extern long volatile CLA_Freq;
CLA_Freq=CLA_test;
}
result CLA_freq is updated every time with a new value
static inline CLA_Update_clafreq (void)
{
extern volatile CLA_Estdata_t CLA_estdata;
extern volatile int CLA_test;
extern long volatile CLA_Freq;
CLA_Freq=CLA_estdata.counter;
}
result: CLA_Freq is always zero. In the debug window I see CLA_estdata.counter is counting. So CLA_estdata.counter is filled with the correct data so why can't the cpu get access to it.
Someone a suggestion how to solve this? What is the difference between a single variable and a struct?
There are no changes between the two tests then there except which variable is stored in CLA_FREQ. and in the debug window I can see the cla fill the variables correctly.
So what is the difference between the cla and cpu? The only thing I could find is memory bus width. So I start re-arranging the struct and made all the variables 32 bit width. After that it starts works.
So I thing you got there an issue there in the compiler. Only the last time I reported a problem. The best TI can do is suggesting to manual modify the asm code to get it working. So that is useless.
So is there a compiler directive to tell the cpu the struct is 32 bit aligned?
Thanks!
Hi,
Because the structure is defined by the C28x, the elements of the structure are the size defined by the C28x compiler. Enumerated types and integers will have a different size on the C28x than the CLA. On the C28x, they are 16-bits. On the CLA, they are 32-bits.
See Section 10.2 of the This is the Optimizing C/C++ Compiler User's Guide
Because of the above, it appears the CLA compiler was grabbing memory which was initialized to zero. Perhaps it was reading counter from memory which was past the declaration of the structure elements. Can you confirm this, please?
Regards,
sal
Sal Pezzino said:If you use data types which define the memory size, I think it would work even if you used 16-bits types. You can try declaring the structure using standard data types like: int16_t, uint16_t, int32_t, float32_t, etc.
Hope this helps,
sal
stdint.h
typedef int int16_t;
typedef unsigned int uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
If you didn't know that .Please forward my problem to someone more senior.
If I change the order of the variable of the struct in the CLA. I can change the result of the output. I think that is an issue. I have a lot of issues reading data back from CLA so I spend a couple of days debugging it. There is an issue with 32 bit vs 16 bit data width in data structures in the compiler. It is easy to reproduce.
Bonus: also check the sizeof a enum for cpu and cla. If you set a value at the enum at the cpu. The CLA can read something else. Because the cpu can't set the higher 16 bit word enum of the CLA data field. at Init there can be a random value. And the cpu can't change it.