在 CCS 5.5.0 中,此代码中出现错误“预期表达式”的原因是什么?

What is the reason that I have an error "expected an expression" in this code in CCS 5.5.0?

提问人:Charles 提问时间:4/18/2023 更新时间:4/18/2023 访问量:83

问:

我最近开始学习C语言。 我必须完成一个 Goertzel 算法来检测 data.bin 文件中是否存在 8 个频率。我正在研究 CCS 5.5.0。 但是在下面的代码中,我在我的for循环开始的两行都出现了错误“#29 expected an expression”。 当然,代码还没有完成,它只是代码的一部分。但我认为这更像是语法问题,但我找不到它。 谢谢!

/*
 *  ======== gtz.c ========
 */

#include <xdc/std.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>

#include <xdc/runtime/Types.h>
#include <xdc/runtime/Timestamp.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "gtz.h"

void clk_SWI_Read_Data(UArg arg0);
void clk_SWI_GTZ_All_Freq(UArg arg0);

extern void task0_dtmfGen(void);
extern void task1_dtmfDetect(void);

extern int sample, tdiff, tdiff_final, gtz_out[8];
extern short coef[8];
extern int flag;

short data[NO_OF_SAMPLES];
short *buffer;
static int i;

/*
 *  ======== main ========
 */
int main() {
    System_printf("\n System Start\n");
    System_flush();

    /* Read binary data file */
    FILE* fp = fopen("../data.bin", "rb");
    if(fp==0) {
        System_printf("Error: Data file not found\n");
        System_flush();
        return 1;
    }
    fread(data, 2, NO_OF_SAMPLES, fp);
    buffer = (short*)malloc(2*8*10000);

    /* Create a Clock Instance */
    Clock_Params clkParams;

    /* Initialise Clock Instance with time period and timeout (system ticks) */
    Clock_Params_init(&clkParams);
    clkParams.period = 1;
    clkParams.startFlag = TRUE;

    /* Instantiate ISR for tone generation  */
    Clock_create(clk_SWI_Read_Data, TIMEOUT, &clkParams, NULL);

    /* Instantiate 8 parallel ISRs for each of the eight Goertzel coefficients */
    Clock_create(clk_SWI_GTZ_All_Freq, TIMEOUT, &clkParams, NULL);

    /* Start SYS_BIOS */
    BIOS_start();
}

/*
 *  ====== clk_SWI_Generate_DTMF =====
 *  Dual-Tone Generation
 *  ==================================
 */
void clk_SWI_Read_Data(UArg arg0) {
    static int tick;
    tick = Clock_getTicks();
    sample = data[tick%NO_OF_SAMPLES];
}

/*
 *  ====== clk_SWI_GTZ =====
 *  gtz sweep
 *  ========================
 */
void clk_SWI_GTZ_All_Freq(UArg arg0) {
    // define variables for timing
    static int start, stop;

    // define feedback times as N
    static int N = 0;

    //Record start time
    start = Timestamp_get32();

    short input = (short) (sample);

    //static int number_bits_used;
    //static float normalized_value_coef1;

    int Goertzel_values[8] = {0,0,0,0,0,0,0,0};
    short delay_values[8] = {0,0,0,0,0,0,0,0};
    short delay_1_values[8] = {0,0,0,0,0,0,0,0};
    short delay_2_values[8] = {0,0,0,0,0,0,0,0};
    short prod1_values[8] = {0,0,0,0,0,0,0,0};
    short prod2_values[8] = {0,0,0,0,0,0,0,0};
    short prod3_values[8] = {0,0,0,0,0,0,0,0};

    int R_in = sample;
    input = (short) R_in;
    input = input>>4;

    input = (short)sample;
    input = input>>4;

    /*
     * TODO 1. Complete the feedback loop of the GTZ algorithm */
    /* ========================= */

    for (int i=0; i<8; i++){ // **Where the error appears**
        prod1_values[i] = (delay_1_values[i] * coef[i]) >> 14;
        delay_values[i] = input + (short) prod1_values[i] - delay_2_values[i];
        delay_2_values[i] = delay_1_values[i];
        delay_1_values[i] = delay_values[i];
    }
    N++;
    /* ========================= */

    //Record stop time
    stop = Timestamp_get32();
    //Record elapsed time
    tdiff = stop-start;

    if (N == 206) {
        //Record start time
        start = Timestamp_get32();

        /* TODO 2. Complete the feedforward loop of the GTZ algorithm*/
        /* ========================= */
        for (int i=0; i<8; i++){ 
            prod1_values[i] = (delay_1_values[i] * delay_1_values[i]) >> 14;
            prod2_values[i] = (delay_2_values[i] * delay_2_values[i]) >> 14;
            prod3_values[i] = (delay_1_values[i] * coef[i]) >> 14;
            prod3_values[i] = prod3_values[i] * delay_2_values[i];

            Goertzel_values[i] =prod1_values[i]+prod2_values[i] - prod3_values[i];
            Goertzel_values[i] <<= 4;
            gtz_out[i] = Goertzel_values[i];
        }
        /* gtz_out[..] = ... */
        /* gtz_out[..] = ... */
        /* ========================= */
        flag = 1;
        N = 0;

        //Record stop time
        stop = Timestamp_get32();
        //Record elapsed time
        tdiff_final = stop-start;
    }
}

我试图在VSCODE上打开文件,看看是否提出了任何解决方案,但声明了任何问题。 我验证了语法,但找不到错误。

c 语法错误 goertzel 算法

评论

0赞 Weather Vane 4/18/2023
您使用的是什么编译器?古代编译器可能不允许使用循环语法。for
0赞 Gerhardh 4/18/2023
欢迎来到 SO。你使用什么编译器?您选择什么 C 标准?如果在该循环之前定义并使用 代替 ?在循环中定义变量是在 C99 中引入的。你使用旧版本吗?int i; for (i= 0; ...for ( int i = 0; ...for
2赞 Vlad from Moscow 4/18/2023
@Charles 尝试在 for 循环之前声明变量 i,例如 int i;在循环中写 for ( i = 0; i < 8; i++ )
3赞 Allan Wind 4/18/2023
全局变量是一个非常糟糕的主意,局部阴影(覆盖)该全局变量。ii
1赞 Charles 4/18/2023
感谢您的回复,我使用 C6000 编译器。好的,我改变了并把 int i;before 和 i=0 在循环中,它起作用了。我在大学里学习一门课程,老师坚持使用这个旧版本,所以我现在别无选择,但我会在之后切换。非常感谢!

答: 暂无答案