Rabbit 4000 プロセッサでステッピング モーターを回転させようとしています。構造体を保持するキューがあり、4 巻線ステッピング モーターを実行するために必要なバイナリ ビットのシーケンスを作成する関数を作成しました。構造体内の関数からキューを埋めるプロデューサーにシーケンスを渡そうとしています。問題は、期待値がキューに入れられないことです。関数から構造体を返す方法を誤解していますか、それとも配列値を個別に割り当てる必要がありますか? 関連するコードのチャンクは次のとおりです。
typedef struct {
char d[4];
int delayUs;
} mQueueEntry_t;
mQueueEntry_t setDirStep(int count0, int count1, int count2, int count3){
mQueueEntry_t entry;
entry.d[0] = (!((count0+1)%4)); //1a
entry.d[1] = (!((count1+1)%4)); //1b
entry.d[2] = (!((count2+1)%4)); //2a
entry.d[3] = (!((count3+1)%4)); //2b
entry.delayUs =10;
printf("Breaking Funct with: %d,%d,%d,%d\n",entry.d[0], entry.d[1], entry.d[2], entry.d[3]);
}
// continually stuff a queue with a dedicated structure
void Producer(void* pdata){
mQueueEntry_t entry;
int count0 = 3;
int count1=1;
int count2=2;
int count3=0;
labQueue_t * q = (labQueue_t *) pdata; // Note use of task data..
printf("Hola Producer\n");
while (1)
{
entry = setDirStep(count0, count1, count2, count3);
printf("Values after funct call: %d,%d,%d,%d\n",entry.d[0], entry.d[1], entry.d[2], entry.d[3]);
count0++;
count1++;
count2++;
count3++;
// send a copy of the element and
switch ( labQueuePut( q, &entry) ){
case LABQ_OK:
printf("put %d,%d,%d,%d\n",entry.d[0], entry.d[1], entry.d[2], entry.d[3]);
break;
case LABQ_TIMEOUT:
OSTimeDly(OS_TICKS_PER_SEC/10);
break;
case LABQ_FULL:
OSTimeDly(OS_TICKS_PER_SEC/10);
break;
default:
assert(0);
break;
}
OSTimeDly(1);
}
}
プログラムの画面出力:
Hola Consumer
Hola Producer
Breaking Funct with: 1,0,0,0 関数
呼び出し後の値: 235,0,24,23
受信 (1a= 0: 1b= 1: 2a= 0:2b= 0) 0
put 235,0 ,24,23
Breaking Funct with: 0,0,1,0
funct 呼び出し後の値: 236,41,237,0
受信 (1a= 0: 1b= 0: 2a= 0:2b= 1) 1
put 236,41,237,0
私の問題は、関数呼び出し後の値が同じであると予想される関数を壊すことから値にあることです。