Example #1
0
uint8_t GetCharFromFifo ( S_fifo *pDescrFifo, int8_t *carLu )
{
   int8_t readSize;
   uint8_t readStatus;

   // détermine le nb de car. que l'on peut lire
   readSize = GetReadSize(pDescrFifo);

   // test si fifo est vide
   if (readSize == 0) {
      readStatus = 1; // fifo EMPTY
      *carLu = 0;     // carLu = NULL
   }
   else {
      // lis le caractère dans le FIFO
      *carLu = *(pDescrFifo->pRead);

      // incrément du pointeur de lecture
      pDescrFifo->pRead++;
      // gestion du rebouclement
      if (pDescrFifo->pRead > pDescrFifo->pFinFifo) {
          pDescrFifo->pRead = pDescrFifo->pDebFifo;
      }
      readStatus = 0; // OK
   }
   return (readStatus);
} // GetCharFromFifo
Example #2
0
void serial_handling(void){
    static int step = 0;
    static uint8_t msg[MESS_SIZE];

    if(UARTReceivedDataIsAvailable(UART2))
    {
       PutCharInFifo ( &descrFifoRX, UARTGetDataByte(UART2));
    }

    if(GetReadSize(&descrFifoRX) < 1){
        // Il n'y a rien à faire
        return ;
    }

    GetCharFromFifo(&descrFifoRX, &msg[step]);

    switch(step){
        case 0:
            // Recherche du caractère '!'
            if(msg[0] == '!'){
                step++;
            }
            break;
        case 1:
        case 2:
            step++;
            break;
        case 3:
            // Message complet
            msg_processing(msg);
            step = 0;
        default:
            step = 0;
            break;

    }


    if (GetReadSize(&descrFifoTX) > 0)
    {
        // Autorise int émission
        INTEnable(INT_U2TX, INT_ENABLED);
    }

}
Example #3
0
//___________________________________________________________________________________________
//called when the user process calls read().  Never fails.  Returns 0 if no data to read.  Otherwise, returns number of bytes read.
ssize_t EvtIoRead(struct file *filep, char *buf, size_t count, loff_t *ppos)
{
   unsigned char tempBuf[BUFFERSIZE];
//   unsigned char tempBuf[3];
   bool noData = false;
   size_t i, bytesToRead;
   size_t bufIdx = 0;
   size_t curTempIdx = 0;
   size_t bytesRead = 0;  //number of bytes actually read from the controller (may not reach count if there's only a few bytes to read)
   DeviceContext *d = filep->private_data;
   size_t bytesAvailable;

#if 0
   unsigned char dumpChar;
   char dumpBuf[512];
   
	printk(KERN_INFO "EvtIoRead TotalBuffer[%i]\n", count);
#endif
	
	bufIdx = 0;
	while ( bytesRead < count && !noData )
	{
		curTempIdx = 0;
		bytesToRead = min(sizeof(tempBuf), count-bytesRead);
		while ( curTempIdx < sizeof(tempBuf) && curTempIdx < count )
		{
			bytesAvailable = GetReadSize(d);
			if ( bytesAvailable <= 0 )
			{
				noData = true;
				break;
			}
			bytesToRead = min(bytesToRead, bytesAvailable);
			tempBuf[curTempIdx++] = inb(d->baseAddress);
		}
		copy_to_user(buf+bytesRead, tempBuf, curTempIdx);
		bytesRead += curTempIdx;
//		printk(KERN_INFO "EvtIoRead Copy to user Total[%i] Cycle[%i]\n", bytesRead, curTempIdx);
	}
#if 0
   if ( bytesRead > 0 )
   {
		memset(dumpBuf, 0, sizeof(dumpBuf));
		for ( i = 0; i < 16 && i < bytesRead; i++ )
		{
			dumpChar = *(buf+i);
//			sprintf(dumpBuf+strlen(dumpBuf), "%X ", dumpChar);
			dumpBuf[i] = *(buf+i);
		}
		printk(KERN_INFO "EvtIoRead Dump: size(%i) data[%s]\n", bytesRead, dumpBuf);
		printk(KERN_INFO "EvtIoRead Total[%i] Read[%i]\n", count, bytesRead);
   }
#endif

   return bytesRead;
}
Example #4
0
wxSoundStream& wxSoundStreamPcm::Read(void *buffer, wxUint32 len)
{
    wxUint32 in_bufsize;

    // We must have a multiple of 2
    len &= 0x01;
    
    if (!m_function_in) {
        m_sndio->Read(buffer, len);
        m_lastcount = m_sndio->GetLastAccess();
        m_snderror = m_sndio->GetError();
        return *this;
    }

    in_bufsize = GetReadSize(len);
    
    if (len <= m_best_size) {
        m_sndio->Read(m_prebuffer, in_bufsize);
        m_snderror  = m_sndio->GetError();
        if (m_snderror != wxSOUND_NOERROR) {
            m_lastcount = 0;
            return *this;
        }
        
        m_function_in(m_prebuffer, buffer, m_sndio->GetLastAccess());
    } else {
        char *temp_buffer;
        
        temp_buffer = new char[in_bufsize];
        m_sndio->Read(temp_buffer, in_bufsize);

        m_snderror =  m_sndio->GetError();
        if (m_snderror != wxSOUND_NOERROR) {
            m_lastcount = 0;
            return *this;
        }
        
        m_function_in(temp_buffer, buffer, m_sndio->GetLastAccess());
        
        delete[] temp_buffer;
    }
    
    m_lastcount = (wxUint32)(m_sndio->GetLastAccess() * m_multiplier_in);
    
    return *this;
}
Example #5
0
void __ISR(_UART_2_VECTOR, IPL5SOFT) UART2_isr(void)
{
   uint8_t ErrFiFoFull = 0;
   uint8_t freeSize, TXsize;
   int8_t c;
   uint8_t i_cts = 0;
   BOOL  TxPossible;

   UART_LINE_STATUS lineStatus;



    // Is this an RX interrupt ?
    if ( INTGetFlag(INT_U2RX) && INTGetEnable(INT_U2RX) ) {


        // oui Test si erreur comm
        lineStatus = UARTGetLineStatus(UART2);

        if ( (lineStatus & (UART_PARITY_ERROR | UART_FRAMING_ERROR |
                            UART_OVERRUN_ERROR)) == 0) {
             // transfert dans le fifo de tous les caractères recu
             while (UARTReceivedDataIsAvailable(UART2))
             {
                 c = UARTGetDataByte(UART2);
                 PutCharInFifo ( &descrFifoRX, c);
             }
             INTClearFlag(INT_U2RX); // buffer is empty, clear interrupt flag

        } else {
             UART2ClearAllErrors();   // Macro C32
        }

         freeSize = GetWriteSpace ( &descrFifoRX);
         if (freeSize <= 6 )        // a cause d'un int pour 6 char
         {
            // Demande de ne plus émettre
            //RS232_RTS = 1;

            if (freeSize == 0) {
                 ErrFiFoFull = 1;    // pour debugging si probème ctrl flux
            }
        }
    } // end if RX

    // Is this an TX interrupt ?
    if(INTGetFlag(INT_U2TX) && INTGetEnable(INT_U2TX)  ) {


         TXsize = GetReadSize (&descrFifoTX);
         // i_cts = input(RS232_CTS);
         // On vérifie 3 conditions :
         //    Si CTS = 0 (autorisation d'émettre)
         //    Si il y a un caratères à émettre
         //    Si le txreg est bien disponible

         //i_cts = RS232_CTS;

         TxPossible = UARTTransmitterIsReady(UART2);
         //if ( (i_cts == 0) && ( TXsize > 0 ) && TxPossible )  {
         if (  ( TXsize > 0 ) && TxPossible )  {
             do {
                 GetCharFromFifo(&descrFifoTX, &c);

                 UARTSendDataByte(UART2, c);
                 //i_cts = RS232_CTS;
                 TXsize = GetReadSize (&descrFifoTX);
                 TxPossible = UARTTransmitterIsReady(UART2);

             //} while ( (i_cts == 0) && ( TXsize > 0 ) && TxPossible  );
             } while (  ( TXsize > 0 ) && TxPossible  );
            // Clear the TX interrupt Flag (Seulement aprés TX)
            INTClearFlag(INT_U2TX);
        } else {
           // disable TX interrupt
           INTEnable(INT_U2TX, INT_DISABLED);
        }
    }
} // UART_isr