arwei的笔记 https://bbs.21ic.com/?110034 [收藏] [复制] [RSS]

日志

MICROBLAZE的UART_LITE驱动

已有 775 次阅读2009-11-19 01:38 |系统分类:EDA/PLD| MB基础驱动

这是刚刚根据数据手册写的一个UART—LITE驱动。



#define DEF_UART_CTLR_ADDR 0x84000000


static unsigned int BASE_UART_ADDR = DEF_UART_CTLR_ADDR  ;
static unsigned int init = 0 ;


static void init_uart(unsigned int addr)
{
BASE_UART_ADDR = addr;
if (addr==0)
BASE_UART_ADDR = DEF_UART_CTLR_ADDR ;
init=1; 
*(unsigned int volatile *)(BASE_UART_ADDR + 0xc) = 0;
}


unsigned char lw_getc(void){
 unsigned char ret ;
   if (init==0)init_uart(0);
   while(!(*(unsigned int volatile *)(BASE_UART_ADDR + 0x8) & (1 << (31 - 31))));//wait when rx FIFO is emputy
   ret = *(unsigned int volatile *)(BASE_UART_ADDR  );return ret;
}
        
void  lw_putc( unsigned char  ch){ 
  if (init==0)init_uart(0);
   while((*(unsigned int volatile *)(BASE_UART_ADDR + 0x8) & (1 << (31 - 28))));//wait when tx FIFO is full
         *(unsigned int  volatile *)(BASE_UART_ADDR  + 4  )= ch ;
}


 


 


使用一下程序进行测试:


int i;
char hex[]={"0123456789abcedfghijklmp" };


int main (void) {


for(;;)
{
lw_putc(lw_getc());
}


/*
for(i=0;;){
i+=1;
i=i%10 ;
lw_putc(hex);
}
*/
}


 


测试通过。



 


 


 


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)