simhm2_pci

Обсуждение установки, настройки и использования LinuxCNC. Вопросы по Gкоду.
nkp
Мастер
Сообщения: 8340
Зарегистрирован: 28 ноя 2011, 00:25
Репутация: 1589
Контактная информация:

simhm2_pci

Сообщение nkp »

понадобилось править ладдер конфига станка СФП-500 "без станка",то есть без плат меса
чтоб запускать - набросал такой компонент
в hal правим строку загрузки

Код: Выделить всё

loadrt shm2_pci #config="num_encoders=0 num_pwmgens=4 num_resolvers=5 sserial_port_0=20000000"
как видно - нужно дописать еще парсинг config=

Код: Выделить всё

/********************************************************************
* Description: shm2_pci.c
*   Mesa board simulation.
*
*********************************************************************
*
* Author: Konstantin Navrockiy  (nkp216 AT gmail DOT com)
*       Based on a work by John Kasunich (jmkasunich AT att DOT net)
* License: GPL Version 2
* Created on: 2021/9/30
* System: Linux
*
* Copyright (c) 2021 All rights reserved.
*
********************************************************************/

#include "rtapi.h"		/* RTAPI realtime OS API */
#include "rtapi_app.h"		/* RTAPI realtime module decls */
#include "hal.h"		/* HAL public API decls */

#include "rtapi_math.h"

/* module information */
MODULE_AUTHOR("Konstantin Navrockiy");
MODULE_DESCRIPTION("Mesa board simulation");
MODULE_LICENSE("GPL");


typedef struct {
    hal_float_t  **resolver_angle;
    hal_float_t  **resolver_position;
    hal_float_t  **resolver_scale;
    hal_float_t  **resolver_velocity;
    hal_bit_t    **resolver_enable;
    hal_float_t   *resolver_khz;
    hal_s32_t    **pwmgen_type;
    hal_float_t  **pwmgen_scale;
    hal_float_t  **pwmgen_value;
    	
    hal_bit_t **pwmgen_enable;
    hal_bit_t **gpio_in_not;
    hal_bit_t **gpio_in;
    hal_bit_t **gpio_is_output; 
    hal_bit_t **gpio_invert_output;  
    hal_bit_t **gpio_out;    
    
        
} Pins_init;

static int comp_id;		/* component ID */

static int Hal_Export(Pins_init *this);
static void read(void *arg, long period);
static void write(void *arg, long period);

int rtapi_app_main(void){
 
   Pins_init     *pComp;

    comp_id = hal_init("shm2_pci");
    
    if (comp_id < 0) {
	rtapi_print_msg(RTAPI_MSG_ERR, "shm2_pci: ERROR: hal_init() failed\n");
	return -1;
    }


    pComp = hal_malloc(sizeof(Pins_init));
    
    if (pComp == NULL) {
        rtapi_print_msg(RTAPI_MSG_ERR, "shm2_pci: ERROR: hal_malloc() failed\n");
        hal_exit(comp_id);
        return(-1);
    }
    
    // Export pins, parameters, and functions.
    if(Hal_Export(pComp)){
        hal_exit(comp_id);
        return(-1);    
    }
    
	rtapi_print_msg(RTAPI_MSG_INFO,
	    "shm2_pci: installed  shm2_pcis\n");

    hal_ready(comp_id);
    return 0;
}

void rtapi_app_exit(void)
{
    hal_exit(comp_id);
}

/***********************************************************************
*                     REALTIME BLOCK FUNCTIONS                         *
************************************************************************/
static int Hal_Export(Pins_init *this){
    int  retval;
    char buf[HAL_NAME_LEN + 1];
    //int  error; 
    int  j;  
    
                 
    /* export function */
    rtapi_snprintf(buf, sizeof(buf), "hm2_5i24.0.read");
    retval = hal_export_funct(buf, read, this, 0, 0, comp_id);
    if (retval != 0) {
	rtapi_print_msg(RTAPI_MSG_ERR,
	    "shm2_pci: ERROR: funct export failed\n");
	return -1;
    }  


    /* export function */
    rtapi_snprintf(buf, sizeof(buf), "hm2_5i24.0.write");
    retval = hal_export_funct(buf, write, this, 0, 0, comp_id);
    if (retval != 0) {
	rtapi_print_msg(RTAPI_MSG_ERR,
	    "shm2_pci: ERROR: funct export failed\n");
	return -1;
    } 


       
    // hal_malloc  gpio_in_not
    this->gpio_in_not = hal_malloc(72 * sizeof(hal_bit_t*));  			     
    for (j = 0; j < 72; j++){
        if (hal_pin_bit_newf(HAL_OUT, &(this->gpio_in_not[j]), comp_id,
                "hm2_5i24.0.gpio.%03i.in_not",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.gpio.%03i.in_not\n",j);
            return -ENOMEM;}
    }
    			            
    // hal_malloc  gpio_in
    this->gpio_in = hal_malloc(72 * sizeof(hal_bit_t*));       
    for (j = 0; j < 72; j++){
        if (hal_pin_bit_newf(HAL_OUT, &(this->gpio_in[j]), comp_id,
                "hm2_5i24.0.gpio.%03i.in",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.gpio.%03i.in\n",j);
            return -ENOMEM;}
    } 
 
 
//OUT
//hm2_5i24.0.gpio.068.is_output 
//hm2_5i24.0.gpio.068.invert_output  
//hm2_5i24.0.gpio.068.out 
       
    // hal_malloc  gpio_out
    this->gpio_out = hal_malloc(72 * sizeof(hal_bit_t*));  			     
    for (j = 0; j < 72; j++){
        if (hal_pin_bit_newf(HAL_IN, &(this->gpio_out[j]), comp_id,
                "hm2_5i24.0.gpio.%03i.out",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.gpio.%03i.out\n",j);
            return -ENOMEM;}
    }
    			            
    // hal_malloc  gpio_is_output 
    this->gpio_is_output = hal_malloc(72 * sizeof(hal_bit_t*));       
    for (j = 0; j < 72; j++){
        if (hal_pin_bit_newf(HAL_IN, &(this->gpio_is_output[j]), comp_id,
                "hm2_5i24.0.gpio.%03i.is_output",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.gpio.%03i.is_output\n",j);
            return -ENOMEM;}
    }  
 
    // hal_malloc  gpio_invert_output 
    this->gpio_invert_output = hal_malloc(72 * sizeof(hal_bit_t*));       
    for (j = 0; j < 72; j++){
        if (hal_pin_bit_newf(HAL_IN, &(this->gpio_invert_output[j]), comp_id,
                "hm2_5i24.0.gpio.%03i.invert_output",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.gpio.%03i.invert_output\n",j);
            return -ENOMEM;}
    }  
 
 
//PWMGEN
//hm2_5i24.0.pwmgen.00.enable           pin   in bit 
//hm2_5i24.0.pwmgen.00.value            pin   in float
//hm2_5i24.0.pwmgen.00.scale            param rw float 
//hm2_5i24.0.pwmgen.00.output-type      param rw s32
  
    // hal_malloc  pwmgen_enable 
    this->pwmgen_enable = hal_malloc(5 * sizeof(hal_bit_t*)); 
          
    for (j = 0; j < 5; j++){
        if (hal_pin_bit_newf(HAL_IN, &(this->pwmgen_enable[j]), comp_id,
                "hm2_5i24.0.pwmgen.%02i.enable",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.pwmgen.%02i.enable\n",j);
            return -ENOMEM;}
    } 

    // hal_malloc  pwmgen_value 
    this->pwmgen_value = hal_malloc(5 * sizeof(hal_float_t*));       
    for (j = 0; j < 5; j++){
        if (hal_pin_float_newf(HAL_IN, &(this->pwmgen_value[j]), comp_id,
                "hm2_5i24.0.pwmgen.%02i.value",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.pwmgen.%02i.value\n",j);
            return -ENOMEM;}
    } 

    // hal_malloc  pwmgen_scale 
    this->pwmgen_scale = hal_malloc(5 * sizeof(hal_float_t*));       
    for (j = 0; j < 5; j++){
        if (hal_pin_float_newf(HAL_IN, &(this->pwmgen_scale[j]), comp_id,
                "hm2_5i24.0.pwmgen.%02i.scale",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.pwmgen.%02i.scale\n",j);
            return -ENOMEM;}
    } 

    // hal_malloc  pwmgen_output-type
    this->pwmgen_type = hal_malloc(5 * sizeof(hal_s32_t*));       
    for (j = 0; j < 5; j++){
        if ( hal_pin_s32_newf(HAL_IN, &(this->pwmgen_type[j]), comp_id,
                "hm2_5i24.0.pwmgen.%02i.output-type", j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.pwmgen.%02i.output-type\n",j);
            return -ENOMEM;}
    } 


//resolver
//hm2_5i24.0.resolver.excitation-khz 
//hm2_5i24.0.resolver.00.position
//hm2_5i24.0.resolver.00.scale
//hm2_5i24.0.resolver.00.velocity
//hm2_5i24.0.resolver.00.index-enable 
//hm2_5i24.0.resolver.04.angle


    // hal_malloc  resolver_khz 
    //this->resolver_khz = hal_malloc(1 * sizeof(hal_float_t*)); 
     
        if (hal_pin_float_newf(HAL_IN, &this->resolver_khz, comp_id,
                "hm2_5i24.0.resolver.excitation-khz") < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.resolver.excitation-khz\n");
            return -ENOMEM;}



 
    // hal_malloc  resolver_position
    this->resolver_position = hal_malloc(5 * sizeof(hal_float_t*)); 
          
    for (j = 0; j < 5; j++){
        if (hal_pin_float_newf(HAL_OUT, &(this->resolver_position[j]), comp_id,
                "hm2_5i24.0.resolver.%02i.position",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.resolver.%02i.position\n",j);
            return -ENOMEM;}
    } 

    // hal_malloc  resolver_scale 
    this->resolver_scale = hal_malloc(5 * sizeof(hal_float_t*));       
    for (j = 0; j < 5; j++){
        if (hal_pin_float_newf(HAL_IN, &(this->resolver_scale[j]), comp_id,
                "hm2_5i24.0.resolver.%02i.scale",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.resolver.%02i.scale\n",j);
            return -ENOMEM;}
    } 

    // hal_malloc  resolver_velocity 
    this->resolver_velocity = hal_malloc(5 * sizeof(hal_float_t*));       
    for (j = 0; j < 5; j++){
        if (hal_pin_float_newf(HAL_OUT, &(this->resolver_velocity[j]), comp_id,
                "hm2_5i24.0.resolver.%02i.velocity",  j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.resolver.%02i.velocity\n",j);
            return -ENOMEM;}
    } 

    // hal_malloc  resolver_enable
    this->resolver_enable = hal_malloc(5 * sizeof(hal_bit_t*));       
    for (j = 0; j < 5; j++){
        if ( hal_pin_bit_newf(HAL_IN, &(this->resolver_enable[j]), comp_id,
                "hm2_5i24.0.resolver.%02i.index-enable", j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.resolver.%02i.index-enable\n",j);
            return -ENOMEM;}
    }  

    // hal_malloc  resolver_angle
    this->resolver_angle = hal_malloc(5 * sizeof(hal_float_t*));       
    for (j = 0; j < 5; j++){
        if (hal_pin_float_newf(HAL_OUT, &(this->resolver_angle[j]), comp_id,
                "hm2_5i24.0.resolver.%02i.angle", j) < 0) {
            rtapi_print_msg(RTAPI_MSG_ERR, "hm2_5i24.0.resolver.%02i.angle\n",j);
            return -ENOMEM;}
    } 
      
  return 0;   
}
    
static void read(void *arg, long period){
int  n;

n=12;
}    
    
static void write(void *arg, long period){
int  n;

n=22;
}     
    

    
по этой рыбе можно накатать "общий вариант",но это наверно излишне,оптимальней под самые ходовые наборы плат...

Вернуться в «LinuxCNC»