hexsha
stringlengths
40
40
repo
stringlengths
5
105
path
stringlengths
3
173
license
sequence
language
stringclasses
1 value
identifier
stringlengths
1
438
return_type
stringlengths
1
106
original_string
stringlengths
21
40.7k
original_docstring
stringlengths
18
13.4k
docstring
stringlengths
11
3.24k
docstring_tokens
sequence
code
stringlengths
14
20.4k
code_tokens
sequence
short_docstring
stringlengths
0
4.36k
short_docstring_tokens
sequence
comment
sequence
parameters
list
docstring_params
dict
80eabcc90dce41e437b50e8b69e07b9f1ab4eea2
SiliconLabs/Gecko_SDK
platform/service/cpc/src/sl_cpc_drv_uart_secondary.c
[ "Zlib" ]
C
start_re_synch
void
static void start_re_synch(void) { DMADRV_StopTransfer(read_channel); sli_cpc_push_back_buffer_handle(&rx_free_list_head, &current_rx_entry->node, current_rx_entry->handle); current_rx_entry = NULL; USART_IntEnable(SL_CPC_DRV_UART_PERIPHERAL, USART_IF_RXDATAV); }
/***************************************************************************/ /** * Stop DMA mode and start receiving bytes in interrupt mode. ******************************************************************************/
Stop DMA mode and start receiving bytes in interrupt mode.
[ "Stop", "DMA", "mode", "and", "start", "receiving", "bytes", "in", "interrupt", "mode", "." ]
static void start_re_synch(void) { DMADRV_StopTransfer(read_channel); sli_cpc_push_back_buffer_handle(&rx_free_list_head, &current_rx_entry->node, current_rx_entry->handle); current_rx_entry = NULL; USART_IntEnable(SL_CPC_DRV_UART_PERIPHERAL, USART_IF_RXDATAV); }
[ "static", "void", "start_re_synch", "(", "void", ")", "{", "DMADRV_StopTransfer", "(", "read_channel", ")", ";", "sli_cpc_push_back_buffer_handle", "(", "&", "rx_free_list_head", ",", "&", "current_rx_entry", "->", "node", ",", "current_rx_entry", "->", "handle", ")", ";", "current_rx_entry", "=", "NULL", ";", "USART_IntEnable", "(", "SL_CPC_DRV_UART_PERIPHERAL", ",", "USART_IF_RXDATAV", ")", ";", "}" ]
Stop DMA mode and start receiving bytes in interrupt mode.
[ "Stop", "DMA", "mode", "and", "start", "receiving", "bytes", "in", "interrupt", "mode", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
35f7e0929bdb986e53ae6cf93e0775981fdbc48e
SiliconLabs/Gecko_SDK
app/bluetooth/common/btmesh_sensor_server/sl_btmesh_sensor_server_cadence.c
[ "Zlib" ]
C
sensor_people_count_fast_cadence
bool
static bool sensor_people_count_fast_cadence(count16_t people_count) { bool ret_val = false; count16_t fast_cadence_high = (count16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_high.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_high.value[1] << FAST_CADENCE_DELTA_SHIFT)); count16_t fast_cadence_low = (count16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_low.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_low.value[1] << FAST_CADENCE_DELTA_SHIFT)); // Check if the Fast Cadence High value is equal or higher than the Fast Cadence Low value if (fast_cadence_high >= fast_cadence_low) { // If the measured value is within the closed interval of // [Fast Cadence Low, Fast Cadence High], Sensor Status publishing period // modification is required. if ((people_count >= fast_cadence_low) && (people_count <= fast_cadence_high)) { ret_val = true; } // Check if the Fast Cadence High value is lower than the Fast Cadence Low value } else { // If the measured value is lower than the Fast Cadence High value or is // higher than the Fast Cadence Low value, Sensor Status publishing period // modification is required. if ((people_count < fast_cadence_high) || (people_count > fast_cadence_low)) { ret_val = true; } } return ret_val; }
/***************************************************************************/ /** * Check if the measured value requires publishing period modification. * * @param[in] people_count People count sensor data value * * @return True if publishing period modification is required false otherwise ******************************************************************************/
Check if the measured value requires publishing period modification. @param[in] people_count People count sensor data value @return True if publishing period modification is required false otherwise
[ "Check", "if", "the", "measured", "value", "requires", "publishing", "period", "modification", ".", "@param", "[", "in", "]", "people_count", "People", "count", "sensor", "data", "value", "@return", "True", "if", "publishing", "period", "modification", "is", "required", "false", "otherwise" ]
static bool sensor_people_count_fast_cadence(count16_t people_count) { bool ret_val = false; count16_t fast_cadence_high = (count16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_high.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_high.value[1] << FAST_CADENCE_DELTA_SHIFT)); count16_t fast_cadence_low = (count16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_low.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].fast_cadence_low.value[1] << FAST_CADENCE_DELTA_SHIFT)); if (fast_cadence_high >= fast_cadence_low) { if ((people_count >= fast_cadence_low) && (people_count <= fast_cadence_high)) { ret_val = true; } } else { if ((people_count < fast_cadence_high) || (people_count > fast_cadence_low)) { ret_val = true; } } return ret_val; }
[ "static", "bool", "sensor_people_count_fast_cadence", "(", "count16_t", "people_count", ")", "{", "bool", "ret_val", "=", "false", ";", "count16_t", "fast_cadence_high", "=", "(", "count16_t", ")", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "fast_cadence_high", ".", "value", "[", "0", "]", "|", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "fast_cadence_high", ".", "value", "[", "1", "]", "<<", "FAST_CADENCE_DELTA_SHIFT", ")", ")", ";", "count16_t", "fast_cadence_low", "=", "(", "count16_t", ")", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "fast_cadence_low", ".", "value", "[", "0", "]", "|", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "fast_cadence_low", ".", "value", "[", "1", "]", "<<", "FAST_CADENCE_DELTA_SHIFT", ")", ")", ";", "if", "(", "fast_cadence_high", ">=", "fast_cadence_low", ")", "{", "if", "(", "(", "people_count", ">=", "fast_cadence_low", ")", "&&", "(", "people_count", "<=", "fast_cadence_high", ")", ")", "{", "ret_val", "=", "true", ";", "}", "}", "else", "{", "if", "(", "(", "people_count", "<", "fast_cadence_high", ")", "||", "(", "people_count", ">", "fast_cadence_low", ")", ")", "{", "ret_val", "=", "true", ";", "}", "}", "return", "ret_val", ";", "}" ]
Check if the measured value requires publishing period modification.
[ "Check", "if", "the", "measured", "value", "requires", "publishing", "period", "modification", "." ]
[ "// Check if the Fast Cadence High value is equal or higher than the Fast Cadence Low value", "// If the measured value is within the closed interval of", "// [Fast Cadence Low, Fast Cadence High], Sensor Status publishing period", "// modification is required.", "// Check if the Fast Cadence High value is lower than the Fast Cadence Low value", "// If the measured value is lower than the Fast Cadence High value or is", "// higher than the Fast Cadence Low value, Sensor Status publishing period", "// modification is required." ]
[ { "param": "people_count", "type": "count16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "people_count", "type": "count16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
35f7e0929bdb986e53ae6cf93e0775981fdbc48e
SiliconLabs/Gecko_SDK
app/bluetooth/common/btmesh_sensor_server/sl_btmesh_sensor_server_cadence.c
[ "Zlib" ]
C
sensor_people_count_delta_cadence
bool
static bool sensor_people_count_delta_cadence(count16_t people_count) { bool ret_val = false; uint16_t delta_percent; uint16_t delta_cadence_up = (uint16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_up.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_up.value[1] << FAST_CADENCE_DELTA_SHIFT)); uint16_t delta_cadence_down = (uint16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_down.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_down.value[1] << FAST_CADENCE_DELTA_SHIFT)); // Check the unit and format of the Status Trigger Delta Down and // the Status Trigger Delta Up fields. if (SENSOR_PEOPLE_COUNT_STATUS_TRIGGER_TYPE_DISCRETE_VALUE == cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_type) { // If the temperature change is rising and the measured quantity change // exceeds the configured Status Trigger Delta Up value, Sensor Status // publishing period modification is required. if ((people_count > prev_people_count_data) && ((people_count - prev_people_count_data) >= (count16_t)delta_cadence_up)) { ret_val = true; // If the temperature change is falling and the measured quantity change // exceeds the configured Status Trigger Delta Down value, Sensor Status // publishing period modification is required. } else if ((people_count < prev_people_count_data) && ((prev_people_count_data - people_count) >= (count16_t)delta_cadence_down)) { ret_val = true; } else { } // Same check with measured value represented unitless as percentage } else if ((SENSOR_PEOPLE_COUNT_STATUS_TRIGGER_TYPE_PERCENTAGE == cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_type) && (prev_people_count_data != people_count)) { if (!prev_people_count_data) { delta_percent = PERCENTAGE_FULL; } else { delta_percent = delta_abs((delta_abs(prev_people_count_data - people_count) * PERCENTAGE_FULL) / prev_people_count_data); } if ((people_count > prev_people_count_data) && (delta_percent >= delta_cadence_up)) { ret_val = true; } else if ((people_count < prev_people_count_data) && (delta_percent >= delta_cadence_down)) { ret_val = true; } else { } } else { } return ret_val; }
/***************************************************************************/ /** * Check if the change of the measured value requires publishing period modification. * * @param[in] people_count People count sensor data value * * @return True if publishing period modification is required false otherwise ******************************************************************************/
Check if the change of the measured value requires publishing period modification. @param[in] people_count People count sensor data value @return True if publishing period modification is required false otherwise
[ "Check", "if", "the", "change", "of", "the", "measured", "value", "requires", "publishing", "period", "modification", ".", "@param", "[", "in", "]", "people_count", "People", "count", "sensor", "data", "value", "@return", "True", "if", "publishing", "period", "modification", "is", "required", "false", "otherwise" ]
static bool sensor_people_count_delta_cadence(count16_t people_count) { bool ret_val = false; uint16_t delta_percent; uint16_t delta_cadence_up = (uint16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_up.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_up.value[1] << FAST_CADENCE_DELTA_SHIFT)); uint16_t delta_cadence_down = (uint16_t)(cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_down.value[0] | (cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_delta_down.value[1] << FAST_CADENCE_DELTA_SHIFT)); if (SENSOR_PEOPLE_COUNT_STATUS_TRIGGER_TYPE_DISCRETE_VALUE == cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_type) { if ((people_count > prev_people_count_data) && ((people_count - prev_people_count_data) >= (count16_t)delta_cadence_up)) { ret_val = true; } else if ((people_count < prev_people_count_data) && ((prev_people_count_data - people_count) >= (count16_t)delta_cadence_down)) { ret_val = true; } else { } } else if ((SENSOR_PEOPLE_COUNT_STATUS_TRIGGER_TYPE_PERCENTAGE == cadences[SENSOR_PEOPLE_COUNT_INDEX].status_trigger_type) && (prev_people_count_data != people_count)) { if (!prev_people_count_data) { delta_percent = PERCENTAGE_FULL; } else { delta_percent = delta_abs((delta_abs(prev_people_count_data - people_count) * PERCENTAGE_FULL) / prev_people_count_data); } if ((people_count > prev_people_count_data) && (delta_percent >= delta_cadence_up)) { ret_val = true; } else if ((people_count < prev_people_count_data) && (delta_percent >= delta_cadence_down)) { ret_val = true; } else { } } else { } return ret_val; }
[ "static", "bool", "sensor_people_count_delta_cadence", "(", "count16_t", "people_count", ")", "{", "bool", "ret_val", "=", "false", ";", "uint16_t", "delta_percent", ";", "uint16_t", "delta_cadence_up", "=", "(", "uint16_t", ")", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "status_trigger_delta_up", ".", "value", "[", "0", "]", "|", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "status_trigger_delta_up", ".", "value", "[", "1", "]", "<<", "FAST_CADENCE_DELTA_SHIFT", ")", ")", ";", "uint16_t", "delta_cadence_down", "=", "(", "uint16_t", ")", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "status_trigger_delta_down", ".", "value", "[", "0", "]", "|", "(", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "status_trigger_delta_down", ".", "value", "[", "1", "]", "<<", "FAST_CADENCE_DELTA_SHIFT", ")", ")", ";", "if", "(", "SENSOR_PEOPLE_COUNT_STATUS_TRIGGER_TYPE_DISCRETE_VALUE", "==", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "status_trigger_type", ")", "{", "if", "(", "(", "people_count", ">", "prev_people_count_data", ")", "&&", "(", "(", "people_count", "-", "prev_people_count_data", ")", ">=", "(", "count16_t", ")", "delta_cadence_up", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "if", "(", "(", "people_count", "<", "prev_people_count_data", ")", "&&", "(", "(", "prev_people_count_data", "-", "people_count", ")", ">=", "(", "count16_t", ")", "delta_cadence_down", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "{", "}", "}", "else", "if", "(", "(", "SENSOR_PEOPLE_COUNT_STATUS_TRIGGER_TYPE_PERCENTAGE", "==", "cadences", "[", "SENSOR_PEOPLE_COUNT_INDEX", "]", ".", "status_trigger_type", ")", "&&", "(", "prev_people_count_data", "!=", "people_count", ")", ")", "{", "if", "(", "!", "prev_people_count_data", ")", "{", "delta_percent", "=", "PERCENTAGE_FULL", ";", "}", "else", "{", "delta_percent", "=", "delta_abs", "(", "(", "delta_abs", "(", "prev_people_count_data", "-", "people_count", ")", "*", "PERCENTAGE_FULL", ")", "/", "prev_people_count_data", ")", ";", "}", "if", "(", "(", "people_count", ">", "prev_people_count_data", ")", "&&", "(", "delta_percent", ">=", "delta_cadence_up", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "if", "(", "(", "people_count", "<", "prev_people_count_data", ")", "&&", "(", "delta_percent", ">=", "delta_cadence_down", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "{", "}", "}", "else", "{", "}", "return", "ret_val", ";", "}" ]
Check if the change of the measured value requires publishing period modification.
[ "Check", "if", "the", "change", "of", "the", "measured", "value", "requires", "publishing", "period", "modification", "." ]
[ "// Check the unit and format of the Status Trigger Delta Down and", "// the Status Trigger Delta Up fields.", "// If the temperature change is rising and the measured quantity change", "// exceeds the configured Status Trigger Delta Up value, Sensor Status", "// publishing period modification is required.", "// If the temperature change is falling and the measured quantity change", "// exceeds the configured Status Trigger Delta Down value, Sensor Status", "// publishing period modification is required.", "// Same check with measured value represented unitless as percentage" ]
[ { "param": "people_count", "type": "count16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "people_count", "type": "count16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
35f7e0929bdb986e53ae6cf93e0775981fdbc48e
SiliconLabs/Gecko_SDK
app/bluetooth/common/btmesh_sensor_server/sl_btmesh_sensor_server_cadence.c
[ "Zlib" ]
C
sensor_thermometer_fast_cadence
bool
static bool sensor_thermometer_fast_cadence(temperature_8_t temperature) { bool ret_val = false; // Check if the Fast Cadence High value is equal or higher than the Fast Cadence Low value if ((temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_high.value[0]) >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_low.value[0])) { // If the measured value is within the closed interval of // [Fast Cadence Low, Fast Cadence High], Sensor Status publishing period // modification is required. if ((temperature >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_low.value[0])) && (temperature <= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_high.value[0]))) { ret_val = true; } // If the Fast Cadence High value is lower than the Fast Cadence Low value } else { // If the measured value is lower than the Fast Cadence High value or is // higher than the Fast Cadence Low value, Sensor Status publishing period // modification is required. if ((temperature < (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_high.value[0])) || (temperature > (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_low.value[0]))) { ret_val = true; } } return ret_val; }
/***************************************************************************/ /** * Check if the measured value requires publishing period modification. * * @param[in] temperature Thermometer sensor data value. * * @return True if modification is required false otherwise ******************************************************************************/
Check if the measured value requires publishing period modification. @param[in] temperature Thermometer sensor data value. @return True if modification is required false otherwise
[ "Check", "if", "the", "measured", "value", "requires", "publishing", "period", "modification", ".", "@param", "[", "in", "]", "temperature", "Thermometer", "sensor", "data", "value", ".", "@return", "True", "if", "modification", "is", "required", "false", "otherwise" ]
static bool sensor_thermometer_fast_cadence(temperature_8_t temperature) { bool ret_val = false; if ((temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_high.value[0]) >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_low.value[0])) { if ((temperature >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_low.value[0])) && (temperature <= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_high.value[0]))) { ret_val = true; } } else { if ((temperature < (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_high.value[0])) || (temperature > (temperature_8_t)(cadences[SENSOR_RHT_INDEX].fast_cadence_low.value[0]))) { ret_val = true; } } return ret_val; }
[ "static", "bool", "sensor_thermometer_fast_cadence", "(", "temperature_8_t", "temperature", ")", "{", "bool", "ret_val", "=", "false", ";", "if", "(", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "fast_cadence_high", ".", "value", "[", "0", "]", ")", ">=", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "fast_cadence_low", ".", "value", "[", "0", "]", ")", ")", "{", "if", "(", "(", "temperature", ">=", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "fast_cadence_low", ".", "value", "[", "0", "]", ")", ")", "&&", "(", "temperature", "<=", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "fast_cadence_high", ".", "value", "[", "0", "]", ")", ")", ")", "{", "ret_val", "=", "true", ";", "}", "}", "else", "{", "if", "(", "(", "temperature", "<", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "fast_cadence_high", ".", "value", "[", "0", "]", ")", ")", "||", "(", "temperature", ">", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "fast_cadence_low", ".", "value", "[", "0", "]", ")", ")", ")", "{", "ret_val", "=", "true", ";", "}", "}", "return", "ret_val", ";", "}" ]
Check if the measured value requires publishing period modification.
[ "Check", "if", "the", "measured", "value", "requires", "publishing", "period", "modification", "." ]
[ "// Check if the Fast Cadence High value is equal or higher than the Fast Cadence Low value", "// If the measured value is within the closed interval of", "// [Fast Cadence Low, Fast Cadence High], Sensor Status publishing period", "// modification is required.", "// If the Fast Cadence High value is lower than the Fast Cadence Low value", "// If the measured value is lower than the Fast Cadence High value or is", "// higher than the Fast Cadence Low value, Sensor Status publishing period", "// modification is required." ]
[ { "param": "temperature", "type": "temperature_8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "temperature", "type": "temperature_8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
35f7e0929bdb986e53ae6cf93e0775981fdbc48e
SiliconLabs/Gecko_SDK
app/bluetooth/common/btmesh_sensor_server/sl_btmesh_sensor_server_cadence.c
[ "Zlib" ]
C
sensor_thermometer_delta_cadence
bool
static bool sensor_thermometer_delta_cadence(temperature_8_t temperature) { bool ret_val = false; uint16_t delta_percent; uint16_t percent_delta_up_value; uint16_t percent_delta_down_value; // Check the unit and format of the Status Trigger Delta Down and // the Status Trigger Delta Up fields. if (SENSOR_THERMOMETER_STATUS_TRIGGER_TYPE_DISCRETE_VALUE == cadences[SENSOR_RHT_INDEX].status_trigger_type) { // If the temperature change is rising edge and the measured quantity change // exceeds the configured Status Trigger Delta Up value, the Sensor Status // messages are published more frequently. if ((temperature > prev_temp_data) && ((temperature - prev_temp_data) >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_up.value[0]))) { ret_val = true; // If the temperature change is rising edge and the measured quantity change // exceeds the configured Status Trigger Delta Up value, the Sensor Status // messages are published more frequently. } else if ((temperature < prev_temp_data) && ((prev_temp_data - temperature) >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_down.value[0]))) { ret_val = true; } else { } // Same check with measured value represented unitless as percentage } else if ((SENSOR_THERMOMETER_STATUS_TRIGGER_TYPE_PERCENTAGE == cadences[SENSOR_RHT_INDEX].status_trigger_type) && (prev_temp_data != temperature)) { percent_delta_down_value = (uint16_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_down.value[0] | (cadences[SENSOR_RHT_INDEX].status_trigger_delta_down.value[1] << FAST_CADENCE_DELTA_SHIFT)); percent_delta_up_value = (uint16_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_up.value[0] | (cadences[SENSOR_RHT_INDEX].status_trigger_delta_up.value[1] << FAST_CADENCE_DELTA_SHIFT)); if (!prev_temp_data) { delta_percent = PERCENTAGE_FULL; } else { delta_percent = delta_abs((delta_abs(prev_temp_data - temperature) * PERCENTAGE_FULL) / prev_temp_data); } if ((temperature > prev_temp_data) && (delta_percent >= percent_delta_up_value)) { ret_val = true; } else if ((temperature < prev_temp_data) && (delta_percent >= percent_delta_down_value)) { ret_val = true; } else { } } else { } return ret_val; }
/***************************************************************************/ /** * Check if the change of the measured value requires publishing period modification. * * @param[in] temperature Thermometer sensor data value. * * @return True if modification is required false otherwise ******************************************************************************/
Check if the change of the measured value requires publishing period modification. @param[in] temperature Thermometer sensor data value. @return True if modification is required false otherwise
[ "Check", "if", "the", "change", "of", "the", "measured", "value", "requires", "publishing", "period", "modification", ".", "@param", "[", "in", "]", "temperature", "Thermometer", "sensor", "data", "value", ".", "@return", "True", "if", "modification", "is", "required", "false", "otherwise" ]
static bool sensor_thermometer_delta_cadence(temperature_8_t temperature) { bool ret_val = false; uint16_t delta_percent; uint16_t percent_delta_up_value; uint16_t percent_delta_down_value; if (SENSOR_THERMOMETER_STATUS_TRIGGER_TYPE_DISCRETE_VALUE == cadences[SENSOR_RHT_INDEX].status_trigger_type) { if ((temperature > prev_temp_data) && ((temperature - prev_temp_data) >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_up.value[0]))) { ret_val = true; } else if ((temperature < prev_temp_data) && ((prev_temp_data - temperature) >= (temperature_8_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_down.value[0]))) { ret_val = true; } else { } } else if ((SENSOR_THERMOMETER_STATUS_TRIGGER_TYPE_PERCENTAGE == cadences[SENSOR_RHT_INDEX].status_trigger_type) && (prev_temp_data != temperature)) { percent_delta_down_value = (uint16_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_down.value[0] | (cadences[SENSOR_RHT_INDEX].status_trigger_delta_down.value[1] << FAST_CADENCE_DELTA_SHIFT)); percent_delta_up_value = (uint16_t)(cadences[SENSOR_RHT_INDEX].status_trigger_delta_up.value[0] | (cadences[SENSOR_RHT_INDEX].status_trigger_delta_up.value[1] << FAST_CADENCE_DELTA_SHIFT)); if (!prev_temp_data) { delta_percent = PERCENTAGE_FULL; } else { delta_percent = delta_abs((delta_abs(prev_temp_data - temperature) * PERCENTAGE_FULL) / prev_temp_data); } if ((temperature > prev_temp_data) && (delta_percent >= percent_delta_up_value)) { ret_val = true; } else if ((temperature < prev_temp_data) && (delta_percent >= percent_delta_down_value)) { ret_val = true; } else { } } else { } return ret_val; }
[ "static", "bool", "sensor_thermometer_delta_cadence", "(", "temperature_8_t", "temperature", ")", "{", "bool", "ret_val", "=", "false", ";", "uint16_t", "delta_percent", ";", "uint16_t", "percent_delta_up_value", ";", "uint16_t", "percent_delta_down_value", ";", "if", "(", "SENSOR_THERMOMETER_STATUS_TRIGGER_TYPE_DISCRETE_VALUE", "==", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_type", ")", "{", "if", "(", "(", "temperature", ">", "prev_temp_data", ")", "&&", "(", "(", "temperature", "-", "prev_temp_data", ")", ">=", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_delta_up", ".", "value", "[", "0", "]", ")", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "if", "(", "(", "temperature", "<", "prev_temp_data", ")", "&&", "(", "(", "prev_temp_data", "-", "temperature", ")", ">=", "(", "temperature_8_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_delta_down", ".", "value", "[", "0", "]", ")", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "{", "}", "}", "else", "if", "(", "(", "SENSOR_THERMOMETER_STATUS_TRIGGER_TYPE_PERCENTAGE", "==", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_type", ")", "&&", "(", "prev_temp_data", "!=", "temperature", ")", ")", "{", "percent_delta_down_value", "=", "(", "uint16_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_delta_down", ".", "value", "[", "0", "]", "|", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_delta_down", ".", "value", "[", "1", "]", "<<", "FAST_CADENCE_DELTA_SHIFT", ")", ")", ";", "percent_delta_up_value", "=", "(", "uint16_t", ")", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_delta_up", ".", "value", "[", "0", "]", "|", "(", "cadences", "[", "SENSOR_RHT_INDEX", "]", ".", "status_trigger_delta_up", ".", "value", "[", "1", "]", "<<", "FAST_CADENCE_DELTA_SHIFT", ")", ")", ";", "if", "(", "!", "prev_temp_data", ")", "{", "delta_percent", "=", "PERCENTAGE_FULL", ";", "}", "else", "{", "delta_percent", "=", "delta_abs", "(", "(", "delta_abs", "(", "prev_temp_data", "-", "temperature", ")", "*", "PERCENTAGE_FULL", ")", "/", "prev_temp_data", ")", ";", "}", "if", "(", "(", "temperature", ">", "prev_temp_data", ")", "&&", "(", "delta_percent", ">=", "percent_delta_up_value", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "if", "(", "(", "temperature", "<", "prev_temp_data", ")", "&&", "(", "delta_percent", ">=", "percent_delta_down_value", ")", ")", "{", "ret_val", "=", "true", ";", "}", "else", "{", "}", "}", "else", "{", "}", "return", "ret_val", ";", "}" ]
Check if the change of the measured value requires publishing period modification.
[ "Check", "if", "the", "change", "of", "the", "measured", "value", "requires", "publishing", "period", "modification", "." ]
[ "// Check the unit and format of the Status Trigger Delta Down and", "// the Status Trigger Delta Up fields.", "// If the temperature change is rising edge and the measured quantity change", "// exceeds the configured Status Trigger Delta Up value, the Sensor Status", "// messages are published more frequently.", "// If the temperature change is rising edge and the measured quantity change", "// exceeds the configured Status Trigger Delta Up value, the Sensor Status", "// messages are published more frequently.", "// Same check with measured value represented unitless as percentage" ]
[ { "param": "temperature", "type": "temperature_8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "temperature", "type": "temperature_8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a2daa1424f838697bd5e2d726e3de87e919ed238
SiliconLabs/Gecko_SDK
protocol/zigbee/app/framework/scenarios/multiprotocol/common/sl_ble_event_handler.c
[ "Zlib" ]
C
zb_ble_dmp_read_light_state
void
void zb_ble_dmp_read_light_state(uint8_t connection) { uint16_t sent_data_len; emberAfCorePrintln("Light state = %d\r\n", ble_lightState); /* Send response to read request */ sl_status_t status = sl_bt_gatt_server_send_user_read_response(connection, gattdb_light_state, SL_STATUS_OK, sizeof(ble_lightState), &ble_lightState, &sent_data_len); if (status != SL_STATUS_OK) { emberAfCorePrintln("Failed to zb_ble_dmp_read_light_state"); } }
/* Characteristic read / write / notify handler functions */
Characteristic read / write / notify handler functions
[ "Characteristic", "read", "/", "write", "/", "notify", "handler", "functions" ]
void zb_ble_dmp_read_light_state(uint8_t connection) { uint16_t sent_data_len; emberAfCorePrintln("Light state = %d\r\n", ble_lightState); sl_status_t status = sl_bt_gatt_server_send_user_read_response(connection, gattdb_light_state, SL_STATUS_OK, sizeof(ble_lightState), &ble_lightState, &sent_data_len); if (status != SL_STATUS_OK) { emberAfCorePrintln("Failed to zb_ble_dmp_read_light_state"); } }
[ "void", "zb_ble_dmp_read_light_state", "(", "uint8_t", "connection", ")", "{", "uint16_t", "sent_data_len", ";", "emberAfCorePrintln", "(", "\"", "\\r", "\\n", "\"", ",", "ble_lightState", ")", ";", "sl_status_t", "status", "=", "sl_bt_gatt_server_send_user_read_response", "(", "connection", ",", "gattdb_light_state", ",", "SL_STATUS_OK", ",", "sizeof", "(", "ble_lightState", ")", ",", "&", "ble_lightState", ",", "&", "sent_data_len", ")", ";", "if", "(", "status", "!=", "SL_STATUS_OK", ")", "{", "emberAfCorePrintln", "(", "\"", "\"", ")", ";", "}", "}" ]
Characteristic read / write / notify handler functions
[ "Characteristic", "read", "/", "write", "/", "notify", "handler", "functions" ]
[ "/* Send response to read request */" ]
[ { "param": "connection", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "connection", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7196c72044bc3fe3ae7690d74b185e5f52701369
SiliconLabs/Gecko_SDK
protocol/zigbee/app/framework/util/af-event.c
[ "Zlib" ]
C
emberAfGetCurrentSleepControlCallback
EmberAfEventSleepControl
EmberAfEventSleepControl emberAfGetCurrentSleepControlCallback(void) { EmberAfEventSleepControl sleepControl = defaultSleepControl; #if defined(EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT) && EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT > 0 uint8_t i; for (i = 0; i < sli_zigbee_app_event_context_length; i++) { sl_zigbee_event_context_t *context = &sli_zigbee_app_event_context[i]; if ( (0 == sl_zigbee_event_get_remaining_ms(&(*context->event))) //equivalent to emberEventControlGetActive && sleepControl < context->sleepControl) { sleepControl = context->sleepControl; } } #endif // EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT return sleepControl; }
// Checks all application events to see if any active events require the micro to stay awake
Checks all application events to see if any active events require the micro to stay awake
[ "Checks", "all", "application", "events", "to", "see", "if", "any", "active", "events", "require", "the", "micro", "to", "stay", "awake" ]
EmberAfEventSleepControl emberAfGetCurrentSleepControlCallback(void) { EmberAfEventSleepControl sleepControl = defaultSleepControl; #if defined(EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT) && EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT > 0 uint8_t i; for (i = 0; i < sli_zigbee_app_event_context_length; i++) { sl_zigbee_event_context_t *context = &sli_zigbee_app_event_context[i]; if ( (0 == sl_zigbee_event_get_remaining_ms(&(*context->event))) && sleepControl < context->sleepControl) { sleepControl = context->sleepControl; } } #endif return sleepControl; }
[ "EmberAfEventSleepControl", "emberAfGetCurrentSleepControlCallback", "(", "void", ")", "{", "EmberAfEventSleepControl", "sleepControl", "=", "defaultSleepControl", ";", "#if", "defined", "(", "EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT", ")", "&&", "EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT", ">", "0", "\n", "uint8_t", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "sli_zigbee_app_event_context_length", ";", "i", "++", ")", "{", "sl_zigbee_event_context_t", "*", "context", "=", "&", "sli_zigbee_app_event_context", "[", "i", "]", ";", "if", "(", "(", "0", "==", "sl_zigbee_event_get_remaining_ms", "(", "&", "(", "*", "context", "->", "event", ")", ")", ")", "&&", "sleepControl", "<", "context", "->", "sleepControl", ")", "{", "sleepControl", "=", "context", "->", "sleepControl", ";", "}", "}", "#endif", "return", "sleepControl", ";", "}" ]
Checks all application events to see if any active events require the micro to stay awake
[ "Checks", "all", "application", "events", "to", "see", "if", "any", "active", "events", "require", "the", "micro", "to", "stay", "awake" ]
[ "//equivalent to emberEventControlGetActive", "// EMBER_AF_GENERATED_UC_EVENT_CONTEXT_COUNT" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
acfd2e0a43f850f75186ef47f577e0d4e665f465
SiliconLabs/Gecko_SDK
app/bluetooth/common_host/ncp_host/ncp_host.c
[ "Zlib" ]
C
ncp_host_peek_timeout
int32_t
int32_t ncp_host_peek_timeout(uint32_t len, uint32_t timeout) { int32_t ret; uint32_t timeout_counter = 0; do { ret = host_comm_peek(); timeout_counter++; app_sleep_us(PEEK_US_SLEEP); } while ((ret < len) && (timeout_counter < timeout)); return ret; }
/**************************************************************************/ /** * Peek if readable data exists with timeout option. *****************************************************************************/
Peek if readable data exists with timeout option.
[ "Peek", "if", "readable", "data", "exists", "with", "timeout", "option", "." ]
int32_t ncp_host_peek_timeout(uint32_t len, uint32_t timeout) { int32_t ret; uint32_t timeout_counter = 0; do { ret = host_comm_peek(); timeout_counter++; app_sleep_us(PEEK_US_SLEEP); } while ((ret < len) && (timeout_counter < timeout)); return ret; }
[ "int32_t", "ncp_host_peek_timeout", "(", "uint32_t", "len", ",", "uint32_t", "timeout", ")", "{", "int32_t", "ret", ";", "uint32_t", "timeout_counter", "=", "0", ";", "do", "{", "ret", "=", "host_comm_peek", "(", ")", ";", "timeout_counter", "++", ";", "app_sleep_us", "(", "PEEK_US_SLEEP", ")", ";", "}", "while", "(", "(", "ret", "<", "len", ")", "&&", "(", "timeout_counter", "<", "timeout", ")", ")", ";", "return", "ret", ";", "}" ]
Peek if readable data exists with timeout option.
[ "Peek", "if", "readable", "data", "exists", "with", "timeout", "option", "." ]
[]
[ { "param": "len", "type": "uint32_t" }, { "param": "timeout", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "len", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "timeout", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8afb48ff21eb37420f2e2a43405441ea7129df9e
SiliconLabs/Gecko_SDK
app/wisun/component/socket/socket_hnd.c
[ "Zlib" ]
C
socket_handler_get_cnt
uint8_t
uint8_t socket_handler_get_cnt(void) { uint8_t retval = 0; _lock(); // lock socket handler retval = _cnt; _unlock(); //unlock socket handler return retval; }
/* get count of sockets in handler */
get count of sockets in handler
[ "get", "count", "of", "sockets", "in", "handler" ]
uint8_t socket_handler_get_cnt(void) { uint8_t retval = 0; _lock(); retval = _cnt; _unlock(); return retval; }
[ "uint8_t", "socket_handler_get_cnt", "(", "void", ")", "{", "uint8_t", "retval", "=", "0", ";", "_lock", "(", ")", ";", "retval", "=", "_cnt", ";", "_unlock", "(", ")", ";", "return", "retval", ";", "}" ]
get count of sockets in handler
[ "get", "count", "of", "sockets", "in", "handler" ]
[ "// lock socket handler", "//unlock socket handler" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
279f7d3c93b46d5534f686a5108fad2b6e2e5d99
SiliconLabs/Gecko_SDK
app/bluetooth/common_host/aoa_corr_angles/aoa_corr_angles.c
[ "Zlib" ]
C
aoa_corr_angles_new
sl_status_t
sl_status_t aoa_corr_angles_new(aoa_id_t id, aoa_corr_angles_t **corr_angles) { aoa_corr_angles_node_t *new = (aoa_corr_angles_node_t *)malloc(sizeof(aoa_corr_angles_node_t)); if (NULL == new) { return SL_STATUS_ALLOCATION_FAILED; } new->corr_angles = (aoa_corr_angles_t *)malloc(aoa_corr_angles_config.sequence_id_slots * sizeof(aoa_corr_angles_t)); if (NULL == new->corr_angles) { return SL_STATUS_ALLOCATION_FAILED; } // Initialize the angle structures for (uint32_t i = 0; i < aoa_corr_angles_config.sequence_id_slots; i++) { new->corr_angles[i].angles = (aoa_angle_t *)malloc(aoa_corr_angles_config.locator_count * sizeof(aoa_angle_t)); new->corr_angles[i].has_angle = (bool *)malloc(aoa_corr_angles_config.locator_count * sizeof(bool)); new->corr_angles[i].sequence = -1; new->corr_angles[i].num_angles = 0; if ((NULL == new->corr_angles[i].angles) || (NULL == new->corr_angles[i].has_angle)) { return SL_STATUS_ALLOCATION_FAILED; } } aoa_id_copy(new->id, id); new->next = head_corr_angles; head_corr_angles = new; *corr_angles = new->corr_angles; return SL_STATUS_OK; }
/**************************************************************************/ /** * Adds a correlated angle to the list. *****************************************************************************/
Adds a correlated angle to the list.
[ "Adds", "a", "correlated", "angle", "to", "the", "list", "." ]
sl_status_t aoa_corr_angles_new(aoa_id_t id, aoa_corr_angles_t **corr_angles) { aoa_corr_angles_node_t *new = (aoa_corr_angles_node_t *)malloc(sizeof(aoa_corr_angles_node_t)); if (NULL == new) { return SL_STATUS_ALLOCATION_FAILED; } new->corr_angles = (aoa_corr_angles_t *)malloc(aoa_corr_angles_config.sequence_id_slots * sizeof(aoa_corr_angles_t)); if (NULL == new->corr_angles) { return SL_STATUS_ALLOCATION_FAILED; } for (uint32_t i = 0; i < aoa_corr_angles_config.sequence_id_slots; i++) { new->corr_angles[i].angles = (aoa_angle_t *)malloc(aoa_corr_angles_config.locator_count * sizeof(aoa_angle_t)); new->corr_angles[i].has_angle = (bool *)malloc(aoa_corr_angles_config.locator_count * sizeof(bool)); new->corr_angles[i].sequence = -1; new->corr_angles[i].num_angles = 0; if ((NULL == new->corr_angles[i].angles) || (NULL == new->corr_angles[i].has_angle)) { return SL_STATUS_ALLOCATION_FAILED; } } aoa_id_copy(new->id, id); new->next = head_corr_angles; head_corr_angles = new; *corr_angles = new->corr_angles; return SL_STATUS_OK; }
[ "sl_status_t", "aoa_corr_angles_new", "(", "aoa_id_t", "id", ",", "aoa_corr_angles_t", "*", "*", "corr_angles", ")", "{", "aoa_corr_angles_node_t", "*", "new", "=", "(", "aoa_corr_angles_node_t", "*", ")", "malloc", "(", "sizeof", "(", "aoa_corr_angles_node_t", ")", ")", ";", "if", "(", "NULL", "==", "new", ")", "{", "return", "SL_STATUS_ALLOCATION_FAILED", ";", "}", "new", "->", "corr_angles", "=", "(", "aoa_corr_angles_t", "*", ")", "malloc", "(", "aoa_corr_angles_config", ".", "sequence_id_slots", "*", "sizeof", "(", "aoa_corr_angles_t", ")", ")", ";", "if", "(", "NULL", "==", "new", "->", "corr_angles", ")", "{", "return", "SL_STATUS_ALLOCATION_FAILED", ";", "}", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "aoa_corr_angles_config", ".", "sequence_id_slots", ";", "i", "++", ")", "{", "new", "->", "corr_angles", "[", "i", "]", ".", "angles", "=", "(", "aoa_angle_t", "*", ")", "malloc", "(", "aoa_corr_angles_config", ".", "locator_count", "*", "sizeof", "(", "aoa_angle_t", ")", ")", ";", "new", "->", "corr_angles", "[", "i", "]", ".", "has_angle", "=", "(", "bool", "*", ")", "malloc", "(", "aoa_corr_angles_config", ".", "locator_count", "*", "sizeof", "(", "bool", ")", ")", ";", "new", "->", "corr_angles", "[", "i", "]", ".", "sequence", "=", "-1", ";", "new", "->", "corr_angles", "[", "i", "]", ".", "num_angles", "=", "0", ";", "if", "(", "(", "NULL", "==", "new", "->", "corr_angles", "[", "i", "]", ".", "angles", ")", "||", "(", "NULL", "==", "new", "->", "corr_angles", "[", "i", "]", ".", "has_angle", ")", ")", "{", "return", "SL_STATUS_ALLOCATION_FAILED", ";", "}", "}", "aoa_id_copy", "(", "new", "->", "id", ",", "id", ")", ";", "new", "->", "next", "=", "head_corr_angles", ";", "head_corr_angles", "=", "new", ";", "*", "corr_angles", "=", "new", "->", "corr_angles", ";", "return", "SL_STATUS_OK", ";", "}" ]
Adds a correlated angle to the list.
[ "Adds", "a", "correlated", "angle", "to", "the", "list", "." ]
[ "// Initialize the angle structures\r" ]
[ { "param": "id", "type": "aoa_id_t" }, { "param": "corr_angles", "type": "aoa_corr_angles_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "id", "type": "aoa_id_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "corr_angles", "type": "aoa_corr_angles_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
279f7d3c93b46d5534f686a5108fad2b6e2e5d99
SiliconLabs/Gecko_SDK
app/bluetooth/common_host/aoa_corr_angles/aoa_corr_angles.c
[ "Zlib" ]
C
aoa_corr_angles_get_by_id
sl_status_t
sl_status_t aoa_corr_angles_get_by_id(aoa_id_t id, aoa_corr_angles_t **corr_angles) { aoa_corr_angles_node_t *current = head_corr_angles; if (NULL == head_corr_angles) { return SL_STATUS_NOT_FOUND; } while (NULL != current) { if (0 == aoa_id_compare(current->id, id)) { *corr_angles = current->corr_angles; return SL_STATUS_OK; } current = current->next; } return SL_STATUS_NOT_FOUND; }
/**************************************************************************/ /** * Returns an entry from the database by its ID. *****************************************************************************/
Returns an entry from the database by its ID.
[ "Returns", "an", "entry", "from", "the", "database", "by", "its", "ID", "." ]
sl_status_t aoa_corr_angles_get_by_id(aoa_id_t id, aoa_corr_angles_t **corr_angles) { aoa_corr_angles_node_t *current = head_corr_angles; if (NULL == head_corr_angles) { return SL_STATUS_NOT_FOUND; } while (NULL != current) { if (0 == aoa_id_compare(current->id, id)) { *corr_angles = current->corr_angles; return SL_STATUS_OK; } current = current->next; } return SL_STATUS_NOT_FOUND; }
[ "sl_status_t", "aoa_corr_angles_get_by_id", "(", "aoa_id_t", "id", ",", "aoa_corr_angles_t", "*", "*", "corr_angles", ")", "{", "aoa_corr_angles_node_t", "*", "current", "=", "head_corr_angles", ";", "if", "(", "NULL", "==", "head_corr_angles", ")", "{", "return", "SL_STATUS_NOT_FOUND", ";", "}", "while", "(", "NULL", "!=", "current", ")", "{", "if", "(", "0", "==", "aoa_id_compare", "(", "current", "->", "id", ",", "id", ")", ")", "{", "*", "corr_angles", "=", "current", "->", "corr_angles", ";", "return", "SL_STATUS_OK", ";", "}", "current", "=", "current", "->", "next", ";", "}", "return", "SL_STATUS_NOT_FOUND", ";", "}" ]
Returns an entry from the database by its ID.
[ "Returns", "an", "entry", "from", "the", "database", "by", "its", "ID", "." ]
[]
[ { "param": "id", "type": "aoa_id_t" }, { "param": "corr_angles", "type": "aoa_corr_angles_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "id", "type": "aoa_id_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "corr_angles", "type": "aoa_corr_angles_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
279f7d3c93b46d5534f686a5108fad2b6e2e5d99
SiliconLabs/Gecko_SDK
app/bluetooth/common_host/aoa_corr_angles/aoa_corr_angles.c
[ "Zlib" ]
C
aoa_corr_angles_add_data
sl_status_t
sl_status_t aoa_corr_angles_add_data(aoa_corr_angles_t *corr_angles_array, uint32_t locator_id, aoa_angle_t *angle, uint32_t *angle_slot) { uint32_t slot = 0; // Drop stored data that are considered too old aoa_corr_angles_remove_old_data(corr_angles_array, angle->sequence); // Find the correct correlated angle slot slot = aoa_corr_angles_get_slot_by_sequence(corr_angles_array, angle->sequence); if (slot > aoa_corr_angles_config.sequence_id_slots) { return SL_STATUS_FAIL; } // Insert the slot if it is not present yet. if (corr_angles_array[slot].sequence != angle->sequence) { for (int i = aoa_corr_angles_config.sequence_id_slots - 1; i > slot; i--) { corr_angles_array[i].sequence = corr_angles_array[i - 1].sequence; corr_angles_array[i].num_angles = corr_angles_array[i - 1].num_angles; memcpy(corr_angles_array[i].angles, corr_angles_array[i - 1].angles, aoa_corr_angles_config.locator_count * sizeof(aoa_angle_t)); memcpy(corr_angles_array[i].has_angle, corr_angles_array[i - 1].has_angle, aoa_corr_angles_config.locator_count * sizeof(bool)); } corr_angles_array[slot].num_angles = 0; memset(corr_angles_array[slot].has_angle, 0, aoa_corr_angles_config.locator_count); corr_angles_array[slot].sequence = angle->sequence; } memcpy(&corr_angles_array[slot].angles[locator_id], angle, sizeof(aoa_angle_t)); corr_angles_array[slot].has_angle[locator_id] = true; corr_angles_array[slot].num_angles++; *angle_slot = slot; return SL_STATUS_OK; }
/**************************************************************************/ /** * Adds data to the slot. *****************************************************************************/
Adds data to the slot.
[ "Adds", "data", "to", "the", "slot", "." ]
sl_status_t aoa_corr_angles_add_data(aoa_corr_angles_t *corr_angles_array, uint32_t locator_id, aoa_angle_t *angle, uint32_t *angle_slot) { uint32_t slot = 0; aoa_corr_angles_remove_old_data(corr_angles_array, angle->sequence); slot = aoa_corr_angles_get_slot_by_sequence(corr_angles_array, angle->sequence); if (slot > aoa_corr_angles_config.sequence_id_slots) { return SL_STATUS_FAIL; } if (corr_angles_array[slot].sequence != angle->sequence) { for (int i = aoa_corr_angles_config.sequence_id_slots - 1; i > slot; i--) { corr_angles_array[i].sequence = corr_angles_array[i - 1].sequence; corr_angles_array[i].num_angles = corr_angles_array[i - 1].num_angles; memcpy(corr_angles_array[i].angles, corr_angles_array[i - 1].angles, aoa_corr_angles_config.locator_count * sizeof(aoa_angle_t)); memcpy(corr_angles_array[i].has_angle, corr_angles_array[i - 1].has_angle, aoa_corr_angles_config.locator_count * sizeof(bool)); } corr_angles_array[slot].num_angles = 0; memset(corr_angles_array[slot].has_angle, 0, aoa_corr_angles_config.locator_count); corr_angles_array[slot].sequence = angle->sequence; } memcpy(&corr_angles_array[slot].angles[locator_id], angle, sizeof(aoa_angle_t)); corr_angles_array[slot].has_angle[locator_id] = true; corr_angles_array[slot].num_angles++; *angle_slot = slot; return SL_STATUS_OK; }
[ "sl_status_t", "aoa_corr_angles_add_data", "(", "aoa_corr_angles_t", "*", "corr_angles_array", ",", "uint32_t", "locator_id", ",", "aoa_angle_t", "*", "angle", ",", "uint32_t", "*", "angle_slot", ")", "{", "uint32_t", "slot", "=", "0", ";", "aoa_corr_angles_remove_old_data", "(", "corr_angles_array", ",", "angle", "->", "sequence", ")", ";", "slot", "=", "aoa_corr_angles_get_slot_by_sequence", "(", "corr_angles_array", ",", "angle", "->", "sequence", ")", ";", "if", "(", "slot", ">", "aoa_corr_angles_config", ".", "sequence_id_slots", ")", "{", "return", "SL_STATUS_FAIL", ";", "}", "if", "(", "corr_angles_array", "[", "slot", "]", ".", "sequence", "!=", "angle", "->", "sequence", ")", "{", "for", "(", "int", "i", "=", "aoa_corr_angles_config", ".", "sequence_id_slots", "-", "1", ";", "i", ">", "slot", ";", "i", "--", ")", "{", "corr_angles_array", "[", "i", "]", ".", "sequence", "=", "corr_angles_array", "[", "i", "-", "1", "]", ".", "sequence", ";", "corr_angles_array", "[", "i", "]", ".", "num_angles", "=", "corr_angles_array", "[", "i", "-", "1", "]", ".", "num_angles", ";", "memcpy", "(", "corr_angles_array", "[", "i", "]", ".", "angles", ",", "corr_angles_array", "[", "i", "-", "1", "]", ".", "angles", ",", "aoa_corr_angles_config", ".", "locator_count", "*", "sizeof", "(", "aoa_angle_t", ")", ")", ";", "memcpy", "(", "corr_angles_array", "[", "i", "]", ".", "has_angle", ",", "corr_angles_array", "[", "i", "-", "1", "]", ".", "has_angle", ",", "aoa_corr_angles_config", ".", "locator_count", "*", "sizeof", "(", "bool", ")", ")", ";", "}", "corr_angles_array", "[", "slot", "]", ".", "num_angles", "=", "0", ";", "memset", "(", "corr_angles_array", "[", "slot", "]", ".", "has_angle", ",", "0", ",", "aoa_corr_angles_config", ".", "locator_count", ")", ";", "corr_angles_array", "[", "slot", "]", ".", "sequence", "=", "angle", "->", "sequence", ";", "}", "memcpy", "(", "&", "corr_angles_array", "[", "slot", "]", ".", "angles", "[", "locator_id", "]", ",", "angle", ",", "sizeof", "(", "aoa_angle_t", ")", ")", ";", "corr_angles_array", "[", "slot", "]", ".", "has_angle", "[", "locator_id", "]", "=", "true", ";", "corr_angles_array", "[", "slot", "]", ".", "num_angles", "++", ";", "*", "angle_slot", "=", "slot", ";", "return", "SL_STATUS_OK", ";", "}" ]
Adds data to the slot.
[ "Adds", "data", "to", "the", "slot", "." ]
[ "// Drop stored data that are considered too old\r", "// Find the correct correlated angle slot\r", "// Insert the slot if it is not present yet.\r" ]
[ { "param": "corr_angles_array", "type": "aoa_corr_angles_t" }, { "param": "locator_id", "type": "uint32_t" }, { "param": "angle", "type": "aoa_angle_t" }, { "param": "angle_slot", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "corr_angles_array", "type": "aoa_corr_angles_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "locator_id", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "angle", "type": "aoa_angle_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "angle_slot", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
279f7d3c93b46d5534f686a5108fad2b6e2e5d99
SiliconLabs/Gecko_SDK
app/bluetooth/common_host/aoa_corr_angles/aoa_corr_angles.c
[ "Zlib" ]
C
aoa_corr_angles_cleanup
sl_status_t
sl_status_t aoa_corr_angles_cleanup(aoa_corr_angles_t *corr_angles_array, uint32_t cleanup_start_idx) { if (cleanup_start_idx > aoa_corr_angles_config.sequence_id_slots) { return SL_STATUS_FAIL; } for (; cleanup_start_idx < aoa_corr_angles_config.sequence_id_slots; cleanup_start_idx++) { corr_angles_array[cleanup_start_idx].num_angles = 0; corr_angles_array[cleanup_start_idx].sequence = -1; memset(corr_angles_array[cleanup_start_idx].has_angle, 0, aoa_corr_angles_config.locator_count); } return SL_STATUS_OK; }
/**************************************************************************/ /** * Cleans up already processed data. *****************************************************************************/
Cleans up already processed data.
[ "Cleans", "up", "already", "processed", "data", "." ]
sl_status_t aoa_corr_angles_cleanup(aoa_corr_angles_t *corr_angles_array, uint32_t cleanup_start_idx) { if (cleanup_start_idx > aoa_corr_angles_config.sequence_id_slots) { return SL_STATUS_FAIL; } for (; cleanup_start_idx < aoa_corr_angles_config.sequence_id_slots; cleanup_start_idx++) { corr_angles_array[cleanup_start_idx].num_angles = 0; corr_angles_array[cleanup_start_idx].sequence = -1; memset(corr_angles_array[cleanup_start_idx].has_angle, 0, aoa_corr_angles_config.locator_count); } return SL_STATUS_OK; }
[ "sl_status_t", "aoa_corr_angles_cleanup", "(", "aoa_corr_angles_t", "*", "corr_angles_array", ",", "uint32_t", "cleanup_start_idx", ")", "{", "if", "(", "cleanup_start_idx", ">", "aoa_corr_angles_config", ".", "sequence_id_slots", ")", "{", "return", "SL_STATUS_FAIL", ";", "}", "for", "(", ";", "cleanup_start_idx", "<", "aoa_corr_angles_config", ".", "sequence_id_slots", ";", "cleanup_start_idx", "++", ")", "{", "corr_angles_array", "[", "cleanup_start_idx", "]", ".", "num_angles", "=", "0", ";", "corr_angles_array", "[", "cleanup_start_idx", "]", ".", "sequence", "=", "-1", ";", "memset", "(", "corr_angles_array", "[", "cleanup_start_idx", "]", ".", "has_angle", ",", "0", ",", "aoa_corr_angles_config", ".", "locator_count", ")", ";", "}", "return", "SL_STATUS_OK", ";", "}" ]
Cleans up already processed data.
[ "Cleans", "up", "already", "processed", "data", "." ]
[]
[ { "param": "corr_angles_array", "type": "aoa_corr_angles_t" }, { "param": "cleanup_start_idx", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "corr_angles_array", "type": "aoa_corr_angles_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cleanup_start_idx", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
279f7d3c93b46d5534f686a5108fad2b6e2e5d99
SiliconLabs/Gecko_SDK
app/bluetooth/common_host/aoa_corr_angles/aoa_corr_angles.c
[ "Zlib" ]
C
aoa_corr_angles_destroy
void
void aoa_corr_angles_destroy(void) { aoa_corr_angles_node_t *current; aoa_corr_angles_node_t *next; for (current = head_corr_angles; current != NULL; current = next) { next = current->next; free(current->corr_angles->angles); free(current->corr_angles->has_angle); free(current->corr_angles); free(current); } head_corr_angles = NULL; }
/**************************************************************************/ /** * Destroys the database and all of its entries. *****************************************************************************/
Destroys the database and all of its entries.
[ "Destroys", "the", "database", "and", "all", "of", "its", "entries", "." ]
void aoa_corr_angles_destroy(void) { aoa_corr_angles_node_t *current; aoa_corr_angles_node_t *next; for (current = head_corr_angles; current != NULL; current = next) { next = current->next; free(current->corr_angles->angles); free(current->corr_angles->has_angle); free(current->corr_angles); free(current); } head_corr_angles = NULL; }
[ "void", "aoa_corr_angles_destroy", "(", "void", ")", "{", "aoa_corr_angles_node_t", "*", "current", ";", "aoa_corr_angles_node_t", "*", "next", ";", "for", "(", "current", "=", "head_corr_angles", ";", "current", "!=", "NULL", ";", "current", "=", "next", ")", "{", "next", "=", "current", "->", "next", ";", "free", "(", "current", "->", "corr_angles", "->", "angles", ")", ";", "free", "(", "current", "->", "corr_angles", "->", "has_angle", ")", ";", "free", "(", "current", "->", "corr_angles", ")", ";", "free", "(", "current", ")", ";", "}", "head_corr_angles", "=", "NULL", ";", "}" ]
Destroys the database and all of its entries.
[ "Destroys", "the", "database", "and", "all", "of", "its", "entries", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
279f7d3c93b46d5534f686a5108fad2b6e2e5d99
SiliconLabs/Gecko_SDK
app/bluetooth/common_host/aoa_corr_angles/aoa_corr_angles.c
[ "Zlib" ]
C
aoa_corr_angles_get_slot_by_sequence
uint32_t
static uint32_t aoa_corr_angles_get_slot_by_sequence(aoa_corr_angles_t *corr_angles_array, int32_t sequence) { for (uint32_t i = 0; i < aoa_corr_angles_config.sequence_id_slots; i++) { if (sequence == corr_angles_array[i].sequence) { return i; } } return 0; }
/**************************************************************************/ /** * Returns an angle slot by the sequence number. *****************************************************************************/
Returns an angle slot by the sequence number.
[ "Returns", "an", "angle", "slot", "by", "the", "sequence", "number", "." ]
static uint32_t aoa_corr_angles_get_slot_by_sequence(aoa_corr_angles_t *corr_angles_array, int32_t sequence) { for (uint32_t i = 0; i < aoa_corr_angles_config.sequence_id_slots; i++) { if (sequence == corr_angles_array[i].sequence) { return i; } } return 0; }
[ "static", "uint32_t", "aoa_corr_angles_get_slot_by_sequence", "(", "aoa_corr_angles_t", "*", "corr_angles_array", ",", "int32_t", "sequence", ")", "{", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "aoa_corr_angles_config", ".", "sequence_id_slots", ";", "i", "++", ")", "{", "if", "(", "sequence", "==", "corr_angles_array", "[", "i", "]", ".", "sequence", ")", "{", "return", "i", ";", "}", "}", "return", "0", ";", "}" ]
Returns an angle slot by the sequence number.
[ "Returns", "an", "angle", "slot", "by", "the", "sequence", "number", "." ]
[]
[ { "param": "corr_angles_array", "type": "aoa_corr_angles_t" }, { "param": "sequence", "type": "int32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "corr_angles_array", "type": "aoa_corr_angles_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sequence", "type": "int32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
ApplicationInit
ZW_APPLICATION_STATUS
ZW_APPLICATION_STATUS ApplicationInit(EResetReason_t eResetReason) { // NULL - We dont have the Application Task handle yet AppTimerInit(EAPPLICATIONEVENT_TIMER, NULL); /* hardware initialization */ Board_Init(); BRD420xBoardInit(RadioConfig.eRegion); #ifdef DEBUGPRINT #if BUILDING_WITH_UC DebugPrintConfig(m_aDebugPrintBuffer, sizeof(m_aDebugPrintBuffer), DebugPrinter); #else static uint8_t m_aDebugPrintBuffer[96]; ZAF_UART0_enable(115200, true, false); DebugPrintConfig(m_aDebugPrintBuffer, sizeof(m_aDebugPrintBuffer), ZAF_UART0_tx_send); #endif // BUILDING_WITH_UC #endif // DEBUGPRINT /* Init state machine*/ currentState = STATE_APP_STARTUP; uint8_t versionMajor = ZAF_GetAppVersionMajor(); uint8_t versionMinor = ZAF_GetAppVersionMinor(); uint8_t versionPatchLevel = ZAF_GetAppVersionPatchLevel(); DPRINT("\n\n-----------------------------\n"); DPRINT("Z-Wave Sample App: Sensor PIR\n"); DPRINTF("\r\nSDK: %d.%d.%d ZAF: %d.%d.%d.%d [Freq: %d]\n", SDK_VERSION_MAJOR, SDK_VERSION_MINOR, SDK_VERSION_PATCH, versionMajor, versionMinor, versionPatchLevel, ZAF_BUILD_NO, RadioConfig.eRegion); DPRINT("-----------------------------\n"); DPRINTF("%s: Send battery report\n", Board_GetButtonLabel(BATTERY_REPORT_BTN)); DPRINTF("%s: Toggle learn mode\n", Board_GetButtonLabel(APP_BUTTON_LEARN_RESET)); DPRINT(" Hold 5 sec: Reset\n"); DPRINTF("%s: Activate PIR event\n", Board_GetButtonLabel(PIR_EVENT_BTN)); DPRINT(" (leave deactivated to allow going to sleep)\n"); DPRINTF("%s: Learn mode + identify\n", Board_GetLedLabel(APP_LED_INDICATOR)); DPRINT("-----------------------------\n\n"); DPRINTF("\r\nApplicationInit eResetReason = %d", eResetReason); DPRINTF("\r\nBoard_GetGpioEm4Flags() = 0b%08x", Board_GetGpioEm4Flags()); if (eResetReason == ERESETREASON_EM4_WUT || eResetReason == ERESETREASON_EM4_EXT_INT) { #ifdef DEBUGPRINT Board_DebugPrintEm4WakeupFlags(Board_GetGpioEm4Flags()); #endif } CC_ZWavePlusInfo_Init(&CCZWavePlusInfo); CC_Version_SetApplicationVersionInfo(versionMajor, versionMinor, versionPatchLevel, ZAF_BUILD_NO); /************************************************************************************* * CREATE USER TASKS - ZW_ApplicationRegisterTask() and ZW_UserTask_CreateTask() ************************************************************************************* * Register the main APP task function. * * ATTENTION: This function is the only task that can call ZAF aPI functions!!! * Failure to follow guidelines will result in undefined behavior. * * This function further is the only way to register Event Notification Bit Numbers * for associating to given event handlers. * * ZW_UserTask_CreateTask() can be used to create additional tasks. * @see SensorPIR_MultiThread example for more info. *************************************************************************************/ bool bWasTaskCreated = ZW_ApplicationRegisterTask( ApplicationTask, EAPPLICATIONEVENT_ZWRX, EAPPLICATIONEVENT_ZWCOMMANDSTATUS, &ProtocolConfig ); ASSERT(bWasTaskCreated); /***************************************************** * This is an multi-threaded application example! * * This next section creates the additional threads * by using ZW_UserTask.h API. * * If a multi-threaded application is not needed, * this next section can be removed by setting the * macro CREATE_USER_TASK to zero. ****************************************************/ #if CREATE_USER_TASK // Create the buffer bundle! ZW_UserTask_Buffer_t mainAppTaskBuffer; mainAppTaskBuffer.taskBuffer = &DataAcquisitionTaskBuffer; mainAppTaskBuffer.stackBuffer = DataAcquisitionStackBuffer; mainAppTaskBuffer.stackBufferLength = TASK_STACK_SIZE_DATA_ACQUISITION; // Create the task setting-structure! ZW_UserTask_t task; task.pTaskFunc = (TaskFunction_t)SensorPIR_DataAcquisitionTask; task.pTaskName = "DataAcqu"; task.pUserTaskParam = NULL; // We pass nothing here, as the EventHelper is already initialized and can be used for task IPC! task.priority = USERTASK_PRIORITY_HIGHEST; // The difficult example is with the HIGHEST priority. task.taskBuffer = &mainAppTaskBuffer; // Create the task! ZW_UserTask_CreateTask(&task, &m_xTaskHandleDataAcquisition); #endif //CREATE_USER_TASK return(APPLICATION_RUNNING); }
/** * @brief See description for function prototype in ZW_basis_api.h. */
@brief See description for function prototype in ZW_basis_api.h.
[ "@brief", "See", "description", "for", "function", "prototype", "in", "ZW_basis_api", ".", "h", "." ]
ZW_APPLICATION_STATUS ApplicationInit(EResetReason_t eResetReason) { AppTimerInit(EAPPLICATIONEVENT_TIMER, NULL); Board_Init(); BRD420xBoardInit(RadioConfig.eRegion); #ifdef DEBUGPRINT #if BUILDING_WITH_UC DebugPrintConfig(m_aDebugPrintBuffer, sizeof(m_aDebugPrintBuffer), DebugPrinter); #else static uint8_t m_aDebugPrintBuffer[96]; ZAF_UART0_enable(115200, true, false); DebugPrintConfig(m_aDebugPrintBuffer, sizeof(m_aDebugPrintBuffer), ZAF_UART0_tx_send); #endif #endif currentState = STATE_APP_STARTUP; uint8_t versionMajor = ZAF_GetAppVersionMajor(); uint8_t versionMinor = ZAF_GetAppVersionMinor(); uint8_t versionPatchLevel = ZAF_GetAppVersionPatchLevel(); DPRINT("\n\n-----------------------------\n"); DPRINT("Z-Wave Sample App: Sensor PIR\n"); DPRINTF("\r\nSDK: %d.%d.%d ZAF: %d.%d.%d.%d [Freq: %d]\n", SDK_VERSION_MAJOR, SDK_VERSION_MINOR, SDK_VERSION_PATCH, versionMajor, versionMinor, versionPatchLevel, ZAF_BUILD_NO, RadioConfig.eRegion); DPRINT("-----------------------------\n"); DPRINTF("%s: Send battery report\n", Board_GetButtonLabel(BATTERY_REPORT_BTN)); DPRINTF("%s: Toggle learn mode\n", Board_GetButtonLabel(APP_BUTTON_LEARN_RESET)); DPRINT(" Hold 5 sec: Reset\n"); DPRINTF("%s: Activate PIR event\n", Board_GetButtonLabel(PIR_EVENT_BTN)); DPRINT(" (leave deactivated to allow going to sleep)\n"); DPRINTF("%s: Learn mode + identify\n", Board_GetLedLabel(APP_LED_INDICATOR)); DPRINT("-----------------------------\n\n"); DPRINTF("\r\nApplicationInit eResetReason = %d", eResetReason); DPRINTF("\r\nBoard_GetGpioEm4Flags() = 0b%08x", Board_GetGpioEm4Flags()); if (eResetReason == ERESETREASON_EM4_WUT || eResetReason == ERESETREASON_EM4_EXT_INT) { #ifdef DEBUGPRINT Board_DebugPrintEm4WakeupFlags(Board_GetGpioEm4Flags()); #endif } CC_ZWavePlusInfo_Init(&CCZWavePlusInfo); CC_Version_SetApplicationVersionInfo(versionMajor, versionMinor, versionPatchLevel, ZAF_BUILD_NO); bool bWasTaskCreated = ZW_ApplicationRegisterTask( ApplicationTask, EAPPLICATIONEVENT_ZWRX, EAPPLICATIONEVENT_ZWCOMMANDSTATUS, &ProtocolConfig ); ASSERT(bWasTaskCreated); #if CREATE_USER_TASK ZW_UserTask_Buffer_t mainAppTaskBuffer; mainAppTaskBuffer.taskBuffer = &DataAcquisitionTaskBuffer; mainAppTaskBuffer.stackBuffer = DataAcquisitionStackBuffer; mainAppTaskBuffer.stackBufferLength = TASK_STACK_SIZE_DATA_ACQUISITION; ZW_UserTask_t task; task.pTaskFunc = (TaskFunction_t)SensorPIR_DataAcquisitionTask; task.pTaskName = "DataAcqu"; task.pUserTaskParam = NULL; task.priority = USERTASK_PRIORITY_HIGHEST; task.taskBuffer = &mainAppTaskBuffer; ZW_UserTask_CreateTask(&task, &m_xTaskHandleDataAcquisition); #endif return(APPLICATION_RUNNING); }
[ "ZW_APPLICATION_STATUS", "ApplicationInit", "(", "EResetReason_t", "eResetReason", ")", "{", "AppTimerInit", "(", "EAPPLICATIONEVENT_TIMER", ",", "NULL", ")", ";", "Board_Init", "(", ")", ";", "BRD420xBoardInit", "(", "RadioConfig", ".", "eRegion", ")", ";", "#ifdef", "DEBUGPRINT", "#if", "BUILDING_WITH_UC", "\n", "DebugPrintConfig", "(", "m_aDebugPrintBuffer", ",", "sizeof", "(", "m_aDebugPrintBuffer", ")", ",", "DebugPrinter", ")", ";", "#else", "static", "uint8_t", "m_aDebugPrintBuffer", "[", "96", "]", ";", "ZAF_UART0_enable", "(", "115200", ",", "true", ",", "false", ")", ";", "DebugPrintConfig", "(", "m_aDebugPrintBuffer", ",", "sizeof", "(", "m_aDebugPrintBuffer", ")", ",", "ZAF_UART0_tx_send", ")", ";", "#endif", "#endif", "currentState", "=", "STATE_APP_STARTUP", ";", "uint8_t", "versionMajor", "=", "ZAF_GetAppVersionMajor", "(", ")", ";", "uint8_t", "versionMinor", "=", "ZAF_GetAppVersionMinor", "(", ")", ";", "uint8_t", "versionPatchLevel", "=", "ZAF_GetAppVersionPatchLevel", "(", ")", ";", "DPRINT", "(", "\"", "\\n", "\\n", "\\n", "\"", ")", ";", "DPRINT", "(", "\"", "\\n", "\"", ")", ";", "DPRINTF", "(", "\"", "\\r", "\\n", "\\n", "\"", ",", "SDK_VERSION_MAJOR", ",", "SDK_VERSION_MINOR", ",", "SDK_VERSION_PATCH", ",", "versionMajor", ",", "versionMinor", ",", "versionPatchLevel", ",", "ZAF_BUILD_NO", ",", "RadioConfig", ".", "eRegion", ")", ";", "DPRINT", "(", "\"", "\\n", "\"", ")", ";", "DPRINTF", "(", "\"", "\\n", "\"", ",", "Board_GetButtonLabel", "(", "BATTERY_REPORT_BTN", ")", ")", ";", "DPRINTF", "(", "\"", "\\n", "\"", ",", "Board_GetButtonLabel", "(", "APP_BUTTON_LEARN_RESET", ")", ")", ";", "DPRINT", "(", "\"", "\\n", "\"", ")", ";", "DPRINTF", "(", "\"", "\\n", "\"", ",", "Board_GetButtonLabel", "(", "PIR_EVENT_BTN", ")", ")", ";", "DPRINT", "(", "\"", "\\n", "\"", ")", ";", "DPRINTF", "(", "\"", "\\n", "\"", ",", "Board_GetLedLabel", "(", "APP_LED_INDICATOR", ")", ")", ";", "DPRINT", "(", "\"", "\\n", "\\n", "\"", ")", ";", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "eResetReason", ")", ";", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "Board_GetGpioEm4Flags", "(", ")", ")", ";", "if", "(", "eResetReason", "==", "ERESETREASON_EM4_WUT", "||", "eResetReason", "==", "ERESETREASON_EM4_EXT_INT", ")", "{", "#ifdef", "DEBUGPRINT", "Board_DebugPrintEm4WakeupFlags", "(", "Board_GetGpioEm4Flags", "(", ")", ")", ";", "#endif", "}", "CC_ZWavePlusInfo_Init", "(", "&", "CCZWavePlusInfo", ")", ";", "CC_Version_SetApplicationVersionInfo", "(", "versionMajor", ",", "versionMinor", ",", "versionPatchLevel", ",", "ZAF_BUILD_NO", ")", ";", "bool", "bWasTaskCreated", "=", "ZW_ApplicationRegisterTask", "(", "ApplicationTask", ",", "EAPPLICATIONEVENT_ZWRX", ",", "EAPPLICATIONEVENT_ZWCOMMANDSTATUS", ",", "&", "ProtocolConfig", ")", ";", "ASSERT", "(", "bWasTaskCreated", ")", ";", "#if", "CREATE_USER_TASK", "\n", "ZW_UserTask_Buffer_t", "mainAppTaskBuffer", ";", "mainAppTaskBuffer", ".", "taskBuffer", "=", "&", "DataAcquisitionTaskBuffer", ";", "mainAppTaskBuffer", ".", "stackBuffer", "=", "DataAcquisitionStackBuffer", ";", "mainAppTaskBuffer", ".", "stackBufferLength", "=", "TASK_STACK_SIZE_DATA_ACQUISITION", ";", "ZW_UserTask_t", "task", ";", "task", ".", "pTaskFunc", "=", "(", "TaskFunction_t", ")", "SensorPIR_DataAcquisitionTask", ";", "task", ".", "pTaskName", "=", "\"", "\"", ";", "task", ".", "pUserTaskParam", "=", "NULL", ";", "task", ".", "priority", "=", "USERTASK_PRIORITY_HIGHEST", ";", "task", ".", "taskBuffer", "=", "&", "mainAppTaskBuffer", ";", "ZW_UserTask_CreateTask", "(", "&", "task", ",", "&", "m_xTaskHandleDataAcquisition", ")", ";", "#endif", "return", "(", "APPLICATION_RUNNING", ")", ";", "}" ]
@brief See description for function prototype in ZW_basis_api.h.
[ "@brief", "See", "description", "for", "function", "prototype", "in", "ZW_basis_api", ".", "h", "." ]
[ "// NULL - We dont have the Application Task handle yet\r", "/* hardware initialization */", "// BUILDING_WITH_UC\r", "// DEBUGPRINT\r", "/* Init state machine*/", "/*************************************************************************************\r\n * CREATE USER TASKS - ZW_ApplicationRegisterTask() and ZW_UserTask_CreateTask()\r\n *************************************************************************************\r\n * Register the main APP task function.\r\n *\r\n * ATTENTION: This function is the only task that can call ZAF aPI functions!!!\r\n * Failure to follow guidelines will result in undefined behavior.\r\n *\r\n * This function further is the only way to register Event Notification Bit Numbers\r\n * for associating to given event handlers.\r\n *\r\n * ZW_UserTask_CreateTask() can be used to create additional tasks.\r\n * @see SensorPIR_MultiThread example for more info.\r\n *************************************************************************************/", "/*****************************************************\r\n * This is an multi-threaded application example!\r\n *\r\n * This next section creates the additional threads\r\n * by using ZW_UserTask.h API.\r\n *\r\n * If a multi-threaded application is not needed,\r\n * this next section can be removed by setting the\r\n * macro CREATE_USER_TASK to zero.\r\n ****************************************************/", "// Create the buffer bundle!\r", "// Create the task setting-structure!\r", "// We pass nothing here, as the EventHelper is already initialized and can be used for task IPC!\r", "// The difficult example is with the HIGHEST priority.\r", "// Create the task!\r", "//CREATE_USER_TASK\r" ]
[ { "param": "eResetReason", "type": "EResetReason_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "eResetReason", "type": "EResetReason_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
ApplicationTask
void
static void ApplicationTask(SApplicationHandles* pAppHandles) { DPRINT("\r\nSensorPIR Main App/Task started! \n"); // Init DPRINT("Enabling watchdog\n"); WDOGn_Enable(DEFAULT_WDOG, true); g_AppTaskHandle = xTaskGetCurrentTaskHandle(); g_pAppHandles = pAppHandles; ZAF_Init(g_AppTaskHandle, pAppHandles, &ProtocolConfig, CC_WakeUp_stayAwakeIfActive); AppTimerSetReceiverTask(g_AppTaskHandle); /* Make sure to call AppTimerEm4PersistentRegister() _after_ ZAF_Init(). * It will access the app handles */ AppTimerEm4PersistentRegister(&EventJobsTimer, false, ZCB_EventJobsTimer); // register for event jobs timeout event // Initialize CC Wake Up CC_WakeUp_setConfiguration(WAKEUP_PAR_DEFAULT_SLEEP_TIME, DEFAULT_SLEEP_TIME); CC_WakeUp_setConfiguration(WAKEUP_PAR_MAX_SLEEP_TIME, MAX_SLEEP_TIME); CC_WakeUp_setConfiguration(WAKEUP_PAR_MIN_SLEEP_TIME, MIN_SLEEP_TIME); CC_WakeUp_setConfiguration(WAKEUP_PAR_SLEEP_STEP, STEP_SLEEP_TIME); ZAF_PM_Register(&m_RadioPowerLock, PM_TYPE_RADIO); /* * Create an initialize some of the modules regarding queue and event handling and passing. * The UserTask that is dependent on modules initialized here, must be able to detect and wait * before using these modules. Specially if it has higher priority than this task! * * Currently, the UserTask is checking whether zaf_event_helper.h module is ready. * This module is the last to be initialized! */ EventQueueInit(); // Generate event that says the APP is initialized ZAF_EventHelperEventEnqueue(EVENT_APP_INIT); //Enables events on test board Board_EnableButton(APP_BUTTON_LEARN_RESET); Board_EnableButton(BATTERY_REPORT_BTN); Board_EnableButton(PIR_EVENT_BTN); Board_IndicatorInit(APP_LED_INDICATOR); Board_IndicateStatus(BOARD_STATUS_IDLE); CommandClassSupervisionInit( CC_SUPERVISION_STATUS_UPDATES_NOT_SUPPORTED, NULL, NULL); EventDistributorConfig( &g_EventDistributor, sizeof_array(g_aEventHandlerTable), g_aEventHandlerTable, NULL ); DPRINTF("\r\nIsWakeupCausedByRtccTimeout=%s", (IsWakeupCausedByRtccTimeout()) ? "true" : "false"); DPRINTF("\r\nCompletedSleepDurationMs =%u", GetCompletedSleepDurationMs()); // Wait for and process events DPRINT("\r\nSensorPIR Event processor Started\n"); uint32_t iMaxTaskSleep = 0xFFFFFFFF; // Block forever for (;;) { EventDistributorDistribute(&g_EventDistributor, iMaxTaskSleep, 0); } }
/** * A pointer to this function is passed to ZW_ApplicationRegisterTask() making it the FreeRTOS * application task. */
A pointer to this function is passed to ZW_ApplicationRegisterTask() making it the FreeRTOS application task.
[ "A", "pointer", "to", "this", "function", "is", "passed", "to", "ZW_ApplicationRegisterTask", "()", "making", "it", "the", "FreeRTOS", "application", "task", "." ]
static void ApplicationTask(SApplicationHandles* pAppHandles) { DPRINT("\r\nSensorPIR Main App/Task started! \n"); DPRINT("Enabling watchdog\n"); WDOGn_Enable(DEFAULT_WDOG, true); g_AppTaskHandle = xTaskGetCurrentTaskHandle(); g_pAppHandles = pAppHandles; ZAF_Init(g_AppTaskHandle, pAppHandles, &ProtocolConfig, CC_WakeUp_stayAwakeIfActive); AppTimerSetReceiverTask(g_AppTaskHandle); AppTimerEm4PersistentRegister(&EventJobsTimer, false, ZCB_EventJobsTimer); CC_WakeUp_setConfiguration(WAKEUP_PAR_DEFAULT_SLEEP_TIME, DEFAULT_SLEEP_TIME); CC_WakeUp_setConfiguration(WAKEUP_PAR_MAX_SLEEP_TIME, MAX_SLEEP_TIME); CC_WakeUp_setConfiguration(WAKEUP_PAR_MIN_SLEEP_TIME, MIN_SLEEP_TIME); CC_WakeUp_setConfiguration(WAKEUP_PAR_SLEEP_STEP, STEP_SLEEP_TIME); ZAF_PM_Register(&m_RadioPowerLock, PM_TYPE_RADIO); EventQueueInit(); ZAF_EventHelperEventEnqueue(EVENT_APP_INIT); Board_EnableButton(APP_BUTTON_LEARN_RESET); Board_EnableButton(BATTERY_REPORT_BTN); Board_EnableButton(PIR_EVENT_BTN); Board_IndicatorInit(APP_LED_INDICATOR); Board_IndicateStatus(BOARD_STATUS_IDLE); CommandClassSupervisionInit( CC_SUPERVISION_STATUS_UPDATES_NOT_SUPPORTED, NULL, NULL); EventDistributorConfig( &g_EventDistributor, sizeof_array(g_aEventHandlerTable), g_aEventHandlerTable, NULL ); DPRINTF("\r\nIsWakeupCausedByRtccTimeout=%s", (IsWakeupCausedByRtccTimeout()) ? "true" : "false"); DPRINTF("\r\nCompletedSleepDurationMs =%u", GetCompletedSleepDurationMs()); DPRINT("\r\nSensorPIR Event processor Started\n"); uint32_t iMaxTaskSleep = 0xFFFFFFFF; for (;;) { EventDistributorDistribute(&g_EventDistributor, iMaxTaskSleep, 0); } }
[ "static", "void", "ApplicationTask", "(", "SApplicationHandles", "*", "pAppHandles", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\\n", "\"", ")", ";", "DPRINT", "(", "\"", "\\n", "\"", ")", ";", "WDOGn_Enable", "(", "DEFAULT_WDOG", ",", "true", ")", ";", "g_AppTaskHandle", "=", "xTaskGetCurrentTaskHandle", "(", ")", ";", "g_pAppHandles", "=", "pAppHandles", ";", "ZAF_Init", "(", "g_AppTaskHandle", ",", "pAppHandles", ",", "&", "ProtocolConfig", ",", "CC_WakeUp_stayAwakeIfActive", ")", ";", "AppTimerSetReceiverTask", "(", "g_AppTaskHandle", ")", ";", "AppTimerEm4PersistentRegister", "(", "&", "EventJobsTimer", ",", "false", ",", "ZCB_EventJobsTimer", ")", ";", "CC_WakeUp_setConfiguration", "(", "WAKEUP_PAR_DEFAULT_SLEEP_TIME", ",", "DEFAULT_SLEEP_TIME", ")", ";", "CC_WakeUp_setConfiguration", "(", "WAKEUP_PAR_MAX_SLEEP_TIME", ",", "MAX_SLEEP_TIME", ")", ";", "CC_WakeUp_setConfiguration", "(", "WAKEUP_PAR_MIN_SLEEP_TIME", ",", "MIN_SLEEP_TIME", ")", ";", "CC_WakeUp_setConfiguration", "(", "WAKEUP_PAR_SLEEP_STEP", ",", "STEP_SLEEP_TIME", ")", ";", "ZAF_PM_Register", "(", "&", "m_RadioPowerLock", ",", "PM_TYPE_RADIO", ")", ";", "EventQueueInit", "(", ")", ";", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_INIT", ")", ";", "Board_EnableButton", "(", "APP_BUTTON_LEARN_RESET", ")", ";", "Board_EnableButton", "(", "BATTERY_REPORT_BTN", ")", ";", "Board_EnableButton", "(", "PIR_EVENT_BTN", ")", ";", "Board_IndicatorInit", "(", "APP_LED_INDICATOR", ")", ";", "Board_IndicateStatus", "(", "BOARD_STATUS_IDLE", ")", ";", "CommandClassSupervisionInit", "(", "CC_SUPERVISION_STATUS_UPDATES_NOT_SUPPORTED", ",", "NULL", ",", "NULL", ")", ";", "EventDistributorConfig", "(", "&", "g_EventDistributor", ",", "sizeof_array", "(", "g_aEventHandlerTable", ")", ",", "g_aEventHandlerTable", ",", "NULL", ")", ";", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "(", "IsWakeupCausedByRtccTimeout", "(", ")", ")", "?", "\"", "\"", ":", "\"", "\"", ")", ";", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "GetCompletedSleepDurationMs", "(", ")", ")", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\\n", "\"", ")", ";", "uint32_t", "iMaxTaskSleep", "=", "0xFFFFFFFF", ";", "for", "(", ";", ";", ")", "{", "EventDistributorDistribute", "(", "&", "g_EventDistributor", ",", "iMaxTaskSleep", ",", "0", ")", ";", "}", "}" ]
A pointer to this function is passed to ZW_ApplicationRegisterTask() making it the FreeRTOS application task.
[ "A", "pointer", "to", "this", "function", "is", "passed", "to", "ZW_ApplicationRegisterTask", "()", "making", "it", "the", "FreeRTOS", "application", "task", "." ]
[ "// Init\r", "/* Make sure to call AppTimerEm4PersistentRegister() _after_ ZAF_Init().\r\n * It will access the app handles */", "// register for event jobs timeout event\r", "// Initialize CC Wake Up\r", "/*\r\n * Create an initialize some of the modules regarding queue and event handling and passing.\r\n * The UserTask that is dependent on modules initialized here, must be able to detect and wait\r\n * before using these modules. Specially if it has higher priority than this task!\r\n *\r\n * Currently, the UserTask is checking whether zaf_event_helper.h module is ready.\r\n * This module is the last to be initialized!\r\n */", "// Generate event that says the APP is initialized\r", "//Enables events on test board\r", "// Wait for and process events\r", "// Block forever\r" ]
[ { "param": "pAppHandles", "type": "SApplicationHandles" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pAppHandles", "type": "SApplicationHandles", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
AppStateManager
void
void AppStateManager(EVENT_APP event) { DPRINTF("AppStateManager St: %d, Ev: 0x%02x\r\n", currentState, event); /* * Here we handle events that are not evaluated in the context of the app state. */ notAppStateDependentActivity(event); switch(currentState) { case STATE_APP_STARTUP: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); } if (EVENT_APP_INIT == event) { /* * This approach makes it possible to do less initialization before the scheduler starts. * Hence, this was made to reduce the boot-up time. */ doRemainingInitialization(); break; } ChangeState(STATE_APP_IDLE); break; case STATE_APP_IDLE: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); LoadConfiguration(); } if (EVENT_APP_SMARTSTART_IN_PROGRESS == event) { ChangeState(STATE_APP_LEARN_MODE); } if ((BTN_EVENT_SHORT_PRESS(APP_BUTTON_LEARN_RESET) == (BUTTON_EVENT)event) || (EVENT_SYSTEM_LEARNMODE_START == (EVENT_SYSTEM)event)) { if (EINCLUSIONSTATE_EXCLUDED != g_pAppHandles->pNetworkInfo->eInclusionState){ DPRINT("\r\nLEARN_MODE_EXCLUSION"); ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_EXCLUSION_NWE); } else{ DPRINT("\r\nLEARN_MODE_INCLUSION"); ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_INCLUSION); } Board_IndicateStatus(BOARD_STATUS_LEARNMODE_ACTIVE); ChangeState(STATE_APP_LEARN_MODE); } // Handle received PIR event if (PIR_EVENT_TRANSITION_TO_ACTIVE(event)) { ZAF_PM_StayAwake(&m_RadioPowerLock, 0); DPRINT("\r\n"); DPRINT("\r\n *!*!**!*!**!*!**!*!**!*!**!*!**!*!**!*!*"); DPRINT("\r\n *!*!* PIR EVENT ACTIVE *!*!*"); DPRINT("\r\n *!*!**!*!**!*!**!*!**!*!**!*!**!*!**!*!*"); DPRINT("\r\n"); ChangeState(STATE_APP_TRANSMIT_DATA); if (false == ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB)) { DPRINT("\r\n** EVENT_APP_NEXT_EVENT_JOB fail\r\n"); } /*Add event's on job-queue*/ ZAF_JobHelperJobEnqueue(EVENT_APP_BASIC_START_JOB); ZAF_JobHelperJobEnqueue(EVENT_APP_NOTIFICATION_START_JOB); ZAF_JobHelperJobEnqueue(EVENT_APP_START_TIMER_EVENTJOB_STOP); } if (BTN_EVENT_SHORT_PRESS(BATTERY_REPORT_BTN) == (BUTTON_EVENT)event) { /* BATTERY REPORT EVENT received. Send a battery level report */ DPRINT("\r\nBattery Level report transmit (keypress trig)\r\n"); ChangeState(STATE_APP_TRANSMIT_DATA); if (false == ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB)) { DPRINT("\r\n** EVENT_APP_NEXT_EVENT_JOB fail\r\n"); } /*Add event's on job-queue*/ ZAF_JobHelperJobEnqueue(EVENT_APP_SEND_BATTERY_LEVEL_REPORT); } break; case STATE_APP_LEARN_MODE: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); LoadConfiguration(); } if ((BTN_EVENT_SHORT_PRESS(APP_BUTTON_LEARN_RESET) == (BUTTON_EVENT)event) || (EVENT_SYSTEM_LEARNMODE_STOP == (EVENT_SYSTEM)event)) { ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_DISABLE); //Go back to smart start if the node was never included. //Protocol will not commence SmartStart if the node is already included in the network. ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_INCLUSION_SMARTSTART); Board_IndicateStatus(BOARD_STATUS_IDLE); ChangeState(STATE_APP_IDLE); /* If we are in a network and the Identify LED state was changed to idle due to learn mode, report it to lifeline */ CC_Indicator_RefreshIndicatorProperties(); ZAF_TSE_Trigger(CC_Indicator_report_stx, (void *)&ZAF_TSE_localActuationIdentifyData, true); } if (EVENT_SYSTEM_LEARNMODE_FINISHED == (EVENT_SYSTEM)event) { //Make sure that the application stays awake for 10 s after learn mode finished //to wait for more messages from the controller CC_WakeUp_stayAwake10s(); /* Also tell application to automatically extend the stay awake period by 10 * seconds on message activities - even though we did not get here by a proper * wakeup from EM4 */ CC_WakeUp_AutoStayAwakeAfterInclusion(); //Go back to smart start if the node was excluded. //Protocol will not commence SmartStart if the node is already included in the network. ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_INCLUSION_SMARTSTART); Board_IndicateStatus(BOARD_STATUS_IDLE); ChangeState(STATE_APP_IDLE); /* If we are in a network and the Identify LED state was changed to idle due to learn mode, report it to lifeline */ CC_Indicator_RefreshIndicatorProperties(); ZAF_TSE_Trigger(CC_Indicator_report_stx, (void *)&ZAF_TSE_localActuationIdentifyData, true); // Start the wakeup timer if the learn mode operation finished in Included state if (EINCLUSIONSTATE_EXCLUDED != g_pAppHandles->pNetworkInfo->eInclusionState) { CC_WakeUp_startWakeUpNotificationTimer(); } } break; case STATE_APP_RESET: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); /* Soft reset */ Board_ResetHandler(); } break; case STATE_APP_POWERDOWN: /* Device is powering down.. wait!*/ break; case STATE_APP_TRANSMIT_DATA: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); LoadConfiguration(); } if (EVENT_APP_NEXT_EVENT_JOB == event) { uint8_t event; /*check job-queue*/ if (true == ZAF_JobHelperJobDequeue(&event)) { /*Let the event scheduler fire the event on state event machine*/ ZAF_EventHelperEventEnqueue(event); } else { DPRINT(" Enqueuing event: EVENT_APP_FINISH_EVENT_JOB"); ZAF_EventHelperEventEnqueue(EVENT_APP_FINISH_EVENT_JOB); } } if (EVENT_APP_BASIC_START_JOB == event) { if (JOB_STATUS_SUCCESS != CC_Basic_Set_tx( &agiTableRootDeviceGroups[0].profile, ENDPOINT_ROOT, BASIC_SET_TRIGGER_VALUE, ZCB_JobStatus)) { DPRINT("\r\nEVENT_APP_BASIC_START_JOB failed"); basicValue = BASIC_SET_TRIGGER_VALUE; /*Kick next job*/ ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_BASIC_STOP_JOB == event) { if (JOB_STATUS_SUCCESS != CC_Basic_Set_tx( &agiTableRootDeviceGroups[0].profile, ENDPOINT_ROOT, 0, ZCB_JobStatus)) { DPRINT("\r\nEVENT_APP_BASIC_STOP_JOB failed"); basicValue = 0; /*Kick next job*/ ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_NOTIFICATION_START_JOB == event) { DPRINT("\r\nEVENT_APP_NOTIFICATION_START_JOB"); NotificationEventTrigger(&lifelineProfile, NOTIFICATION_TYPE_HOME_SECURITY, supportedEvents, NULL, 0, ENDPOINT_ROOT); if (JOB_STATUS_SUCCESS != UnsolicitedNotificationAction(&lifelineProfile, ENDPOINT_ROOT, ZCB_JobStatus)) { /*Kick next job*/ ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_NOTIFICATION_STOP_JOB == event) { DPRINT("\r\nEVENT_APP_NOTIFICATION_STOP_JOB"); NotificationEventTrigger(&lifelineProfile, NOTIFICATION_TYPE_HOME_SECURITY, 0, &supportedEvents, 1, ENDPOINT_ROOT); if (JOB_STATUS_SUCCESS != UnsolicitedNotificationAction(&lifelineProfile, ENDPOINT_ROOT, ZCB_JobStatus)) { /*Kick next job*/ ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_START_TIMER_EVENTJOB_STOP== event) { DPRINT("\r\n#EVENT_APP_START_TIMER_EVENTJOB_STOP\r\n"); AppTimerEm4PersistentStart(&EventJobsTimer, BASIC_SET_TIMEOUT); } if (EVENT_APP_SEND_BATTERY_LEVEL_REPORT == event) { ReportBatteryLevel(); } if (EVENT_APP_FINISH_EVENT_JOB == event) { ChangeState(STATE_APP_IDLE); } DPRINTF("\r\nSTATE_APP_TRANSMIT_DATA done (state: %d)", currentState); break; default: // Do nothing. DPRINT("\r\nAppStateHandler(): Case is not handled!!!"); break; } }
/** * @brief The core state machine of this sample application. * @param event The event that triggered the call of AppStateManager. */
@brief The core state machine of this sample application. @param event The event that triggered the call of AppStateManager.
[ "@brief", "The", "core", "state", "machine", "of", "this", "sample", "application", ".", "@param", "event", "The", "event", "that", "triggered", "the", "call", "of", "AppStateManager", "." ]
void AppStateManager(EVENT_APP event) { DPRINTF("AppStateManager St: %d, Ev: 0x%02x\r\n", currentState, event); notAppStateDependentActivity(event); switch(currentState) { case STATE_APP_STARTUP: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); } if (EVENT_APP_INIT == event) { doRemainingInitialization(); break; } ChangeState(STATE_APP_IDLE); break; case STATE_APP_IDLE: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); LoadConfiguration(); } if (EVENT_APP_SMARTSTART_IN_PROGRESS == event) { ChangeState(STATE_APP_LEARN_MODE); } if ((BTN_EVENT_SHORT_PRESS(APP_BUTTON_LEARN_RESET) == (BUTTON_EVENT)event) || (EVENT_SYSTEM_LEARNMODE_START == (EVENT_SYSTEM)event)) { if (EINCLUSIONSTATE_EXCLUDED != g_pAppHandles->pNetworkInfo->eInclusionState){ DPRINT("\r\nLEARN_MODE_EXCLUSION"); ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_EXCLUSION_NWE); } else{ DPRINT("\r\nLEARN_MODE_INCLUSION"); ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_INCLUSION); } Board_IndicateStatus(BOARD_STATUS_LEARNMODE_ACTIVE); ChangeState(STATE_APP_LEARN_MODE); } if (PIR_EVENT_TRANSITION_TO_ACTIVE(event)) { ZAF_PM_StayAwake(&m_RadioPowerLock, 0); DPRINT("\r\n"); DPRINT("\r\n *!*!**!*!**!*!**!*!**!*!**!*!**!*!**!*!*"); DPRINT("\r\n *!*!* PIR EVENT ACTIVE *!*!*"); DPRINT("\r\n *!*!**!*!**!*!**!*!**!*!**!*!**!*!**!*!*"); DPRINT("\r\n"); ChangeState(STATE_APP_TRANSMIT_DATA); if (false == ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB)) { DPRINT("\r\n** EVENT_APP_NEXT_EVENT_JOB fail\r\n"); } ZAF_JobHelperJobEnqueue(EVENT_APP_BASIC_START_JOB); ZAF_JobHelperJobEnqueue(EVENT_APP_NOTIFICATION_START_JOB); ZAF_JobHelperJobEnqueue(EVENT_APP_START_TIMER_EVENTJOB_STOP); } if (BTN_EVENT_SHORT_PRESS(BATTERY_REPORT_BTN) == (BUTTON_EVENT)event) { DPRINT("\r\nBattery Level report transmit (keypress trig)\r\n"); ChangeState(STATE_APP_TRANSMIT_DATA); if (false == ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB)) { DPRINT("\r\n** EVENT_APP_NEXT_EVENT_JOB fail\r\n"); } ZAF_JobHelperJobEnqueue(EVENT_APP_SEND_BATTERY_LEVEL_REPORT); } break; case STATE_APP_LEARN_MODE: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); LoadConfiguration(); } if ((BTN_EVENT_SHORT_PRESS(APP_BUTTON_LEARN_RESET) == (BUTTON_EVENT)event) || (EVENT_SYSTEM_LEARNMODE_STOP == (EVENT_SYSTEM)event)) { ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_DISABLE); ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_INCLUSION_SMARTSTART); Board_IndicateStatus(BOARD_STATUS_IDLE); ChangeState(STATE_APP_IDLE); CC_Indicator_RefreshIndicatorProperties(); ZAF_TSE_Trigger(CC_Indicator_report_stx, (void *)&ZAF_TSE_localActuationIdentifyData, true); } if (EVENT_SYSTEM_LEARNMODE_FINISHED == (EVENT_SYSTEM)event) { CC_WakeUp_stayAwake10s(); CC_WakeUp_AutoStayAwakeAfterInclusion(); ZAF_setNetworkLearnMode(E_NETWORK_LEARN_MODE_INCLUSION_SMARTSTART); Board_IndicateStatus(BOARD_STATUS_IDLE); ChangeState(STATE_APP_IDLE); CC_Indicator_RefreshIndicatorProperties(); ZAF_TSE_Trigger(CC_Indicator_report_stx, (void *)&ZAF_TSE_localActuationIdentifyData, true); if (EINCLUSIONSTATE_EXCLUDED != g_pAppHandles->pNetworkInfo->eInclusionState) { CC_WakeUp_startWakeUpNotificationTimer(); } } break; case STATE_APP_RESET: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); Board_ResetHandler(); } break; case STATE_APP_POWERDOWN: break; case STATE_APP_TRANSMIT_DATA: if(EVENT_APP_FLUSHMEM_READY == event) { AppResetNvm(); LoadConfiguration(); } if (EVENT_APP_NEXT_EVENT_JOB == event) { uint8_t event; if (true == ZAF_JobHelperJobDequeue(&event)) { ZAF_EventHelperEventEnqueue(event); } else { DPRINT(" Enqueuing event: EVENT_APP_FINISH_EVENT_JOB"); ZAF_EventHelperEventEnqueue(EVENT_APP_FINISH_EVENT_JOB); } } if (EVENT_APP_BASIC_START_JOB == event) { if (JOB_STATUS_SUCCESS != CC_Basic_Set_tx( &agiTableRootDeviceGroups[0].profile, ENDPOINT_ROOT, BASIC_SET_TRIGGER_VALUE, ZCB_JobStatus)) { DPRINT("\r\nEVENT_APP_BASIC_START_JOB failed"); basicValue = BASIC_SET_TRIGGER_VALUE; ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_BASIC_STOP_JOB == event) { if (JOB_STATUS_SUCCESS != CC_Basic_Set_tx( &agiTableRootDeviceGroups[0].profile, ENDPOINT_ROOT, 0, ZCB_JobStatus)) { DPRINT("\r\nEVENT_APP_BASIC_STOP_JOB failed"); basicValue = 0; ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_NOTIFICATION_START_JOB == event) { DPRINT("\r\nEVENT_APP_NOTIFICATION_START_JOB"); NotificationEventTrigger(&lifelineProfile, NOTIFICATION_TYPE_HOME_SECURITY, supportedEvents, NULL, 0, ENDPOINT_ROOT); if (JOB_STATUS_SUCCESS != UnsolicitedNotificationAction(&lifelineProfile, ENDPOINT_ROOT, ZCB_JobStatus)) { ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_NOTIFICATION_STOP_JOB == event) { DPRINT("\r\nEVENT_APP_NOTIFICATION_STOP_JOB"); NotificationEventTrigger(&lifelineProfile, NOTIFICATION_TYPE_HOME_SECURITY, 0, &supportedEvents, 1, ENDPOINT_ROOT); if (JOB_STATUS_SUCCESS != UnsolicitedNotificationAction(&lifelineProfile, ENDPOINT_ROOT, ZCB_JobStatus)) { ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } } if (EVENT_APP_START_TIMER_EVENTJOB_STOP== event) { DPRINT("\r\n#EVENT_APP_START_TIMER_EVENTJOB_STOP\r\n"); AppTimerEm4PersistentStart(&EventJobsTimer, BASIC_SET_TIMEOUT); } if (EVENT_APP_SEND_BATTERY_LEVEL_REPORT == event) { ReportBatteryLevel(); } if (EVENT_APP_FINISH_EVENT_JOB == event) { ChangeState(STATE_APP_IDLE); } DPRINTF("\r\nSTATE_APP_TRANSMIT_DATA done (state: %d)", currentState); break; default: DPRINT("\r\nAppStateHandler(): Case is not handled!!!"); break; } }
[ "void", "AppStateManager", "(", "EVENT_APP", "event", ")", "{", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "currentState", ",", "event", ")", ";", "notAppStateDependentActivity", "(", "event", ")", ";", "switch", "(", "currentState", ")", "{", "case", "STATE_APP_STARTUP", ":", "if", "(", "EVENT_APP_FLUSHMEM_READY", "==", "event", ")", "{", "AppResetNvm", "(", ")", ";", "}", "if", "(", "EVENT_APP_INIT", "==", "event", ")", "{", "doRemainingInitialization", "(", ")", ";", "break", ";", "}", "ChangeState", "(", "STATE_APP_IDLE", ")", ";", "break", ";", "case", "STATE_APP_IDLE", ":", "if", "(", "EVENT_APP_FLUSHMEM_READY", "==", "event", ")", "{", "AppResetNvm", "(", ")", ";", "LoadConfiguration", "(", ")", ";", "}", "if", "(", "EVENT_APP_SMARTSTART_IN_PROGRESS", "==", "event", ")", "{", "ChangeState", "(", "STATE_APP_LEARN_MODE", ")", ";", "}", "if", "(", "(", "BTN_EVENT_SHORT_PRESS", "(", "APP_BUTTON_LEARN_RESET", ")", "==", "(", "BUTTON_EVENT", ")", "event", ")", "||", "(", "EVENT_SYSTEM_LEARNMODE_START", "==", "(", "EVENT_SYSTEM", ")", "event", ")", ")", "{", "if", "(", "EINCLUSIONSTATE_EXCLUDED", "!=", "g_pAppHandles", "->", "pNetworkInfo", "->", "eInclusionState", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "ZAF_setNetworkLearnMode", "(", "E_NETWORK_LEARN_MODE_EXCLUSION_NWE", ")", ";", "}", "else", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "ZAF_setNetworkLearnMode", "(", "E_NETWORK_LEARN_MODE_INCLUSION", ")", ";", "}", "Board_IndicateStatus", "(", "BOARD_STATUS_LEARNMODE_ACTIVE", ")", ";", "ChangeState", "(", "STATE_APP_LEARN_MODE", ")", ";", "}", "if", "(", "PIR_EVENT_TRANSITION_TO_ACTIVE", "(", "event", ")", ")", "{", "ZAF_PM_StayAwake", "(", "&", "m_RadioPowerLock", ",", "0", ")", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "ChangeState", "(", "STATE_APP_TRANSMIT_DATA", ")", ";", "if", "(", "false", "==", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\\r", "\\n", "\"", ")", ";", "}", "ZAF_JobHelperJobEnqueue", "(", "EVENT_APP_BASIC_START_JOB", ")", ";", "ZAF_JobHelperJobEnqueue", "(", "EVENT_APP_NOTIFICATION_START_JOB", ")", ";", "ZAF_JobHelperJobEnqueue", "(", "EVENT_APP_START_TIMER_EVENTJOB_STOP", ")", ";", "}", "if", "(", "BTN_EVENT_SHORT_PRESS", "(", "BATTERY_REPORT_BTN", ")", "==", "(", "BUTTON_EVENT", ")", "event", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\\r", "\\n", "\"", ")", ";", "ChangeState", "(", "STATE_APP_TRANSMIT_DATA", ")", ";", "if", "(", "false", "==", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\\r", "\\n", "\"", ")", ";", "}", "ZAF_JobHelperJobEnqueue", "(", "EVENT_APP_SEND_BATTERY_LEVEL_REPORT", ")", ";", "}", "break", ";", "case", "STATE_APP_LEARN_MODE", ":", "if", "(", "EVENT_APP_FLUSHMEM_READY", "==", "event", ")", "{", "AppResetNvm", "(", ")", ";", "LoadConfiguration", "(", ")", ";", "}", "if", "(", "(", "BTN_EVENT_SHORT_PRESS", "(", "APP_BUTTON_LEARN_RESET", ")", "==", "(", "BUTTON_EVENT", ")", "event", ")", "||", "(", "EVENT_SYSTEM_LEARNMODE_STOP", "==", "(", "EVENT_SYSTEM", ")", "event", ")", ")", "{", "ZAF_setNetworkLearnMode", "(", "E_NETWORK_LEARN_MODE_DISABLE", ")", ";", "ZAF_setNetworkLearnMode", "(", "E_NETWORK_LEARN_MODE_INCLUSION_SMARTSTART", ")", ";", "Board_IndicateStatus", "(", "BOARD_STATUS_IDLE", ")", ";", "ChangeState", "(", "STATE_APP_IDLE", ")", ";", "CC_Indicator_RefreshIndicatorProperties", "(", ")", ";", "ZAF_TSE_Trigger", "(", "CC_Indicator_report_stx", ",", "(", "void", "*", ")", "&", "ZAF_TSE_localActuationIdentifyData", ",", "true", ")", ";", "}", "if", "(", "EVENT_SYSTEM_LEARNMODE_FINISHED", "==", "(", "EVENT_SYSTEM", ")", "event", ")", "{", "CC_WakeUp_stayAwake10s", "(", ")", ";", "CC_WakeUp_AutoStayAwakeAfterInclusion", "(", ")", ";", "ZAF_setNetworkLearnMode", "(", "E_NETWORK_LEARN_MODE_INCLUSION_SMARTSTART", ")", ";", "Board_IndicateStatus", "(", "BOARD_STATUS_IDLE", ")", ";", "ChangeState", "(", "STATE_APP_IDLE", ")", ";", "CC_Indicator_RefreshIndicatorProperties", "(", ")", ";", "ZAF_TSE_Trigger", "(", "CC_Indicator_report_stx", ",", "(", "void", "*", ")", "&", "ZAF_TSE_localActuationIdentifyData", ",", "true", ")", ";", "if", "(", "EINCLUSIONSTATE_EXCLUDED", "!=", "g_pAppHandles", "->", "pNetworkInfo", "->", "eInclusionState", ")", "{", "CC_WakeUp_startWakeUpNotificationTimer", "(", ")", ";", "}", "}", "break", ";", "case", "STATE_APP_RESET", ":", "if", "(", "EVENT_APP_FLUSHMEM_READY", "==", "event", ")", "{", "AppResetNvm", "(", ")", ";", "Board_ResetHandler", "(", ")", ";", "}", "break", ";", "case", "STATE_APP_POWERDOWN", ":", "break", ";", "case", "STATE_APP_TRANSMIT_DATA", ":", "if", "(", "EVENT_APP_FLUSHMEM_READY", "==", "event", ")", "{", "AppResetNvm", "(", ")", ";", "LoadConfiguration", "(", ")", ";", "}", "if", "(", "EVENT_APP_NEXT_EVENT_JOB", "==", "event", ")", "{", "uint8_t", "event", ";", "if", "(", "true", "==", "ZAF_JobHelperJobDequeue", "(", "&", "event", ")", ")", "{", "ZAF_EventHelperEventEnqueue", "(", "event", ")", ";", "}", "else", "{", "DPRINT", "(", "\"", "\"", ")", ";", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_FINISH_EVENT_JOB", ")", ";", "}", "}", "if", "(", "EVENT_APP_BASIC_START_JOB", "==", "event", ")", "{", "if", "(", "JOB_STATUS_SUCCESS", "!=", "CC_Basic_Set_tx", "(", "&", "agiTableRootDeviceGroups", "[", "0", "]", ".", "profile", ",", "ENDPOINT_ROOT", ",", "BASIC_SET_TRIGGER_VALUE", ",", "ZCB_JobStatus", ")", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "basicValue", "=", "BASIC_SET_TRIGGER_VALUE", ";", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ";", "}", "}", "if", "(", "EVENT_APP_BASIC_STOP_JOB", "==", "event", ")", "{", "if", "(", "JOB_STATUS_SUCCESS", "!=", "CC_Basic_Set_tx", "(", "&", "agiTableRootDeviceGroups", "[", "0", "]", ".", "profile", ",", "ENDPOINT_ROOT", ",", "0", ",", "ZCB_JobStatus", ")", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "basicValue", "=", "0", ";", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ";", "}", "}", "if", "(", "EVENT_APP_NOTIFICATION_START_JOB", "==", "event", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "NotificationEventTrigger", "(", "&", "lifelineProfile", ",", "NOTIFICATION_TYPE_HOME_SECURITY", ",", "supportedEvents", ",", "NULL", ",", "0", ",", "ENDPOINT_ROOT", ")", ";", "if", "(", "JOB_STATUS_SUCCESS", "!=", "UnsolicitedNotificationAction", "(", "&", "lifelineProfile", ",", "ENDPOINT_ROOT", ",", "ZCB_JobStatus", ")", ")", "{", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ";", "}", "}", "if", "(", "EVENT_APP_NOTIFICATION_STOP_JOB", "==", "event", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "NotificationEventTrigger", "(", "&", "lifelineProfile", ",", "NOTIFICATION_TYPE_HOME_SECURITY", ",", "0", ",", "&", "supportedEvents", ",", "1", ",", "ENDPOINT_ROOT", ")", ";", "if", "(", "JOB_STATUS_SUCCESS", "!=", "UnsolicitedNotificationAction", "(", "&", "lifelineProfile", ",", "ENDPOINT_ROOT", ",", "ZCB_JobStatus", ")", ")", "{", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ";", "}", "}", "if", "(", "EVENT_APP_START_TIMER_EVENTJOB_STOP", "==", "event", ")", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\\r", "\\n", "\"", ")", ";", "AppTimerEm4PersistentStart", "(", "&", "EventJobsTimer", ",", "BASIC_SET_TIMEOUT", ")", ";", "}", "if", "(", "EVENT_APP_SEND_BATTERY_LEVEL_REPORT", "==", "event", ")", "{", "ReportBatteryLevel", "(", ")", ";", "}", "if", "(", "EVENT_APP_FINISH_EVENT_JOB", "==", "event", ")", "{", "ChangeState", "(", "STATE_APP_IDLE", ")", ";", "}", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "currentState", ")", ";", "break", ";", "default", ":", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "break", ";", "}", "}" ]
@brief The core state machine of this sample application.
[ "@brief", "The", "core", "state", "machine", "of", "this", "sample", "application", "." ]
[ "/*\r\n * Here we handle events that are not evaluated in the context of the app state.\r\n */", "/*\r\n * This approach makes it possible to do less initialization before the scheduler starts.\r\n * Hence, this was made to reduce the boot-up time.\r\n */", "// Handle received PIR event\r", "/*Add event's on job-queue*/", "/* BATTERY REPORT EVENT received. Send a battery level report */", "/*Add event's on job-queue*/", "//Go back to smart start if the node was never included.\r", "//Protocol will not commence SmartStart if the node is already included in the network.\r", "/* If we are in a network and the Identify LED state was changed to idle due to learn mode, report it to lifeline */", "//Make sure that the application stays awake for 10 s after learn mode finished\r", "//to wait for more messages from the controller\r", "/* Also tell application to automatically extend the stay awake period by 10\r\n * seconds on message activities - even though we did not get here by a proper\r\n * wakeup from EM4\r\n */", "//Go back to smart start if the node was excluded.\r", "//Protocol will not commence SmartStart if the node is already included in the network.\r", "/* If we are in a network and the Identify LED state was changed to idle due to learn mode, report it to lifeline */", "// Start the wakeup timer if the learn mode operation finished in Included state\r", "/* Soft reset */", "/* Device is powering down.. wait!*/", "/*check job-queue*/", "/*Let the event scheduler fire the event on state event machine*/", "/*Kick next job*/", "/*Kick next job*/", "/*Kick next job*/", "/*Kick next job*/", "// Do nothing.\r" ]
[ { "param": "event", "type": "EVENT_APP" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "event", "type": "EVENT_APP", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
CC_Battery_BatteryGet_handler
uint8_t
uint8_t CC_Battery_BatteryGet_handler(uint8_t endpoint) { uint32_t VBattery; uint8_t accurateLevel; uint8_t roundedLevel; UNUSED(endpoint); /* * Simple example how to use the ADC to measure the battery voltage * and convert to a percentage battery level on a linear scale. */ ZAF_ADC_Enable(); VBattery = ZAF_ADC_Measure_VSupply(); DPRINTF("\r\nBattery voltage: %dmV", VBattery); ZAF_ADC_Disable(); if (MY_BATTERY_SPEC_LEVEL_FULL <= VBattery) { // Level is full return (uint8_t)CMD_CLASS_BATTERY_LEVEL_FULL; } else if (MY_BATTERY_SPEC_LEVEL_EMPTY > VBattery) { // Level is empty (<0%) return (uint8_t)CMD_CLASS_BATTERY_LEVEL_WARNING; } else { // Calculate the percentage level from 0 to 100 accurateLevel = (uint8_t)((100 * (VBattery - MY_BATTERY_SPEC_LEVEL_EMPTY)) / (MY_BATTERY_SPEC_LEVEL_FULL - MY_BATTERY_SPEC_LEVEL_EMPTY)); // And round off to the nearest "BATTERY_LEVEL_REPORTING_DECREMENTS" level roundedLevel = (accurateLevel / BATTERY_LEVEL_REPORTING_DECREMENTS) * BATTERY_LEVEL_REPORTING_DECREMENTS; // Rounded down if ((accurateLevel % BATTERY_LEVEL_REPORTING_DECREMENTS) >= (BATTERY_LEVEL_REPORTING_DECREMENTS / 2)) { roundedLevel += BATTERY_LEVEL_REPORTING_DECREMENTS; // Round up } } return roundedLevel; }
/** * Report current battery level to battery command class handler * * @brief See description for function prototype in CC_Battery.h */
Report current battery level to battery command class handler @brief See description for function prototype in CC_Battery.h
[ "Report", "current", "battery", "level", "to", "battery", "command", "class", "handler", "@brief", "See", "description", "for", "function", "prototype", "in", "CC_Battery", ".", "h" ]
uint8_t CC_Battery_BatteryGet_handler(uint8_t endpoint) { uint32_t VBattery; uint8_t accurateLevel; uint8_t roundedLevel; UNUSED(endpoint); ZAF_ADC_Enable(); VBattery = ZAF_ADC_Measure_VSupply(); DPRINTF("\r\nBattery voltage: %dmV", VBattery); ZAF_ADC_Disable(); if (MY_BATTERY_SPEC_LEVEL_FULL <= VBattery) { return (uint8_t)CMD_CLASS_BATTERY_LEVEL_FULL; } else if (MY_BATTERY_SPEC_LEVEL_EMPTY > VBattery) { return (uint8_t)CMD_CLASS_BATTERY_LEVEL_WARNING; } else { accurateLevel = (uint8_t)((100 * (VBattery - MY_BATTERY_SPEC_LEVEL_EMPTY)) / (MY_BATTERY_SPEC_LEVEL_FULL - MY_BATTERY_SPEC_LEVEL_EMPTY)); roundedLevel = (accurateLevel / BATTERY_LEVEL_REPORTING_DECREMENTS) * BATTERY_LEVEL_REPORTING_DECREMENTS; if ((accurateLevel % BATTERY_LEVEL_REPORTING_DECREMENTS) >= (BATTERY_LEVEL_REPORTING_DECREMENTS / 2)) { roundedLevel += BATTERY_LEVEL_REPORTING_DECREMENTS; } } return roundedLevel; }
[ "uint8_t", "CC_Battery_BatteryGet_handler", "(", "uint8_t", "endpoint", ")", "{", "uint32_t", "VBattery", ";", "uint8_t", "accurateLevel", ";", "uint8_t", "roundedLevel", ";", "UNUSED", "(", "endpoint", ")", ";", "ZAF_ADC_Enable", "(", ")", ";", "VBattery", "=", "ZAF_ADC_Measure_VSupply", "(", ")", ";", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "VBattery", ")", ";", "ZAF_ADC_Disable", "(", ")", ";", "if", "(", "MY_BATTERY_SPEC_LEVEL_FULL", "<=", "VBattery", ")", "{", "return", "(", "uint8_t", ")", "CMD_CLASS_BATTERY_LEVEL_FULL", ";", "}", "else", "if", "(", "MY_BATTERY_SPEC_LEVEL_EMPTY", ">", "VBattery", ")", "{", "return", "(", "uint8_t", ")", "CMD_CLASS_BATTERY_LEVEL_WARNING", ";", "}", "else", "{", "accurateLevel", "=", "(", "uint8_t", ")", "(", "(", "100", "*", "(", "VBattery", "-", "MY_BATTERY_SPEC_LEVEL_EMPTY", ")", ")", "/", "(", "MY_BATTERY_SPEC_LEVEL_FULL", "-", "MY_BATTERY_SPEC_LEVEL_EMPTY", ")", ")", ";", "roundedLevel", "=", "(", "accurateLevel", "/", "BATTERY_LEVEL_REPORTING_DECREMENTS", ")", "*", "BATTERY_LEVEL_REPORTING_DECREMENTS", ";", "if", "(", "(", "accurateLevel", "%", "BATTERY_LEVEL_REPORTING_DECREMENTS", ")", ">=", "(", "BATTERY_LEVEL_REPORTING_DECREMENTS", "/", "2", ")", ")", "{", "roundedLevel", "+=", "BATTERY_LEVEL_REPORTING_DECREMENTS", ";", "}", "}", "return", "roundedLevel", ";", "}" ]
Report current battery level to battery command class handler
[ "Report", "current", "battery", "level", "to", "battery", "command", "class", "handler" ]
[ "/*\r\n * Simple example how to use the ADC to measure the battery voltage\r\n * and convert to a percentage battery level on a linear scale.\r\n */", "// Level is full\r", "// Level is empty (<0%)\r", "// Calculate the percentage level from 0 to 100\r", "// And round off to the nearest \"BATTERY_LEVEL_REPORTING_DECREMENTS\" level\r", "// Rounded down\r", "// Round up\r" ]
[ { "param": "endpoint", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "endpoint", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
ZCB_JobStatus
void
void ZCB_JobStatus(TRANSMISSION_RESULT * pTransmissionResult) { DPRINT("Callback: ZCB_JobStatus()"); if (TRANSMISSION_RESULT_FINISHED == pTransmissionResult->isFinished) { ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } }
/** * @brief Callback function used for unsolicited commands. * @param pTransmissionResult Result of each transmission. */
@brief Callback function used for unsolicited commands. @param pTransmissionResult Result of each transmission.
[ "@brief", "Callback", "function", "used", "for", "unsolicited", "commands", ".", "@param", "pTransmissionResult", "Result", "of", "each", "transmission", "." ]
void ZCB_JobStatus(TRANSMISSION_RESULT * pTransmissionResult) { DPRINT("Callback: ZCB_JobStatus()"); if (TRANSMISSION_RESULT_FINISHED == pTransmissionResult->isFinished) { ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } }
[ "void", "ZCB_JobStatus", "(", "TRANSMISSION_RESULT", "*", "pTransmissionResult", ")", "{", "DPRINT", "(", "\"", "\"", ")", ";", "if", "(", "TRANSMISSION_RESULT_FINISHED", "==", "pTransmissionResult", "->", "isFinished", ")", "{", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ";", "}", "}" ]
@brief Callback function used for unsolicited commands.
[ "@brief", "Callback", "function", "used", "for", "unsolicited", "commands", "." ]
[]
[ { "param": "pTransmissionResult", "type": "TRANSMISSION_RESULT" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pTransmissionResult", "type": "TRANSMISSION_RESULT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
SetDefaultConfiguration
void
void SetDefaultConfiguration(void) { Ecode_t errCode; DPRINT("\r\nSet Default Configuration"); AssociationInit(true, pFileSystemApplication); DefaultNotificationStatus(NOTIFICATION_STATUS_UNSOLICIT_ACTIVATED); CC_WakeUp_notificationMemorySetDefault(pFileSystemApplication); DPRINT("\r\nEnded Set Default Configuration"); BatteryData.lastReportedBatteryLevel = BATTERY_DATA_UNASSIGNED_VALUE; writeBatteryData(&BatteryData); loadInitStatusPowerLevel(); uint32_t appVersion = ZAF_GetAppVersion(); errCode = nvm3_writeData(pFileSystemApplication, ZAF_FILE_ID_APP_VERSION, &appVersion, ZAF_FILE_SIZE_APP_VERSION); ASSERT(ECODE_NVM3_OK == errCode); //Assert has been kept for debugging , can be removed from production code if this error can only be caused by some internal flash HW failure }
/** * @brief Function resets configuration to default values. * * Add application specific functions here to initialize configuration values stored in persistent memory. * Will be called at any of the following events: * - Network Exclusion * - Network Secure Inclusion (after S2 bootstrapping complete) * - Device Reset Locally */
@brief Function resets configuration to default values. Add application specific functions here to initialize configuration values stored in persistent memory. Will be called at any of the following events: - Network Exclusion - Network Secure Inclusion (after S2 bootstrapping complete) - Device Reset Locally
[ "@brief", "Function", "resets", "configuration", "to", "default", "values", ".", "Add", "application", "specific", "functions", "here", "to", "initialize", "configuration", "values", "stored", "in", "persistent", "memory", ".", "Will", "be", "called", "at", "any", "of", "the", "following", "events", ":", "-", "Network", "Exclusion", "-", "Network", "Secure", "Inclusion", "(", "after", "S2", "bootstrapping", "complete", ")", "-", "Device", "Reset", "Locally" ]
void SetDefaultConfiguration(void) { Ecode_t errCode; DPRINT("\r\nSet Default Configuration"); AssociationInit(true, pFileSystemApplication); DefaultNotificationStatus(NOTIFICATION_STATUS_UNSOLICIT_ACTIVATED); CC_WakeUp_notificationMemorySetDefault(pFileSystemApplication); DPRINT("\r\nEnded Set Default Configuration"); BatteryData.lastReportedBatteryLevel = BATTERY_DATA_UNASSIGNED_VALUE; writeBatteryData(&BatteryData); loadInitStatusPowerLevel(); uint32_t appVersion = ZAF_GetAppVersion(); errCode = nvm3_writeData(pFileSystemApplication, ZAF_FILE_ID_APP_VERSION, &appVersion, ZAF_FILE_SIZE_APP_VERSION); ASSERT(ECODE_NVM3_OK == errCode); }
[ "void", "SetDefaultConfiguration", "(", "void", ")", "{", "Ecode_t", "errCode", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "AssociationInit", "(", "true", ",", "pFileSystemApplication", ")", ";", "DefaultNotificationStatus", "(", "NOTIFICATION_STATUS_UNSOLICIT_ACTIVATED", ")", ";", "CC_WakeUp_notificationMemorySetDefault", "(", "pFileSystemApplication", ")", ";", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "BatteryData", ".", "lastReportedBatteryLevel", "=", "BATTERY_DATA_UNASSIGNED_VALUE", ";", "writeBatteryData", "(", "&", "BatteryData", ")", ";", "loadInitStatusPowerLevel", "(", ")", ";", "uint32_t", "appVersion", "=", "ZAF_GetAppVersion", "(", ")", ";", "errCode", "=", "nvm3_writeData", "(", "pFileSystemApplication", ",", "ZAF_FILE_ID_APP_VERSION", ",", "&", "appVersion", ",", "ZAF_FILE_SIZE_APP_VERSION", ")", ";", "ASSERT", "(", "ECODE_NVM3_OK", "==", "errCode", ")", ";", "}" ]
@brief Function resets configuration to default values.
[ "@brief", "Function", "resets", "configuration", "to", "default", "values", "." ]
[ "//Assert has been kept for debugging , can be removed from production code if this error can only be caused by some internal flash HW failure\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
LoadConfiguration
bool
bool LoadConfiguration(void) { uint32_t appVersion; Ecode_t versionFileStatus = nvm3_readData(pFileSystemApplication, ZAF_FILE_ID_APP_VERSION, &appVersion, ZAF_FILE_SIZE_APP_VERSION); if (ECODE_NVM3_OK == versionFileStatus) { if (ZAF_GetAppVersion() != appVersion) { // Add code for migration of file system to higher version here. } BatteryData = readBatteryData(); /* Initialize association module */ AssociationInit(false, pFileSystemApplication); loadStatusPowerLevel(); return true; } else { DPRINT("\r\nApplication FileSystem Verify failed"); loadInitStatusPowerLevel(); // Reset the file system if ZAF_FILE_ID_APP_VERSION is missing since this indicates // corrupt or missing file system. AppResetNvm(); return false; } }
/** * @brief This function loads the application settings from non-volatile memory. * If no settings are found, default values are used and saved. */
@brief This function loads the application settings from non-volatile memory. If no settings are found, default values are used and saved.
[ "@brief", "This", "function", "loads", "the", "application", "settings", "from", "non", "-", "volatile", "memory", ".", "If", "no", "settings", "are", "found", "default", "values", "are", "used", "and", "saved", "." ]
bool LoadConfiguration(void) { uint32_t appVersion; Ecode_t versionFileStatus = nvm3_readData(pFileSystemApplication, ZAF_FILE_ID_APP_VERSION, &appVersion, ZAF_FILE_SIZE_APP_VERSION); if (ECODE_NVM3_OK == versionFileStatus) { if (ZAF_GetAppVersion() != appVersion) { } BatteryData = readBatteryData(); AssociationInit(false, pFileSystemApplication); loadStatusPowerLevel(); return true; } else { DPRINT("\r\nApplication FileSystem Verify failed"); loadInitStatusPowerLevel(); AppResetNvm(); return false; } }
[ "bool", "LoadConfiguration", "(", "void", ")", "{", "uint32_t", "appVersion", ";", "Ecode_t", "versionFileStatus", "=", "nvm3_readData", "(", "pFileSystemApplication", ",", "ZAF_FILE_ID_APP_VERSION", ",", "&", "appVersion", ",", "ZAF_FILE_SIZE_APP_VERSION", ")", ";", "if", "(", "ECODE_NVM3_OK", "==", "versionFileStatus", ")", "{", "if", "(", "ZAF_GetAppVersion", "(", ")", "!=", "appVersion", ")", "{", "}", "BatteryData", "=", "readBatteryData", "(", ")", ";", "AssociationInit", "(", "false", ",", "pFileSystemApplication", ")", ";", "loadStatusPowerLevel", "(", ")", ";", "return", "true", ";", "}", "else", "{", "DPRINT", "(", "\"", "\\r", "\\n", "\"", ")", ";", "loadInitStatusPowerLevel", "(", ")", ";", "AppResetNvm", "(", ")", ";", "return", "false", ";", "}", "}" ]
@brief This function loads the application settings from non-volatile memory.
[ "@brief", "This", "function", "loads", "the", "application", "settings", "from", "non", "-", "volatile", "memory", "." ]
[ "// Add code for migration of file system to higher version here.\r", "/* Initialize association module */", "// Reset the file system if ZAF_FILE_ID_APP_VERSION is missing since this indicates\r", "// corrupt or missing file system.\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
ZCB_EventJobsTimer
void
void ZCB_EventJobsTimer(SSwTimer *pTimer) { DPRINTF("\r\nTimer callback: ZCB_EventJobsTimer() pTimer->Id=%d", pTimer->Id); /* If the node has been woken up from EM4 because the event job timer timed out * the app will now be in the state STATE_APP_STARTUP. Need to switch to * STATE_APP_TRANSMIT_DATA to properly process the job events */ ZAF_JobHelperJobEnqueue(EVENT_APP_NOTIFICATION_STOP_JOB); ZAF_JobHelperJobEnqueue(EVENT_APP_BASIC_STOP_JOB); if (STATE_APP_TRANSMIT_DATA != currentState) { ChangeState(STATE_APP_TRANSMIT_DATA); ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } UNUSED(pTimer); }
/** * @brief event jobs timeout event * * @param pTimer Timer connected to this method */
@brief event jobs timeout event @param pTimer Timer connected to this method
[ "@brief", "event", "jobs", "timeout", "event", "@param", "pTimer", "Timer", "connected", "to", "this", "method" ]
void ZCB_EventJobsTimer(SSwTimer *pTimer) { DPRINTF("\r\nTimer callback: ZCB_EventJobsTimer() pTimer->Id=%d", pTimer->Id); ZAF_JobHelperJobEnqueue(EVENT_APP_NOTIFICATION_STOP_JOB); ZAF_JobHelperJobEnqueue(EVENT_APP_BASIC_STOP_JOB); if (STATE_APP_TRANSMIT_DATA != currentState) { ChangeState(STATE_APP_TRANSMIT_DATA); ZAF_EventHelperEventEnqueue(EVENT_APP_NEXT_EVENT_JOB); } UNUSED(pTimer); }
[ "void", "ZCB_EventJobsTimer", "(", "SSwTimer", "*", "pTimer", ")", "{", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "pTimer", "->", "Id", ")", ";", "ZAF_JobHelperJobEnqueue", "(", "EVENT_APP_NOTIFICATION_STOP_JOB", ")", ";", "ZAF_JobHelperJobEnqueue", "(", "EVENT_APP_BASIC_STOP_JOB", ")", ";", "if", "(", "STATE_APP_TRANSMIT_DATA", "!=", "currentState", ")", "{", "ChangeState", "(", "STATE_APP_TRANSMIT_DATA", ")", ";", "ZAF_EventHelperEventEnqueue", "(", "EVENT_APP_NEXT_EVENT_JOB", ")", ";", "}", "UNUSED", "(", "pTimer", ")", ";", "}" ]
@brief event jobs timeout event
[ "@brief", "event", "jobs", "timeout", "event" ]
[ "/* If the node has been woken up from EM4 because the event job timer timed out\r\n * the app will now be in the state STATE_APP_STARTUP. Need to switch to\r\n * STATE_APP_TRANSMIT_DATA to properly process the job events\r\n */" ]
[ { "param": "pTimer", "type": "SSwTimer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pTimer", "type": "SSwTimer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b53ba51b651759366c9b8ad69df1eb7563733852
SiliconLabs/Gecko_SDK
protocol/z-wave/Apps/SensorPIR/SensorPIR.c
[ "Zlib" ]
C
CC_ManufacturerSpecific_DeviceSpecificGet_handler
void
void CC_ManufacturerSpecific_DeviceSpecificGet_handler(device_id_type_t * pDeviceIDType, device_id_format_t * pDeviceIDDataFormat, uint8_t * pDeviceIDDataLength, uint8_t * pDeviceIDData) { *pDeviceIDType = DEVICE_ID_TYPE_SERIAL_NUMBER; *pDeviceIDDataFormat = DEVICE_ID_FORMAT_BINARY; *pDeviceIDDataLength = 8; uint64_t uuID = SYSTEM_GetUnique(); DPRINTF("\r\n uuID: %x", (uint32_t)uuID); *(pDeviceIDData + 0) = (uint8_t)(uuID >> 56); *(pDeviceIDData + 1) = (uint8_t)(uuID >> 48); *(pDeviceIDData + 2) = (uint8_t)(uuID >> 40); *(pDeviceIDData + 3) = (uint8_t)(uuID >> 32); *(pDeviceIDData + 4) = (uint8_t)(uuID >> 24); *(pDeviceIDData + 5) = (uint8_t)(uuID >> 16); *(pDeviceIDData + 6) = (uint8_t)(uuID >> 8); *(pDeviceIDData + 7) = (uint8_t)(uuID >> 0); }
/* * This function will report a serial number in a binary format according to the specification. * The serial number is the chip serial number and can be verified using the Simplicity Commander. * The choice of reporting can be changed in accordance with the Manufacturer Specific * Command Class specification. */
This function will report a serial number in a binary format according to the specification. The serial number is the chip serial number and can be verified using the Simplicity Commander. The choice of reporting can be changed in accordance with the Manufacturer Specific Command Class specification.
[ "This", "function", "will", "report", "a", "serial", "number", "in", "a", "binary", "format", "according", "to", "the", "specification", ".", "The", "serial", "number", "is", "the", "chip", "serial", "number", "and", "can", "be", "verified", "using", "the", "Simplicity", "Commander", ".", "The", "choice", "of", "reporting", "can", "be", "changed", "in", "accordance", "with", "the", "Manufacturer", "Specific", "Command", "Class", "specification", "." ]
void CC_ManufacturerSpecific_DeviceSpecificGet_handler(device_id_type_t * pDeviceIDType, device_id_format_t * pDeviceIDDataFormat, uint8_t * pDeviceIDDataLength, uint8_t * pDeviceIDData) { *pDeviceIDType = DEVICE_ID_TYPE_SERIAL_NUMBER; *pDeviceIDDataFormat = DEVICE_ID_FORMAT_BINARY; *pDeviceIDDataLength = 8; uint64_t uuID = SYSTEM_GetUnique(); DPRINTF("\r\n uuID: %x", (uint32_t)uuID); *(pDeviceIDData + 0) = (uint8_t)(uuID >> 56); *(pDeviceIDData + 1) = (uint8_t)(uuID >> 48); *(pDeviceIDData + 2) = (uint8_t)(uuID >> 40); *(pDeviceIDData + 3) = (uint8_t)(uuID >> 32); *(pDeviceIDData + 4) = (uint8_t)(uuID >> 24); *(pDeviceIDData + 5) = (uint8_t)(uuID >> 16); *(pDeviceIDData + 6) = (uint8_t)(uuID >> 8); *(pDeviceIDData + 7) = (uint8_t)(uuID >> 0); }
[ "void", "CC_ManufacturerSpecific_DeviceSpecificGet_handler", "(", "device_id_type_t", "*", "pDeviceIDType", ",", "device_id_format_t", "*", "pDeviceIDDataFormat", ",", "uint8_t", "*", "pDeviceIDDataLength", ",", "uint8_t", "*", "pDeviceIDData", ")", "{", "*", "pDeviceIDType", "=", "DEVICE_ID_TYPE_SERIAL_NUMBER", ";", "*", "pDeviceIDDataFormat", "=", "DEVICE_ID_FORMAT_BINARY", ";", "*", "pDeviceIDDataLength", "=", "8", ";", "uint64_t", "uuID", "=", "SYSTEM_GetUnique", "(", ")", ";", "DPRINTF", "(", "\"", "\\r", "\\n", "\"", ",", "(", "uint32_t", ")", "uuID", ")", ";", "*", "(", "pDeviceIDData", "+", "0", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "56", ")", ";", "*", "(", "pDeviceIDData", "+", "1", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "48", ")", ";", "*", "(", "pDeviceIDData", "+", "2", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "40", ")", ";", "*", "(", "pDeviceIDData", "+", "3", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "32", ")", ";", "*", "(", "pDeviceIDData", "+", "4", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "24", ")", ";", "*", "(", "pDeviceIDData", "+", "5", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "16", ")", ";", "*", "(", "pDeviceIDData", "+", "6", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "8", ")", ";", "*", "(", "pDeviceIDData", "+", "7", ")", "=", "(", "uint8_t", ")", "(", "uuID", ">>", "0", ")", ";", "}" ]
This function will report a serial number in a binary format according to the specification.
[ "This", "function", "will", "report", "a", "serial", "number", "in", "a", "binary", "format", "according", "to", "the", "specification", "." ]
[]
[ { "param": "pDeviceIDType", "type": "device_id_type_t" }, { "param": "pDeviceIDDataFormat", "type": "device_id_format_t" }, { "param": "pDeviceIDDataLength", "type": "uint8_t" }, { "param": "pDeviceIDData", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pDeviceIDType", "type": "device_id_type_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pDeviceIDDataFormat", "type": "device_id_format_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pDeviceIDDataLength", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pDeviceIDData", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9e15f3e65acd205720b530d71bdf8bcb7dccce10
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_btmesh_sensor_server/app_out_lcd.c
[ "Zlib" ]
C
sl_btmesh_sensor_server_on_temperature_measurement
void
void sl_btmesh_sensor_server_on_temperature_measurement(temperature_8_t temperature) { sl_status_t status = SL_STATUS_OK; if ((temperature_8_t)SL_BTMESH_SENSOR_TEMPERATURE_VALUE_IS_NOT_KNOWN == temperature) { app_log("Temperature: UNKNOWN\r\n"); status = sl_btmesh_LCD_write("Temperature: N/K ", BTMESH_WSTK_LCD_ROW_TEMPERATURE); } else { char str[LCD_ROW_LEN]; app_log("Temperature: %3d.%1d °C\r\n", INT_TEMP(temperature), FRAC_TEMP(temperature)); snprintf(str, LCD_ROW_LEN, "Temperature: %3d.%1d C", INT_TEMP(temperature), FRAC_TEMP(temperature)); status = sl_btmesh_LCD_write(str, BTMESH_WSTK_LCD_ROW_TEMPERATURE); } app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); }
/******************************************************************************* * Called when a temperature measurement is done ******************************************************************************/
Called when a temperature measurement is done
[ "Called", "when", "a", "temperature", "measurement", "is", "done" ]
void sl_btmesh_sensor_server_on_temperature_measurement(temperature_8_t temperature) { sl_status_t status = SL_STATUS_OK; if ((temperature_8_t)SL_BTMESH_SENSOR_TEMPERATURE_VALUE_IS_NOT_KNOWN == temperature) { app_log("Temperature: UNKNOWN\r\n"); status = sl_btmesh_LCD_write("Temperature: N/K ", BTMESH_WSTK_LCD_ROW_TEMPERATURE); } else { char str[LCD_ROW_LEN]; app_log("Temperature: %3d.%1d °C\r\n", INT_TEMP(temperature), FRAC_TEMP(temperature)); snprintf(str, LCD_ROW_LEN, "Temperature: %3d.%1d C", INT_TEMP(temperature), FRAC_TEMP(temperature)); status = sl_btmesh_LCD_write(str, BTMESH_WSTK_LCD_ROW_TEMPERATURE); } app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); }
[ "void", "sl_btmesh_sensor_server_on_temperature_measurement", "(", "temperature_8_t", "temperature", ")", "{", "sl_status_t", "status", "=", "SL_STATUS_OK", ";", "if", "(", "(", "temperature_8_t", ")", "SL_BTMESH_SENSOR_TEMPERATURE_VALUE_IS_NOT_KNOWN", "==", "temperature", ")", "{", "app_log", "(", "\"", "\\r", "\\n", "\"", ")", ";", "status", "=", "sl_btmesh_LCD_write", "(", "\"", "\"", ",", "BTMESH_WSTK_LCD_ROW_TEMPERATURE", ")", ";", "}", "else", "{", "char", "str", "[", "LCD_ROW_LEN", "]", ";", "app_log", "(", "\"", "r\\", "n\"", ",", "", "INT_TEMP", "(", "temperature", ")", ",", "FRAC_TEMP", "(", "temperature", ")", ")", ";", "snprintf", "(", "str", ",", "LCD_ROW_LEN", ",", "\"", "\"", ",", "INT_TEMP", "(", "temperature", ")", ",", "FRAC_TEMP", "(", "temperature", ")", ")", ";", "status", "=", "sl_btmesh_LCD_write", "(", "str", ",", "BTMESH_WSTK_LCD_ROW_TEMPERATURE", ")", ";", "}", "app_log_status_level_f", "(", "APP_LOG_LEVEL_ERROR", ",", "status", ",", "\"", "\"", ")", ";", "}" ]
Called when a temperature measurement is done
[ "Called", "when", "a", "temperature", "measurement", "is", "done" ]
[]
[ { "param": "temperature", "type": "temperature_8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "temperature", "type": "temperature_8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9e15f3e65acd205720b530d71bdf8bcb7dccce10
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_btmesh_sensor_server/app_out_lcd.c
[ "Zlib" ]
C
sl_btmesh_sensor_server_on_light_measurement
void
void sl_btmesh_sensor_server_on_light_measurement(illuminance_t light) { sl_status_t status = SL_STATUS_OK; if ((illuminance_t)SL_BTMESH_SENSOR_LIGHT_VALUE_IS_NOT_KNOWN == light) { app_log("Illuminance: UNKNOWN\r\n"); status = sl_btmesh_LCD_write("Illuminance: N/K", BTMESH_WSTK_LCD_ROW_ILLUMINANCE); } else { app_log("Illuminance: %4lu.%02lu lx\r\n", INT_ILLUM(light), FRAC_ILLUM(light)); char str[LCD_ROW_LEN]; snprintf(str, LCD_ROW_LEN, "Illuminance:%4lu.%02lx", INT_ILLUM(light), FRAC_ILLUM(light)); app_log(str); status = sl_btmesh_LCD_write(str, BTMESH_WSTK_LCD_ROW_ILLUMINANCE); } app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); }
/******************************************************************************* * Called when a light measurement is done ******************************************************************************/
Called when a light measurement is done
[ "Called", "when", "a", "light", "measurement", "is", "done" ]
void sl_btmesh_sensor_server_on_light_measurement(illuminance_t light) { sl_status_t status = SL_STATUS_OK; if ((illuminance_t)SL_BTMESH_SENSOR_LIGHT_VALUE_IS_NOT_KNOWN == light) { app_log("Illuminance: UNKNOWN\r\n"); status = sl_btmesh_LCD_write("Illuminance: N/K", BTMESH_WSTK_LCD_ROW_ILLUMINANCE); } else { app_log("Illuminance: %4lu.%02lu lx\r\n", INT_ILLUM(light), FRAC_ILLUM(light)); char str[LCD_ROW_LEN]; snprintf(str, LCD_ROW_LEN, "Illuminance:%4lu.%02lx", INT_ILLUM(light), FRAC_ILLUM(light)); app_log(str); status = sl_btmesh_LCD_write(str, BTMESH_WSTK_LCD_ROW_ILLUMINANCE); } app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); }
[ "void", "sl_btmesh_sensor_server_on_light_measurement", "(", "illuminance_t", "light", ")", "{", "sl_status_t", "status", "=", "SL_STATUS_OK", ";", "if", "(", "(", "illuminance_t", ")", "SL_BTMESH_SENSOR_LIGHT_VALUE_IS_NOT_KNOWN", "==", "light", ")", "{", "app_log", "(", "\"", "\\r", "\\n", "\"", ")", ";", "status", "=", "sl_btmesh_LCD_write", "(", "\"", "\"", ",", "BTMESH_WSTK_LCD_ROW_ILLUMINANCE", ")", ";", "}", "else", "{", "app_log", "(", "\"", "\\r", "\\n", "\"", ",", "INT_ILLUM", "(", "light", ")", ",", "FRAC_ILLUM", "(", "light", ")", ")", ";", "char", "str", "[", "LCD_ROW_LEN", "]", ";", "snprintf", "(", "str", ",", "LCD_ROW_LEN", ",", "\"", "\"", ",", "INT_ILLUM", "(", "light", ")", ",", "FRAC_ILLUM", "(", "light", ")", ")", ";", "app_log", "(", "str", ")", ";", "status", "=", "sl_btmesh_LCD_write", "(", "str", ",", "BTMESH_WSTK_LCD_ROW_ILLUMINANCE", ")", ";", "}", "app_log_status_level_f", "(", "APP_LOG_LEVEL_ERROR", ",", "status", ",", "\"", "\"", ")", ";", "}" ]
Called when a light measurement is done
[ "Called", "when", "a", "light", "measurement", "is", "done" ]
[]
[ { "param": "light", "type": "illuminance_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "light", "type": "illuminance_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9e15f3e65acd205720b530d71bdf8bcb7dccce10
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_btmesh_sensor_server/app_out_lcd.c
[ "Zlib" ]
C
sl_btmesh_sensor_server_on_people_count_measurement
void
void sl_btmesh_sensor_server_on_people_count_measurement(count16_t people) { sl_status_t status = SL_STATUS_OK; if ((count16_t)SL_BTMESH_SENSOR_PEOPLE_COUNT_VALUE_IS_NOT_KNOWN == people) { app_log("People count: UNKNOWN\r\n"); status = sl_btmesh_LCD_write("People count: N/K", BTMESH_WSTK_LCD_ROW_PEOPLE_COUNT); } else { app_log("People count: %5u\r\n", people); char str[LCD_ROW_LEN]; snprintf(str, LCD_ROW_LEN, "People count: %5u", people); status = sl_btmesh_LCD_write(str, BTMESH_WSTK_LCD_ROW_PEOPLE_COUNT); } app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); }
/******************************************************************************* * Called when a people count measurement is done ******************************************************************************/
Called when a people count measurement is done
[ "Called", "when", "a", "people", "count", "measurement", "is", "done" ]
void sl_btmesh_sensor_server_on_people_count_measurement(count16_t people) { sl_status_t status = SL_STATUS_OK; if ((count16_t)SL_BTMESH_SENSOR_PEOPLE_COUNT_VALUE_IS_NOT_KNOWN == people) { app_log("People count: UNKNOWN\r\n"); status = sl_btmesh_LCD_write("People count: N/K", BTMESH_WSTK_LCD_ROW_PEOPLE_COUNT); } else { app_log("People count: %5u\r\n", people); char str[LCD_ROW_LEN]; snprintf(str, LCD_ROW_LEN, "People count: %5u", people); status = sl_btmesh_LCD_write(str, BTMESH_WSTK_LCD_ROW_PEOPLE_COUNT); } app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); }
[ "void", "sl_btmesh_sensor_server_on_people_count_measurement", "(", "count16_t", "people", ")", "{", "sl_status_t", "status", "=", "SL_STATUS_OK", ";", "if", "(", "(", "count16_t", ")", "SL_BTMESH_SENSOR_PEOPLE_COUNT_VALUE_IS_NOT_KNOWN", "==", "people", ")", "{", "app_log", "(", "\"", "\\r", "\\n", "\"", ")", ";", "status", "=", "sl_btmesh_LCD_write", "(", "\"", "\"", ",", "BTMESH_WSTK_LCD_ROW_PEOPLE_COUNT", ")", ";", "}", "else", "{", "app_log", "(", "\"", "\\r", "\\n", "\"", ",", "people", ")", ";", "char", "str", "[", "LCD_ROW_LEN", "]", ";", "snprintf", "(", "str", ",", "LCD_ROW_LEN", ",", "\"", "\"", ",", "people", ")", ";", "status", "=", "sl_btmesh_LCD_write", "(", "str", ",", "BTMESH_WSTK_LCD_ROW_PEOPLE_COUNT", ")", ";", "}", "app_log_status_level_f", "(", "APP_LOG_LEVEL_ERROR", ",", "status", ",", "\"", "\"", ")", ";", "}" ]
Called when a people count measurement is done
[ "Called", "when", "a", "people", "count", "measurement", "is", "done" ]
[]
[ { "param": "people", "type": "count16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "people", "type": "count16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9e15f3e65acd205720b530d71bdf8bcb7dccce10
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_btmesh_sensor_server/app_out_lcd.c
[ "Zlib" ]
C
app_show_btmesh_node_provisioning_started
void
void app_show_btmesh_node_provisioning_started(uint16_t result) { app_log("BT mesh node provisioning is started (result: 0x%04x)\r\n", result); sl_status_t status = sl_btmesh_LCD_write("provisioning...", BTMESH_WSTK_LCD_ROW_STATUS); app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); (void)result; }
/******************************************************************************* * Called from sl_btmesh_on_node_provisioning_started callback in app.c ******************************************************************************/
Called from sl_btmesh_on_node_provisioning_started callback in app.c
[ "Called", "from", "sl_btmesh_on_node_provisioning_started", "callback", "in", "app", ".", "c" ]
void app_show_btmesh_node_provisioning_started(uint16_t result) { app_log("BT mesh node provisioning is started (result: 0x%04x)\r\n", result); sl_status_t status = sl_btmesh_LCD_write("provisioning...", BTMESH_WSTK_LCD_ROW_STATUS); app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); (void)result; }
[ "void", "app_show_btmesh_node_provisioning_started", "(", "uint16_t", "result", ")", "{", "app_log", "(", "\"", "\\r", "\\n", "\"", ",", "result", ")", ";", "sl_status_t", "status", "=", "sl_btmesh_LCD_write", "(", "\"", "\"", ",", "BTMESH_WSTK_LCD_ROW_STATUS", ")", ";", "app_log_status_level_f", "(", "APP_LOG_LEVEL_ERROR", ",", "status", ",", "\"", "\"", ")", ";", "(", "void", ")", "result", ";", "}" ]
Called from sl_btmesh_on_node_provisioning_started callback in app.c
[ "Called", "from", "sl_btmesh_on_node_provisioning_started", "callback", "in", "app", ".", "c" ]
[]
[ { "param": "result", "type": "uint16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "result", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9e15f3e65acd205720b530d71bdf8bcb7dccce10
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_btmesh_sensor_server/app_out_lcd.c
[ "Zlib" ]
C
app_show_btmesh_node_provisioned
void
void app_show_btmesh_node_provisioned(uint16_t address, uint32_t iv_index) { app_log("BT mesh node is provisioned (address: 0x%04x, iv_index: 0x%lx)\r\n", address, iv_index); sl_status_t status = sl_btmesh_LCD_write("provisioned", BTMESH_WSTK_LCD_ROW_STATUS); app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); (void)address; (void)iv_index; }
/******************************************************************************* * Called from sl_btmesh_on_node_provisioned callback in app.c ******************************************************************************/
Called from sl_btmesh_on_node_provisioned callback in app.c
[ "Called", "from", "sl_btmesh_on_node_provisioned", "callback", "in", "app", ".", "c" ]
void app_show_btmesh_node_provisioned(uint16_t address, uint32_t iv_index) { app_log("BT mesh node is provisioned (address: 0x%04x, iv_index: 0x%lx)\r\n", address, iv_index); sl_status_t status = sl_btmesh_LCD_write("provisioned", BTMESH_WSTK_LCD_ROW_STATUS); app_log_status_level_f(APP_LOG_LEVEL_ERROR, status, "LCD write failed"); (void)address; (void)iv_index; }
[ "void", "app_show_btmesh_node_provisioned", "(", "uint16_t", "address", ",", "uint32_t", "iv_index", ")", "{", "app_log", "(", "\"", "\\r", "\\n", "\"", ",", "address", ",", "iv_index", ")", ";", "sl_status_t", "status", "=", "sl_btmesh_LCD_write", "(", "\"", "\"", ",", "BTMESH_WSTK_LCD_ROW_STATUS", ")", ";", "app_log_status_level_f", "(", "APP_LOG_LEVEL_ERROR", ",", "status", ",", "\"", "\"", ")", ";", "(", "void", ")", "address", ";", "(", "void", ")", "iv_index", ";", "}" ]
Called from sl_btmesh_on_node_provisioned callback in app.c
[ "Called", "from", "sl_btmesh_on_node_provisioned", "callback", "in", "app", ".", "c" ]
[]
[ { "param": "address", "type": "uint16_t" }, { "param": "iv_index", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "address", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "iv_index", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
67cddf598efedba8f20a818e44d6fbe656dd322f
SiliconLabs/Gecko_SDK
protocol/openthread/platform-abstraction/efr32/radio.c
[ "Zlib" ]
C
isFilterMaskValid
bool
static bool isFilterMaskValid(uint8_t mask) { bool valid = false; #if OPENTHREAD_RADIO && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE == 1 /* Packet will be considered as a valid packet in 3 cases: * Case 1: If the packet was directed towards bcast address or bcase panid * * Case 2: If the packet was directed to right address corresponding to the panid * (If Address filter and pan filter in the received packet match). * * Case 3: We dont have either the destination addressing feild or destination PanId * in the received packet to determine if the dest address and dest pan match. */ if( ((mask & RADIO_BCAST_PANID_FILTER_MASK) || (mask & RADIO_BCAST_ADDR_FILTER_MASK)) || //Case 1 ((mask & 0x0F) == (mask >> 4)) || //Case 2 (((mask & 0x0F) == 0) || ((mask >> 4) == 0)) ) //Case 3 { valid = true; } #else (void)mask; valid = true; #endif return valid; }
/* * This API validates the received FilterMask by checking if the destination address * in the received packet corresponds to destination PanID. */
This API validates the received FilterMask by checking if the destination address in the received packet corresponds to destination PanID.
[ "This", "API", "validates", "the", "received", "FilterMask", "by", "checking", "if", "the", "destination", "address", "in", "the", "received", "packet", "corresponds", "to", "destination", "PanID", "." ]
static bool isFilterMaskValid(uint8_t mask) { bool valid = false; #if OPENTHREAD_RADIO && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE == 1 if( ((mask & RADIO_BCAST_PANID_FILTER_MASK) || (mask & RADIO_BCAST_ADDR_FILTER_MASK)) || ((mask & 0x0F) == (mask >> 4)) || (((mask & 0x0F) == 0) || ((mask >> 4) == 0)) ) { valid = true; } #else (void)mask; valid = true; #endif return valid; }
[ "static", "bool", "isFilterMaskValid", "(", "uint8_t", "mask", ")", "{", "bool", "valid", "=", "false", ";", "#if", "OPENTHREAD_RADIO", "&&", "OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE", "==", "1", "\n\n", "if", "(", "(", "(", "mask", "&", "RADIO_BCAST_PANID_FILTER_MASK", ")", "||", "(", "mask", "&", "RADIO_BCAST_ADDR_FILTER_MASK", ")", ")", "||", "(", "(", "mask", "&", "0x0F", ")", "==", "(", "mask", ">>", "4", ")", ")", "||", "(", "(", "(", "mask", "&", "0x0F", ")", "==", "0", ")", "||", "(", "(", "mask", ">>", "4", ")", "==", "0", ")", ")", ")", "{", "valid", "=", "true", ";", "}", "#else", "(", "void", ")", "mask", ";", "valid", "=", "true", ";", "#endif", "return", "valid", ";", "}" ]
This API validates the received FilterMask by checking if the destination address in the received packet corresponds to destination PanID.
[ "This", "API", "validates", "the", "received", "FilterMask", "by", "checking", "if", "the", "destination", "address", "in", "the", "received", "packet", "corresponds", "to", "destination", "PanID", "." ]
[ "/* Packet will be considered as a valid packet in 3 cases:\n * Case 1: If the packet was directed towards bcast address or bcase panid\n *\n * Case 2: If the packet was directed to right address corresponding to the panid\n * (If Address filter and pan filter in the received packet match).\n *\n * Case 3: We dont have either the destination addressing feild or destination PanId\n * in the received packet to determine if the dest address and dest pan match.\n */", "//Case 1", "//Case 2", "//Case 3" ]
[ { "param": "mask", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mask", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
67cddf598efedba8f20a818e44d6fbe656dd322f
SiliconLabs/Gecko_SDK
protocol/openthread/platform-abstraction/efr32/radio.c
[ "Zlib" ]
C
writeIeee802154EnhancedAck
bool
static bool writeIeee802154EnhancedAck(RAIL_Handle_t aRailHandle) { // RAIL will generate an Immediate ACK for us. // For an Enhanced ACK, we need to generate the whole packet ourselves. // An 802.15.4 packet from RAIL should look like: // 1/2 | 1/2 | 0/1 | 0/2 | 0/2/8 | 0/2 | 0/2/8 | 14 // PHR | MacFCF | Seq# | DstPan | DstAdr | SrcPan | SrcAdr | SecHdr // With RAIL_IEEE802154_EnableEarlyFramePending(), RAIL_EVENT_IEEE802154_DATA_REQUEST_COMMAND // is triggered after receiving through the SrcAdr field of Version 0/1 packets, // and after receiving through the SecHdr for Version 2 packets. RAIL_RxPacketInfo_t packetInfoForEnhAck; otRadioFrame receivedFrame, enhAckFrame; uint8_t receivedPsdu[IEEE802154_MAX_LENGTH]; uint8_t enhAckPsdu[IEEE802154_MAX_LENGTH]; #define EARLY_FRAME_PENDING_EXPECTED_BYTES (2U + 2U + 1U + 2U + 8U + 2U + 8U + 14U) #define FINAL_PACKET_LENGTH_WITH_IE (EARLY_FRAME_PENDING_EXPECTED_BYTES + OT_ACK_IE_MAX_SIZE) uint8_t intialPktReadBytes = readInitialPacketData(&packetInfoForEnhAck, EARLY_FRAME_PENDING_EXPECTED_BYTES, (PHY_HEADER_SIZE + 2), receivedPsdu, FINAL_PACKET_LENGTH_WITH_IE); uint8_t iid = getIidFromFilterMask(packetInfoForEnhAck.filterMask); if (intialPktReadBytes == 0U) { return true; // Nothing to read, which means generating an immediate ACK is also pointless } receivedFrame.mPsdu = receivedPsdu + PHY_HEADER_SIZE; enhAckFrame.mPsdu = enhAckPsdu + PHY_HEADER_SIZE; if (! otMacFrameIsVersion2015(&receivedFrame)) { return false; } otMacAddress aSrcAddress; uint8_t linkMetricsDataLen = 0; uint8_t *dataPtr = NULL; bool setFramePending = false; otMacFrameGetSrcAddr(&receivedFrame, &aSrcAddress); if (sIsSrcMatchEnabled && (aSrcAddress.mType != OT_MAC_ADDRESS_TYPE_NONE)) { if (aSrcAddress.mType == OT_MAC_ADDRESS_TYPE_EXTENDED) { setFramePending = (utilsSoftSrcMatchExtFindEntry(iid , &aSrcAddress.mAddress.mExtAddress) >= 0); } else { setFramePending = (utilsSoftSrcMatchShortFindEntry(iid, aSrcAddress.mAddress.mShortAddress) >= 0); } } // Generate our IE header. // Write IE data for enhanced ACK (link metrics + allocate bytes for CSL) #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE uint8_t linkMetricsData[OT_ENH_PROBING_IE_DATA_MAX_SIZE]; linkMetricsDataLen = otLinkMetricsEnhAckGenData(&aSrcAddress, sReceiveFrame.mInfo.mRxInfo.mLqi, sReceiveFrame.mInfo.mRxInfo.mRssi, linkMetricsData); if (linkMetricsDataLen > 0) { dataPtr = linkMetricsData; } #endif sAckIeDataLength = generateAckIeData(dataPtr, linkMetricsDataLen); otEXPECT(otMacFrameGenerateEnhAck(&receivedFrame, setFramePending, sAckIeData, sAckIeDataLength, &enhAckFrame) == OT_ERROR_NONE); #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE if (sCslPeriod > 0) { // Update IE data in the 802.15.4 header with the newest CSL period / phase otMacFrameSetCslIe(&enhAckFrame, (uint16_t)sCslPeriod, getCslPhase()); } #endif if (otMacFrameIsSecurityEnabled(&enhAckFrame)) { uint8_t iid = getIidFromFilterMask(packetInfoForEnhAck.filterMask); otEXPECT(radioProcessTransmitSecurity(&enhAckFrame, iid) == OT_ERROR_NONE); } // Before we're done, store some important info in reserved bits in the // MAC header (cleared later) // Check whether frame pending is set. // Check whether enhanced ACK is secured. otEXPECT((skipRxPacketLengthBytes(&packetInfoForEnhAck)) == OT_ERROR_NONE); uint8_t *macFcfPointer = ((packetInfoForEnhAck.firstPortionBytes == 0) ? (uint8_t *) packetInfoForEnhAck.lastPortionData : (uint8_t *) packetInfoForEnhAck.firstPortionData); if (otMacFrameIsSecurityEnabled(&enhAckFrame)) { *macFcfPointer |= IEEE802154_SECURED_OUTGOING_ENHANCED_ACK; } if (setFramePending) { *macFcfPointer |= IEEE802154_FRAME_PENDING_SET_IN_OUTGOING_ACK; } // Fill in PHR now that we know Enh-ACK's length if (PHY_HEADER_SIZE == 2U) // Not true till SubGhz implementation is in place { enhAckPsdu[0] = (0x08U /*FCS=2byte*/ | 0x10U /*Whiten=enabled*/); enhAckPsdu[1] = (uint8_t)(__RBIT(enhAckFrame.mLength) >> 24); } else { enhAckPsdu[0] = enhAckFrame.mLength; } RAIL_Status_t enhAckStatus = RAIL_IEEE802154_WriteEnhAck(aRailHandle, enhAckPsdu, enhAckFrame.mLength); otEXPECT(enhAckStatus == RAIL_STATUS_NO_ERROR); exit: return true; }
// Return false if we should generate an immediate ACK // Return true otherwise
Return false if we should generate an immediate ACK Return true otherwise
[ "Return", "false", "if", "we", "should", "generate", "an", "immediate", "ACK", "Return", "true", "otherwise" ]
static bool writeIeee802154EnhancedAck(RAIL_Handle_t aRailHandle) { RAIL_RxPacketInfo_t packetInfoForEnhAck; otRadioFrame receivedFrame, enhAckFrame; uint8_t receivedPsdu[IEEE802154_MAX_LENGTH]; uint8_t enhAckPsdu[IEEE802154_MAX_LENGTH]; #define EARLY_FRAME_PENDING_EXPECTED_BYTES (2U + 2U + 1U + 2U + 8U + 2U + 8U + 14U) #define FINAL_PACKET_LENGTH_WITH_IE (EARLY_FRAME_PENDING_EXPECTED_BYTES + OT_ACK_IE_MAX_SIZE) uint8_t intialPktReadBytes = readInitialPacketData(&packetInfoForEnhAck, EARLY_FRAME_PENDING_EXPECTED_BYTES, (PHY_HEADER_SIZE + 2), receivedPsdu, FINAL_PACKET_LENGTH_WITH_IE); uint8_t iid = getIidFromFilterMask(packetInfoForEnhAck.filterMask); if (intialPktReadBytes == 0U) { return true; } receivedFrame.mPsdu = receivedPsdu + PHY_HEADER_SIZE; enhAckFrame.mPsdu = enhAckPsdu + PHY_HEADER_SIZE; if (! otMacFrameIsVersion2015(&receivedFrame)) { return false; } otMacAddress aSrcAddress; uint8_t linkMetricsDataLen = 0; uint8_t *dataPtr = NULL; bool setFramePending = false; otMacFrameGetSrcAddr(&receivedFrame, &aSrcAddress); if (sIsSrcMatchEnabled && (aSrcAddress.mType != OT_MAC_ADDRESS_TYPE_NONE)) { if (aSrcAddress.mType == OT_MAC_ADDRESS_TYPE_EXTENDED) { setFramePending = (utilsSoftSrcMatchExtFindEntry(iid , &aSrcAddress.mAddress.mExtAddress) >= 0); } else { setFramePending = (utilsSoftSrcMatchShortFindEntry(iid, aSrcAddress.mAddress.mShortAddress) >= 0); } } #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE uint8_t linkMetricsData[OT_ENH_PROBING_IE_DATA_MAX_SIZE]; linkMetricsDataLen = otLinkMetricsEnhAckGenData(&aSrcAddress, sReceiveFrame.mInfo.mRxInfo.mLqi, sReceiveFrame.mInfo.mRxInfo.mRssi, linkMetricsData); if (linkMetricsDataLen > 0) { dataPtr = linkMetricsData; } #endif sAckIeDataLength = generateAckIeData(dataPtr, linkMetricsDataLen); otEXPECT(otMacFrameGenerateEnhAck(&receivedFrame, setFramePending, sAckIeData, sAckIeDataLength, &enhAckFrame) == OT_ERROR_NONE); #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE if (sCslPeriod > 0) { otMacFrameSetCslIe(&enhAckFrame, (uint16_t)sCslPeriod, getCslPhase()); } #endif if (otMacFrameIsSecurityEnabled(&enhAckFrame)) { uint8_t iid = getIidFromFilterMask(packetInfoForEnhAck.filterMask); otEXPECT(radioProcessTransmitSecurity(&enhAckFrame, iid) == OT_ERROR_NONE); } otEXPECT((skipRxPacketLengthBytes(&packetInfoForEnhAck)) == OT_ERROR_NONE); uint8_t *macFcfPointer = ((packetInfoForEnhAck.firstPortionBytes == 0) ? (uint8_t *) packetInfoForEnhAck.lastPortionData : (uint8_t *) packetInfoForEnhAck.firstPortionData); if (otMacFrameIsSecurityEnabled(&enhAckFrame)) { *macFcfPointer |= IEEE802154_SECURED_OUTGOING_ENHANCED_ACK; } if (setFramePending) { *macFcfPointer |= IEEE802154_FRAME_PENDING_SET_IN_OUTGOING_ACK; } if (PHY_HEADER_SIZE == 2U) { enhAckPsdu[0] = (0x08U | 0x10U ); enhAckPsdu[1] = (uint8_t)(__RBIT(enhAckFrame.mLength) >> 24); } else { enhAckPsdu[0] = enhAckFrame.mLength; } RAIL_Status_t enhAckStatus = RAIL_IEEE802154_WriteEnhAck(aRailHandle, enhAckPsdu, enhAckFrame.mLength); otEXPECT(enhAckStatus == RAIL_STATUS_NO_ERROR); exit: return true; }
[ "static", "bool", "writeIeee802154EnhancedAck", "(", "RAIL_Handle_t", "aRailHandle", ")", "{", "RAIL_RxPacketInfo_t", "packetInfoForEnhAck", ";", "otRadioFrame", "receivedFrame", ",", "enhAckFrame", ";", "uint8_t", "receivedPsdu", "[", "IEEE802154_MAX_LENGTH", "]", ";", "uint8_t", "enhAckPsdu", "[", "IEEE802154_MAX_LENGTH", "]", ";", "#define", "EARLY_FRAME_PENDING_EXPECTED_BYTES", " (2U + 2U + 1U + 2U + 8U + 2U + 8U + 14U)", "\n", "#define", "FINAL_PACKET_LENGTH_WITH_IE", " (EARLY_FRAME_PENDING_EXPECTED_BYTES + OT_ACK_IE_MAX_SIZE)", "\n\n", "uint8_t", "intialPktReadBytes", "=", "readInitialPacketData", "(", "&", "packetInfoForEnhAck", ",", "EARLY_FRAME_PENDING_EXPECTED_BYTES", ",", "(", "PHY_HEADER_SIZE", "+", "2", ")", ",", "receivedPsdu", ",", "FINAL_PACKET_LENGTH_WITH_IE", ")", ";", "uint8_t", "iid", "=", "getIidFromFilterMask", "(", "packetInfoForEnhAck", ".", "filterMask", ")", ";", "if", "(", "intialPktReadBytes", "==", "0U", ")", "{", "return", "true", ";", "}", "receivedFrame", ".", "mPsdu", "=", "receivedPsdu", "+", "PHY_HEADER_SIZE", ";", "enhAckFrame", ".", "mPsdu", "=", "enhAckPsdu", "+", "PHY_HEADER_SIZE", ";", "if", "(", "!", "otMacFrameIsVersion2015", "(", "&", "receivedFrame", ")", ")", "{", "return", "false", ";", "}", "otMacAddress", "aSrcAddress", ";", "uint8_t", "linkMetricsDataLen", "=", "0", ";", "uint8_t", "*", "dataPtr", "=", "NULL", ";", "bool", "setFramePending", "=", "false", ";", "otMacFrameGetSrcAddr", "(", "&", "receivedFrame", ",", "&", "aSrcAddress", ")", ";", "if", "(", "sIsSrcMatchEnabled", "&&", "(", "aSrcAddress", ".", "mType", "!=", "OT_MAC_ADDRESS_TYPE_NONE", ")", ")", "{", "if", "(", "aSrcAddress", ".", "mType", "==", "OT_MAC_ADDRESS_TYPE_EXTENDED", ")", "{", "setFramePending", "=", "(", "utilsSoftSrcMatchExtFindEntry", "(", "iid", ",", "&", "aSrcAddress", ".", "mAddress", ".", "mExtAddress", ")", ">=", "0", ")", ";", "}", "else", "{", "setFramePending", "=", "(", "utilsSoftSrcMatchShortFindEntry", "(", "iid", ",", "aSrcAddress", ".", "mAddress", ".", "mShortAddress", ")", ">=", "0", ")", ";", "}", "}", "#if", "OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE", "\n", "uint8_t", "linkMetricsData", "[", "OT_ENH_PROBING_IE_DATA_MAX_SIZE", "]", ";", "linkMetricsDataLen", "=", "otLinkMetricsEnhAckGenData", "(", "&", "aSrcAddress", ",", "sReceiveFrame", ".", "mInfo", ".", "mRxInfo", ".", "mLqi", ",", "sReceiveFrame", ".", "mInfo", ".", "mRxInfo", ".", "mRssi", ",", "linkMetricsData", ")", ";", "if", "(", "linkMetricsDataLen", ">", "0", ")", "{", "dataPtr", "=", "linkMetricsData", ";", "}", "#endif", "sAckIeDataLength", "=", "generateAckIeData", "(", "dataPtr", ",", "linkMetricsDataLen", ")", ";", "otEXPECT", "(", "otMacFrameGenerateEnhAck", "(", "&", "receivedFrame", ",", "setFramePending", ",", "sAckIeData", ",", "sAckIeDataLength", ",", "&", "enhAckFrame", ")", "==", "OT_ERROR_NONE", ")", ";", "#if", "OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE", "\n", "if", "(", "sCslPeriod", ">", "0", ")", "{", "otMacFrameSetCslIe", "(", "&", "enhAckFrame", ",", "(", "uint16_t", ")", "sCslPeriod", ",", "getCslPhase", "(", ")", ")", ";", "}", "#endif", "if", "(", "otMacFrameIsSecurityEnabled", "(", "&", "enhAckFrame", ")", ")", "{", "uint8_t", "iid", "=", "getIidFromFilterMask", "(", "packetInfoForEnhAck", ".", "filterMask", ")", ";", "otEXPECT", "(", "radioProcessTransmitSecurity", "(", "&", "enhAckFrame", ",", "iid", ")", "==", "OT_ERROR_NONE", ")", ";", "}", "otEXPECT", "(", "(", "skipRxPacketLengthBytes", "(", "&", "packetInfoForEnhAck", ")", ")", "==", "OT_ERROR_NONE", ")", ";", "uint8_t", "*", "macFcfPointer", "=", "(", "(", "packetInfoForEnhAck", ".", "firstPortionBytes", "==", "0", ")", "?", "(", "uint8_t", "*", ")", "packetInfoForEnhAck", ".", "lastPortionData", ":", "(", "uint8_t", "*", ")", "packetInfoForEnhAck", ".", "firstPortionData", ")", ";", "if", "(", "otMacFrameIsSecurityEnabled", "(", "&", "enhAckFrame", ")", ")", "{", "*", "macFcfPointer", "|=", "IEEE802154_SECURED_OUTGOING_ENHANCED_ACK", ";", "}", "if", "(", "setFramePending", ")", "{", "*", "macFcfPointer", "|=", "IEEE802154_FRAME_PENDING_SET_IN_OUTGOING_ACK", ";", "}", "if", "(", "PHY_HEADER_SIZE", "==", "2U", ")", "{", "enhAckPsdu", "[", "0", "]", "=", "(", "0x08U", "|", "0x10U", ")", ";", "enhAckPsdu", "[", "1", "]", "=", "(", "uint8_t", ")", "(", "__RBIT", "(", "enhAckFrame", ".", "mLength", ")", ">>", "24", ")", ";", "}", "else", "{", "enhAckPsdu", "[", "0", "]", "=", "enhAckFrame", ".", "mLength", ";", "}", "RAIL_Status_t", "enhAckStatus", "=", "RAIL_IEEE802154_WriteEnhAck", "(", "aRailHandle", ",", "enhAckPsdu", ",", "enhAckFrame", ".", "mLength", ")", ";", "otEXPECT", "(", "enhAckStatus", "==", "RAIL_STATUS_NO_ERROR", ")", ";", "exit", ":", "return", "true", ";", "}" ]
Return false if we should generate an immediate ACK Return true otherwise
[ "Return", "false", "if", "we", "should", "generate", "an", "immediate", "ACK", "Return", "true", "otherwise" ]
[ "// RAIL will generate an Immediate ACK for us.", "// For an Enhanced ACK, we need to generate the whole packet ourselves.", "// An 802.15.4 packet from RAIL should look like:", "// 1/2 | 1/2 | 0/1 | 0/2 | 0/2/8 | 0/2 | 0/2/8 | 14", "// PHR | MacFCF | Seq# | DstPan | DstAdr | SrcPan | SrcAdr | SecHdr", "// With RAIL_IEEE802154_EnableEarlyFramePending(), RAIL_EVENT_IEEE802154_DATA_REQUEST_COMMAND", "// is triggered after receiving through the SrcAdr field of Version 0/1 packets,", "// and after receiving through the SecHdr for Version 2 packets.", "// Nothing to read, which means generating an immediate ACK is also pointless", "// Generate our IE header.", "// Write IE data for enhanced ACK (link metrics + allocate bytes for CSL)", "// Update IE data in the 802.15.4 header with the newest CSL period / phase", "// Before we're done, store some important info in reserved bits in the", "// MAC header (cleared later)", "// Check whether frame pending is set.", "// Check whether enhanced ACK is secured.", "// Fill in PHR now that we know Enh-ACK's length", "// Not true till SubGhz implementation is in place", "/*FCS=2byte*/", "/*Whiten=enabled*/" ]
[ { "param": "aRailHandle", "type": "RAIL_Handle_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "aRailHandle", "type": "RAIL_Handle_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
99e961d29da3e255ba5b9f6a3c79ebf394dcfdcf
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_light_rail_dmp/micriumos/app_proprietary.c
[ "Zlib" ]
C
proprietary_timer_callback
void
static void proprietary_timer_callback(void *p_tmr, void *p_arg) { PP_UNUSED_PARAM(p_tmr); PP_UNUSED_PARAM(p_arg); proprietary_queue_post(PROP_TIMER_EXPIRED); }
/**************************************************************************/ /** * Proprietary timer callback. * * @param p_tmr is pointer to the user-allocated timer. * @param p_arg is argument passed when creating the timer. * * Called when timer expires *****************************************************************************/
Proprietary timer callback. @param p_tmr is pointer to the user-allocated timer. @param p_arg is argument passed when creating the timer. Called when timer expires
[ "Proprietary", "timer", "callback", ".", "@param", "p_tmr", "is", "pointer", "to", "the", "user", "-", "allocated", "timer", ".", "@param", "p_arg", "is", "argument", "passed", "when", "creating", "the", "timer", ".", "Called", "when", "timer", "expires" ]
static void proprietary_timer_callback(void *p_tmr, void *p_arg) { PP_UNUSED_PARAM(p_tmr); PP_UNUSED_PARAM(p_arg); proprietary_queue_post(PROP_TIMER_EXPIRED); }
[ "static", "void", "proprietary_timer_callback", "(", "void", "*", "p_tmr", ",", "void", "*", "p_arg", ")", "{", "PP_UNUSED_PARAM", "(", "p_tmr", ")", ";", "PP_UNUSED_PARAM", "(", "p_arg", ")", ";", "proprietary_queue_post", "(", "PROP_TIMER_EXPIRED", ")", ";", "}" ]
Proprietary timer callback.
[ "Proprietary", "timer", "callback", "." ]
[]
[ { "param": "p_tmr", "type": "void" }, { "param": "p_arg", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "p_tmr", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p_arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
99e961d29da3e255ba5b9f6a3c79ebf394dcfdcf
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_light_rail_dmp/micriumos/app_proprietary.c
[ "Zlib" ]
C
proprietaryTxPacket
void
static void proprietaryTxPacket(prop_pkt pktType) { RAIL_SchedulerInfo_t schedulerInfo; RAIL_Status_t res; RAIL_Handle_t rail_handle = sl_rail_util_get_handle(SL_RAIL_UTIL_HANDLE_INST0); // This assumes the Tx time is around 200us schedulerInfo = (RAIL_SchedulerInfo_t){ .priority = 100, .slipTime = 100000, .transactionTime = 200 }; // address of light Mem_Copy((void *)&data_packet[PACKET_HEADER_LEN], (void *)demo.own_addr.addr, sizeof(demo.own_addr.addr)); // light role data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; data_packet[LIGHT_CONTROL_DATA_BYTE] |= (DEMO_CONTROL_ROLE_LIGHT << DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT_SHIFT) & DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; // advertisement packet if (PROP_PKT_ADVERTISE == pktType) { data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; data_packet[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_ADVERTISE << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; // status packet } else if (PROP_PKT_STATUS == pktType) { data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; data_packet[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_LIGHT_STATE_REPORT << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~0x01; data_packet[LIGHT_CONTROL_DATA_BYTE] |= (uint8_t)demo.light; } else { } RAIL_WriteTxFifo((RAIL_Handle_t)rail_handle, data_packet, sizeof(data_packet), true); res = RAIL_StartTx((RAIL_Handle_t)rail_handle, 0, RAIL_TX_OPTIONS_DEFAULT, &schedulerInfo); if (res != RAIL_STATUS_NO_ERROR) { // Try once to resend the packet 100ms later in case of error RAIL_ScheduleTxConfig_t scheduledTxConfig = { .when = RAIL_GetTime() + 100000, .mode = RAIL_TIME_ABSOLUTE }; // Transmit this packet at the specified time or up to 50 ms late res = RAIL_StartScheduledTx((RAIL_Handle_t)sl_rail_util_get_handle(SL_RAIL_UTIL_HANDLE_INST0), 0, RAIL_TX_OPTIONS_DEFAULT, &scheduledTxConfig, &schedulerInfo); } }
/**************************************************************************/ /** * Proprietary packet send. * * @param pktType Packet type * * Sends a packet using RAIL. The data shall be in data_packet *****************************************************************************/
Proprietary packet send. @param pktType Packet type Sends a packet using RAIL. The data shall be in data_packet
[ "Proprietary", "packet", "send", ".", "@param", "pktType", "Packet", "type", "Sends", "a", "packet", "using", "RAIL", ".", "The", "data", "shall", "be", "in", "data_packet" ]
static void proprietaryTxPacket(prop_pkt pktType) { RAIL_SchedulerInfo_t schedulerInfo; RAIL_Status_t res; RAIL_Handle_t rail_handle = sl_rail_util_get_handle(SL_RAIL_UTIL_HANDLE_INST0); schedulerInfo = (RAIL_SchedulerInfo_t){ .priority = 100, .slipTime = 100000, .transactionTime = 200 }; Mem_Copy((void *)&data_packet[PACKET_HEADER_LEN], (void *)demo.own_addr.addr, sizeof(demo.own_addr.addr)); data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; data_packet[LIGHT_CONTROL_DATA_BYTE] |= (DEMO_CONTROL_ROLE_LIGHT << DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT_SHIFT) & DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; if (PROP_PKT_ADVERTISE == pktType) { data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; data_packet[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_ADVERTISE << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; } else if (PROP_PKT_STATUS == pktType) { data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; data_packet[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_LIGHT_STATE_REPORT << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; data_packet[LIGHT_CONTROL_DATA_BYTE] &= ~0x01; data_packet[LIGHT_CONTROL_DATA_BYTE] |= (uint8_t)demo.light; } else { } RAIL_WriteTxFifo((RAIL_Handle_t)rail_handle, data_packet, sizeof(data_packet), true); res = RAIL_StartTx((RAIL_Handle_t)rail_handle, 0, RAIL_TX_OPTIONS_DEFAULT, &schedulerInfo); if (res != RAIL_STATUS_NO_ERROR) { RAIL_ScheduleTxConfig_t scheduledTxConfig = { .when = RAIL_GetTime() + 100000, .mode = RAIL_TIME_ABSOLUTE }; res = RAIL_StartScheduledTx((RAIL_Handle_t)sl_rail_util_get_handle(SL_RAIL_UTIL_HANDLE_INST0), 0, RAIL_TX_OPTIONS_DEFAULT, &scheduledTxConfig, &schedulerInfo); } }
[ "static", "void", "proprietaryTxPacket", "(", "prop_pkt", "pktType", ")", "{", "RAIL_SchedulerInfo_t", "schedulerInfo", ";", "RAIL_Status_t", "res", ";", "RAIL_Handle_t", "rail_handle", "=", "sl_rail_util_get_handle", "(", "SL_RAIL_UTIL_HANDLE_INST0", ")", ";", "schedulerInfo", "=", "(", "RAIL_SchedulerInfo_t", ")", "{", ".", "priority", "=", "100", ",", ".", "slipTime", "=", "100000", ",", ".", "transactionTime", "=", "200", "}", ";", "Mem_Copy", "(", "(", "void", "*", ")", "&", "data_packet", "[", "PACKET_HEADER_LEN", "]", ",", "(", "void", "*", ")", "demo", ".", "own_addr", ".", "addr", ",", "sizeof", "(", "demo", ".", "own_addr", ".", "addr", ")", ")", ";", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT", ";", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "DEMO_CONTROL_ROLE_LIGHT", "<<", "DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT_SHIFT", ")", "&", "DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT", ";", "if", "(", "PROP_PKT_ADVERTISE", "==", "pktType", ")", "{", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "(", "uint8_t", ")", "DEMO_CONTROL_CMD_ADVERTISE", "<<", "DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT", ")", "&", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "}", "else", "if", "(", "PROP_PKT_STATUS", "==", "pktType", ")", "{", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "(", "uint8_t", ")", "DEMO_CONTROL_CMD_LIGHT_STATE_REPORT", "<<", "DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT", ")", "&", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "0x01", ";", "data_packet", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "uint8_t", ")", "demo", ".", "light", ";", "}", "else", "{", "}", "RAIL_WriteTxFifo", "(", "(", "RAIL_Handle_t", ")", "rail_handle", ",", "data_packet", ",", "sizeof", "(", "data_packet", ")", ",", "true", ")", ";", "res", "=", "RAIL_StartTx", "(", "(", "RAIL_Handle_t", ")", "rail_handle", ",", "0", ",", "RAIL_TX_OPTIONS_DEFAULT", ",", "&", "schedulerInfo", ")", ";", "if", "(", "res", "!=", "RAIL_STATUS_NO_ERROR", ")", "{", "RAIL_ScheduleTxConfig_t", "scheduledTxConfig", "=", "{", ".", "when", "=", "RAIL_GetTime", "(", ")", "+", "100000", ",", ".", "mode", "=", "RAIL_TIME_ABSOLUTE", "}", ";", "res", "=", "RAIL_StartScheduledTx", "(", "(", "RAIL_Handle_t", ")", "sl_rail_util_get_handle", "(", "SL_RAIL_UTIL_HANDLE_INST0", ")", ",", "0", ",", "RAIL_TX_OPTIONS_DEFAULT", ",", "&", "scheduledTxConfig", ",", "&", "schedulerInfo", ")", ";", "}", "}" ]
Proprietary packet send.
[ "Proprietary", "packet", "send", "." ]
[ "// This assumes the Tx time is around 200us", "// address of light", "// light role", "// advertisement packet", "// status packet", "// Try once to resend the packet 100ms later in case of error", "// Transmit this packet at the specified time or up to 50 ms late" ]
[ { "param": "pktType", "type": "prop_pkt" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pktType", "type": "prop_pkt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c014010e2d4a5717c615d9068a32e84d83239645
SiliconLabs/Gecko_SDK
app/bluetooth/example_host/positioning/app.c
[ "Zlib" ]
C
aoa_loc_on_position_ready
void
void aoa_loc_on_position_ready(aoa_asset_tag_t *tag) { sl_status_t sc; char *payload; const char topic_template[] = AOA_TOPIC_POSITION_PRINT; char topic[sizeof(topic_template) + sizeof(aoa_id_t) + sizeof(aoa_id_t)]; // Compile topic. snprintf(topic, sizeof(topic), topic_template, positioning_id, tag->id); // Compile payload. sc = aoa_serialize_position(&tag->position, &payload); app_assert_status(sc); sc = mqtt_publish(&mqtt_handle, topic, payload, false); app_assert_status(sc); // Clean up. free(payload); }
/**************************************************************************/ /** * Callback from the locator engine, position calculation done. *****************************************************************************/
Callback from the locator engine, position calculation done.
[ "Callback", "from", "the", "locator", "engine", "position", "calculation", "done", "." ]
void aoa_loc_on_position_ready(aoa_asset_tag_t *tag) { sl_status_t sc; char *payload; const char topic_template[] = AOA_TOPIC_POSITION_PRINT; char topic[sizeof(topic_template) + sizeof(aoa_id_t) + sizeof(aoa_id_t)]; snprintf(topic, sizeof(topic), topic_template, positioning_id, tag->id); sc = aoa_serialize_position(&tag->position, &payload); app_assert_status(sc); sc = mqtt_publish(&mqtt_handle, topic, payload, false); app_assert_status(sc); free(payload); }
[ "void", "aoa_loc_on_position_ready", "(", "aoa_asset_tag_t", "*", "tag", ")", "{", "sl_status_t", "sc", ";", "char", "*", "payload", ";", "const", "char", "topic_template", "[", "]", "=", "AOA_TOPIC_POSITION_PRINT", ";", "char", "topic", "[", "sizeof", "(", "topic_template", ")", "+", "sizeof", "(", "aoa_id_t", ")", "+", "sizeof", "(", "aoa_id_t", ")", "]", ";", "snprintf", "(", "topic", ",", "sizeof", "(", "topic", ")", ",", "topic_template", ",", "positioning_id", ",", "tag", "->", "id", ")", ";", "sc", "=", "aoa_serialize_position", "(", "&", "tag", "->", "position", ",", "&", "payload", ")", ";", "app_assert_status", "(", "sc", ")", ";", "sc", "=", "mqtt_publish", "(", "&", "mqtt_handle", ",", "topic", ",", "payload", ",", "false", ")", ";", "app_assert_status", "(", "sc", ")", ";", "free", "(", "payload", ")", ";", "}" ]
Callback from the locator engine, position calculation done.
[ "Callback", "from", "the", "locator", "engine", "position", "calculation", "done", "." ]
[ "// Compile topic.", "// Compile payload.", "// Clean up." ]
[ { "param": "tag", "type": "aoa_asset_tag_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "tag", "type": "aoa_asset_tag_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
be90187ce6bf1d18671f14f1e4d4f83f0e63375c
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_light_std_dmp/freertos/app_proprietary.c
[ "Zlib" ]
C
app_set_rail_tx_fifo
int16_t
int16_t app_set_rail_tx_fifo(RAIL_Handle_t rail_handle) { // RAIL FIFO size allocated by RAIL_SetTxFifo() call uint16_t allocated_tx_fifo_size = 0; allocated_tx_fifo_size = RAIL_SetTxFifo(rail_handle, tx_fifo.fifo, 0u, RAIL_FIFO_SIZE); app_assert(allocated_tx_fifo_size == RAIL_FIFO_SIZE, "RAIL_SetTxFifo() failed to allocate a large enough fifo" " (%d bytes instead of %d bytes%s)", allocated_tx_fifo_size, RAIL_FIFO_SIZE, APP_LOG_NEW_LINE); if (allocated_tx_fifo_size != RAIL_FIFO_SIZE) { return -1; } return 0; }
// ----------------------------------------------------------------------------- // Public functions /****************************************************************************** * Initialization of RAIL TX FIFO *****************************************************************************/
Public functions Initialization of RAIL TX FIFO
[ "Public", "functions", "Initialization", "of", "RAIL", "TX", "FIFO" ]
int16_t app_set_rail_tx_fifo(RAIL_Handle_t rail_handle) { uint16_t allocated_tx_fifo_size = 0; allocated_tx_fifo_size = RAIL_SetTxFifo(rail_handle, tx_fifo.fifo, 0u, RAIL_FIFO_SIZE); app_assert(allocated_tx_fifo_size == RAIL_FIFO_SIZE, "RAIL_SetTxFifo() failed to allocate a large enough fifo" " (%d bytes instead of %d bytes%s)", allocated_tx_fifo_size, RAIL_FIFO_SIZE, APP_LOG_NEW_LINE); if (allocated_tx_fifo_size != RAIL_FIFO_SIZE) { return -1; } return 0; }
[ "int16_t", "app_set_rail_tx_fifo", "(", "RAIL_Handle_t", "rail_handle", ")", "{", "uint16_t", "allocated_tx_fifo_size", "=", "0", ";", "allocated_tx_fifo_size", "=", "RAIL_SetTxFifo", "(", "rail_handle", ",", "tx_fifo", ".", "fifo", ",", "0u", ",", "RAIL_FIFO_SIZE", ")", ";", "app_assert", "(", "allocated_tx_fifo_size", "==", "RAIL_FIFO_SIZE", ",", "\"", "\"", "\"", "\"", ",", "allocated_tx_fifo_size", ",", "RAIL_FIFO_SIZE", ",", "APP_LOG_NEW_LINE", ")", ";", "if", "(", "allocated_tx_fifo_size", "!=", "RAIL_FIFO_SIZE", ")", "{", "return", "-1", ";", "}", "return", "0", ";", "}" ]
Public functions Initialization of RAIL TX FIFO
[ "Public", "functions", "Initialization", "of", "RAIL", "TX", "FIFO" ]
[ "// RAIL FIFO size allocated by RAIL_SetTxFifo() call" ]
[ { "param": "rail_handle", "type": "RAIL_Handle_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "rail_handle", "type": "RAIL_Handle_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
be90187ce6bf1d18671f14f1e4d4f83f0e63375c
SiliconLabs/Gecko_SDK
app/bluetooth/example/soc_light_std_dmp/freertos/app_proprietary.c
[ "Zlib" ]
C
standardTxPacket
void
static void standardTxPacket(prop_pkt pktType) { uint16_t packet_size; RAIL_SchedulerInfo_t schedulerInfo; RAIL_Status_t rail_status; RAIL_Handle_t rail_handle = sl_flex_util_get_handle(); // This assumes the Tx time is around 200us schedulerInfo = (RAIL_SchedulerInfo_t){ .priority = 100, .slipTime = 100000, .transactionTime = 200 }; // address of light memcpy((void *)&tx_payload.fifo[PACKET_HEADER_LEN], (void *)demo.own_addr.addr, sizeof(demo.own_addr.addr)); // light role tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= (DEMO_CONTROL_ROLE_LIGHT << DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT_SHIFT) & DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; // advertisement packet if (PROP_PKT_ADVERTISE == pktType) { tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_ADVERTISE << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; // status packet } else if (PROP_PKT_STATUS == pktType) { tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_LIGHT_STATE_REPORT << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~0x01; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= (uint8_t)demo.light; } else { } #ifdef SL_CATALOG_FLEX_IEEE802154_SUPPORT_PRESENT // Prepare packet sl_flex_ieee802154_prepare_sending(&tx_frame, (uint8_t *)tx_payload.fifo, sizeof(tx_payload.fifo)); // packs the data frame using the parameter information and the packed // frame is copied into the fifo (void)sl_flex_ieee802154_pack_data_frame(sl_flex_ieee802154_get_std(), &tx_frame, &packet_size, tx_frame_buff); // Send packet // sets the tx options based on the current ACK settings (auto-ACK enabled?) rail_status = sl_flex_ieee802154_transmission(rail_handle, tx_frame_buff, packet_size); if (rail_status != RAIL_STATUS_NO_ERROR) { app_log_warning("sl_flex_ieee802154_transmission() status: %d", rail_status); app_log_nl(); } #elif defined SL_CATALOG_FLEX_BLE_SUPPORT_PRESENT sl_flex_ble_advertising_packet_t *ble_send_packet; // Prepare packet // set ble_send_packet pointer to tx app buff ble_send_packet = sl_flex_ble_get_packet(tx_frame_buff); sl_flex_ble_prepare_packet(ble_send_packet, tx_payload.fifo, sizeof(tx_payload.fifo)); packet_size = sl_flex_ble_get_packet_size(ble_send_packet); // Send Packet rail_status = RAIL_WriteTxFifo(rail_handle, tx_frame_buff, packet_size, true); if (rail_status != packet_size) { app_log_warning("BLE RAIL_WriteTxFifo status: %d", rail_status); app_log_nl(); } rail_status = RAIL_StartTx(rail_handle, BLE_CHANNEL, RAIL_TX_OPTIONS_DEFAULT, NULL); if (rail_status != RAIL_STATUS_NO_ERROR) { app_log_warning("BLE RAIL_StartTx status: %d", rail_status); app_log_nl(); } #endif if (rail_status != RAIL_STATUS_NO_ERROR) { // Try once to resend the packet 100ms later in case of error RAIL_ScheduleTxConfig_t scheduledTxConfig = { .when = RAIL_GetTime() + 100000, .mode = RAIL_TIME_ABSOLUTE }; // Transmit this packet at the specified time or up to 50 ms late rail_status = RAIL_StartScheduledTx((RAIL_Handle_t)sl_flex_util_get_handle(), 0, RAIL_TX_OPTIONS_DEFAULT, &scheduledTxConfig, &schedulerInfo); } }
/**************************************************************************/ /** * Proprietary packet send. * * @param pktType Packet type * * Sends a packet using standard protocol. The data shall be in tx_payload *****************************************************************************/
Proprietary packet send. @param pktType Packet type Sends a packet using standard protocol. The data shall be in tx_payload
[ "Proprietary", "packet", "send", ".", "@param", "pktType", "Packet", "type", "Sends", "a", "packet", "using", "standard", "protocol", ".", "The", "data", "shall", "be", "in", "tx_payload" ]
static void standardTxPacket(prop_pkt pktType) { uint16_t packet_size; RAIL_SchedulerInfo_t schedulerInfo; RAIL_Status_t rail_status; RAIL_Handle_t rail_handle = sl_flex_util_get_handle(); schedulerInfo = (RAIL_SchedulerInfo_t){ .priority = 100, .slipTime = 100000, .transactionTime = 200 }; memcpy((void *)&tx_payload.fifo[PACKET_HEADER_LEN], (void *)demo.own_addr.addr, sizeof(demo.own_addr.addr)); tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= (DEMO_CONTROL_ROLE_LIGHT << DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT_SHIFT) & DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT; if (PROP_PKT_ADVERTISE == pktType) { tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_ADVERTISE << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; } else if (PROP_PKT_STATUS == pktType) { tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~DEMO_CONTROL_PAYLOAD_CMD_MASK; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= ((uint8_t)DEMO_CONTROL_CMD_LIGHT_STATE_REPORT << DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT) & DEMO_CONTROL_PAYLOAD_CMD_MASK; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] &= ~0x01; tx_payload.fifo[LIGHT_CONTROL_DATA_BYTE] |= (uint8_t)demo.light; } else { } #ifdef SL_CATALOG_FLEX_IEEE802154_SUPPORT_PRESENT sl_flex_ieee802154_prepare_sending(&tx_frame, (uint8_t *)tx_payload.fifo, sizeof(tx_payload.fifo)); (void)sl_flex_ieee802154_pack_data_frame(sl_flex_ieee802154_get_std(), &tx_frame, &packet_size, tx_frame_buff); rail_status = sl_flex_ieee802154_transmission(rail_handle, tx_frame_buff, packet_size); if (rail_status != RAIL_STATUS_NO_ERROR) { app_log_warning("sl_flex_ieee802154_transmission() status: %d", rail_status); app_log_nl(); } #elif defined SL_CATALOG_FLEX_BLE_SUPPORT_PRESENT sl_flex_ble_advertising_packet_t *ble_send_packet; ble_send_packet = sl_flex_ble_get_packet(tx_frame_buff); sl_flex_ble_prepare_packet(ble_send_packet, tx_payload.fifo, sizeof(tx_payload.fifo)); packet_size = sl_flex_ble_get_packet_size(ble_send_packet); rail_status = RAIL_WriteTxFifo(rail_handle, tx_frame_buff, packet_size, true); if (rail_status != packet_size) { app_log_warning("BLE RAIL_WriteTxFifo status: %d", rail_status); app_log_nl(); } rail_status = RAIL_StartTx(rail_handle, BLE_CHANNEL, RAIL_TX_OPTIONS_DEFAULT, NULL); if (rail_status != RAIL_STATUS_NO_ERROR) { app_log_warning("BLE RAIL_StartTx status: %d", rail_status); app_log_nl(); } #endif if (rail_status != RAIL_STATUS_NO_ERROR) { RAIL_ScheduleTxConfig_t scheduledTxConfig = { .when = RAIL_GetTime() + 100000, .mode = RAIL_TIME_ABSOLUTE }; rail_status = RAIL_StartScheduledTx((RAIL_Handle_t)sl_flex_util_get_handle(), 0, RAIL_TX_OPTIONS_DEFAULT, &scheduledTxConfig, &schedulerInfo); } }
[ "static", "void", "standardTxPacket", "(", "prop_pkt", "pktType", ")", "{", "uint16_t", "packet_size", ";", "RAIL_SchedulerInfo_t", "schedulerInfo", ";", "RAIL_Status_t", "rail_status", ";", "RAIL_Handle_t", "rail_handle", "=", "sl_flex_util_get_handle", "(", ")", ";", "schedulerInfo", "=", "(", "RAIL_SchedulerInfo_t", ")", "{", ".", "priority", "=", "100", ",", ".", "slipTime", "=", "100000", ",", ".", "transactionTime", "=", "200", "}", ";", "memcpy", "(", "(", "void", "*", ")", "&", "tx_payload", ".", "fifo", "[", "PACKET_HEADER_LEN", "]", ",", "(", "void", "*", ")", "demo", ".", "own_addr", ".", "addr", ",", "sizeof", "(", "demo", ".", "own_addr", ".", "addr", ")", ")", ";", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT", ";", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "DEMO_CONTROL_ROLE_LIGHT", "<<", "DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT_SHIFT", ")", "&", "DEMO_CONTROL_PAYLOAD_SRC_ROLE_BIT", ";", "if", "(", "PROP_PKT_ADVERTISE", "==", "pktType", ")", "{", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "(", "uint8_t", ")", "DEMO_CONTROL_CMD_ADVERTISE", "<<", "DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT", ")", "&", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "}", "else", "if", "(", "PROP_PKT_STATUS", "==", "pktType", ")", "{", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "(", "uint8_t", ")", "DEMO_CONTROL_CMD_LIGHT_STATE_REPORT", "<<", "DEMO_CONTROL_PAYLOAD_CMD_MASK_SHIFT", ")", "&", "DEMO_CONTROL_PAYLOAD_CMD_MASK", ";", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "&=", "~", "0x01", ";", "tx_payload", ".", "fifo", "[", "LIGHT_CONTROL_DATA_BYTE", "]", "|=", "(", "uint8_t", ")", "demo", ".", "light", ";", "}", "else", "{", "}", "#ifdef", "SL_CATALOG_FLEX_IEEE802154_SUPPORT_PRESENT", "sl_flex_ieee802154_prepare_sending", "(", "&", "tx_frame", ",", "(", "uint8_t", "*", ")", "tx_payload", ".", "fifo", ",", "sizeof", "(", "tx_payload", ".", "fifo", ")", ")", ";", "(", "void", ")", "sl_flex_ieee802154_pack_data_frame", "(", "sl_flex_ieee802154_get_std", "(", ")", ",", "&", "tx_frame", ",", "&", "packet_size", ",", "tx_frame_buff", ")", ";", "rail_status", "=", "sl_flex_ieee802154_transmission", "(", "rail_handle", ",", "tx_frame_buff", ",", "packet_size", ")", ";", "if", "(", "rail_status", "!=", "RAIL_STATUS_NO_ERROR", ")", "{", "app_log_warning", "(", "\"", "\"", ",", "rail_status", ")", ";", "app_log_nl", "(", ")", ";", "}", "#elif", "defined", "SL_CATALOG_FLEX_BLE_SUPPORT_PRESENT", "\n", "sl_flex_ble_advertising_packet_t", "*", "ble_send_packet", ";", "ble_send_packet", "=", "sl_flex_ble_get_packet", "(", "tx_frame_buff", ")", ";", "sl_flex_ble_prepare_packet", "(", "ble_send_packet", ",", "tx_payload", ".", "fifo", ",", "sizeof", "(", "tx_payload", ".", "fifo", ")", ")", ";", "packet_size", "=", "sl_flex_ble_get_packet_size", "(", "ble_send_packet", ")", ";", "rail_status", "=", "RAIL_WriteTxFifo", "(", "rail_handle", ",", "tx_frame_buff", ",", "packet_size", ",", "true", ")", ";", "if", "(", "rail_status", "!=", "packet_size", ")", "{", "app_log_warning", "(", "\"", "\"", ",", "rail_status", ")", ";", "app_log_nl", "(", ")", ";", "}", "rail_status", "=", "RAIL_StartTx", "(", "rail_handle", ",", "BLE_CHANNEL", ",", "RAIL_TX_OPTIONS_DEFAULT", ",", "NULL", ")", ";", "if", "(", "rail_status", "!=", "RAIL_STATUS_NO_ERROR", ")", "{", "app_log_warning", "(", "\"", "\"", ",", "rail_status", ")", ";", "app_log_nl", "(", ")", ";", "}", "#endif", "if", "(", "rail_status", "!=", "RAIL_STATUS_NO_ERROR", ")", "{", "RAIL_ScheduleTxConfig_t", "scheduledTxConfig", "=", "{", ".", "when", "=", "RAIL_GetTime", "(", ")", "+", "100000", ",", ".", "mode", "=", "RAIL_TIME_ABSOLUTE", "}", ";", "rail_status", "=", "RAIL_StartScheduledTx", "(", "(", "RAIL_Handle_t", ")", "sl_flex_util_get_handle", "(", ")", ",", "0", ",", "RAIL_TX_OPTIONS_DEFAULT", ",", "&", "scheduledTxConfig", ",", "&", "schedulerInfo", ")", ";", "}", "}" ]
Proprietary packet send.
[ "Proprietary", "packet", "send", "." ]
[ "// This assumes the Tx time is around 200us", "// address of light", "// light role", "// advertisement packet", "// status packet", "// Prepare packet", "// packs the data frame using the parameter information and the packed", "// frame is copied into the fifo", "// Send packet", "// sets the tx options based on the current ACK settings (auto-ACK enabled?)", "// Prepare packet", "// set ble_send_packet pointer to tx app buff", "// Send Packet", "// Try once to resend the packet 100ms later in case of error", "// Transmit this packet at the specified time or up to 50 ms late" ]
[ { "param": "pktType", "type": "prop_pkt" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pktType", "type": "prop_pkt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4b264f8ff054523f474f988a26963939d5a78852
nrspruit/ompi
ompi/mca/rte/pmix/rte_pmix_module.c
[ "BSD-3-Clause-Open-MPI" ]
C
ompi_rte_wait_for_debugger
void
void ompi_rte_wait_for_debugger(void) { int debugger; opal_list_t *codes, directives; opal_value_t *kv; char *evar; int time; /* check PMIx to see if we are under a debugger */ debugger = pmix_in_parallel_debugger; if (1 == MPIR_being_debugged) { debugger = 1; } if (!debugger && NULL == getenv("PMIX_TEST_DEBUGGER_ATTACH")) { /* if not, just return */ return; } /* if we are being debugged, then we need to find * the correct plug-ins */ ompi_debugger_setup_dlls(); if (NULL != (evar = getenv("PMIX_TEST_DEBUGGER_SLEEP"))) { time = strtol(evar, NULL, 10); sleep(time); return; } /* register an event handler for the PMIX_ERR_DEBUGGER_RELEASE event */ codes = OBJ_NEW(opal_list_t); kv = OBJ_NEW(opal_value_t); kv->key = strdup("errorcode"); kv->type = OPAL_INT; kv->data.integer = OPAL_ERR_DEBUGGER_RELEASE; opal_list_append(codes, &kv->super); OBJ_CONSTRUCT(&directives, opal_list_t); kv = OBJ_NEW(opal_value_t); kv->key = strdup(OPAL_PMIX_EVENT_HDLR_NAME); kv->type = OPAL_STRING; kv->data.string = strdup("MPI-DEBUGGER-ATTACH"); opal_list_append(&directives, &kv->super); opal_pmix.register_evhandler(codes, &directives, _release_fn, _register_fn, codes); /* let the MPI progress engine run while we wait for registration to complete */ OMPI_WAIT_FOR_COMPLETION(debugger_register_active); OPAL_LIST_DESTRUCT(&directives); /* let the MPI progress engine run while we wait for debugger release */ OMPI_WAIT_FOR_COMPLETION(debugger_event_active); /* deregister the event handler */ opal_pmix.deregister_evhandler(handler, NULL, NULL); }
/* * Wait for a debugger if asked. We support two ways of waiting for * attaching debuggers -- see big comment in * pmix/tools/pmixrun/debuggers.c explaining the two scenarios. */
Wait for a debugger if asked. We support two ways of waiting for attaching debuggers -- see big comment in pmix/tools/pmixrun/debuggers.c explaining the two scenarios.
[ "Wait", "for", "a", "debugger", "if", "asked", ".", "We", "support", "two", "ways", "of", "waiting", "for", "attaching", "debuggers", "--", "see", "big", "comment", "in", "pmix", "/", "tools", "/", "pmixrun", "/", "debuggers", ".", "c", "explaining", "the", "two", "scenarios", "." ]
void ompi_rte_wait_for_debugger(void) { int debugger; opal_list_t *codes, directives; opal_value_t *kv; char *evar; int time; debugger = pmix_in_parallel_debugger; if (1 == MPIR_being_debugged) { debugger = 1; } if (!debugger && NULL == getenv("PMIX_TEST_DEBUGGER_ATTACH")) { return; } ompi_debugger_setup_dlls(); if (NULL != (evar = getenv("PMIX_TEST_DEBUGGER_SLEEP"))) { time = strtol(evar, NULL, 10); sleep(time); return; } codes = OBJ_NEW(opal_list_t); kv = OBJ_NEW(opal_value_t); kv->key = strdup("errorcode"); kv->type = OPAL_INT; kv->data.integer = OPAL_ERR_DEBUGGER_RELEASE; opal_list_append(codes, &kv->super); OBJ_CONSTRUCT(&directives, opal_list_t); kv = OBJ_NEW(opal_value_t); kv->key = strdup(OPAL_PMIX_EVENT_HDLR_NAME); kv->type = OPAL_STRING; kv->data.string = strdup("MPI-DEBUGGER-ATTACH"); opal_list_append(&directives, &kv->super); opal_pmix.register_evhandler(codes, &directives, _release_fn, _register_fn, codes); OMPI_WAIT_FOR_COMPLETION(debugger_register_active); OPAL_LIST_DESTRUCT(&directives); OMPI_WAIT_FOR_COMPLETION(debugger_event_active); opal_pmix.deregister_evhandler(handler, NULL, NULL); }
[ "void", "ompi_rte_wait_for_debugger", "(", "void", ")", "{", "int", "debugger", ";", "opal_list_t", "*", "codes", ",", "directives", ";", "opal_value_t", "*", "kv", ";", "char", "*", "evar", ";", "int", "time", ";", "debugger", "=", "pmix_in_parallel_debugger", ";", "if", "(", "1", "==", "MPIR_being_debugged", ")", "{", "debugger", "=", "1", ";", "}", "if", "(", "!", "debugger", "&&", "NULL", "==", "getenv", "(", "\"", "\"", ")", ")", "{", "return", ";", "}", "ompi_debugger_setup_dlls", "(", ")", ";", "if", "(", "NULL", "!=", "(", "evar", "=", "getenv", "(", "\"", "\"", ")", ")", ")", "{", "time", "=", "strtol", "(", "evar", ",", "NULL", ",", "10", ")", ";", "sleep", "(", "time", ")", ";", "return", ";", "}", "codes", "=", "OBJ_NEW", "(", "opal_list_t", ")", ";", "kv", "=", "OBJ_NEW", "(", "opal_value_t", ")", ";", "kv", "->", "key", "=", "strdup", "(", "\"", "\"", ")", ";", "kv", "->", "type", "=", "OPAL_INT", ";", "kv", "->", "data", ".", "integer", "=", "OPAL_ERR_DEBUGGER_RELEASE", ";", "opal_list_append", "(", "codes", ",", "&", "kv", "->", "super", ")", ";", "OBJ_CONSTRUCT", "(", "&", "directives", ",", "opal_list_t", ")", ";", "kv", "=", "OBJ_NEW", "(", "opal_value_t", ")", ";", "kv", "->", "key", "=", "strdup", "(", "OPAL_PMIX_EVENT_HDLR_NAME", ")", ";", "kv", "->", "type", "=", "OPAL_STRING", ";", "kv", "->", "data", ".", "string", "=", "strdup", "(", "\"", "\"", ")", ";", "opal_list_append", "(", "&", "directives", ",", "&", "kv", "->", "super", ")", ";", "opal_pmix", ".", "register_evhandler", "(", "codes", ",", "&", "directives", ",", "_release_fn", ",", "_register_fn", ",", "codes", ")", ";", "OMPI_WAIT_FOR_COMPLETION", "(", "debugger_register_active", ")", ";", "OPAL_LIST_DESTRUCT", "(", "&", "directives", ")", ";", "OMPI_WAIT_FOR_COMPLETION", "(", "debugger_event_active", ")", ";", "opal_pmix", ".", "deregister_evhandler", "(", "handler", ",", "NULL", ",", "NULL", ")", ";", "}" ]
Wait for a debugger if asked.
[ "Wait", "for", "a", "debugger", "if", "asked", "." ]
[ "/* check PMIx to see if we are under a debugger */", "/* if not, just return */", "/* if we are being debugged, then we need to find\n * the correct plug-ins\n */", "/* register an event handler for the PMIX_ERR_DEBUGGER_RELEASE event */", "/* let the MPI progress engine run while we wait for registration to complete */", "/* let the MPI progress engine run while we wait for debugger release */", "/* deregister the event handler */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
610ce4470067fa2dc9c85a4ea9f17ac16844bf52
nrspruit/ompi
ompi/mca/osc/rdma/osc_rdma_frag.h
[ "BSD-3-Clause-Open-MPI" ]
C
ompi_osc_rdma_frag_alloc
int
static inline int ompi_osc_rdma_frag_alloc (ompi_osc_rdma_module_t *module, size_t request_len, ompi_osc_rdma_frag_t **buffer, char **ptr) { ompi_osc_rdma_frag_t *curr; int ret; /* ensure all buffers are 8-byte aligned */ request_len = OPAL_ALIGN(request_len, 8, size_t); if (request_len > (mca_osc_rdma_component.buffer_size >> 1)) { return OMPI_ERR_VALUE_OUT_OF_BOUNDS; } OPAL_THREAD_LOCK(&module->lock); curr = module->rdma_frag; if (OPAL_UNLIKELY(NULL == curr || curr->remain_len < request_len)) { if (NULL == curr || (NULL != curr && curr->pending > 1)) { opal_free_list_item_t *item = NULL; /* release the initial reference to the buffer */ module->rdma_frag = NULL; if (curr) { ompi_osc_rdma_frag_complete (curr); } item = opal_free_list_get (&mca_osc_rdma_component.frags); if (OPAL_UNLIKELY(NULL == item)) { OPAL_THREAD_UNLOCK(&module->lock); return OMPI_ERR_OUT_OF_RESOURCE; } curr = module->rdma_frag = (ompi_osc_rdma_frag_t *) item; curr->handle = NULL; curr->pending = 1; curr->module = module; } curr->top = curr->super.ptr; curr->remain_len = mca_osc_rdma_component.buffer_size; if (curr->remain_len < request_len) { OPAL_THREAD_UNLOCK(&module->lock); return OMPI_ERR_TEMP_OUT_OF_RESOURCE; } } if (!curr->handle && module->selected_btl->btl_register_mem) { ret = ompi_osc_rdma_register (module, MCA_BTL_ENDPOINT_ANY, curr->super.ptr, mca_osc_rdma_component.buffer_size, MCA_BTL_REG_FLAG_ACCESS_ANY, &curr->handle); if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) { OPAL_THREAD_UNLOCK(&module->lock); return ret; } } *ptr = (char *) curr->top; *buffer = curr; curr->top += request_len; curr->remain_len -= request_len; OPAL_THREAD_ADD_FETCH32(&curr->pending, 1); OPAL_THREAD_UNLOCK(&module->lock); return OMPI_SUCCESS; }
/* * Note: module lock must be held during this operation */
module lock must be held during this operation
[ "module", "lock", "must", "be", "held", "during", "this", "operation" ]
static inline int ompi_osc_rdma_frag_alloc (ompi_osc_rdma_module_t *module, size_t request_len, ompi_osc_rdma_frag_t **buffer, char **ptr) { ompi_osc_rdma_frag_t *curr; int ret; request_len = OPAL_ALIGN(request_len, 8, size_t); if (request_len > (mca_osc_rdma_component.buffer_size >> 1)) { return OMPI_ERR_VALUE_OUT_OF_BOUNDS; } OPAL_THREAD_LOCK(&module->lock); curr = module->rdma_frag; if (OPAL_UNLIKELY(NULL == curr || curr->remain_len < request_len)) { if (NULL == curr || (NULL != curr && curr->pending > 1)) { opal_free_list_item_t *item = NULL; module->rdma_frag = NULL; if (curr) { ompi_osc_rdma_frag_complete (curr); } item = opal_free_list_get (&mca_osc_rdma_component.frags); if (OPAL_UNLIKELY(NULL == item)) { OPAL_THREAD_UNLOCK(&module->lock); return OMPI_ERR_OUT_OF_RESOURCE; } curr = module->rdma_frag = (ompi_osc_rdma_frag_t *) item; curr->handle = NULL; curr->pending = 1; curr->module = module; } curr->top = curr->super.ptr; curr->remain_len = mca_osc_rdma_component.buffer_size; if (curr->remain_len < request_len) { OPAL_THREAD_UNLOCK(&module->lock); return OMPI_ERR_TEMP_OUT_OF_RESOURCE; } } if (!curr->handle && module->selected_btl->btl_register_mem) { ret = ompi_osc_rdma_register (module, MCA_BTL_ENDPOINT_ANY, curr->super.ptr, mca_osc_rdma_component.buffer_size, MCA_BTL_REG_FLAG_ACCESS_ANY, &curr->handle); if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) { OPAL_THREAD_UNLOCK(&module->lock); return ret; } } *ptr = (char *) curr->top; *buffer = curr; curr->top += request_len; curr->remain_len -= request_len; OPAL_THREAD_ADD_FETCH32(&curr->pending, 1); OPAL_THREAD_UNLOCK(&module->lock); return OMPI_SUCCESS; }
[ "static", "inline", "int", "ompi_osc_rdma_frag_alloc", "(", "ompi_osc_rdma_module_t", "*", "module", ",", "size_t", "request_len", ",", "ompi_osc_rdma_frag_t", "*", "*", "buffer", ",", "char", "*", "*", "ptr", ")", "{", "ompi_osc_rdma_frag_t", "*", "curr", ";", "int", "ret", ";", "request_len", "=", "OPAL_ALIGN", "(", "request_len", ",", "8", ",", "size_t", ")", ";", "if", "(", "request_len", ">", "(", "mca_osc_rdma_component", ".", "buffer_size", ">>", "1", ")", ")", "{", "return", "OMPI_ERR_VALUE_OUT_OF_BOUNDS", ";", "}", "OPAL_THREAD_LOCK", "(", "&", "module", "->", "lock", ")", ";", "curr", "=", "module", "->", "rdma_frag", ";", "if", "(", "OPAL_UNLIKELY", "(", "NULL", "==", "curr", "||", "curr", "->", "remain_len", "<", "request_len", ")", ")", "{", "if", "(", "NULL", "==", "curr", "||", "(", "NULL", "!=", "curr", "&&", "curr", "->", "pending", ">", "1", ")", ")", "{", "opal_free_list_item_t", "*", "item", "=", "NULL", ";", "module", "->", "rdma_frag", "=", "NULL", ";", "if", "(", "curr", ")", "{", "ompi_osc_rdma_frag_complete", "(", "curr", ")", ";", "}", "item", "=", "opal_free_list_get", "(", "&", "mca_osc_rdma_component", ".", "frags", ")", ";", "if", "(", "OPAL_UNLIKELY", "(", "NULL", "==", "item", ")", ")", "{", "OPAL_THREAD_UNLOCK", "(", "&", "module", "->", "lock", ")", ";", "return", "OMPI_ERR_OUT_OF_RESOURCE", ";", "}", "curr", "=", "module", "->", "rdma_frag", "=", "(", "ompi_osc_rdma_frag_t", "*", ")", "item", ";", "curr", "->", "handle", "=", "NULL", ";", "curr", "->", "pending", "=", "1", ";", "curr", "->", "module", "=", "module", ";", "}", "curr", "->", "top", "=", "curr", "->", "super", ".", "ptr", ";", "curr", "->", "remain_len", "=", "mca_osc_rdma_component", ".", "buffer_size", ";", "if", "(", "curr", "->", "remain_len", "<", "request_len", ")", "{", "OPAL_THREAD_UNLOCK", "(", "&", "module", "->", "lock", ")", ";", "return", "OMPI_ERR_TEMP_OUT_OF_RESOURCE", ";", "}", "}", "if", "(", "!", "curr", "->", "handle", "&&", "module", "->", "selected_btl", "->", "btl_register_mem", ")", "{", "ret", "=", "ompi_osc_rdma_register", "(", "module", ",", "MCA_BTL_ENDPOINT_ANY", ",", "curr", "->", "super", ".", "ptr", ",", "mca_osc_rdma_component", ".", "buffer_size", ",", "MCA_BTL_REG_FLAG_ACCESS_ANY", ",", "&", "curr", "->", "handle", ")", ";", "if", "(", "OPAL_UNLIKELY", "(", "OMPI_SUCCESS", "!=", "ret", ")", ")", "{", "OPAL_THREAD_UNLOCK", "(", "&", "module", "->", "lock", ")", ";", "return", "ret", ";", "}", "}", "*", "ptr", "=", "(", "char", "*", ")", "curr", "->", "top", ";", "*", "buffer", "=", "curr", ";", "curr", "->", "top", "+=", "request_len", ";", "curr", "->", "remain_len", "-=", "request_len", ";", "OPAL_THREAD_ADD_FETCH32", "(", "&", "curr", "->", "pending", ",", "1", ")", ";", "OPAL_THREAD_UNLOCK", "(", "&", "module", "->", "lock", ")", ";", "return", "OMPI_SUCCESS", ";", "}" ]
Note: module lock must be held during this operation
[ "Note", ":", "module", "lock", "must", "be", "held", "during", "this", "operation" ]
[ "/* ensure all buffers are 8-byte aligned */", "/* release the initial reference to the buffer */" ]
[ { "param": "module", "type": "ompi_osc_rdma_module_t" }, { "param": "request_len", "type": "size_t" }, { "param": "buffer", "type": "ompi_osc_rdma_frag_t" }, { "param": "ptr", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "module", "type": "ompi_osc_rdma_module_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "request_len", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buffer", "type": "ompi_osc_rdma_frag_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ptr", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc_look_xml
int
static int hwloc_look_xml(struct hwloc_backend *backend) { struct hwloc_topology *topology = backend->topology; struct hwloc_xml_backend_data_s *data = backend->private_data; struct hwloc__xml_import_state_s state, childstate; struct hwloc_obj *root = topology->levels[0][0]; char *tag; int gotignored = 0; hwloc_localeswitch_declare; int ret; state.global = data; assert(!root->cpuset); hwloc_localeswitch_init(); data->nbnumanodes = 0; data->first_numanode = data->last_numanode = NULL; data->first_v1dist = data->last_v1dist = NULL; ret = data->look_init(data, &state); if (ret < 0) goto failed; /* find root object tag and import it */ ret = state.global->find_child(&state, &childstate, &tag); if (ret < 0 || !ret || strcmp(tag, "object")) goto failed; ret = hwloc__xml_import_object(topology, data, NULL /* no parent */, root, &gotignored, &childstate); if (ret < 0) goto failed; state.global->close_child(&childstate); assert(!gotignored); /* find v2 distances */ while (1) { ret = state.global->find_child(&state, &childstate, &tag); if (ret < 0) goto failed; if (!ret) break; if (strcmp(tag, "distances2")) goto failed; ret = hwloc__xml_import_v2distances(topology, &childstate); if (ret < 0) goto failed; state.global->close_child(&childstate); } /* find end of topology tag */ state.global->close_tag(&state); if (!root->cpuset) { if (hwloc__xml_verbose()) fprintf(stderr, "invalid root object without cpuset\n"); goto err; } /* handle v1 distances */ if (data->first_v1dist) { struct hwloc__xml_imported_v1distances_s *v1dist, *v1next = data->first_v1dist; while ((v1dist = v1next) != NULL) { unsigned nbobjs = v1dist->nbobjs; v1next = v1dist->next; /* Handle distances as NUMA node distances if nbobjs matches. * Otherwise drop, only NUMA distances really matter. * * We could also attach to a random level with the right nbobjs, * but it would require to have those objects in the original XML order (like the first_numanode cousin-list). * because the topology order can be different if some parents are ignored during load. */ if (nbobjs == data->nbnumanodes) { hwloc_obj_t *objs = malloc(nbobjs*sizeof(hwloc_obj_t)); uint64_t *values = malloc(nbobjs*nbobjs*sizeof(*values)); if (objs && values) { hwloc_obj_t node; unsigned i; for(i=0, node = data->first_numanode; i<nbobjs; i++, node = node->next_cousin) objs[i] = node; hwloc_convert_from_v1dist_floats(topology, nbobjs, v1dist->floats, values); hwloc_internal_distances_add(topology, nbobjs, objs, values, v1dist->kind, 0); } else { free(objs); free(values); } } free(v1dist->floats); free(v1dist); } data->first_v1dist = data->last_v1dist = NULL; } /* FIXME: * We should check that the existing object sets are consistent: * no intersection between objects of a same level, * object sets included in parent sets. * hwloc never generated such buggy XML, but users could create one. * * We want to add these checks to the existing core code that * adds missing sets and propagates parent/children sets * (in case another backend ever generates buggy object sets as well). */ if (!data->nbnumanodes) { /* before 2.0, XML could have no NUMA node objects and no nodesets */ hwloc_obj_t numa; /* create missing root nodesets and make sure they are consistent with the upcoming NUMA node */ if (!root->nodeset) root->nodeset = hwloc_bitmap_alloc(); if (!root->allowed_nodeset) root->allowed_nodeset = hwloc_bitmap_alloc(); if (!root->complete_nodeset) root->complete_nodeset = hwloc_bitmap_alloc(); hwloc_bitmap_only(root->nodeset, 0); hwloc_bitmap_only(root->allowed_nodeset, 0); hwloc_bitmap_only(root->complete_nodeset, 0); /* add a NUMA node and move the root memory there */ numa = hwloc_alloc_setup_object(topology, HWLOC_OBJ_NUMANODE, 0); numa->cpuset = hwloc_bitmap_dup(root->cpuset); numa->nodeset = hwloc_bitmap_alloc(); hwloc_bitmap_set(numa->nodeset, 0); memcpy(&numa->memory, &topology->levels[0][0]->memory, sizeof(numa->memory)); memset(&topology->levels[0][0]->memory, 0, sizeof(numa->memory)); /* insert by cpuset so that it goes between root and its existing children */ hwloc_insert_object_by_cpuset(topology, numa); } /* make sure we have a nodeset now. if we got NUMA nodes without nodeset, something bad happened */ if (!root->nodeset) { if (hwloc__xml_verbose()) fprintf(stderr, "invalid root object without nodeset\n"); goto err; } /* allocate default cpusets and nodesets if missing, the core will restrict them */ hwloc_alloc_obj_cpusets(root); /* keep the "Backend" information intact */ /* we could add "BackendSource=XML" to notify that XML was used between the actual backend and here */ topology->support.discovery->pu = 1; hwloc_localeswitch_fini(); return 0; failed: if (data->look_failed) data->look_failed(data); if (hwloc__xml_verbose()) fprintf(stderr, "%s: XML component discovery failed.\n", data->msgprefix); err: hwloc_free_object_siblings_and_children(root->first_child); root->first_child = NULL; hwloc_free_object_siblings_and_children(root->io_first_child); root->io_first_child = NULL; hwloc_free_object_siblings_and_children(root->misc_first_child); root->misc_first_child = NULL; hwloc_localeswitch_fini(); return -1; }
/* this canNOT be the first XML call */
this canNOT be the first XML call
[ "this", "canNOT", "be", "the", "first", "XML", "call" ]
static int hwloc_look_xml(struct hwloc_backend *backend) { struct hwloc_topology *topology = backend->topology; struct hwloc_xml_backend_data_s *data = backend->private_data; struct hwloc__xml_import_state_s state, childstate; struct hwloc_obj *root = topology->levels[0][0]; char *tag; int gotignored = 0; hwloc_localeswitch_declare; int ret; state.global = data; assert(!root->cpuset); hwloc_localeswitch_init(); data->nbnumanodes = 0; data->first_numanode = data->last_numanode = NULL; data->first_v1dist = data->last_v1dist = NULL; ret = data->look_init(data, &state); if (ret < 0) goto failed; ret = state.global->find_child(&state, &childstate, &tag); if (ret < 0 || !ret || strcmp(tag, "object")) goto failed; ret = hwloc__xml_import_object(topology, data, NULL , root, &gotignored, &childstate); if (ret < 0) goto failed; state.global->close_child(&childstate); assert(!gotignored); while (1) { ret = state.global->find_child(&state, &childstate, &tag); if (ret < 0) goto failed; if (!ret) break; if (strcmp(tag, "distances2")) goto failed; ret = hwloc__xml_import_v2distances(topology, &childstate); if (ret < 0) goto failed; state.global->close_child(&childstate); } state.global->close_tag(&state); if (!root->cpuset) { if (hwloc__xml_verbose()) fprintf(stderr, "invalid root object without cpuset\n"); goto err; } if (data->first_v1dist) { struct hwloc__xml_imported_v1distances_s *v1dist, *v1next = data->first_v1dist; while ((v1dist = v1next) != NULL) { unsigned nbobjs = v1dist->nbobjs; v1next = v1dist->next; if (nbobjs == data->nbnumanodes) { hwloc_obj_t *objs = malloc(nbobjs*sizeof(hwloc_obj_t)); uint64_t *values = malloc(nbobjs*nbobjs*sizeof(*values)); if (objs && values) { hwloc_obj_t node; unsigned i; for(i=0, node = data->first_numanode; i<nbobjs; i++, node = node->next_cousin) objs[i] = node; hwloc_convert_from_v1dist_floats(topology, nbobjs, v1dist->floats, values); hwloc_internal_distances_add(topology, nbobjs, objs, values, v1dist->kind, 0); } else { free(objs); free(values); } } free(v1dist->floats); free(v1dist); } data->first_v1dist = data->last_v1dist = NULL; } if (!data->nbnumanodes) { hwloc_obj_t numa; if (!root->nodeset) root->nodeset = hwloc_bitmap_alloc(); if (!root->allowed_nodeset) root->allowed_nodeset = hwloc_bitmap_alloc(); if (!root->complete_nodeset) root->complete_nodeset = hwloc_bitmap_alloc(); hwloc_bitmap_only(root->nodeset, 0); hwloc_bitmap_only(root->allowed_nodeset, 0); hwloc_bitmap_only(root->complete_nodeset, 0); numa = hwloc_alloc_setup_object(topology, HWLOC_OBJ_NUMANODE, 0); numa->cpuset = hwloc_bitmap_dup(root->cpuset); numa->nodeset = hwloc_bitmap_alloc(); hwloc_bitmap_set(numa->nodeset, 0); memcpy(&numa->memory, &topology->levels[0][0]->memory, sizeof(numa->memory)); memset(&topology->levels[0][0]->memory, 0, sizeof(numa->memory)); hwloc_insert_object_by_cpuset(topology, numa); } if (!root->nodeset) { if (hwloc__xml_verbose()) fprintf(stderr, "invalid root object without nodeset\n"); goto err; } hwloc_alloc_obj_cpusets(root); topology->support.discovery->pu = 1; hwloc_localeswitch_fini(); return 0; failed: if (data->look_failed) data->look_failed(data); if (hwloc__xml_verbose()) fprintf(stderr, "%s: XML component discovery failed.\n", data->msgprefix); err: hwloc_free_object_siblings_and_children(root->first_child); root->first_child = NULL; hwloc_free_object_siblings_and_children(root->io_first_child); root->io_first_child = NULL; hwloc_free_object_siblings_and_children(root->misc_first_child); root->misc_first_child = NULL; hwloc_localeswitch_fini(); return -1; }
[ "static", "int", "hwloc_look_xml", "(", "struct", "hwloc_backend", "*", "backend", ")", "{", "struct", "hwloc_topology", "*", "topology", "=", "backend", "->", "topology", ";", "struct", "hwloc_xml_backend_data_s", "*", "data", "=", "backend", "->", "private_data", ";", "struct", "hwloc__xml_import_state_s", "state", ",", "childstate", ";", "struct", "hwloc_obj", "*", "root", "=", "topology", "->", "levels", "[", "0", "]", "[", "0", "]", ";", "char", "*", "tag", ";", "int", "gotignored", "=", "0", ";", "hwloc_localeswitch_declare", ";", "int", "ret", ";", "state", ".", "global", "=", "data", ";", "assert", "(", "!", "root", "->", "cpuset", ")", ";", "hwloc_localeswitch_init", "(", ")", ";", "data", "->", "nbnumanodes", "=", "0", ";", "data", "->", "first_numanode", "=", "data", "->", "last_numanode", "=", "NULL", ";", "data", "->", "first_v1dist", "=", "data", "->", "last_v1dist", "=", "NULL", ";", "ret", "=", "data", "->", "look_init", "(", "data", ",", "&", "state", ")", ";", "if", "(", "ret", "<", "0", ")", "goto", "failed", ";", "ret", "=", "state", ".", "global", "->", "find_child", "(", "&", "state", ",", "&", "childstate", ",", "&", "tag", ")", ";", "if", "(", "ret", "<", "0", "||", "!", "ret", "||", "strcmp", "(", "tag", ",", "\"", "\"", ")", ")", "goto", "failed", ";", "ret", "=", "hwloc__xml_import_object", "(", "topology", ",", "data", ",", "NULL", ",", "root", ",", "&", "gotignored", ",", "&", "childstate", ")", ";", "if", "(", "ret", "<", "0", ")", "goto", "failed", ";", "state", ".", "global", "->", "close_child", "(", "&", "childstate", ")", ";", "assert", "(", "!", "gotignored", ")", ";", "while", "(", "1", ")", "{", "ret", "=", "state", ".", "global", "->", "find_child", "(", "&", "state", ",", "&", "childstate", ",", "&", "tag", ")", ";", "if", "(", "ret", "<", "0", ")", "goto", "failed", ";", "if", "(", "!", "ret", ")", "break", ";", "if", "(", "strcmp", "(", "tag", ",", "\"", "\"", ")", ")", "goto", "failed", ";", "ret", "=", "hwloc__xml_import_v2distances", "(", "topology", ",", "&", "childstate", ")", ";", "if", "(", "ret", "<", "0", ")", "goto", "failed", ";", "state", ".", "global", "->", "close_child", "(", "&", "childstate", ")", ";", "}", "state", ".", "global", "->", "close_tag", "(", "&", "state", ")", ";", "if", "(", "!", "root", "->", "cpuset", ")", "{", "if", "(", "hwloc__xml_verbose", "(", ")", ")", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "goto", "err", ";", "}", "if", "(", "data", "->", "first_v1dist", ")", "{", "struct", "hwloc__xml_imported_v1distances_s", "*", "v1dist", ",", "*", "v1next", "=", "data", "->", "first_v1dist", ";", "while", "(", "(", "v1dist", "=", "v1next", ")", "!=", "NULL", ")", "{", "unsigned", "nbobjs", "=", "v1dist", "->", "nbobjs", ";", "v1next", "=", "v1dist", "->", "next", ";", "if", "(", "nbobjs", "==", "data", "->", "nbnumanodes", ")", "{", "hwloc_obj_t", "*", "objs", "=", "malloc", "(", "nbobjs", "*", "sizeof", "(", "hwloc_obj_t", ")", ")", ";", "uint64_t", "*", "values", "=", "malloc", "(", "nbobjs", "*", "nbobjs", "*", "sizeof", "(", "*", "values", ")", ")", ";", "if", "(", "objs", "&&", "values", ")", "{", "hwloc_obj_t", "node", ";", "unsigned", "i", ";", "for", "(", "i", "=", "0", ",", "node", "=", "data", "->", "first_numanode", ";", "i", "<", "nbobjs", ";", "i", "++", ",", "node", "=", "node", "->", "next_cousin", ")", "objs", "[", "i", "]", "=", "node", ";", "hwloc_convert_from_v1dist_floats", "(", "topology", ",", "nbobjs", ",", "v1dist", "->", "floats", ",", "values", ")", ";", "hwloc_internal_distances_add", "(", "topology", ",", "nbobjs", ",", "objs", ",", "values", ",", "v1dist", "->", "kind", ",", "0", ")", ";", "}", "else", "{", "free", "(", "objs", ")", ";", "free", "(", "values", ")", ";", "}", "}", "free", "(", "v1dist", "->", "floats", ")", ";", "free", "(", "v1dist", ")", ";", "}", "data", "->", "first_v1dist", "=", "data", "->", "last_v1dist", "=", "NULL", ";", "}", "if", "(", "!", "data", "->", "nbnumanodes", ")", "{", "hwloc_obj_t", "numa", ";", "if", "(", "!", "root", "->", "nodeset", ")", "root", "->", "nodeset", "=", "hwloc_bitmap_alloc", "(", ")", ";", "if", "(", "!", "root", "->", "allowed_nodeset", ")", "root", "->", "allowed_nodeset", "=", "hwloc_bitmap_alloc", "(", ")", ";", "if", "(", "!", "root", "->", "complete_nodeset", ")", "root", "->", "complete_nodeset", "=", "hwloc_bitmap_alloc", "(", ")", ";", "hwloc_bitmap_only", "(", "root", "->", "nodeset", ",", "0", ")", ";", "hwloc_bitmap_only", "(", "root", "->", "allowed_nodeset", ",", "0", ")", ";", "hwloc_bitmap_only", "(", "root", "->", "complete_nodeset", ",", "0", ")", ";", "numa", "=", "hwloc_alloc_setup_object", "(", "topology", ",", "HWLOC_OBJ_NUMANODE", ",", "0", ")", ";", "numa", "->", "cpuset", "=", "hwloc_bitmap_dup", "(", "root", "->", "cpuset", ")", ";", "numa", "->", "nodeset", "=", "hwloc_bitmap_alloc", "(", ")", ";", "hwloc_bitmap_set", "(", "numa", "->", "nodeset", ",", "0", ")", ";", "memcpy", "(", "&", "numa", "->", "memory", ",", "&", "topology", "->", "levels", "[", "0", "]", "[", "0", "]", "->", "memory", ",", "sizeof", "(", "numa", "->", "memory", ")", ")", ";", "memset", "(", "&", "topology", "->", "levels", "[", "0", "]", "[", "0", "]", "->", "memory", ",", "0", ",", "sizeof", "(", "numa", "->", "memory", ")", ")", ";", "hwloc_insert_object_by_cpuset", "(", "topology", ",", "numa", ")", ";", "}", "if", "(", "!", "root", "->", "nodeset", ")", "{", "if", "(", "hwloc__xml_verbose", "(", ")", ")", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "goto", "err", ";", "}", "hwloc_alloc_obj_cpusets", "(", "root", ")", ";", "topology", "->", "support", ".", "discovery", "->", "pu", "=", "1", ";", "hwloc_localeswitch_fini", "(", ")", ";", "return", "0", ";", "failed", ":", "if", "(", "data", "->", "look_failed", ")", "data", "->", "look_failed", "(", "data", ")", ";", "if", "(", "hwloc__xml_verbose", "(", ")", ")", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "data", "->", "msgprefix", ")", ";", "err", ":", "hwloc_free_object_siblings_and_children", "(", "root", "->", "first_child", ")", ";", "root", "->", "first_child", "=", "NULL", ";", "hwloc_free_object_siblings_and_children", "(", "root", "->", "io_first_child", ")", ";", "root", "->", "io_first_child", "=", "NULL", ";", "hwloc_free_object_siblings_and_children", "(", "root", "->", "misc_first_child", ")", ";", "root", "->", "misc_first_child", "=", "NULL", ";", "hwloc_localeswitch_fini", "(", ")", ";", "return", "-1", ";", "}" ]
this canNOT be the first XML call
[ "this", "canNOT", "be", "the", "first", "XML", "call" ]
[ "/* find root object tag and import it */", "/* no parent */", "/* find v2 distances */", "/* find end of topology tag */", "/* handle v1 distances */", "/* Handle distances as NUMA node distances if nbobjs matches.\n * Otherwise drop, only NUMA distances really matter.\n *\n * We could also attach to a random level with the right nbobjs,\n * but it would require to have those objects in the original XML order (like the first_numanode cousin-list).\n * because the topology order can be different if some parents are ignored during load.\n */", "/* FIXME:\n * We should check that the existing object sets are consistent:\n * no intersection between objects of a same level,\n * object sets included in parent sets.\n * hwloc never generated such buggy XML, but users could create one.\n *\n * We want to add these checks to the existing core code that\n * adds missing sets and propagates parent/children sets\n * (in case another backend ever generates buggy object sets as well).\n */", "/* before 2.0, XML could have no NUMA node objects and no nodesets */", "/* create missing root nodesets and make sure they are consistent with the upcoming NUMA node */", "/* add a NUMA node and move the root memory there */", "/* insert by cpuset so that it goes between root and its existing children */", "/* make sure we have a nodeset now. if we got NUMA nodes without nodeset, something bad happened */", "/* allocate default cpusets and nodesets if missing, the core will restrict them */", "/* keep the \"Backend\" information intact */", "/* we could add \"BackendSource=XML\" to notify that XML was used between the actual backend and here */" ]
[ { "param": "backend", "type": "struct hwloc_backend" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "backend", "type": "struct hwloc_backend", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc_topology_diff_load_xml
int
int hwloc_topology_diff_load_xml(const char *xmlpath, hwloc_topology_diff_t *firstdiffp, char **refnamep) { struct hwloc__xml_import_state_s state; struct hwloc_xml_backend_data_s fakedata; /* only for storing global info during parsing */ hwloc_localeswitch_declare; const char *basename; int force_nolibxml; int ret; state.global = &fakedata; basename = strrchr(xmlpath, '/'); if (basename) basename++; else basename = xmlpath; fakedata.msgprefix = strdup(basename); hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); *firstdiffp = NULL; force_nolibxml = hwloc_nolibxml_import(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->import_diff(&state, xmlpath, NULL, 0, firstdiffp, refnamep); else { ret = hwloc_libxml_callbacks->import_diff(&state, xmlpath, NULL, 0, firstdiffp, refnamep); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); free(fakedata.msgprefix); return ret; }
/* this can be the first XML call */
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
int hwloc_topology_diff_load_xml(const char *xmlpath, hwloc_topology_diff_t *firstdiffp, char **refnamep) { struct hwloc__xml_import_state_s state; struct hwloc_xml_backend_data_s fakedata; hwloc_localeswitch_declare; const char *basename; int force_nolibxml; int ret; state.global = &fakedata; basename = strrchr(xmlpath, '/'); if (basename) basename++; else basename = xmlpath; fakedata.msgprefix = strdup(basename); hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); *firstdiffp = NULL; force_nolibxml = hwloc_nolibxml_import(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->import_diff(&state, xmlpath, NULL, 0, firstdiffp, refnamep); else { ret = hwloc_libxml_callbacks->import_diff(&state, xmlpath, NULL, 0, firstdiffp, refnamep); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); free(fakedata.msgprefix); return ret; }
[ "int", "hwloc_topology_diff_load_xml", "(", "const", "char", "*", "xmlpath", ",", "hwloc_topology_diff_t", "*", "firstdiffp", ",", "char", "*", "*", "refnamep", ")", "{", "struct", "hwloc__xml_import_state_s", "state", ";", "struct", "hwloc_xml_backend_data_s", "fakedata", ";", "hwloc_localeswitch_declare", ";", "const", "char", "*", "basename", ";", "int", "force_nolibxml", ";", "int", "ret", ";", "state", ".", "global", "=", "&", "fakedata", ";", "basename", "=", "strrchr", "(", "xmlpath", ",", "'", "'", ")", ";", "if", "(", "basename", ")", "basename", "++", ";", "else", "basename", "=", "xmlpath", ";", "fakedata", ".", "msgprefix", "=", "strdup", "(", "basename", ")", ";", "hwloc_components_init", "(", ")", ";", "assert", "(", "hwloc_nolibxml_callbacks", ")", ";", "hwloc_localeswitch_init", "(", ")", ";", "*", "firstdiffp", "=", "NULL", ";", "force_nolibxml", "=", "hwloc_nolibxml_import", "(", ")", ";", "retry", ":", "if", "(", "!", "hwloc_libxml_callbacks", "||", "(", "hwloc_nolibxml_callbacks", "&&", "force_nolibxml", ")", ")", "ret", "=", "hwloc_nolibxml_callbacks", "->", "import_diff", "(", "&", "state", ",", "xmlpath", ",", "NULL", ",", "0", ",", "firstdiffp", ",", "refnamep", ")", ";", "else", "{", "ret", "=", "hwloc_libxml_callbacks", "->", "import_diff", "(", "&", "state", ",", "xmlpath", ",", "NULL", ",", "0", ",", "firstdiffp", ",", "refnamep", ")", ";", "if", "(", "ret", "<", "0", "&&", "errno", "==", "ENOSYS", ")", "{", "hwloc_libxml_callbacks", "=", "NULL", ";", "goto", "retry", ";", "}", "}", "hwloc_localeswitch_fini", "(", ")", ";", "hwloc_components_fini", "(", ")", ";", "free", "(", "fakedata", ".", "msgprefix", ")", ";", "return", "ret", ";", "}" ]
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
[ "/* only for storing global info during parsing */" ]
[ { "param": "xmlpath", "type": "char" }, { "param": "firstdiffp", "type": "hwloc_topology_diff_t" }, { "param": "refnamep", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "xmlpath", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "firstdiffp", "type": "hwloc_topology_diff_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "refnamep", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc_topology_diff_load_xmlbuffer
int
int hwloc_topology_diff_load_xmlbuffer(const char *xmlbuffer, int buflen, hwloc_topology_diff_t *firstdiffp, char **refnamep) { struct hwloc__xml_import_state_s state; struct hwloc_xml_backend_data_s fakedata; /* only for storing global info during parsing */ hwloc_localeswitch_declare; int force_nolibxml; int ret; state.global = &fakedata; fakedata.msgprefix = strdup("xmldiffbuffer"); hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); *firstdiffp = NULL; force_nolibxml = hwloc_nolibxml_import(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->import_diff(&state, NULL, xmlbuffer, buflen, firstdiffp, refnamep); else { ret = hwloc_libxml_callbacks->import_diff(&state, NULL, xmlbuffer, buflen, firstdiffp, refnamep); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); free(fakedata.msgprefix); return ret; }
/* this can be the first XML call */
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
int hwloc_topology_diff_load_xmlbuffer(const char *xmlbuffer, int buflen, hwloc_topology_diff_t *firstdiffp, char **refnamep) { struct hwloc__xml_import_state_s state; struct hwloc_xml_backend_data_s fakedata; hwloc_localeswitch_declare; int force_nolibxml; int ret; state.global = &fakedata; fakedata.msgprefix = strdup("xmldiffbuffer"); hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); *firstdiffp = NULL; force_nolibxml = hwloc_nolibxml_import(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->import_diff(&state, NULL, xmlbuffer, buflen, firstdiffp, refnamep); else { ret = hwloc_libxml_callbacks->import_diff(&state, NULL, xmlbuffer, buflen, firstdiffp, refnamep); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); free(fakedata.msgprefix); return ret; }
[ "int", "hwloc_topology_diff_load_xmlbuffer", "(", "const", "char", "*", "xmlbuffer", ",", "int", "buflen", ",", "hwloc_topology_diff_t", "*", "firstdiffp", ",", "char", "*", "*", "refnamep", ")", "{", "struct", "hwloc__xml_import_state_s", "state", ";", "struct", "hwloc_xml_backend_data_s", "fakedata", ";", "hwloc_localeswitch_declare", ";", "int", "force_nolibxml", ";", "int", "ret", ";", "state", ".", "global", "=", "&", "fakedata", ";", "fakedata", ".", "msgprefix", "=", "strdup", "(", "\"", "\"", ")", ";", "hwloc_components_init", "(", ")", ";", "assert", "(", "hwloc_nolibxml_callbacks", ")", ";", "hwloc_localeswitch_init", "(", ")", ";", "*", "firstdiffp", "=", "NULL", ";", "force_nolibxml", "=", "hwloc_nolibxml_import", "(", ")", ";", "retry", ":", "if", "(", "!", "hwloc_libxml_callbacks", "||", "(", "hwloc_nolibxml_callbacks", "&&", "force_nolibxml", ")", ")", "ret", "=", "hwloc_nolibxml_callbacks", "->", "import_diff", "(", "&", "state", ",", "NULL", ",", "xmlbuffer", ",", "buflen", ",", "firstdiffp", ",", "refnamep", ")", ";", "else", "{", "ret", "=", "hwloc_libxml_callbacks", "->", "import_diff", "(", "&", "state", ",", "NULL", ",", "xmlbuffer", ",", "buflen", ",", "firstdiffp", ",", "refnamep", ")", ";", "if", "(", "ret", "<", "0", "&&", "errno", "==", "ENOSYS", ")", "{", "hwloc_libxml_callbacks", "=", "NULL", ";", "goto", "retry", ";", "}", "}", "hwloc_localeswitch_fini", "(", ")", ";", "hwloc_components_fini", "(", ")", ";", "free", "(", "fakedata", ".", "msgprefix", ")", ";", "return", "ret", ";", "}" ]
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
[ "/* only for storing global info during parsing */" ]
[ { "param": "xmlbuffer", "type": "char" }, { "param": "buflen", "type": "int" }, { "param": "firstdiffp", "type": "hwloc_topology_diff_t" }, { "param": "refnamep", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "xmlbuffer", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buflen", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "firstdiffp", "type": "hwloc_topology_diff_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "refnamep", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc__xml_export_safestrdup
char
static char* hwloc__xml_export_safestrdup(const char *old) { char *new = malloc(strlen(old)+1); char *dst = new; const char *src = old; while (*src) { if (HWLOC_XML_CHAR_VALID(*src)) *(dst++) = *src; src++; } *dst = '\0'; return new; }
/* strdup and remove ugly chars from random string */
strdup and remove ugly chars from random string
[ "strdup", "and", "remove", "ugly", "chars", "from", "random", "string" ]
static char* hwloc__xml_export_safestrdup(const char *old) { char *new = malloc(strlen(old)+1); char *dst = new; const char *src = old; while (*src) { if (HWLOC_XML_CHAR_VALID(*src)) *(dst++) = *src; src++; } *dst = '\0'; return new; }
[ "static", "char", "*", "hwloc__xml_export_safestrdup", "(", "const", "char", "*", "old", ")", "{", "char", "*", "new", "=", "malloc", "(", "strlen", "(", "old", ")", "+", "1", ")", ";", "char", "*", "dst", "=", "new", ";", "const", "char", "*", "src", "=", "old", ";", "while", "(", "*", "src", ")", "{", "if", "(", "HWLOC_XML_CHAR_VALID", "(", "*", "src", ")", ")", "*", "(", "dst", "++", ")", "=", "*", "src", ";", "src", "++", ";", "}", "*", "dst", "=", "'", "\\0", "'", ";", "return", "new", ";", "}" ]
strdup and remove ugly chars from random string
[ "strdup", "and", "remove", "ugly", "chars", "from", "random", "string" ]
[]
[ { "param": "old", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "old", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc_topology_export_xml
int
int hwloc_topology_export_xml(hwloc_topology_t topology, const char *filename, unsigned long flags) { hwloc_localeswitch_declare; int force_nolibxml; int ret; if (!topology->is_loaded) { errno = EINVAL; return -1; } assert(hwloc_nolibxml_callbacks); /* the core called components_init() for the topology */ if (flags & ~HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1) { errno = EINVAL; return -1; } hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_file(topology, filename, flags); else { ret = hwloc_libxml_callbacks->export_file(topology, filename, flags); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); return ret; }
/* this can be the first XML call */
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
int hwloc_topology_export_xml(hwloc_topology_t topology, const char *filename, unsigned long flags) { hwloc_localeswitch_declare; int force_nolibxml; int ret; if (!topology->is_loaded) { errno = EINVAL; return -1; } assert(hwloc_nolibxml_callbacks); if (flags & ~HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1) { errno = EINVAL; return -1; } hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_file(topology, filename, flags); else { ret = hwloc_libxml_callbacks->export_file(topology, filename, flags); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); return ret; }
[ "int", "hwloc_topology_export_xml", "(", "hwloc_topology_t", "topology", ",", "const", "char", "*", "filename", ",", "unsigned", "long", "flags", ")", "{", "hwloc_localeswitch_declare", ";", "int", "force_nolibxml", ";", "int", "ret", ";", "if", "(", "!", "topology", "->", "is_loaded", ")", "{", "errno", "=", "EINVAL", ";", "return", "-1", ";", "}", "assert", "(", "hwloc_nolibxml_callbacks", ")", ";", "if", "(", "flags", "&", "~", "HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1", ")", "{", "errno", "=", "EINVAL", ";", "return", "-1", ";", "}", "hwloc_localeswitch_init", "(", ")", ";", "force_nolibxml", "=", "hwloc_nolibxml_export", "(", ")", ";", "retry", ":", "if", "(", "!", "hwloc_libxml_callbacks", "||", "(", "hwloc_nolibxml_callbacks", "&&", "force_nolibxml", ")", ")", "ret", "=", "hwloc_nolibxml_callbacks", "->", "export_file", "(", "topology", ",", "filename", ",", "flags", ")", ";", "else", "{", "ret", "=", "hwloc_libxml_callbacks", "->", "export_file", "(", "topology", ",", "filename", ",", "flags", ")", ";", "if", "(", "ret", "<", "0", "&&", "errno", "==", "ENOSYS", ")", "{", "hwloc_libxml_callbacks", "=", "NULL", ";", "goto", "retry", ";", "}", "}", "hwloc_localeswitch_fini", "(", ")", ";", "return", "ret", ";", "}" ]
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
[ "/* the core called components_init() for the topology */" ]
[ { "param": "topology", "type": "hwloc_topology_t" }, { "param": "filename", "type": "char" }, { "param": "flags", "type": "unsigned long" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "topology", "type": "hwloc_topology_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "filename", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "flags", "type": "unsigned long", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc_topology_export_xmlbuffer
int
int hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen, unsigned long flags) { hwloc_localeswitch_declare; int force_nolibxml; int ret; if (!topology->is_loaded) { errno = EINVAL; return -1; } assert(hwloc_nolibxml_callbacks); /* the core called components_init() for the topology */ if (flags & ~HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1) { errno = EINVAL; return -1; } hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_buffer(topology, xmlbuffer, buflen, flags); else { ret = hwloc_libxml_callbacks->export_buffer(topology, xmlbuffer, buflen, flags); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); return ret; }
/* this can be the first XML call */
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
int hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen, unsigned long flags) { hwloc_localeswitch_declare; int force_nolibxml; int ret; if (!topology->is_loaded) { errno = EINVAL; return -1; } assert(hwloc_nolibxml_callbacks); if (flags & ~HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1) { errno = EINVAL; return -1; } hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_buffer(topology, xmlbuffer, buflen, flags); else { ret = hwloc_libxml_callbacks->export_buffer(topology, xmlbuffer, buflen, flags); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); return ret; }
[ "int", "hwloc_topology_export_xmlbuffer", "(", "hwloc_topology_t", "topology", ",", "char", "*", "*", "xmlbuffer", ",", "int", "*", "buflen", ",", "unsigned", "long", "flags", ")", "{", "hwloc_localeswitch_declare", ";", "int", "force_nolibxml", ";", "int", "ret", ";", "if", "(", "!", "topology", "->", "is_loaded", ")", "{", "errno", "=", "EINVAL", ";", "return", "-1", ";", "}", "assert", "(", "hwloc_nolibxml_callbacks", ")", ";", "if", "(", "flags", "&", "~", "HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1", ")", "{", "errno", "=", "EINVAL", ";", "return", "-1", ";", "}", "hwloc_localeswitch_init", "(", ")", ";", "force_nolibxml", "=", "hwloc_nolibxml_export", "(", ")", ";", "retry", ":", "if", "(", "!", "hwloc_libxml_callbacks", "||", "(", "hwloc_nolibxml_callbacks", "&&", "force_nolibxml", ")", ")", "ret", "=", "hwloc_nolibxml_callbacks", "->", "export_buffer", "(", "topology", ",", "xmlbuffer", ",", "buflen", ",", "flags", ")", ";", "else", "{", "ret", "=", "hwloc_libxml_callbacks", "->", "export_buffer", "(", "topology", ",", "xmlbuffer", ",", "buflen", ",", "flags", ")", ";", "if", "(", "ret", "<", "0", "&&", "errno", "==", "ENOSYS", ")", "{", "hwloc_libxml_callbacks", "=", "NULL", ";", "goto", "retry", ";", "}", "}", "hwloc_localeswitch_fini", "(", ")", ";", "return", "ret", ";", "}" ]
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
[ "/* the core called components_init() for the topology */" ]
[ { "param": "topology", "type": "hwloc_topology_t" }, { "param": "xmlbuffer", "type": "char" }, { "param": "buflen", "type": "int" }, { "param": "flags", "type": "unsigned long" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "topology", "type": "hwloc_topology_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "xmlbuffer", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buflen", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "flags", "type": "unsigned long", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc_topology_diff_export_xml
int
int hwloc_topology_diff_export_xml(hwloc_topology_diff_t diff, const char *refname, const char *filename) { hwloc_localeswitch_declare; hwloc_topology_diff_t tmpdiff; int force_nolibxml; int ret; tmpdiff = diff; while (tmpdiff) { if (tmpdiff->generic.type == HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX) { errno = EINVAL; return -1; } tmpdiff = tmpdiff->generic.next; } hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_diff_file(diff, refname, filename); else { ret = hwloc_libxml_callbacks->export_diff_file(diff, refname, filename); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); return ret; }
/* this can be the first XML call */
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
int hwloc_topology_diff_export_xml(hwloc_topology_diff_t diff, const char *refname, const char *filename) { hwloc_localeswitch_declare; hwloc_topology_diff_t tmpdiff; int force_nolibxml; int ret; tmpdiff = diff; while (tmpdiff) { if (tmpdiff->generic.type == HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX) { errno = EINVAL; return -1; } tmpdiff = tmpdiff->generic.next; } hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_diff_file(diff, refname, filename); else { ret = hwloc_libxml_callbacks->export_diff_file(diff, refname, filename); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); return ret; }
[ "int", "hwloc_topology_diff_export_xml", "(", "hwloc_topology_diff_t", "diff", ",", "const", "char", "*", "refname", ",", "const", "char", "*", "filename", ")", "{", "hwloc_localeswitch_declare", ";", "hwloc_topology_diff_t", "tmpdiff", ";", "int", "force_nolibxml", ";", "int", "ret", ";", "tmpdiff", "=", "diff", ";", "while", "(", "tmpdiff", ")", "{", "if", "(", "tmpdiff", "->", "generic", ".", "type", "==", "HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX", ")", "{", "errno", "=", "EINVAL", ";", "return", "-1", ";", "}", "tmpdiff", "=", "tmpdiff", "->", "generic", ".", "next", ";", "}", "hwloc_components_init", "(", ")", ";", "assert", "(", "hwloc_nolibxml_callbacks", ")", ";", "hwloc_localeswitch_init", "(", ")", ";", "force_nolibxml", "=", "hwloc_nolibxml_export", "(", ")", ";", "retry", ":", "if", "(", "!", "hwloc_libxml_callbacks", "||", "(", "hwloc_nolibxml_callbacks", "&&", "force_nolibxml", ")", ")", "ret", "=", "hwloc_nolibxml_callbacks", "->", "export_diff_file", "(", "diff", ",", "refname", ",", "filename", ")", ";", "else", "{", "ret", "=", "hwloc_libxml_callbacks", "->", "export_diff_file", "(", "diff", ",", "refname", ",", "filename", ")", ";", "if", "(", "ret", "<", "0", "&&", "errno", "==", "ENOSYS", ")", "{", "hwloc_libxml_callbacks", "=", "NULL", ";", "goto", "retry", ";", "}", "}", "hwloc_localeswitch_fini", "(", ")", ";", "hwloc_components_fini", "(", ")", ";", "return", "ret", ";", "}" ]
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
[]
[ { "param": "diff", "type": "hwloc_topology_diff_t" }, { "param": "refname", "type": "char" }, { "param": "filename", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "diff", "type": "hwloc_topology_diff_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "refname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "filename", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4692d8111892e841d56b69b5d6177d7097d59000
nrspruit/ompi
opal/mca/hwloc/hwloc2a/hwloc/hwloc/topology-xml.c
[ "BSD-3-Clause-Open-MPI" ]
C
hwloc_topology_diff_export_xmlbuffer
int
int hwloc_topology_diff_export_xmlbuffer(hwloc_topology_diff_t diff, const char *refname, char **xmlbuffer, int *buflen) { hwloc_localeswitch_declare; hwloc_topology_diff_t tmpdiff; int force_nolibxml; int ret; tmpdiff = diff; while (tmpdiff) { if (tmpdiff->generic.type == HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX) { errno = EINVAL; return -1; } tmpdiff = tmpdiff->generic.next; } hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_diff_buffer(diff, refname, xmlbuffer, buflen); else { ret = hwloc_libxml_callbacks->export_diff_buffer(diff, refname, xmlbuffer, buflen); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); return ret; }
/* this can be the first XML call */
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
int hwloc_topology_diff_export_xmlbuffer(hwloc_topology_diff_t diff, const char *refname, char **xmlbuffer, int *buflen) { hwloc_localeswitch_declare; hwloc_topology_diff_t tmpdiff; int force_nolibxml; int ret; tmpdiff = diff; while (tmpdiff) { if (tmpdiff->generic.type == HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX) { errno = EINVAL; return -1; } tmpdiff = tmpdiff->generic.next; } hwloc_components_init(); assert(hwloc_nolibxml_callbacks); hwloc_localeswitch_init(); force_nolibxml = hwloc_nolibxml_export(); retry: if (!hwloc_libxml_callbacks || (hwloc_nolibxml_callbacks && force_nolibxml)) ret = hwloc_nolibxml_callbacks->export_diff_buffer(diff, refname, xmlbuffer, buflen); else { ret = hwloc_libxml_callbacks->export_diff_buffer(diff, refname, xmlbuffer, buflen); if (ret < 0 && errno == ENOSYS) { hwloc_libxml_callbacks = NULL; goto retry; } } hwloc_localeswitch_fini(); hwloc_components_fini(); return ret; }
[ "int", "hwloc_topology_diff_export_xmlbuffer", "(", "hwloc_topology_diff_t", "diff", ",", "const", "char", "*", "refname", ",", "char", "*", "*", "xmlbuffer", ",", "int", "*", "buflen", ")", "{", "hwloc_localeswitch_declare", ";", "hwloc_topology_diff_t", "tmpdiff", ";", "int", "force_nolibxml", ";", "int", "ret", ";", "tmpdiff", "=", "diff", ";", "while", "(", "tmpdiff", ")", "{", "if", "(", "tmpdiff", "->", "generic", ".", "type", "==", "HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX", ")", "{", "errno", "=", "EINVAL", ";", "return", "-1", ";", "}", "tmpdiff", "=", "tmpdiff", "->", "generic", ".", "next", ";", "}", "hwloc_components_init", "(", ")", ";", "assert", "(", "hwloc_nolibxml_callbacks", ")", ";", "hwloc_localeswitch_init", "(", ")", ";", "force_nolibxml", "=", "hwloc_nolibxml_export", "(", ")", ";", "retry", ":", "if", "(", "!", "hwloc_libxml_callbacks", "||", "(", "hwloc_nolibxml_callbacks", "&&", "force_nolibxml", ")", ")", "ret", "=", "hwloc_nolibxml_callbacks", "->", "export_diff_buffer", "(", "diff", ",", "refname", ",", "xmlbuffer", ",", "buflen", ")", ";", "else", "{", "ret", "=", "hwloc_libxml_callbacks", "->", "export_diff_buffer", "(", "diff", ",", "refname", ",", "xmlbuffer", ",", "buflen", ")", ";", "if", "(", "ret", "<", "0", "&&", "errno", "==", "ENOSYS", ")", "{", "hwloc_libxml_callbacks", "=", "NULL", ";", "goto", "retry", ";", "}", "}", "hwloc_localeswitch_fini", "(", ")", ";", "hwloc_components_fini", "(", ")", ";", "return", "ret", ";", "}" ]
this can be the first XML call
[ "this", "can", "be", "the", "first", "XML", "call" ]
[]
[ { "param": "diff", "type": "hwloc_topology_diff_t" }, { "param": "refname", "type": "char" }, { "param": "xmlbuffer", "type": "char" }, { "param": "buflen", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "diff", "type": "hwloc_topology_diff_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "refname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "xmlbuffer", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buflen", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6fbff80eb5254d23507e624e717a36086d0bdb24
BU-EC444/esp-idf
examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c
[ "Apache-2.0" ]
C
restart
int
static int restart(int argc, char **argv) { ESP_LOGI(TAG, "Restarting"); esp_restart(); }
/** 'restart' command restarts the program */
'restart' command restarts the program
[ "'", "restart", "'", "command", "restarts", "the", "program" ]
static int restart(int argc, char **argv) { ESP_LOGI(TAG, "Restarting"); esp_restart(); }
[ "static", "int", "restart", "(", "int", "argc", ",", "char", "*", "*", "argv", ")", "{", "ESP_LOGI", "(", "TAG", ",", "\"", "\"", ")", ";", "esp_restart", "(", ")", ";", "}" ]
'restart' command restarts the program
[ "'", "restart", "'", "command", "restarts", "the", "program" ]
[]
[ { "param": "argc", "type": "int" }, { "param": "argv", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "argv", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6fbff80eb5254d23507e624e717a36086d0bdb24
BU-EC444/esp-idf
examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c
[ "Apache-2.0" ]
C
free_mem
int
static int free_mem(int argc, char **argv) { printf("%d\n", esp_get_free_heap_size()); return 0; }
/** 'free' command prints available heap memory */
'free' command prints available heap memory
[ "'", "free", "'", "command", "prints", "available", "heap", "memory" ]
static int free_mem(int argc, char **argv) { printf("%d\n", esp_get_free_heap_size()); return 0; }
[ "static", "int", "free_mem", "(", "int", "argc", ",", "char", "*", "*", "argv", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "esp_get_free_heap_size", "(", ")", ")", ";", "return", "0", ";", "}" ]
'free' command prints available heap memory
[ "'", "free", "'", "command", "prints", "available", "heap", "memory" ]
[]
[ { "param": "argc", "type": "int" }, { "param": "argv", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "argv", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6fbff80eb5254d23507e624e717a36086d0bdb24
BU-EC444/esp-idf
examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c
[ "Apache-2.0" ]
C
heap_size
int
static int heap_size(int argc, char **argv) { uint32_t heap_size = heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT); ESP_LOGI(TAG, "min heap size: %u", heap_size); return 0; }
/* 'heap' command prints minumum heap size */
'heap' command prints minumum heap size
[ "'", "heap", "'", "command", "prints", "minumum", "heap", "size" ]
static int heap_size(int argc, char **argv) { uint32_t heap_size = heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT); ESP_LOGI(TAG, "min heap size: %u", heap_size); return 0; }
[ "static", "int", "heap_size", "(", "int", "argc", ",", "char", "*", "*", "argv", ")", "{", "uint32_t", "heap_size", "=", "heap_caps_get_minimum_free_size", "(", "MALLOC_CAP_DEFAULT", ")", ";", "ESP_LOGI", "(", "TAG", ",", "\"", "\"", ",", "heap_size", ")", ";", "return", "0", ";", "}" ]
'heap' command prints minumum heap size
[ "'", "heap", "'", "command", "prints", "minumum", "heap", "size" ]
[]
[ { "param": "argc", "type": "int" }, { "param": "argv", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "argv", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5a0b6d8ea1268cd346165e7b3a3e89b8ef658b3b
BU-EC444/esp-idf
components/driver/test/test_spi_master.c
[ "Apache-2.0" ]
C
bitswap
uint8_t
static uint8_t bitswap(uint8_t in) { uint8_t out = 0; for (int i = 0; i < 8; i++) { out = out >> 1; if (in & 0x80) { out |= 0x80; } in = in << 1; } return out; }
//These will only be enabled on chips with 2 or more SPI peripherals
These will only be enabled on chips with 2 or more SPI peripherals
[ "These", "will", "only", "be", "enabled", "on", "chips", "with", "2", "or", "more", "SPI", "peripherals" ]
static uint8_t bitswap(uint8_t in) { uint8_t out = 0; for (int i = 0; i < 8; i++) { out = out >> 1; if (in & 0x80) { out |= 0x80; } in = in << 1; } return out; }
[ "static", "uint8_t", "bitswap", "(", "uint8_t", "in", ")", "{", "uint8_t", "out", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "out", "=", "out", ">>", "1", ";", "if", "(", "in", "&", "0x80", ")", "{", "out", "|=", "0x80", ";", "}", "in", "=", "in", "<<", "1", ";", "}", "return", "out", ";", "}" ]
These will only be enabled on chips with 2 or more SPI peripherals
[ "These", "will", "only", "be", "enabled", "on", "chips", "with", "2", "or", "more", "SPI", "peripherals" ]
[]
[ { "param": "in", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "in", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a2d0d9794bee0e19ac4a981a15a1dcc272e50119
BU-EC444/esp-idf
components/driver/pulse_cnt.c
[ "Apache-2.0" ]
C
check_pulse_cnt_driver_conflict
void
__attribute__((constructor)) static void check_pulse_cnt_driver_conflict(void) { extern int pcnt_driver_init_count; pcnt_driver_init_count++; if (pcnt_driver_init_count > 1) { ESP_EARLY_LOGE(TAG, "CONFLICT! The pulse_cnt driver can't work along with the legacy pcnt driver"); abort(); } }
/** * @brief This function will be called during start up, to check that pulse_cnt driver is not running along with the legacy pcnt driver */
@brief This function will be called during start up, to check that pulse_cnt driver is not running along with the legacy pcnt driver
[ "@brief", "This", "function", "will", "be", "called", "during", "start", "up", "to", "check", "that", "pulse_cnt", "driver", "is", "not", "running", "along", "with", "the", "legacy", "pcnt", "driver" ]
__attribute__((constructor)) static void check_pulse_cnt_driver_conflict(void) { extern int pcnt_driver_init_count; pcnt_driver_init_count++; if (pcnt_driver_init_count > 1) { ESP_EARLY_LOGE(TAG, "CONFLICT! The pulse_cnt driver can't work along with the legacy pcnt driver"); abort(); } }
[ "__attribute__", "(", "(", "constructor", ")", ")", "static", "void", "check_pulse_cnt_driver_conflict", "(", "void", ")", "{", "extern", "int", "pcnt_driver_init_count", ";", "pcnt_driver_init_count", "++", ";", "if", "(", "pcnt_driver_init_count", ">", "1", ")", "{", "ESP_EARLY_LOGE", "(", "TAG", ",", "\"", "\"", ")", ";", "abort", "(", ")", ";", "}", "}" ]
@brief This function will be called during start up, to check that pulse_cnt driver is not running along with the legacy pcnt driver
[ "@brief", "This", "function", "will", "be", "called", "during", "start", "up", "to", "check", "that", "pulse_cnt", "driver", "is", "not", "running", "along", "with", "the", "legacy", "pcnt", "driver" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
7ad342c57e963a2bf29740cec94b7c79eb95887e
BU-EC444/esp-idf
components/spi_flash/partition.c
[ "Apache-2.0" ]
C
load_partitions
esp_err_t
static esp_err_t load_partitions(void) { const uint8_t *p_start; const uint8_t *p_end; #if !CONFIG_IDF_TARGET_LINUX spi_flash_mmap_handle_t handle; #endif // Temporary list of loaded partitions, if valid then we copy this to s_partition_list typeof(s_partition_list) new_partitions_list = SLIST_HEAD_INITIALIZER(s_partition_list); partition_list_item_t *last = NULL; #if CONFIG_PARTITION_TABLE_MD5 const uint8_t *md5_part = NULL; const uint8_t *stored_md5; uint8_t calc_md5[ESP_ROM_MD5_DIGEST_LEN]; md5_context_t context; esp_rom_md5_init(&context); #endif uint32_t partition_align_pg_size = (ESP_PARTITION_TABLE_OFFSET) & ~(0x10000 - 1); uint32_t partition_pad = ESP_PARTITION_TABLE_OFFSET - partition_align_pg_size; #if CONFIG_IDF_TARGET_LINUX esp_err_t err = esp_partition_file_mmap(&p_start); #else esp_err_t err = spi_flash_mmap(partition_align_pg_size, SPI_FLASH_SEC_SIZE, SPI_FLASH_MMAP_DATA, (const void **)&p_start, &handle); #endif if (err != ESP_OK) { return err; } // calculate partition address within mmap-ed region p_start += partition_pad; p_end = p_start + SPI_FLASH_SEC_SIZE; for (const uint8_t *p_entry = p_start; p_entry < p_end; p_entry += sizeof(esp_partition_info_t)) { esp_partition_info_t entry; // copying to RAM instead of using pointer to flash to avoid any chance of TOCTOU due to cache miss // when flash encryption is used memcpy(&entry, p_entry, sizeof(entry)); #if CONFIG_PARTITION_TABLE_MD5 if (entry.magic == ESP_PARTITION_MAGIC_MD5) { md5_part = p_entry; break; } #endif if (entry.magic != ESP_PARTITION_MAGIC) { break; } #if CONFIG_PARTITION_TABLE_MD5 esp_rom_md5_update(&context, &entry, sizeof(entry)); #endif // allocate new linked list item and populate it with data from partition table partition_list_item_t *item = (partition_list_item_t *) calloc(sizeof(partition_list_item_t), 1); if (item == NULL) { err = ESP_ERR_NO_MEM; break; } #if CONFIG_IDF_TARGET_LINUX item->info.flash_chip = NULL; #else item->info.flash_chip = esp_flash_default_chip; #endif item->info.address = entry.pos.offset; item->info.size = entry.pos.size; item->info.type = entry.type; item->info.subtype = entry.subtype; item->info.encrypted = entry.flags & PART_FLAG_ENCRYPTED; item->user_registered = false; #if CONFIG_IDF_TARGET_LINUX item->info.encrypted = false; #else if (!esp_flash_encryption_enabled()) { /* If flash encryption is not turned on, no partitions should be treated as encrypted */ item->info.encrypted = false; } else if (entry.type == ESP_PARTITION_TYPE_APP || (entry.type == ESP_PARTITION_TYPE_DATA && entry.subtype == ESP_PARTITION_SUBTYPE_DATA_OTA) || (entry.type == ESP_PARTITION_TYPE_DATA && entry.subtype == ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS)) { /* If encryption is turned on, all app partitions and OTA data are always encrypted */ item->info.encrypted = true; } #endif #if CONFIG_NVS_COMPATIBLE_PRE_V4_3_ENCRYPTION_FLAG if (entry.type == ESP_PARTITION_TYPE_DATA && entry.subtype == ESP_PARTITION_SUBTYPE_DATA_NVS && (entry.flags & PART_FLAG_ENCRYPTED)) { ESP_LOGI(TAG, "Ignoring encrypted flag for \"%s\" partition", entry.label); item->info.encrypted = false; } #endif // item->info.label is initialized by calloc, so resulting string will be null terminated strncpy(item->info.label, (const char *) entry.label, sizeof(item->info.label) - 1); // add it to the list if (last == NULL) { SLIST_INSERT_HEAD(&new_partitions_list, item, next); } else { SLIST_INSERT_AFTER(last, item, next); } last = item; } #if CONFIG_PARTITION_TABLE_MD5 if (md5_part == NULL) { ESP_LOGE(TAG, "No MD5 found in partition table"); err = ESP_ERR_NOT_FOUND; } else { stored_md5 = md5_part + ESP_PARTITION_MD5_OFFSET; esp_rom_md5_final(calc_md5, &context); #if !CONFIG_IDF_TARGET_LINUX ESP_LOG_BUFFER_HEXDUMP("calculated md5", calc_md5, ESP_ROM_MD5_DIGEST_LEN, ESP_LOG_VERBOSE); ESP_LOG_BUFFER_HEXDUMP("stored md5", stored_md5, ESP_ROM_MD5_DIGEST_LEN, ESP_LOG_VERBOSE); #endif if (memcmp(calc_md5, stored_md5, ESP_ROM_MD5_DIGEST_LEN) != 0) { ESP_LOGE(TAG, "Partition table MD5 mismatch"); err = ESP_ERR_INVALID_STATE; } else { ESP_LOGV(TAG, "Partition table MD5 verified"); } } #endif if (err == ESP_OK) { /* Don't copy the list to the static variable unless it's verified */ s_partition_list = new_partitions_list; } else { /* Otherwise, free all the memory we just allocated */ partition_list_item_t *it = new_partitions_list.slh_first; while (it) { partition_list_item_t *next = it->next.sle_next; free(it); it = next; } } #if !CONFIG_IDF_TARGET_LINUX spi_flash_munmap(handle); #endif return err; }
// Create linked list of partition_list_item_t structures. // This function is called only once, with s_partition_list_lock taken.
Create linked list of partition_list_item_t structures. This function is called only once, with s_partition_list_lock taken.
[ "Create", "linked", "list", "of", "partition_list_item_t", "structures", ".", "This", "function", "is", "called", "only", "once", "with", "s_partition_list_lock", "taken", "." ]
static esp_err_t load_partitions(void) { const uint8_t *p_start; const uint8_t *p_end; #if !CONFIG_IDF_TARGET_LINUX spi_flash_mmap_handle_t handle; #endif typeof(s_partition_list) new_partitions_list = SLIST_HEAD_INITIALIZER(s_partition_list); partition_list_item_t *last = NULL; #if CONFIG_PARTITION_TABLE_MD5 const uint8_t *md5_part = NULL; const uint8_t *stored_md5; uint8_t calc_md5[ESP_ROM_MD5_DIGEST_LEN]; md5_context_t context; esp_rom_md5_init(&context); #endif uint32_t partition_align_pg_size = (ESP_PARTITION_TABLE_OFFSET) & ~(0x10000 - 1); uint32_t partition_pad = ESP_PARTITION_TABLE_OFFSET - partition_align_pg_size; #if CONFIG_IDF_TARGET_LINUX esp_err_t err = esp_partition_file_mmap(&p_start); #else esp_err_t err = spi_flash_mmap(partition_align_pg_size, SPI_FLASH_SEC_SIZE, SPI_FLASH_MMAP_DATA, (const void **)&p_start, &handle); #endif if (err != ESP_OK) { return err; } p_start += partition_pad; p_end = p_start + SPI_FLASH_SEC_SIZE; for (const uint8_t *p_entry = p_start; p_entry < p_end; p_entry += sizeof(esp_partition_info_t)) { esp_partition_info_t entry; memcpy(&entry, p_entry, sizeof(entry)); #if CONFIG_PARTITION_TABLE_MD5 if (entry.magic == ESP_PARTITION_MAGIC_MD5) { md5_part = p_entry; break; } #endif if (entry.magic != ESP_PARTITION_MAGIC) { break; } #if CONFIG_PARTITION_TABLE_MD5 esp_rom_md5_update(&context, &entry, sizeof(entry)); #endif partition_list_item_t *item = (partition_list_item_t *) calloc(sizeof(partition_list_item_t), 1); if (item == NULL) { err = ESP_ERR_NO_MEM; break; } #if CONFIG_IDF_TARGET_LINUX item->info.flash_chip = NULL; #else item->info.flash_chip = esp_flash_default_chip; #endif item->info.address = entry.pos.offset; item->info.size = entry.pos.size; item->info.type = entry.type; item->info.subtype = entry.subtype; item->info.encrypted = entry.flags & PART_FLAG_ENCRYPTED; item->user_registered = false; #if CONFIG_IDF_TARGET_LINUX item->info.encrypted = false; #else if (!esp_flash_encryption_enabled()) { item->info.encrypted = false; } else if (entry.type == ESP_PARTITION_TYPE_APP || (entry.type == ESP_PARTITION_TYPE_DATA && entry.subtype == ESP_PARTITION_SUBTYPE_DATA_OTA) || (entry.type == ESP_PARTITION_TYPE_DATA && entry.subtype == ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS)) { item->info.encrypted = true; } #endif #if CONFIG_NVS_COMPATIBLE_PRE_V4_3_ENCRYPTION_FLAG if (entry.type == ESP_PARTITION_TYPE_DATA && entry.subtype == ESP_PARTITION_SUBTYPE_DATA_NVS && (entry.flags & PART_FLAG_ENCRYPTED)) { ESP_LOGI(TAG, "Ignoring encrypted flag for \"%s\" partition", entry.label); item->info.encrypted = false; } #endif strncpy(item->info.label, (const char *) entry.label, sizeof(item->info.label) - 1); if (last == NULL) { SLIST_INSERT_HEAD(&new_partitions_list, item, next); } else { SLIST_INSERT_AFTER(last, item, next); } last = item; } #if CONFIG_PARTITION_TABLE_MD5 if (md5_part == NULL) { ESP_LOGE(TAG, "No MD5 found in partition table"); err = ESP_ERR_NOT_FOUND; } else { stored_md5 = md5_part + ESP_PARTITION_MD5_OFFSET; esp_rom_md5_final(calc_md5, &context); #if !CONFIG_IDF_TARGET_LINUX ESP_LOG_BUFFER_HEXDUMP("calculated md5", calc_md5, ESP_ROM_MD5_DIGEST_LEN, ESP_LOG_VERBOSE); ESP_LOG_BUFFER_HEXDUMP("stored md5", stored_md5, ESP_ROM_MD5_DIGEST_LEN, ESP_LOG_VERBOSE); #endif if (memcmp(calc_md5, stored_md5, ESP_ROM_MD5_DIGEST_LEN) != 0) { ESP_LOGE(TAG, "Partition table MD5 mismatch"); err = ESP_ERR_INVALID_STATE; } else { ESP_LOGV(TAG, "Partition table MD5 verified"); } } #endif if (err == ESP_OK) { s_partition_list = new_partitions_list; } else { partition_list_item_t *it = new_partitions_list.slh_first; while (it) { partition_list_item_t *next = it->next.sle_next; free(it); it = next; } } #if !CONFIG_IDF_TARGET_LINUX spi_flash_munmap(handle); #endif return err; }
[ "static", "esp_err_t", "load_partitions", "(", "void", ")", "{", "const", "uint8_t", "*", "p_start", ";", "const", "uint8_t", "*", "p_end", ";", "#if", "!", "CONFIG_IDF_TARGET_LINUX", "\n", "spi_flash_mmap_handle_t", "handle", ";", "#endif", "typeof", "(", "s_partition_list", ")", "new_partitions_list", "=", "SLIST_HEAD_INITIALIZER", "(", "s_partition_list", ")", ";", "partition_list_item_t", "*", "last", "=", "NULL", ";", "#if", "CONFIG_PARTITION_TABLE_MD5", "\n", "const", "uint8_t", "*", "md5_part", "=", "NULL", ";", "const", "uint8_t", "*", "stored_md5", ";", "uint8_t", "calc_md5", "[", "ESP_ROM_MD5_DIGEST_LEN", "]", ";", "md5_context_t", "context", ";", "esp_rom_md5_init", "(", "&", "context", ")", ";", "#endif", "uint32_t", "partition_align_pg_size", "=", "(", "ESP_PARTITION_TABLE_OFFSET", ")", "&", "~", "(", "0x10000", "-", "1", ")", ";", "uint32_t", "partition_pad", "=", "ESP_PARTITION_TABLE_OFFSET", "-", "partition_align_pg_size", ";", "#if", "CONFIG_IDF_TARGET_LINUX", "\n", "esp_err_t", "err", "=", "esp_partition_file_mmap", "(", "&", "p_start", ")", ";", "#else", "esp_err_t", "err", "=", "spi_flash_mmap", "(", "partition_align_pg_size", ",", "SPI_FLASH_SEC_SIZE", ",", "SPI_FLASH_MMAP_DATA", ",", "(", "const", "void", "*", "*", ")", "&", "p_start", ",", "&", "handle", ")", ";", "#endif", "if", "(", "err", "!=", "ESP_OK", ")", "{", "return", "err", ";", "}", "p_start", "+=", "partition_pad", ";", "p_end", "=", "p_start", "+", "SPI_FLASH_SEC_SIZE", ";", "for", "(", "const", "uint8_t", "*", "p_entry", "=", "p_start", ";", "p_entry", "<", "p_end", ";", "p_entry", "+=", "sizeof", "(", "esp_partition_info_t", ")", ")", "{", "esp_partition_info_t", "entry", ";", "memcpy", "(", "&", "entry", ",", "p_entry", ",", "sizeof", "(", "entry", ")", ")", ";", "#if", "CONFIG_PARTITION_TABLE_MD5", "\n", "if", "(", "entry", ".", "magic", "==", "ESP_PARTITION_MAGIC_MD5", ")", "{", "md5_part", "=", "p_entry", ";", "break", ";", "}", "#endif", "if", "(", "entry", ".", "magic", "!=", "ESP_PARTITION_MAGIC", ")", "{", "break", ";", "}", "#if", "CONFIG_PARTITION_TABLE_MD5", "\n", "esp_rom_md5_update", "(", "&", "context", ",", "&", "entry", ",", "sizeof", "(", "entry", ")", ")", ";", "#endif", "partition_list_item_t", "*", "item", "=", "(", "partition_list_item_t", "*", ")", "calloc", "(", "sizeof", "(", "partition_list_item_t", ")", ",", "1", ")", ";", "if", "(", "item", "==", "NULL", ")", "{", "err", "=", "ESP_ERR_NO_MEM", ";", "break", ";", "}", "#if", "CONFIG_IDF_TARGET_LINUX", "\n", "item", "->", "info", ".", "flash_chip", "=", "NULL", ";", "#else", "item", "->", "info", ".", "flash_chip", "=", "esp_flash_default_chip", ";", "#endif", "item", "->", "info", ".", "address", "=", "entry", ".", "pos", ".", "offset", ";", "item", "->", "info", ".", "size", "=", "entry", ".", "pos", ".", "size", ";", "item", "->", "info", ".", "type", "=", "entry", ".", "type", ";", "item", "->", "info", ".", "subtype", "=", "entry", ".", "subtype", ";", "item", "->", "info", ".", "encrypted", "=", "entry", ".", "flags", "&", "PART_FLAG_ENCRYPTED", ";", "item", "->", "user_registered", "=", "false", ";", "#if", "CONFIG_IDF_TARGET_LINUX", "\n", "item", "->", "info", ".", "encrypted", "=", "false", ";", "#else", "if", "(", "!", "esp_flash_encryption_enabled", "(", ")", ")", "{", "item", "->", "info", ".", "encrypted", "=", "false", ";", "}", "else", "if", "(", "entry", ".", "type", "==", "ESP_PARTITION_TYPE_APP", "||", "(", "entry", ".", "type", "==", "ESP_PARTITION_TYPE_DATA", "&&", "entry", ".", "subtype", "==", "ESP_PARTITION_SUBTYPE_DATA_OTA", ")", "||", "(", "entry", ".", "type", "==", "ESP_PARTITION_TYPE_DATA", "&&", "entry", ".", "subtype", "==", "ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS", ")", ")", "{", "item", "->", "info", ".", "encrypted", "=", "true", ";", "}", "#endif", "#if", "CONFIG_NVS_COMPATIBLE_PRE_V4_3_ENCRYPTION_FLAG", "\n", "if", "(", "entry", ".", "type", "==", "ESP_PARTITION_TYPE_DATA", "&&", "entry", ".", "subtype", "==", "ESP_PARTITION_SUBTYPE_DATA_NVS", "&&", "(", "entry", ".", "flags", "&", "PART_FLAG_ENCRYPTED", ")", ")", "{", "ESP_LOGI", "(", "TAG", ",", "\"", "\\\"", "\\\"", "\"", ",", "entry", ".", "label", ")", ";", "item", "->", "info", ".", "encrypted", "=", "false", ";", "}", "#endif", "strncpy", "(", "item", "->", "info", ".", "label", ",", "(", "const", "char", "*", ")", "entry", ".", "label", ",", "sizeof", "(", "item", "->", "info", ".", "label", ")", "-", "1", ")", ";", "if", "(", "last", "==", "NULL", ")", "{", "SLIST_INSERT_HEAD", "(", "&", "new_partitions_list", ",", "item", ",", "next", ")", ";", "}", "else", "{", "SLIST_INSERT_AFTER", "(", "last", ",", "item", ",", "next", ")", ";", "}", "last", "=", "item", ";", "}", "#if", "CONFIG_PARTITION_TABLE_MD5", "\n", "if", "(", "md5_part", "==", "NULL", ")", "{", "ESP_LOGE", "(", "TAG", ",", "\"", "\"", ")", ";", "err", "=", "ESP_ERR_NOT_FOUND", ";", "}", "else", "{", "stored_md5", "=", "md5_part", "+", "ESP_PARTITION_MD5_OFFSET", ";", "esp_rom_md5_final", "(", "calc_md5", ",", "&", "context", ")", ";", "#if", "!", "CONFIG_IDF_TARGET_LINUX", "\n", "ESP_LOG_BUFFER_HEXDUMP", "(", "\"", "\"", ",", "calc_md5", ",", "ESP_ROM_MD5_DIGEST_LEN", ",", "ESP_LOG_VERBOSE", ")", ";", "ESP_LOG_BUFFER_HEXDUMP", "(", "\"", "\"", ",", "stored_md5", ",", "ESP_ROM_MD5_DIGEST_LEN", ",", "ESP_LOG_VERBOSE", ")", ";", "#endif", "if", "(", "memcmp", "(", "calc_md5", ",", "stored_md5", ",", "ESP_ROM_MD5_DIGEST_LEN", ")", "!=", "0", ")", "{", "ESP_LOGE", "(", "TAG", ",", "\"", "\"", ")", ";", "err", "=", "ESP_ERR_INVALID_STATE", ";", "}", "else", "{", "ESP_LOGV", "(", "TAG", ",", "\"", "\"", ")", ";", "}", "}", "#endif", "if", "(", "err", "==", "ESP_OK", ")", "{", "s_partition_list", "=", "new_partitions_list", ";", "}", "else", "{", "partition_list_item_t", "*", "it", "=", "new_partitions_list", ".", "slh_first", ";", "while", "(", "it", ")", "{", "partition_list_item_t", "*", "next", "=", "it", "->", "next", ".", "sle_next", ";", "free", "(", "it", ")", ";", "it", "=", "next", ";", "}", "}", "#if", "!", "CONFIG_IDF_TARGET_LINUX", "\n", "spi_flash_munmap", "(", "handle", ")", ";", "#endif", "return", "err", ";", "}" ]
Create linked list of partition_list_item_t structures.
[ "Create", "linked", "list", "of", "partition_list_item_t", "structures", "." ]
[ "// Temporary list of loaded partitions, if valid then we copy this to s_partition_list", "// calculate partition address within mmap-ed region", "// copying to RAM instead of using pointer to flash to avoid any chance of TOCTOU due to cache miss", "// when flash encryption is used", "// allocate new linked list item and populate it with data from partition table", "/* If flash encryption is not turned on, no partitions should be treated as encrypted */", "/* If encryption is turned on, all app partitions and OTA data\n are always encrypted */", "// item->info.label is initialized by calloc, so resulting string will be null terminated", "// add it to the list", "/* Don't copy the list to the static variable unless it's verified */", "/* Otherwise, free all the memory we just allocated */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
cd00eaaf3ca84b9265300689bde466851522f2a6
Wimoto/firmware
WimotoBle/MMA8653FC Driver Code/mma8653.c
[ "Unlicense" ]
C
MMA8653_ReadXYZdata
bool
bool MMA8653_ReadXYZdata(uint32_t * ptr_to_Reg_val) { uint8_t base_address = MMA8653_OUT_X_MSB; /* Base address of the X_MSB register(first register of coordinates*/ uint8_t data_buffer[3] = {0xff,0xFF,0xFF}; /* Initializing data buffer */ uint8_t read_Reg_Val; if(false == MMA8653_read_register (MMA8653_STATUS, &read_Reg_Val)) return false; if (read_Reg_Val & MMA8653_CHECKING_STATUS) { if (twi_master_transfer (MMA8653_ADDRESS ,(uint8_t*)&base_address ,1 ,TWI_DONT_ISSUE_STOP)) { twi_master_transfer ( MMA8653_ADDRESS | TWI_READ_BIT ,data_buffer ,3 ,TWI_ISSUE_STOP); *ptr_to_Reg_val = ((data_buffer[0] << 24) | (data_buffer[1] << 16) | data_buffer[2]); return true; } } return false; }
/* Data is assumed to be in 8 bit format*/ /** *@brief Function to read the X,Y,Z data from OUT_X(Y,Z)_MSB, registers * *@details Check the ZYXDR bit in status register for X, Y, Z-axis new data ready, if the new data is ready * read the X,Y,Z axis data */
Data is assumed to be in 8 bit format
[ "Data", "is", "assumed", "to", "be", "in", "8", "bit", "format" ]
bool MMA8653_ReadXYZdata(uint32_t * ptr_to_Reg_val) { uint8_t base_address = MMA8653_OUT_X_MSB; uint8_t data_buffer[3] = {0xff,0xFF,0xFF}; uint8_t read_Reg_Val; if(false == MMA8653_read_register (MMA8653_STATUS, &read_Reg_Val)) return false; if (read_Reg_Val & MMA8653_CHECKING_STATUS) { if (twi_master_transfer (MMA8653_ADDRESS ,(uint8_t*)&base_address ,1 ,TWI_DONT_ISSUE_STOP)) { twi_master_transfer ( MMA8653_ADDRESS | TWI_READ_BIT ,data_buffer ,3 ,TWI_ISSUE_STOP); *ptr_to_Reg_val = ((data_buffer[0] << 24) | (data_buffer[1] << 16) | data_buffer[2]); return true; } } return false; }
[ "bool", "MMA8653_ReadXYZdata", "(", "uint32_t", "*", "ptr_to_Reg_val", ")", "{", "uint8_t", "base_address", "=", "MMA8653_OUT_X_MSB", ";", "uint8_t", "data_buffer", "[", "3", "]", "=", "{", "0xff", ",", "0xFF", ",", "0xFF", "}", ";", "uint8_t", "read_Reg_Val", ";", "if", "(", "false", "==", "MMA8653_read_register", "(", "MMA8653_STATUS", ",", "&", "read_Reg_Val", ")", ")", "return", "false", ";", "if", "(", "read_Reg_Val", "&", "MMA8653_CHECKING_STATUS", ")", "{", "if", "(", "twi_master_transfer", "(", "MMA8653_ADDRESS", ",", "(", "uint8_t", "*", ")", "&", "base_address", ",", "1", ",", "TWI_DONT_ISSUE_STOP", ")", ")", "{", "twi_master_transfer", "(", "MMA8653_ADDRESS", "|", "TWI_READ_BIT", ",", "data_buffer", ",", "3", ",", "TWI_ISSUE_STOP", ")", ";", "*", "ptr_to_Reg_val", "=", "(", "(", "data_buffer", "[", "0", "]", "<<", "24", ")", "|", "(", "data_buffer", "[", "1", "]", "<<", "16", ")", "|", "data_buffer", "[", "2", "]", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Data is assumed to be in 8 bit format
[ "Data", "is", "assumed", "to", "be", "in", "8", "bit", "format" ]
[ "/* Base address of the X_MSB register(first register of coordinates*/", "/* Initializing data buffer */" ]
[ { "param": "ptr_to_Reg_val", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ptr_to_Reg_val", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [ { "identifier": "brief", "docstring": "Function to read the X,Y,Z data from OUT_X(Y,Z)_MSB, registers", "docstring_tokens": [ "Function", "to", "read", "the", "X", "Y", "Z", "data", "from", "OUT_X", "(", "Y", "Z", ")", "_MSB", "registers" ] }, { "identifier": "details", "docstring": "Check the ZYXDR bit in status register for X, Y, Z-axis new data ready, if the new data is ready\nread the X,Y,Z axis data", "docstring_tokens": [ "Check", "the", "ZYXDR", "bit", "in", "status", "register", "for", "X", "Y", "Z", "-", "axis", "new", "data", "ready", "if", "the", "new", "data", "is", "ready", "read", "the", "X", "Y", "Z", "axis", "data" ] } ] }
8bfc04b581f65b4a71d2a04f515cd61749834642
Wimoto/firmware
WimotoBle/ble_wimoto_sentry_app/connect.c
[ "Unlicense" ]
C
twi_turn_OFF
void
void twi_turn_OFF(void) { NRF_TWI0->POWER = 0; NRF_TWI1->POWER = 0; }
/* Turn OFF TWI if TWI is not using , considering power optimization*/
Turn OFF TWI if TWI is not using , considering power optimization
[ "Turn", "OFF", "TWI", "if", "TWI", "is", "not", "using", "considering", "power", "optimization" ]
void twi_turn_OFF(void) { NRF_TWI0->POWER = 0; NRF_TWI1->POWER = 0; }
[ "void", "twi_turn_OFF", "(", "void", ")", "{", "NRF_TWI0", "->", "POWER", "=", "0", ";", "NRF_TWI1", "->", "POWER", "=", "0", ";", "}" ]
Turn OFF TWI if TWI is not using , considering power optimization
[ "Turn", "OFF", "TWI", "if", "TWI", "is", "not", "using", "considering", "power", "optimization" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8bfc04b581f65b4a71d2a04f515cd61749834642
Wimoto/firmware
WimotoBle/ble_wimoto_sentry_app/connect.c
[ "Unlicense" ]
C
twi_turn_ON
void
void twi_turn_ON(void) { NRF_TWI1->POWER = 1; twi_master_init(); }
/* Turn ON TWI (used only after turning it OFF)*/
Turn ON TWI (used only after turning it OFF)
[ "Turn", "ON", "TWI", "(", "used", "only", "after", "turning", "it", "OFF", ")" ]
void twi_turn_ON(void) { NRF_TWI1->POWER = 1; twi_master_init(); }
[ "void", "twi_turn_ON", "(", "void", ")", "{", "NRF_TWI1", "->", "POWER", "=", "1", ";", "twi_master_init", "(", ")", ";", "}" ]
Turn ON TWI (used only after turning it OFF)
[ "Turn", "ON", "TWI", "(", "used", "only", "after", "turning", "it", "OFF", ")" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
5a2d2c5b41ebdff28392d0712691bfb871bcf866
Wimoto/firmware
WimotoBle/ble_wimoto_thermo_app/adc_probe_temp.c
[ "Unlicense" ]
C
do_probe_temperature_measurement
uint16_t
uint16_t do_probe_temperature_measurement() { uint16_t adc_result; /* Result after ADC conversion*/ nrf_gpio_cfg_output(PROBE_SENSOR_ENERGIZE_PIN); /* Configure energize pin as output */ nrf_gpio_pin_dir_set(PROBE_SENSOR_ENERGIZE_PIN,NRF_GPIO_PIN_DIR_OUTPUT); /* Set the direction of output pin*/ nrf_gpio_pin_set(PROBE_SENSOR_ENERGIZE_PIN); /* Set the value of energize pin for ADC probe*/ nrf_gpio_cfg_input(PROBE_ADC_INPUT_AIN5_P04, NRF_GPIO_PIN_NOPULL); /*configure ADC input*/ adc_init(); /* Initialize ADC for probe temperature measurement */ // start ADC conversion NRF_ADC->TASKS_START = 1; // wait for conversion to end while (!NRF_ADC->EVENTS_END) {} NRF_ADC->EVENTS_END = 0; //Save your ADC result adc_result = NRF_ADC->RESULT; /* ADC result after conversion*/ NRF_ADC->TASKS_STOP = 1; NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled; /*Disable the ADC*/ nrf_gpio_pin_clear(PROBE_SENSOR_ENERGIZE_PIN); /* Clear the energize pin after the use of sensor*/ return adc_result; }
/** *@brief Function to read the sensor output value after using ADC (conversion of analog data into digital data using ADC) *@retval 10 bit data from the ADC , after conversion */
@brief Function to read the sensor output value after using ADC (conversion of analog data into digital data using ADC) @retval 10 bit data from the ADC , after conversion
[ "@brief", "Function", "to", "read", "the", "sensor", "output", "value", "after", "using", "ADC", "(", "conversion", "of", "analog", "data", "into", "digital", "data", "using", "ADC", ")", "@retval", "10", "bit", "data", "from", "the", "ADC", "after", "conversion" ]
uint16_t do_probe_temperature_measurement() { uint16_t adc_result; nrf_gpio_cfg_output(PROBE_SENSOR_ENERGIZE_PIN); nrf_gpio_pin_dir_set(PROBE_SENSOR_ENERGIZE_PIN,NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_set(PROBE_SENSOR_ENERGIZE_PIN); nrf_gpio_cfg_input(PROBE_ADC_INPUT_AIN5_P04, NRF_GPIO_PIN_NOPULL); adc_init(); NRF_ADC->TASKS_START = 1; while (!NRF_ADC->EVENTS_END) {} NRF_ADC->EVENTS_END = 0; adc_result = NRF_ADC->RESULT; NRF_ADC->TASKS_STOP = 1; NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled; nrf_gpio_pin_clear(PROBE_SENSOR_ENERGIZE_PIN); return adc_result; }
[ "uint16_t", "do_probe_temperature_measurement", "(", ")", "{", "uint16_t", "adc_result", ";", "nrf_gpio_cfg_output", "(", "PROBE_SENSOR_ENERGIZE_PIN", ")", ";", "nrf_gpio_pin_dir_set", "(", "PROBE_SENSOR_ENERGIZE_PIN", ",", "NRF_GPIO_PIN_DIR_OUTPUT", ")", ";", "nrf_gpio_pin_set", "(", "PROBE_SENSOR_ENERGIZE_PIN", ")", ";", "nrf_gpio_cfg_input", "(", "PROBE_ADC_INPUT_AIN5_P04", ",", "NRF_GPIO_PIN_NOPULL", ")", ";", "adc_init", "(", ")", ";", "NRF_ADC", "->", "TASKS_START", "=", "1", ";", "while", "(", "!", "NRF_ADC", "->", "EVENTS_END", ")", "{", "}", "NRF_ADC", "->", "EVENTS_END", "=", "0", ";", "adc_result", "=", "NRF_ADC", "->", "RESULT", ";", "NRF_ADC", "->", "TASKS_STOP", "=", "1", ";", "NRF_ADC", "->", "ENABLE", "=", "ADC_ENABLE_ENABLE_Disabled", ";", "nrf_gpio_pin_clear", "(", "PROBE_SENSOR_ENERGIZE_PIN", ")", ";", "return", "adc_result", ";", "}" ]
@brief Function to read the sensor output value after using ADC (conversion of analog data into digital data using ADC) @retval 10 bit data from the ADC , after conversion
[ "@brief", "Function", "to", "read", "the", "sensor", "output", "value", "after", "using", "ADC", "(", "conversion", "of", "analog", "data", "into", "digital", "data", "using", "ADC", ")", "@retval", "10", "bit", "data", "from", "the", "ADC", "after", "conversion" ]
[ "/* Result after ADC conversion*/", "/* Configure energize pin as output */", "/* Set the direction of output pin*/", "/* Set the value of energize pin for ADC probe*/", "/*configure ADC input*/", "/* Initialize ADC for probe temperature measurement */", "// start ADC conversion\r", "// wait for conversion to end\r", "//Save your ADC result\t", "/* ADC result after conversion*/", "/*Disable the ADC*/", "/* Clear the energize pin after the use of sensor*/" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
4a980d51d5028faedbd501c5c1e7ce0801c9f802
Wimoto/firmware
WimotoBle/ble_wimoto_clim_app/broadcast.c
[ "Unlicense" ]
C
do_battery_measurement
uint32_t
static uint32_t do_battery_measurement(void) { uint8_t adc_result; uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos; NRF_ADC->ENABLE = 1; NRF_ADC->TASKS_START = 1; while(!NRF_ADC->EVENTS_END); adc_result = NRF_ADC->RESULT; NRF_ADC->ENABLE = 0; batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts); return percentage_batt_lvl; }
/* This function measures the battery voltage using the bandgap as a reference. * 3.6 V will return 100 %, so depending on battery voltage, it might need scaling. */
This function measures the battery voltage using the bandgap as a reference. 3.6 V will return 100 %, so depending on battery voltage, it might need scaling.
[ "This", "function", "measures", "the", "battery", "voltage", "using", "the", "bandgap", "as", "a", "reference", ".", "3", ".", "6", "V", "will", "return", "100", "%", "so", "depending", "on", "battery", "voltage", "it", "might", "need", "scaling", "." ]
static uint32_t do_battery_measurement(void) { uint8_t adc_result; uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos; NRF_ADC->ENABLE = 1; NRF_ADC->TASKS_START = 1; while(!NRF_ADC->EVENTS_END); adc_result = NRF_ADC->RESULT; NRF_ADC->ENABLE = 0; batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts); return percentage_batt_lvl; }
[ "static", "uint32_t", "do_battery_measurement", "(", "void", ")", "{", "uint8_t", "adc_result", ";", "uint16_t", "batt_lvl_in_milli_volts", ";", "uint8_t", "percentage_batt_lvl", ";", "NRF_ADC", "->", "CONFIG", "=", "ADC_CONFIG_RES_8bit", "<<", "ADC_CONFIG_RES_Pos", "|", "ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling", "<<", "ADC_CONFIG_INPSEL_Pos", "|", "ADC_CONFIG_REFSEL_VBG", "<<", "ADC_CONFIG_REFSEL_Pos", ";", "NRF_ADC", "->", "ENABLE", "=", "1", ";", "NRF_ADC", "->", "TASKS_START", "=", "1", ";", "while", "(", "!", "NRF_ADC", "->", "EVENTS_END", ")", ";", "adc_result", "=", "NRF_ADC", "->", "RESULT", ";", "NRF_ADC", "->", "ENABLE", "=", "0", ";", "batt_lvl_in_milli_volts", "=", "ADC_RESULT_IN_MILLI_VOLTS", "(", "adc_result", ")", "+", "DIODE_FWD_VOLT_DROP_MILLIVOLTS", ";", "percentage_batt_lvl", "=", "battery_level_in_percent", "(", "batt_lvl_in_milli_volts", ")", ";", "return", "percentage_batt_lvl", ";", "}" ]
This function measures the battery voltage using the bandgap as a reference.
[ "This", "function", "measures", "the", "battery", "voltage", "using", "the", "bandgap", "as", "a", "reference", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
769602e7b6b3a20534accab2beeab02f4a69e5cd
Wimoto/firmware
WimotoBle/ble_wimoto_sentry_app/broadcast.c
[ "Unlicense" ]
C
do_battery_measurement
uint32_t
static uint32_t do_battery_measurement(void) { uint8_t adc_result; uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos; NRF_ADC->ENABLE = 1; NRF_ADC->TASKS_START = 1; while(!NRF_ADC->EVENTS_END); adc_result = NRF_ADC->RESULT; NRF_ADC->ENABLE = 0; batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts); return percentage_batt_lvl; }
/* This function measures the battery voltage using the bandgap as a reference. * 3.6 V will return 100 %, so depending on battery voltage */
This function measures the battery voltage using the bandgap as a reference. 3.6 V will return 100 %, so depending on battery voltage
[ "This", "function", "measures", "the", "battery", "voltage", "using", "the", "bandgap", "as", "a", "reference", ".", "3", ".", "6", "V", "will", "return", "100", "%", "so", "depending", "on", "battery", "voltage" ]
static uint32_t do_battery_measurement(void) { uint8_t adc_result; uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos; NRF_ADC->ENABLE = 1; NRF_ADC->TASKS_START = 1; while(!NRF_ADC->EVENTS_END); adc_result = NRF_ADC->RESULT; NRF_ADC->ENABLE = 0; batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts); return percentage_batt_lvl; }
[ "static", "uint32_t", "do_battery_measurement", "(", "void", ")", "{", "uint8_t", "adc_result", ";", "uint16_t", "batt_lvl_in_milli_volts", ";", "uint8_t", "percentage_batt_lvl", ";", "NRF_ADC", "->", "CONFIG", "=", "ADC_CONFIG_RES_8bit", "<<", "ADC_CONFIG_RES_Pos", "|", "ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling", "<<", "ADC_CONFIG_INPSEL_Pos", "|", "ADC_CONFIG_REFSEL_VBG", "<<", "ADC_CONFIG_REFSEL_Pos", ";", "NRF_ADC", "->", "ENABLE", "=", "1", ";", "NRF_ADC", "->", "TASKS_START", "=", "1", ";", "while", "(", "!", "NRF_ADC", "->", "EVENTS_END", ")", ";", "adc_result", "=", "NRF_ADC", "->", "RESULT", ";", "NRF_ADC", "->", "ENABLE", "=", "0", ";", "batt_lvl_in_milli_volts", "=", "ADC_RESULT_IN_MILLI_VOLTS", "(", "adc_result", ")", "+", "DIODE_FWD_VOLT_DROP_MILLIVOLTS", ";", "percentage_batt_lvl", "=", "battery_level_in_percent", "(", "batt_lvl_in_milli_volts", ")", ";", "return", "percentage_batt_lvl", ";", "}" ]
This function measures the battery voltage using the bandgap as a reference.
[ "This", "function", "measures", "the", "battery", "voltage", "using", "the", "bandgap", "as", "a", "reference", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c9125ec487b1e7e01734b57148098534e918fa2f
Wimoto/firmware
WimotoBle/ble_wimoto_thermo_app/broadcast.c
[ "Unlicense" ]
C
do_battery_measurement
uint8_t
static uint8_t do_battery_measurement(void) { uint8_t adc_result; uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos; NRF_ADC->ENABLE = 1; NRF_ADC->TASKS_START = 1; while(!NRF_ADC->EVENTS_END); adc_result = NRF_ADC->RESULT; NRF_ADC->ENABLE = 0; batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts); return percentage_batt_lvl; }
/* This function measures the battery voltage using the bandgap as a reference. * 3.6 V will return 100 %, so depending on battery voltage, it might need scaling. */
This function measures the battery voltage using the bandgap as a reference. 3.6 V will return 100 %, so depending on battery voltage, it might need scaling.
[ "This", "function", "measures", "the", "battery", "voltage", "using", "the", "bandgap", "as", "a", "reference", ".", "3", ".", "6", "V", "will", "return", "100", "%", "so", "depending", "on", "battery", "voltage", "it", "might", "need", "scaling", "." ]
static uint8_t do_battery_measurement(void) { uint8_t adc_result; uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos; NRF_ADC->ENABLE = 1; NRF_ADC->TASKS_START = 1; while(!NRF_ADC->EVENTS_END); adc_result = NRF_ADC->RESULT; NRF_ADC->ENABLE = 0; batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts); return percentage_batt_lvl; }
[ "static", "uint8_t", "do_battery_measurement", "(", "void", ")", "{", "uint8_t", "adc_result", ";", "uint16_t", "batt_lvl_in_milli_volts", ";", "uint8_t", "percentage_batt_lvl", ";", "NRF_ADC", "->", "CONFIG", "=", "ADC_CONFIG_RES_8bit", "<<", "ADC_CONFIG_RES_Pos", "|", "ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling", "<<", "ADC_CONFIG_INPSEL_Pos", "|", "ADC_CONFIG_REFSEL_VBG", "<<", "ADC_CONFIG_REFSEL_Pos", ";", "NRF_ADC", "->", "ENABLE", "=", "1", ";", "NRF_ADC", "->", "TASKS_START", "=", "1", ";", "while", "(", "!", "NRF_ADC", "->", "EVENTS_END", ")", ";", "adc_result", "=", "NRF_ADC", "->", "RESULT", ";", "NRF_ADC", "->", "ENABLE", "=", "0", ";", "batt_lvl_in_milli_volts", "=", "ADC_RESULT_IN_MILLI_VOLTS", "(", "adc_result", ")", "+", "DIODE_FWD_VOLT_DROP_MILLIVOLTS", ";", "percentage_batt_lvl", "=", "battery_level_in_percent", "(", "batt_lvl_in_milli_volts", ")", ";", "return", "percentage_batt_lvl", ";", "}" ]
This function measures the battery voltage using the bandgap as a reference.
[ "This", "function", "measures", "the", "battery", "voltage", "using", "the", "bandgap", "as", "a", "reference", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
b6d30c68260d4fab66b9dd8787653a0085784e63
AMOSSYS/OpenDTeX-Secure-Boot-DRTM
tools/libtcg.c
[ "BSD-3-Clause" ]
C
InsertKey
int
int InsertKey(long int depth, char *name, int isWellKnown, int flagsPCR) { TCG_KEY *kKey; if(currentKey->depth + 1 == depth) { //Insertion of key in the children of the current key kKey = malloc(sizeof(TCG_KEY)); if(kKey == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : out of memory\n", __FUNCTION__); return 1; } //Init the key kKey->kParent = currentKey; kKey->kChildren = 0; kKey->kBrother = 0; kKey->hKey = 0; kKey->hPolicy = 0; kKey->hPcrs = 0; kKey->depth = depth; kKey->isWellKnown = isWellKnown; kKey->flagsPCR = flagsPCR; strncpy(kKey->name, name, MAXSIZE); //Become a children of the current key currentKey->kChildren = kKey; //Become the current key currentKey = kKey; } else if(currentKey->depth == depth) { //Insertion of brother key if(depth == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, trying to create a key a the same level of SRK !\n", __FUNCTION__); return 1; } kKey = malloc(sizeof(TCG_KEY)); if(kKey == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, out of memory\n", __FUNCTION__); return 1; } //Init the key kKey->kParent = currentKey->kParent; kKey->kChildren = 0; kKey->kBrother = 0; kKey->hKey = 0; kKey->hPolicy = 0; kKey->hPcrs = 0; kKey->depth = currentKey->depth; kKey->isWellKnown = isWellKnown; kKey->flagsPCR = flagsPCR; strncpy(kKey->name, name, MAXSIZE); //Become a brother of the current key currentKey->kBrother = kKey; //Become the current key currentKey = kKey; } else if(currentKey->depth > depth){ //Insertion of a brother key at a lesser depth if(depth == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, trying to create a key a the same level of SRK !\n", __FUNCTION__); return 1; } while(currentKey->depth != depth) { currentKey = currentKey->kParent; } //Insertion of a brother kKey = malloc(sizeof(TCG_KEY)); if(kKey == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, out of memory\n", __FUNCTION__); return 1; } //Init the key kKey->kParent = currentKey->kParent; kKey->kChildren = 0; kKey->kBrother = 0; kKey->hKey = 0; kKey->hPolicy = 0; kKey->hPcrs = 0; kKey->depth = currentKey->depth; kKey->isWellKnown = isWellKnown; kKey->flagsPCR = flagsPCR; strncpy(kKey->name, name, MAXSIZE); //Become a brother of the current key currentKey->kBrother = kKey; //Become the current key currentKey = kKey; } else { //Invalid insertion fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, invalid insertion\n", __FUNCTION__); return 1; } return 0; }
//Insert a key in the key architecture. This key becomes the current key //return 0 if success
Insert a key in the key architecture. This key becomes the current key return 0 if success
[ "Insert", "a", "key", "in", "the", "key", "architecture", ".", "This", "key", "becomes", "the", "current", "key", "return", "0", "if", "success" ]
int InsertKey(long int depth, char *name, int isWellKnown, int flagsPCR) { TCG_KEY *kKey; if(currentKey->depth + 1 == depth) { kKey = malloc(sizeof(TCG_KEY)); if(kKey == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : out of memory\n", __FUNCTION__); return 1; } kKey->kParent = currentKey; kKey->kChildren = 0; kKey->kBrother = 0; kKey->hKey = 0; kKey->hPolicy = 0; kKey->hPcrs = 0; kKey->depth = depth; kKey->isWellKnown = isWellKnown; kKey->flagsPCR = flagsPCR; strncpy(kKey->name, name, MAXSIZE); currentKey->kChildren = kKey; currentKey = kKey; } else if(currentKey->depth == depth) { if(depth == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, trying to create a key a the same level of SRK !\n", __FUNCTION__); return 1; } kKey = malloc(sizeof(TCG_KEY)); if(kKey == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, out of memory\n", __FUNCTION__); return 1; } kKey->kParent = currentKey->kParent; kKey->kChildren = 0; kKey->kBrother = 0; kKey->hKey = 0; kKey->hPolicy = 0; kKey->hPcrs = 0; kKey->depth = currentKey->depth; kKey->isWellKnown = isWellKnown; kKey->flagsPCR = flagsPCR; strncpy(kKey->name, name, MAXSIZE); currentKey->kBrother = kKey; currentKey = kKey; } else if(currentKey->depth > depth){ if(depth == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, trying to create a key a the same level of SRK !\n", __FUNCTION__); return 1; } while(currentKey->depth != depth) { currentKey = currentKey->kParent; } kKey = malloc(sizeof(TCG_KEY)); if(kKey == 0) { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, out of memory\n", __FUNCTION__); return 1; } kKey->kParent = currentKey->kParent; kKey->kChildren = 0; kKey->kBrother = 0; kKey->hKey = 0; kKey->hPolicy = 0; kKey->hPcrs = 0; kKey->depth = currentKey->depth; kKey->isWellKnown = isWellKnown; kKey->flagsPCR = flagsPCR; strncpy(kKey->name, name, MAXSIZE); currentKey->kBrother = kKey; currentKey = kKey; } else { fprintf(stderr, "(%s) : During insertion of %s : \n", __FUNCTION__, name); fprintf(stderr, "(%s) : error, invalid insertion\n", __FUNCTION__); return 1; } return 0; }
[ "int", "InsertKey", "(", "long", "int", "depth", ",", "char", "*", "name", ",", "int", "isWellKnown", ",", "int", "flagsPCR", ")", "{", "TCG_KEY", "*", "kKey", ";", "if", "(", "currentKey", "->", "depth", "+", "1", "==", "depth", ")", "{", "kKey", "=", "malloc", "(", "sizeof", "(", "TCG_KEY", ")", ")", ";", "if", "(", "kKey", "==", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ",", "name", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ")", ";", "return", "1", ";", "}", "kKey", "->", "kParent", "=", "currentKey", ";", "kKey", "->", "kChildren", "=", "0", ";", "kKey", "->", "kBrother", "=", "0", ";", "kKey", "->", "hKey", "=", "0", ";", "kKey", "->", "hPolicy", "=", "0", ";", "kKey", "->", "hPcrs", "=", "0", ";", "kKey", "->", "depth", "=", "depth", ";", "kKey", "->", "isWellKnown", "=", "isWellKnown", ";", "kKey", "->", "flagsPCR", "=", "flagsPCR", ";", "strncpy", "(", "kKey", "->", "name", ",", "name", ",", "MAXSIZE", ")", ";", "currentKey", "->", "kChildren", "=", "kKey", ";", "currentKey", "=", "kKey", ";", "}", "else", "if", "(", "currentKey", "->", "depth", "==", "depth", ")", "{", "if", "(", "depth", "==", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ",", "name", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ")", ";", "return", "1", ";", "}", "kKey", "=", "malloc", "(", "sizeof", "(", "TCG_KEY", ")", ")", ";", "if", "(", "kKey", "==", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ",", "name", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ")", ";", "return", "1", ";", "}", "kKey", "->", "kParent", "=", "currentKey", "->", "kParent", ";", "kKey", "->", "kChildren", "=", "0", ";", "kKey", "->", "kBrother", "=", "0", ";", "kKey", "->", "hKey", "=", "0", ";", "kKey", "->", "hPolicy", "=", "0", ";", "kKey", "->", "hPcrs", "=", "0", ";", "kKey", "->", "depth", "=", "currentKey", "->", "depth", ";", "kKey", "->", "isWellKnown", "=", "isWellKnown", ";", "kKey", "->", "flagsPCR", "=", "flagsPCR", ";", "strncpy", "(", "kKey", "->", "name", ",", "name", ",", "MAXSIZE", ")", ";", "currentKey", "->", "kBrother", "=", "kKey", ";", "currentKey", "=", "kKey", ";", "}", "else", "if", "(", "currentKey", "->", "depth", ">", "depth", ")", "{", "if", "(", "depth", "==", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ",", "name", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ")", ";", "return", "1", ";", "}", "while", "(", "currentKey", "->", "depth", "!=", "depth", ")", "{", "currentKey", "=", "currentKey", "->", "kParent", ";", "}", "kKey", "=", "malloc", "(", "sizeof", "(", "TCG_KEY", ")", ")", ";", "if", "(", "kKey", "==", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ",", "name", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ")", ";", "return", "1", ";", "}", "kKey", "->", "kParent", "=", "currentKey", "->", "kParent", ";", "kKey", "->", "kChildren", "=", "0", ";", "kKey", "->", "kBrother", "=", "0", ";", "kKey", "->", "hKey", "=", "0", ";", "kKey", "->", "hPolicy", "=", "0", ";", "kKey", "->", "hPcrs", "=", "0", ";", "kKey", "->", "depth", "=", "currentKey", "->", "depth", ";", "kKey", "->", "isWellKnown", "=", "isWellKnown", ";", "kKey", "->", "flagsPCR", "=", "flagsPCR", ";", "strncpy", "(", "kKey", "->", "name", ",", "name", ",", "MAXSIZE", ")", ";", "currentKey", "->", "kBrother", "=", "kKey", ";", "currentKey", "=", "kKey", ";", "}", "else", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ",", "name", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ")", ";", "return", "1", ";", "}", "return", "0", ";", "}" ]
Insert a key in the key architecture.
[ "Insert", "a", "key", "in", "the", "key", "architecture", "." ]
[ "//Insertion of key in the children of the current key", "//Init the key", "//Become a children of the current key", "//Become the current key", "//Insertion of brother key", "//Init the key", "//Become a brother of the current key", "//Become the current key", "//Insertion of a brother key at a lesser depth", "//Insertion of a brother", "//Init the key", "//Become a brother of the current key", "//Become the current key", "//Invalid insertion" ]
[ { "param": "depth", "type": "long int" }, { "param": "name", "type": "char" }, { "param": "isWellKnown", "type": "int" }, { "param": "flagsPCR", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "depth", "type": "long int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "isWellKnown", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "flagsPCR", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9183069545f1b84b7a1d845ba5fe256ab157d1ea
MDT-Maikel/sommerfeld
main_micromegas.c
[ "CC-BY-4.0" ]
C
alpha_strong
double
double alpha_strong(double q) { // Implement a cut off for the momentum q of 1 GeV to not enter the non-perturbative regime. q = fmax(q, 1.0); // MSbar masses for the quarks. double mtop = 160; double mbottom = 4.18; double mcharm = 1.28; // Determine number of active flavors. double nf = 6.0; if (q < mcharm) nf = 3.0; else if (q < mbottom) nf = 4.0; else if (q < mtop) nf = 5.0; // Determine the threshold lambdas. double lambda = 0.08896768177299201; if (q < mcharm) lambda = 0.33348050663724466; else if (q < mbottom) lambda = 0.2913885366061117; else if (q < mtop) lambda = 0.20953346238097081; // Determine alpha_strong and return it. double t = log(pow(q / lambda, 2.0)); double z3 = 1.202056903159594; double b0 = (33.0 - 2.0 * nf) / (12.0 * M_PI); double b1 = (153.0 - 19.0 * nf) / (24.0 * pow(M_PI, 2.0)); double b2 = (2857.0 - 5033.0 / 9.0 * nf + 325.0 / 27.0 * pow(nf, 2.0)) / (128.0 * pow(M_PI, 3.0)); double b3 = ((149753.0 / 6.0 + 3564.0 * z3) - (1078361.0 / 162.0 + 6508.0 / 27.0 * z3) * nf + (50065.0 / 162.0 + 6472.0 / 81.0 * z3) * pow(nf, 2.0) + 1093.0 / 729.0 * pow(nf, 3.0)) / (256.0 * pow(M_PI, 4.0)); return 1.0 / (b0 * t) * (1.0 - b1 / pow(b0, 2.0) * log(t) / t + (pow(b1, 2.0) * (pow(log(t), 2.0) - log(t) - 1.0) + b0 * b2) / (pow(b0, 4.0) * pow(t, 2.0)) - 1.0 / (pow(b0, 6.0) * pow(t, 3.0)) * (pow(b1, 3.0) * (pow(log(t), 3.0) - 5.0 / 2.0 * pow(log(t), 2.0) - 2.0 * log(t) + 1.0 / 2.0) + 3.0 * b0 * b1 * b2 * log(t) - 0.5 * pow(b0, 2.0) * b3)); }
// See the Mathematica notebook for the details of this definition of alpha_strong.
See the Mathematica notebook for the details of this definition of alpha_strong.
[ "See", "the", "Mathematica", "notebook", "for", "the", "details", "of", "this", "definition", "of", "alpha_strong", "." ]
double alpha_strong(double q) { q = fmax(q, 1.0); double mtop = 160; double mbottom = 4.18; double mcharm = 1.28; double nf = 6.0; if (q < mcharm) nf = 3.0; else if (q < mbottom) nf = 4.0; else if (q < mtop) nf = 5.0; double lambda = 0.08896768177299201; if (q < mcharm) lambda = 0.33348050663724466; else if (q < mbottom) lambda = 0.2913885366061117; else if (q < mtop) lambda = 0.20953346238097081; double t = log(pow(q / lambda, 2.0)); double z3 = 1.202056903159594; double b0 = (33.0 - 2.0 * nf) / (12.0 * M_PI); double b1 = (153.0 - 19.0 * nf) / (24.0 * pow(M_PI, 2.0)); double b2 = (2857.0 - 5033.0 / 9.0 * nf + 325.0 / 27.0 * pow(nf, 2.0)) / (128.0 * pow(M_PI, 3.0)); double b3 = ((149753.0 / 6.0 + 3564.0 * z3) - (1078361.0 / 162.0 + 6508.0 / 27.0 * z3) * nf + (50065.0 / 162.0 + 6472.0 / 81.0 * z3) * pow(nf, 2.0) + 1093.0 / 729.0 * pow(nf, 3.0)) / (256.0 * pow(M_PI, 4.0)); return 1.0 / (b0 * t) * (1.0 - b1 / pow(b0, 2.0) * log(t) / t + (pow(b1, 2.0) * (pow(log(t), 2.0) - log(t) - 1.0) + b0 * b2) / (pow(b0, 4.0) * pow(t, 2.0)) - 1.0 / (pow(b0, 6.0) * pow(t, 3.0)) * (pow(b1, 3.0) * (pow(log(t), 3.0) - 5.0 / 2.0 * pow(log(t), 2.0) - 2.0 * log(t) + 1.0 / 2.0) + 3.0 * b0 * b1 * b2 * log(t) - 0.5 * pow(b0, 2.0) * b3)); }
[ "double", "alpha_strong", "(", "double", "q", ")", "{", "q", "=", "fmax", "(", "q", ",", "1.0", ")", ";", "double", "mtop", "=", "160", ";", "double", "mbottom", "=", "4.18", ";", "double", "mcharm", "=", "1.28", ";", "double", "nf", "=", "6.0", ";", "if", "(", "q", "<", "mcharm", ")", "nf", "=", "3.0", ";", "else", "if", "(", "q", "<", "mbottom", ")", "nf", "=", "4.0", ";", "else", "if", "(", "q", "<", "mtop", ")", "nf", "=", "5.0", ";", "double", "lambda", "=", "0.08896768177299201", ";", "if", "(", "q", "<", "mcharm", ")", "lambda", "=", "0.33348050663724466", ";", "else", "if", "(", "q", "<", "mbottom", ")", "lambda", "=", "0.2913885366061117", ";", "else", "if", "(", "q", "<", "mtop", ")", "lambda", "=", "0.20953346238097081", ";", "double", "t", "=", "log", "(", "pow", "(", "q", "/", "lambda", ",", "2.0", ")", ")", ";", "double", "z3", "=", "1.202056903159594", ";", "double", "b0", "=", "(", "33.0", "-", "2.0", "*", "nf", ")", "/", "(", "12.0", "*", "M_PI", ")", ";", "double", "b1", "=", "(", "153.0", "-", "19.0", "*", "nf", ")", "/", "(", "24.0", "*", "pow", "(", "M_PI", ",", "2.0", ")", ")", ";", "double", "b2", "=", "(", "2857.0", "-", "5033.0", "/", "9.0", "*", "nf", "+", "325.0", "/", "27.0", "*", "pow", "(", "nf", ",", "2.0", ")", ")", "/", "(", "128.0", "*", "pow", "(", "M_PI", ",", "3.0", ")", ")", ";", "double", "b3", "=", "(", "(", "149753.0", "/", "6.0", "+", "3564.0", "*", "z3", ")", "-", "(", "1078361.0", "/", "162.0", "+", "6508.0", "/", "27.0", "*", "z3", ")", "*", "nf", "+", "(", "50065.0", "/", "162.0", "+", "6472.0", "/", "81.0", "*", "z3", ")", "*", "pow", "(", "nf", ",", "2.0", ")", "+", "1093.0", "/", "729.0", "*", "pow", "(", "nf", ",", "3.0", ")", ")", "/", "(", "256.0", "*", "pow", "(", "M_PI", ",", "4.0", ")", ")", ";", "return", "1.0", "/", "(", "b0", "*", "t", ")", "*", "(", "1.0", "-", "b1", "/", "pow", "(", "b0", ",", "2.0", ")", "*", "log", "(", "t", ")", "/", "t", "+", "(", "pow", "(", "b1", ",", "2.0", ")", "*", "(", "pow", "(", "log", "(", "t", ")", ",", "2.0", ")", "-", "log", "(", "t", ")", "-", "1.0", ")", "+", "b0", "*", "b2", ")", "/", "(", "pow", "(", "b0", ",", "4.0", ")", "*", "pow", "(", "t", ",", "2.0", ")", ")", "-", "1.0", "/", "(", "pow", "(", "b0", ",", "6.0", ")", "*", "pow", "(", "t", ",", "3.0", ")", ")", "*", "(", "pow", "(", "b1", ",", "3.0", ")", "*", "(", "pow", "(", "log", "(", "t", ")", ",", "3.0", ")", "-", "5.0", "/", "2.0", "*", "pow", "(", "log", "(", "t", ")", ",", "2.0", ")", "-", "2.0", "*", "log", "(", "t", ")", "+", "1.0", "/", "2.0", ")", "+", "3.0", "*", "b0", "*", "b1", "*", "b2", "*", "log", "(", "t", ")", "-", "0.5", "*", "pow", "(", "b0", ",", "2.0", ")", "*", "b3", ")", ")", ";", "}" ]
See the Mathematica notebook for the details of this definition of alpha_strong.
[ "See", "the", "Mathematica", "notebook", "for", "the", "details", "of", "this", "definition", "of", "alpha_strong", "." ]
[ "// Implement a cut off for the momentum q of 1 GeV to not enter the non-perturbative regime.", "// MSbar masses for the quarks.", "// Determine number of active flavors.", "// Determine the threshold lambdas.", "// Determine alpha_strong and return it." ]
[ { "param": "q", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "q", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9183069545f1b84b7a1d845ba5fe256ab157d1ea
MDT-Maikel/sommerfeld
main_micromegas.c
[ "CC-BY-4.0" ]
C
exp_cut
double
double exp_cut(double x) { if (x < -50) return 0; return exp(x); }
// Helper function to compute an exponential without underflowing.
Helper function to compute an exponential without underflowing.
[ "Helper", "function", "to", "compute", "an", "exponential", "without", "underflowing", "." ]
double exp_cut(double x) { if (x < -50) return 0; return exp(x); }
[ "double", "exp_cut", "(", "double", "x", ")", "{", "if", "(", "x", "<", "-50", ")", "return", "0", ";", "return", "exp", "(", "x", ")", ";", "}" ]
Helper function to compute an exponential without underflowing.
[ "Helper", "function", "to", "compute", "an", "exponential", "without", "underflowing", "." ]
[]
[ { "param": "x", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "x", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9183069545f1b84b7a1d845ba5fe256ab157d1ea
MDT-Maikel/sommerfeld
main_micromegas.c
[ "CC-BY-4.0" ]
C
alphaS_bs
double
double alphaS_bs(int color, double m, double *alpha_table) { // Min, max and step size of the table. int mmin = 0, mmax = 20000, mstep = 10; int color_index; if (color == 3) color_index = 0; if (color == 6) color_index = 1; if (color == 8) color_index = 2; int mbin = (int) floor((m - mmin) / mstep + 0.001); return alpha_table[mbin * 3 + color_index]; }
// Alpha strong for the bound state formation is determined from a recursive formula in Mathermatica and is read in from a table.
Alpha strong for the bound state formation is determined from a recursive formula in Mathermatica and is read in from a table.
[ "Alpha", "strong", "for", "the", "bound", "state", "formation", "is", "determined", "from", "a", "recursive", "formula", "in", "Mathermatica", "and", "is", "read", "in", "from", "a", "table", "." ]
double alphaS_bs(int color, double m, double *alpha_table) { int mmin = 0, mmax = 20000, mstep = 10; int color_index; if (color == 3) color_index = 0; if (color == 6) color_index = 1; if (color == 8) color_index = 2; int mbin = (int) floor((m - mmin) / mstep + 0.001); return alpha_table[mbin * 3 + color_index]; }
[ "double", "alphaS_bs", "(", "int", "color", ",", "double", "m", ",", "double", "*", "alpha_table", ")", "{", "int", "mmin", "=", "0", ",", "mmax", "=", "20000", ",", "mstep", "=", "10", ";", "int", "color_index", ";", "if", "(", "color", "==", "3", ")", "color_index", "=", "0", ";", "if", "(", "color", "==", "6", ")", "color_index", "=", "1", ";", "if", "(", "color", "==", "8", ")", "color_index", "=", "2", ";", "int", "mbin", "=", "(", "int", ")", "floor", "(", "(", "m", "-", "mmin", ")", "/", "mstep", "+", "0.001", ")", ";", "return", "alpha_table", "[", "mbin", "*", "3", "+", "color_index", "]", ";", "}" ]
Alpha strong for the bound state formation is determined from a recursive formula in Mathermatica and is read in from a table.
[ "Alpha", "strong", "for", "the", "bound", "state", "formation", "is", "determined", "from", "a", "recursive", "formula", "in", "Mathermatica", "and", "is", "read", "in", "from", "a", "table", "." ]
[ "// Min, max and step size of the table." ]
[ { "param": "color", "type": "int" }, { "param": "m", "type": "double" }, { "param": "alpha_table", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "color", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "m", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "alpha_table", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
805c9af8f163f09cea43b3aa12f02b6437b5495c
TomMinuzzo/CANOpenRobotController
src/core/CANopen/CANopenNode/stack/CO_SDOmaster.c
[ "Apache-2.0" ]
C
CO_SDOclient_receive
void
static void CO_SDOclient_receive(void *object, const CO_CANrxMsg_t *msg){ CO_SDOclient_t *SDO_C; SDO_C = (CO_SDOclient_t*)object; /* this is the correct pointer type of the first argument */ /* verify message length and message overflow (previous message was not processed yet) */ if((msg->DLC == 8U) && (!SDO_C->CANrxNew) && (SDO_C->state != SDO_STATE_NOTDEFINED)){ if(SDO_C->state != SDO_STATE_BLOCKUPLOAD_INPROGRES) { /* copy data and set 'new message' flag */ SDO_C->CANrxData[0] = msg->data[0]; SDO_C->CANrxData[1] = msg->data[1]; SDO_C->CANrxData[2] = msg->data[2]; SDO_C->CANrxData[3] = msg->data[3]; SDO_C->CANrxData[4] = msg->data[4]; SDO_C->CANrxData[5] = msg->data[5]; SDO_C->CANrxData[6] = msg->data[6]; SDO_C->CANrxData[7] = msg->data[7]; SDO_C->CANrxNew = true; } else { /* block upload, copy data directly */ uint8_t seqno; SDO_C->CANrxData[0] = msg->data[0]; seqno = SDO_C->CANrxData[0] & 0x7f; SDO_C->timeoutTimer = 0; SDO_C->timeoutTimerBLOCK = 0; /* check correct sequence number. */ if(seqno == (SDO_C->block_seqno + 1)) { /* block_seqno is correct */ uint8_t i; SDO_C->block_seqno++; /* copy data */ for(i=1; i<8; i++) { SDO_C->buffer[SDO_C->dataSizeTransfered++] = msg->data[i]; if(SDO_C->dataSizeTransfered >= SDO_C->bufferSize) { /* buffer full, break reception */ SDO_C->state = SDO_STATE_BLOCKUPLOAD_SUB_END; SDO_C->CANrxNew = true; break; } } /* break reception if last segment or block sequence is too large */ if(((SDO_C->CANrxData[0] & 0x80U) == 0x80U) || (SDO_C->block_seqno >= SDO_C->block_blksize)) { SDO_C->state = SDO_STATE_BLOCKUPLOAD_SUB_END; SDO_C->CANrxNew = true; } } else if((seqno == SDO_C->block_seqno) || (SDO_C->block_seqno == 0U)){ /* Ignore message, if it is duplicate or if sequence didn't started yet. */ } else { /* seqno is totally wrong, break reception. */ SDO_C->state = SDO_STATE_BLOCKUPLOAD_SUB_END; SDO_C->CANrxNew = true; } } /* Optional signal to RTOS, which can resume task, which handles SDO client. */ if(SDO_C->CANrxNew && SDO_C->pFunctSignal != NULL) { SDO_C->pFunctSignal(); } } }
/* * Read received message from CAN module. * * Function will be called (by CAN receive interrupt) every time, when CAN * message with correct identifier will be received. For more information and * description of parameters see file CO_driver.h. */
Read received message from CAN module. Function will be called (by CAN receive interrupt) every time, when CAN message with correct identifier will be received. For more information and description of parameters see file CO_driver.h.
[ "Read", "received", "message", "from", "CAN", "module", ".", "Function", "will", "be", "called", "(", "by", "CAN", "receive", "interrupt", ")", "every", "time", "when", "CAN", "message", "with", "correct", "identifier", "will", "be", "received", ".", "For", "more", "information", "and", "description", "of", "parameters", "see", "file", "CO_driver", ".", "h", "." ]
static void CO_SDOclient_receive(void *object, const CO_CANrxMsg_t *msg){ CO_SDOclient_t *SDO_C; SDO_C = (CO_SDOclient_t*)object; if((msg->DLC == 8U) && (!SDO_C->CANrxNew) && (SDO_C->state != SDO_STATE_NOTDEFINED)){ if(SDO_C->state != SDO_STATE_BLOCKUPLOAD_INPROGRES) { SDO_C->CANrxData[0] = msg->data[0]; SDO_C->CANrxData[1] = msg->data[1]; SDO_C->CANrxData[2] = msg->data[2]; SDO_C->CANrxData[3] = msg->data[3]; SDO_C->CANrxData[4] = msg->data[4]; SDO_C->CANrxData[5] = msg->data[5]; SDO_C->CANrxData[6] = msg->data[6]; SDO_C->CANrxData[7] = msg->data[7]; SDO_C->CANrxNew = true; } else { uint8_t seqno; SDO_C->CANrxData[0] = msg->data[0]; seqno = SDO_C->CANrxData[0] & 0x7f; SDO_C->timeoutTimer = 0; SDO_C->timeoutTimerBLOCK = 0; if(seqno == (SDO_C->block_seqno + 1)) { uint8_t i; SDO_C->block_seqno++; for(i=1; i<8; i++) { SDO_C->buffer[SDO_C->dataSizeTransfered++] = msg->data[i]; if(SDO_C->dataSizeTransfered >= SDO_C->bufferSize) { SDO_C->state = SDO_STATE_BLOCKUPLOAD_SUB_END; SDO_C->CANrxNew = true; break; } } if(((SDO_C->CANrxData[0] & 0x80U) == 0x80U) || (SDO_C->block_seqno >= SDO_C->block_blksize)) { SDO_C->state = SDO_STATE_BLOCKUPLOAD_SUB_END; SDO_C->CANrxNew = true; } } else if((seqno == SDO_C->block_seqno) || (SDO_C->block_seqno == 0U)){ } else { SDO_C->state = SDO_STATE_BLOCKUPLOAD_SUB_END; SDO_C->CANrxNew = true; } } if(SDO_C->CANrxNew && SDO_C->pFunctSignal != NULL) { SDO_C->pFunctSignal(); } } }
[ "static", "void", "CO_SDOclient_receive", "(", "void", "*", "object", ",", "const", "CO_CANrxMsg_t", "*", "msg", ")", "{", "CO_SDOclient_t", "*", "SDO_C", ";", "SDO_C", "=", "(", "CO_SDOclient_t", "*", ")", "object", ";", "if", "(", "(", "msg", "->", "DLC", "==", "8U", ")", "&&", "(", "!", "SDO_C", "->", "CANrxNew", ")", "&&", "(", "SDO_C", "->", "state", "!=", "SDO_STATE_NOTDEFINED", ")", ")", "{", "if", "(", "SDO_C", "->", "state", "!=", "SDO_STATE_BLOCKUPLOAD_INPROGRES", ")", "{", "SDO_C", "->", "CANrxData", "[", "0", "]", "=", "msg", "->", "data", "[", "0", "]", ";", "SDO_C", "->", "CANrxData", "[", "1", "]", "=", "msg", "->", "data", "[", "1", "]", ";", "SDO_C", "->", "CANrxData", "[", "2", "]", "=", "msg", "->", "data", "[", "2", "]", ";", "SDO_C", "->", "CANrxData", "[", "3", "]", "=", "msg", "->", "data", "[", "3", "]", ";", "SDO_C", "->", "CANrxData", "[", "4", "]", "=", "msg", "->", "data", "[", "4", "]", ";", "SDO_C", "->", "CANrxData", "[", "5", "]", "=", "msg", "->", "data", "[", "5", "]", ";", "SDO_C", "->", "CANrxData", "[", "6", "]", "=", "msg", "->", "data", "[", "6", "]", ";", "SDO_C", "->", "CANrxData", "[", "7", "]", "=", "msg", "->", "data", "[", "7", "]", ";", "SDO_C", "->", "CANrxNew", "=", "true", ";", "}", "else", "{", "uint8_t", "seqno", ";", "SDO_C", "->", "CANrxData", "[", "0", "]", "=", "msg", "->", "data", "[", "0", "]", ";", "seqno", "=", "SDO_C", "->", "CANrxData", "[", "0", "]", "&", "0x7f", ";", "SDO_C", "->", "timeoutTimer", "=", "0", ";", "SDO_C", "->", "timeoutTimerBLOCK", "=", "0", ";", "if", "(", "seqno", "==", "(", "SDO_C", "->", "block_seqno", "+", "1", ")", ")", "{", "uint8_t", "i", ";", "SDO_C", "->", "block_seqno", "++", ";", "for", "(", "i", "=", "1", ";", "i", "<", "8", ";", "i", "++", ")", "{", "SDO_C", "->", "buffer", "[", "SDO_C", "->", "dataSizeTransfered", "++", "]", "=", "msg", "->", "data", "[", "i", "]", ";", "if", "(", "SDO_C", "->", "dataSizeTransfered", ">=", "SDO_C", "->", "bufferSize", ")", "{", "SDO_C", "->", "state", "=", "SDO_STATE_BLOCKUPLOAD_SUB_END", ";", "SDO_C", "->", "CANrxNew", "=", "true", ";", "break", ";", "}", "}", "if", "(", "(", "(", "SDO_C", "->", "CANrxData", "[", "0", "]", "&", "0x80U", ")", "==", "0x80U", ")", "||", "(", "SDO_C", "->", "block_seqno", ">=", "SDO_C", "->", "block_blksize", ")", ")", "{", "SDO_C", "->", "state", "=", "SDO_STATE_BLOCKUPLOAD_SUB_END", ";", "SDO_C", "->", "CANrxNew", "=", "true", ";", "}", "}", "else", "if", "(", "(", "seqno", "==", "SDO_C", "->", "block_seqno", ")", "||", "(", "SDO_C", "->", "block_seqno", "==", "0U", ")", ")", "{", "}", "else", "{", "SDO_C", "->", "state", "=", "SDO_STATE_BLOCKUPLOAD_SUB_END", ";", "SDO_C", "->", "CANrxNew", "=", "true", ";", "}", "}", "if", "(", "SDO_C", "->", "CANrxNew", "&&", "SDO_C", "->", "pFunctSignal", "!=", "NULL", ")", "{", "SDO_C", "->", "pFunctSignal", "(", ")", ";", "}", "}", "}" ]
Read received message from CAN module.
[ "Read", "received", "message", "from", "CAN", "module", "." ]
[ "/* this is the correct pointer type of the first argument */", "/* verify message length and message overflow (previous message was not processed yet) */", "/* copy data and set 'new message' flag */", "/* block upload, copy data directly */", "/* check correct sequence number. */", "/* block_seqno is correct */", "/* copy data */", "/* buffer full, break reception */", "/* break reception if last segment or block sequence is too large */", "/* Ignore message, if it is duplicate or if sequence didn't started yet. */", "/* seqno is totally wrong, break reception. */", "/* Optional signal to RTOS, which can resume task, which handles SDO client. */" ]
[ { "param": "object", "type": "void" }, { "param": "msg", "type": "CO_CANrxMsg_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "object", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "CO_CANrxMsg_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
de2c783701f1dda400f895c9f5f803eeb4480d35
acronis/pcs-io
libpcs_io/minheap.c
[ "MIT" ]
C
mh_swap
void
static void mh_swap(struct mh_root *h, struct mh_node * __restrict x, struct mh_node * __restrict y) { struct mh_node *px = x->parent, *py = y->parent; struct mh_node **xlink = mh_link(h, x), **ylink = mh_link(h, y); struct mh_node *xl = x->left, *xr = x->right; struct mh_node *yl = y->left, *yr = y->right; if (x->left == y) { mh_set_child(x, &x->left, yl); mh_set_child(x, &x->right, yr); mh_set_child(y, &y->left, x); mh_set_child(y, &y->right, xr); x->parent = y; y->parent = px; *xlink = y; } else if (x->right == y) { mh_set_child(x, &x->left, yl); mh_set_child(x, &x->right, yr); mh_set_child(y, &y->left, xl); mh_set_child(y, &y->right, x); x->parent = y; y->parent = px; *xlink = y; } else if (px == py) { struct mh_node *t = px->left; px->left = px->right; px->right = t; } else { mh_set_child(x, &x->left, yl); mh_set_child(x, &x->right, yr); mh_set_child(y, &y->left, xl); mh_set_child(y, &y->right, xr); x->parent = py; y->parent = px; *xlink = y; *ylink = x; } struct cd_list t; cd_list_add(&t, &x->siblings); cd_list_move_tail(&x->siblings, &y->siblings); cd_list_move_tail(&y->siblings, &t); cd_list_del(&t); if (unlikely(h->bottom_right == x)) h->bottom_right = y; else if (unlikely(h->bottom_right == y)) h->bottom_right = x; }
/* Swap entries @x and @y of a minheap @h. If these two nodes are a child and a parent, then @x must point to the parent. */
Swap entries @x and @y of a minheap @h. If these two nodes are a child and a parent, then @x must point to the parent.
[ "Swap", "entries", "@x", "and", "@y", "of", "a", "minheap", "@h", ".", "If", "these", "two", "nodes", "are", "a", "child", "and", "a", "parent", "then", "@x", "must", "point", "to", "the", "parent", "." ]
static void mh_swap(struct mh_root *h, struct mh_node * __restrict x, struct mh_node * __restrict y) { struct mh_node *px = x->parent, *py = y->parent; struct mh_node **xlink = mh_link(h, x), **ylink = mh_link(h, y); struct mh_node *xl = x->left, *xr = x->right; struct mh_node *yl = y->left, *yr = y->right; if (x->left == y) { mh_set_child(x, &x->left, yl); mh_set_child(x, &x->right, yr); mh_set_child(y, &y->left, x); mh_set_child(y, &y->right, xr); x->parent = y; y->parent = px; *xlink = y; } else if (x->right == y) { mh_set_child(x, &x->left, yl); mh_set_child(x, &x->right, yr); mh_set_child(y, &y->left, xl); mh_set_child(y, &y->right, x); x->parent = y; y->parent = px; *xlink = y; } else if (px == py) { struct mh_node *t = px->left; px->left = px->right; px->right = t; } else { mh_set_child(x, &x->left, yl); mh_set_child(x, &x->right, yr); mh_set_child(y, &y->left, xl); mh_set_child(y, &y->right, xr); x->parent = py; y->parent = px; *xlink = y; *ylink = x; } struct cd_list t; cd_list_add(&t, &x->siblings); cd_list_move_tail(&x->siblings, &y->siblings); cd_list_move_tail(&y->siblings, &t); cd_list_del(&t); if (unlikely(h->bottom_right == x)) h->bottom_right = y; else if (unlikely(h->bottom_right == y)) h->bottom_right = x; }
[ "static", "void", "mh_swap", "(", "struct", "mh_root", "*", "h", ",", "struct", "mh_node", "*", "__restrict", "x", ",", "struct", "mh_node", "*", "__restrict", "y", ")", "{", "struct", "mh_node", "*", "px", "=", "x", "->", "parent", ",", "*", "py", "=", "y", "->", "parent", ";", "struct", "mh_node", "*", "*", "xlink", "=", "mh_link", "(", "h", ",", "x", ")", ",", "*", "*", "ylink", "=", "mh_link", "(", "h", ",", "y", ")", ";", "struct", "mh_node", "*", "xl", "=", "x", "->", "left", ",", "*", "xr", "=", "x", "->", "right", ";", "struct", "mh_node", "*", "yl", "=", "y", "->", "left", ",", "*", "yr", "=", "y", "->", "right", ";", "if", "(", "x", "->", "left", "==", "y", ")", "{", "mh_set_child", "(", "x", ",", "&", "x", "->", "left", ",", "yl", ")", ";", "mh_set_child", "(", "x", ",", "&", "x", "->", "right", ",", "yr", ")", ";", "mh_set_child", "(", "y", ",", "&", "y", "->", "left", ",", "x", ")", ";", "mh_set_child", "(", "y", ",", "&", "y", "->", "right", ",", "xr", ")", ";", "x", "->", "parent", "=", "y", ";", "y", "->", "parent", "=", "px", ";", "*", "xlink", "=", "y", ";", "}", "else", "if", "(", "x", "->", "right", "==", "y", ")", "{", "mh_set_child", "(", "x", ",", "&", "x", "->", "left", ",", "yl", ")", ";", "mh_set_child", "(", "x", ",", "&", "x", "->", "right", ",", "yr", ")", ";", "mh_set_child", "(", "y", ",", "&", "y", "->", "left", ",", "xl", ")", ";", "mh_set_child", "(", "y", ",", "&", "y", "->", "right", ",", "x", ")", ";", "x", "->", "parent", "=", "y", ";", "y", "->", "parent", "=", "px", ";", "*", "xlink", "=", "y", ";", "}", "else", "if", "(", "px", "==", "py", ")", "{", "struct", "mh_node", "*", "t", "=", "px", "->", "left", ";", "px", "->", "left", "=", "px", "->", "right", ";", "px", "->", "right", "=", "t", ";", "}", "else", "{", "mh_set_child", "(", "x", ",", "&", "x", "->", "left", ",", "yl", ")", ";", "mh_set_child", "(", "x", ",", "&", "x", "->", "right", ",", "yr", ")", ";", "mh_set_child", "(", "y", ",", "&", "y", "->", "left", ",", "xl", ")", ";", "mh_set_child", "(", "y", ",", "&", "y", "->", "right", ",", "xr", ")", ";", "x", "->", "parent", "=", "py", ";", "y", "->", "parent", "=", "px", ";", "*", "xlink", "=", "y", ";", "*", "ylink", "=", "x", ";", "}", "struct", "cd_list", "t", ";", "cd_list_add", "(", "&", "t", ",", "&", "x", "->", "siblings", ")", ";", "cd_list_move_tail", "(", "&", "x", "->", "siblings", ",", "&", "y", "->", "siblings", ")", ";", "cd_list_move_tail", "(", "&", "y", "->", "siblings", ",", "&", "t", ")", ";", "cd_list_del", "(", "&", "t", ")", ";", "if", "(", "unlikely", "(", "h", "->", "bottom_right", "==", "x", ")", ")", "h", "->", "bottom_right", "=", "y", ";", "else", "if", "(", "unlikely", "(", "h", "->", "bottom_right", "==", "y", ")", ")", "h", "->", "bottom_right", "=", "x", ";", "}" ]
Swap entries @x and @y of a minheap @h. If these two nodes are a child and a parent, then @x must point to the parent.
[ "Swap", "entries", "@x", "and", "@y", "of", "a", "minheap", "@h", ".", "If", "these", "two", "nodes", "are", "a", "child", "and", "a", "parent", "then", "@x", "must", "point", "to", "the", "parent", "." ]
[]
[ { "param": "h", "type": "struct mh_root" }, { "param": "x", "type": "struct mh_node" }, { "param": "y", "type": "struct mh_node" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "h", "type": "struct mh_root", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x", "type": "struct mh_node", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "y", "type": "struct mh_node", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6fc4ea5979bc1a773db9387ac88aea9b004cca18
acronis/pcs-io
libpcs_io/pcs_co_io.c
[ "MIT" ]
C
__pcs_co_file_get_from_pool
null
static struct pcs_co_file *__pcs_co_file_get_from_pool(void) { struct pcs_process *proc = pcs_current_proc; struct pcs_co_file *file = pcs_atomic_ptr_load(&proc->co_file_pool); for (;;) { if (!file) { file = pcs_xzmalloc(sizeof(*file)); #ifdef __SUN__ pthread_mutex_init(&file->mutex, NULL); #endif break; } void *next = pcs_atomic_ptr_load(&file->next); void *res = pcs_atomic_ptr_cas(&proc->co_file_pool, file, next); if (res == file) break; file = res; } return file; }
/* When epoll is running in multiple threads, it is possible that file is closed * before already recieved event for the file was processed in another thread. * We want to handle this race without added synchronization overhead. * We solve the problem by never freeing struct pcs_co_file. * In the worst case we can get spurious wakeup of the coroutine performing I/O * on the reused struct pcs_co_file, which is handled properly. */
When epoll is running in multiple threads, it is possible that file is closed before already recieved event for the file was processed in another thread. We want to handle this race without added synchronization overhead. We solve the problem by never freeing struct pcs_co_file. In the worst case we can get spurious wakeup of the coroutine performing I/O on the reused struct pcs_co_file, which is handled properly.
[ "When", "epoll", "is", "running", "in", "multiple", "threads", "it", "is", "possible", "that", "file", "is", "closed", "before", "already", "recieved", "event", "for", "the", "file", "was", "processed", "in", "another", "thread", ".", "We", "want", "to", "handle", "this", "race", "without", "added", "synchronization", "overhead", ".", "We", "solve", "the", "problem", "by", "never", "freeing", "struct", "pcs_co_file", ".", "In", "the", "worst", "case", "we", "can", "get", "spurious", "wakeup", "of", "the", "coroutine", "performing", "I", "/", "O", "on", "the", "reused", "struct", "pcs_co_file", "which", "is", "handled", "properly", "." ]
static struct pcs_co_file *__pcs_co_file_get_from_pool(void) { struct pcs_process *proc = pcs_current_proc; struct pcs_co_file *file = pcs_atomic_ptr_load(&proc->co_file_pool); for (;;) { if (!file) { file = pcs_xzmalloc(sizeof(*file)); #ifdef __SUN__ pthread_mutex_init(&file->mutex, NULL); #endif break; } void *next = pcs_atomic_ptr_load(&file->next); void *res = pcs_atomic_ptr_cas(&proc->co_file_pool, file, next); if (res == file) break; file = res; } return file; }
[ "static", "struct", "pcs_co_file", "*", "__pcs_co_file_get_from_pool", "(", "void", ")", "{", "struct", "pcs_process", "*", "proc", "=", "pcs_current_proc", ";", "struct", "pcs_co_file", "*", "file", "=", "pcs_atomic_ptr_load", "(", "&", "proc", "->", "co_file_pool", ")", ";", "for", "(", ";", ";", ")", "{", "if", "(", "!", "file", ")", "{", "file", "=", "pcs_xzmalloc", "(", "sizeof", "(", "*", "file", ")", ")", ";", "#ifdef", "__SUN__", "pthread_mutex_init", "(", "&", "file", "->", "mutex", ",", "NULL", ")", ";", "#endif", "break", ";", "}", "void", "*", "next", "=", "pcs_atomic_ptr_load", "(", "&", "file", "->", "next", ")", ";", "void", "*", "res", "=", "pcs_atomic_ptr_cas", "(", "&", "proc", "->", "co_file_pool", ",", "file", ",", "next", ")", ";", "if", "(", "res", "==", "file", ")", "break", ";", "file", "=", "res", ";", "}", "return", "file", ";", "}" ]
When epoll is running in multiple threads, it is possible that file is closed before already recieved event for the file was processed in another thread.
[ "When", "epoll", "is", "running", "in", "multiple", "threads", "it", "is", "possible", "that", "file", "is", "closed", "before", "already", "recieved", "event", "for", "the", "file", "was", "processed", "in", "another", "thread", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
6fc4ea5979bc1a773db9387ac88aea9b004cca18
acronis/pcs-io
libpcs_io/pcs_co_io.c
[ "MIT" ]
C
pcs_co_io_wait_cancelable
int
int pcs_co_io_wait_cancelable(int *timeout_p) { struct pcs_coroutine *co = pcs_current_co; int err; if ((err = pcs_cancelable_prepare_wait(&co->io_wait, co->ctx))) return err; if ((err = pcs_co_event_wait_timeout(&co->io_wait.ev, timeout_p))) return err; return pcs_context_is_canceled(co->ctx); }
/* TODO: kill timeout_p argument also... everything to be done via context... */
kill timeout_p argument also... everything to be done via context
[ "kill", "timeout_p", "argument", "also", "...", "everything", "to", "be", "done", "via", "context" ]
int pcs_co_io_wait_cancelable(int *timeout_p) { struct pcs_coroutine *co = pcs_current_co; int err; if ((err = pcs_cancelable_prepare_wait(&co->io_wait, co->ctx))) return err; if ((err = pcs_co_event_wait_timeout(&co->io_wait.ev, timeout_p))) return err; return pcs_context_is_canceled(co->ctx); }
[ "int", "pcs_co_io_wait_cancelable", "(", "int", "*", "timeout_p", ")", "{", "struct", "pcs_coroutine", "*", "co", "=", "pcs_current_co", ";", "int", "err", ";", "if", "(", "(", "err", "=", "pcs_cancelable_prepare_wait", "(", "&", "co", "->", "io_wait", ",", "co", "->", "ctx", ")", ")", ")", "return", "err", ";", "if", "(", "(", "err", "=", "pcs_co_event_wait_timeout", "(", "&", "co", "->", "io_wait", ".", "ev", ",", "timeout_p", ")", ")", ")", "return", "err", ";", "return", "pcs_context_is_canceled", "(", "co", "->", "ctx", ")", ";", "}" ]
TODO: kill timeout_p argument also... everything to be done via context...
[ "TODO", ":", "kill", "timeout_p", "argument", "also", "...", "everything", "to", "be", "done", "via", "context", "..." ]
[]
[ { "param": "timeout_p", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "timeout_p", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d25c6e204141cb7fee4101db07b36ae5373a9fd1
acronis/pcs-io
libpcs_io/bug.c
[ "MIT" ]
C
pcs_bug_at
void
void pcs_bug_at(struct bug_point* bp) { if (!bp->active) { struct bugon_exception* x; bp->active = 1; for (x = bugon_except_list; x; x = x->next) { if (x->line == bp->line && !strcmp(x->file, bp->file)) { bp->active = -1; break; } } } ++bp->hits; if (bp->active < 0) { pcs_log(LOG_ERR, "IGNORED BUG at %s:%d/%s() [hit number %llu]", bp->file, bp->line, bp->func, bp->hits); return; } pcs_bug(bp->file, bp->line, bp->func); }
/* Same as above but may be optionally ignored */
Same as above but may be optionally ignored
[ "Same", "as", "above", "but", "may", "be", "optionally", "ignored" ]
void pcs_bug_at(struct bug_point* bp) { if (!bp->active) { struct bugon_exception* x; bp->active = 1; for (x = bugon_except_list; x; x = x->next) { if (x->line == bp->line && !strcmp(x->file, bp->file)) { bp->active = -1; break; } } } ++bp->hits; if (bp->active < 0) { pcs_log(LOG_ERR, "IGNORED BUG at %s:%d/%s() [hit number %llu]", bp->file, bp->line, bp->func, bp->hits); return; } pcs_bug(bp->file, bp->line, bp->func); }
[ "void", "pcs_bug_at", "(", "struct", "bug_point", "*", "bp", ")", "{", "if", "(", "!", "bp", "->", "active", ")", "{", "struct", "bugon_exception", "*", "x", ";", "bp", "->", "active", "=", "1", ";", "for", "(", "x", "=", "bugon_except_list", ";", "x", ";", "x", "=", "x", "->", "next", ")", "{", "if", "(", "x", "->", "line", "==", "bp", "->", "line", "&&", "!", "strcmp", "(", "x", "->", "file", ",", "bp", "->", "file", ")", ")", "{", "bp", "->", "active", "=", "-1", ";", "break", ";", "}", "}", "}", "++", "bp", "->", "hits", ";", "if", "(", "bp", "->", "active", "<", "0", ")", "{", "pcs_log", "(", "LOG_ERR", ",", "\"", "\"", ",", "bp", "->", "file", ",", "bp", "->", "line", ",", "bp", "->", "func", ",", "bp", "->", "hits", ")", ";", "return", ";", "}", "pcs_bug", "(", "bp", "->", "file", ",", "bp", "->", "line", ",", "bp", "->", "func", ")", ";", "}" ]
Same as above but may be optionally ignored
[ "Same", "as", "above", "but", "may", "be", "optionally", "ignored" ]
[]
[ { "param": "bp", "type": "struct bug_point" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bp", "type": "struct bug_point", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d25c6e204141cb7fee4101db07b36ae5373a9fd1
acronis/pcs-io
libpcs_io/bug.c
[ "MIT" ]
C
pcs_bug_ignore
int
int pcs_bug_ignore(const char *file, int line) { struct bugon_exception* x = pcs_malloc(sizeof(*x)); if (!x) return PCS_ERR_NOMEM; if (!(x->file = pcs_strdup(file))) { pcs_free(x); return PCS_ERR_NOMEM; } x->line = line; x->next = bugon_except_list; bugon_except_list = x; return 0; }
/* Add bugon exception. Expected to be called at the application initialization stage only. * May return PCS_ERR_NOMEM on allocation failure. */
Add bugon exception. Expected to be called at the application initialization stage only. May return PCS_ERR_NOMEM on allocation failure.
[ "Add", "bugon", "exception", ".", "Expected", "to", "be", "called", "at", "the", "application", "initialization", "stage", "only", ".", "May", "return", "PCS_ERR_NOMEM", "on", "allocation", "failure", "." ]
int pcs_bug_ignore(const char *file, int line) { struct bugon_exception* x = pcs_malloc(sizeof(*x)); if (!x) return PCS_ERR_NOMEM; if (!(x->file = pcs_strdup(file))) { pcs_free(x); return PCS_ERR_NOMEM; } x->line = line; x->next = bugon_except_list; bugon_except_list = x; return 0; }
[ "int", "pcs_bug_ignore", "(", "const", "char", "*", "file", ",", "int", "line", ")", "{", "struct", "bugon_exception", "*", "x", "=", "pcs_malloc", "(", "sizeof", "(", "*", "x", ")", ")", ";", "if", "(", "!", "x", ")", "return", "PCS_ERR_NOMEM", ";", "if", "(", "!", "(", "x", "->", "file", "=", "pcs_strdup", "(", "file", ")", ")", ")", "{", "pcs_free", "(", "x", ")", ";", "return", "PCS_ERR_NOMEM", ";", "}", "x", "->", "line", "=", "line", ";", "x", "->", "next", "=", "bugon_except_list", ";", "bugon_except_list", "=", "x", ";", "return", "0", ";", "}" ]
Add bugon exception.
[ "Add", "bugon", "exception", "." ]
[]
[ { "param": "file", "type": "char" }, { "param": "line", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "line", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d25c6e204141cb7fee4101db07b36ae5373a9fd1
acronis/pcs-io
libpcs_io/bug.c
[ "MIT" ]
C
pcs_bug_ignore_spec
int
int pcs_bug_ignore_spec(const char *spec) { int res = 0; char *spec_copy, *sep, *eptr = 0; long line; if (!(spec_copy = pcs_strdup(spec))) { return PCS_ERR_NOMEM; } if (!(sep = strchr(spec_copy, ':'))) { res = PCS_ERR_INV_PARAMS; goto cleanup; } *sep++ = 0; line = strtol(sep, &eptr, 10); if (!*sep || *eptr || line <= 0) { res = PCS_ERR_INV_PARAMS; goto cleanup; } res = pcs_bug_ignore(spec_copy, line); cleanup: pcs_free(spec_copy); return res; }
/* Accept file:line specification. May return PCS_ERR_NOMEM or PCS_ERR_INV_PARAMS errors. */
Accept file:line specification.
[ "Accept", "file", ":", "line", "specification", "." ]
int pcs_bug_ignore_spec(const char *spec) { int res = 0; char *spec_copy, *sep, *eptr = 0; long line; if (!(spec_copy = pcs_strdup(spec))) { return PCS_ERR_NOMEM; } if (!(sep = strchr(spec_copy, ':'))) { res = PCS_ERR_INV_PARAMS; goto cleanup; } *sep++ = 0; line = strtol(sep, &eptr, 10); if (!*sep || *eptr || line <= 0) { res = PCS_ERR_INV_PARAMS; goto cleanup; } res = pcs_bug_ignore(spec_copy, line); cleanup: pcs_free(spec_copy); return res; }
[ "int", "pcs_bug_ignore_spec", "(", "const", "char", "*", "spec", ")", "{", "int", "res", "=", "0", ";", "char", "*", "spec_copy", ",", "*", "sep", ",", "*", "eptr", "=", "0", ";", "long", "line", ";", "if", "(", "!", "(", "spec_copy", "=", "pcs_strdup", "(", "spec", ")", ")", ")", "{", "return", "PCS_ERR_NOMEM", ";", "}", "if", "(", "!", "(", "sep", "=", "strchr", "(", "spec_copy", ",", "'", "'", ")", ")", ")", "{", "res", "=", "PCS_ERR_INV_PARAMS", ";", "goto", "cleanup", ";", "}", "*", "sep", "++", "=", "0", ";", "line", "=", "strtol", "(", "sep", ",", "&", "eptr", ",", "10", ")", ";", "if", "(", "!", "*", "sep", "||", "*", "eptr", "||", "line", "<=", "0", ")", "{", "res", "=", "PCS_ERR_INV_PARAMS", ";", "goto", "cleanup", ";", "}", "res", "=", "pcs_bug_ignore", "(", "spec_copy", ",", "line", ")", ";", "cleanup", ":", "pcs_free", "(", "spec_copy", ")", ";", "return", "res", ";", "}" ]
Accept file:line specification.
[ "Accept", "file", ":", "line", "specification", "." ]
[]
[ { "param": "spec", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "spec", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d25c6e204141cb7fee4101db07b36ae5373a9fd1
acronis/pcs-io
libpcs_io/bug.c
[ "MIT" ]
C
pcs_dbg_bugon_init
void
void pcs_dbg_bugon_init(void) { if (getenv("PSTORAGE_DBG_BUGON")) pcs_dbg_bugon_enable = 1; }
/* Read PSTORAGE_DBG_BUGON environment variable and set pcs_dbg_bugon_enable accordingly */
Read PSTORAGE_DBG_BUGON environment variable and set pcs_dbg_bugon_enable accordingly
[ "Read", "PSTORAGE_DBG_BUGON", "environment", "variable", "and", "set", "pcs_dbg_bugon_enable", "accordingly" ]
void pcs_dbg_bugon_init(void) { if (getenv("PSTORAGE_DBG_BUGON")) pcs_dbg_bugon_enable = 1; }
[ "void", "pcs_dbg_bugon_init", "(", "void", ")", "{", "if", "(", "getenv", "(", "\"", "\"", ")", ")", "pcs_dbg_bugon_enable", "=", "1", ";", "}" ]
Read PSTORAGE_DBG_BUGON environment variable and set pcs_dbg_bugon_enable accordingly
[ "Read", "PSTORAGE_DBG_BUGON", "environment", "variable", "and", "set", "pcs_dbg_bugon_enable", "accordingly" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
6bb832a02359cf625d98188339601e2ea0c03898
acronis/pcs-io
libpcs_io/pcs_sync_io.c
[ "MIT" ]
C
pcs_sync_nwrite
int
int pcs_sync_nwrite(pcs_fd_t fd, u64 offs, void const *buf, int sz) { int w = 0; pcs_might_block(); while (sz) { int n = pwrite(fd, buf, sz, offs); if (n < 0) { if (errno == EINTR) continue; return -errno; } BUG_ON(n == 0); buf += n; offs += n; w += n; sz -= n; } return w; }
/* returns number of bytes written or -errno */
returns number of bytes written or -errno
[ "returns", "number", "of", "bytes", "written", "or", "-", "errno" ]
int pcs_sync_nwrite(pcs_fd_t fd, u64 offs, void const *buf, int sz) { int w = 0; pcs_might_block(); while (sz) { int n = pwrite(fd, buf, sz, offs); if (n < 0) { if (errno == EINTR) continue; return -errno; } BUG_ON(n == 0); buf += n; offs += n; w += n; sz -= n; } return w; }
[ "int", "pcs_sync_nwrite", "(", "pcs_fd_t", "fd", ",", "u64", "offs", ",", "void", "const", "*", "buf", ",", "int", "sz", ")", "{", "int", "w", "=", "0", ";", "pcs_might_block", "(", ")", ";", "while", "(", "sz", ")", "{", "int", "n", "=", "pwrite", "(", "fd", ",", "buf", ",", "sz", ",", "offs", ")", ";", "if", "(", "n", "<", "0", ")", "{", "if", "(", "errno", "==", "EINTR", ")", "continue", ";", "return", "-", "errno", ";", "}", "BUG_ON", "(", "n", "==", "0", ")", ";", "buf", "+=", "n", ";", "offs", "+=", "n", ";", "w", "+=", "n", ";", "sz", "-=", "n", ";", "}", "return", "w", ";", "}" ]
returns number of bytes written or -errno
[ "returns", "number", "of", "bytes", "written", "or", "-", "errno" ]
[]
[ { "param": "fd", "type": "pcs_fd_t" }, { "param": "offs", "type": "u64" }, { "param": "buf", "type": "void" }, { "param": "sz", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fd", "type": "pcs_fd_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "offs", "type": "u64", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sz", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bb832a02359cf625d98188339601e2ea0c03898
acronis/pcs-io
libpcs_io/pcs_sync_io.c
[ "MIT" ]
C
pcs_sync_swrite
int
int pcs_sync_swrite(pcs_fd_t fd, void const *buf, int sz) { int w = sz; pcs_might_block(); while (w) { int n = write(fd, buf, w); if (n < 0) { if (errno == EINTR) continue; return -errno; } BUG_ON(n == 0); buf = (const char*)buf + n; w -= n; } return sz; }
/* returns 0 if ok or -errno if error */
returns 0 if ok or -errno if error
[ "returns", "0", "if", "ok", "or", "-", "errno", "if", "error" ]
int pcs_sync_swrite(pcs_fd_t fd, void const *buf, int sz) { int w = sz; pcs_might_block(); while (w) { int n = write(fd, buf, w); if (n < 0) { if (errno == EINTR) continue; return -errno; } BUG_ON(n == 0); buf = (const char*)buf + n; w -= n; } return sz; }
[ "int", "pcs_sync_swrite", "(", "pcs_fd_t", "fd", ",", "void", "const", "*", "buf", ",", "int", "sz", ")", "{", "int", "w", "=", "sz", ";", "pcs_might_block", "(", ")", ";", "while", "(", "w", ")", "{", "int", "n", "=", "write", "(", "fd", ",", "buf", ",", "w", ")", ";", "if", "(", "n", "<", "0", ")", "{", "if", "(", "errno", "==", "EINTR", ")", "continue", ";", "return", "-", "errno", ";", "}", "BUG_ON", "(", "n", "==", "0", ")", ";", "buf", "=", "(", "const", "char", "*", ")", "buf", "+", "n", ";", "w", "-=", "n", ";", "}", "return", "sz", ";", "}" ]
returns 0 if ok or -errno if error
[ "returns", "0", "if", "ok", "or", "-", "errno", "if", "error" ]
[]
[ { "param": "fd", "type": "pcs_fd_t" }, { "param": "buf", "type": "void" }, { "param": "sz", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fd", "type": "pcs_fd_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sz", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bb832a02359cf625d98188339601e2ea0c03898
acronis/pcs-io
libpcs_io/pcs_sync_io.c
[ "MIT" ]
C
pcs_sync_openat
int
int pcs_sync_openat(pcs_fd_t dirfd, const char *filename, int flags, int mode, pcs_fd_t * out_fd) { BUG_ON(dirfd < 0); /* Do not allow special values PCS_INVALID_FD or AT_FDCWD, use pcs_sync_open() instead */ BUG_ON(!strcmp(filename, "..")); /* Disallow "..", but allow "." */ flags |= O_NOFOLLOW; /* If we use openat() we don't want follow symlinks */ pcs_might_block(); pcs_fd_t fd = -1; while (1) { fd = openat(dirfd, filename, flags | O_CLOEXEC, mode); if (fd >= 0) break; if (errno != EINTR) return -errno; } if (fd >= 0) { *out_fd = fd; return 0; } int rc = -errno; #ifdef USE_OPENAT_EMULATION if (rc != -ENOSYS) return rc; char *path = pcs_pathat(dirfd, filename); rc = pcs_sync_open(path, flags, mode, out_fd); pcs_free(path); #endif /* USE_OPENAT_EMULATION */ return rc; }
/* We use openat() for security reasons to prevent a user to open a file or directory outside the parent directory. * Thus we require @dirfd to be a valid directory descriptor, not special values like AT_FDCWD. * We disallow multicomponent path as filename to prevent symlink attack, also we disable ".." to disallow jumping out from the parent directory. */
We use openat() for security reasons to prevent a user to open a file or directory outside the parent directory. Thus we require @dirfd to be a valid directory descriptor, not special values like AT_FDCWD. We disallow multicomponent path as filename to prevent symlink attack, also we disable ".." to disallow jumping out from the parent directory.
[ "We", "use", "openat", "()", "for", "security", "reasons", "to", "prevent", "a", "user", "to", "open", "a", "file", "or", "directory", "outside", "the", "parent", "directory", ".", "Thus", "we", "require", "@dirfd", "to", "be", "a", "valid", "directory", "descriptor", "not", "special", "values", "like", "AT_FDCWD", ".", "We", "disallow", "multicomponent", "path", "as", "filename", "to", "prevent", "symlink", "attack", "also", "we", "disable", "\"", "..", "\"", "to", "disallow", "jumping", "out", "from", "the", "parent", "directory", "." ]
int pcs_sync_openat(pcs_fd_t dirfd, const char *filename, int flags, int mode, pcs_fd_t * out_fd) { BUG_ON(dirfd < 0); BUG_ON(!strcmp(filename, "..")); flags |= O_NOFOLLOW; pcs_might_block(); pcs_fd_t fd = -1; while (1) { fd = openat(dirfd, filename, flags | O_CLOEXEC, mode); if (fd >= 0) break; if (errno != EINTR) return -errno; } if (fd >= 0) { *out_fd = fd; return 0; } int rc = -errno; #ifdef USE_OPENAT_EMULATION if (rc != -ENOSYS) return rc; char *path = pcs_pathat(dirfd, filename); rc = pcs_sync_open(path, flags, mode, out_fd); pcs_free(path); #endif return rc; }
[ "int", "pcs_sync_openat", "(", "pcs_fd_t", "dirfd", ",", "const", "char", "*", "filename", ",", "int", "flags", ",", "int", "mode", ",", "pcs_fd_t", "*", "out_fd", ")", "{", "BUG_ON", "(", "dirfd", "<", "0", ")", ";", "BUG_ON", "(", "!", "strcmp", "(", "filename", ",", "\"", "\"", ")", ")", ";", "flags", "|=", "O_NOFOLLOW", ";", "pcs_might_block", "(", ")", ";", "pcs_fd_t", "fd", "=", "-1", ";", "while", "(", "1", ")", "{", "fd", "=", "openat", "(", "dirfd", ",", "filename", ",", "flags", "|", "O_CLOEXEC", ",", "mode", ")", ";", "if", "(", "fd", ">=", "0", ")", "break", ";", "if", "(", "errno", "!=", "EINTR", ")", "return", "-", "errno", ";", "}", "if", "(", "fd", ">=", "0", ")", "{", "*", "out_fd", "=", "fd", ";", "return", "0", ";", "}", "int", "rc", "=", "-", "errno", ";", "#ifdef", "USE_OPENAT_EMULATION", "if", "(", "rc", "!=", "-", "ENOSYS", ")", "return", "rc", ";", "char", "*", "path", "=", "pcs_pathat", "(", "dirfd", ",", "filename", ")", ";", "rc", "=", "pcs_sync_open", "(", "path", ",", "flags", ",", "mode", ",", "out_fd", ")", ";", "pcs_free", "(", "path", ")", ";", "#endif", "return", "rc", ";", "}" ]
We use openat() for security reasons to prevent a user to open a file or directory outside the parent directory.
[ "We", "use", "openat", "()", "for", "security", "reasons", "to", "prevent", "a", "user", "to", "open", "a", "file", "or", "directory", "outside", "the", "parent", "directory", "." ]
[ "/* Do not allow special values PCS_INVALID_FD or AT_FDCWD, use pcs_sync_open() instead */", "/* Disallow \"..\", but allow \".\" */", "/* If we use openat() we don't want follow symlinks */", "/* USE_OPENAT_EMULATION */" ]
[ { "param": "dirfd", "type": "pcs_fd_t" }, { "param": "filename", "type": "char" }, { "param": "flags", "type": "int" }, { "param": "mode", "type": "int" }, { "param": "out_fd", "type": "pcs_fd_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dirfd", "type": "pcs_fd_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "filename", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "flags", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mode", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "out_fd", "type": "pcs_fd_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7339c2933c642187241bbaac49a943ec467db930
acronis/pcs-io
libpcs_io/pcs_process.c
[ "MIT" ]
C
pcs_call_in_job
void
void pcs_call_in_job(struct pcs_process* proc, void (*fn)(void*), void* arg) { struct async_job* j = pcs_xmalloc(sizeof(*j)); j->fn1 = fn; j->arg1 = arg; pcs_job_init(proc, &j->job, async_worker1, j); pcs_job_wakeup(&j->job); }
/* Execute function in the context of the event loop. Creates pcs_job internally. */
Execute function in the context of the event loop.
[ "Execute", "function", "in", "the", "context", "of", "the", "event", "loop", "." ]
void pcs_call_in_job(struct pcs_process* proc, void (*fn)(void*), void* arg) { struct async_job* j = pcs_xmalloc(sizeof(*j)); j->fn1 = fn; j->arg1 = arg; pcs_job_init(proc, &j->job, async_worker1, j); pcs_job_wakeup(&j->job); }
[ "void", "pcs_call_in_job", "(", "struct", "pcs_process", "*", "proc", ",", "void", "(", "*", "fn", ")", "(", "void", "*", ")", ",", "void", "*", "arg", ")", "{", "struct", "async_job", "*", "j", "=", "pcs_xmalloc", "(", "sizeof", "(", "*", "j", ")", ")", ";", "j", "->", "fn1", "=", "fn", ";", "j", "->", "arg1", "=", "arg", ";", "pcs_job_init", "(", "proc", ",", "&", "j", "->", "job", ",", "async_worker1", ",", "j", ")", ";", "pcs_job_wakeup", "(", "&", "j", "->", "job", ")", ";", "}" ]
Execute function in the context of the event loop.
[ "Execute", "function", "in", "the", "context", "of", "the", "event", "loop", "." ]
[]
[ { "param": "proc", "type": "struct pcs_process" }, { "param": "fn", "type": "void" }, { "param": "arg", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "proc", "type": "struct pcs_process", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fn", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a84cd608fab3f9cdfb5807aaf622b98be7134ed1
acronis/pcs-io
libpcs_io/pcs_config_file.c
[ "MIT" ]
C
strstrip
char
static char *strstrip(char *str) { char *end; while ((str[0] != '\0') && isspace(str[0])) str++; end = str + strlen(str); while ((end > str) && isspace(end[-1])) end--; end[0] = '\0'; return str; }
/* strips whitespace from the passed string, returns its substring */
strips whitespace from the passed string, returns its substring
[ "strips", "whitespace", "from", "the", "passed", "string", "returns", "its", "substring" ]
static char *strstrip(char *str) { char *end; while ((str[0] != '\0') && isspace(str[0])) str++; end = str + strlen(str); while ((end > str) && isspace(end[-1])) end--; end[0] = '\0'; return str; }
[ "static", "char", "*", "strstrip", "(", "char", "*", "str", ")", "{", "char", "*", "end", ";", "while", "(", "(", "str", "[", "0", "]", "!=", "'", "\\0", "'", ")", "&&", "isspace", "(", "str", "[", "0", "]", ")", ")", "str", "++", ";", "end", "=", "str", "+", "strlen", "(", "str", ")", ";", "while", "(", "(", "end", ">", "str", ")", "&&", "isspace", "(", "end", "[", "-1", "]", ")", ")", "end", "--", ";", "end", "[", "0", "]", "=", "'", "\\0", "'", ";", "return", "str", ";", "}" ]
strips whitespace from the passed string, returns its substring
[ "strips", "whitespace", "from", "the", "passed", "string", "returns", "its", "substring" ]
[]
[ { "param": "str", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "str", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a84cd608fab3f9cdfb5807aaf622b98be7134ed1
acronis/pcs-io
libpcs_io/pcs_config_file.c
[ "MIT" ]
C
pcs_free_config
void
void pcs_free_config(struct pcs_config *cfg) { if (cfg == NULL) return; rb_destroy(&cfg->root, &pcs_free_config_node); pcs_free(cfg); }
/* Release config and all associated resources */
Release config and all associated resources
[ "Release", "config", "and", "all", "associated", "resources" ]
void pcs_free_config(struct pcs_config *cfg) { if (cfg == NULL) return; rb_destroy(&cfg->root, &pcs_free_config_node); pcs_free(cfg); }
[ "void", "pcs_free_config", "(", "struct", "pcs_config", "*", "cfg", ")", "{", "if", "(", "cfg", "==", "NULL", ")", "return", ";", "rb_destroy", "(", "&", "cfg", "->", "root", ",", "&", "pcs_free_config_node", ")", ";", "pcs_free", "(", "cfg", ")", ";", "}" ]
Release config and all associated resources
[ "Release", "config", "and", "all", "associated", "resources" ]
[]
[ { "param": "cfg", "type": "struct pcs_config" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cfg", "type": "struct pcs_config", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a84cd608fab3f9cdfb5807aaf622b98be7134ed1
acronis/pcs-io
libpcs_io/pcs_config_file.c
[ "MIT" ]
C
pcs_read_config
null
struct pcs_config *pcs_read_config(const char *fname) { FILE *f; int res = -1; struct pcs_config* cfg = pcs_create_config(); if (!cfg) return 0; f = fopen(fname, "rte"); if (f) { res = pcs_parse_config_file(cfg, f); fclose(f); } if (res) { pcs_free_config(cfg); return 0; } else return cfg; }
/* Create config structure and read configuration from the file * Returns config context on success or NULL on failure. */
Create config structure and read configuration from the file Returns config context on success or NULL on failure.
[ "Create", "config", "structure", "and", "read", "configuration", "from", "the", "file", "Returns", "config", "context", "on", "success", "or", "NULL", "on", "failure", "." ]
struct pcs_config *pcs_read_config(const char *fname) { FILE *f; int res = -1; struct pcs_config* cfg = pcs_create_config(); if (!cfg) return 0; f = fopen(fname, "rte"); if (f) { res = pcs_parse_config_file(cfg, f); fclose(f); } if (res) { pcs_free_config(cfg); return 0; } else return cfg; }
[ "struct", "pcs_config", "*", "pcs_read_config", "(", "const", "char", "*", "fname", ")", "{", "FILE", "*", "f", ";", "int", "res", "=", "-1", ";", "struct", "pcs_config", "*", "cfg", "=", "pcs_create_config", "(", ")", ";", "if", "(", "!", "cfg", ")", "return", "0", ";", "f", "=", "fopen", "(", "fname", ",", "\"", "\"", ")", ";", "if", "(", "f", ")", "{", "res", "=", "pcs_parse_config_file", "(", "cfg", ",", "f", ")", ";", "fclose", "(", "f", ")", ";", "}", "if", "(", "res", ")", "{", "pcs_free_config", "(", "cfg", ")", ";", "return", "0", ";", "}", "else", "return", "cfg", ";", "}" ]
Create config structure and read configuration from the file Returns config context on success or NULL on failure.
[ "Create", "config", "structure", "and", "read", "configuration", "from", "the", "file", "Returns", "config", "context", "on", "success", "or", "NULL", "on", "failure", "." ]
[]
[ { "param": "fname", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2f38cac49ba8dabf8ad48565b6a8e72352c40cf1
acronis/pcs-io
libpcs_io/crc32_sse.c
[ "MIT" ]
C
crc32c
uint32_t
uint32_t crc32c(const void *buf, size_t len, uint32_t crc) { const unsigned char *next = buf; const unsigned char *end; uint64_t crc0, crc1, crc2; /* need to be 64 bits for crc32q */ /* populate shift tables the first time through */ pthread_once(&crc32c_once_hw, crc32c_init_hw); /* pre-process the crc */ crc0 = crc ^ 0xffffffff; /* compute the crc for up to seven leading bytes to bring the data pointer to an eight-byte boundary */ while (len && ((uintptr_t)next & 7) != 0) { sse_crc32_u8(crc0, next); next++; len--; } /* compute the crc on sets of LONG*3 bytes, executing three independent crc instructions, each on LONG bytes -- this is optimized for the Nehalem, Westmere, Sandy Bridge, and Ivy Bridge architectures, which have a throughput of one crc per cycle, but a latency of three cycles */ while (len >= LONG*3) { crc1 = 0; crc2 = 0; end = next + LONG; do { sse_crc32_u64(crc0, next); sse_crc32_u64(crc1, next + LONGx1); sse_crc32_u64(crc2, next + LONGx2); next += 8; } while (next < end); crc0 = crc32c_shift(crc32c_long, (uint32_t)crc0) ^ crc1; crc0 = crc32c_shift(crc32c_long, (uint32_t)crc0) ^ crc2; next += LONG*2; len -= LONG*3; } /* do the same thing, but now on SHORT*3 blocks for the remaining data less than a LONG*3 block */ while (len >= SHORT*3) { crc1 = 0; crc2 = 0; end = next + SHORT; do { sse_crc32_u64(crc0, next); sse_crc32_u64(crc1, next + SHORTx1); sse_crc32_u64(crc2, next + SHORTx2); next += 8; } while (next < end); crc0 = crc32c_shift(crc32c_short, (uint32_t)crc0) ^ crc1; crc0 = crc32c_shift(crc32c_short, (uint32_t)crc0) ^ crc2; next += SHORT*2; len -= SHORT*3; } /* compute the crc on the remaining eight-byte units less than a SHORT*3 block */ end = next + (len - (len & 7)); while (next < end) { sse_crc32_u64(crc0, next); next += 8; } len &= 7; /* compute the crc for up to seven trailing bytes */ while (len) { sse_crc32_u8(crc0, next); next++; len--; } /* return a post-processed crc */ return (uint32_t)(crc0 ^ 0xffffffff); }
/* Compute CRC-32C using the Intel hardware instruction. */
Compute CRC-32C using the Intel hardware instruction.
[ "Compute", "CRC", "-", "32C", "using", "the", "Intel", "hardware", "instruction", "." ]
uint32_t crc32c(const void *buf, size_t len, uint32_t crc) { const unsigned char *next = buf; const unsigned char *end; uint64_t crc0, crc1, crc2; pthread_once(&crc32c_once_hw, crc32c_init_hw); crc0 = crc ^ 0xffffffff; while (len && ((uintptr_t)next & 7) != 0) { sse_crc32_u8(crc0, next); next++; len--; } while (len >= LONG*3) { crc1 = 0; crc2 = 0; end = next + LONG; do { sse_crc32_u64(crc0, next); sse_crc32_u64(crc1, next + LONGx1); sse_crc32_u64(crc2, next + LONGx2); next += 8; } while (next < end); crc0 = crc32c_shift(crc32c_long, (uint32_t)crc0) ^ crc1; crc0 = crc32c_shift(crc32c_long, (uint32_t)crc0) ^ crc2; next += LONG*2; len -= LONG*3; } while (len >= SHORT*3) { crc1 = 0; crc2 = 0; end = next + SHORT; do { sse_crc32_u64(crc0, next); sse_crc32_u64(crc1, next + SHORTx1); sse_crc32_u64(crc2, next + SHORTx2); next += 8; } while (next < end); crc0 = crc32c_shift(crc32c_short, (uint32_t)crc0) ^ crc1; crc0 = crc32c_shift(crc32c_short, (uint32_t)crc0) ^ crc2; next += SHORT*2; len -= SHORT*3; } end = next + (len - (len & 7)); while (next < end) { sse_crc32_u64(crc0, next); next += 8; } len &= 7; while (len) { sse_crc32_u8(crc0, next); next++; len--; } return (uint32_t)(crc0 ^ 0xffffffff); }
[ "uint32_t", "crc32c", "(", "const", "void", "*", "buf", ",", "size_t", "len", ",", "uint32_t", "crc", ")", "{", "const", "unsigned", "char", "*", "next", "=", "buf", ";", "const", "unsigned", "char", "*", "end", ";", "uint64_t", "crc0", ",", "crc1", ",", "crc2", ";", "pthread_once", "(", "&", "crc32c_once_hw", ",", "crc32c_init_hw", ")", ";", "crc0", "=", "crc", "^", "0xffffffff", ";", "while", "(", "len", "&&", "(", "(", "uintptr_t", ")", "next", "&", "7", ")", "!=", "0", ")", "{", "sse_crc32_u8", "(", "crc0", ",", "next", ")", ";", "next", "++", ";", "len", "--", ";", "}", "while", "(", "len", ">=", "LONG", "*", "3", ")", "{", "crc1", "=", "0", ";", "crc2", "=", "0", ";", "end", "=", "next", "+", "LONG", ";", "do", "{", "sse_crc32_u64", "(", "crc0", ",", "next", ")", ";", "sse_crc32_u64", "(", "crc1", ",", "next", "+", "LONGx1", ")", ";", "sse_crc32_u64", "(", "crc2", ",", "next", "+", "LONGx2", ")", ";", "next", "+=", "8", ";", "}", "while", "(", "next", "<", "end", ")", ";", "crc0", "=", "crc32c_shift", "(", "crc32c_long", ",", "(", "uint32_t", ")", "crc0", ")", "^", "crc1", ";", "crc0", "=", "crc32c_shift", "(", "crc32c_long", ",", "(", "uint32_t", ")", "crc0", ")", "^", "crc2", ";", "next", "+=", "LONG", "*", "2", ";", "len", "-=", "LONG", "*", "3", ";", "}", "while", "(", "len", ">=", "SHORT", "*", "3", ")", "{", "crc1", "=", "0", ";", "crc2", "=", "0", ";", "end", "=", "next", "+", "SHORT", ";", "do", "{", "sse_crc32_u64", "(", "crc0", ",", "next", ")", ";", "sse_crc32_u64", "(", "crc1", ",", "next", "+", "SHORTx1", ")", ";", "sse_crc32_u64", "(", "crc2", ",", "next", "+", "SHORTx2", ")", ";", "next", "+=", "8", ";", "}", "while", "(", "next", "<", "end", ")", ";", "crc0", "=", "crc32c_shift", "(", "crc32c_short", ",", "(", "uint32_t", ")", "crc0", ")", "^", "crc1", ";", "crc0", "=", "crc32c_shift", "(", "crc32c_short", ",", "(", "uint32_t", ")", "crc0", ")", "^", "crc2", ";", "next", "+=", "SHORT", "*", "2", ";", "len", "-=", "SHORT", "*", "3", ";", "}", "end", "=", "next", "+", "(", "len", "-", "(", "len", "&", "7", ")", ")", ";", "while", "(", "next", "<", "end", ")", "{", "sse_crc32_u64", "(", "crc0", ",", "next", ")", ";", "next", "+=", "8", ";", "}", "len", "&=", "7", ";", "while", "(", "len", ")", "{", "sse_crc32_u8", "(", "crc0", ",", "next", ")", ";", "next", "++", ";", "len", "--", ";", "}", "return", "(", "uint32_t", ")", "(", "crc0", "^", "0xffffffff", ")", ";", "}" ]
Compute CRC-32C using the Intel hardware instruction.
[ "Compute", "CRC", "-", "32C", "using", "the", "Intel", "hardware", "instruction", "." ]
[ "/* need to be 64 bits for crc32q */", "/* populate shift tables the first time through */", "/* pre-process the crc */", "/* compute the crc for up to seven leading bytes to bring the data pointer\n\t to an eight-byte boundary */", "/* compute the crc on sets of LONG*3 bytes, executing three independent crc\n\t instructions, each on LONG bytes -- this is optimized for the Nehalem,\n\t Westmere, Sandy Bridge, and Ivy Bridge architectures, which have a\n\t throughput of one crc per cycle, but a latency of three cycles */", "/* do the same thing, but now on SHORT*3 blocks for the remaining data less\n\t than a LONG*3 block */", "/* compute the crc on the remaining eight-byte units less than a SHORT*3\n\t block */", "/* compute the crc for up to seven trailing bytes */", "/* return a post-processed crc */" ]
[ { "param": "buf", "type": "void" }, { "param": "len", "type": "size_t" }, { "param": "crc", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "crc", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
__log_printf
void
static void __log_printf(void *arg, const char *fmt, ...) { char buf[1024]; va_list va; va_start(va, fmt); int len = vsnprintf(buf, sizeof(buf), fmt, va); va_end(va); if (len < 0) abort(); // don't use BUG_ON - recursion if (len >= sizeof(buf)) len = (int)strlen(buf); if (len && buf[len - 1] == '\n') len--; /* special case when handler set - its duty is to print TS */ if (log_handler) { log_handler(LOG_ERR, buf, len); return; } log_print_buf_locked(LOG_ERR, buf, len); }
/* log_printf should be used under log lock or in extreme cases (crash). unlike printf, it adds \n at the end. */
log_printf should be used under log lock or in extreme cases (crash). unlike printf, it adds \n at the end.
[ "log_printf", "should", "be", "used", "under", "log", "lock", "or", "in", "extreme", "cases", "(", "crash", ")", ".", "unlike", "printf", "it", "adds", "\\", "n", "at", "the", "end", "." ]
static void __log_printf(void *arg, const char *fmt, ...) { char buf[1024]; va_list va; va_start(va, fmt); int len = vsnprintf(buf, sizeof(buf), fmt, va); va_end(va); if (len < 0) abort(); if (len >= sizeof(buf)) len = (int)strlen(buf); if (len && buf[len - 1] == '\n') len--; if (log_handler) { log_handler(LOG_ERR, buf, len); return; } log_print_buf_locked(LOG_ERR, buf, len); }
[ "static", "void", "__log_printf", "(", "void", "*", "arg", ",", "const", "char", "*", "fmt", ",", "...", ")", "{", "char", "buf", "[", "1024", "]", ";", "va_list", "va", ";", "va_start", "(", "va", ",", "fmt", ")", ";", "int", "len", "=", "vsnprintf", "(", "buf", ",", "sizeof", "(", "buf", ")", ",", "fmt", ",", "va", ")", ";", "va_end", "(", "va", ")", ";", "if", "(", "len", "<", "0", ")", "abort", "(", ")", ";", "if", "(", "len", ">=", "sizeof", "(", "buf", ")", ")", "len", "=", "(", "int", ")", "strlen", "(", "buf", ")", ";", "if", "(", "len", "&&", "buf", "[", "len", "-", "1", "]", "==", "'", "\\n", "'", ")", "len", "--", ";", "if", "(", "log_handler", ")", "{", "log_handler", "(", "LOG_ERR", ",", "buf", ",", "len", ")", ";", "return", ";", "}", "log_print_buf_locked", "(", "LOG_ERR", ",", "buf", ",", "len", ")", ";", "}" ]
log_printf should be used under log lock or in extreme cases (crash).
[ "log_printf", "should", "be", "used", "under", "log", "lock", "or", "in", "extreme", "cases", "(", "crash", ")", "." ]
[ "// don't use BUG_ON - recursion", "/* special case when handler set - its duty is to print TS */" ]
[ { "param": "arg", "type": "void" }, { "param": "fmt", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fmt", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
pcs_log_get_tail
int
int pcs_log_get_tail(char* buff, unsigned int* sz) { struct log_buff *curr, *prev; size_t sz_curr, sz_left, sz_total = 0; if (!logwriter) return -1; pthread_mutex_lock(&loglock); /* * Get the most we can from 2 buffers */ curr = &logwriter->b[logwriter->curr]; if ((sz_curr = curr->used) <= (sz_left = *sz)) { sz_left -= sz_curr; prev = &logwriter->b[log_buff_prev(logwriter, logwriter->curr)]; if (prev->used <= sz_left) { memcpy(buff, prev->buff, prev->used); sz_total += prev->used; } else { memcpy(buff, prev->buff + prev->used - sz_left, sz_left); sz_total += sz_left; } memcpy(buff + sz_total, curr->buff, sz_curr); sz_total += sz_curr; } else { memcpy(buff, curr->buff + sz_curr - sz_left, sz_left); sz_total += sz_left; } pthread_mutex_unlock(&loglock); BUG_ON(sz_total > *sz); *sz = (unsigned int)sz_total; return 0; }
/* Fill provided buffer with buffered log tail or returns -1 if log is not buffered. */
Fill provided buffer with buffered log tail or returns -1 if log is not buffered.
[ "Fill", "provided", "buffer", "with", "buffered", "log", "tail", "or", "returns", "-", "1", "if", "log", "is", "not", "buffered", "." ]
int pcs_log_get_tail(char* buff, unsigned int* sz) { struct log_buff *curr, *prev; size_t sz_curr, sz_left, sz_total = 0; if (!logwriter) return -1; pthread_mutex_lock(&loglock); curr = &logwriter->b[logwriter->curr]; if ((sz_curr = curr->used) <= (sz_left = *sz)) { sz_left -= sz_curr; prev = &logwriter->b[log_buff_prev(logwriter, logwriter->curr)]; if (prev->used <= sz_left) { memcpy(buff, prev->buff, prev->used); sz_total += prev->used; } else { memcpy(buff, prev->buff + prev->used - sz_left, sz_left); sz_total += sz_left; } memcpy(buff + sz_total, curr->buff, sz_curr); sz_total += sz_curr; } else { memcpy(buff, curr->buff + sz_curr - sz_left, sz_left); sz_total += sz_left; } pthread_mutex_unlock(&loglock); BUG_ON(sz_total > *sz); *sz = (unsigned int)sz_total; return 0; }
[ "int", "pcs_log_get_tail", "(", "char", "*", "buff", ",", "unsigned", "int", "*", "sz", ")", "{", "struct", "log_buff", "*", "curr", ",", "*", "prev", ";", "size_t", "sz_curr", ",", "sz_left", ",", "sz_total", "=", "0", ";", "if", "(", "!", "logwriter", ")", "return", "-1", ";", "pthread_mutex_lock", "(", "&", "loglock", ")", ";", "curr", "=", "&", "logwriter", "->", "b", "[", "logwriter", "->", "curr", "]", ";", "if", "(", "(", "sz_curr", "=", "curr", "->", "used", ")", "<=", "(", "sz_left", "=", "*", "sz", ")", ")", "{", "sz_left", "-=", "sz_curr", ";", "prev", "=", "&", "logwriter", "->", "b", "[", "log_buff_prev", "(", "logwriter", ",", "logwriter", "->", "curr", ")", "]", ";", "if", "(", "prev", "->", "used", "<=", "sz_left", ")", "{", "memcpy", "(", "buff", ",", "prev", "->", "buff", ",", "prev", "->", "used", ")", ";", "sz_total", "+=", "prev", "->", "used", ";", "}", "else", "{", "memcpy", "(", "buff", ",", "prev", "->", "buff", "+", "prev", "->", "used", "-", "sz_left", ",", "sz_left", ")", ";", "sz_total", "+=", "sz_left", ";", "}", "memcpy", "(", "buff", "+", "sz_total", ",", "curr", "->", "buff", ",", "sz_curr", ")", ";", "sz_total", "+=", "sz_curr", ";", "}", "else", "{", "memcpy", "(", "buff", ",", "curr", "->", "buff", "+", "sz_curr", "-", "sz_left", ",", "sz_left", ")", ";", "sz_total", "+=", "sz_left", ";", "}", "pthread_mutex_unlock", "(", "&", "loglock", ")", ";", "BUG_ON", "(", "sz_total", ">", "*", "sz", ")", ";", "*", "sz", "=", "(", "unsigned", "int", ")", "sz_total", ";", "return", "0", ";", "}" ]
Fill provided buffer with buffered log tail or returns -1 if log is not buffered.
[ "Fill", "provided", "buffer", "with", "buffered", "log", "tail", "or", "returns", "-", "1", "if", "log", "is", "not", "buffered", "." ]
[ "/*\n\t * Get the most we can from 2 buffers\n\t */" ]
[ { "param": "buff", "type": "char" }, { "param": "sz", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buff", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sz", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
init_ops
char
const char * init_ops(struct log_writer *l, const char *ext) { init_ops_generic(l); if (!ext) return ""; #ifdef _ENABLE_GZIP_COMPRESSION if (!strcmp(ext, "gz")) { init_ops_gzip(l); return ext; } #endif #if defined(_ENABLE_ZSTD_COMPRESSION) || defined(_ENABLE_GZIP_COMPRESSION) if (!strcmp(ext, "zst")) { #ifdef _ENABLE_ZSTD_COMPRESSION init_ops_zstd(l); return ext; #else init_ops_gzip(l); return "gz"; #endif } #endif return ext; }
/* * Initialize log ops depending on 'compression' extension. * It could be 'gz', 'zst' for corresponsing compression or some other, * in which case no compression will be used. If libpcs is compiled without * ZST compression and with gzip compression support, and ext is 'zst', then * it fallbacks to gzip compression. * * Returns file extension (it make sense in case of fallback to gzip). */
Initialize log ops depending on 'compression' extension. It could be 'gz', 'zst' for corresponsing compression or some other, in which case no compression will be used. If libpcs is compiled without ZST compression and with gzip compression support, and ext is 'zst', then it fallbacks to gzip compression. Returns file extension (it make sense in case of fallback to gzip).
[ "Initialize", "log", "ops", "depending", "on", "'", "compression", "'", "extension", ".", "It", "could", "be", "'", "gz", "'", "'", "zst", "'", "for", "corresponsing", "compression", "or", "some", "other", "in", "which", "case", "no", "compression", "will", "be", "used", ".", "If", "libpcs", "is", "compiled", "without", "ZST", "compression", "and", "with", "gzip", "compression", "support", "and", "ext", "is", "'", "zst", "'", "then", "it", "fallbacks", "to", "gzip", "compression", ".", "Returns", "file", "extension", "(", "it", "make", "sense", "in", "case", "of", "fallback", "to", "gzip", ")", "." ]
const char * init_ops(struct log_writer *l, const char *ext) { init_ops_generic(l); if (!ext) return ""; #ifdef _ENABLE_GZIP_COMPRESSION if (!strcmp(ext, "gz")) { init_ops_gzip(l); return ext; } #endif #if defined(_ENABLE_ZSTD_COMPRESSION) || defined(_ENABLE_GZIP_COMPRESSION) if (!strcmp(ext, "zst")) { #ifdef _ENABLE_ZSTD_COMPRESSION init_ops_zstd(l); return ext; #else init_ops_gzip(l); return "gz"; #endif } #endif return ext; }
[ "const", "char", "*", "init_ops", "(", "struct", "log_writer", "*", "l", ",", "const", "char", "*", "ext", ")", "{", "init_ops_generic", "(", "l", ")", ";", "if", "(", "!", "ext", ")", "return", "\"", "\"", ";", "#ifdef", "_ENABLE_GZIP_COMPRESSION", "if", "(", "!", "strcmp", "(", "ext", ",", "\"", "\"", ")", ")", "{", "init_ops_gzip", "(", "l", ")", ";", "return", "ext", ";", "}", "#endif", "#if", "defined", "(", "_ENABLE_ZSTD_COMPRESSION", ")", "||", "defined", "(", "_ENABLE_GZIP_COMPRESSION", ")", "\n", "if", "(", "!", "strcmp", "(", "ext", ",", "\"", "\"", ")", ")", "{", "#ifdef", "_ENABLE_ZSTD_COMPRESSION", "init_ops_zstd", "(", "l", ")", ";", "return", "ext", ";", "#else", "init_ops_gzip", "(", "l", ")", ";", "return", "\"", "\"", ";", "#endif", "}", "#endif", "return", "ext", ";", "}" ]
Initialize log ops depending on 'compression' extension.
[ "Initialize", "log", "ops", "depending", "on", "'", "compression", "'", "extension", "." ]
[]
[ { "param": "l", "type": "struct log_writer" }, { "param": "ext", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "l", "type": "struct log_writer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ext", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
pcs_get_logfile
char
const char* pcs_get_logfile(void) { if (logwriter) { return logwriter->fname; } else { return 0; } }
/* Returns currently used log file or NULL if it was not set yet */
Returns currently used log file or NULL if it was not set yet
[ "Returns", "currently", "used", "log", "file", "or", "NULL", "if", "it", "was", "not", "set", "yet" ]
const char* pcs_get_logfile(void) { if (logwriter) { return logwriter->fname; } else { return 0; } }
[ "const", "char", "*", "pcs_get_logfile", "(", "void", ")", "{", "if", "(", "logwriter", ")", "{", "return", "logwriter", "->", "fname", ";", "}", "else", "{", "return", "0", ";", "}", "}" ]
Returns currently used log file or NULL if it was not set yet
[ "Returns", "currently", "used", "log", "file", "or", "NULL", "if", "it", "was", "not", "set", "yet" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
pcs_get_logfile_base_ext
char
char* pcs_get_logfile_base_ext(const char** pext) { if (logwriter) { return get_basename_ext(logwriter->fname, pext); } else { if (pext) { *pext = 0; } return 0; } }
/* Returns currently used logfile path split onto the basename part and extension. * The returned basename part must be freed by caller passing them to pcs_free(). */
Returns currently used logfile path split onto the basename part and extension. The returned basename part must be freed by caller passing them to pcs_free().
[ "Returns", "currently", "used", "logfile", "path", "split", "onto", "the", "basename", "part", "and", "extension", ".", "The", "returned", "basename", "part", "must", "be", "freed", "by", "caller", "passing", "them", "to", "pcs_free", "()", "." ]
char* pcs_get_logfile_base_ext(const char** pext) { if (logwriter) { return get_basename_ext(logwriter->fname, pext); } else { if (pext) { *pext = 0; } return 0; } }
[ "char", "*", "pcs_get_logfile_base_ext", "(", "const", "char", "*", "*", "pext", ")", "{", "if", "(", "logwriter", ")", "{", "return", "get_basename_ext", "(", "logwriter", "->", "fname", ",", "pext", ")", ";", "}", "else", "{", "if", "(", "pext", ")", "{", "*", "pext", "=", "0", ";", "}", "return", "0", ";", "}", "}" ]
Returns currently used logfile path split onto the basename part and extension.
[ "Returns", "currently", "used", "logfile", "path", "split", "onto", "the", "basename", "part", "and", "extension", "." ]
[]
[ { "param": "pext", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pext", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
pcs_log_fatal_sighandler
void
void pcs_log_fatal_sighandler(int sig, siginfo_t *info, void *context) { if (in_fatal_signal_handler) { /* double fault, can't recover :( */ /* SA_RESETHAND is ignored when called from Go signal handler, reseting handler explicitly */ signal(sig, SIG_DFL); return; } in_fatal_signal_handler = 1; #if defined(__linux__) /* add PROFILER_SIGNO in mask of blocked signals to avoid truncated coredumps */ sigaddset(&((ucontext_t*)context)->uc_sigmask, PROFILER_SIGNO); #endif struct log_buff *b = flush_full_buffers(); describe_signal(sig, info, register_get_pc((ucontext_t*)context)); register_dump((ucontext_t*)context, __log_printf, NULL); trace_dump((ucontext_t*)context, __log_printf, NULL); flush_log_buffer(b); pcs_call_atexit(exit_fatal); /* re-raise signal, handler is reset due to SA_RESETHAND and leads to default handler (core) */ raise(sig); }
/* This signal handler expects that it is registered using sigaction() with * flags field set to SA_NODEFER | SA_RESETHAND | SA_SIGINFO. * Due to SA_RESETHAND the signal action is restored to the default upon * entry to the signal handler. Then returning from the handler makes * execution to be restarted from the faulty instruction which will do * another fault, so we'll get one more signal of the same type, but now the * default handler will be called. */
This signal handler expects that it is registered using sigaction() with flags field set to SA_NODEFER | SA_RESETHAND | SA_SIGINFO. Due to SA_RESETHAND the signal action is restored to the default upon entry to the signal handler. Then returning from the handler makes execution to be restarted from the faulty instruction which will do another fault, so we'll get one more signal of the same type, but now the default handler will be called.
[ "This", "signal", "handler", "expects", "that", "it", "is", "registered", "using", "sigaction", "()", "with", "flags", "field", "set", "to", "SA_NODEFER", "|", "SA_RESETHAND", "|", "SA_SIGINFO", ".", "Due", "to", "SA_RESETHAND", "the", "signal", "action", "is", "restored", "to", "the", "default", "upon", "entry", "to", "the", "signal", "handler", ".", "Then", "returning", "from", "the", "handler", "makes", "execution", "to", "be", "restarted", "from", "the", "faulty", "instruction", "which", "will", "do", "another", "fault", "so", "we", "'", "ll", "get", "one", "more", "signal", "of", "the", "same", "type", "but", "now", "the", "default", "handler", "will", "be", "called", "." ]
void pcs_log_fatal_sighandler(int sig, siginfo_t *info, void *context) { if (in_fatal_signal_handler) { signal(sig, SIG_DFL); return; } in_fatal_signal_handler = 1; #if defined(__linux__) sigaddset(&((ucontext_t*)context)->uc_sigmask, PROFILER_SIGNO); #endif struct log_buff *b = flush_full_buffers(); describe_signal(sig, info, register_get_pc((ucontext_t*)context)); register_dump((ucontext_t*)context, __log_printf, NULL); trace_dump((ucontext_t*)context, __log_printf, NULL); flush_log_buffer(b); pcs_call_atexit(exit_fatal); raise(sig); }
[ "void", "pcs_log_fatal_sighandler", "(", "int", "sig", ",", "siginfo_t", "*", "info", ",", "void", "*", "context", ")", "{", "if", "(", "in_fatal_signal_handler", ")", "{", "signal", "(", "sig", ",", "SIG_DFL", ")", ";", "return", ";", "}", "in_fatal_signal_handler", "=", "1", ";", "#if", "defined", "(", "__linux__", ")", "\n", "sigaddset", "(", "&", "(", "(", "ucontext_t", "*", ")", "context", ")", "->", "uc_sigmask", ",", "PROFILER_SIGNO", ")", ";", "#endif", "struct", "log_buff", "*", "b", "=", "flush_full_buffers", "(", ")", ";", "describe_signal", "(", "sig", ",", "info", ",", "register_get_pc", "(", "(", "ucontext_t", "*", ")", "context", ")", ")", ";", "register_dump", "(", "(", "ucontext_t", "*", ")", "context", ",", "__log_printf", ",", "NULL", ")", ";", "trace_dump", "(", "(", "ucontext_t", "*", ")", "context", ",", "__log_printf", ",", "NULL", ")", ";", "flush_log_buffer", "(", "b", ")", ";", "pcs_call_atexit", "(", "exit_fatal", ")", ";", "raise", "(", "sig", ")", ";", "}" ]
This signal handler expects that it is registered using sigaction() with flags field set to SA_NODEFER | SA_RESETHAND | SA_SIGINFO.
[ "This", "signal", "handler", "expects", "that", "it", "is", "registered", "using", "sigaction", "()", "with", "flags", "field", "set", "to", "SA_NODEFER", "|", "SA_RESETHAND", "|", "SA_SIGINFO", "." ]
[ "/* double fault, can't recover :( */", "/* SA_RESETHAND is ignored when called from Go signal handler, reseting handler explicitly */", "/* add PROFILER_SIGNO in mask of blocked signals to avoid truncated coredumps */", "/* re-raise signal, handler is reset due to SA_RESETHAND and leads to default handler (core) */" ]
[ { "param": "sig", "type": "int" }, { "param": "info", "type": "siginfo_t" }, { "param": "context", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sig", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "info", "type": "siginfo_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "context", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
gz_close
int
static int gz_close(struct log_writer *l) { int res = gzclose(l->gz_file); l->gz_file = NULL; return (res == Z_OK) ? 0 : res; }
/* this closes gz_file with gzclose and inherent fd */
this closes gz_file with gzclose and inherent fd
[ "this", "closes", "gz_file", "with", "gzclose", "and", "inherent", "fd" ]
static int gz_close(struct log_writer *l) { int res = gzclose(l->gz_file); l->gz_file = NULL; return (res == Z_OK) ? 0 : res; }
[ "static", "int", "gz_close", "(", "struct", "log_writer", "*", "l", ")", "{", "int", "res", "=", "gzclose", "(", "l", "->", "gz_file", ")", ";", "l", "->", "gz_file", "=", "NULL", ";", "return", "(", "res", "==", "Z_OK", ")", "?", "0", ":", "res", ";", "}" ]
this closes gz_file with gzclose and inherent fd
[ "this", "closes", "gz_file", "with", "gzclose", "and", "inherent", "fd" ]
[]
[ { "param": "l", "type": "struct log_writer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "l", "type": "struct log_writer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
91e3367ceb9c547152d18d7243e56083bb67e11d
acronis/pcs-io
libpcs_io/log.c
[ "MIT" ]
C
gz_open_existing
int
static int gz_open_existing(int fd, u64 size, struct log_writer *log) { struct gz_footer footer; int buf_len, err; unsigned char *buf = NULL; u64 offs; int reason; if (size <= (GZ_FOOTER_LEN + sizeof(gz_hdr_signature))) { err = z_truncate_existing_and_open(log, fd, 0); if (err) log_file_close(fd); return err; } reason = 1; err = gz_seek_last_record(fd, size, &offs, &footer); if (err) goto rotate; reason = 2; err = gz_read_last_record(fd, &buf, &buf_len, &footer); if (err < 0) goto rotate; reason = 3; if (err > 0) { /* file is not corrupted */ if (z_open_log_by_fd(log, fd) < 0) goto rotate; return 0; } /* last file record is corrupted, truncate and rewrite */ reason = 4; if (z_truncate_existing_and_open(log, fd, offs)) goto rotate; reason = 5; err = z_add_last_record(log, buf, buf_len); if (err) { z_close_log(log); goto rotate; } pcs_free(buf); return 0; rotate: pcs_free(buf); log_file_close(fd); if (logrotate_run(&log->rotate)) return -1; log->reopen_log(log); if (!z_funcs.file_is_null(log)) { char str[128]; snprintf(str, sizeof(str), "------ gzlog file forcefully rotated on error (reason %d, err %d) ------\n\n", reason, err); gzputs(log->gz_file, str); gzflush(log->gz_file, Z_FINISH); } return z_funcs.file_is_null(log); }
/* unlike other functions open_existing() closes fd on errors, i.e. caller should forget about fd at all */
unlike other functions open_existing() closes fd on errors, i.e. caller should forget about fd at all
[ "unlike", "other", "functions", "open_existing", "()", "closes", "fd", "on", "errors", "i", ".", "e", ".", "caller", "should", "forget", "about", "fd", "at", "all" ]
static int gz_open_existing(int fd, u64 size, struct log_writer *log) { struct gz_footer footer; int buf_len, err; unsigned char *buf = NULL; u64 offs; int reason; if (size <= (GZ_FOOTER_LEN + sizeof(gz_hdr_signature))) { err = z_truncate_existing_and_open(log, fd, 0); if (err) log_file_close(fd); return err; } reason = 1; err = gz_seek_last_record(fd, size, &offs, &footer); if (err) goto rotate; reason = 2; err = gz_read_last_record(fd, &buf, &buf_len, &footer); if (err < 0) goto rotate; reason = 3; if (err > 0) { if (z_open_log_by_fd(log, fd) < 0) goto rotate; return 0; } reason = 4; if (z_truncate_existing_and_open(log, fd, offs)) goto rotate; reason = 5; err = z_add_last_record(log, buf, buf_len); if (err) { z_close_log(log); goto rotate; } pcs_free(buf); return 0; rotate: pcs_free(buf); log_file_close(fd); if (logrotate_run(&log->rotate)) return -1; log->reopen_log(log); if (!z_funcs.file_is_null(log)) { char str[128]; snprintf(str, sizeof(str), "------ gzlog file forcefully rotated on error (reason %d, err %d) ------\n\n", reason, err); gzputs(log->gz_file, str); gzflush(log->gz_file, Z_FINISH); } return z_funcs.file_is_null(log); }
[ "static", "int", "gz_open_existing", "(", "int", "fd", ",", "u64", "size", ",", "struct", "log_writer", "*", "log", ")", "{", "struct", "gz_footer", "footer", ";", "int", "buf_len", ",", "err", ";", "unsigned", "char", "*", "buf", "=", "NULL", ";", "u64", "offs", ";", "int", "reason", ";", "if", "(", "size", "<=", "(", "GZ_FOOTER_LEN", "+", "sizeof", "(", "gz_hdr_signature", ")", ")", ")", "{", "err", "=", "z_truncate_existing_and_open", "(", "log", ",", "fd", ",", "0", ")", ";", "if", "(", "err", ")", "log_file_close", "(", "fd", ")", ";", "return", "err", ";", "}", "reason", "=", "1", ";", "err", "=", "gz_seek_last_record", "(", "fd", ",", "size", ",", "&", "offs", ",", "&", "footer", ")", ";", "if", "(", "err", ")", "goto", "rotate", ";", "reason", "=", "2", ";", "err", "=", "gz_read_last_record", "(", "fd", ",", "&", "buf", ",", "&", "buf_len", ",", "&", "footer", ")", ";", "if", "(", "err", "<", "0", ")", "goto", "rotate", ";", "reason", "=", "3", ";", "if", "(", "err", ">", "0", ")", "{", "if", "(", "z_open_log_by_fd", "(", "log", ",", "fd", ")", "<", "0", ")", "goto", "rotate", ";", "return", "0", ";", "}", "reason", "=", "4", ";", "if", "(", "z_truncate_existing_and_open", "(", "log", ",", "fd", ",", "offs", ")", ")", "goto", "rotate", ";", "reason", "=", "5", ";", "err", "=", "z_add_last_record", "(", "log", ",", "buf", ",", "buf_len", ")", ";", "if", "(", "err", ")", "{", "z_close_log", "(", "log", ")", ";", "goto", "rotate", ";", "}", "pcs_free", "(", "buf", ")", ";", "return", "0", ";", "rotate", ":", "pcs_free", "(", "buf", ")", ";", "log_file_close", "(", "fd", ")", ";", "if", "(", "logrotate_run", "(", "&", "log", "->", "rotate", ")", ")", "return", "-1", ";", "log", "->", "reopen_log", "(", "log", ")", ";", "if", "(", "!", "z_funcs", ".", "file_is_null", "(", "log", ")", ")", "{", "char", "str", "[", "128", "]", ";", "snprintf", "(", "str", ",", "sizeof", "(", "str", ")", ",", "\"", "\\n", "\\n", "\"", ",", "reason", ",", "err", ")", ";", "gzputs", "(", "log", "->", "gz_file", ",", "str", ")", ";", "gzflush", "(", "log", "->", "gz_file", ",", "Z_FINISH", ")", ";", "}", "return", "z_funcs", ".", "file_is_null", "(", "log", ")", ";", "}" ]
unlike other functions open_existing() closes fd on errors, i.e.
[ "unlike", "other", "functions", "open_existing", "()", "closes", "fd", "on", "errors", "i", ".", "e", "." ]
[ "/* file is not corrupted */", "/* last file record is corrupted, truncate and rewrite */" ]
[ { "param": "fd", "type": "int" }, { "param": "size", "type": "u64" }, { "param": "log", "type": "struct log_writer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fd", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "u64", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "log", "type": "struct log_writer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2f871d3033b9d5afc46f119e5fefb4f7d2e946f1
acronis/pcs-io
libpcs_io/regdump.c
[ "MIT" ]
C
advance_ptr
void
static void advance_ptr(char **pptr, DWORD len, size_t path_sz) { if (!len || len >= path_sz) return; char *ptr = *pptr; ptr += len; *ptr = ';'; ptr++; *ptr = 0; *pptr = ptr; }
/* If len is non-zero and less than path_sz, add value separator ';' and set *ptr to next character. * len does not include terminating null character. */
If len is non-zero and less than path_sz, add value separator ';' and set *ptr to next character. len does not include terminating null character.
[ "If", "len", "is", "non", "-", "zero", "and", "less", "than", "path_sz", "add", "value", "separator", "'", ";", "'", "and", "set", "*", "ptr", "to", "next", "character", ".", "len", "does", "not", "include", "terminating", "null", "character", "." ]
static void advance_ptr(char **pptr, DWORD len, size_t path_sz) { if (!len || len >= path_sz) return; char *ptr = *pptr; ptr += len; *ptr = ';'; ptr++; *ptr = 0; *pptr = ptr; }
[ "static", "void", "advance_ptr", "(", "char", "*", "*", "pptr", ",", "DWORD", "len", ",", "size_t", "path_sz", ")", "{", "if", "(", "!", "len", "||", "len", ">=", "path_sz", ")", "return", ";", "char", "*", "ptr", "=", "*", "pptr", ";", "ptr", "+=", "len", ";", "*", "ptr", "=", "'", "'", ";", "ptr", "++", ";", "*", "ptr", "=", "0", ";", "*", "pptr", "=", "ptr", ";", "}" ]
If len is non-zero and less than path_sz, add value separator ';' and set *ptr to next character.
[ "If", "len", "is", "non", "-", "zero", "and", "less", "than", "path_sz", "add", "value", "separator", "'", ";", "'", "and", "set", "*", "ptr", "to", "next", "character", "." ]
[]
[ { "param": "pptr", "type": "char" }, { "param": "len", "type": "DWORD" }, { "param": "path_sz", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pptr", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "DWORD", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "path_sz", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
83f6c630c0bcf57b6b24218c6e47f584efdffe99
acronis/pcs-io
libpcs_io/jhash.h
[ "MIT" ]
C
jhash3
u32
static inline u32 jhash3(u32 a, u32 b, u32 c, u32 initval) { a += JHASH_MAGIC; b += JHASH_MAGIC; c += initval; jmix(a, b, c); return c; }
/* This is special version of lookup2, handling hashing of 3 u32 words only. */
This is special version of lookup2, handling hashing of 3 u32 words only.
[ "This", "is", "special", "version", "of", "lookup2", "handling", "hashing", "of", "3", "u32", "words", "only", "." ]
static inline u32 jhash3(u32 a, u32 b, u32 c, u32 initval) { a += JHASH_MAGIC; b += JHASH_MAGIC; c += initval; jmix(a, b, c); return c; }
[ "static", "inline", "u32", "jhash3", "(", "u32", "a", ",", "u32", "b", ",", "u32", "c", ",", "u32", "initval", ")", "{", "a", "+=", "JHASH_MAGIC", ";", "b", "+=", "JHASH_MAGIC", ";", "c", "+=", "initval", ";", "jmix", "(", "a", ",", "b", ",", "c", ")", ";", "return", "c", ";", "}" ]
This is special version of lookup2, handling hashing of 3 u32 words only.
[ "This", "is", "special", "version", "of", "lookup2", "handling", "hashing", "of", "3", "u32", "words", "only", "." ]
[]
[ { "param": "a", "type": "u32" }, { "param": "b", "type": "u32" }, { "param": "c", "type": "u32" }, { "param": "initval", "type": "u32" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "a", "type": "u32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "b", "type": "u32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "c", "type": "u32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "initval", "type": "u32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1528384b5468d687efa5c639a2aff2b540b07d57
acronis/pcs-io
libpcs_io/pcs_co_locks.c
[ "MIT" ]
C
__pcs_co_read_trylock
ULONG_PTR
ULONG_PTR __pcs_co_read_trylock(struct pcs_co_rwlock *lock) { ULONG_PTR val = pcs_atomic_uptr_load(&lock->val); for (;;) { if (unlikely((val & (PCS_CO_RWLOCK_WRITE_LOCKED | PCS_CO_RWLOCK_HAS_WAITERS)) != 0)) { /* RW-lock is locked for write or has write waiters, * have to put current coroutine into read waiters queue */ return val; } /* Transition A->C or C->C */ ULONG_PTR res = pcs_atomic_uptr_cas(&lock->val, val, val + (1 << PCS_CO_RWLOCK_NR_READERS_SHIFT)); if (likely(res == val)) return 0; val = res; } }
/* Returns 0 on success, current value of lock->val otherwise */
Returns 0 on success, current value of lock->val otherwise
[ "Returns", "0", "on", "success", "current", "value", "of", "lock", "-", ">", "val", "otherwise" ]
ULONG_PTR __pcs_co_read_trylock(struct pcs_co_rwlock *lock) { ULONG_PTR val = pcs_atomic_uptr_load(&lock->val); for (;;) { if (unlikely((val & (PCS_CO_RWLOCK_WRITE_LOCKED | PCS_CO_RWLOCK_HAS_WAITERS)) != 0)) { return val; } ULONG_PTR res = pcs_atomic_uptr_cas(&lock->val, val, val + (1 << PCS_CO_RWLOCK_NR_READERS_SHIFT)); if (likely(res == val)) return 0; val = res; } }
[ "ULONG_PTR", "__pcs_co_read_trylock", "(", "struct", "pcs_co_rwlock", "*", "lock", ")", "{", "ULONG_PTR", "val", "=", "pcs_atomic_uptr_load", "(", "&", "lock", "->", "val", ")", ";", "for", "(", ";", ";", ")", "{", "if", "(", "unlikely", "(", "(", "val", "&", "(", "PCS_CO_RWLOCK_WRITE_LOCKED", "|", "PCS_CO_RWLOCK_HAS_WAITERS", ")", ")", "!=", "0", ")", ")", "{", "return", "val", ";", "}", "ULONG_PTR", "res", "=", "pcs_atomic_uptr_cas", "(", "&", "lock", "->", "val", ",", "val", ",", "val", "+", "(", "1", "<<", "PCS_CO_RWLOCK_NR_READERS_SHIFT", ")", ")", ";", "if", "(", "likely", "(", "res", "==", "val", ")", ")", "return", "0", ";", "val", "=", "res", ";", "}", "}" ]
Returns 0 on success, current value of lock->val otherwise
[ "Returns", "0", "on", "success", "current", "value", "of", "lock", "-", ">", "val", "otherwise" ]
[ "/* RW-lock is locked for write or has write waiters,\n\t\t\t * have to put current coroutine into read waiters queue */", "/* Transition A->C or C->C */" ]
[ { "param": "lock", "type": "struct pcs_co_rwlock" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "lock", "type": "struct pcs_co_rwlock", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1528384b5468d687efa5c639a2aff2b540b07d57
acronis/pcs-io
libpcs_io/pcs_co_locks.c
[ "MIT" ]
C
__pcs_co_read_unlock_writer
void
static void __pcs_co_read_unlock_writer(struct pcs_co_rwlock *lock, ULONG_PTR val, struct pcs_coroutine *co) { ULONG_PTR new_val = (ULONG_PTR)co | PCS_CO_RWLOCK_WRITE_LOCKED; if (!cd_list_empty(&lock->wwaiters) || !cd_list_empty(&lock->rwaiters)) new_val |= PCS_CO_RWLOCK_HAS_WAITERS; ULONG_PTR res = pcs_atomic_uptr_exchange(&lock->val, new_val); BUG_ON(res != val); }
/* Handoff RW-lock ownerwhip to selected coroutine */
Handoff RW-lock ownerwhip to selected coroutine
[ "Handoff", "RW", "-", "lock", "ownerwhip", "to", "selected", "coroutine" ]
static void __pcs_co_read_unlock_writer(struct pcs_co_rwlock *lock, ULONG_PTR val, struct pcs_coroutine *co) { ULONG_PTR new_val = (ULONG_PTR)co | PCS_CO_RWLOCK_WRITE_LOCKED; if (!cd_list_empty(&lock->wwaiters) || !cd_list_empty(&lock->rwaiters)) new_val |= PCS_CO_RWLOCK_HAS_WAITERS; ULONG_PTR res = pcs_atomic_uptr_exchange(&lock->val, new_val); BUG_ON(res != val); }
[ "static", "void", "__pcs_co_read_unlock_writer", "(", "struct", "pcs_co_rwlock", "*", "lock", ",", "ULONG_PTR", "val", ",", "struct", "pcs_coroutine", "*", "co", ")", "{", "ULONG_PTR", "new_val", "=", "(", "ULONG_PTR", ")", "co", "|", "PCS_CO_RWLOCK_WRITE_LOCKED", ";", "if", "(", "!", "cd_list_empty", "(", "&", "lock", "->", "wwaiters", ")", "||", "!", "cd_list_empty", "(", "&", "lock", "->", "rwaiters", ")", ")", "new_val", "|=", "PCS_CO_RWLOCK_HAS_WAITERS", ";", "ULONG_PTR", "res", "=", "pcs_atomic_uptr_exchange", "(", "&", "lock", "->", "val", ",", "new_val", ")", ";", "BUG_ON", "(", "res", "!=", "val", ")", ";", "}" ]
Handoff RW-lock ownerwhip to selected coroutine
[ "Handoff", "RW", "-", "lock", "ownerwhip", "to", "selected", "coroutine" ]
[]
[ { "param": "lock", "type": "struct pcs_co_rwlock" }, { "param": "val", "type": "ULONG_PTR" }, { "param": "co", "type": "struct pcs_coroutine" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "lock", "type": "struct pcs_co_rwlock", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "val", "type": "ULONG_PTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "co", "type": "struct pcs_coroutine", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1528384b5468d687efa5c639a2aff2b540b07d57
acronis/pcs-io
libpcs_io/pcs_co_locks.c
[ "MIT" ]
C
__pcs_co_sem_tryget
int
static int __pcs_co_sem_tryget(struct pcs_co_sem *sem) { s32 val = pcs_atomic32_load(&sem->val); for (;;) { if (unlikely(val <= 0)) return 0; /* Transition A->A */ s32 res = pcs_atomic32_cas(&sem->val, val, val - 1); if (likely(res == val)) return 1; val = res; } }
/* Returns 1 on success, 0 otherwise */
Returns 1 on success, 0 otherwise
[ "Returns", "1", "on", "success", "0", "otherwise" ]
static int __pcs_co_sem_tryget(struct pcs_co_sem *sem) { s32 val = pcs_atomic32_load(&sem->val); for (;;) { if (unlikely(val <= 0)) return 0; s32 res = pcs_atomic32_cas(&sem->val, val, val - 1); if (likely(res == val)) return 1; val = res; } }
[ "static", "int", "__pcs_co_sem_tryget", "(", "struct", "pcs_co_sem", "*", "sem", ")", "{", "s32", "val", "=", "pcs_atomic32_load", "(", "&", "sem", "->", "val", ")", ";", "for", "(", ";", ";", ")", "{", "if", "(", "unlikely", "(", "val", "<=", "0", ")", ")", "return", "0", ";", "s32", "res", "=", "pcs_atomic32_cas", "(", "&", "sem", "->", "val", ",", "val", ",", "val", "-", "1", ")", ";", "if", "(", "likely", "(", "res", "==", "val", ")", ")", "return", "1", ";", "val", "=", "res", ";", "}", "}" ]
Returns 1 on success, 0 otherwise
[ "Returns", "1", "on", "success", "0", "otherwise" ]
[ "/* Transition A->A */" ]
[ { "param": "sem", "type": "struct pcs_co_sem" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sem", "type": "struct pcs_co_sem", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b8d3fcbe90ebcea11a7a540499ff44f0089eb04
acronis/pcs-io
libpcs_io/crc32.c
[ "MIT" ]
C
crc32_32bit
uint32_t
static uint32_t crc32_32bit(uint32_t crc, const unsigned char *s, unsigned int len) { crc ^= 0xFFFFFFFF; while (((uintptr_t)s & 3) && len) { crc = crc32_table[0][(unsigned char)(crc ^ (*s))] ^ (crc >> 8); s++; len--; } while (len >= 4) { const uint32_t *w = (const uint32_t *)s; crc ^= cpu_to_le32(*w); crc = crc32_table[3][(crc) & 255] ^ crc32_table[2][(crc >> 8) & 255] ^ crc32_table[1][(crc >> 16) & 255] ^ crc32_table[0][(crc >> 24) & 255]; s += 4; len -= 4; } while (len) { crc = crc32_table[0][(unsigned char)(crc ^ (*s))] ^ (crc >> 8); s++; len--; } return crc ^ 0xFFFFFFFF; }
/* this function is more optimal for 32bit. not optimized for BE architecture */
this function is more optimal for 32bit. not optimized for BE architecture
[ "this", "function", "is", "more", "optimal", "for", "32bit", ".", "not", "optimized", "for", "BE", "architecture" ]
static uint32_t crc32_32bit(uint32_t crc, const unsigned char *s, unsigned int len) { crc ^= 0xFFFFFFFF; while (((uintptr_t)s & 3) && len) { crc = crc32_table[0][(unsigned char)(crc ^ (*s))] ^ (crc >> 8); s++; len--; } while (len >= 4) { const uint32_t *w = (const uint32_t *)s; crc ^= cpu_to_le32(*w); crc = crc32_table[3][(crc) & 255] ^ crc32_table[2][(crc >> 8) & 255] ^ crc32_table[1][(crc >> 16) & 255] ^ crc32_table[0][(crc >> 24) & 255]; s += 4; len -= 4; } while (len) { crc = crc32_table[0][(unsigned char)(crc ^ (*s))] ^ (crc >> 8); s++; len--; } return crc ^ 0xFFFFFFFF; }
[ "static", "uint32_t", "crc32_32bit", "(", "uint32_t", "crc", ",", "const", "unsigned", "char", "*", "s", ",", "unsigned", "int", "len", ")", "{", "crc", "^=", "0xFFFFFFFF", ";", "while", "(", "(", "(", "uintptr_t", ")", "s", "&", "3", ")", "&&", "len", ")", "{", "crc", "=", "crc32_table", "[", "0", "]", "[", "(", "unsigned", "char", ")", "(", "crc", "^", "(", "*", "s", ")", ")", "]", "^", "(", "crc", ">>", "8", ")", ";", "s", "++", ";", "len", "--", ";", "}", "while", "(", "len", ">=", "4", ")", "{", "const", "uint32_t", "*", "w", "=", "(", "const", "uint32_t", "*", ")", "s", ";", "crc", "^=", "cpu_to_le32", "(", "*", "w", ")", ";", "crc", "=", "crc32_table", "[", "3", "]", "[", "(", "crc", ")", "&", "255", "]", "^", "crc32_table", "[", "2", "]", "[", "(", "crc", ">>", "8", ")", "&", "255", "]", "^", "crc32_table", "[", "1", "]", "[", "(", "crc", ">>", "16", ")", "&", "255", "]", "^", "crc32_table", "[", "0", "]", "[", "(", "crc", ">>", "24", ")", "&", "255", "]", ";", "s", "+=", "4", ";", "len", "-=", "4", ";", "}", "while", "(", "len", ")", "{", "crc", "=", "crc32_table", "[", "0", "]", "[", "(", "unsigned", "char", ")", "(", "crc", "^", "(", "*", "s", ")", ")", "]", "^", "(", "crc", ">>", "8", ")", ";", "s", "++", ";", "len", "--", ";", "}", "return", "crc", "^", "0xFFFFFFFF", ";", "}" ]
this function is more optimal for 32bit.
[ "this", "function", "is", "more", "optimal", "for", "32bit", "." ]
[]
[ { "param": "crc", "type": "uint32_t" }, { "param": "s", "type": "unsigned char" }, { "param": "len", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "crc", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b8d3fcbe90ebcea11a7a540499ff44f0089eb04
acronis/pcs-io
libpcs_io/crc32.c
[ "MIT" ]
C
crc_table_init
void
static void crc_table_init(crcfn32 crcfn, uint64_t table[8][256]) { uint64_t crc; int n, k; /* generate CRCs for all single byte sequences */ for (n = 0; n < 256; n++) { unsigned char c = (unsigned char)n; table[0][n] = crcfn(0xFFFFFFFF, &c, 1) ^ 0xFFFFFFFF; } /* generate nested CRC table for future slice-by-8 lookup */ for (n = 0; n < 256; n++) { crc = table[0][n]; for (k = 1; k < 8; k++) { crc = table[0][crc & 0xff] ^ (crc >> 8); table[k][n] = crc; } } /* Transform to the big endian table if needed */ for (k = 0; k < 8; k++) for (n = 0; n < 256; n++) table[k][n] = le64_to_cpu(table[k][n]); }
/* Fill in a CRC constants table. */
Fill in a CRC constants table.
[ "Fill", "in", "a", "CRC", "constants", "table", "." ]
static void crc_table_init(crcfn32 crcfn, uint64_t table[8][256]) { uint64_t crc; int n, k; for (n = 0; n < 256; n++) { unsigned char c = (unsigned char)n; table[0][n] = crcfn(0xFFFFFFFF, &c, 1) ^ 0xFFFFFFFF; } for (n = 0; n < 256; n++) { crc = table[0][n]; for (k = 1; k < 8; k++) { crc = table[0][crc & 0xff] ^ (crc >> 8); table[k][n] = crc; } } for (k = 0; k < 8; k++) for (n = 0; n < 256; n++) table[k][n] = le64_to_cpu(table[k][n]); }
[ "static", "void", "crc_table_init", "(", "crcfn32", "crcfn", ",", "uint64_t", "table", "[", "8", "]", "[", "256", "]", ")", "{", "uint64_t", "crc", ";", "int", "n", ",", "k", ";", "for", "(", "n", "=", "0", ";", "n", "<", "256", ";", "n", "++", ")", "{", "unsigned", "char", "c", "=", "(", "unsigned", "char", ")", "n", ";", "table", "[", "0", "]", "[", "n", "]", "=", "crcfn", "(", "0xFFFFFFFF", ",", "&", "c", ",", "1", ")", "^", "0xFFFFFFFF", ";", "}", "for", "(", "n", "=", "0", ";", "n", "<", "256", ";", "n", "++", ")", "{", "crc", "=", "table", "[", "0", "]", "[", "n", "]", ";", "for", "(", "k", "=", "1", ";", "k", "<", "8", ";", "k", "++", ")", "{", "crc", "=", "table", "[", "0", "]", "[", "crc", "&", "0xff", "]", "^", "(", "crc", ">>", "8", ")", ";", "table", "[", "k", "]", "[", "n", "]", "=", "crc", ";", "}", "}", "for", "(", "k", "=", "0", ";", "k", "<", "8", ";", "k", "++", ")", "for", "(", "n", "=", "0", ";", "n", "<", "256", ";", "n", "++", ")", "table", "[", "k", "]", "[", "n", "]", "=", "le64_to_cpu", "(", "table", "[", "k", "]", "[", "n", "]", ")", ";", "}" ]
Fill in a CRC constants table.
[ "Fill", "in", "a", "CRC", "constants", "table", "." ]
[ "/* generate CRCs for all single byte sequences */", "/* generate nested CRC table for future slice-by-8 lookup */", "/* Transform to the big endian table if needed */" ]
[ { "param": "crcfn", "type": "crcfn32" }, { "param": "table", "type": "uint64_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "crcfn", "type": "crcfn32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "table", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b8d3fcbe90ebcea11a7a540499ff44f0089eb04
acronis/pcs-io
libpcs_io/crc32.c
[ "MIT" ]
C
crcspeed64little
uint64_t
static uint64_t crcspeed64little(uint64_t little_table[8][256], uint64_t crc, void *buf, unsigned int len) { unsigned char *next = buf; /* process individual bytes until we reach an 8-byte aligned pointer */ while (len && ((uintptr_t)next & 7) != 0) { crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); len--; } /* fast middle processing, 8 bytes (aligned!) per loop */ while (len >= 8) { crc ^= *(uint64_t *)next; crc = little_table[7][crc & 0xff] ^ little_table[6][(crc >> 8) & 0xff] ^ little_table[5][(crc >> 16) & 0xff] ^ little_table[4][(crc >> 24) & 0xff] ^ little_table[3][(crc >> 32) & 0xff] ^ little_table[2][(crc >> 40) & 0xff] ^ little_table[1][(crc >> 48) & 0xff] ^ little_table[0][crc >> 56]; next += 8; len -= 8; } /* process remaining bytes (can't be larger than 8) */ while (len) { crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); len--; } return crc; }
/* Calculate a non-inverted CRC multiple bytes at a time on a little-endian * architecture. If you need inverted CRC, invert *before* calling and invert * *after* calling. * 64 bit crc = process 8 bytes at once; */
Calculate a non-inverted CRC multiple bytes at a time on a little-endian architecture. If you need inverted CRC, invert *before* calling and invert *after* calling. 64 bit crc = process 8 bytes at once.
[ "Calculate", "a", "non", "-", "inverted", "CRC", "multiple", "bytes", "at", "a", "time", "on", "a", "little", "-", "endian", "architecture", ".", "If", "you", "need", "inverted", "CRC", "invert", "*", "before", "*", "calling", "and", "invert", "*", "after", "*", "calling", ".", "64", "bit", "crc", "=", "process", "8", "bytes", "at", "once", "." ]
static uint64_t crcspeed64little(uint64_t little_table[8][256], uint64_t crc, void *buf, unsigned int len) { unsigned char *next = buf; while (len && ((uintptr_t)next & 7) != 0) { crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); len--; } while (len >= 8) { crc ^= *(uint64_t *)next; crc = little_table[7][crc & 0xff] ^ little_table[6][(crc >> 8) & 0xff] ^ little_table[5][(crc >> 16) & 0xff] ^ little_table[4][(crc >> 24) & 0xff] ^ little_table[3][(crc >> 32) & 0xff] ^ little_table[2][(crc >> 40) & 0xff] ^ little_table[1][(crc >> 48) & 0xff] ^ little_table[0][crc >> 56]; next += 8; len -= 8; } while (len) { crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); len--; } return crc; }
[ "static", "uint64_t", "crcspeed64little", "(", "uint64_t", "little_table", "[", "8", "]", "[", "256", "]", ",", "uint64_t", "crc", ",", "void", "*", "buf", ",", "unsigned", "int", "len", ")", "{", "unsigned", "char", "*", "next", "=", "buf", ";", "while", "(", "len", "&&", "(", "(", "uintptr_t", ")", "next", "&", "7", ")", "!=", "0", ")", "{", "crc", "=", "little_table", "[", "0", "]", "[", "(", "crc", "^", "*", "next", "++", ")", "&", "0xff", "]", "^", "(", "crc", ">>", "8", ")", ";", "len", "--", ";", "}", "while", "(", "len", ">=", "8", ")", "{", "crc", "^=", "*", "(", "uint64_t", "*", ")", "next", ";", "crc", "=", "little_table", "[", "7", "]", "[", "crc", "&", "0xff", "]", "^", "little_table", "[", "6", "]", "[", "(", "crc", ">>", "8", ")", "&", "0xff", "]", "^", "little_table", "[", "5", "]", "[", "(", "crc", ">>", "16", ")", "&", "0xff", "]", "^", "little_table", "[", "4", "]", "[", "(", "crc", ">>", "24", ")", "&", "0xff", "]", "^", "little_table", "[", "3", "]", "[", "(", "crc", ">>", "32", ")", "&", "0xff", "]", "^", "little_table", "[", "2", "]", "[", "(", "crc", ">>", "40", ")", "&", "0xff", "]", "^", "little_table", "[", "1", "]", "[", "(", "crc", ">>", "48", ")", "&", "0xff", "]", "^", "little_table", "[", "0", "]", "[", "crc", ">>", "56", "]", ";", "next", "+=", "8", ";", "len", "-=", "8", ";", "}", "while", "(", "len", ")", "{", "crc", "=", "little_table", "[", "0", "]", "[", "(", "crc", "^", "*", "next", "++", ")", "&", "0xff", "]", "^", "(", "crc", ">>", "8", ")", ";", "len", "--", ";", "}", "return", "crc", ";", "}" ]
Calculate a non-inverted CRC multiple bytes at a time on a little-endian architecture.
[ "Calculate", "a", "non", "-", "inverted", "CRC", "multiple", "bytes", "at", "a", "time", "on", "a", "little", "-", "endian", "architecture", "." ]
[ "/* process individual bytes until we reach an 8-byte aligned pointer */", "/* fast middle processing, 8 bytes (aligned!) per loop */", "/* process remaining bytes (can't be larger than 8) */" ]
[ { "param": "little_table", "type": "uint64_t" }, { "param": "crc", "type": "uint64_t" }, { "param": "buf", "type": "void" }, { "param": "len", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "little_table", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "crc", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b8d3fcbe90ebcea11a7a540499ff44f0089eb04
acronis/pcs-io
libpcs_io/crc32.c
[ "MIT" ]
C
crcspeed64big
uint64_t
static uint64_t crcspeed64big(uint64_t big_table[8][256], uint64_t crc, void *buf, unsigned int len) { unsigned char *next = buf; crc = cpu_to_le64(crc); while (len && ((uintptr_t)next & 7) != 0) { crc = big_table[0][(crc >> 56) ^ *next++] ^ (crc << 8); len--; } while (len >= 8) { crc ^= *(uint64_t *)next; crc = big_table[0][crc & 0xff] ^ big_table[1][(crc >> 8) & 0xff] ^ big_table[2][(crc >> 16) & 0xff] ^ big_table[3][(crc >> 24) & 0xff] ^ big_table[4][(crc >> 32) & 0xff] ^ big_table[5][(crc >> 40) & 0xff] ^ big_table[6][(crc >> 48) & 0xff] ^ big_table[7][crc >> 56]; next += 8; len -= 8; } while (len) { crc = big_table[0][(crc >> 56) ^ *next++] ^ (crc << 8); len--; } crc = cpu_to_le64(crc); return crc; }
/* Calculate a non-inverted CRC eight bytes at a time on a big-endian * architecture. */
Calculate a non-inverted CRC eight bytes at a time on a big-endian architecture.
[ "Calculate", "a", "non", "-", "inverted", "CRC", "eight", "bytes", "at", "a", "time", "on", "a", "big", "-", "endian", "architecture", "." ]
static uint64_t crcspeed64big(uint64_t big_table[8][256], uint64_t crc, void *buf, unsigned int len) { unsigned char *next = buf; crc = cpu_to_le64(crc); while (len && ((uintptr_t)next & 7) != 0) { crc = big_table[0][(crc >> 56) ^ *next++] ^ (crc << 8); len--; } while (len >= 8) { crc ^= *(uint64_t *)next; crc = big_table[0][crc & 0xff] ^ big_table[1][(crc >> 8) & 0xff] ^ big_table[2][(crc >> 16) & 0xff] ^ big_table[3][(crc >> 24) & 0xff] ^ big_table[4][(crc >> 32) & 0xff] ^ big_table[5][(crc >> 40) & 0xff] ^ big_table[6][(crc >> 48) & 0xff] ^ big_table[7][crc >> 56]; next += 8; len -= 8; } while (len) { crc = big_table[0][(crc >> 56) ^ *next++] ^ (crc << 8); len--; } crc = cpu_to_le64(crc); return crc; }
[ "static", "uint64_t", "crcspeed64big", "(", "uint64_t", "big_table", "[", "8", "]", "[", "256", "]", ",", "uint64_t", "crc", ",", "void", "*", "buf", ",", "unsigned", "int", "len", ")", "{", "unsigned", "char", "*", "next", "=", "buf", ";", "crc", "=", "cpu_to_le64", "(", "crc", ")", ";", "while", "(", "len", "&&", "(", "(", "uintptr_t", ")", "next", "&", "7", ")", "!=", "0", ")", "{", "crc", "=", "big_table", "[", "0", "]", "[", "(", "crc", ">>", "56", ")", "^", "*", "next", "++", "]", "^", "(", "crc", "<<", "8", ")", ";", "len", "--", ";", "}", "while", "(", "len", ">=", "8", ")", "{", "crc", "^=", "*", "(", "uint64_t", "*", ")", "next", ";", "crc", "=", "big_table", "[", "0", "]", "[", "crc", "&", "0xff", "]", "^", "big_table", "[", "1", "]", "[", "(", "crc", ">>", "8", ")", "&", "0xff", "]", "^", "big_table", "[", "2", "]", "[", "(", "crc", ">>", "16", ")", "&", "0xff", "]", "^", "big_table", "[", "3", "]", "[", "(", "crc", ">>", "24", ")", "&", "0xff", "]", "^", "big_table", "[", "4", "]", "[", "(", "crc", ">>", "32", ")", "&", "0xff", "]", "^", "big_table", "[", "5", "]", "[", "(", "crc", ">>", "40", ")", "&", "0xff", "]", "^", "big_table", "[", "6", "]", "[", "(", "crc", ">>", "48", ")", "&", "0xff", "]", "^", "big_table", "[", "7", "]", "[", "crc", ">>", "56", "]", ";", "next", "+=", "8", ";", "len", "-=", "8", ";", "}", "while", "(", "len", ")", "{", "crc", "=", "big_table", "[", "0", "]", "[", "(", "crc", ">>", "56", ")", "^", "*", "next", "++", "]", "^", "(", "crc", "<<", "8", ")", ";", "len", "--", ";", "}", "crc", "=", "cpu_to_le64", "(", "crc", ")", ";", "return", "crc", ";", "}" ]
Calculate a non-inverted CRC eight bytes at a time on a big-endian architecture.
[ "Calculate", "a", "non", "-", "inverted", "CRC", "eight", "bytes", "at", "a", "time", "on", "a", "big", "-", "endian", "architecture", "." ]
[]
[ { "param": "big_table", "type": "uint64_t" }, { "param": "crc", "type": "uint64_t" }, { "param": "buf", "type": "void" }, { "param": "len", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "big_table", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "crc", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b8d3fcbe90ebcea11a7a540499ff44f0089eb04
acronis/pcs-io
libpcs_io/crc32.c
[ "MIT" ]
C
crc32_64bit
uint32_t
static uint32_t crc32_64bit(uint32_t crc, const void *buf, unsigned int len) { if (!crc32_table_initialized) crc32_init(); crc ^= 0xFFFFFFFF; crc = pcs_cpu_little_endian() ? (uint32_t)crcspeed64little(crc64_table, crc, (void *)buf, len) : (uint32_t)crcspeed64big(crc64_table, crc, (void *)buf, len); return crc ^ 0xFFFFFFFF; }
/* 64bit version and table init are done similar to crc64.c */
64bit version and table init are done similar to crc64.c
[ "64bit", "version", "and", "table", "init", "are", "done", "similar", "to", "crc64", ".", "c" ]
static uint32_t crc32_64bit(uint32_t crc, const void *buf, unsigned int len) { if (!crc32_table_initialized) crc32_init(); crc ^= 0xFFFFFFFF; crc = pcs_cpu_little_endian() ? (uint32_t)crcspeed64little(crc64_table, crc, (void *)buf, len) : (uint32_t)crcspeed64big(crc64_table, crc, (void *)buf, len); return crc ^ 0xFFFFFFFF; }
[ "static", "uint32_t", "crc32_64bit", "(", "uint32_t", "crc", ",", "const", "void", "*", "buf", ",", "unsigned", "int", "len", ")", "{", "if", "(", "!", "crc32_table_initialized", ")", "crc32_init", "(", ")", ";", "crc", "^=", "0xFFFFFFFF", ";", "crc", "=", "pcs_cpu_little_endian", "(", ")", "?", "(", "uint32_t", ")", "crcspeed64little", "(", "crc64_table", ",", "crc", ",", "(", "void", "*", ")", "buf", ",", "len", ")", ":", "(", "uint32_t", ")", "crcspeed64big", "(", "crc64_table", ",", "crc", ",", "(", "void", "*", ")", "buf", ",", "len", ")", ";", "return", "crc", "^", "0xFFFFFFFF", ";", "}" ]
64bit version and table init are done similar to crc64.c
[ "64bit", "version", "and", "table", "init", "are", "done", "similar", "to", "crc64", ".", "c" ]
[]
[ { "param": "crc", "type": "uint32_t" }, { "param": "buf", "type": "void" }, { "param": "len", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "crc", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fc74f9c0e86b6c4b0131c03f1a16c2b38676f854
acronis/pcs-io
libpcs_io/pcs_rdma_io.c
[ "MIT" ]
C
rio_get_comp
int
static int rio_get_comp(struct pcs_rdmaio *rio, struct ibv_wc *wc) { struct ibv_cq *cq = rio->cq; void *ctx; int ret; for (;;) { ret = rio_poll_cq(cq, wc); if (ret) { if (ret < 0) pcs_log_errno("rio_get_comp", "ibv_poll_cq"); break; } ret = ibv_req_notify_cq(cq, 0); if (ret) { pcs_log_errno("rio_get_comp", "ibv_req_notify_cq"); break; } ret = rio_poll_cq(cq, wc); if (ret) { if (ret < 0) pcs_log_errno("rio_get_comp", "ibv_poll_cq"); break; } ret = ibv_get_cq_event(rio->cc, &cq, &ctx); if (ret) { if (errno == EAGAIN) ret = 0; else pcs_log_errno("rio_get_comp", "ibv_get_cq_event"); break; } BUG_ON(cq != rio->cq); ibv_ack_cq_events(cq, 1); } return ret; }
/* * Loop until either got a work completion or explicit EAGAIN. * See rdma-core/librdmacm/rdma_verbs.h::rdma_get_recv_comp() */
Loop until either got a work completion or explicit EAGAIN.
[ "Loop", "until", "either", "got", "a", "work", "completion", "or", "explicit", "EAGAIN", "." ]
static int rio_get_comp(struct pcs_rdmaio *rio, struct ibv_wc *wc) { struct ibv_cq *cq = rio->cq; void *ctx; int ret; for (;;) { ret = rio_poll_cq(cq, wc); if (ret) { if (ret < 0) pcs_log_errno("rio_get_comp", "ibv_poll_cq"); break; } ret = ibv_req_notify_cq(cq, 0); if (ret) { pcs_log_errno("rio_get_comp", "ibv_req_notify_cq"); break; } ret = rio_poll_cq(cq, wc); if (ret) { if (ret < 0) pcs_log_errno("rio_get_comp", "ibv_poll_cq"); break; } ret = ibv_get_cq_event(rio->cc, &cq, &ctx); if (ret) { if (errno == EAGAIN) ret = 0; else pcs_log_errno("rio_get_comp", "ibv_get_cq_event"); break; } BUG_ON(cq != rio->cq); ibv_ack_cq_events(cq, 1); } return ret; }
[ "static", "int", "rio_get_comp", "(", "struct", "pcs_rdmaio", "*", "rio", ",", "struct", "ibv_wc", "*", "wc", ")", "{", "struct", "ibv_cq", "*", "cq", "=", "rio", "->", "cq", ";", "void", "*", "ctx", ";", "int", "ret", ";", "for", "(", ";", ";", ")", "{", "ret", "=", "rio_poll_cq", "(", "cq", ",", "wc", ")", ";", "if", "(", "ret", ")", "{", "if", "(", "ret", "<", "0", ")", "pcs_log_errno", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "break", ";", "}", "ret", "=", "ibv_req_notify_cq", "(", "cq", ",", "0", ")", ";", "if", "(", "ret", ")", "{", "pcs_log_errno", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "break", ";", "}", "ret", "=", "rio_poll_cq", "(", "cq", ",", "wc", ")", ";", "if", "(", "ret", ")", "{", "if", "(", "ret", "<", "0", ")", "pcs_log_errno", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "break", ";", "}", "ret", "=", "ibv_get_cq_event", "(", "rio", "->", "cc", ",", "&", "cq", ",", "&", "ctx", ")", ";", "if", "(", "ret", ")", "{", "if", "(", "errno", "==", "EAGAIN", ")", "ret", "=", "0", ";", "else", "pcs_log_errno", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "break", ";", "}", "BUG_ON", "(", "cq", "!=", "rio", "->", "cq", ")", ";", "ibv_ack_cq_events", "(", "cq", ",", "1", ")", ";", "}", "return", "ret", ";", "}" ]
Loop until either got a work completion or explicit EAGAIN.
[ "Loop", "until", "either", "got", "a", "work", "completion", "or", "explicit", "EAGAIN", "." ]
[]
[ { "param": "rio", "type": "struct pcs_rdmaio" }, { "param": "wc", "type": "struct ibv_wc" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "rio", "type": "struct pcs_rdmaio", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wc", "type": "struct ibv_wc", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fc74f9c0e86b6c4b0131c03f1a16c2b38676f854
acronis/pcs-io
libpcs_io/pcs_rdma_io.c
[ "MIT" ]
C
rio_handle_errored
void
static void rio_handle_errored(struct pcs_rdmaio *rio) { if (rio->n_rx_posted + rio->n_tx_posted == 0) pcs_ioconn_unregister(&rio->compc); }
/* * A helper to be called on RX/TX completion when rio->errored */
A helper to be called on RX/TX completion when rio->errored
[ "A", "helper", "to", "be", "called", "on", "RX", "/", "TX", "completion", "when", "rio", "-", ">", "errored" ]
static void rio_handle_errored(struct pcs_rdmaio *rio) { if (rio->n_rx_posted + rio->n_tx_posted == 0) pcs_ioconn_unregister(&rio->compc); }
[ "static", "void", "rio_handle_errored", "(", "struct", "pcs_rdmaio", "*", "rio", ")", "{", "if", "(", "rio", "->", "n_rx_posted", "+", "rio", "->", "n_tx_posted", "==", "0", ")", "pcs_ioconn_unregister", "(", "&", "rio", "->", "compc", ")", ";", "}" ]
A helper to be called on RX/TX completion when rio->errored
[ "A", "helper", "to", "be", "called", "on", "RX", "/", "TX", "completion", "when", "rio", "-", ">", "errored" ]
[]
[ { "param": "rio", "type": "struct pcs_rdmaio" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "rio", "type": "struct pcs_rdmaio", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fc74f9c0e86b6c4b0131c03f1a16c2b38676f854
acronis/pcs-io
libpcs_io/pcs_rdma_io.c
[ "MIT" ]
C
rio_handle_rx_immediate
int
static int rio_handle_rx_immediate(struct pcs_rdmaio *rio, char *buf, int len, struct pcs_remote_buf *rb, int *throttle, struct pcs_rdma_desc *rd) { struct pcs_msg *msg; int offset = rio->hdr_size; if (len < rio->hdr_size) { pcs_log(LOG_ERR, "rio read short msg: %d < %d", len, rio->hdr_size); return PCS_ERR_NET_ABORT; } msg = rio->netio.getmsg(&rio->netio, buf); if (msg == NULL) { int err = 0; if (rio->throttled) *throttle = 1; else err = PCS_ERR_NOMEM; return err; } if (msg->size != len + (rb ? rb->rlen : 0)) { pcs_log(LOG_ERR, "rio read wrong len: %d != %d (%lx/%x/%d)", len, msg->size, rb ? rb->rbuf : 0, rb ? rb->rkey : 0, rb ? rb->rlen : -1); pcs_free_msg(msg); return PCS_ERR_NET_ABORT; } while (offset < len) { int body_len = 0; void *body = msg->get_chunk(msg, offset, &body_len); /* Yeah... mr_buf is useless if payload is sent w/o RDMA */ unwind_mr_buf(&body, &body_len); if (body_len > len - offset) body_len = len - offset; memcpy(body, buf + offset, body_len); offset += body_len; } if (len == msg->size) msg->done(msg); else rdma_desc_build(rio, msg, offset, rb, rd); return 0; }
/* * rio wire header is already stripped, buf points to payload data (pcs_rpc hdr) */
rio wire header is already stripped, buf points to payload data (pcs_rpc hdr)
[ "rio", "wire", "header", "is", "already", "stripped", "buf", "points", "to", "payload", "data", "(", "pcs_rpc", "hdr", ")" ]
static int rio_handle_rx_immediate(struct pcs_rdmaio *rio, char *buf, int len, struct pcs_remote_buf *rb, int *throttle, struct pcs_rdma_desc *rd) { struct pcs_msg *msg; int offset = rio->hdr_size; if (len < rio->hdr_size) { pcs_log(LOG_ERR, "rio read short msg: %d < %d", len, rio->hdr_size); return PCS_ERR_NET_ABORT; } msg = rio->netio.getmsg(&rio->netio, buf); if (msg == NULL) { int err = 0; if (rio->throttled) *throttle = 1; else err = PCS_ERR_NOMEM; return err; } if (msg->size != len + (rb ? rb->rlen : 0)) { pcs_log(LOG_ERR, "rio read wrong len: %d != %d (%lx/%x/%d)", len, msg->size, rb ? rb->rbuf : 0, rb ? rb->rkey : 0, rb ? rb->rlen : -1); pcs_free_msg(msg); return PCS_ERR_NET_ABORT; } while (offset < len) { int body_len = 0; void *body = msg->get_chunk(msg, offset, &body_len); unwind_mr_buf(&body, &body_len); if (body_len > len - offset) body_len = len - offset; memcpy(body, buf + offset, body_len); offset += body_len; } if (len == msg->size) msg->done(msg); else rdma_desc_build(rio, msg, offset, rb, rd); return 0; }
[ "static", "int", "rio_handle_rx_immediate", "(", "struct", "pcs_rdmaio", "*", "rio", ",", "char", "*", "buf", ",", "int", "len", ",", "struct", "pcs_remote_buf", "*", "rb", ",", "int", "*", "throttle", ",", "struct", "pcs_rdma_desc", "*", "rd", ")", "{", "struct", "pcs_msg", "*", "msg", ";", "int", "offset", "=", "rio", "->", "hdr_size", ";", "if", "(", "len", "<", "rio", "->", "hdr_size", ")", "{", "pcs_log", "(", "LOG_ERR", ",", "\"", "\"", ",", "len", ",", "rio", "->", "hdr_size", ")", ";", "return", "PCS_ERR_NET_ABORT", ";", "}", "msg", "=", "rio", "->", "netio", ".", "getmsg", "(", "&", "rio", "->", "netio", ",", "buf", ")", ";", "if", "(", "msg", "==", "NULL", ")", "{", "int", "err", "=", "0", ";", "if", "(", "rio", "->", "throttled", ")", "*", "throttle", "=", "1", ";", "else", "err", "=", "PCS_ERR_NOMEM", ";", "return", "err", ";", "}", "if", "(", "msg", "->", "size", "!=", "len", "+", "(", "rb", "?", "rb", "->", "rlen", ":", "0", ")", ")", "{", "pcs_log", "(", "LOG_ERR", ",", "\"", "\"", ",", "len", ",", "msg", "->", "size", ",", "rb", "?", "rb", "->", "rbuf", ":", "0", ",", "rb", "?", "rb", "->", "rkey", ":", "0", ",", "rb", "?", "rb", "->", "rlen", ":", "-1", ")", ";", "pcs_free_msg", "(", "msg", ")", ";", "return", "PCS_ERR_NET_ABORT", ";", "}", "while", "(", "offset", "<", "len", ")", "{", "int", "body_len", "=", "0", ";", "void", "*", "body", "=", "msg", "->", "get_chunk", "(", "msg", ",", "offset", ",", "&", "body_len", ")", ";", "unwind_mr_buf", "(", "&", "body", ",", "&", "body_len", ")", ";", "if", "(", "body_len", ">", "len", "-", "offset", ")", "body_len", "=", "len", "-", "offset", ";", "memcpy", "(", "body", ",", "buf", "+", "offset", ",", "body_len", ")", ";", "offset", "+=", "body_len", ";", "}", "if", "(", "len", "==", "msg", "->", "size", ")", "msg", "->", "done", "(", "msg", ")", ";", "else", "rdma_desc_build", "(", "rio", ",", "msg", ",", "offset", ",", "rb", ",", "rd", ")", ";", "return", "0", ";", "}" ]
rio wire header is already stripped, buf points to payload data (pcs_rpc hdr)
[ "rio", "wire", "header", "is", "already", "stripped", "buf", "points", "to", "payload", "data", "(", "pcs_rpc", "hdr", ")" ]
[ "/* Yeah... mr_buf is useless if payload is sent w/o RDMA */" ]
[ { "param": "rio", "type": "struct pcs_rdmaio" }, { "param": "buf", "type": "char" }, { "param": "len", "type": "int" }, { "param": "rb", "type": "struct pcs_remote_buf" }, { "param": "throttle", "type": "int" }, { "param": "rd", "type": "struct pcs_rdma_desc" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "rio", "type": "struct pcs_rdmaio", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rb", "type": "struct pcs_remote_buf", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "throttle", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rd", "type": "struct pcs_rdma_desc", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }