这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » easyarm,d12 我想在easyarm上用d12

共2条 1/1 1 跳转至

easyarm,d12 我想在easyarm上用d12

院士
2006-09-17 18:14:16     打赏
easyarm,d12 我想在easyarm上用d12



关键词: easyarm     想在     上用    

院士
2006-12-22 22:43:00     打赏
2楼
问 我想在easyARM上用d12,你们提供的都是ucos上的代码,请问有没有不带操作系统的程序 1: 我自己改了一个D12Driver.c


#include "config.h"
#include "D12Config.h"
#include "D12CI.h"
#include "D12HAL.h"
#include "Chap_9.h"
#include "D12Driver.h"
#include "uart0.h"

extern EPPFLAGS bEPPflags;

unsigned char ssss[1024];

volatile unsigned char USB_setup_flag;

volatile unsigned char ep1_rx_ok;
unsigned char ep1_rx_buf[16];

volatile unsigned char ep1_tx_ok;
volatile unsigned char ep1_tx_max;
volatile unsigned char ep1_tx_cnt;
unsigned char *ep1_tx_buf;

volatile unsigned char  ep2_rx_ok;
volatile unsigned short ep2_rx_max;
volatile unsigned short ep2_rx_cnt;
unsigned char ep2_rx_buf[1024];

volatile unsigned char  ep2_tx_ok;
volatile unsigned short ep2_tx_max;
volatile unsigned short ep2_tx_cnt;
unsigned char *ep2_tx_buf;

void ep1_rxdone(void);
void ep1_txdone(void);
void ep2_rxdone(void);
void ep2_txdone(void);

unsigned char USB_write_port1(unsigned short len, unsigned char *buf)
{
    unsigned char length;

    ep1_tx_ok = 1;
    D12_ClearBuff(3);
    ep1_tx_buf = buf;            
    ep1_tx_max = len;            
    ep1_tx_cnt = 0;

    length = ep1_tx_max - ep1_tx_cnt;    
    if (length > 0)
    {                            
        if (length >= 16)
        {                    
            length = D12_WriteEndpoint(3, 16, buf + ep1_tx_cnt);
        }
        else                                    
        {
            length = D12_WriteEndpoint(3, length, buf + ep1_tx_cnt);
        }
        ep1_tx_cnt = ep1_tx_cnt + length;            
        
    }
    ep1_tx_ok = 0;
        
    return 0;                    
}    

unsigned char USB_write_port2(unsigned short len, unsigned char *buf)
{
    unsigned char i;
    unsigned short length;

    ep2_tx_ok = 1;
    D12_ClearBuff(5);
    ep2_tx_buf = buf;            
    ep2_tx_max  = len;            
    ep2_tx_cnt = 0;

    for (i= 0; i<2; i++)
    {                                        
        length = ep2_tx_max - ep2_tx_cnt;    
        if (length > 0)
        {                            
            if (length >= 64)
            {                    
                length = D12_WriteEndpoint(5, 64, buf + ep2_tx_cnt);
            }
            else                                    
            {
                length = D12_WriteEndpoint(5, (unsigned char)length, buf + ep2_tx_cnt);
            }
            ep2_tx_cnt = ep2_tx_cnt + length;            
            
        }
    }    
    ep2_tx_ok = 0;
        
    return 0;                    
}    

unsigned char Init_D12(void)
{
    unsigned short i;
    
    Init_D12Port();                            //初始化PDIUSBD12与LPC2200的连接的硬件配置
    Rst_D12();                                //复位PDIUSBD12
    reconnect_USB();                        //重新连接USB
    if (readchipid() != 0x1012){            //读取芯片ID号,如果不为 1012H
        return 1;                            //则复位失败
    }
    bEPPflags.value = 0;                    //初始化USB事件标志变量
     USB_setup_flag = 0;
     
     for (i=0; i<1024; i++)
     {
         ssss[i] = (unsigned char)i;
     }
     
     ep1_rx_ok = 0;
     ep1_tx_ok = 1;
     ep1_tx_cnt = 0;
     ep1_tx_max = 0;
     ep2_rx_ok = 0;
     ep2_rx_cnt = 0;
     ep2_rx_max = 1024;
     ep2_tx_ok = 1;
     ep2_tx_cnt = 0;
     ep2_tx_max = 0;
     
     return 0;                                
}

void bus_reset(void)
{
}

void dma_eot(void)
{
}

void USB_suspend(void)
{
}

void __irq USB_irq(void)
{
    unsigned short i_st;

    i_st = D12_ReadInterruptRegister();                //读取PDIUSBD12中断寄存器值
    
    if(i_st != 0) {
        if(i_st & D12_INT_BUSRESET)
            bus_reset();                            //总线复位处理
        if(i_st & D12_INT_EOT)
            dma_eot();                                //DMA传输技术处理
        if(i_st & D12_INT_SUSPENDCHANGE)
            USB_suspend();                            //总线挂起改变
        if(i_st & D12_INT_ENDP0IN)
            ep0_txdone();                            //控制端点发送数据处理
        if(i_st & D12_INT_ENDP0OUT)
            ep0_rxdone();                            //控制端点接收数据处理
        if(i_st & D12_INT_ENDP1IN)
            ep1_txdone();                            //端点 1发送数据处理
        if(i_st & D12_INT_ENDP1OUT)
            ep1_rxdone();                            //端点 1接收数据处理
        if(i_st & D12_INT_ENDP2IN)
            ep2_txdone();                            //端点 2发送数据处理
        if(i_st & D12_INT_ENDP2OUT)
            ep2_rxdone();                            //端点 2接收数据处理
    }
    CLR_INTD12();                                    //清除PDIUSBD12的中断标志
    CLR_INT();                                        //通知中断结束
}

void USB_task(void)
{
    unsigned char ack = 0x01;
    unsigned short i;
    
    if (USB_setup_flag == 1)
    {
        USB_setup_flag = 0;                 
        control_handler();                
    }
    if (ep1_rx_ok == 1)
    {
        for (i=0; i<8; i++)
        {
            uart0_putchar(ep1_rx_buf[i]);    
        }
        D12_ClearBuff(4);
        ep2_rx_cnt = 0;
          USB_write_port1(1, &ack);                    
         ep1_rx_ok = 0;    
    }
    if (ep2_rx_ok == 1)
    {
        //for (i=0; i<1024; i++)
        //{
        //    uart0_putchar(ep2_rx_buf[i]);    
        //}
        ep2_rx_cnt = 0;    
        //D12_ClearBuff(4);                
         ep2_rx_max = 1024;                    
        //USB_write_port2(1024, ep2_rx_buf);
         ep2_rx_ok = 0;    
    }
}

void ep1_rxdone(void)
{
    unsigned char len;
    
    D12_ReadLastTransactionStatus(2);               
    
    if (ep1_rx_ok == 0)
    {                                  
        len = (unsigned char)D12_ReadEndpoint(2, 16, ep1_rx_buf);
        
        if (len == 8)
        {    
            ep1_rx_ok = 1;
           }
    }
    else
    {
        D12_ClearBuff(2);
    }
}

void ep2_rxdone(void)
{
    unsigned char i;
    unsigned char endpstatus;
    unsigned short len;
    
    D12_ReadLastTransactionStatus(4);               
    
    if (ep2_rx_ok == 0)
    {                                  
        for (i=0; i<2; i++)
        {                                            
            len = ep2_rx_max - ep2_rx_cnt;  
            if (len > 0)
            {
                if (len >= 64)                                            
                {
                    len = (unsigned char)D12_ReadEndpoint(4, 64, ep2_rx_buf+ep2_rx_cnt);
                }
                else
                {
                    len = (unsigned char)D12_ReadEndpoint(4, len, ep2_rx_buf+ep2_rx_cnt);      
                }
                ep2_rx_cnt = ep2_rx_cnt + len;            
            }

            if (ep2_rx_cnt >= ep2_rx_max)
            {    
                ep2_rx_ok = 1;
                  break;
               }
            endpstatus = D12_ReadEndpointStatus(4);    
            if ((endpstatus & 0x60) == 0)
            {
                 break;        
            }
        }
    }
    else
    {
        D12_ClearBuff(4);
    }
}

void ep1_txdone(void)
{
    unsigned char len;
    unsigned char endpstatus;
    
    D12_ReadLastTransactionStatus(3);                    
    
    if (ep1_tx_ok == 0)
    {                                                            
        if (ep1_tx_cnt >= ep1_tx_max)
        {            
            endpstatus = D12_ReadEndpointStatus(3) & 0x60;
            if (endpstatus == 0)
            {                            
                ep1_tx_ok = 1;                    
            }
            else
                return;
        }
    }
    else
          return;
      
      if (ep1_tx_ok == 0)
      {                                    
        endpstatus = D12_ReadEndpointStatus(3) & 0x60;
        if (endpstatus == 0x60)
        {
              return;                    
        }    
        len = ep1_tx_max - ep1_tx_cnt;
        if (len > 0)
        {                                       
            if (len >= 16)
            {                               
                len = D12_WriteEndpoint(3, 16, ep1_tx_buf + ep1_tx_cnt);
            }
            else                                           
            {
                len = D12_WriteEndpoint(3, len, ep1_tx_buf + ep1_tx_cnt);  
            }
            ep1_tx_cnt = ep1_tx_cnt + len;                  
        }
    }
}

void ep2_txdone(void)
{
    unsigned short len;
    unsigned char  i,endpstatus;
    
    D12_ReadLastTransactionStatus(5);                    
    
    if (ep2_tx_ok == 0)
    {                                                            
        if (ep2_tx_cnt >= ep2_tx_max)
        {            
            endpstatus = D12_ReadEndpointStatus(5) & 0x60;
            if (endpstatus == 0)
            {                            
                ep2_tx_ok = 1;                    
            }
            else
                return;
        }
    }
    else
          return;
      
      if (ep2_tx_ok == 0)
      {                                    
        for (i=0; i<2; i++)
        {
            endpstatus = D12_ReadEndpointStatus(5) & 0x60;
            if (endpstatus == 0x60)
            {
                  break;                    
            }    
            len = ep2_tx_max - ep2_tx_cnt;
            if (len > 0)
            {                                       
                if (len >= 64)
                {                               
                    len = D12_WriteEndpoint(5, 64, ep2_tx_buf + ep2_tx_cnt);
                }
                else                                           
                {
                    len = D12_WriteEndpoint(5, len, ep2_tx_buf + ep2_tx_cnt);  
                }
                ep2_tx_cnt = ep2_tx_cnt + len;                  
            }
        }    
    }
}

void Init_D12Int(void)
{
    VICVectCntl1 = (0x20 | 0x0E);            //EINT0通道分配到IRQ slot 1
       VICVectAddr1 = (unsigned long)USB_irq;        //设置EINT0向量地址
       VICIntEnable = 1 << 14;                    //允许EINT0
}

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]