etherlab/EthercatCFileGenerator.py
changeset 2407 5f2b1bb464a0
parent 2405 af050469fc5c
child 2425 68e7da937162
equal deleted inserted replaced
2406:ffd091b51cd0 2407:5f2b1bb464a0
    86                 ["IEC_%(var_type)s %(real_var)s;" % entry_infos,
    86                 ["IEC_%(var_type)s %(real_var)s;" % entry_infos,
    87                  "IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos])
    87                  "IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos])
    88         for declaration in entry_infos.get("extra_declarations", []):
    88         for declaration in entry_infos.get("extra_declarations", []):
    89             entry_infos["extra_decl"] = declaration
    89             entry_infos["extra_decl"] = declaration
    90             str_completion["located_variables_declaration"].append(
    90             str_completion["located_variables_declaration"].append(
    91                  "IEC_%(var_type)s *%(extra_decl)s = &%(real_var)s;" % entry_infos)
    91                 "IEC_%(var_type)s *%(extra_decl)s = &%(real_var)s;" % entry_infos)
    92     elif "real_var" not in entry_infos:
    92     elif "real_var" not in entry_infos:
    93         entry_infos["real_var"] = "beremiz" + entry_infos["var_name"]
    93         entry_infos["real_var"] = "beremiz" + entry_infos["var_name"]
    94 
    94 
    95     str_completion["used_pdo_entry_offset_variables_declaration"].append(
    95     str_completion["used_pdo_entry_offset_variables_declaration"].append(
    96         "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos)
    96         "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos)
    98     if entry_infos["data_type"] == "BIT":
    98     if entry_infos["data_type"] == "BIT":
    99         str_completion["used_pdo_entry_offset_variables_declaration"].append(
    99         str_completion["used_pdo_entry_offset_variables_declaration"].append(
   100             "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x_bit;" % entry_infos)
   100             "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x_bit;" % entry_infos)
   101 
   101 
   102         str_completion["used_pdo_entry_configuration"].append(
   102         str_completion["used_pdo_entry_configuration"].append(
   103              ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, " +
   103             ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, " +
   104               "0x%(index).4x, %(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x, " +
   104              "0x%(index).4x, %(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x, " +
   105               "&slave%(slave)d_%(index).4x_%(subindex).2x_bit},") % entry_infos)
   105              "&slave%(slave)d_%(index).4x_%(subindex).2x_bit},") % entry_infos)
   106 
   106 
   107         if entry_infos["dir"] == "I":
   107         if entry_infos["dir"] == "I":
   108             str_completion["retrieve_variables"].append(
   108             str_completion["retrieve_variables"].append(
   109               ("    %(real_var)s = EC_READ_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " +
   109                 ("    %(real_var)s = EC_READ_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " +
   110                "slave%(slave)d_%(index).4x_%(subindex).2x_bit);") % entry_infos)
   110                  "slave%(slave)d_%(index).4x_%(subindex).2x_bit);") % entry_infos)
   111         elif entry_infos["dir"] == "Q":
   111         elif entry_infos["dir"] == "Q":
   112             str_completion["publish_variables"].append(
   112             str_completion["publish_variables"].append(
   113               ("    EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " +
   113                 ("    EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " +
   114                "slave%(slave)d_%(index).4x_%(subindex).2x_bit, %(real_var)s);") % entry_infos)
   114                  "slave%(slave)d_%(index).4x_%(subindex).2x_bit, %(real_var)s);") % entry_infos)
   115 
   115 
   116     else:
   116     else:
   117         str_completion["used_pdo_entry_configuration"].append(
   117         str_completion["used_pdo_entry_configuration"].append(
   118             ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " +
   118             ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " +
   119              "%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos)
   119              "%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos)
   530                                 break
   530                                 break
   531 
   531 
   532                             pdo["entries"].append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
   532                             pdo["entries"].append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
   533                             if entry_infos["bitlen"] < module_extra_params["pdo_alignment"]:
   533                             if entry_infos["bitlen"] < module_extra_params["pdo_alignment"]:
   534                                 pdo["entries"].append("    {0x0000, 0x00, %d}, /* None */" % (
   534                                 pdo["entries"].append("    {0x0000, 0x00, %d}, /* None */" % (
   535                                         module_extra_params["pdo_alignment"] - entry_infos["bitlen"]))
   535                                     module_extra_params["pdo_alignment"] - entry_infos["bitlen"]))
   536                             pdo["entries_number"] += 1
   536                             pdo["entries_number"] += 1
   537 
   537 
   538                             if pdo["entries_number"] == module_extra_params["max_pdo_size"]:
   538                             if pdo["entries_number"] == module_extra_params["max_pdo_size"]:
   539                                 dynamic_pdos[pdo_type]["pdos"].pop(0)
   539                                 dynamic_pdos[pdo_type]["pdos"].pop(0)
   540 
   540