Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
PTU power sharing API

Functions

uint32_t ptu_power_sharing_init (ptu_sm_handler_t sm_handler)
 Initialize power sharing module. More...
 
void ptu_power_sharing_on_wpt_service_evt (ble_wpts_c_t *p_wpts_c, ble_wpts_c_evt_t *const p_wpts_c_evt)
 Handle service events. More...
 
void ptu_power_sharing_temperature_warning_set (bool warning)
 Inform power control module that PTU is having a high temperature warning. When this occurs the power control module will instruct PRUs to lower their power consumption. More...
 

Detailed Description

Function Documentation

uint32_t ptu_power_sharing_init ( ptu_sm_handler_t  sm_handler)

Initialize power sharing module.

Parameters
[in]sm_handlerState machine handler
Returns
NRF_ERROR_INVALID_PARAM if sm_handler is NULL, otherwise NRF_SUCCESS.

Definition at line 650 of file ptu_power_sharing.c.

651 {
652  if(sm_handler == NULL)
653  return NRF_ERROR_INVALID_PARAM;
654 
655  m_sm_handler = sm_handler;
656  memset(&m_pctl_status, 0, sizeof(ptu_pctl_status_t));
657 
658  return NRF_SUCCESS;
659 }
static ptu_sm_handler_t m_sm_handler
State machine event handler.
Definition: ptu_sensors.c:55
void ptu_power_sharing_on_wpt_service_evt ( ble_wpts_c_t p_wpts_c,
ble_wpts_c_evt_t *const  p_wpts_c_evt 
)

Handle service events.

Parameters
[in]p_wpts_cHandles.
[in]p_wpts_c_evtEvent data.

Definition at line 666 of file ptu_power_sharing.c.

667 {
668  ptu_reg_item_t * new_reg_item_p = ptu_reg_item_get_from_conn_handle(p_wpts_c->conn_handle);
669 
671 
672  if (new_reg_item_p != NULL)
673  {
674  // Perform charge_complete control
675  if(p_wpts_c_evt->type == BLE_WPTS_C_EVT_PRU_ALERT ||
677  {
678  m_charge_complete_update(new_reg_item_p, p_wpts_c_evt);
679  m_status_update();
680 
681  if(p_wpts_c_evt->data.pru_dynamic.adjust_power_response == 1)
682  new_reg_item_p->adjusted_power = true;
683  }
684 
685  // Whenever we receive a PRU dynamic update we might wanna adjust power.
686  switch(p_wpts_c_evt->type)
687  {
689 
690  // If we have a new device to register.
691  if(new_reg_item_p->state != REG_ITEM_STATE_REGISTERED)
692  {
693  m_handle_new_device(new_reg_item_p);
694  }
695 
696  else
697  {
698  if(!m_pctl_status.pending_power_adjust)
699  {
700  // If we have in sum have granted PRUs to consume more power than we can give
701  if(m_pctl_status.available_power < 0)
702  {
703  // Attempt to instruct PRUs to reduce power
704  if(!m_pru_decrease_power())
705  {
706  // If not possible to reduce PRU power, we have to deny some PRUs to use power.
707  (void)m_pru_deny_power();
708  }
709  }
710  // If any PRUs has been denied to start charging
711  else if(m_pctl_status.prus_waiting)
712  {
713  // Attempt to allow denied PRUs start charging.
714  if(!m_pru_allow_power())
715  {
716  // If this was not possible we try to reduce power to the other PRUs.
717  (void)m_pru_decrease_power();
718  }
719  }
720  else
721  {
722  // We have power "left". We allow PRUs to consume more power.
723  (void)m_pru_increase_power();
724  }
725  }
726  }
727  break;
729  new_reg_item_p->pending_ctl_write = false;
730  break;
731  default:
732  break;
733  }
734  }
735 }
Registry item.
Definition: ptu_registry.h:47
union ble_wpts_c_evt_t::@1 data
uint16_t conn_handle
Definition: ble_wpts_c.h:66
uint8_t adjust_power_response
Definition: wpt.h:177
static void m_handle_new_device(ptu_reg_item_t *reg_item_p)
Handle the power sharing of a new PRU.
uint8_t pending_ctl_write
Definition: ptu_registry.h:65
static bool m_pru_decrease_power()
Search for PRUs having "adjust power" capability and send control packet instructing the PRU to reduc...
static bool m_pru_deny_power()
Search for PRUs being permitted to enable charge output and send control packet denying the PRU to do...
ble_wpts_c_evt_type_t type
Definition: ble_wpts_c.h:46
static bool m_pru_increase_power()
Search for PRUs having "adjust power" capability and send control packet allowing the PRU to increase...
static bool m_pru_allow_power()
Search for PRUs not being permitted to enable charge output and send control packet allowing the PRU ...
ptu_reg_item_t * ptu_reg_item_get_from_conn_handle(uint16_t conn_handle)
Get registry item from connection handle.
Definition: ptu_registry.c:137
pru_dynamic_t pru_dynamic
Definition: ble_wpts_c.h:51
static void m_update_pru_p_adj_status(void)
Update cooldown values for all PRUs which has received a power adjust command recently. Also checks for PRUs that does not respond with power adjust bit correctly after being sent a power adjust command.
static void m_charge_complete_update(ptu_reg_item_t *p_reg_item, ble_wpts_c_evt_t *const p_wpts_c_evt)
Check if all PRUs are done charging, in which case all will be disabled.
static void m_status_update(void)
Collect status information from all PRUs and update m_pctl_status.
ptu_reg_item_state_t state
Definition: ptu_registry.h:49
uint8_t adjusted_power
Definition: ptu_registry.h:63
void ptu_power_sharing_temperature_warning_set ( bool  warning)

Inform power control module that PTU is having a high temperature warning. When this occurs the power control module will instruct PRUs to lower their power consumption.

Parameters
[in]warningTemperature warning true or false.

Definition at line 661 of file ptu_power_sharing.c.

662 {
663  m_pctl_status.temperature_warning = warning;
664 }