ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcbAFE.hpp
Go to the documentation of this file.
1
7#ifndef ngcbAFE_H
8#define ngcbAFE_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14
15#include <stdio.h>
16#include <stdlib.h>
17
18
22class ngcbAFE {
23public:
25 ngcbAFE() {erms_[0] = '\0';}
26
28 virtual ~ngcbAFE() {}
29
31 char *ErrMsg() {return (erms_);}
32
34 int Write(int addr, int value) {
35 int buffer[64];
36 int reg = addr & 0x0F00;
37 int side = (addr & 0x0080) >> 7;
38 int tx = 0;
39 int i, res;
40 int scl = 0x3 << 4;
41
42 /*
43 * Clear error message
44 */
45 erms_[0] = '\0';
46
47 /*
48 * Init write
49 */
50 buffer[tx++] = 0x0;
51 buffer[tx++] = 0x0;
52 buffer[tx++] = reg;
53 buffer[tx++] = reg | scl;
54
55 /*
56 * 3-Bit address
57 */
58 for (i=0;i<2;i++)
59 {
60 int d = ((addr >> i) & 0x1);
61 d |= (d << 1);
62 buffer[tx++] = reg | d;
63 buffer[tx++] = reg | d | scl;
64 }
65
66 /*
67 * Test bit
68 */
69 buffer[tx++] = reg;
70 buffer[tx++] = reg | scl;
71
72 /*
73 * 11-Bit data
74 */
75 for (i=0;i<11;i++)
76 {
77 int d = ((value >> i) & 0x1);
78 d |= (d << 1);
79 buffer[tx++] = reg | d;
80 buffer[tx++] = reg | d | scl;
81 }
82
83 /*
84 * End;
85 */
86 buffer[tx++] = 0x0;
87 buffer[tx++] = 0x0;
88
89 /*
90 * Now send the buffer
91 */
92 for (i=0;i<tx;i++)
93 {
94 if (OutCB(side, buffer[i], &res, erms_) != 0)
95 {
96 return (res);
97 }
98 }
99
100 return (0);
101 }
102
103protected:
105 virtual int OutCB(int side, int d, int *resultCode, char *erms) {
106 char s[33];
107 *resultCode = 0;
108 erms[0] = '\0';
109 Int2Bin_(s, d);
110 if (side == 0) fprintf(stdout, "L: <%s> <0x%04X>\n", s, d & 0xffff);
111 else fprintf(stdout, "R: <%s> <0x%04X>\n", s, d & 0xffff);
112 return (0);
113 }
114
115private:
117 char erms_[256];
118
120 void Int2Bin_(char *str, int in) {
121 int x = in;
122 int i;
123
124 for (i=0;i<32;i++)
125 {
126 if ((x & 0x00000001) == 1) str[31 - i]='1';
127 else str[31 - i]='0';
128 x = x >> 1;
129 }
130 str[32] = '\0';
131 }
132
133};
134
135#endif
virtual ~ngcbAFE()
Destructor.
Definition ngcbAFE.hpp:28
virtual int OutCB(int side, int d, int *resultCode, char *erms)
Output call-back (1 word)
Definition ngcbAFE.hpp:105
int Write(int addr, int value)
11-bit write operation
Definition ngcbAFE.hpp:34
ngcbAFE()
Constructor.
Definition ngcbAFE.hpp:25
char * ErrMsg()
Return current error-message.
Definition ngcbAFE.hpp:31