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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [rtos.c] - Diff between revs 407 and 416

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

Rev 407 Rev 416
Line 22... Line 22...
#define SEM_RESERVED_COUNT 2
#define SEM_RESERVED_COUNT 2
#define INFO_COUNT 4
#define INFO_COUNT 4
#define HEAP_COUNT 8
#define HEAP_COUNT 8
 
 
#define PRINTF_DEBUG(STRING, A, B)
#define PRINTF_DEBUG(STRING, A, B)
//#define PRINTF_DEBUG(STRING, A, B) printf(STRING, A, B)
//#define PRINTF_DEBUG(STRING, A, B) UartPrintfCritical(STRING, A, B)
 
 
/*************** Structures ***************/
/*************** Structures ***************/
#ifdef WIN32
#ifdef WIN32
   #define setjmp _setjmp
   #define setjmp _setjmp
   //x86 registers
   //x86 registers
Line 201... Line 201...
            node += node->size;
            node += node->size;
            node->size = nunits;
            node->size = nunits;
         }
         }
         heap->available = prevp;
         heap->available = prevp;
         node->next = (HeapNode_t*)heap;
         node->next = (HeapNode_t*)heap;
         OS_SemaphorePost(heap->semaphore);
         PRINTF_DEBUG("malloc(%d, %d)\n", node->size * sizeof(HeapNode_t), heap->count);
         ++heap->count;
         ++heap->count;
 
         OS_SemaphorePost(heap->semaphore);
         //UartPrintfCritical("OS_HeapMalloc(%d)=0x%x\n", bytes, (int)(node+1));
         //UartPrintfCritical("OS_HeapMalloc(%d)=0x%x\n", bytes, (int)(node+1));
         return (void*)(node + 1);
         return (void*)(node + 1);
      }
      }
      if(node == heap->available)   //Wrapped around free list
      if(node == heap->available)   //Wrapped around free list
      {
      {
Line 232... Line 233...
   bp = (HeapNode_t*)block - 1;   //point to block header
   bp = (HeapNode_t*)block - 1;   //point to block header
   heap = (OS_Heap_t*)bp->next;
   heap = (OS_Heap_t*)bp->next;
   assert(heap->magic == HEAP_MAGIC);
   assert(heap->magic == HEAP_MAGIC);
   if(heap->magic != HEAP_MAGIC)
   if(heap->magic != HEAP_MAGIC)
      return;
      return;
   --heap->count;
 
   OS_SemaphorePend(heap->semaphore, OS_WAIT_FOREVER);
   OS_SemaphorePend(heap->semaphore, OS_WAIT_FOREVER);
 
   --heap->count;
 
   PRINTF_DEBUG("free(%d, %d)\n", bp->size * sizeof(HeapNode_t), heap->count);
   for(node = heap->available; !(node < bp && bp < node->next); node = node->next)
   for(node = heap->available; !(node < bp && bp < node->next); node = node->next)
   {
   {
      if(node >= node->next && (bp > node || bp < node->next))
      if(node >= node->next && (bp > node || bp < node->next))
         break;               //freed block at start or end of area
         break;               //freed block at start or end of area
   }
   }
Line 423... Line 425...
      if(threadCurrent)
      if(threadCurrent)
      {
      {
         assert(threadCurrent->magic[0] == THREAD_MAGIC); //check stack overflow
         assert(threadCurrent->magic[0] == THREAD_MAGIC); //check stack overflow
         if(threadCurrent->state == THREAD_RUNNING)
         if(threadCurrent->state == THREAD_RUNNING)
            OS_ThreadPriorityInsert(&ThreadHead, threadCurrent);
            OS_ThreadPriorityInsert(&ThreadHead, threadCurrent);
         PRINTF_DEBUG("Pause(%d,%s) ", OS_CpuIndex(), threadCurrent->name);
         //PRINTF_DEBUG("Pause(%d,%s) ", OS_CpuIndex(), threadCurrent->name);
         rc = setjmp(threadCurrent->env);  //ANSI C call to save registers
         rc = setjmp(threadCurrent->env);  //ANSI C call to save registers
         if(rc)
         if(rc)
         {
         {
            PRINTF_DEBUG("Resume(%d,%s) ", OS_CpuIndex(),
            //PRINTF_DEBUG("Resume(%d,%s) ", OS_CpuIndex(), 
               ThreadCurrent[OS_CpuIndex()]->name);
            //   ThreadCurrent[OS_CpuIndex()]->name);
            return;  //Returned from longjmp()
            return;  //Returned from longjmp()
         }
         }
      }
      }
 
 
      //Remove the new running thread from the ThreadHead linked list
      //Remove the new running thread from the ThreadHead linked list
Line 728... Line 730...
{
{
   uint32 state, cpuIndex;
   uint32 state, cpuIndex;
   OS_Thread_t *thread;
   OS_Thread_t *thread;
   int returnCode=0;
   int returnCode=0;
 
 
   PRINTF_DEBUG("SemPend(%d,%s) ", OS_CpuIndex(), semaphore->name);
   //PRINTF_DEBUG("SemPend(%d,%s) ", OS_CpuIndex(), semaphore->name);
   assert(semaphore);
   assert(semaphore);
   assert(InterruptInside[OS_CpuIndex()] == 0);
   assert(InterruptInside[OS_CpuIndex()] == 0);
   state = OS_CriticalBegin();    //Disable interrupts
   state = OS_CriticalBegin();    //Disable interrupts
   if(--semaphore->count < 0)
   if(--semaphore->count < 0)
   {
   {
Line 771... Line 773...
void OS_SemaphorePost(OS_Semaphore_t *semaphore)
void OS_SemaphorePost(OS_Semaphore_t *semaphore)
{
{
   uint32 state;
   uint32 state;
   OS_Thread_t *thread;
   OS_Thread_t *thread;
 
 
   PRINTF_DEBUG("SemPost(%d,%s) ", OS_CpuIndex(), semaphore->name);
   //PRINTF_DEBUG("SemPost(%d,%s) ", OS_CpuIndex(), semaphore->name);
   assert(semaphore);
   assert(semaphore);
   state = OS_CriticalBegin();
   state = OS_CriticalBegin();
   if(++semaphore->count <= 0)
   if(++semaphore->count <= 0)
   {
   {
      //Wake up a thread that was waiting for this semaphore
      //Wake up a thread that was waiting for this semaphore
Line 1322... Line 1324...
   if((int)OS_Init > 0x10000000)        //Running from DDR?
   if((int)OS_Init > 0x10000000)        //Running from DDR?
      OS_AsmInterruptInit();            //Patch interrupt vector
      OS_AsmInterruptInit();            //Patch interrupt vector
   OS_InterruptMaskClear(0xffffffff);   //Disable interrupts
   OS_InterruptMaskClear(0xffffffff);   //Disable interrupts
   HeapArray[0] = OS_HeapCreate("Heap", heapStorage, bytes);
   HeapArray[0] = OS_HeapCreate("Heap", heapStorage, bytes);
   HeapArray[1] = HeapArray[0];
   HeapArray[1] = HeapArray[0];
 
#ifndef WIN32
 
   HeapArray[7] = OS_HeapCreate("Alt", (uint8*)RAM_EXTERNAL_BASE +
 
      RAM_EXTERNAL_SIZE*2, 1024*1024*60);
 
   OS_HeapAlternate(HeapArray[0], HeapArray[7]);
 
#endif
   SemaphoreSleep = OS_SemaphoreCreate("Sleep", 0);
   SemaphoreSleep = OS_SemaphoreCreate("Sleep", 0);
   SemaphoreRelease = OS_SemaphoreCreate("Release", 1);
   SemaphoreRelease = OS_SemaphoreCreate("Release", 1);
   SemaphoreLock = OS_SemaphoreCreate("Lock", 1);
   SemaphoreLock = OS_SemaphoreCreate("Lock", 1);
   if((MemoryRead(IRQ_STATUS) & (IRQ_COUNTER18 | IRQ_COUNTER18_NOT)) == 0)
   if((MemoryRead(IRQ_STATUS) & (IRQ_COUNTER18 | IRQ_COUNTER18_NOT)) == 0)
   {
   {
Line 1373... Line 1380...
{
{
   (void)programEnd;  //Pointer to end of used memory
   (void)programEnd;  //Pointer to end of used memory
   (void)argv;
   (void)argv;
 
 
   UartPrintfCritical("Starting RTOS\n");
   UartPrintfCritical("Starting RTOS\n");
 
   MemoryWrite(IRQ_MASK, 0);
#ifdef WIN32
#ifdef WIN32
   OS_Init((uint32*)HeapSpace, sizeof(HeapSpace));  //For PC simulation
   OS_Init((uint32*)HeapSpace, sizeof(HeapSpace));  //For PC simulation
#else
#else
   //Create heap in remaining space after program in 1MB external RAM
   //Create heap in remaining space after program in 1MB external RAM
   OS_Init((uint32*)programEnd,
   OS_Init((uint32*)programEnd,

powered by: WebSVN 2.1.0

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