[ create a new paste ] login | about

Link: http://codepad.org/jdzUgDXg    [ raw code | fork ]

C, pasted on Jul 28:
int hm2_sserial_read_nvram_word(hostmot2_t *hm2, 
                                hm2_sserial_remote_t *chan, 
                                int addr,
                                int length,
                                void *data){
    u32 buff;
    buff = 0xEC000000;
    hm2->llio->write(hm2->llio, chan->reg_cs_addr, &buff, sizeof(u32));
    buff = 0x01;
    hm2->llio->write(hm2->llio, chan->reg_0_addr, &buff, sizeof(u32));
    buff = 0x1000 | (1 << chan->index);
    hm2->llio->write(hm2->llio, chan->command_reg_addr, &buff, sizeof(u32));
    if (0 > hm2_sserial_waitfor(hm2, chan->command_reg_addr, 0xFFFFFFFF, 1012)){
        HM2_ERR("Timeout in sserial_read_nvram_word(2)\n");
        goto fail0;
    }
    switch (length){
        case 1:
            buff = 0x44000000 + addr; break;
        case 2:
            buff = 0x45000000 + addr; break;
        case 4:
            buff = 0x46000000 + addr; break;
        default:
            HM2_ERR("Unsupported global variable bitlength");
            return -EINVAL;
    }
    hm2->llio->write(hm2->llio, chan->reg_cs_addr, &buff, sizeof(u32));
    buff = 0x1000 | (1 << chan->index);
    hm2->llio->write(hm2->llio, chan->command_reg_addr, &buff, sizeof(u32));
    if (0 > hm2_sserial_waitfor(hm2, chan->command_reg_addr, 0xFFFFFFFF, 1013)){
        HM2_ERR("Timeout in sserial_read_nvram_word(4)\n");
        goto fail0;
    }
    hm2->llio->read(hm2->llio, chan->reg_0_addr, data, sizeof(u32));
    
fail0: // attempt to set back to normal access
    buff = 0xEC000000;
    hm2->llio->write(hm2->llio, chan->reg_cs_addr, &buff, sizeof(u32));
    buff = 0x00;
    hm2->llio->write(hm2->llio, chan->reg_0_addr, &buff, sizeof(u32));
    buff = 0x1000 | (1 << chan->index);
    if (0 > hm2_sserial_waitfor(hm2, chan->command_reg_addr, 0xFFFFFFFF, 1014)){
        HM2_ERR("Timeout in sserial_read_nvram_word(6)\n");
        return -EINVAL;
    }
    return 0;
}  


Create a new paste based on this one


Comments: