1

我一直在为我的 Raspberry Pi B+ 开发一个“操作系统”(还不是真正的操作系统),当我处理数据输入时,我无法让 scanf() 工作,每次我将它包含到我的操作系统中,我的操作系统甚至没有启动。我搜索了很多网站,但似乎是我制造的一个错误(很可能),我不知道如何找到它,所以我请求大家帮助。我将提供所有需要的代码,所以如果您需要其他任何东西,请告诉我。

我的输入功能:

int _read(int file, char *buf, int len) {
    volatile int i;
    for(i = 0; i < len; i++)
    {
        buf[i] = RPI_GetChar();
        if(buf[i] == '\n')
        {
            return i;
        }
    }
    return i;
}

char RPI_GetChar(void)
{
    unsigned char in;
    unsigned char pot = 0;
    char out = 0;
    unsigned char confirm = false;
    unsigned char shift = false;
    while(!confirm)
    {
        in = RPI_UartRead();
        if(in & 0x80)
        {
            pot = in & 0x0F;
        }
        else
        {
            switch(in)
            {
            case 0:
                break;
            case 1:
                //Enter - Space
                if(shift)
                    return ' ';
                else{
                    return '\n';
                }
                break;
            case 2:
                //Shift - Select key
                if(shift)
                    confirm = true;
                else
                    shift = true;
                break;
            case 3:
                out = 97;
                break;
            case 4:
                out = 107;
                break;
            case 5:
                out = 117;
                break;
            case 6:
                if(shift)
                    out = 33;
                else
                    out = 48;
                break;
            case 7:
                break;
            }
        }
        sendChar(out+pot);
        mvCursor(getx()-1, gety());
    }
    mvCursor(getx()+1, gety());
    return out+pot;
}

我的标志:-O1 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -Wall

我已经解决了为 printf() 启用 VFP 的问题,所以它应该不是问题。

int kernel_main()
{
    initLCD();
    RPI_UartInit();
    char i = 'a';

    printf("Hi?\n");
    // Always when I add scanf to my code, my os does not start
    scanf("%c", &i); 
    printf("Hi %c\n", i);
    while(1);
}

我已经测试了相同的代码,但使用 getchar() 而不是 scanf(),它运行良好。RPI_GetChar() 本身没有任何问题。

谢谢你的帮助。(甚至没有启动我的意思是我的操作系统根本没有启动,就像 kernel_main 函数为空一样)

4

0 回答 0