OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [uart.c] - Diff between revs 163 and 188

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 163 Rev 188
Line 18... Line 18...
#define BUFFER_WRITE_SIZE 128
#define BUFFER_WRITE_SIZE 128
#define BUFFER_READ_SIZE 128
#define BUFFER_READ_SIZE 128
#define BUFFER_PRINTF_SIZE 1024
#define BUFFER_PRINTF_SIZE 1024
#undef UartPrintf
#undef UartPrintf
 
 
 
void UartPrintfCritical(const char *format,
 
                        int arg0, int arg1, int arg2, int arg3,
 
                        int arg4, int arg5, int arg6, int arg7);
 
 
typedef struct Buffer_s {
typedef struct Buffer_s {
   uint8 *data;
   uint8 *data;
   int size;
   int size;
   volatile int read, write;
   volatile int read, write;
   volatile int pendingRead, pendingWrite;
   volatile int pendingRead, pendingWrite;
Line 63... Line 67...
   buffer->semaphoreWrite = OS_SemaphoreCreate("BufferWrite", 0);
   buffer->semaphoreWrite = OS_SemaphoreCreate("BufferWrite", 0);
   return buffer;
   return buffer;
}
}
 
 
 
 
void BufferWrite(Buffer_t *Buffer, int Value, int Pend)
void BufferWrite(Buffer_t *buffer, int value, int pend)
{
{
   int writeNext;
   int writeNext;
 
 
   writeNext = Buffer->write + 1;
   writeNext = buffer->write + 1;
   if(writeNext >= Buffer->size)
   if(writeNext >= buffer->size)
      writeNext = 0;
      writeNext = 0;
 
 
   //Check if room for value
   //Check if room for value
   if(writeNext == Buffer->read)
   if(writeNext == buffer->read)
   {
   {
      if(Pend == 0)
      if(pend == 0)
         return;
         return;
      ++Buffer->pendingWrite;
      ++buffer->pendingWrite;
      OS_SemaphorePend(Buffer->semaphoreWrite, OS_WAIT_FOREVER);
      OS_SemaphorePend(buffer->semaphoreWrite, OS_WAIT_FOREVER);
   }
   }
 
 
   Buffer->data[Buffer->write] = (uint8)Value;
   buffer->data[buffer->write] = (uint8)value;
   Buffer->write = writeNext;
   buffer->write = writeNext;
   if(Buffer->pendingRead)
   if(buffer->pendingRead)
   {
   {
      --Buffer->pendingRead;
      --buffer->pendingRead;
      OS_SemaphorePost(Buffer->semaphoreRead);
      OS_SemaphorePost(buffer->semaphoreRead);
   }
   }
}
}
 
 
 
 
int BufferRead(Buffer_t *Buffer, int Pend)
int BufferRead(Buffer_t *buffer, int pend)
{
{
   int value;
   int value;
 
 
   //Check if empty buffer
   //Check if empty buffer
   if(Buffer->read == Buffer->write)
   if(buffer->read == buffer->write)
   {
   {
      if(Pend == 0)
      if(pend == 0)
         return 0;
         return 0;
      ++Buffer->pendingRead;
      ++buffer->pendingRead;
      OS_SemaphorePend(Buffer->semaphoreRead, OS_WAIT_FOREVER);
      OS_SemaphorePend(buffer->semaphoreRead, OS_WAIT_FOREVER);
   }
   }
 
 
   value = Buffer->data[Buffer->read];
   value = buffer->data[buffer->read];
   if(++Buffer->read >= Buffer->size)
   if(++buffer->read >= buffer->size)
      Buffer->read = 0;
      buffer->read = 0;
   if(Buffer->pendingWrite)
   if(buffer->pendingWrite)
   {
   {
      --Buffer->pendingWrite;
      --buffer->pendingWrite;
      OS_SemaphorePost(Buffer->semaphoreWrite);
      OS_SemaphorePost(buffer->semaphoreWrite);
   }
   }
   return value;
   return value;
}
}
 
 
 
 
Line 224... Line 228...
   return value;
   return value;
}
}
#endif
#endif
 
 
 
 
static void UartInterrupt(void *Arg)
static void UartInterrupt(void *arg)
{
{
   uint32 status, value, count=0;
   uint32 status, value, count=0;
   (void)Arg;
   (void)arg;
 
 
   status = OS_InterruptStatus();
   status = OS_InterruptStatus();
   while(status & IRQ_UART_READ_AVAILABLE)
   while(status & IRQ_UART_READ_AVAILABLE)
   {
   {
      value = MemoryRead(UART_READ);
      value = MemoryRead(UART_READ);
Line 281... Line 285...
   OS_InterruptRegister(mask, UartInterrupt);
   OS_InterruptRegister(mask, UartInterrupt);
   OS_InterruptMaskSet(IRQ_UART_READ_AVAILABLE);
   OS_InterruptMaskSet(IRQ_UART_READ_AVAILABLE);
}
}
 
 
 
 
void UartWrite(int C)
void UartWrite(int ch)
{
{
   BufferWrite(WriteBuffer, C, 1);
   BufferWrite(WriteBuffer, ch, 1);
   OS_InterruptMaskSet(IRQ_UART_WRITE_AVAILABLE);
   OS_InterruptMaskSet(IRQ_UART_WRITE_AVAILABLE);
}
}
 
 
 
 
uint8 UartRead(void)
uint8 UartRead(void)
{
{
   return (uint8)BufferRead(ReadBuffer, 1);
   return (uint8)BufferRead(ReadBuffer, 1);
}
}
 
 
 
 
void UartWriteData(uint8 *Data, int Length)
void UartWriteData(uint8 *data, int length)
{
{
   OS_SemaphorePend(SemaphoreUart, OS_WAIT_FOREVER);
   OS_SemaphorePend(SemaphoreUart, OS_WAIT_FOREVER);
   while(Length--)
   while(length--)
      UartWrite(*Data++);
      UartWrite(*data++);
   OS_SemaphorePost(SemaphoreUart);
   OS_SemaphorePost(SemaphoreUart);
}
}
 
 
 
 
void UartReadData(uint8 *Data, int Length)
void UartReadData(uint8 *data, int length)
{
{
   OS_SemaphorePend(SemaphoreUart, OS_WAIT_FOREVER);
   OS_SemaphorePend(SemaphoreUart, OS_WAIT_FOREVER);
   while(Length--)
   while(length--)
      *Data++ = UartRead();
      *data++ = UartRead();
   OS_SemaphorePost(SemaphoreUart);
   OS_SemaphorePost(SemaphoreUart);
}
}
 
 
 
 
void UartPrintf(const char *format,
void UartPrintf(const char *format,
Line 442... Line 446...
   UartPacketSize = PacketSize;
   UartPacketSize = PacketSize;
   UartPacketMQueue = mQueue;
   UartPacketMQueue = mQueue;
}
}
 
 
 
 
void UartPacketSend(uint8 *Data, int Bytes)
void UartPacketSend(uint8 *data, int bytes)
{
{
   UartPacketOutByte = 0;
   UartPacketOutByte = 0;
   UartPacketOutLength = Bytes;
   UartPacketOutLength = bytes;
   UartPacketOut = Data;
   UartPacketOut = data;
   OS_InterruptMaskSet(IRQ_UART_WRITE_AVAILABLE);
   OS_InterruptMaskSet(IRQ_UART_WRITE_AVAILABLE);
}
}
#endif
#endif
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.