문제

안녕하세요 저는 작업을하고있는 게임에 대한 내 FPGA.나는 메시지 큐를 사용하여 여기에 내 문제는 내가 원할 때 인쇄하는 값 배열에서 나는 항상 같은 결과를 얻을 때에도 서로 다른 값을 넣어합니다.될 수 있 나는 그들을 인쇄하는 잘못된 또는 어쩌면 그들은 다시 얻을 할 때는 작업이 실행됩니다.

#define   MSG_QUEUE_SIZE  4
OS_EVENT  *msgqueue;
void      *msgqueue_tbl[MSG_QUEUE_SIZE];

int say_array[MSG_QUEUE_SIZE];
int idx,x;

// Interrupt Service Routine for KEY0-KEY3 IRQ
void isr_pio_key(void *context, alt_u32 id)
{
INT32U msg = IORD_ALTERA_AVALON_PIO_EDGE_CAP(PIO_KEY_BASE);

// Post message in queue
OSQPost(msgqueue, (void *)msg);

// Reset EDGE CAP
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_KEY_BASE, 0x01);
}

void key_pressed_task(void *pdata)
{
INT8U error_code = OS_NO_ERR;
INT32U msg;
OS_Q_DATA queue_data;
INT16U num_msgs;

int say_array[MSG_QUEUE_SIZE];

for(;;) {

    srand(time(NULL));
    int led = rand()%4;

    if(led == 3){
        IOWR_32DIRECT(PIO_LEDG_BASE,0,0x08);
        say_array[3] = led;
        idx++;
    }
    if(led == 2){
        IOWR_32DIRECT(PIO_LEDG_BASE,0,0x04);
        say_array[2] = led;
        idx++;
    }
    if(led == 1){
        IOWR_32DIRECT(PIO_LEDG_BASE,0,0x02);
        say_array[1] = led;
        idx++;
    }
    if(led == 0){
        IOWR_32DIRECT(PIO_LEDG_BASE,0,0x01);
        say_array[0] = led;
        idx++;
    }

    printf("%d",led);

    if(idx==4)
    {
        printf("\nSimon said: ");
        for(x=0;x<4;x++)
            printf("%d",say_array[x]);
        printf("\n");

        idx=0;
        for(;;)
        {
            OSQQuery(msgqueue, &queue_data);
            num_msgs = queue_data.OSNMsgs;

            if(num_msgs > 0)
            {
                msg = (INT32U)OSQPend(msgqueue, 4, &error_code);
                printf("msg: %d\n", msg);

                if((!error_code) && (msg == 1))
                    printf("(KEY_PRESSED_TASK) KEY0 Pressed\n");break;

                if((!error_code) && (msg == 2))
                    printf("(KEY_PRESSED_TASK) KEY1 Pressed\n");break;

                if((!error_code) && (msg == 4))
                    printf("(KEY_PRESSED_TASK) KEY2 Pressed\n");break;

                if((!error_code) && (msg == 8))
                    printf("(KEY_PRESSED_TASK) KEY3 Pressed\n");break;

                msg = 0;
            }
        }
    }
    OSTimeDlyHMSM(0,0,1,0);
}
}

int main()
{
// Create message queue
msgqueue = OSQCreate(&msgqueue_tbl[0], MSG_QUEUE_SIZE);

// Set up interrupts (mask KEY0)
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PIO_KEY_BASE, 0x0F);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_KEY_BASE, 0x01);
alt_ic_isr_register(PIO_KEY_IRQ_INTERRUPT_CONTROLLER_ID, PIO_KEY_IRQ, (void *)isr_pio_key, NULL, NULL);

// Create task
OSTaskCreate(key_pressed_task, NULL, &KEY_PRESSED_TASK_STACK[STACKSIZE-1], KEY_PRESSED_TASK_PRIO);

// Start uC/OS-II
OSStart();

// Shouldn't reach this point
return -1;

}

는 부분이 나에 대해 궁금은 이것입니다:

printf("\nSimon said: ");
for(x=0;x<4;x++)
printf("%d",say_array[x]);
printf("\n");

위의 코드는 인쇄해야하는 값을 설정하는 Led 가 켜져 있습니다.그러나 그것은 항상 인쇄 0123

어떤 아이디어가?

도움이 되었습니까?

해결책

for(;;) 루프에 당신은 항상 설정 say_array[led] = led;.I.e.면 led==3 당신이 설정 say_array[3] = 3.를 만드는 시도는 배열의 배열 부울 값을 전환하는 요소,예를 들어, say_array[led] = !say_array[led]; 또한 중 하나를 제거 say_array 정의,당신은 하나의 파일 범위에서 두 번째 함수 범위에서.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top