sis3803.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------
00002  *  Copyright (c) 1996      TRIUMF Data Acquistion Group
00003  *  Please leave this header in any reproduction of that distribution
00004  * 
00005  *  TRIUMF Data Acquisition Group, 4004 Wesbrook Mall, Vancouver, B.C. V6T 2A3
00006  *  Email: online@triumf.ca           Tel: (604) 222-1047  Fax: (604) 222-1074
00007  *         amaudruz@triumf.ca
00008  * -----------------------------------------------------------------------------
00009  *  
00010  *  Description : Support function library for the SIS3803 200MHz 16ch. scalers
00011  *                P.A. Amaudruz
00012  *  Requires    : sis3803.h
00013  *  Application : VME
00014  *  Author      : Pierre-Andre Amaudruz Data Acquisition Group
00015   $Id: sis3803.c 3767 2007-07-23 21:45:52Z olchanski $
00016 
00017  *
00018  *---------------------------------------------------------------------------*/
00019 #include "sis3803.h"
00020 
00021 void myStub_sis3803(void)
00022 {
00023    static int sis3803_private_counter = 0;
00024 #ifdef OS_VXWORKS
00025    sis3803_int_source_disable(0, 0);
00026    logMsg("sis3803 IRQ#%i served\n", sis3803_private_counter++, 0, 0, 0, 0, 0);
00027    sis3803_int_source_enable(0, 0);
00028 #endif
00029 }
00030 
00031 /************ INLINE function for General command ***********/
00032 INLINE DWORD sis3803_module_ID(const DWORD base_adr)
00033 /**************************************************************\
00034  Purpose: return the Module ID number (I) version (V)
00035           IRQ level (L) IRQ vector# (BB)
00036  Input: 
00037   DWORD base_addr     : base address of the SIS3803
00038  Output:
00039     none
00040  Function value:
00041  DWORD                : 0xIIIIVLBB
00042 \**************************************************************/
00043 {
00044    volatile DWORD *spec_adr;
00045 
00046    spec_adr = (DWORD *) (A32D24 + base_adr + MODULE_ID);
00047    return *spec_adr;
00048 }
00049 
00050 /************ INLINE function for General command ***********/
00051 INLINE void sis3803_module_reset(const DWORD base_adr)
00052 /**************************************************************\
00053  Purpose: General Module reset
00054  Input: 
00055   DWORD base_addr     : base address of the SIS3803
00056  Output:
00057     none
00058  Function value:
00059  none
00060 \**************************************************************/
00061 {
00062    volatile DWORD *spec_adr;
00063 
00064    spec_adr = (DWORD *) (A32D24 + base_adr + MODULE_RESET);
00065    *spec_adr = 0x0;
00066 }
00067 
00068 /************ INLINE function for General command ***********/
00069 INLINE DWORD sis3803_IRQ_REG_read(const DWORD base_adr)
00070 /**************************************************************\
00071  Purpose: return the lower 12 bits corresponding to
00072           VME IRQ enable, levels, vector(lower 8bits)
00073  Input: 
00074   DWORD base_addr     : base address of the SIS3803
00075  Output:
00076     none
00077  Function value:
00078  DWORD                : 0xE(1)L(3)V(8)
00079 \**************************************************************/
00080 {
00081    volatile DWORD *spec_adr;
00082 
00083    spec_adr = (DWORD *) (A32D24 + base_adr + IRQ_REG);
00084    return (*spec_adr & 0xFFF);
00085 }
00086 
00087 /************ INLINE function for General command ***********/
00088 INLINE DWORD sis3803_IRQ_REG_write(const DWORD base_adr, DWORD irq)
00089 /**************************************************************\
00090  Purpose: write irq (ELV) to the register and read back 
00091  Input: 
00092   DWORD base_addr     : base address of the SIS3803
00093   DWORD irq           : reg 
00094  Output:
00095     none
00096  Function value:
00097  DWORD                : 0xE(1)L(3)V(8)
00098 \**************************************************************/
00099 {
00100    volatile DWORD *spec_adr;
00101 
00102    spec_adr = (DWORD *) (A32D24 + base_adr + IRQ_REG);
00103    *spec_adr = irq;
00104    return (*spec_adr & 0xFFF);
00105 }
00106 
00107 /************ INLINE function for General command ***********/
00108 INLINE DWORD sis3803_input_mode(const DWORD base_adr, DWORD mode)
00109 /**************************************************************\
00110  Purpose: Set input configuration mode (only mode 1 available)
00111  Input: 
00112   DWORD base_addr     : base address of the SIS3803
00113   DWORD mode          : Mode 0-3
00114  Output:
00115     none
00116  Function value:
00117     DWORD             : current mode
00118 \**************************************************************/
00119 {
00120    volatile DWORD *spec_adr;
00121 
00122    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00123    if (mode < 4)
00124       mode <<= 2;
00125    *spec_adr = mode;
00126    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_READ);
00127    return ((*spec_adr & GET_MODE) >> 2);
00128 }
00129 
00130 /************ INLINE function for General command ***********/
00131 INLINE DWORD sis3803_ref1(const DWORD base_adr, DWORD endis)
00132 /**************************************************************\
00133  Purpose: Enable/Disable Reference on Channel 1
00134  Input: 
00135   DWORD base_addr     : base address of the SIS3803
00136   DWORD endis         : action either ENABLE_REF_CH1
00137                                       DISABLE_REF_CH1
00138  Output:
00139     none
00140  Function value:
00141                : status of the ref1 1=enable, 0=disable
00142 \**************************************************************/
00143 {
00144    volatile DWORD *spec_adr;
00145 
00146    if ((endis == ENABLE_REF_CH1) || (endis == DISABLE_REF_CH1)) {
00147       spec_adr = (DWORD *) (A32D24 + base_adr + endis);
00148       *spec_adr = 0x0;
00149    } else
00150       printf("sis3803_ref1: unknown command %d\n", endis);
00151 
00152    /* read back the status */
00153    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_READ);
00154    return ((*spec_adr & IS_REF1) ? 1 : 0);
00155 }
00156 
00157 /************ INLINE function for General command ***********/
00158 INLINE void sis3803_channel_enable(const DWORD base_adr, DWORD pat)
00159 /**************************************************************\
00160  Purpose: Enable pat channel for acquistion.
00161           blind command! 0x0..0xffff
00162  Input: 
00163   DWORD base_addr     : base address of the SIS3803
00164   DWORD pat           : channel pattern
00165  Output:
00166     none
00167  Function value:
00168     none
00169 \**************************************************************/
00170 {
00171    volatile DWORD *spec_adr;
00172 
00173    spec_adr = (DWORD *) (A32D24 + base_adr + SELECT_COUNT_DIS_REG);
00174    *spec_adr = (~pat & 0xffff);
00175 }
00176 
00177 
00178 /************ INLINE function for General command ***********/
00179 INLINE void sis3803_channel_disable(const DWORD base_adr, DWORD pat)
00180 /**************************************************************\
00181  Purpose: Disable pat channel for acquistion.
00182           blind command! 0x0..0xffff
00183  Input: 
00184   DWORD base_addr     : base address of the SIS3803
00185   DWORD pat           : channel pattern
00186  Output:
00187     none
00188  Function value:
00189     none
00190 \**************************************************************/
00191 {
00192    volatile DWORD *spec_adr;
00193 
00194    spec_adr = (DWORD *) (A32D24 + base_adr + SELECT_COUNT_DIS_REG);
00195    *spec_adr = pat & 0xffff;
00196 }
00197 
00198 /************ INLINE function for General command ***********/
00199 INLINE DWORD sis3803_CSR_read(const DWORD base_adr, const DWORD what)
00200 /**************************************************************\
00201  Purpose: Read the CSR and return 1/0 based on what.
00202           except for what == CSR_FULL where it returns current CSR
00203  Input: 
00204   DWORD base_addr     : base address of the SIS3803
00205   DWORD what          : bitwise field (see sis3803.h)
00206  Output:
00207     none
00208  Function value:
00209  DWORD             : CSR 32bit current content
00210 \**************************************************************/
00211 {
00212    volatile DWORD *spec_adr;
00213 
00214    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_READ);
00215    if (what == CSR_FULL)
00216       return *spec_adr;
00217    else
00218       return ((*spec_adr & what) ? 1 : 0);
00219 }
00220 
00221 /************ INLINE function for General command ***********/
00222 INLINE DWORD sis3803_CSR_write(const DWORD base_adr, const DWORD what)
00223 /**************************************************************\
00224  Purpose: Write to the CSR and return CSR_FULL.
00225  Input: 
00226   DWORD base_addr     : base address of the SIS3803
00227   DWORD what          : bitwise field 
00228  Output:
00229     none
00230  Function value:
00231  DWORD             : CSR 32bit current content
00232 \**************************************************************/
00233 {
00234    volatile DWORD *spec_adr;
00235 
00236    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00237    *spec_adr = what;
00238    return sis3803_CSR_read(base_adr, CSR_FULL);
00239 }
00240 
00241 /************ INLINE function for General command ***********/
00242 INLINE void sis3803_all_clear(const DWORD base_adr)
00243 /**************************************************************\
00244  Purpose: Clear all module + overflow bits
00245  Input:
00246   DWORD base_addr     : base address of the SIS3803
00247  Output:
00248     none
00249  Function value:
00250  none
00251 \**************************************************************/
00252 {
00253    volatile DWORD *spec_adr;
00254 
00255    spec_adr = (DWORD *) (A32D24 + base_adr + ALL_CLEAR);
00256    *spec_adr = 0x0;
00257 }
00258 
00259 /************ INLINE function for General command ***********/
00260 INLINE void sis3803_test_enable(const DWORD base_adr)
00261 /**************************************************************\
00262  Purpose: Enable test pulse and input test
00263  Input:
00264   DWORD base_addr     : base address of the SIS3803
00265  Output:
00266     none
00267  Function value:
00268  none
00269 \**************************************************************/
00270 {
00271    volatile DWORD *spec_adr;
00272 
00273    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00274    *spec_adr = ENABLE_TEST_PULSE;
00275 }
00276 
00277 /************ INLINE function for General command ***********/
00278 INLINE void sis3803_test_disable(const DWORD base_adr)
00279 /**************************************************************\
00280  Purpose: Disable test pulse and input test
00281  Input:
00282   DWORD base_addr     : base address of the SIS3803
00283  Output:
00284     none
00285  Function value:
00286  none
00287 \**************************************************************/
00288 {
00289    volatile DWORD *spec_adr;
00290 
00291    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00292    *spec_adr = DISABLE_TEST_PULSE;
00293 }
00294 
00295 /************ INLINE function for General command ***********/
00296 INLINE void sis3803_all_enable(const DWORD base_adr)
00297 /**************************************************************\
00298  Purpose: Enable global counting
00299  Input:
00300   DWORD base_addr     : base address of the SIS3803
00301  Output:
00302     none
00303  Function value:
00304  none
00305 \**************************************************************/
00306 {
00307    volatile DWORD *spec_adr;
00308 
00309    spec_adr = (DWORD *) (A32D24 + base_adr + ENABLE_GBL_COUNT);
00310    *spec_adr = 0x0;
00311 }
00312 
00313 /************ INLINE function for General command ***********/
00314 INLINE void sis3803_all_disable(const DWORD base_adr)
00315 /**************************************************************\
00316  Purpose: Disable global counting
00317  Input:
00318   DWORD base_addr     : base address of the SIS3803
00319  Output:
00320     none
00321  Function value:
00322  none
00323 \**************************************************************/
00324 {
00325    volatile DWORD *spec_adr;
00326 
00327    spec_adr = (DWORD *) (A32D24 + base_adr + DISABLE_GBL_COUNT);
00328    *spec_adr = 0x0;
00329 }
00330 
00331 /************ INLINE function for General command ***********/
00332 INLINE void sis3803_grp1_clear(const DWORD base_adr)
00333 /**************************************************************\
00334  Purpose: Clear group 1 (1-8) channels + overflow bits
00335  Input:
00336   DWORD base_addr     : base address of the SIS3803
00337  Output:
00338     none
00339  Function value:
00340  none
00341 \**************************************************************/
00342 {
00343    volatile DWORD *spec_adr;
00344 
00345    spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_GRP1_CLEAR);
00346    *spec_adr = 0x0;
00347 }
00348 
00349 /************ INLINE function for General command ***********/
00350 INLINE void sis3803_grp2_clear(const DWORD base_adr)
00351 /**************************************************************\
00352  Purpose: Clear group 2 (9-16) channels + overflow bits
00353  Input:
00354   DWORD base_addr     : base address of the SIS3803
00355  Output:
00356     none
00357  Function value:
00358  none
00359 \**************************************************************/
00360 {
00361    volatile DWORD *spec_adr;
00362 
00363    spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_GRP2_CLEAR);
00364    *spec_adr = 0x0;
00365 }
00366 
00367 /************ INLINE function for General command ***********/
00368 INLINE void sis3803_single_clear(const DWORD base_adr, const INT ch)
00369 /**************************************************************\
00370  Purpose: Clear single scaler channels + overflow bits
00371  Input:
00372   DWORD base_addr     : base address of the SIS3803
00373  Output:
00374     none
00375  Function value:
00376  none
00377 \**************************************************************/
00378 {
00379    volatile DWORD *spec_adr;
00380 
00381    if (ch < 16) {
00382       spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_CLEAR + (ch << 2));
00383       *spec_adr = 0x0;
00384    }
00385 }
00386 
00387 /************ INLINE function for General command ***********/
00388 INLINE void sis3803_single_OVFL_clear(const DWORD base_adr, INT ch)
00389 /**************************************************************\
00390  Purpose: Clear single scaler channels + overflow bits
00391  Input:
00392   DWORD base_addr     : base address of the SIS3803
00393  Output:
00394     none
00395  Function value:
00396  none
00397 \**************************************************************/
00398 {
00399    volatile DWORD *spec_adr;
00400 
00401    if (ch < 16) {
00402       spec_adr = (DWORD *) (A32D24 + base_adr + OVERFLOW_CLEAR + (ch << 2));
00403       *spec_adr = 0x0;
00404    }
00405 }
00406 
00407 /*********** INLINE function for General command ***********/
00408 INLINE void sis3803_counter_read(const DWORD base_adr, INT ch, DWORD * pvalue)
00409 /**************************************************************\
00410  Purpose: Reads one individual scaler
00411  Input:
00412   DWORD base_addr     : base address of the SIS3803
00413   INT   ch            : Channel to be read
00414   DWORD *pvalue       : destination pointer
00415  Output:
00416     none
00417  Function value:
00418     none
00419 \**************************************************************/
00420 {
00421    volatile DWORD *spec_adr;
00422 
00423    if (ch < 16) {
00424       spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_READ + (ch << 2));
00425       *pvalue = *spec_adr;
00426    }
00427 }
00428 
00429 /*********** INLINE function for General command ***********/
00430 INLINE void sis3803_all_read(const DWORD base_adr, DWORD * pvalue)
00431 /**************************************************************\
00432  Purpose: Reads all 16 channels scaler
00433  Input:
00434   DWORD base_addr     : base address of the SIS3803
00435   DWORD *pvalue       : destination pointer
00436  Output:
00437     none
00438  Function value:
00439     none
00440 \**************************************************************/
00441 {
00442    INT i;
00443    volatile DWORD *spec_adr;
00444 
00445    spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_READ);
00446    for (i = 0; i < 16; i++) {
00447       *pvalue++ = *spec_adr++;
00448    }
00449 }
00450 
00451 /*********** INLINE function for General command ***********/
00452 INLINE void sis3803_grp1_read(const DWORD base_adr, DWORD * pvalue)
00453 /**************************************************************\
00454  Purpose: Reads group 1 (1..8) channels scaler
00455  Input:
00456   DWORD base_addr     : base address of the SIS3803
00457   DWORD *pvalue       : destination pointer
00458  Output:
00459     none
00460  Function value:
00461     none
00462 \**************************************************************/
00463 {
00464    INT i;
00465    volatile DWORD *spec_adr;
00466 
00467    spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_READ);
00468    for (i = 0; i < 8; i++) {
00469       *pvalue++ = *spec_adr++;
00470    }
00471 }
00472 
00473 /*********** INLINE function for General command ***********/
00474 INLINE void sis3803_grp2_read(const DWORD base_adr, DWORD * pvalue)
00475 /**************************************************************\
00476  Purpose: Reads group 1 (1..8) channels scaler
00477  Input:
00478   DWORD base_addr     : base address of the SIS3803
00479   DWORD *pvalue       : destination pointer
00480  Output:
00481     none
00482  Function value:
00483     none
00484 \**************************************************************/
00485 {
00486    INT i;
00487    volatile DWORD *spec_adr;
00488 
00489    spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_GRP2_READ);
00490    for (i = 0; i < 8; i++) {
00491       *pvalue++ = *spec_adr++;
00492    }
00493 }
00494 
00495 /*********** INLINE function for General command ***********/
00496 INLINE void sis3803_all_read_clear(const DWORD base_adr, DWORD * pvalue)
00497 /**************************************************************\
00498  Purpose: Reads & clear all 16 channels scaler
00499  Input:
00500   DWORD base_addr     : base address of the SIS3803
00501   DWORD *pvalue       : destination pointer
00502  Output:
00503     none
00504  Function value:
00505     none
00506 \**************************************************************/
00507 {
00508    INT i;
00509    volatile DWORD *spec_adr;
00510 
00511    spec_adr = (DWORD *) (A32D24 + base_adr + COUNTER_READ_CLEAR);
00512    for (i = 0; i < 16; i++) {
00513       *pvalue++ = *spec_adr++;
00514    }
00515 }
00516 
00517 /************ INLINE function for General command ***********/
00518 INLINE void sis3803_OVFL_grp1_read(const DWORD base_adr, DWORD * reg)
00519 /**************************************************************\
00520  Purpose: Read Overflow reg for group 1 (1-8) 
00521  Input:
00522   DWORD base_addr     : base address of the SIS3803
00523  Output:
00524     reg               : pointer to overflow reg 
00525  Function value:
00526  none
00527 \**************************************************************/
00528 {
00529    volatile DWORD *spec_adr;
00530 
00531    spec_adr = (DWORD *) (A32D24 + base_adr + OVERFLOW_REG1_8);
00532    *reg = *spec_adr;
00533    *reg >>= 24;
00534 }
00535 
00536 /************ INLINE function for General command ***********/
00537 INLINE void sis3803_OVFL_grp2_read(const DWORD base_adr, DWORD * reg)
00538 /**************************************************************\
00539  Purpose: Read Overflow reg for group 2 (9-16) 
00540  Input:
00541   DWORD base_addr     : base address of the SIS3803
00542  Output:
00543     reg               : pointer to overflow reg 
00544  Function value:
00545  none
00546 \**************************************************************/
00547 {
00548    volatile DWORD *spec_adr;
00549 
00550    spec_adr = (DWORD *) (A32D24 + base_adr + OVERFLOW_REG9_16);
00551    *reg = *spec_adr;
00552    *reg >>= 24;
00553 }
00554 
00555 /************ INLINE function for General command ***********/
00556 INLINE void sis3803_int_source_enable(const DWORD base_adr, const int intnum)
00557 /**************************************************************\
00558  Purpose: Enable the interrupt for the bitwise input intnum (0xff).
00559           The interrupt vector is then the VECTOR_BASE
00560  Input:
00561   DWORD * base_addr       : base address of the sis3803
00562   DWORD * intnum          : interrupt number (input 0:7)
00563  Output:
00564     none
00565  Function value:
00566     none
00567 \**************************************************************/
00568 {
00569    volatile DWORD *spec_adr;
00570    DWORD int_source;
00571 
00572    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00573    switch (intnum) {
00574    case 0:
00575       int_source = ENABLE_IRQ_EN_BS0;
00576       break;
00577    case 1:
00578       int_source = ENABLE_IRQ_EN_BS1;
00579       break;
00580    case 2:
00581       int_source = ENABLE_IRQ_EN_BS2;
00582       break;
00583    default:
00584       logMsg("Unknown interrupt source (%d)\n", int_source, 0, 0, 0, 0, 0);
00585    }
00586    *spec_adr = int_source;
00587 }
00588 
00589 /************ INLINE function for General command ***********/
00590 INLINE void sis3803_int_source_disable(const DWORD base_adr, const int intnum)
00591 /**************************************************************\
00592  Purpose: Disable the interrupt for the bitwise input intnum (0xff).
00593           The interrupt vector is then the VECTOR_BASE+intnum
00594  Input:
00595   DWORD * base_addr       : base address of the sis3803
00596   int     level           : IRQ level (1..7)
00597   int   * intnum          : interrupt number (input 0..3)
00598  Output:
00599     none
00600  Function value:
00601     none
00602 \**************************************************************/
00603 {
00604    volatile DWORD *spec_adr;
00605    DWORD int_source;
00606 
00607    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00608    switch (intnum) {
00609    case 0:
00610       int_source = DISABLE_IRQ_DI_BS0;
00611       break;
00612    case 1:
00613       int_source = DISABLE_IRQ_DI_BS1;
00614       break;
00615    case 2:
00616       int_source = DISABLE_IRQ_DI_BS2;
00617       break;
00618    default:
00619       logMsg("Unknown interrupt source (%d)\n", int_source, 0, 0, 0, 0, 0);
00620    }
00621    *spec_adr = int_source;
00622 }
00623 
00624 /************ INLINE function for General command ***********/
00625 INLINE void sis3803_int_source(const DWORD base_adr, DWORD int_source)
00626 /**************************************************************\
00627  Purpose: Enable the one of the 4 interrupt using the
00628           predefined parameters (see sis3803.h)
00629  Input:
00630   DWORD * base_addr       : base address of the sis3803
00631   DWORD * intnum          : interrupt number (input 0..3)
00632  Output:
00633     none
00634  Function value:
00635     none
00636 \**************************************************************/
00637 {
00638    volatile DWORD *spec_adr;
00639 
00640    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00641 
00642    int_source &= (ENABLE_IRQ_EN_BS0 | ENABLE_IRQ_EN_BS1
00643                   | ENABLE_IRQ_EN_BS2
00644                   | DISABLE_IRQ_DI_BS0 | DISABLE_IRQ_DI_BS1 | DISABLE_IRQ_DI_BS2);
00645    *spec_adr = int_source;
00646 }
00647 
00648 /************ INLINE function for General command ***********/
00649 INLINE void sis3803_int_attach(const DWORD base_adr, DWORD base_vect, int level,
00650                                void (*isr) (void))
00651 /**************************************************************\
00652  Purpose: Book an ISR for a bitwise set of interrupt input (0xff).
00653           The interrupt vector is then the VECTOR_BASE+intnum
00654  Input:
00655   DWORD * base_addr      : base address of the sis3803
00656   DWORD base_vect        : base vector of the module
00657   int   level            : IRQ level (1..7)
00658   DWORD isr_routine      : interrupt routine pointer
00659  Output:
00660     none
00661  Function value:
00662     none
00663 \**************************************************************/
00664 {
00665    volatile DWORD *spec_adr;
00666 
00667    /* disable all IRQ sources */
00668 /*  Should be done but not in attach 
00669   sis3803_int_source(base_adr
00670                              , DISABLE_IRQ_DI_BS0
00671                              | DISABLE_IRQ_DI_BS1
00672                              | DISABLE_IRQ_DI_BS2);
00673 */
00674 
00675 #ifdef OS_VXWORKS
00676    if ((level < 8) && (level > 0) && (base_vect < 0x100)) {
00677       spec_adr = (DWORD *) (A32D24 + base_adr + IRQ_REG);
00678       *spec_adr = (level << 8) | VME_IRQ_ENABLE | base_vect;
00679       sysIntEnable(level);      /* interrupt level */
00680    }
00681    intConnect(INUM_TO_IVEC(base_vect), (VOIDFUNCPTR) isr, 0);
00682 #else
00683    printf("Not implemented for this OS\n");
00684 #endif
00685 }
00686 
00687 /************ INLINE function for General command ***********/
00688 INLINE void sis3803_int_detach(const DWORD base_adr, DWORD base_vect, int level)
00689 /**************************************************************\
00690  Purpose: Unbook an ISR for a bitwise set of interrupt input (0xff).
00691           The interrupt vector is then the VECTOR_BASE+intnum
00692  Input:
00693   DWORD * base_addr       : base address of the sis3803
00694   DWORD base_vect        : base vector of the module
00695   int   level            : IRQ level (1..7)
00696  Output:
00697     none
00698  Function value:
00699     none
00700 \**************************************************************/
00701 {
00702 
00703    /* disable all IRQ sources */
00704 /*  Should be done but not in detach 
00705   sis3803_int_source(base_adr   , DISABLE_IRQ_DI_BS0
00706                     | DISABLE_IRQ_DI_BS1
00707                     | DISABLE_IRQ_DI_BS2);
00708 */
00709 
00710 #ifdef OS_VXWORKS
00711 /* Suppose to save the default isr before attach but would
00712  * required isr table in case of multiple IRQ
00713  * for now restore with myStub()
00714  */
00715    intConnect(INUM_TO_IVEC(base_vect), (VOIDFUNCPTR) myStub_sis3803, 0);
00716    sysIntDisable(level);        /* interrupt level */
00717 #else
00718    printf("vector : 0x%x\n", base_vect + intnum);
00719 #endif
00720 }
00721 
00722 /************ INLINE function for General command ***********/
00723 INLINE void sis3803_int_clear(const DWORD base_adr, const int intnum)
00724 /**************************************************************\
00725  Purpose: Disable the interrupt for the bitwise input intnum (0xff).
00726           The interrupt vector is then the VECTOR_BASE+intnum
00727  Input:
00728   DWORD * base_addr       : base address of the sis3803
00729   int   * intnum          : interrupt number (input 0..3)
00730  Output:
00731     none
00732  Function value:
00733     none
00734 \**************************************************************/
00735 {
00736    volatile DWORD *spec_adr;
00737    DWORD int_source;
00738 
00739    spec_adr = (DWORD *) (A32D24 + base_adr + CSR_WRITE);
00740    switch (intnum) {
00741    case 0:
00742       int_source = DISABLE_IRQ_DI_BS0;
00743       *spec_adr = int_source;
00744       int_source = ENABLE_IRQ_EN_BS0;
00745       *spec_adr = int_source;
00746       break;
00747    case 1:
00748       int_source = DISABLE_IRQ_DI_BS1;
00749       *spec_adr = int_source;
00750       int_source = ENABLE_IRQ_EN_BS1;
00751       *spec_adr = int_source;
00752       break;
00753    case 2:
00754       int_source = DISABLE_IRQ_DI_BS2;
00755       *spec_adr = int_source;
00756       int_source = ENABLE_IRQ_EN_BS2;
00757       *spec_adr = int_source;
00758       break;
00759    default:
00760       logMsg("Unknown interrupt source (%d)\n", int_source, 0, 0, 0, 0, 0);
00761    }
00762 }
00763 
00764 /************ INLINE function for General command ***********/
00765 void sis3803_setup(const DWORD base_adr, int mode, int dsp)
00766 {
00767    switch (mode) {
00768    case 1:
00769       /* */
00770       if (dsp) {
00771          printf("Setting          : %d \t", mode);
00772          printf("Info             : PAA/June 2000\n");
00773       }
00774       sis3803_module_reset(base_adr);
00775       sis3803_input_mode(base_adr, 1);  /* mode 1 ONLY */
00776       sis3803_all_enable(base_adr);
00777       sis3803_channel_enable(base_adr, 0xf);    /* 4 channels */
00778       if (dsp)
00779          SIS3803_CSR_read(base_adr);
00780       if (dsp)
00781          printf("# of active ch.  : 4\n");
00782       break;
00783    default:
00784       printf("Undefined mode %d (known mode :1, 2, 3, 4, 5)\n", mode);
00785       break;
00786    }
00787 }
00788 
00789 /************ INLINE function for General command ***********/
00790 void sis3803(void)
00791 /**************************************************************\
00792  Purpose: Display SIS3803 build-in commands
00793  Input:
00794     none
00795  Output:
00796     none
00797  Function value:
00798     none
00799 \**************************************************************/
00800 {
00801    printf("\n---> SIS 3803 32 MultiScalers (sis3803.c) <---\n");
00802    printf("Inline : sis3803_module_ID (vmeBase);\n");
00803    printf("Inline : sis3803_IRQ_REG_read(vmeBase);\n");
00804    printf("Inline : sis3803_IRQ_REG_write(vmeBase, irq);\n");
00805    printf("Inline : sis3803_module_reset (vmeBase);\n");
00806    printf("Inline : sis3803_ref1 (vmeBase, enable/disable);\n");
00807    printf("Inline : sis3803_channel_enable (vmeBase, pattern);\n");
00808    printf("Inline : sis3803_channel_disable (vmeBase, pattern);\n");
00809    printf("Inline : sis3803_CSR_read (vmeBase, what);\n");
00810    printf("Inline : sis3803_CSR_write (vmeBase, what);\n");
00811    printf("Inline : sis3803_test_enable(vmeBase);\n");
00812    printf("Inline : sis3803_test_disable(vmeBase);\n");
00813    printf("Inline : sis3803_all_clear(vmeBase);\n");
00814    printf("Inline : sis3803_all_enable(vmeBase);\n");
00815    printf("Inline : sis3803_all_disable(vmeBase);\n");
00816    printf("Inline : sis3803_grp1_clear(vmeBase);\n");
00817    printf("Inline : sis3803_grp2_clear(vmeBase);\n");
00818    printf("Inline : sis3803_single_clear(vmeBase, ch);\n");
00819    printf("Inline : sis3803_single_OVFL_clear(vmeBase, ch);\n");
00820    printf("Inline : sis3803_counter_read(vmeBase, ch, *p);\n");
00821    printf("Inline : sis3803_all_read(vmeBase, *p);\n");
00822    printf("Inline : sis3803_grp1_read(vmeBase, *p);\n");
00823    printf("Inline : sis3803_grp2_read(vmeBase, *p);\n");
00824    printf("Inline : sis3803_all_read_clear(vmeBase, *p);\n");
00825    printf("Inline : sis3803_OVFL_grp1_read(vmeBase, *p);\n");
00826    printf("Inline : sis3803_OVFL_grp2_read(vmeBase, *p);\n");
00827    printf("Inline : sis3803_int_source (vmeBase, enable/disable);\n");
00828    printf("Inline : sis3803_int_source_enable (vmeBase, source (0..3));\n");
00829    printf("Inline : sis3803_int_source_disable (vmeBase, source (0..3));\n");
00830    printf("Inline : sis3803_int_attach (vmeBase, vect, level, void (*isr)(void));\n");
00831    printf("Inline : sis3803_int_detach (vmeBase, vect, level);\n");
00832    printf("Inline : sis3803_int_clear (vmeBase, source (0..3));\n");
00833    printf("         sis3803_setup(vmeBase, mode, display);\n");
00834    printf("calls  : SIS3803_setup( base_adr, mode)\n");
00835    printf("calls  : SIS3803_CSR_read( base_adr)\n");
00836    printf("calls  : SIS3803_all_read( base_adr) 'sis3803_counter_read()'\n");
00837    printf("calls  : SIS3803_all_read_clear( base_adr) 'sis3803_single_clear'\n");
00838    printf("calls  : SIS3803_all_bread( base_adr) 'sis3803_all_read'\n");
00839    printf("calls  : SIS3803_all_bcread( base_adr) 'sis3803_all_read_clear'\n");
00840 }
00841 
00842 /**************************************************************/
00843 void SIS3803_setup(const DWORD base_adr, int mode)
00844 {
00845    sis3803_setup(base_adr, mode, 1);
00846 }
00847 
00848 void SIS3803_CSR_read(const DWORD base_adr)
00849 {
00850    DWORD csr;
00851 
00852    csr = sis3803_CSR_read(base_adr, CSR_FULL);
00853 
00854    printf("Module Version   : %d\t", ((sis3803_module_ID(base_adr) & 0xf000) >> 12));
00855    printf("Module ID        : %4.4x\n", (sis3803_module_ID(base_adr) >> 16));
00856    printf("LED              : %s \t", (csr & IS_LED) ? "Y" : "N");
00857    printf("Input mode       : %d \n", sis3803_input_mode(base_adr, 1));
00858    printf("Reference pulse 1: %s \t", (csr & IS_REF1) ? "Y" : "N");
00859    printf("Global Enable    : %s \t", (csr & IS_GBL_ENABLE) ? "Y" : "N");
00860    printf("Global OVFL bit  : %s \n", (csr & IS_GBL_OVFL) ? "Y" : "N");
00861    printf("IRQ enable BS0   : %s \t", (csr & IS_IRQ_EN_BS0) ? "Y" : "N");
00862    printf("IRQ enable BS1   : %s \t", (csr & IS_IRQ_EN_BS1) ? "Y" : "N");
00863    printf("IRQ enable BS2   : %s \n", (csr & IS_IRQ_EN_BS2) ? "Y" : "N");
00864    printf("IRQ Bit Source 0 : %s \t", (csr & IS_IRQ_BS0) ? "Y" : "N");
00865    printf("IRQ Bit Source 1 : %s \t", (csr & IS_IRQ_BS1) ? "Y" : "N");
00866    printf("IRQ Bit Source 2 : %s \n", (csr & IS_IRQ_BS2) ? "Y" : "N");
00867    printf("internal VME IRQ : %s \t", (csr & 0x4000000) ? "Y" : "N");
00868    printf("VME IRQ          : %s \n", (csr & 0x8000000) ? "Y" : "N");
00869 }
00870 
00871 void SIS3803_all_read(const DWORD base_adr)
00872 {
00873    DWORD count;
00874    INT i;
00875 
00876    for (i = 0; i < 16; i++) {
00877       sis3803_counter_read(base_adr, i, &count);
00878       printf("Counter[%i] : %u\n", i, count);
00879    }
00880 }
00881 
00882 void SIS3803_all_read_clear(const DWORD base_adr)
00883 {
00884    DWORD count;
00885    INT i;
00886 
00887    for (i = 0; i < 16; i++) {
00888       sis3803_counter_read(base_adr, i, &count);
00889       sis3803_single_clear(base_adr, i);
00890       printf("Counter[%i] : %u\n", i, count);
00891    }
00892 }
00893 
00894 void SIS3803_all_bread(const DWORD base_adr)
00895 {
00896    DWORD count[16];
00897    INT i;
00898 
00899    sis3803_all_read(base_adr, &(count[0]));
00900    for (i = 0; i < 16; i++) {
00901       printf("Counter[%i] : %u 0x%x\n", i, count[i], count[i]);
00902    }
00903 }
00904 
00905 void SIS3803_all_bcread(const DWORD base_adr)
00906 {
00907    DWORD count[16];
00908    INT i;
00909 
00910    sis3803_all_read_clear(base_adr, &(count[0]));
00911    for (i = 0; i < 16; i++) {
00912       printf("Counter[%i] : %u\n", i, count[i]);
00913    }
00914 }
00915 
00916 DWORD *p = NULL;
00917 
00918 void test(DWORD mem)
00919 {
00920    PART_ID part_id;
00921 
00922    if (p != NULL)
00923       free(p);
00924    (char *) p = malloc(mem);
00925 }

Midas DOC Version 2.0.2 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk