器件型号:BEAGLEBK
工具/软件:TI C/C++编译器
您好!
我正在优化 BeagleBoneBlack 上的 PRU 状态机。
执行状态代码和更改状态的经典方法是一个 big switch()语句,如下所示:
#define State_stop 0
#define State_A 1.
#define State_B 2.
#define State_C 3.
(笑声)
int statemachine (int state){
switch (state){
案例 State_A:
do 什么东西();
if (some 条件)
返回 State_B;
其他
返回 State_stop;
用例 State_B:
(笑声)
。
}
}
main(){
(笑声)
STATE = State_A;
while (state = statmachine(statstate));
(笑声)
}
我看到 PRU-ICSS clpru 编译器(此处为2.3.1)编译了"switch()…… 案例"作为测试列表、如此伪代码
如果(状态= 1)则如此
(笑声)
否则、如果(状态= 2)则为
…
否则、如果(状态= 3)则为
(笑声)
由于我在这里有一些情况、这个测试链占用了 PRU 执行时间的一部分。
如果使用一个"计算得到的 gotos"数组、可以生成更快的代码。 GCC 支持将其作为"labels as values"扩展名、如以下堆栈溢出示例中所示:
<fastcode>
int main(){
int value = 2;
const void *labels[] = {&&val_0, &&val_1, &&val_2};
goto *labels[value];
val_0:
printf("The value is 0\n");
goto end;
val_1:
printf("The value is 1\n");
goto end;
val_2:
printf("The value is 2\n");
goto end;
end:
return(0);
}
</fastcode>
"Labels as values" is a strange feature of course, its justification seems limited to writing zero-overhead command processors.
Sadly, the "Labels as values" extension seems not supported in clpru 2.3.1 ... clpru complains like
Invoking: PRU Compiler
..... /ti-cgt-pru_2.3.1//bin/clpru --include_path= ....
"pru1_statemachine_data_slave.c", line 51: error #1489: GCC && operator not
supported
const void* labelarray[] = &&lab1, &&lab2, &&lab3} ;
Any chance to get "labels as values" implemented in clpru?
best regards,
Joerg