提问人:Charles 提问时间:4/18/2023 更新时间:4/18/2023 访问量:83
在 CCS 5.5.0 中,此代码中出现错误“预期表达式”的原因是什么?
What is the reason that I have an error "expected an expression" in this code in CCS 5.5.0?
问:
我最近开始学习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上打开文件,看看是否提出了任何解决方案,但声明了任何问题。 我验证了语法,但找不到错误。
答: 暂无答案
评论
for
int i;
for (i= 0; ...
for ( int i = 0; ...
for
i
i