53 #define PRINTF(...) printf(__VA_ARGS__) 58 #define PM_ENABLE_LINE_SET GPIO_SET_PIN(PM_ENABLE_PORT_BASE, \ 60 #define PM_ENABLE_LINE_CLR GPIO_CLR_PIN(PM_ENABLE_PORT_BASE, \ 62 #define PM_ENABLE_AS_OUTPUT GPIO_SET_OUTPUT(PM_ENABLE_PORT_BASE, \ 64 #define PM_ENABLE_LINE_CMD PM_ENABLE_LINE_SET; \ 65 clock_delay_usec(100); 68 #define PM_NUMBITS(X) (1 << ((X)-1)) 70 static uint8_t initialized = 0;
71 static uint8_t lbuf[5];
80 i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN,
81 I2C_SCL_NORMAL_BUS_SPEED);
87 pm_write_byte(uint8_t reg, uint8_t val)
105 pm_read_byte(uint8_t reg, uint8_t *val, uint8_t len)
108 if((reg < PM_VBAT) || (reg >= PM_MAX_COMMANDS) || (!len)) {
109 PRINTF(
"PM: invalid settings/not initialized\n");
117 printf(
"PM: Data 0x%02X\n", *val);
122 PRINTF(
"PM: Error reading the registers\n");
135 lbuf[0] = PM_CMD_RST_HARD;
155 if(time > PM_SOFT_SHTDN_28_DAYS) {
156 PRINTF(
"PM: maximum timeout is %u\n", (uint32_t)PM_SOFT_SHTDN_28_DAYS);
160 lbuf[0] = PM_SOFT_TIME;
161 lbuf[1] = (uint8_t)(time >> 24);
162 lbuf[2] = (uint8_t)(time >> 16) & 0xFF;
163 lbuf[3] = (uint8_t)(time >> 8) & 0xFF;
164 lbuf[4] = (uint8_t)(time & 0xFF);
165 PRINTF(
"PM: Timeout 0x%02x%02x%02x%02x\n", lbuf[1], lbuf[2], lbuf[3], lbuf[4]);
174 PRINTF(
"PM: error setting the timeout\n");
187 retval |= ((uint32_t)lbuf[0] << 24);
188 retval |= ((uint32_t)lbuf[1] << 16);
189 retval |= ((uint32_t)lbuf[2] << 8);
195 PRINTF(
"PM: Timeout 0x%02x%02x%02x%02x\n", lbuf[0], lbuf[1], lbuf[2], lbuf[3]);
197 retval *= PM_SOFT_SHTDN_INTERVAL;
210 retval |= ((uint32_t)lbuf[0] << 24);
211 retval |= ((uint32_t)lbuf[1] << 16);
212 retval |= ((uint32_t)lbuf[2] << 8);
217 PRINTF(
"PM: Sleep cycles: 0x%02x%02x%02x%02x\n", lbuf[0], lbuf[1], lbuf[2],
226 PRINTF(
"PM: Not initialized\n");
230 if((type != PM_HARD_SLEEP_CONFIG) && (type != PM_SOFT_SLEEP_CONFIG)) {
231 PRINTF(
"PM: Invalid shutdown mode type\n");
237 if(type == PM_HARD_SLEEP_CONFIG) {
238 pm_write_byte(PM_HARD_SLEEP_CONFIG, PM_ENABLE);
244 pm_write_byte(PM_SOFT_SLEEP_CONFIG, PM_ENABLE);
260 *state = (uint16_t)lbuf[0] << 8;
266 PRINTF(
"PM: Voltage %u [%u][%u]\n", *state, lbuf[0], lbuf[1]);
278 if((!initialized) || (fwver == NULL)) {
282 if(pm_read_byte(PM_FW_VERSION, fwver, 1) == PM_SUCCESS) {
uint8_t i2c_burst_send(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to send multiple bytes to a slave.
Header file with register and macro declarations for the cc2538 GPIO module.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
int8_t pm_enable(void)
Initializes the Power Management driver.
int8_t pm_reset_system(void)
Restarts the on-board low-power PIC, provoking a board reset.
#define PWR_MNGMT_ADDR
Power Management slave address.
uint32_t pm_get_num_cycles(void)
Gets current cycles.
int8_t pm_get_fw_ver(uint8_t *fwver)
Gets the current firmware version of power management module.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
Header file for the real-time timer module.
Header file for the RE-Mote Power Management driver.
int8_t pm_get_voltage(uint16_t *state)
Reads the voltage of the external battery if connected to VIN pin.
uint8_t i2c_burst_receive(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to receive multiple bytes from a slave.
int8_t pm_shutdown_now(uint8_t type)
Disconnects the board battery and enter shutdown mode PM_SOFT/HARD_SLEEP_CONFIG.
uint32_t pm_get_timeout(void)
Gets the current timeout value configured in power management module.
uint8_t i2c_single_send(uint8_t slave_addr, uint8_t data)
Perform all operations to send a byte to a slave.
int8_t pm_set_timeout(uint32_t time)
Configure Internal Timeout for Hard and Soft shutdown modes.