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