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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [aemb/] [thread.hh] - Diff between revs 139 and 145

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

Rev 139 Rev 145
Line 1... Line 1...
/* $Id: thread.hh,v 1.8 2008-04-26 19:31:35 sybreon Exp $
/* $Id: thread.hh,v 1.9 2008-04-27 16:33:42 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.
**
**
** AEMB is free software: you can redistribute it and/or modify it
** AEMB is free software: you can redistribute it and/or modify it
** under the terms of the GNU Lesser General Public License as
** under the terms of the GNU General Public License as published by
** published by the Free Software Foundation, either version 3 of the
** the Free Software Foundation, either version 3 of the License, or
** License, or (at your option) any later version.
** (at your option) any later version.
**
**
** AEMB is distributed in the hope that it will be useful, but WITHOUT
** AEMB is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
** Public License for more details.
** License for more details.
**
**
** You should have received a copy of the GNU Lesser General Public
** You should have received a copy of the GNU General Public License
** License along with AEMB. If not, see .
** along with AEMB.  If not, see .
*/
*/
 
 
/**
/**
   Basic thread functions
   Basic thread functions
   @file thread.hh
   @file thread.hh
Line 70... Line 70...
 
 
  /**
  /**
     Hardware Mutex Signal.
     Hardware Mutex Signal.
     Unlock the hardware mutex, which is unlocked on reset.
     Unlock the hardware mutex, which is unlocked on reset.
   */
   */
  inline void signalMutex()
  inline void _mtx_free()
  {
  {
    int tmp;
    int tmp;
    asm volatile ("msrclr %0, 0x0010":"=r"(tmp));
    asm volatile ("msrclr %0, %1":"=r"(tmp):"K"(MSR_MTX));
  }
  }
 
 
  /**
  /**
     Hardware Mutex Wait.
     Hardware Mutex Wait.
 
 
     Waits until the hardware mutex is unlocked. This should be used
     Waits until the hardware mutex is unlocked. This should be used
     as part of a larger software mutex mechanism.
     as part of a larger software mutex mechanism.
   */
   */
  inline void waitMutex()
  inline void _mtx_lock()
  {
  {
    int rmsr;
    int rmsr;
    do
    do
      {
      {
        asm volatile ("msrset %0, 0x0010":"=r"(rmsr));
        asm volatile ("msrset %0, %1":"=r"(rmsr):"K"(MSR_MTX));
      }
      }
    while (rmsr & MSR_MTX);
    while (rmsr & MSR_MTX);
  }
  }
 
 
  // TODO: Extend this library to include threading mechanisms such as
  // TODO: Extend this library to include threading mechanisms such as
Line 101... Line 101...
     Semaphore struct.
     Semaphore struct.
     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.
     required as the threads are hardware.
  */
  */
 
 
  typedef volatile int semaphore;
  typedef int semaphore;
 
 
  /**
  /**
     Increment the semaphore
     Software Semaphore Signal.
 
 
 
     Increment the semaphore and run. This is a software mechanism.
  */
  */
  inline void signal(semaphore _sem) { _sem++; }
  inline void signal(volatile semaphore _sem)
 
  {
 
    _mtx_lock();
 
    _sem++;
 
    _mtx_free();
 
  }
 
 
  /**
  /**
     Decrement the semaphore and block if < 0
     Software Semaphore Wait.
 
 
 
     Decrement the semaphore and block if < 0. This is a software
 
     mechanism.
  */
  */
  inline void wait(semaphore _sem) { _sem--; while (_sem < 0); } // block while
  inline void wait(volatile semaphore _sem)
                                                     // semaphore is
  {
                                                     // negative
    _mtx_lock();
 
    _sem--;
 
    _mtx_free();
 
    while (_sem < 0);
 
  }
 
 
  semaphore __mutex_rendezvous0 = 0; ///< internal rendezvous mutex
  semaphore __mutex_rendezvous0 = 0; ///< internal rendezvous mutex
  semaphore __mutex_rendezvous1 = 1; ///< internal rendezvous mutex
  semaphore __mutex_rendezvous1 = 1; ///< internal rendezvous mutex
 
 
  /**
  /**
     Implements a simple rendezvous mechanism
     Implements a simple rendezvous mechanism
   */
   */
 
 
  void rendezvous()
  inline void rendezvous()
  {
  {
    if (isThread1())
    if (isThread1())
      {
      {
        wait(__mutex_rendezvous0);
        wait(__mutex_rendezvous0);
        signal(__mutex_rendezvous1);
        signal(__mutex_rendezvous1);
Line 144... Line 158...
 
 
#endif
#endif
 
 
/*
/*
  $Log: not supported by cvs2svn $
  $Log: not supported by cvs2svn $
 
  Revision 1.8  2008/04/26 19:31:35  sybreon
 
  Made headers C compatible.
 
 
  Revision 1.7  2008/04/26 18:05:22  sybreon
  Revision 1.7  2008/04/26 18:05:22  sybreon
  Minor cosmetic changes.
  Minor cosmetic changes.
 
 
  Revision 1.6  2008/04/23 14:19:39  sybreon
  Revision 1.6  2008/04/23 14:19:39  sybreon
  Fixed minor bugs.
  Fixed minor bugs.

powered by: WebSVN 2.1.0

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