void XPm_ClientAbortSuspend(void) { /* Enable interrupts at processor level */ pm_enable_int(); /* Clear powerdown request */ pm_write(MASTER_PWRCTL, pm_read(MASTER_PWRCTL) & ~primary_master->pwrdn_mask); }
/** Measure the voltage on a probes channel \param pm a pointer to a pm_context \param power a pointer to a float to store the result \retval 0 - all fine \retval -1 - invalid pm_context \retval -2 - invalid channel selected \retval -3 - sending command failed \retval -3 - reading device failed \retval -4 - internal conversion error */ PM600X_EXPORT int pm_measure_voltage_channel(struct pm_context *pm, float *voltage, int channel) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); if (channel < 1 || channel > 2) pm_error_return(-2, "invalid channel selected"); // send command char cmd[30]; int count = sprintf(cmd, "VOLTCH%i?\r\n", channel); if (!count) pm_error_return(-4, "internal conversion error"); int ret = pm_write(pm, cmd, count); if (ret < 0) pm_error_return(-3, "sending command failed"); // read answer char buf[20]; ret = pm_read_line(pm, buf, 20); if (ret < 0) pm_error_return(-4, "reading device failed"); *voltage = atof(buf); pm_error_return(0, "all fine"); }
void XPm_ClientSuspend(const struct XPm_Master *const master) { /* Disable interrupts at processor level */ pm_disable_int(); /* Set powerdown request */ pm_write(MASTER_PWRCTL, pm_read(MASTER_PWRCTL) | master->pwrdn_mask); }
/** Measure the raw data on a probes channel \param pm a pointer to a pm_context \param power a pointer to a float to store the result \retval 0 - all fine \retval -1 - invalid pm_context \retval -2 - invalid channel selected \retval -3 - sending command failed \retval -3 - reading device failed \retval -4 - internal conversion error */ PM600X_EXPORT int pm_measure_raw_channel(struct pm_context *pm, unsigned long *raw_value, int channel) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); if (channel < 1 || channel > 2) pm_error_return(-2, "invalid channel selected"); // send command char cmd[30]; int count = sprintf(cmd, "RAWCH%i?\r\n", channel); if (!count) pm_error_return(-4, "internal conversion error"); int ret = pm_write(pm, cmd, count); if (ret < 0) pm_error_return(-3, "sending command failed"); // read answer char buf[20]; ret = pm_read_line(pm, buf, 20); if (ret < 0) pm_error_return(-4, "reading device failed"); *raw_value = atol(buf) & 0xfff; // only the lower 12 bits are relevant pm_error_return(0, "all fine"); }
/** Measure the power on a probe \param pm a pointer to a pm_context \param power a pointer to a float to store the result \retval 0 - all fine \retval -1 - invalid pm_context \retval -2 - sending command failed \retval -3 - reading device failed \retval -4 - internal conversion error */ PM600X_EXPORT int pm_measure(struct pm_context *pm, float *power) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); // send command char cmd[30]; int count = 0; // for PM6006 we only accept int frequencies in MHz if (pm->type == TYPE_PM_6006) count = sprintf(cmd, "POW? %lu\r\n", (unsigned long)(pm->frequency / 1000000)); // for PM6003 float values in MHz are allowed else if (pm->type == TYPE_PM_6003) count = sprintf(cmd, "POW? %f\r\n", (float)pm->frequency / 1000000.0f); if (!count) pm_error_return(-4, "internal conversion error"); int ret = pm_write(pm, cmd, count); if (ret < 0) pm_error_return(-2, "sending command failed"); // read answer char buf[20]; ret = pm_read_line(pm, buf, 20); if (ret < 0) pm_error_return(-4, "reading device failed"); *power = atof(buf); pm_error_return(0, "all fine"); }
void XPm_ClientWakeup(const struct XPm_Master *const master) { u32 cpuid = pm_get_cpuid(master->node_id); if (UNDEFINED_CPUID != cpuid) { u32 val = pm_read(MASTER_PWRCTL); val &= ~(master->pwrdn_mask); pm_write(MASTER_PWRCTL, val); } }
/** Reset a power meter probes settings \param pm a pointer to a pm_context \retval 0 - all fine \retval -1 - invalid pm_context \retval -2 - resetting device failed */ PM600X_EXPORT int pm_reset(struct pm_context *pm) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); // reset the device via *RST int ret = pm_write(pm, "\r\n*RST\r\n", strlen("\r\n*RST\r\n")); if (ret < 0) pm_error_return(-2, "resetting device failed"); pm_error_return(0, "all fine"); }
/** Blink the probes green LED for about 6 seconds. This helps to identify a specific probe if several of them are used. You can easily identify them in your measurement setup by blinking the LED. \param pm a pointer to a pm_context \retval 0 - all fine \retval -1 - invalid pm_context */ PM600X_EXPORT int pm_blink(struct pm_context *pm) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); // send blink command char *cmd = "BLINK\r\n"; int ret = pm_write(pm, cmd, strlen(cmd)); if (ret < 0) pm_error_return(-2, "sending command failed"); pm_error_return(0, "all fine"); }
/** Returns identification string of a probe \param pm a pointer to a pm_context \param buf a paointer to a buffer where to store the id string \retval 0 - all fine \retval -1 - invalid pm_context \retval -2 - sending command failed \retval -3 - reading device failed */ PM600X_EXPORT int pm_identify(struct pm_context *pm, char *buf) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); // send command int ret = pm_write(pm, "\r\n*IDN?\r\n", strlen("\r\n*IDN?\r\n")); if (ret < 0) pm_error_return(-2, "sending command failed"); // read answer ret = pm_read_line(pm, buf, 40); if (ret <= 0) pm_error_return(-3, "reading device failed"); pm_error_return(0, "all fine"); }
/** Measure the power supply voltage of the probe \param pm a pointer to a pm_context \param power a pointer to a float to store the result \retval 0 - all fine \retval -1 - invalid pm_context \retval -2 - sending command failed \retval -3 - reading device failed */ PM600X_EXPORT int pm_measure_vsupply(struct pm_context *pm, float *value) { if (!pm->handle) pm_error_return(-1, "invalid pm_context"); // send command char *cmd = "TEMP?\r\n"; int ret = pm_write(pm, cmd, strlen(cmd)); if (ret < 0) pm_error_return(-2, "sending command failed"); // read answer char buf[20]; ret = pm_read_line(pm, buf, 20); if (ret < 0) pm_error_return(-3, "reading device failed"); *value = atof(buf); pm_error_return(0, "all fine"); }
/** Set measurement average count Set the count of measurements the device averages before returning a result \param pm a pointer to a pm_context \param avg the averaging count in the range 1-10000 \retval 0 - all fine \retval -1 - average out of range \retval -2 - invalid pm_context \retval -3 - setting average failed \retval -4 - internal conversion error */ PM600X_EXPORT int pm_set_averages(struct pm_context *pm, unsigned short avg) { if (avg < 1) pm_error_return(-1, "average out of range"); if (!pm->handle) pm_error_return(-2, "invalid pm_context"); char cmd[20]; int count = sprintf(cmd, "AVG %i\r\n", avg); if (!count) pm_error_return(-4, "internal conversion error"); int ret = pm_write(pm, cmd, count); if (ret < 0) pm_error_return(-3, "setting average failed"); pm->averages = avg; pm_error_return(0, "all fine"); }