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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [uart.c] - Diff between revs 402 and 416

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

Rev 402 Rev 416
Line 6... Line 6...
 * PROJECT: Plasma CPU core
 * PROJECT: Plasma CPU core
 * COPYRIGHT: Software placed into the public domain by the author.
 * COPYRIGHT: Software placed into the public domain by the author.
 *    Software 'as is' without warranty.  Author liable for nothing.
 *    Software 'as is' without warranty.  Author liable for nothing.
 * DESCRIPTION:
 * DESCRIPTION:
 *    Plasma Uart Driver
 *    Plasma Uart Driver
 
 *    UART_PACKETS permits "Ethernet" packets to be sent and received.
 *--------------------------------------------------------------------*/
 *--------------------------------------------------------------------*/
#define NO_ELLIPSIS2
#define NO_ELLIPSIS2
#include "plasma.h"
#include "plasma.h"
#include "rtos.h"
#include "rtos.h"
 
 
#ifndef NO_PACKETS
 
#define SUPPORT_DATA_PACKETS
 
#endif
 
 
 
#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
 
 
Line 36... Line 33...
 
 
static Buffer_t *WriteBuffer, *ReadBuffer;
static Buffer_t *WriteBuffer, *ReadBuffer;
static OS_Semaphore_t *SemaphoreUart;
static OS_Semaphore_t *SemaphoreUart;
static char PrintfString[BUFFER_PRINTF_SIZE];  //Used in UartPrintf
static char PrintfString[BUFFER_PRINTF_SIZE];  //Used in UartPrintf
 
 
#ifdef SUPPORT_DATA_PACKETS
#ifdef UART_PACKETS
//For packet processing [0xff lengthMSB lengthLSB checksum data]
//For packet processing [0xff lengthMSB lengthLSB checksum data]
static PacketGetFunc_t UartPacketGet;
static PacketGetFunc_t UartPacketGet;
static uint8 *PacketCurrent;
static uint8 *PacketCurrent;
static uint32 UartPacketSize;
static uint32 UartPacketSize;
static uint32 UartPacketChecksum, Checksum;
static uint32 UartPacketChecksum, Checksum;
static OS_MQueue_t *UartPacketMQueue;
static OS_MQueue_t *UartPacketMQueue;
static uint32 PacketBytes, PacketLength;
static uint32 PacketBytes, PacketLength;
static uint32 UartPacketOutLength, UartPacketOutByte;
static uint32 UartPacketOutLength, UartPacketOutByte;
int CountOk, CountError;
int CountOk, CountError;
#endif
 
static uint8 *UartPacketOut;
static uint8 *UartPacketOut;
 
#endif //UART_PACKETS
 
 
 
 
/******************************************/
/******************************************/
Buffer_t *BufferCreate(int size)
Buffer_t *BufferCreate(int size)
{
{
Line 122... Line 119...
   return value;
   return value;
}
}
 
 
 
 
/******************************************/
/******************************************/
#ifdef SUPPORT_DATA_PACKETS
#ifdef UART_PACKETS
static void UartPacketRead(uint32 value)
static void UartPacketRead(uint32 value)
{
{
   uint32 message[4];
   uint32 message[4];
   if(PacketBytes == 0 && value == 0xff)
   if(PacketBytes == 0 && value == 0xff)
   {
   {
Line 230... Line 227...
         }
         }
      }
      }
   }
   }
   return value;
   return value;
}
}
#endif
#endif  //UART_PACKETS
 
 
 
 
static void UartInterrupt(void *arg)
static void UartInterrupt(void *arg)
{
{
   uint32 status, value, count=0;
   uint32 status, value, count=0;
Line 242... Line 239...
 
 
   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);
#ifdef SUPPORT_DATA_PACKETS
#ifdef UART_PACKETS
      if(UartPacketGet && (value == 0xff || PacketBytes))
      if(UartPacketGet && (value == 0xff || PacketBytes))
         UartPacketRead(value);
         UartPacketRead(value);
      else
      else
#endif
#endif
      BufferWrite(ReadBuffer, value, 0);
      BufferWrite(ReadBuffer, value, 0);
Line 254... Line 251...
      if(++count >= 16)
      if(++count >= 16)
         break;
         break;
   }
   }
   while(status & IRQ_UART_WRITE_AVAILABLE)
   while(status & IRQ_UART_WRITE_AVAILABLE)
   {
   {
#ifdef SUPPORT_DATA_PACKETS
#ifdef UART_PACKETS
      if(UartPacketOut)
      if(UartPacketOut)
      {
      {
         value = UartPacketWrite();
         value = UartPacketWrite();
         MemoryWrite(UART_WRITE, value);
         MemoryWrite(UART_WRITE, value);
      } else
      } else
Line 350... Line 347...
   ptr = (uint8*)PrintfString;
   ptr = (uint8*)PrintfString;
   while(*ptr)
   while(*ptr)
   {
   {
      if(*ptr == '\n')
      if(*ptr == '\n')
         UartWrite('\r');
         UartWrite('\r');
#ifdef SUPPORT_DATA_PACKETS
#ifdef UART_PACKETS
      if(*ptr == 0xff)
      if(*ptr == 0xff)
         *ptr = '@';
         *ptr = '@';
#endif
#endif
      UartWrite(*ptr++);
      UartWrite(*ptr++);
   }
   }
   OS_SemaphorePost(SemaphoreUart);
   OS_SemaphorePost(SemaphoreUart);
}
}
 
 
 
 
 
#if 0
void UartPrintfPoll(const char *format,
void UartPrintfPoll(const char *format,
                    int arg0, int arg1, int arg2, int arg3,
                    int arg0, int arg1, int arg2, int arg3,
                    int arg4, int arg5, int arg6, int arg7)
                    int arg4, int arg5, int arg6, int arg7)
{
{
   uint8 *ptr;
   uint8 *ptr;
Line 387... Line 385...
      OS_CriticalEnd(state);
      OS_CriticalEnd(state);
   }
   }
   if(SemaphoreUart)
   if(SemaphoreUart)
      OS_SemaphorePost(SemaphoreUart);
      OS_SemaphorePost(SemaphoreUart);
}
}
 
#endif
 
 
 
 
void UartPrintfCritical(const char *format,
void UartPrintfCritical(const char *format,
                        int arg0, int arg1, int arg2, int arg3,
                        int arg0, int arg1, int arg2, int arg3,
                        int arg4, int arg5, int arg6, int arg7)
                        int arg4, int arg5, int arg6, int arg7)
{
{
 
   char buffer[128];
   uint8 *ptr;
   uint8 *ptr;
   uint32 state;
   uint32 state;
 
 
   state = OS_CriticalBegin();
   state = OS_CriticalBegin();
   sprintf(PrintfString, format, arg0, arg1, arg2, arg3,
   sprintf(buffer, format, arg0, arg1, arg2, arg3,
           arg4, arg5, arg6, arg7);
           arg4, arg5, arg6, arg7);
   ptr = (uint8*)PrintfString;
   ptr = (uint8*)buffer;
   while(*ptr)
   while(*ptr)
   {
   {
      while((MemoryRead(IRQ_STATUS) & IRQ_UART_WRITE_AVAILABLE) == 0)
      while((MemoryRead(IRQ_STATUS) & IRQ_UART_WRITE_AVAILABLE) == 0)
         ;
         ;
      MemoryWrite(UART_WRITE, *ptr++);
      MemoryWrite(UART_WRITE, *ptr++);
#ifdef SUPPORT_DATA_PACKETS
#ifdef UART_PACKETS
      if(UartPacketOut && UartPacketOutByte - 4 < UartPacketOutLength)
      if(UartPacketOut && UartPacketOutByte - 4 < UartPacketOutLength)
      {
      {
         ++UartPacketOutByte;
         ++UartPacketOutByte;
         --ptr;
         --ptr;
      }
      }
#endif
#endif
   }
   }
   memset(PrintfString, 0, sizeof(PrintfString));
 
   OS_CriticalEnd(state);
   OS_CriticalEnd(state);
}
}
 
 
 
 
void UartPrintfNull(void)
 
{
 
}
 
 
 
 
 
void UartScanf(const char *format,
void UartScanf(const char *format,
               int arg0, int arg1, int arg2, int arg3,
               int arg0, int arg1, int arg2, int arg3,
               int arg4, int arg5, int arg6, int arg7)
               int arg4, int arg5, int arg6, int arg7)
{
{
   int index = 0, ch;
   int index = 0, ch;
Line 456... Line 450...
          arg4, arg5, arg6, arg7);
          arg4, arg5, arg6, arg7);
   OS_SemaphorePost(SemaphoreUart);
   OS_SemaphorePost(SemaphoreUart);
}
}
 
 
 
 
#ifdef SUPPORT_DATA_PACKETS
#ifdef UART_PACKETS
void UartPacketConfig(PacketGetFunc_t PacketGetFunc,
void UartPacketConfig(PacketGetFunc_t PacketGetFunc,
                      int PacketSize,
                      int PacketSize,
                      OS_MQueue_t *mQueue)
                      OS_MQueue_t *mQueue)
{
{
   UartPacketGet = PacketGetFunc;
   UartPacketGet = PacketGetFunc;
Line 474... Line 468...
   UartPacketOutByte = 0;
   UartPacketOutByte = 0;
   UartPacketOutLength = bytes;
   UartPacketOutLength = bytes;
   UartPacketOut = data;
   UartPacketOut = data;
   OS_InterruptMaskSet(IRQ_UART_WRITE_AVAILABLE);
   OS_InterruptMaskSet(IRQ_UART_WRITE_AVAILABLE);
}
}
#else
#else  //UART_PACKETS
void UartPacketConfig(PacketGetFunc_t PacketGetFunc,
void UartPacketConfig(PacketGetFunc_t PacketGetFunc,
                      int PacketSize,
                      int PacketSize,
                      OS_MQueue_t *mQueue)
                      OS_MQueue_t *mQueue)
{ (void)PacketGetFunc; (void)PacketSize; (void)mQueue; }
{ (void)PacketGetFunc; (void)PacketSize; (void)mQueue; }
 
 

powered by: WebSVN 2.1.0

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