//-------------------------SCI_OutChar------------------------ // Wait for buffer to be empty, output 8-bit to serial port // interrupt synchronization // Input: SCI port, 8-bit data to be transferred // Output: none void SCI_OutChar(unsigned char port, char data){ #if HISTOGRAM TxHistogram[port][TxFifo_Size(port)]++; // analysis of FIFO #endif while (TxFifo_Put(port, data) == 0){}; // spin if TxFifo is full if(port==0) SCI0CR2 = 0xAC; /* arm TDRE */ if(port==1) SCI1CR2 = 0xAC; /* arm TDRE */ }
// output ASCII character to UART // block if TxFifo is full void UART_OutChar(char data){ while(TxFifo_Put(data) == FIFOFAIL){ OS_Wait(&TxRoomLeft); } UART0_IM_R &= ~UART_IM_TXIM; // disable TX FIFO interrupt copySoftwareToHardware(); UART0_IM_R |= UART_IM_TXIM; // enable TX FIFO interrupt }
//------------UART_OutCharNonBlock------------ // non blocking output ASCII character to UART // Input: letter is an 8-bit ASCII character to be transferred // Output: none // Error: return with lost data if TxFifo is full void UART_OutCharNonBlock(char data){ if(TxFifo_Put(data) == FIFOFAIL) return; // lost data UART0_IM_R &= ~UART_IM_TXIM; // disable TX FIFO interrupt copySoftwareToHardware(); UART0_IM_R |= UART_IM_TXIM; // enable TX FIFO interrupt }
int main2(void){ int i; // *************** Test #1: test transmit (index) FIFO ************** TxFifo_Init(); result = TxFifo_Get(&letter); // letter = ??, result = 0 result = TxFifo_Put('A'); // result = 1 result = TxFifo_Put('B'); // result = 1 result = TxFifo_Put('C'); // result = 1 result = TxFifo_Get(&letter); // letter = 0x41, result = 1 result = TxFifo_Get(&letter); // letter = 0x42, result = 1 result = TxFifo_Put('D'); // result = 1 result = TxFifo_Size(); // result = 2 result = TxFifo_Get(&letter); // letter = 0x43, result = 1 result = TxFifo_Get(&letter); // letter = 0x44, result = 1 result = TxFifo_Size(); // result = 0 result = TxFifo_Get(&letter); // letter = ??, result = 0 for(i='A'; i<'A'+TXFIFOSIZE; i=i+1){ result = TxFifo_Put(i); // result = 1 } result = TxFifo_Size(); // result = 16 result = TxFifo_Get(&letter); // letter = 0x41, result = 1 result = TxFifo_Size(); // result = 15 result = TxFifo_Get(&letter); // letter = 0x42, result = 1 result = TxFifo_Size(); // result = 14 result = TxFifo_Put(' '); // result = 1 result = TxFifo_Size(); // result = 15 // *************** Test #2: test receive (pointer) FIFO ************* RxFifo_Init(); result = RxFifo_Get(&letter); // letter = ??, result = 0 result = RxFifo_Put('A'); // result = 1 result = RxFifo_Put('B'); // result = 1 result = RxFifo_Put('C'); // result = 1 result = RxFifo_Get(&letter); // letter = 0x41, result = 1 result = RxFifo_Get(&letter); // letter = 0x42, result = 1 result = RxFifo_Put('D'); // result = 1 result = RxFifo_Size(); // result = 2 result = RxFifo_Get(&letter); // letter = 0x43, result = 1 result = RxFifo_Get(&letter); // letter = 0x44, result = 1 result = RxFifo_Size(); // result = 0 result = RxFifo_Get(&letter); // letter = ??, result = 0 for(i='A'; i<'A'+RXFIFOSIZE-1; i=i+1){ result = RxFifo_Put(i); // result = 1 } result = RxFifo_Size(); // result = 9 result = RxFifo_Get(&letter); // letter = 0x41, result = 1 result = RxFifo_Size(); // result = 8 result = RxFifo_Get(&letter); // letter = 0x42, result = 1 result = RxFifo_Size(); // result = 7 result = RxFifo_Put(' '); // result = 1 result = RxFifo_Size(); // result = 8 // *********** Test #3: test transmit (index) FIFO creator ********** Tx2Fifo_Init(); result = Tx2Fifo_Get(&letter);// letter = ??, result = 0 result = Tx2Fifo_Put('A'); // result = 1 result = Tx2Fifo_Put('B'); // result = 1 result = Tx2Fifo_Put('C'); // result = 1 result = Tx2Fifo_Get(&letter);// letter = 0x41, result = 1 result = Tx2Fifo_Get(&letter);// letter = 0x42, result = 1 result = Tx2Fifo_Put('D'); // result = 1 result = Tx2Fifo_Size(); // result = 2 result = Tx2Fifo_Get(&letter);// letter = 0x43, result = 1 result = Tx2Fifo_Get(&letter);// letter = 0x44, result = 1 result = Tx2Fifo_Size(); // result = 0 result = Tx2Fifo_Get(&letter);// letter = ??, result = 0 for(i='A'; i<'A'+TX2FIFOSIZE; i=i+1){ result = Tx2Fifo_Put(i); // result = 1 } result = Tx2Fifo_Size(); // result = 32 result = Tx2Fifo_Get(&letter);// letter = 0x41, result = 1 result = Tx2Fifo_Size(); // result = 31 result = Tx2Fifo_Get(&letter);// letter = 0x42, result = 1 result = Tx2Fifo_Size(); // result = 30 result = Tx2Fifo_Put(' '); // result = 1 result = Tx2Fifo_Size(); // result = 31 // *********** Test #4: test receive (pointer) FIFO creator ********* Rx2Fifo_Init(); result = Rx2Fifo_Get(&letter);// letter = ??, result = 0 result = Rx2Fifo_Put('A'); // result = 1 result = Rx2Fifo_Put('B'); // result = 1 result = Rx2Fifo_Put('C'); // result = 1 result = Rx2Fifo_Get(&letter);// letter = 0x41, result = 1 result = Rx2Fifo_Get(&letter);// letter = 0x42, result = 1 result = Rx2Fifo_Put('D'); // result = 1 result = Rx2Fifo_Size(); // result = 2 result = Rx2Fifo_Get(&letter);// letter = 0x43, result = 1 result = Rx2Fifo_Get(&letter);// letter = 0x44, result = 1 result = Rx2Fifo_Size(); // result = 0 result = Rx2Fifo_Get(&letter);// letter = ??, result = 0 for(i='A'; i<'A'+RX2FIFOSIZE-1; i=i+1){ result = Rx2Fifo_Put(i); // result = 1 } result = Rx2Fifo_Size(); // result = 26 result = Rx2Fifo_Get(&letter);// letter = 0x41, result = 1 result = Rx2Fifo_Size(); // result = 25 result = Rx2Fifo_Get(&letter);// letter = 0x42, result = 1 result = Rx2Fifo_Size(); // result = 24 result = Rx2Fifo_Put(' '); // result = 1 result = Rx2Fifo_Size(); // result = 25 while(1); }
// output ASCII character to UART // spin if TxFifo is full void UART_OutChar(unsigned char data){ while(TxFifo_Put(data) == FIFOFAIL){}; UART0_IM_R &= ~UART_IM_TXIM; // disable TX FIFO interrupt copySoftwareToHardware(); UART0_IM_R |= UART_IM_TXIM; // enable TX FIFO interrupt }