KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
octocpld.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : octoclpd.h
11  * Created : 21 jan. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #ifndef OCTOCPLD_H_
16 #define OCTOCPLD_H_
17 
18 /**
19  * @file
20  *
21  * @ingroup i2cdrivers
22  *
23  * This driver encapsulates the functionality of the CPLD on the octopus board.
24  *
25  * Though on the CPLD each registers byte can be read separately this driver groups all 3 bytes
26  * into one 32 bit register. Thus when reading the ocRegFault register the fault status of all
27  * 20 channels is returned in one 32 bit integer, where each bit position corresponds to its
28  * respective channel.
29  */
30 
31 #include "drv/wb/i2c.h"
32 #include "kernel/tm.h"
33 
34 /**
35  * Octopus CPLD registers.
36  */
37 typedef enum {
38  ocRegOn = 0, //!< PMT On register
39  ocRegFault = 4, //!< Fault register
40  ocRegClkEn = 8 //!< Clock enable
41 } OCReg;
42 
43 
44 /**
45  * Reads one of the CPLD registers.
46  *
47  * @param dev The I2C device
48  * @param addr The I2C address
49  * @param reg The CPLD register (ocRegOn, ocRegFault or orRegClkEn)
50  * @param value A pointer to a 32 bit integer to fill as bit mask.
51  *
52  * @retval true Success
53  * @retval false Failure
54  */
55 bool ocRead(I2C_Device * dev, uint8_t addr, OCReg reg, uint32_t * value);
56 
57 /**
58  * Writes one of the CPLD registers.
59  *
60  * @param dev The I2C device
61  * @param addr The I2C address
62  * @param reg The CPLD register (ocRegOn, ocRegFault or orRegClkEn)
63  * @param value A 32bit integer as bitmask, where each bit corresponds to its channel
64  *
65  * @retval true Success
66  * @retval false Failure
67  */
68 bool ocWrite(I2C_Device * dev, uint8_t addr, OCReg reg, uint32_t value);
69 
70 /**
71  * Wakes up the octopus board, apparently it needs it.
72  *
73  * @param dev
74  * @return
75  */
76 static inline bool ocWakeUp(I2C_Device * dev, uint8_t addr)
77 {
78  uint32_t x;
79 
80  int i = 10;
81 
82  while (i > 0) {
83  if (!ocRead(dev, addr, ocRegOn, &x)) {
84  timeDelay(200);
85  } else {
86  i = -1;
87  errClear();
88  break;
89  }
90  i--;
91  }
92 
93  return (i == -1);
94 }
95 
96 
97 
98 #endif /* OCTOCPLD_H_ */
Fault register.
Definition: octocpld.h:39
Structure defines OpenCores I2C Device.
Definition: dev_i2c.h:55
void timeDelay(uint32_t msec)
Simple busy-wait delay.
Definition: tm.c:18
OCReg
Octopus CPLD registers.
Definition: octocpld.h:37
Clock enable.
Definition: octocpld.h:40
PMT On register.
Definition: octocpld.h:38
Simple timer functions.
bool ocWrite(I2C_Device *dev, uint8_t addr, OCReg reg, uint32_t value)
Writes one of the CPLD registers.
Definition: octocpld.c:31
void errClear()
Clears the current error.
Definition: err.c:46
bool ocRead(I2C_Device *dev, uint8_t addr, OCReg reg, uint32_t *value)
Reads one of the CPLD registers.
Definition: octocpld.c:18
static bool ocWakeUp(I2C_Device *dev, uint8_t addr)
Wakes up the octopus board, apparently it needs it.
Definition: octocpld.h:76
OpenCores I2C device driver.