Skip to content

Commit 0a62603

Browse files
authored
Merge pull request #4320 from BsAtHome/halgs_drivers-uspace-2
hal: Update the last uspace drivers to getter/setter
2 parents a74d308 + 567afbd commit 0a62603

6 files changed

Lines changed: 1012 additions & 1064 deletions

File tree

src/hal/drivers/gm.h

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,53 +32,51 @@
3232
#define notPresented 0x00000000
3333

3434
typedef struct {
35-
hal_u32_t serialModulesDataOut[16][8]; // 0000 0000
36-
hal_u32_t serialModulesDataIn[16][8]; // 1000 0000
37-
38-
hal_u32_t moduleId[8]; //addr 0 0000 000
39-
40-
hal_u32_t card_status_reg; //addr 1 0001 000 // ... Estop_2 | Estop_1 | Pwr_fault | Bus_err | Wdt_err //Card status read resets wdt
41-
hal_u32_t cardID; // 0001 001
42-
hal_u32_t card_control_reg; // 0001 010 // Wdt_period(16 bit)[us] | ... | EstopEn_2 | EstopEn_1 | power_enable | card_enable
43-
hal_u32_t reserved_0; // 0001 011
44-
hal_u32_t gpio; // 0001 100
45-
hal_u32_t gpioDir; // 0001 101
46-
hal_u32_t StepGen_status; // 0001 110
47-
hal_u32_t PCI_clk_counter; // 0001 111
48-
49-
hal_u32_t ENC_control_reg; //addr 2 0010 000
50-
hal_u32_t CAN_status_reg;
51-
hal_u32_t CAN_control_reg;
52-
hal_u32_t DAC_0; //DAC AXIS 1-0
53-
hal_u32_t DAC_1; //DAC AXIS 3-2
54-
hal_u32_t DAC_2; //DAC AXIS 5-4
55-
hal_u32_t reserved_1[2];
56-
57-
hal_u32_t CAN_RX_buffer[4]; //addr 3 0011 000
58-
hal_u32_t CAN_TX_buffer[4];
59-
hal_u32_t reserved_2[8]; //addr 4 0100 000
60-
61-
hal_u32_t reserved_3[8]; //addr 5 0101 000
62-
63-
hal_u32_t reserved_4[8]; //addr 6 0110 000
64-
65-
hal_u32_t reserved_5[8]; //addr 7 0111 000
66-
67-
hal_s32_t ENC_counter[6]; //addr 8 1000 000
68-
hal_u32_t reserved_6[2];
69-
hal_s32_t ENC_period[6]; //addr 9 1001 000
70-
hal_u32_t reserved_7[2];
71-
hal_s32_t ENC_index_latch[6]; //addr 10 1010 000
72-
hal_u32_t reserved_8[2];
73-
hal_s32_t reserved_9[8]; //addr 11 1011 000
74-
75-
hal_s32_t StepGen_steprate[6]; //addr 12 1100 000
76-
hal_u32_t reserved_10[2];
77-
hal_u32_t StepGen_fb[6]; //addr 13 1101 000
78-
hal_u32_t reserved_11[2];
79-
hal_u32_t StepGen_time_params[6]; //addr 14 1110 000
80-
hal_u32_t reserved_12[2];
81-
hal_u32_t reserved_16[8]; //addr 15 1111 000
35+
volatile rtapi_u32 serialModulesDataOut[16][8]; // 0000 0000
36+
volatile rtapi_u32 serialModulesDataIn[16][8]; // 1000 0000
37+
38+
volatile rtapi_u32 moduleId[8]; // addr 0 0000 000
39+
40+
volatile rtapi_u32 card_status_reg; // addr 1 0001 000 // ... Estop_2 | Estop_1 | Pwr_fault | Bus_err | Wdt_err //Card status read resets wdt
41+
volatile rtapi_u32 cardID; // 0001 001
42+
volatile rtapi_u32 card_control_reg; // 0001 010 // Wdt_period(16 bit)[us] | ... | EstopEn_2 | EstopEn_1 | power_enable | card_enable
43+
volatile rtapi_u32 reserved_0; // 0001 011
44+
volatile rtapi_u32 gpio; // 0001 100
45+
volatile rtapi_u32 gpioDir; // 0001 101
46+
volatile rtapi_u32 StepGen_status; // 0001 110
47+
volatile rtapi_u32 PCI_clk_counter; // 0001 111
48+
49+
volatile rtapi_u32 ENC_control_reg; // addr 2 0010 000
50+
volatile rtapi_u32 CAN_status_reg;
51+
volatile rtapi_u32 CAN_control_reg;
52+
volatile rtapi_u32 DAC_0; // DAC AXIS 1-0
53+
volatile rtapi_u32 DAC_1; // DAC AXIS 3-2
54+
volatile rtapi_u32 DAC_2; // DAC AXIS 5-4
55+
volatile rtapi_u32 reserved_1[2];
56+
57+
volatile rtapi_u32 CAN_RX_buffer[4]; // addr 3 0011 000
58+
volatile rtapi_u32 CAN_TX_buffer[4];
59+
60+
volatile rtapi_u32 reserved_2[8]; // addr 4 0100 000
61+
volatile rtapi_u32 reserved_3[8]; // addr 5 0101 000
62+
volatile rtapi_u32 reserved_4[8]; // addr 6 0110 000
63+
volatile rtapi_u32 reserved_5[8]; // addr 7 0111 000
64+
65+
volatile rtapi_s32 ENC_counter[6]; // addr 8 1000 000
66+
volatile rtapi_u32 reserved_6[2];
67+
volatile rtapi_s32 ENC_period[6]; // addr 9 1001 000
68+
volatile rtapi_u32 reserved_7[2];
69+
volatile rtapi_s32 ENC_index_latch[6]; // addr 10 1010 000
70+
volatile rtapi_u32 reserved_8[2];
71+
volatile rtapi_s32 reserved_9[8]; // addr 11 1011 000
72+
73+
volatile rtapi_s32 StepGen_steprate[6]; // addr 12 1100 000
74+
volatile rtapi_u32 reserved_10[2];
75+
volatile rtapi_u32 StepGen_fb[6]; // addr 13 1101 000
76+
volatile rtapi_u32 reserved_11[2];
77+
volatile rtapi_u32 StepGen_time_params[6]; // addr 14 1110 000
78+
volatile rtapi_u32 reserved_12[2];
79+
volatile rtapi_u32 reserved_16[8]; // addr 15 1111 000
8280

8381
} volatile card;
8482

src/hal/drivers/hal_bb_gpio.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ MODULE_LICENSE("GPL");
3434
#define PINS_PER_HEADER 46
3535

3636
typedef struct {
37-
hal_bit_t* led_pins[4];
38-
hal_bit_t* input_pins[1 + PINS_PER_HEADER * HEADERS]; // array of pointers to bivts
39-
hal_bit_t* output_pins[1 + PINS_PER_HEADER * HEADERS]; // array of pointers to bits
40-
hal_bit_t *led_inv[4];
41-
hal_bit_t *input_inv[1 + PINS_PER_HEADER * HEADERS];
42-
hal_bit_t *output_inv[1 + PINS_PER_HEADER * HEADERS];
37+
hal_bool_t led_pins[4];
38+
hal_bool_t input_pins[1 + PINS_PER_HEADER * HEADERS]; // array of pointers to bivts
39+
hal_bool_t output_pins[1 + PINS_PER_HEADER * HEADERS]; // array of pointers to bits
40+
hal_bool_t led_inv[4];
41+
hal_bool_t input_inv[1 + PINS_PER_HEADER * HEADERS];
42+
hal_bool_t output_inv[1 + PINS_PER_HEADER * HEADERS];
4343
} port_data_t;
4444

4545
static port_data_t *port_data;
@@ -169,7 +169,7 @@ int rtapi_app_main(void) {
169169
}
170170

171171
// Add HAL pin
172-
retval = hal_pin_bit_newf(HAL_IN, &(port_data->led_pins[led]), comp_id, "bb_gpio.userled%d", led);
172+
retval = hal_pin_new_bool(comp_id, HAL_IN, &(port_data->led_pins[led]), 0, "bb_gpio.userled%d", led);
173173

174174
if(retval < 0) {
175175
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: userled %d could not export pin, err: %d\n", modname, led, retval);
@@ -178,17 +178,14 @@ int rtapi_app_main(void) {
178178
}
179179

180180
// Add HAL pin
181-
retval = hal_pin_bit_newf(HAL_IN, &(port_data->led_inv[led]), comp_id, "bb_gpio.userled%d-invert", led);
181+
retval = hal_pin_new_bool(comp_id, HAL_IN, &(port_data->led_inv[led]), 0, "bb_gpio.userled%d-invert", led);
182182

183183
if(retval < 0) {
184184
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: userled %d could not export pin, err: %d\n", modname, led, retval);
185185
hal_exit(comp_id);
186186
return -1;
187187
}
188188

189-
// Initialize HAL pin
190-
*(port_data->led_inv[led]) = 0;
191-
192189
int gpio_num = user_led_gpio_pins[led].port_num;
193190
// configure gpio port if necessary
194191
if(gpio_ports[gpio_num] == NULL) {
@@ -241,7 +238,7 @@ int rtapi_app_main(void) {
241238
data = NULL; // after the first call, subsequent calls to strtok need to be on NULL
242239

243240
// Add HAL pin
244-
retval = hal_pin_bit_newf(HAL_OUT, &(port_data->input_pins[pin + (header - 8)*PINS_PER_HEADER]), comp_id, "bb_gpio.p%d.in-%02d", header, pin);
241+
retval = hal_pin_new_bool(comp_id, HAL_OUT, &(port_data->input_pins[pin + (header - 8)*PINS_PER_HEADER]), 0, "bb_gpio.p%d.in-%02d", header, pin);
245242

246243
if(retval < 0) {
247244
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: pin p%d.%02d could not export pin, err: %d\n", modname, header, pin, retval);
@@ -250,17 +247,14 @@ int rtapi_app_main(void) {
250247
}
251248

252249
// Add HAL pin
253-
retval = hal_pin_bit_newf(HAL_IN, &(port_data->input_inv[pin + (header - 8)*PINS_PER_HEADER]), comp_id, "bb_gpio.p%d.in-%02d-invert", header, pin);
250+
retval = hal_pin_new_bool(comp_id, HAL_IN, &(port_data->input_inv[pin + (header - 8)*PINS_PER_HEADER]), 0, "bb_gpio.p%d.in-%02d-invert", header, pin);
254251

255252
if(retval < 0) {
256253
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: pin p%d.%02d could not export pin, err: %d\n", modname, header, pin, retval);
257254
hal_exit(comp_id);
258255
return -1;
259256
}
260257

261-
// Initialize HAL pin
262-
*(port_data->input_inv[pin + (header - 8)*PINS_PER_HEADER]) = 0;
263-
264258
int gpio_num = bbpin->port_num;
265259

266260
// configure gpio port if necessary
@@ -315,7 +309,7 @@ int rtapi_app_main(void) {
315309
data = NULL; // after the first call, subsequent calls to strtok need to be on NULL
316310

317311
// Add HAL pin
318-
retval = hal_pin_bit_newf(HAL_IN, &(port_data->output_pins[pin + (header - 8)*PINS_PER_HEADER]), comp_id, "bb_gpio.p%d.out-%02d", header, pin);
312+
retval = hal_pin_new_bool(comp_id, HAL_IN, &(port_data->output_pins[pin + (header - 8)*PINS_PER_HEADER]), 0, "bb_gpio.p%d.out-%02d", header, pin);
319313

320314
if(retval < 0) {
321315
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: pin p%d.%02d could not export pin, err: %d\n", modname, header, pin, retval);
@@ -324,17 +318,14 @@ int rtapi_app_main(void) {
324318
}
325319

326320
// Add HAL pin
327-
retval = hal_pin_bit_newf(HAL_IN, &(port_data->output_inv[pin + (header - 8)*PINS_PER_HEADER]), comp_id, "bb_gpio.p%d.out-%02d-invert", header, pin);
321+
retval = hal_pin_new_bool(comp_id, HAL_IN, &(port_data->output_inv[pin + (header - 8)*PINS_PER_HEADER]), 0, "bb_gpio.p%d.out-%02d-invert", header, pin);
328322

329323
if(retval < 0) {
330324
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: pin p%d.%02d could not export pin, err: %d\n", modname, header, pin, retval);
331325
hal_exit(comp_id);
332326
return -1;
333327
}
334328

335-
// Initialize HAL pin
336-
*(port_data->output_inv[pin + (header - 8)*PINS_PER_HEADER]) = 0;
337-
338329
int gpio_num = bbpin->port_num;
339330

340331
// configure gpio port if necessary
@@ -393,7 +384,7 @@ static void write_port(void *arg, long period) {
393384

394385
if(pin.claimed != 'O') continue; // if we somehow get here but the pin isn't claimed as output, short circuit
395386

396-
if((*port->led_pins[i] ^ *(port->led_inv[i])) == 0)
387+
if((hal_get_bool(port->led_pins[i]) ^ hal_get_bool(port->led_inv[i])) == 0)
397388
*(pin.port->clrdataout_reg) = (1 << pin.pin_num);
398389
else
399390
*(pin.port->setdataout_reg) = (1 << pin.pin_num);
@@ -412,7 +403,7 @@ static void write_port(void *arg, long period) {
412403

413404
if(pin.claimed != 'O') continue; // if we somehow get here but the pin isn't claimed as output, short circuit
414405

415-
if((*port->output_pins[i] ^ *(port->output_inv[i])) == 0)
406+
if((hal_get_bool(port->output_pins[i]) ^ hal_get_bool(port->output_inv[i])) == 0)
416407
*(pin.port->clrdataout_reg) = (1 << pin.pin_num);
417408
else
418409
*(pin.port->setdataout_reg) = (1 << pin.pin_num);
@@ -440,7 +431,7 @@ static void read_port(void *arg, long period) {
440431

441432
if(!(pin.claimed == 'I' || pin.claimed == 'U' || pin.claimed == 'D')) continue; // if we get here but the pin isn't claimed as input, short circuit
442433

443-
*port->input_pins[i] = ((*(pin.port->datain_reg) & (1 << pin.pin_num)) >> pin.pin_num) ^ *(port->input_inv[i]);
434+
hal_set_bool(port->input_pins[i], ((*(pin.port->datain_reg) & (1 << pin.pin_num)) >> pin.pin_num) ^ hal_get_bool(port->input_inv[i]));
444435
}
445436
}
446437

src/hal/drivers/hal_evoreg.c

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ RTAPI_MP_STRING(cfg, "config string"); */
8686
*/
8787

8888
typedef struct {
89-
void *io_base;
90-
hal_float_t *dac_out[3]; /* ptrs for dac output */
91-
hal_float_t *position[3]; /* ptrs for encoder input */
92-
hal_bit_t *digital_in[47]; /* ptrs for digital input pins 0 - 45 */
93-
hal_bit_t *digital_out[25]; /* ptrs for digital output pins 0 - 20 */
94-
__u16 raw_counts_old[3];
95-
__s32 counts[3];
96-
hal_float_t pos_scale; /*! \todo scale for position command FIXME should be one per axis */
89+
void *io_base;
90+
hal_real_t dac_out[3]; /* ptrs for dac output */
91+
hal_real_t position[3]; /* ptrs for encoder input */
92+
hal_bool_t digital_in[47]; /* ptrs for digital input pins 0 - 45 */
93+
hal_bool_t digital_out[25]; /* ptrs for digital output pins 0 - 20 */
94+
rtapi_u16 raw_counts_old[3];
95+
rtapi_s32 counts[3];
96+
hal_real_t pos_scale; /*! \todo scale for position command FIXME should be one per axis */
9797
} evoreg_t;
9898

9999
/* pointer to array of evoreg_t structs in shared memory, 1 per port */
@@ -172,8 +172,8 @@ int rtapi_app_main(void)
172172

173173
/* Export DAC pin's */
174174
for ( num_dac=1; num_dac<=MAX_DAC; num_dac++) {
175-
retval = hal_pin_float_newf(HAL_IN, &(port_data_array->dac_out[num_dac-1]),
176-
comp_id, "evoreg.%d.dac-%02d-out", 1, num_dac);
175+
retval = hal_pin_new_real(comp_id, HAL_IN, &(port_data_array->dac_out[num_dac-1]),
176+
0.0, "evoreg.%d.dac-%02d-out", 1, num_dac);
177177
if (retval < 0) {
178178
rtapi_print_msg(RTAPI_MSG_ERR,
179179
"EVOREG: ERROR: port %d var export failed with err=%i\n", n + 1,
@@ -185,8 +185,8 @@ int rtapi_app_main(void)
185185

186186
/* Export Encoder pin's */
187187
for ( num_enc=1; num_enc<=MAX_ENC; num_enc++) {
188-
retval = hal_pin_float_newf(HAL_OUT, &(port_data_array->position[num_enc - 1]),
189-
comp_id, "evoreg.%d.position-%02d-in", 1, num_enc);
188+
retval = hal_pin_new_real(comp_id, HAL_OUT, &(port_data_array->position[num_enc - 1]),
189+
0.0, "evoreg.%d.position-%02d-in", 1, num_enc);
190190
if (retval < 0) {
191191
rtapi_print_msg(RTAPI_MSG_ERR,
192192
"EVOREG: ERROR: port %d var export failed with err=%i\n", n + 1,
@@ -200,8 +200,8 @@ int rtapi_app_main(void)
200200

201201
/* export write only HAL pin's for the input bit */
202202
for ( i=0; i<=45;i++) {
203-
retval += hal_pin_bit_newf(HAL_OUT, &(port_data_array->digital_in[i]),
204-
comp_id, "evoreg.%d.pin-%02d-in", 1, i);
203+
retval += hal_pin_new_bool(comp_id, HAL_OUT, &(port_data_array->digital_in[i]),
204+
0, "evoreg.%d.pin-%02d-in", 1, i);
205205

206206
/* export another write only HAL pin for the same bit inverted */
207207
/*
@@ -218,8 +218,8 @@ int rtapi_app_main(void)
218218

219219
/* export read only HAL pin's for the output bit */
220220
for ( i=0; i<=23;i++) {
221-
retval += hal_pin_bit_newf(HAL_IN, &(port_data_array->digital_out[i]),
222-
comp_id, "evoreg.%d.pin-%02d-out", 1, i);
221+
retval += hal_pin_new_bool(comp_id, HAL_IN, &(port_data_array->digital_out[i]),
222+
0, "evoreg.%d.pin-%02d-out", 1, i);
223223

224224
/* export another read only HAL pin for the same bit inverted */
225225
/*
@@ -235,8 +235,8 @@ int rtapi_app_main(void)
235235
}
236236

237237
/* export parameter for scaling */
238-
retval = hal_param_float_newf(HAL_RW, &(port_data_array->pos_scale),
239-
comp_id, "evoreg.%d.position-scale", 1);
238+
retval = hal_param_new_real(comp_id, HAL_RW, &(port_data_array->pos_scale),
239+
0.0, "evoreg.%d.position-scale", 1);
240240
if (retval != 0) {
241241
return retval;
242242
}
@@ -278,9 +278,9 @@ static void update_port(void *arg, long period)
278278
port = arg;
279279

280280
/* write DAC's */
281-
writew((*(port->dac_out[0])/10 * 0x7fff), (char *)port->io_base + 0x60);
282-
writew((*(port->dac_out[1])/10 * 0x7fff), (char *)port->io_base + 0x80);
283-
writew((*(port->dac_out[2])/10 * 0x7fff), (char *)port->io_base + 0xa0);
281+
writew((hal_get_real(port->dac_out[0])/10 * 0x7fff), (char *)port->io_base + 0x60);
282+
writew((hal_get_real(port->dac_out[1])/10 * 0x7fff), (char *)port->io_base + 0x80);
283+
writew((hal_get_real(port->dac_out[2])/10 * 0x7fff), (char *)port->io_base + 0xa0);
284284

285285
/* Read Encoders, improve the 16bit hardware counters to 32bit and scale the values */
286286
raw_counts[0] = (__u16) readw(port->io_base);
@@ -296,29 +296,30 @@ static void update_port(void *arg, long period)
296296
port->counts[2] += (__s16) (raw_counts[2] - port->raw_counts_old[2]);
297297
port->raw_counts_old[2] = raw_counts[2];
298298

299-
*port->position[0] = port->counts[0] * port->pos_scale;
300-
*port->position[1] = port->counts[1] * port->pos_scale;
301-
*port->position[2] = port->counts[2] * port->pos_scale;
299+
rtapi_real pos_scale = hal_get_real(port->pos_scale);
300+
hal_set_real(port->position[0], port->counts[0] * pos_scale);
301+
hal_set_real(port->position[1], port->counts[1] * pos_scale);
302+
hal_set_real(port->position[2], port->counts[2] * pos_scale);
302303

303304

304305
/* read digital inputs */
305306
tmp = readw((char *)port->io_base + 0x20); /* digital input 0-15 */
306307
mask = 0x01;
307308
for (pin=0 ; pin < 16 ; pin++) {
308-
*port->digital_in[pin] = (tmp & mask) ? 1:0 ;
309+
hal_set_bool(port->digital_in[pin], (tmp & mask) ? 1:0);
309310
mask <<= 1;
310311
}
311312
tmp = readw((char *)port->io_base + 0x40); /* digital input 16-31 */
312313
mask = 0x01;
313314
for (pin=16 ; pin < 32 ; pin++) {
314-
*port->digital_in[pin] = (tmp & mask) ? 1:0 ;
315+
hal_set_bool(port->digital_in[pin], (tmp & mask) ? 1:0);
315316
mask <<= 1;
316317
}
317318

318319
tmp = readw((char *)port->io_base + 0x60); /* digital input 32-45 */
319320
mask = 0x01;
320321
for (pin=32 ; pin < 46 ; pin++) {
321-
*port->digital_in[pin] = (tmp & mask) ? 1:0 ;
322+
hal_set_bool(port->digital_in[pin], (tmp & mask) ? 1:0);
322323
mask <<= 1;
323324
}
324325

@@ -327,21 +328,21 @@ static void update_port(void *arg, long period)
327328
tmp = 0x0;
328329
mask = 0x01;
329330
for (pin=0; pin < 16; pin++) {
330-
if (port->digital_out[pin]) {
331+
if (hal_get_bool(port->digital_out[pin])) {
331332
tmp |= mask;
332-
mask <<= 1;
333333
}
334+
mask <<= 1;
334335
}
335336
writew( tmp, (char *)port->io_base + 0x20); /* digital output 0-15 */
336337

337338

338339
tmp = 0x0;
339340
mask = 0x01;
340341
for (pin=16; pin < 24; pin++) {
341-
if (port->digital_out[pin]) {
342+
if (hal_get_bool(port->digital_out[pin])) {
342343
tmp |= mask;
343-
mask <<= 1;
344344
}
345+
mask <<= 1;
345346
}
346347
writew( tmp, (char *)port->io_base + 0x40); /* digital output 16-23 */
347348

0 commit comments

Comments
 (0)