⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.c

📁 本source code 為s3c4510的bootloader
💻 C
📖 第 1 页 / 共 5 页
字号:
   RxQ[cn].cnt  = 0;			// Rx Queue bytes count   UART_ERR[cn].overrun = 0; 		// clear overrun error count   UART_ERR[cn].parity  = 0;		// clear parity error count   UART_ERR[cn].frame   = 0;		// clear frame error count   UART_ERR[cn].brdet   = 0;		// break detected// clear UART0/UART1 Rx & Tx buffers ///////////////////////////////////////////     for(pos = 0; pos < MAXEVENT; ++pos)     {     TxQ[cn].buff[pos] = 0xFF;     RxQ[cn].buff[pos] = 0xFF;    }  }//////////////////////////////////////////////////////////////////////////////// for(uartbrd = 0; uartbrd < BAUD_TABLE_SIZE; ++uartbrd)   {    if(BaudTable[uartbrd].baud == baudrate) {			      break;				//     }  } if(uartbrd < BAUD_TABLE_SIZE)  {// baudrate find in table //////////////////////////////////////////////////////   uartbrd = BaudTable[uartbrd].div;  } else  {   uartbrd = BaudTable[0].div;  }//  UARTBRD0  = uartbrd; 			// UART0 baud rate register UARTBRD1  = uartbrd; 			// UART1 baud rate register #ifdef _KS32C50100_// system compiled with KS32C50100 support ///////////////////////////////////// if((SYSCFG & 0x0C000000) != 0x0C000000)   {   U32 stat;// (product id != S3C4530) => KS32C50100 ///////////////////////////////////////// UARTLCON0 & UARTLCON1 content // (Uart Line control register content) ///////    UARTLCON1 = UARTLCON0 = 		//     UARTLCON_WL8    | 			// word length = 8 bits    UARTLCON_PMD_NO | 			// parity mode = no oarity #ifdef EX_UCLK      UARTLCON_UCLK;      		// external clock,29.4912MHz#else    0;           			// internal clock#endif// UARTCONT0 & UARTCONT1 content ///////////////////////////////////////////////    UARTCONT1 = UARTCONT0 =     UARTCON_RXM_INTREQ | 		// rx mode = int req    UARTCON_TXM_INTREQ |		// tx mode = int req	    UARTCON_RXSTAT_INT;			// Rx Status () Interrupt   SysSetInterrupt(nUART0_TX_INT    , S3C4510_Uart0TxISR);    // UART 0 tx int    SysSetInterrupt(nUART1_TX_INT    , S3C4510_Uart1TxISR);    // UART 1 tx int   SysSetInterrupt(nUART0_RX_ERR_INT, S3C4510_Uart0RxErrISR); // UART 0 rx int    SysSetInterrupt(nUART1_RX_ERR_INT, S3C4510_Uart1RxErrISR); // UART 1 rx int     stat = UARTSTAT0;   stat = UARTSTAT1;  }#endif#ifdef _S3C4530_// compiled with S3C4530 support /////////////////////////////////////////////// if((SYSCFG & 0x0C000000) == 0x0C000000)   {   U32 stat;// lo bits of PID = 11 => s3C4530 //////////////////////////////////////////////    UCON1 = UCON0 =     UCON_TMODE_INTREQ | 		// transmit mode = int request     UCON_RMODE_INTREQ | 		// receive mode = int request #ifdef EX_UCLK      UCON_UCLK         |#endif    UCON_TFEN  	      |			// transmit fifo enable     UCON_RFEN  	      |			// receive  fifo enable    UCON_TFRST 	      |			// transmit fifo reset     UCON_RFRST        |			// receive  fifo reset     UCON_RFTL_1	      | 		/* 00 = 1-byte vaild/32-byte */    UCON_TFTL_8       |			/* 00 = 30-byte empty/32-byte */		    UCON_WL8;				// word length = 8 bit//   UINTEN1 = UINTEN0 =     UINTEN_THEIE |			/* enable transmit holding reg empty */     UINTEN_RDVIE |			/* Enable UART1 Rx Interrupt */    UINTEN_BSDIE |			/* break signal detected */    UINTEN_FERIE |			// frame error int en    UINTEN_PERIE |			// parity error int en    UINTEN_OERIE; 			// overrun int en   SysSetInterrupt(nUART0_TX_INT    , S3C4530_Uart0TxISR);    // UART 0 tx int    SysSetInterrupt(nUART1_TX_INT    , S3C4530_Uart1TxISR);    // UART 1 tx int   SysSetInterrupt(nUART0_RX_ERR_INT, S3C4530_Uart0RxErrISR); // UART 0 rx int    SysSetInterrupt(nUART1_RX_ERR_INT, S3C4530_Uart1RxErrISR); // UART 1 rx int     stat = USTAT0;   stat = USTAT1;  } #endif// Enable_Int(nGLOBAL_INT);  		// Global interrupt disabled return(1);}////////////////////////////////////////////////////////////////////////////////// set UART0/1 speed ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int UARTSetSpeed(U32 channel, int speed){ U32 pos;				 if(channel > 1)  {   return(0);  }  for(pos = 0; pos < BAUD_TABLE_SIZE; ++pos)   {   if(BaudTable[pos].baud == speed)    {			// baudrate find in table //////////////////////////////////////////////////////     pos = BaudTable[pos].div;     if(channel == 0)      {       UARTBRD0 = pos; 			// UART0 baud rate register      }     else      {       UARTBRD1 = pos; 			// UART1 baud rate register       }//     return(1);    }  } return(0);}int UARTGetSpeed(U32 channel){ U32 uartbrd;				// UARTBRD content  U32 pos;				// BRD table index // if(channel == 0)  {   uartbrd = UARTBRD0; 			// UART0 baud rate register  } else if(channel == 1)  {   uartbrd = UARTBRD1; 			// UART1 baud rate register   } else  {   return(0);  }  for(pos = 0; pos < BAUD_TABLE_SIZE; ++pos)   {   if(BaudTable[pos].div == uartbrd)    {			     return(BaudTable[pos].baud);    }  }// return(0);}////////////////////////////////////////////////////////////////////////////////// wait transmit complete //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int UARTWaitTxComp(int ch){ if(ch == 0)   {#ifdef _S3C4530_    if(is_s3c4530(syscfg_pd_id)) {      while( (USTAT0 & USTAT_THE) == 0 ) {;}    } else {      while( (UARTSTAT0 & UARTSTAT_TXB_EMPTY) == 0 ) {;}    }#else       while( (UARTSTAT0 & UARTSTAT_TXB_EMPTY) == 0 ) {;}#endif  } else  if(ch == 1)  {#ifdef _S3C4530_    if(is_s3c4530(syscfg_pd_id)) {      while( (USTAT1 & USTAT_THE) == 0 ) {;}    } else {      while( (UARTSTAT1 & UARTSTAT_TXB_EMPTY) == 0 ) {;}    }#else       while( (UARTSTAT1 & UARTSTAT_TXB_EMPTY) == 0 ) {;}#endif  }  else  {   return(0);	  }//  return(1);}//////////////////////////////////////////////////////////////////////////////////// set UART channel loop back mode ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ch = channel numberint UARTSetLoopBack(int ch, int on){ if(ch == 0)   {// UART0 ///////////////////////////////////////////////////////////////////////   if(on == 1)     {					// UART0 set loop back mode        U32 err;#ifdef _S3C4530_ 	     if(is_s3c4530(syscfg_pd_id)) {	// S3C4530 family       UCON0 |= UCON_LOOPB | UCON_TFRST | UCON_RFRST;     } else {       UARTCONT0 |= UARTCON_LOOPBACK;	// KS32C50100     }#else       UARTCONT0 |= UARTCON_LOOPBACK;#endif       for(err = 0; err < 10000; ++err) {;}       err = UARTRXB0;    }    else     {					// UART0 clear loop back mode #ifdef _S3C4530_ 	     if(is_s3c4530(syscfg_pd_id)) {	// S3C4530 family       UCON0     &=~UCON_LOOPB;     } else {       UARTCONT0 &=~UARTCON_LOOPBACK;     }#else       UARTCONT0 &=~UARTCON_LOOPBACK;#endif    }// end UART0 processing ////////////////////////////////////////////////////////  } else if(ch == 1)  {					// UART1 ///////////////////////////////////////////////////////////////////////   if(on == 1)     {					// UART1 set loop back mode        U32 err;#ifdef _S3C4530_     if(is_s3c4530(syscfg_pd_id)) {	// S3C4530 family       UCON1 |= UCON_LOOPB | UCON_TFRST | UCON_RFRST;     } else {       UARTCONT1 |= UARTCON_LOOPBACK;	//      }#else     UARTCONT1 |= UARTCON_LOOPBACK;	//#endif								/* _S3C4530_ */       for(err = 0; err < 10000; ++err) {;}       err = UARTRXB1;    }    else     {					// UART1 clear loop back mode #ifdef _S3C4530_     if(is_s3c4530(syscfg_pd_id)) {	// S3C4530 family       UCON1     &=~UCON_LOOPB;     } else {       UARTCONT1 &=~UARTCON_LOOPBACK;     }#else       UARTCONT1 &=~UARTCON_LOOPBACK;#endif								/* _S3C4530_ */     }// UART1 ///////////////////////////////////////////////////////////////////////  } else  {   return(0);  } //  return(1);}////////////////////////////////////////////////////////////////////////////////// Enable UART0/1 Tx interrupt, Set UART0/1 Tx Interrupt pending bit ///////////////////////////////////////////////////////////////////////////////////////////void UARTTxIntOn(int channel){ if(channel == 1)   {/* Enable Interrupt, Set pending Bit for UART1 */   Enable_Int(nUART1_TX_INT);		/* INTMASK &= ~(1<<(n)) */#ifdef _S3C4530_ 	   if(is_s3c4530(syscfg_pd_id)) {	//      U32 stat;				//      UCON1 |= UCON_TFRST;		//      stat   = USTAT1;			//    }#endif     							/* _S3C4530_ */  } else  if(channel == 0)   {   Enable_Int(nUART0_TX_INT);#ifdef _S3C4530_ 	   if(is_s3c4530(syscfg_pd_id)) {	//      U32 stat;				//      UCON0 |= UCON_TFRST;		//      stat   = USTAT0;			//    } #endif     							/* _S3C4530_ */  }}////////////////////////////////////////////////////////////////////////////////// Enable UART0/1 Rx/Status Interrupt //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void UARTRxIntOn(int channel){ if(channel == 1)   {   Enable_Int(nUART1_RX_ERR_INT);#ifdef _S3C4530_ 	   if(is_s3c4530(syscfg_pd_id)) {     U32 stat;	     UCON1 |= UCON_RFRST;	     stat   = USTAT1;   }#endif     							/* _S3C4530_ */   } else  if(channel == 0)  {   Enable_Int(nUART0_RX_ERR_INT);#ifdef _S3C4530_ 	   if(is_s3c4530(syscfg_pd_id)) {     U32 stat;     UCON0 |= UCON_RFRST;     stat   = USTAT0;   }#endif     							/* _S3C4530_ */	  }}////////////////////////////////////////////////////////////////////////////////// Diasable UART0/1 Tx Interrupt, Clear UART0/1 Tx Interrupt pending bit ///////////////////////////////////////////////////////////////////////////////////////void UARTTxIntOff(int channel){ if(channel == 1)   {   Disable_Int(nUART1_TX_INT);   TxQ[1].wptr = 0;			// UART1 Tx Queue write pointer 	   TxQ[1].rptr = 0;			// UART1 Tx Queue read pointer    TxQ[1].cnt  = 0;			// UART1 Tx Queue bytes count  } else  if(channel == 0)  {/* Disable Interrupt */   Disable_Int(nUART0_TX_INT);   TxQ[0].wptr = 0;			// UART0 Tx Queue write pointer 	   TxQ[0].rptr = 0;			// UART0 Tx Queue read pointer    TxQ[0].cnt  = 0;			// UART0 Tx Queue bytes count  }}////////////////////////////////////////////////////////////////////////////////// Disable UART0/1 Rx&Status Interrupt /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void UARTRxIntOff(int channel){ if(channel == 1)   {// UART0 ///////////////////////////////////////////////////////////////////////   Disable_Int(nUART1_RX_ERR_INT);	// disable UART1 rx & error int   RxQ[1].wptr = 0;			// UART1 Rx Queue write pointer 	   RxQ[1].rptr = 0;			// UART1 Rx Queue read pointer    RxQ[1].cnt  = 0;			// UART1 Rx Queue bytes count }else if(channel == 0)  {  Disable_Int(nUART0_RX_ERR_INT);  RxQ[0].wptr = 0;			// UART0 Rx Queue write pointer 	  RxQ[0].rptr = 0;			// UART0 Rx Queue read pointer   RxQ[0].cnt  = 0;			// UART0 Rx Queue bytes count }}////////////////////////////////////////////////////////////////////////////////// read byte in interrupt mode /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int i_getc(int channel, U8 * ch){ if(channel < 0 || channel > 1 || ch == 0)  {   return(0);  }  if(RxQ[channel].cnt == 0)   {						// Rx buffer empty	   return(0);					// read byte failure  } if(RxQ[channel].rptr >= MAXEVENT) {   RxQ[channel].rptr = 0; 			// loop back } *ch = RxQ[channel].buff[RxQ[channel].rptr];  // read byte from Rx buffer  RxQ[channel].buff[RxQ[channel].rptr] = 0xFF; RxQ[channel].rptr++;//  Disable_Int(channel ? nUART1_RX_ERR_INT : nUART0_RX_ERR_INT);  RxQ[channel].cnt--; Enable_Int (channel ? nUART1_RX_ERR_INT : nUART0_RX_ERR_INT);  return(1);					// }////////////////////////////////////////////////////////////////////////////////// write byte in interrupt mode ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int i_putc(int channel, U8 ch){ U32 stat;				// status registyer content  if(channel < 0 || channel > 1){   return(0); } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -