|
发表于 2010-12-20 16:23:31
|
显示全部楼层
以PIO12为例,C程序里面设置:
PioSetDir(1<<12,0);
PioSetKalimba(1<<12,~0);
PioSetDirKalimba(1<<12,0); startKalimba();
DSP程序:
//read pio state
//This module used register r1,r2
//return r2
.MODULE $M.read_pio_state;
.CODESEGMENT PM;
.DATASEGMENT DM;
$read_pio_state:
// push rLink onto stack
$push_rLink_macro;
r2 = M[$PIO_IN];
r2 = r1 AND r2;
M[$read_pio_result] = r2;
// pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE;
// set pio to high
//This module used register r1,r2
.MODULE $M.set_pio_high;
.CODESEGMENT PM;
.DATASEGMENT DM;
$set_pio_high:
// push rLink onto stack
$push_rLink_macro;
r3 = r1;
r2 = 0xffffff;
r2 = r2 XOR r1; //bit reverse.
r1 = M[$PIO_DIR];
r1 = r1 AND r2;
M[$PIO_DIR] = r1;
r1 = r3;
r2 = M[$PIO_OUT];
r2 = r2 OR r1;
M[$PIO_OUT] = r2;
// pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE;
// set pio to low
//This module used register r1,r2
.MODULE $M.set_pio_low;
.CODESEGMENT PM;
.DATASEGMENT DM;
$set_pio_low:
// push rLink onto stack
$push_rLink_macro;
r2 = M[$PIO_DIR];
r2 = r2 OR r1;
M[$PIO_DIR] = r2;
r2 = 0xffffff;
r2 = r2 XOR r1; //bit reverse.
r1 = M[$PIO_OUT];
r1 = r1 AND r2;
M[$PIO_OUT] = r1;
// pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE; |
|