共2条
1/1 1 跳转至页
easyarm,d12 我想在easyarm上用d12
问
我想在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
}
#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 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【笔记】生成报错synthdesignERROR被打赏50分 | |
【STM32H7S78-DK评测】LTDC+DMA2D驱动RGBLCD屏幕被打赏50分 | |
【STM32H7S78-DK评测】Coremark基准测试被打赏50分 | |
【STM32H7S78-DK评测】浮点数计算性能测试被打赏50分 | |
【STM32H7S78-DK评测】Execute in place(XIP)模式学习笔记被打赏50分 | |
每周了解几个硬件知识+buckboost电路(五)被打赏10分 | |
【换取逻辑分析仪】RA8 PMU 模块功能寄存器功能说明被打赏20分 | |
野火启明6M5适配SPI被打赏20分 | |
NUCLEO-U083RC学习历程2-串口输出测试被打赏20分 | |
【笔记】STM32CUBEIDE的Noruletomaketarget编译问题被打赏50分 |