📄 test_usb.c
字号:
/* * test_usb.c -- demo of test usb chip_id application * * Author: li ming <lmcs00@mails.tsinghua.edu.cn> * Date: 2004-11-1 * Copyright: http://www.lumit.org */#include "led.h"#include <stdio.h>//#define SYSCFG (0x03ff0000)#define UART0_BASE (SYSCFG + 0xD000)#define UART1_BASE (SYSCFG + 0xE000)/* * Serial settings....................... */ #define ULCON 0x00 #define UCON 0x04#define USTAT 0x08#define UTXBUF 0x0C#define URXBUF 0x10#define UBRDIV 0x14/* * Line control register bits............ */ #define ULCR8bits (3)#define ULCRS1StopBit (0)#define ULCRNoParity (0)/* * UART Control Register bits............ */ #define UCRRxM (1)#define UCRRxSI (1 << 2)#define UCRTxM (1 << 3)#define UCRLPB (1 << 7)/* * UART Status Register bits */ #define USROverrun (1 << 0)#define USRParity (1 << 1)#define USRFraming (1 << 2)#define USRBreak (1 << 3)#define USRDTR (1 << 4)#define USRRxData (1 << 5) #define USRTxHoldEmpty (1 << 6)#define USRTxEmpty (1 << 7)#define GET_STATUS(p) (*(volatile unsigned *)((p) + USTAT))#define RX_DATA(s) ((s) & USRRxData)#define GET_CHAR(p) (*(volatile unsigned *)((p) + URXBUF))#define TX_READY(s) ((s) & USRTxHoldEmpty)#define PUT_CHAR(p,c) (*(unsigned *)((p) + UTXBUF) = (unsigned )(c))void delay(){ int i, j; for( i=0; i<50; i++ ) for ( j=0; j<65536; j++ ) ;}void loop( void ){ LED_1_ON; LED_2_ON; LED_3_ON; LED_4_ON; delay(); LED_1_OFF; LED_2_OFF; LED_3_OFF; LED_4_OFF; delay(); LED_1_ON; LED_2_ON; LED_3_ON; LED_4_ON;}int putchar_uart0(int ch){ /* Place your implementation of fputc here */ /* e.g. write a character to a UART, or to the */ /* debugger console with SWI WriteC */ while ( TX_READY(GET_STATUS(UART0_BASE))==0); PUT_CHAR(UART0_BASE, ch); return ch;}struct __FILE { int handle; /* Add whatever you need here */};FILE __stdout;int fputc(int ch, FILE *f){ /* Place your implementation of fputc here */ /* e.g. write a character to a UART, or to the */ /* debugger console with SWI WriteC */ putchar_uart0( ch ); return ch;}int ferror(FILE *f){ /* Your implementation of ferror */ return EOF;}void USBTest(void);//int main (void)void C_Entry( void ){ // set all gpio as output, so we can light leds. *(unsigned int *)0x03ff5000 = 0xffffffff; // set external bus width as 8-bits *(unsigned int *)0x3ff3010 = 0x0fdff556; USBTest(); printf( "Special thanks to gongxufei <gxf@sde.sgnec.com> for this great contribution \r\n" ); while(1);}/**************************************************************** * End of test_usb.c ****************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -