示例#1
0
文件: ipmb.c 项目: ryanSie/Advantech
/* FUNCTION *******************************************************************
* Get the MCH/MCMC backplane IPMB address as 8 bit I2C address
*
*******************************************************************************/
unsigned char ipmb_get_addr(void)
{
    unsigned char ftest, stest;
    unsigned char addr = 0;

    /* Set Pin to 0 and save the Pin-State of the Address Pins */
    set_gpio(IPMB_ADR_GA_SEL_PORT, IPMB_ADR_GA_SEL_PIN);

    ftest = (((chk_gpio(IPMB_ADR_GA2_PORT, IPMB_ADR_GA2_PIN)<<2) |
              (chk_gpio(IPMB_ADR_GA1_PORT, IPMB_ADR_GA1_PIN)<<1) |
              (chk_gpio(IPMB_ADR_GA0_PORT, IPMB_ADR_GA0_PIN)<<0)) & 0x7);

    /* Set Pin to 1 and save the Pin-State of the Address Pins again */
    clr_gpio(IPMB_ADR_GA_SEL_PORT, IPMB_ADR_GA_SEL_PIN);

    stest = (((chk_gpio(IPMB_ADR_GA2_PORT, IPMB_ADR_GA2_PIN)<<2) |
              (chk_gpio(IPMB_ADR_GA1_PORT, IPMB_ADR_GA1_PIN)<<1) |
              (chk_gpio(IPMB_ADR_GA0_PORT, IPMB_ADR_GA0_PIN)<<0)) & 0x7);

    /* Check which Pins are unconnected and have changed the state while testing */
    if((ftest == 0x0) && (stest == 0x7))
    {
        addr = (unsigned char)(IPMB_ADDR_OFFSET);    /* MCH1 10h */
    }
    else if((ftest == 0x7) && (stest == 0x7))
    {
        addr = (unsigned char)(IPMB_ADDR_OFFSET + 0x02);    /* MCH2 12h */
    }
    else
    {
        /* If nothing matches take undefined IPMB address */
        addr = (unsigned char)(0x00);

    }

    set_gpio(IPMB_ADR_GA_SEL_PORT, IPMB_ADR_GA_SEL_PIN);

    return (addr & 0xFE);

}
示例#2
0
static const char *special_commands(void *userdata, char letter, float value,
				    const char *remaining) {
  GCodeMachineControl_t *state = (GCodeMachineControl_t*)userdata;
  const int code = (int)value;

  if (letter == 'M') {
    int pin = -1;
    int aux_bit = -1;

    switch (code) {
    case 0: set_gpio(ESTOP_SW_GPIO); break;
    case 3:
    case 4:
      for (;;) {
        const char* after_pair = gcodep_parse_pair(remaining, &letter, &value,
                                                   state->msg_stream);
        if (after_pair == NULL) break;
        else if (letter == 'S') state->spindle_rpm = round2int(value);
        else break;
        remaining = after_pair;
      }
      if (state->spindle_rpm) {
        state->aux_bits |= AUX_BIT_SPINDLE_ON;
	if (code == 3) state->aux_bits &= ~AUX_BIT_SPINDLE_DIR;
        else state->aux_bits |= AUX_BIT_SPINDLE_DIR;
      }
      break;
    case 5: state->aux_bits &= ~(AUX_BIT_SPINDLE_ON | AUX_BIT_SPINDLE_DIR); break;
    case 7: state->aux_bits |= AUX_BIT_MIST; break;
    case 8: state->aux_bits |= AUX_BIT_FLOOD; break;
    case 9: state->aux_bits &= ~(AUX_BIT_MIST | AUX_BIT_FLOOD); break;
    case 10: state->aux_bits |= AUX_BIT_VACUUM; break;
    case 11: state->aux_bits &= ~AUX_BIT_VACUUM; break;
    case 42:
    case 62:
    case 63:
    case 64:
    case 65:
      for (;;) {
        const char* after_pair = gcodep_parse_pair(remaining, &letter, &value,
                                                   state->msg_stream);
        if (after_pair == NULL) break;
        if (letter == 'P') pin = round2int(value);
        else if (letter == 'S' && code == 42) aux_bit = round2int(value);
        else break;
        remaining = after_pair;
      }
      if (code == 62 || code == 64)
        aux_bit = 1;
      else if (code == 63 || code == 65)
        aux_bit = 0;
      if (pin >= 0 && pin <= MAX_AUX_PIN) {
        if (aux_bit >= 0 && aux_bit <= 1) {
          if (aux_bit) state->aux_bits |= 1 << pin;
          else state->aux_bits &= ~(1 << pin);
        } else if (code == 42 && state->msg_stream) {  // Just read operation.
          mprintf(state, "%d\n", (state->aux_bits >> pin) & 1);
	}
      }
      break;
    case 80: set_gpio(MACHINE_PWR_GPIO); break;
    case 81: clr_gpio(MACHINE_PWR_GPIO); break;
    case 105: mprintf(state, "T-300\n"); break;  // no temp yet.
    case 114:
      if (buffer_available(&state->buffer)) {
        struct AxisTarget *current = buffer_at(&state->buffer, 0);
        const int *mpos = current->position_steps;
        const float x = 1.0f * mpos[AXIS_X] / state->cfg.steps_per_mm[AXIS_X];
        const float y = 1.0f * mpos[AXIS_Y] / state->cfg.steps_per_mm[AXIS_Y];
        const float z = 1.0f * mpos[AXIS_Z] / state->cfg.steps_per_mm[AXIS_Z];
        const float e = 1.0f * mpos[AXIS_E] / state->cfg.steps_per_mm[AXIS_E];
        const float *origin = state->coordinate_display_origin;
        mprintf(state, "X:%.3f Y:%.3f Z:%.3f E:%.3f",
                x - origin[AXIS_X], y - origin[AXIS_Y], z - origin[AXIS_Z],
                e - origin[AXIS_E]);
        mprintf(state, " [ABS. MACHINE CUBE X:%.3f Y:%.3f Z:%.3f]", x, y, z);
        switch (state->homing_state) {
        case HOMING_STATE_NEVER_HOMED:
          mprintf(state, " (Unsure: machine never homed!)\n");
          break;
        case HOMING_STATE_HOMED_BUT_MOTORS_UNPOWERED:
          mprintf(state, " (Lower confidence: motor power off at "
                  "least once after homing)\n");
          break;
        case HOMING_STATE_HOMED:
          mprintf(state, " (confident: machine was homed)\n");
          break;
        }
      } else {
        mprintf(state, "// no current pos\n");
      }
      break;
    case 115: mprintf(state, "%s\n", VERSION_STRING); break;
    case 117:
      mprintf(state, "// Msg: %s\n", remaining); // TODO: different output ?
      remaining = NULL;  // consume the full line.
      break;
    case 119: {
      char any_enstops_found = 0;
      for (int axis = 0; axis < GCODE_NUM_AXES; ++axis) {
        struct EndstopConfig config = state->min_endstop[axis];
        if (config.endstop_number) {
          int value = get_gpio(get_endstop_gpio_descriptor(config));
          mprintf(state, "%c_min:%s ",
                  tolower(gcodep_axis2letter(axis)),
                  value == config.trigger_value ? "TRIGGERED" : "open");
          any_enstops_found = 1;
        }
        config = state->max_endstop[axis];
        if (config.endstop_number) {
          int value = get_gpio(get_endstop_gpio_descriptor(config));
          mprintf(state, "%c_max:%s ",
                  tolower(gcodep_axis2letter(axis)),
                  value == config.trigger_value ? "TRIGGERED" : "open");
          any_enstops_found = 1;
        }
      }
      if (any_enstops_found) {
        mprintf(state, "\n");
      } else {
        mprintf(state, "// This machine has no endstops configured.\n");
      }
    }
      break;
    case 999: clr_gpio(ESTOP_SW_GPIO); break;
    default:
      mprintf(state, "// BeagleG: didn't understand ('%c', %d, '%s')\n",
              letter, code, remaining);
      remaining = NULL;  // In this case, let's just discard remainig block.
      break;
    }