KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
octocpld.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : octocpld.c
11  * Created : 21 jan. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #include "drv/i2c/octocpld.h"
16 // #include <stdio.h>
17 
18 bool ocRead(I2C_Device * dev, uint8_t addr, OCReg reg, uint32_t * value)
19 {
20  uint8_t rd[3];
21 
22  if (!i2cReadReg(dev, addr, reg, rd, sizeof(rd))) return errRebase("OctoCPLD");
23 
24  *value = rd[0] | ( rd[1] << 8 ) | ( rd[2] << 16 );
25 
26 // printf("Read CPLD reg %d: %06x\n", reg, *value);
27 
28  return true;
29 }
30 
31 bool ocWrite(I2C_Device * dev, uint8_t addr, OCReg reg, uint32_t value)
32 {
33  uint8_t wr[3];
34 
35  // fault register can not be written.
36  if (reg == ocRegFault) return errSet(ERROR(E_INVARGUMENT));
37 
38 // printf("Write CPLD reg %d: %06x\n", reg, value);
39 
40  wr[0] = value & 0xff;
41  wr[1] = (value >> 8) & 0xff;
42  wr[2] = (value >> 16) & 0xff;
43 
44  return i2cWriteReg(dev, addr, reg, wr, sizeof(wr));
45 }
Fault register.
Definition: octocpld.h:39
Structure defines OpenCores I2C Device.
Definition: dev_i2c.h:55
OCReg
Octopus CPLD registers.
Definition: octocpld.h:37
bool i2cReadReg(I2C_Device *dev, i2cAddr addr, uint8_t regNo, uint8_t *rd, int rdLen)
Reads from the I2C device register.
Definition: i2c.c:188
#define E_INVARGUMENT
Generic error: invalid argument.
Definition: errorcode.h:112
bool i2cWriteReg(I2C_Device *dev, i2cAddr addr, uint8_t regNo, uint8_t *wr, int wrLen)
Writes to the I2C device register.
Definition: i2c.c:247
bool ocWrite(I2C_Device *dev, uint8_t addr, OCReg reg, uint32_t value)
Writes one of the CPLD registers.
Definition: octocpld.c:31
static bool errRebase(const char *name)
Rebases the cause of the error message.
Definition: err.h:104
bool ocRead(I2C_Device *dev, uint8_t addr, OCReg reg, uint32_t *value)
Reads one of the CPLD registers.
Definition: octocpld.c:18
This driver encapsulates the functionality of the CPLD on the octopus board.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).