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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [aemb/] [thread.hh] - Diff between revs 117 and 121

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

Rev 117 Rev 121
Line 1... Line 1...
/* $Id: thread.hh,v 1.4 2008-04-12 14:07:26 sybreon Exp $
/* $Id: thread.hh,v 1.5 2008-04-20 16:35:53 sybreon Exp $
**
**
** AEMB2 HI-PERFORMANCE CPU
** AEMB2 HI-PERFORMANCE CPU
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap 
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap 
**
**
** This file is part of AEMB.
** This file is part of AEMB.
Line 30... Line 30...
#include "aemb/msr.hh"
#include "aemb/msr.hh"
 
 
#ifndef AEMB_THREAD_HH
#ifndef AEMB_THREAD_HH
#define AEMB_THREAD_HH
#define AEMB_THREAD_HH
 
 
 
#ifdef __cplusplus
namespace aemb {
namespace aemb {
 
#endif
 
 
  /**
  /**
     Checks to see if currently executing Thread 1
     Checks to see if currently executing Thread 1
     @return true if is Thread 1
     @return true if is Thread 1
  */
  */
 
 
  inline bool isThread1()
  inline bool isThread1()
  {
  {
    int rmsr = aemb::getMSR();
    int rmsr = getMSR();
    return ((rmsr & aemb::MSR_HTX) && (rmsr & aemb::MSR_HTP));
    return ((rmsr & MSR_HTX) && (rmsr & MSR_PHA));
  }
  }
 
 
  /**
  /**
     Checks to see if currently executing Thread 0
     Checks to see if currently executing Thread 0
     @return true if is Thread 0
     @return true if is Thread 0
  */
  */
 
 
  inline bool isThread0()
  inline bool isThread0()
  {
  {
    int rmsr = aemb::getMSR();
    int rmsr = getMSR();
    return ((rmsr & aemb::MSR_HTX) && (!(rmsr & aemb::MSR_HTP)));
    return ((rmsr & MSR_HTX) && (!(rmsr & MSR_PHA)));
  }
  }
 
 
  /**
  /**
     Checks to see if it is multi-threaded or not
     Checks to see if it is multi-threaded or not.
     @return true if thread capable
     @return true if thread capable
  */
  */
  inline bool isThreaded()
  inline bool isThreaded()
  {
  {
    int rmsr = aemb::getMSR();
    int rmsr = getMSR();
    return (rmsr & aemb::MSR_HTX);
    return (rmsr & MSR_HTX);
  }
  }
 
 
  // TODO: Extend this library to include threading mechanisms such as
  /**
  // semaphores, mutexes and such.
     Hardware Mutex Signal.
 
     Unlock the hardware mutex, which is unlocked on reset.
 
   */
 
  inline void signalMutex()
 
  {
 
    int tmp;
 
    asm volatile ("msrclr %0, 0x0010":"=r"(tmp));
 
  }
 
 
  /**
  /**
     Semaphore class
     Hardware Mutex Wait.
 
     Waits until the hardware mutex is unlocked.
 
   */
 
  inline void waitMutex()
 
  {
 
    int rmsr;
 
    do
 
      {
 
        asm volatile ("msrset %0, 0x0010":"=r"(rmsr));
 
      }
 
    while (rmsr & MSR_MTX);
 
  }
 
 
     Based on: Little Book of Semaphores, The - Downey, Allen B.
  // TODO: Extend this library to include threading mechanisms such as
 
  // semaphores, mutexes and such.
 
 
 
  /**
 
     Semaphore class.
     Presently implemented as software solution but a hardware one may be
     Presently implemented as software solution but a hardware one may be
     required as the threads are hardware. This can be implemented using
     required as the threads are hardware.
     a specialised add/sub/load register.
 
  */
  */
 
 
  class semaphore {
  class semaphore {
  private:
  private:
    volatile int _sem; ///< Semaphore in Memory
    volatile int _sem; ///< Semaphore in Memory
Line 122... Line 143...
        __mutex_rendezvous0.signal();
        __mutex_rendezvous0.signal();
        __mutex_rendezvous1.wait();
        __mutex_rendezvous1.wait();
      }
      }
  }
  }
 
 
 
#ifdef __cplusplus
}
}
 
#endif
 
 
#endif
#endif
 
 
/*
/*
  $Log: not supported by cvs2svn $
  $Log: not supported by cvs2svn $
 
  Revision 1.4  2008/04/12 14:07:26  sybreon
 
  added a rendezvous function
 
 
  Revision 1.3  2008/04/11 15:53:24  sybreon
  Revision 1.3  2008/04/11 15:53:24  sybreon
  changed MSR bits
  changed MSR bits
 
 
  Revision 1.2  2008/04/11 11:34:30  sybreon
  Revision 1.2  2008/04/11 11:34:30  sybreon
  changed semaphore case
  changed semaphore case

powered by: WebSVN 2.1.0

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