Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

bus_lock.c

Go to the documentation of this file.
00001 
00002 
00003 #include "bus_lock.h"
00004 
00005 #include <vxWorks.h>
00006 #include <taskLib.h>
00007 #include <logLib.h>
00008 
00009 struct BL_ADDR_INFO
00010 {
00011   unsigned long addr;
00012   int board_type;
00013 };
00014 
00015 int bus_lock_use_intlock = 1;
00016 void *test_bus_lock_addr = (void *) 0x4e00000;
00017 int test_buf_size = 0x4000;
00018 int test_bus_lock_board_type = VX_MVME162_BOARD_TYPE;
00019 static char c = 'a';
00020 int testBusLockQuit;
00021 int test_bus_lock_count = 0x4000;
00022 int intLockKey = 0;
00023 
00024 
00025 
00026 void
00027 regWriteChar (char *addr, char c)
00028 {
00029   *addr = c;
00030 }
00031 
00032 char
00033 regReadChar (char *addr)
00034 {
00035   return *addr;
00036 }
00037 
00038 void
00039 regWriteShort (short *addr, short c)
00040 {
00041   *addr = c;
00042 }
00043 
00044 short
00045 regReadShort (short *addr)
00046 {
00047   return *addr;
00048 }
00049 
00050 void
00051 regWriteLong (long *addr, long c)
00052 {
00053   *addr = c;
00054 }
00055 
00056 long
00057 regReadLong (long *addr)
00058 {
00059   return *addr;
00060 }
00061 
00062 void
00063 regWriteULong (unsigned long *addr, unsigned long c)
00064 {
00065   *addr = c;
00066 }
00067 
00068 unsigned long
00069 regReadULong (long *addr)
00070 {
00071   return *addr;
00072 }
00073 
00074 
00075 
00076 
00077 int
00078 testBusLockRead ()
00079 {
00080   struct BL_ADDR_INFO *info;
00081   char c1, c2;
00082   int i;
00083 
00084   info =
00085     getBusLockInfo (test_bus_lock_board_type,
00086                     (unsigned long) test_bus_lock_addr);
00087   if (0 == info)
00088     {
00089       return -1;
00090     }
00091   for (i = 0; i < test_bus_lock_count && !testBusLockQuit; i++)
00092     {
00093       enableBusLock (info);
00094       c1 = *((char *) test_bus_lock_addr);
00095       c2 = *((char *) test_bus_lock_addr + test_buf_size - 1);
00096       disableBusLock (info);
00097       if (c1 != c2)
00098         {
00099           logMsg (" %c != %c", c1, c2, 0, 0, 0, 0);
00100           return -1;
00101         }
00102     }
00103 }
00104 
00105 
00106 
00107 int
00108 testBusLockWrite ()
00109 {
00110   struct BL_ADDR_INFO *info;
00111   int i;
00112 
00113   info =
00114     getBusLockInfo (test_bus_lock_board_type,
00115                     (unsigned long) test_bus_lock_addr);
00116   if (0 == info)
00117     {
00118       return -1;
00119     }
00120   for (i = 0; i < test_bus_lock_count && !testBusLockQuit; i++)
00121     {
00122       c++;
00123       if (c > 'z')
00124         {
00125           c = 'a';
00126         }
00127       enableBusLock (info);
00128       memset (test_bus_lock_addr, c, test_buf_size);
00129       disableBusLock (info);
00130     }
00131   freeBusLockInfo (info);
00132   return 0;
00133 }
00134 
00135 struct BL_ADDR_INFO *
00136 getBusLockInfo (int board_type, unsigned long addr)
00137 {
00138   struct BL_ADDR_INFO *info;
00139   char vme_bus_enable_control_reg;
00140   unsigned long a1;
00141   unsigned long enda1;
00142   unsigned long starta1;
00143 
00144   switch (board_type)
00145     {
00146     case VX_MVME162_BOARD_TYPE:
00147       info = (struct BL_ADDR_INFO *) malloc (sizeof (struct BL_ADDR_INFO));
00148       if (0 == info)
00149         {
00150           return 0;
00151         }
00152       info->addr = addr;
00153       info->board_type = board_type;
00154       return info;
00155 
00156     default:
00157       break;
00158     }
00159   return (0);
00160 }
00161 
00162 void
00163 freeBusLockInfo (struct BL_ADDR_INFO *info)
00164 {
00165   if (0 == info)
00166     {
00167       return;
00168     }
00169   free (info);
00170 }
00171 
00172 int
00173 enableBusLock (struct BL_ADDR_INFO *info)
00174 {
00175   long requestor_control_register_val;
00176   long DHB = 0;
00177   int board_type;
00178   if (0 == info)
00179     {
00180       return -1;
00181     }
00182 #ifdef VXWORKS
00183   if (bus_lock_use_intlock)
00184     {
00185       intLockKey = intLock ();
00186     }
00187   else
00188     {
00189       taskLock ();
00190     }
00191 #endif
00192   board_type = info->board_type;
00193   switch (board_type)
00194     {
00195     case VX_MVME162_BOARD_TYPE:
00196       while (!DHB)
00197         {
00198           requestor_control_register_val = regReadLong ((long *) 0xFFF40030);
00199           DHB = requestor_control_register_val & (1 << 14);
00200           requestor_control_register_val |= (1 << 13);
00201           regWriteLong (((long *) 0xFFF40030),
00202                         requestor_control_register_val);
00203         }
00204       return 0;
00205 
00206     defualt:
00207       return -1;
00208     }
00209   return -1;
00210 }
00211 
00212 
00213 
00214 
00215 
00216 int
00217 disableBusLock (struct BL_ADDR_INFO *info)
00218 {
00219   long requestor_control_register_val;
00220   long DHB = 0;
00221   long attribute_register;
00222   int board_type;
00223   if (0 == info)
00224     {
00225       return -1;
00226     }
00227   board_type = info->board_type;
00228   switch (board_type)
00229     {
00230     case VX_MVME162_BOARD_TYPE:
00231       requestor_control_register_val = regReadLong ((long *) 0xFFF40030);
00232       requestor_control_register_val &= ~(1 << 13);
00233       regWriteLong (((long *) 0xfff40030), requestor_control_register_val);
00234 #ifdef VXWORKS
00235       if (bus_lock_use_intlock)
00236         {
00237           intUnlock (intLockKey);
00238         }
00239       else
00240         {
00241           taskUnlock ();
00242         }
00243 #endif
00244       return 0;
00245     defualt:
00246       break;
00247     }
00248 #ifdef VXWORKS
00249   if (bus_lock_use_intlock)
00250     {
00251       intUnlock (intLockKey);
00252     }
00253   else
00254     {
00255       taskUnlock ();
00256     }
00257 #endif
00258   return -1;
00259 }

Generated on Sun Dec 2 15:56:48 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001