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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [aemb/] [thread.hh] - Blame information for rev 207

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 151 sybreon
/* $Id: thread.hh,v 1.10 2008-04-28 20:29:15 sybreon Exp $
2 107 sybreon
**
3
** AEMB2 HI-PERFORMANCE CPU
4
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap 
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9 145 sybreon
** under the terms of the GNU General Public License as published by
10
** the Free Software Foundation, either version 3 of the License, or
11
** (at your option) any later version.
12 107 sybreon
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 145 sybreon
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
** License for more details.
17 107 sybreon
**
18 145 sybreon
** You should have received a copy of the GNU General Public License
19
** along with AEMB.  If not, see .
20 107 sybreon
*/
21
 
22
/**
23
   Basic thread functions
24
   @file thread.hh
25
 
26
   These functions deal with the various hardware threads. It also
27
   provides simple mechanisms for toggling semaphores.
28
 */
29
 
30
#include "aemb/msr.hh"
31
 
32 151 sybreon
#ifndef _AEMB_THREAD_HH
33
#define _AEMB_THREAD_HH
34 107 sybreon
 
35 139 sybreon
#ifdef __cplusplus
36 151 sybreon
extern "C" {
37 139 sybreon
#endif
38 107 sybreon
 
39
  /**
40 117 sybreon
     Checks to see if currently executing Thread 1
41
     @return true if is Thread 1
42 107 sybreon
  */
43
 
44 151 sybreon
  inline int aembIsThread1()
45 107 sybreon
  {
46 151 sybreon
    int rmsr = aembGetMSR();
47
    return ((rmsr & AEMB_MSR_HTX) && (rmsr & AEMB_MSR_PHA));
48 107 sybreon
  }
49
 
50
  /**
51 117 sybreon
     Checks to see if currently executing Thread 0
52
     @return true if is Thread 0
53 107 sybreon
  */
54
 
55 151 sybreon
  inline int aembIsThread0()
56 107 sybreon
  {
57 151 sybreon
    int rmsr = aembGetMSR();
58
    return ((rmsr & AEMB_MSR_HTX) && (!(rmsr & AEMB_MSR_PHA)));
59 107 sybreon
  }
60
 
61
  /**
62 121 sybreon
     Checks to see if it is multi-threaded or not.
63 117 sybreon
     @return true if thread capable
64 107 sybreon
  */
65 151 sybreon
  inline int aembIsThreaded()
66 107 sybreon
  {
67 151 sybreon
    int rmsr = aembGetMSR();
68
    return (rmsr & AEMB_MSR_HTX);
69 107 sybreon
  }
70 121 sybreon
 
71
  /**
72
     Hardware Mutex Signal.
73
     Unlock the hardware mutex, which is unlocked on reset.
74
   */
75 151 sybreon
  inline void _aembFreeMTX()
76 121 sybreon
  {
77
    int tmp;
78 151 sybreon
    asm volatile ("msrclr %0, %1":"=r"(tmp):"K"(AEMB_MSR_MTX));
79 121 sybreon
  }
80
 
81
  /**
82
     Hardware Mutex Wait.
83 128 sybreon
 
84
     Waits until the hardware mutex is unlocked. This should be used
85
     as part of a larger software mutex mechanism.
86 121 sybreon
   */
87 151 sybreon
  inline void _aembLockMTX()
88 121 sybreon
  {
89
    int rmsr;
90
    do
91
      {
92 151 sybreon
        asm volatile ("msrset %0, %1":"=r"(rmsr):"K"(AEMB_MSR_MTX));
93 121 sybreon
      }
94 151 sybreon
    while (rmsr & AEMB_MSR_MTX);
95 121 sybreon
  }
96
 
97 139 sybreon
#ifdef __cplusplus
98 107 sybreon
}
99 139 sybreon
#endif
100 107 sybreon
 
101
#endif
102
 
103
/*
104
  $Log: not supported by cvs2svn $
105 151 sybreon
  Revision 1.9  2008/04/27 16:33:42  sybreon
106
  License change to GPL3.
107
 
108 145 sybreon
  Revision 1.8  2008/04/26 19:31:35  sybreon
109
  Made headers C compatible.
110
 
111 139 sybreon
  Revision 1.7  2008/04/26 18:05:22  sybreon
112
  Minor cosmetic changes.
113
 
114 137 sybreon
  Revision 1.6  2008/04/23 14:19:39  sybreon
115
  Fixed minor bugs.
116
  Initial use of hardware mutex.
117
 
118 128 sybreon
  Revision 1.5  2008/04/20 16:35:53  sybreon
119
  Added C/C++ compatible #ifdef statements
120
 
121 121 sybreon
  Revision 1.4  2008/04/12 14:07:26  sybreon
122
  added a rendezvous function
123
 
124 117 sybreon
  Revision 1.3  2008/04/11 15:53:24  sybreon
125
  changed MSR bits
126
 
127 114 sybreon
  Revision 1.2  2008/04/11 11:34:30  sybreon
128
  changed semaphore case
129
 
130 108 sybreon
  Revision 1.1  2008/04/09 19:48:37  sybreon
131
  Added new C++ files
132
 
133 107 sybreon
*/

powered by: WebSVN 2.1.0

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