@@ -141,7 +141,7 @@ int hm2_absenc_setup_ssi(hostmot2_t *hm2, hm2_sserial_remote_t *chan,
141141
142142 if ( hm2_sserial_create_pins (hm2 , chan )) return - EINVAL ;
143143
144- chan -> params = hal_malloc (sizeof (hm2_sserial_params_t ));
144+ chan -> params = hal_malloc (sizeof (* chan -> params ));
145145 hm2 -> absenc .clock_frequency = md -> clock_freq ;
146146 hm2 -> absenc .ssi_version = md -> version ;
147147
@@ -158,9 +158,12 @@ int hm2_absenc_setup_ssi(hostmot2_t *hm2, hm2_sserial_remote_t *chan,
158158 + (3 * md -> register_stride );
159159 chan -> data_written [0 ] = 0 ;
160160
161-
162- chan -> params -> float_param = 500 ;
163- chan -> params -> timer_num = 0 ;
161+ if (hal_param_new_real (hm2 -> llio -> comp_id , HAL_RW , & (chan -> params -> param .r ),
162+ 500.0 , "%s.frequency-khz" , chan -> name )){
163+ HM2_ERR ("error adding frequency param for %s, aborting\n" ,
164+ chan -> name );
165+ return - EINVAL ;
166+ }
164167 return 0 ;
165168}
166169
@@ -169,7 +172,7 @@ int hm2_absenc_setup_biss(hostmot2_t *hm2, hm2_sserial_remote_t *chan,
169172
170173 if ( hm2_sserial_create_pins (hm2 , chan )) return - EINVAL ;
171174
172- chan -> params = hal_malloc (sizeof (hm2_sserial_params_t ));
175+ chan -> params = hal_malloc (sizeof (* chan -> params ));
173176 hm2 -> absenc .clock_frequency = md -> clock_freq ;
174177 hm2 -> absenc .biss_version = md -> version ;
175178
@@ -185,9 +188,13 @@ int hm2_absenc_setup_biss(hostmot2_t *hm2, hm2_sserial_remote_t *chan,
185188 hm2 -> absenc .biss_global_start_addr = md -> base_address
186189 + (3 * md -> register_stride );
187190 chan -> data_written [0 ] = 0 ;
188-
189- chan -> params -> float_param = 500 ;
190- chan -> params -> timer_num = 0 ;
191+
192+ if (hal_param_new_real (hm2 -> llio -> comp_id , HAL_RW , & (chan -> params -> param .r ),
193+ 500.0 , "%s.frequency-khz" , chan -> name )){
194+ HM2_ERR ("error adding frequency param for %s, aborting\n" ,
195+ chan -> name );
196+ return - EINVAL ;
197+ }
191198 return 0 ;
192199}
193200
@@ -196,7 +203,7 @@ int hm2_absenc_setup_fabs(hostmot2_t *hm2, hm2_sserial_remote_t *chan,
196203
197204 if ( hm2_sserial_create_pins (hm2 , chan )) return - EINVAL ;
198205
199- chan -> params = hal_malloc (sizeof (hm2_sserial_params_t ));
206+ chan -> params = hal_malloc (sizeof (* chan -> params ));
200207 hm2 -> absenc .clock_frequency = md -> clock_freq ;
201208 hm2 -> absenc .fanuc_version = md -> version ;
202209
@@ -219,16 +226,23 @@ int hm2_absenc_setup_fabs(hostmot2_t *hm2, hm2_sserial_remote_t *chan,
219226 + (5 * md -> register_stride );
220227 chan -> data_written [0 ] = 0 ;
221228
222- if (hal_param_u32_newf (HAL_RW , & (chan -> params -> u32_param ),
223- hm2 -> llio -> comp_id ,"%s.filter" ,
224- chan -> name )){
229+ // Note:
230+ // This parameter was abused by first writing 1024.0 to the floating point
231+ // part and then overwriting the lower part with 0x0000000F. It is now
232+ // exclusively set to the unsigned value.
233+ // Setting the frequency parameter would overwrite the filter setting and
234+ // is now separated out into a separate param storage reference (fanucf).
235+ if (hal_param_new_ui32 (hm2 -> llio -> comp_id , HAL_RW , & (chan -> params -> param .u ),
236+ 0xF , "%s.filter" , chan -> name )) {
225237 HM2_ERR ("error adding param fanuc param 2, aborting\n" );
226238 return - EINVAL ;
227239 }
228- chan -> params -> float_param = 1024.0 ;
229- chan -> params -> u32_param = 0xF ;
230- chan -> params -> timer_num = 0 ;
231-
240+ if (hal_param_new_real (hm2 -> llio -> comp_id , HAL_RW , & (chan -> params -> fanucf ),
241+ 1024.0 , "%s.frequency-khz" , chan -> name )){
242+ HM2_ERR ("error adding frequency param for %s, aborting\n" ,
243+ chan -> name );
244+ return - EINVAL ;
245+ }
232246 return 0 ;
233247}
234248
@@ -355,7 +369,7 @@ int hm2_absenc_parse_format(hm2_sserial_remote_t *chan, hm2_absenc_format_t *de
355369
356370int hm2_absenc_parse_md (hostmot2_t * hm2 , int md_index ) {
357371 hm2_module_descriptor_t * md = & hm2 -> md [md_index ];
358- hm2_absenc_format_t * def = 0 ;
372+ hm2_absenc_format_t * def = NULL ;
359373 struct rtapi_list_head * ptr ;
360374 int index ;
361375
@@ -444,24 +458,15 @@ int hm2_absenc_parse_md(hostmot2_t *hm2, int md_index) {
444458 }
445459
446460 // Set up the common pins
447- if (hal_pin_bit_newf (HAL_OUT , & (chan -> params -> error ),
448- hm2 -> llio -> comp_id ,"%s.data-invalid" ,
449- chan -> name )){
461+ if (hal_pin_new_bool (hm2 -> llio -> comp_id , HAL_OUT , & (chan -> params -> error ),
462+ 0 , "%s.data-invalid" , chan -> name )){
450463 HM2_ERR ("error adding %s over-run pin, aborting\n" ,
451464 chan -> name );
452465 return - EINVAL ;
453466 }
454467 // And Params
455- if (hal_param_float_newf (HAL_RW , & (chan -> params -> float_param ),
456- hm2 -> llio -> comp_id ,"%s.frequency-khz" ,
457- chan -> name )){
458- HM2_ERR ("error adding frequency param for %s, aborting\n" ,
459- chan -> name );
460- return - EINVAL ;
461- }
462- if (hal_param_u32_newf (HAL_RW , & (chan -> params -> timer_num ),
463- hm2 -> llio -> comp_id ,"%s.timer-number" ,
464- chan -> name )){
468+ if (hal_param_new_ui32 (hm2 -> llio -> comp_id , HAL_RW , & (chan -> params -> timer_num ),
469+ 0 , "%s.timer-number" , chan -> name )){
465470 HM2_ERR ("error adding %s timer number param, aborting\n" ,
466471 chan -> name );
467472 return - EINVAL ;
@@ -528,7 +533,7 @@ void hm2_absenc_process_tram_read(hostmot2_t *hm2, long period) {
528533 HM2_ERR ("Data transmission not complete on channel %s read."
529534 " You may need to change the timing of %s. This "
530535 "warning will not repeat\n" , chan -> name ,
531- (chan -> params -> timer_num == 0 ) ?
536+ (hal_get_ui32 ( chan -> params -> timer_num ) == 0 ) ?
532537 "the trigger function" : "the hm2dpll timer" );
533538 err_tag [i ] = 1 ;
534539 }
@@ -540,14 +545,14 @@ void hm2_absenc_process_tram_read(hostmot2_t *hm2, long period) {
540545 if (err_count [i ] < 5001 ) {
541546 ++ err_count [i ];
542547 } else {
543- * chan -> params -> error = 1 ;
548+ hal_set_bool ( chan -> params -> error , 1 ) ;
544549 }
545550
546551 } else {
547552 if (err_count [i ] > 4950 ){
548553 -- err_count [i ];
549554 } else {
550- * chan -> params -> error = 0 ;
555+ hal_set_bool ( chan -> params -> error , 0 ) ;
551556 }
552557 }
553558 }
@@ -562,14 +567,15 @@ void hm2_absenc_write(hostmot2_t *hm2){
562567
563568 for (i = 0 ; i < hm2 -> absenc .num_chans ; i ++ ) {
564569 hm2_sserial_remote_t * chan = & hm2 -> absenc .chans [i ];
570+ rtapi_u32 timer_num = hal_get_ui32 (chan -> params -> timer_num );
565571 switch (chan -> myinst ){
566572 case HM2_GTAG_SSI :
567- if (chan -> params -> timer_num > 4 ) chan -> params -> timer_num = 4 ;
568- buff = ((rtapi_u32 )(0x10000 * (chan -> params -> float_param * 1000
573+ if (timer_num > 4 ) timer_num = hal_set_ui32 ( chan -> params -> timer_num , 4 ) ;
574+ buff = ((rtapi_u32 )(0x10000 * (hal_get_real ( chan -> params -> param . r ) * 1000
569575 / hm2 -> absenc .clock_frequency ))) << 16
570- | chan -> params -> timer_num << 12
571- | (chan -> params -> timer_num == 0 ) << 8
572- | (chan -> params -> timer_num != 0 ) << 9
576+ | timer_num << 12
577+ | (timer_num == 0 ) << 8
578+ | (timer_num != 0 ) << 9
573579 | chan -> num_read_bits ;
574580 if (buff != chan -> data_written [0 ]){
575581 hm2 -> llio -> write (hm2 -> llio ,
@@ -581,8 +587,8 @@ void hm2_absenc_write(hostmot2_t *hm2){
581587 break ;
582588
583589 case HM2_GTAG_BISS :
584- if (chan -> params -> timer_num > 4 ) chan -> params -> timer_num = 4 ;
585- dds = ((rtapi_u32 )(0x10000 * (chan -> params -> float_param * 1000
590+ if (timer_num > 4 ) timer_num = hal_set_ui32 ( chan -> params -> timer_num , 4 ) ;
591+ dds = ((rtapi_u32 )(0x10000 * (hal_get_real ( chan -> params -> param . r ) * 1000
586592 / hm2 -> absenc .clock_frequency )));
587593 filt = 0x8000 /dds ; // RX data filter set to 1/2 a clock period
588594 if (filt > 63 ) { filt = 63 ; } // bound so we dont splatter into adjacent fields
@@ -598,9 +604,9 @@ void hm2_absenc_write(hostmot2_t *hm2){
598604 sizeof (rtapi_u32 ));
599605 chan -> data_written [0 ] = buff ;
600606 }
601- buff2 = chan -> params -> timer_num << 12
602- | (chan -> params -> timer_num == 0 ) << 8
603- | (chan -> params -> timer_num != 0 ) << 9 ;
607+ buff2 = timer_num << 12
608+ | (timer_num == 0 ) << 8
609+ | (timer_num != 0 ) << 9 ;
604610 if (buff2 != chan -> data_written [1 ]){
605611 hm2 -> llio -> write (hm2 -> llio ,
606612 chan -> rw_addr [2 ],
@@ -611,16 +617,27 @@ void hm2_absenc_write(hostmot2_t *hm2){
611617 break ;
612618
613619 case HM2_GTAG_FABS :
614- if (chan -> params -> timer_num > 4 ) chan -> params -> timer_num = 4 ;
615- if (chan -> params -> u32_param > 15 ) chan -> params -> u32_param = 15 ;
616- buff3 = chan -> num_read_bits << 24
620+ // Note:
621+ // The original calculation used an awkward overlapped parameter
622+ // storage between floating point and an unsigned value.
623+ // 'u32_param' would occupy the lower storage part of 'float_param.
624+ // The float would be set to 1024.0 and the lower part would get
625+ // set as an unsigned with 0x0000000F. The setting of the few lower
626+ // mantissa bits has no real bearing on the value as a float.
627+ // The paramater storage has now been split.
628+ // Original:
629+ // buff2 = (u32_param << 28) | (rtapi_u32)(0x100000 * (float_param * 1000 / hm2->absenc.clock_frequency))
630+ // Now
631+ // buff2 = (u32_param << 28) | (rtapi_u32)(0x100000 * (fanucf * 1000 / hm2->absenc.clock_frequency))
632+ if (timer_num > 4 ) timer_num = hal_set_ui32 (chan -> params -> timer_num , 4 );
633+ if (hal_get_ui32 (chan -> params -> param .u ) > 15 ) hal_set_ui32 (chan -> params -> param .u , 15 );
634+ buff3 = (chan -> num_read_bits << 24 )
617635 | (rtapi_u32 )(8.0e-6 * hm2 -> absenc .clock_frequency ) << 14 ;
618- buff2 = chan -> params -> u32_param << 28
619- | ((rtapi_u32 )(0x100000 * (chan -> params -> float_param * 1000
620- / hm2 -> absenc .clock_frequency )));
621- buff = chan -> params -> timer_num << 12
622- | (chan -> params -> timer_num == 0 ) << 8
623- | (chan -> params -> timer_num != 0 ) << 9
636+ buff2 = (hal_get_ui32 (chan -> params -> param .u ) << 28 )
637+ | ((rtapi_u32 )(0x100000 * (hal_get_real (chan -> params -> fanucf ) * 1000.0 / hm2 -> absenc .clock_frequency )));
638+ buff = (timer_num << 12 )
639+ | (timer_num == 0 ) << 8
640+ | (timer_num != 0 ) << 9
624641 | (buff3 != chan -> data_written [2 ] || buff2 != chan -> data_written [1 ]) << 7 ;
625642 if (buff != chan -> data_written [0 ]){
626643 // if necessary this will set the write flag, then next time through
0 commit comments