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
04f6b76c245c7ae18726823c036ec9cb01bb9ad6
ParticleBeamHQ/zephyr
drivers/modem/modem_cmd_handler.c
[ "Apache-2.0" ]
C
find_cmd_match
null
static const struct modem_cmd *find_cmd_match( struct modem_cmd_handler_data *data) { int j; size_t i; for (j = 0; j < ARRAY_SIZE(data->cmds); j++) { if (!data->cmds[j] || data->cmds_len[j] == 0U) { continue; } for (i = 0; i < data->cmds_len[j]; i++) { /* match on "empty" cmd */ if (strlen(data->cmds[j][i].cmd) == 0 || strncmp(data->match_buf, data->cmds[j][i].cmd, data->cmds[j][i].cmd_len) == 0) { return &data->cmds[j][i]; } } } return NULL; }
/* * check 3 arrays of commands for a match in match_buf: * - response handlers[0] * - unsolicited handlers[1] * - current assigned handlers[2] */
check 3 arrays of commands for a match in match_buf: - response handlers[0] - unsolicited handlers[1] - current assigned handlers[2]
[ "check", "3", "arrays", "of", "commands", "for", "a", "match", "in", "match_buf", ":", "-", "response", "handlers", "[", "0", "]", "-", "unsolicited", "handlers", "[", "1", "]", "-", "current", "assigned", "handlers", "[", "2", "]" ]
static const struct modem_cmd *find_cmd_match( struct modem_cmd_handler_data *data) { int j; size_t i; for (j = 0; j < ARRAY_SIZE(data->cmds); j++) { if (!data->cmds[j] || data->cmds_len[j] == 0U) { continue; } for (i = 0; i < data->cmds_len[j]; i++) { if (strlen(data->cmds[j][i].cmd) == 0 || strncmp(data->match_buf, data->cmds[j][i].cmd, data->cmds[j][i].cmd_len) == 0) { return &data->cmds[j][i]; } } } return NULL; }
[ "static", "const", "struct", "modem_cmd", "*", "find_cmd_match", "(", "struct", "modem_cmd_handler_data", "*", "data", ")", "{", "int", "j", ";", "size_t", "i", ";", "for", "(", "j", "=", "0", ";", "j", "<", "ARRAY_SIZE", "(", "data", "->", "cmds", ")", ";", "j", "++", ")", "{", "if", "(", "!", "data", "->", "cmds", "[", "j", "]", "||", "data", "->", "cmds_len", "[", "j", "]", "==", "0U", ")", "{", "continue", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "data", "->", "cmds_len", "[", "j", "]", ";", "i", "++", ")", "{", "if", "(", "strlen", "(", "data", "->", "cmds", "[", "j", "]", "[", "i", "]", ".", "cmd", ")", "==", "0", "||", "strncmp", "(", "data", "->", "match_buf", ",", "data", "->", "cmds", "[", "j", "]", "[", "i", "]", ".", "cmd", ",", "data", "->", "cmds", "[", "j", "]", "[", "i", "]", ".", "cmd_len", ")", "==", "0", ")", "{", "return", "&", "data", "->", "cmds", "[", "j", "]", "[", "i", "]", ";", "}", "}", "}", "return", "NULL", ";", "}" ]
check 3 arrays of commands for a match in match_buf: - response handlers[0] - unsolicited handlers[1] - current assigned handlers[2]
[ "check", "3", "arrays", "of", "commands", "for", "a", "match", "in", "match_buf", ":", "-", "response", "handlers", "[", "0", "]", "-", "unsolicited", "handlers", "[", "1", "]", "-", "current", "assigned", "handlers", "[", "2", "]" ]
[ "/* match on \"empty\" cmd */" ]
[ { "param": "data", "type": "struct modem_cmd_handler_data" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "struct modem_cmd_handler_data", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
04f6b76c245c7ae18726823c036ec9cb01bb9ad6
ParticleBeamHQ/zephyr
drivers/modem/modem_cmd_handler.c
[ "Apache-2.0" ]
C
modem_cmd_handler_setup_cmds
int
int modem_cmd_handler_setup_cmds(struct modem_iface *iface, struct modem_cmd_handler *handler, const struct setup_cmd *cmds, size_t cmds_len, struct k_sem *sem, k_timeout_t timeout) { int ret = 0; size_t i; for (i = 0; i < cmds_len; i++) { if (i) { k_sleep(K_MSEC(50)); } if (cmds[i].handle_cmd.cmd && cmds[i].handle_cmd.func) { ret = modem_cmd_send(iface, handler, &cmds[i].handle_cmd, 1U, cmds[i].send_cmd, sem, timeout); } else { ret = modem_cmd_send(iface, handler, NULL, 0, cmds[i].send_cmd, sem, timeout); } if (ret < 0) { LOG_ERR("command %s ret:%d", log_strdup(cmds[i].send_cmd), ret); break; } } return ret; }
/* run a set of AT commands */
run a set of AT commands
[ "run", "a", "set", "of", "AT", "commands" ]
int modem_cmd_handler_setup_cmds(struct modem_iface *iface, struct modem_cmd_handler *handler, const struct setup_cmd *cmds, size_t cmds_len, struct k_sem *sem, k_timeout_t timeout) { int ret = 0; size_t i; for (i = 0; i < cmds_len; i++) { if (i) { k_sleep(K_MSEC(50)); } if (cmds[i].handle_cmd.cmd && cmds[i].handle_cmd.func) { ret = modem_cmd_send(iface, handler, &cmds[i].handle_cmd, 1U, cmds[i].send_cmd, sem, timeout); } else { ret = modem_cmd_send(iface, handler, NULL, 0, cmds[i].send_cmd, sem, timeout); } if (ret < 0) { LOG_ERR("command %s ret:%d", log_strdup(cmds[i].send_cmd), ret); break; } } return ret; }
[ "int", "modem_cmd_handler_setup_cmds", "(", "struct", "modem_iface", "*", "iface", ",", "struct", "modem_cmd_handler", "*", "handler", ",", "const", "struct", "setup_cmd", "*", "cmds", ",", "size_t", "cmds_len", ",", "struct", "k_sem", "*", "sem", ",", "k_timeout_t", "timeout", ")", "{", "int", "ret", "=", "0", ";", "size_t", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "cmds_len", ";", "i", "++", ")", "{", "if", "(", "i", ")", "{", "k_sleep", "(", "K_MSEC", "(", "50", ")", ")", ";", "}", "if", "(", "cmds", "[", "i", "]", ".", "handle_cmd", ".", "cmd", "&&", "cmds", "[", "i", "]", ".", "handle_cmd", ".", "func", ")", "{", "ret", "=", "modem_cmd_send", "(", "iface", ",", "handler", ",", "&", "cmds", "[", "i", "]", ".", "handle_cmd", ",", "1U", ",", "cmds", "[", "i", "]", ".", "send_cmd", ",", "sem", ",", "timeout", ")", ";", "}", "else", "{", "ret", "=", "modem_cmd_send", "(", "iface", ",", "handler", ",", "NULL", ",", "0", ",", "cmds", "[", "i", "]", ".", "send_cmd", ",", "sem", ",", "timeout", ")", ";", "}", "if", "(", "ret", "<", "0", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "log_strdup", "(", "cmds", "[", "i", "]", ".", "send_cmd", ")", ",", "ret", ")", ";", "break", ";", "}", "}", "return", "ret", ";", "}" ]
run a set of AT commands
[ "run", "a", "set", "of", "AT", "commands" ]
[]
[ { "param": "iface", "type": "struct modem_iface" }, { "param": "handler", "type": "struct modem_cmd_handler" }, { "param": "cmds", "type": "struct setup_cmd" }, { "param": "cmds_len", "type": "size_t" }, { "param": "sem", "type": "struct k_sem" }, { "param": "timeout", "type": "k_timeout_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "iface", "type": "struct modem_iface", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "handler", "type": "struct modem_cmd_handler", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cmds", "type": "struct setup_cmd", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cmds_len", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sem", "type": "struct k_sem", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "timeout", "type": "k_timeout_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
04f6b76c245c7ae18726823c036ec9cb01bb9ad6
ParticleBeamHQ/zephyr
drivers/modem/modem_cmd_handler.c
[ "Apache-2.0" ]
C
modem_cmd_handler_setup_cmds_nolock
int
int modem_cmd_handler_setup_cmds_nolock(struct modem_iface *iface, struct modem_cmd_handler *handler, const struct setup_cmd *cmds, size_t cmds_len, struct k_sem *sem, k_timeout_t timeout) { int ret = 0; size_t i; for (i = 0; i < cmds_len; i++) { if (i) { k_sleep(K_MSEC(50)); } if (cmds[i].handle_cmd.cmd && cmds[i].handle_cmd.func) { ret = modem_cmd_send_nolock(iface, handler, &cmds[i].handle_cmd, 1U, cmds[i].send_cmd, sem, timeout); } else { ret = modem_cmd_send_nolock(iface, handler, NULL, 0, cmds[i].send_cmd, sem, timeout); } if (ret < 0) { LOG_ERR("command %s ret:%d", log_strdup(cmds[i].send_cmd), ret); break; } } return ret; }
/* run a set of AT commands, without lock */
run a set of AT commands, without lock
[ "run", "a", "set", "of", "AT", "commands", "without", "lock" ]
int modem_cmd_handler_setup_cmds_nolock(struct modem_iface *iface, struct modem_cmd_handler *handler, const struct setup_cmd *cmds, size_t cmds_len, struct k_sem *sem, k_timeout_t timeout) { int ret = 0; size_t i; for (i = 0; i < cmds_len; i++) { if (i) { k_sleep(K_MSEC(50)); } if (cmds[i].handle_cmd.cmd && cmds[i].handle_cmd.func) { ret = modem_cmd_send_nolock(iface, handler, &cmds[i].handle_cmd, 1U, cmds[i].send_cmd, sem, timeout); } else { ret = modem_cmd_send_nolock(iface, handler, NULL, 0, cmds[i].send_cmd, sem, timeout); } if (ret < 0) { LOG_ERR("command %s ret:%d", log_strdup(cmds[i].send_cmd), ret); break; } } return ret; }
[ "int", "modem_cmd_handler_setup_cmds_nolock", "(", "struct", "modem_iface", "*", "iface", ",", "struct", "modem_cmd_handler", "*", "handler", ",", "const", "struct", "setup_cmd", "*", "cmds", ",", "size_t", "cmds_len", ",", "struct", "k_sem", "*", "sem", ",", "k_timeout_t", "timeout", ")", "{", "int", "ret", "=", "0", ";", "size_t", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "cmds_len", ";", "i", "++", ")", "{", "if", "(", "i", ")", "{", "k_sleep", "(", "K_MSEC", "(", "50", ")", ")", ";", "}", "if", "(", "cmds", "[", "i", "]", ".", "handle_cmd", ".", "cmd", "&&", "cmds", "[", "i", "]", ".", "handle_cmd", ".", "func", ")", "{", "ret", "=", "modem_cmd_send_nolock", "(", "iface", ",", "handler", ",", "&", "cmds", "[", "i", "]", ".", "handle_cmd", ",", "1U", ",", "cmds", "[", "i", "]", ".", "send_cmd", ",", "sem", ",", "timeout", ")", ";", "}", "else", "{", "ret", "=", "modem_cmd_send_nolock", "(", "iface", ",", "handler", ",", "NULL", ",", "0", ",", "cmds", "[", "i", "]", ".", "send_cmd", ",", "sem", ",", "timeout", ")", ";", "}", "if", "(", "ret", "<", "0", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "log_strdup", "(", "cmds", "[", "i", "]", ".", "send_cmd", ")", ",", "ret", ")", ";", "break", ";", "}", "}", "return", "ret", ";", "}" ]
run a set of AT commands, without lock
[ "run", "a", "set", "of", "AT", "commands", "without", "lock" ]
[]
[ { "param": "iface", "type": "struct modem_iface" }, { "param": "handler", "type": "struct modem_cmd_handler" }, { "param": "cmds", "type": "struct setup_cmd" }, { "param": "cmds_len", "type": "size_t" }, { "param": "sem", "type": "struct k_sem" }, { "param": "timeout", "type": "k_timeout_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "iface", "type": "struct modem_iface", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "handler", "type": "struct modem_cmd_handler", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cmds", "type": "struct setup_cmd", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cmds_len", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sem", "type": "struct k_sem", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "timeout", "type": "k_timeout_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0457b5193c9633780172170065c9ab05cf4f249d
ParticleBeamHQ/zephyr
samples/boards/stm32/usbc/sink/src/usbc_snk.c
[ "Apache-2.0" ]
C
sink_power_sub_states
void
static void sink_power_sub_states(void) { enum tc_cc_voltage_state cc; enum tc_cc_voltage_state new_cc_voltage; char const *pwr; cc = tc.cc_polarity ? tc.cc2 : tc.cc1; if (cc == TC_CC_VOLT_RP_DEF) { new_cc_voltage = TC_CC_VOLT_RP_DEF; pwr = pwr2_5_str; } else if (cc == TC_CC_VOLT_RP_1A5) { new_cc_voltage = TC_CC_VOLT_RP_1A5; pwr = pwr7_5_str; } else if (cc == TC_CC_VOLT_RP_3A0) { new_cc_voltage = TC_CC_VOLT_RP_3A0; pwr = pwr15_str; } else { new_cc_voltage = TC_CC_VOLT_OPEN; pwr = pwr_open_str; } /* Debounce the cc state */ if (new_cc_voltage != tc.cc_voltage) { tc.cc_voltage = new_cc_voltage; tc.cc_debounce = T_RP_VALUE_CHANGE; } else if (tc.cc_debounce) { /* Update timer */ tc.cc_debounce--; } }
/** * @brief Sink power sub states. Only called if a PD contract is ot in place */
@brief Sink power sub states. Only called if a PD contract is ot in place
[ "@brief", "Sink", "power", "sub", "states", ".", "Only", "called", "if", "a", "PD", "contract", "is", "ot", "in", "place" ]
static void sink_power_sub_states(void) { enum tc_cc_voltage_state cc; enum tc_cc_voltage_state new_cc_voltage; char const *pwr; cc = tc.cc_polarity ? tc.cc2 : tc.cc1; if (cc == TC_CC_VOLT_RP_DEF) { new_cc_voltage = TC_CC_VOLT_RP_DEF; pwr = pwr2_5_str; } else if (cc == TC_CC_VOLT_RP_1A5) { new_cc_voltage = TC_CC_VOLT_RP_1A5; pwr = pwr7_5_str; } else if (cc == TC_CC_VOLT_RP_3A0) { new_cc_voltage = TC_CC_VOLT_RP_3A0; pwr = pwr15_str; } else { new_cc_voltage = TC_CC_VOLT_OPEN; pwr = pwr_open_str; } if (new_cc_voltage != tc.cc_voltage) { tc.cc_voltage = new_cc_voltage; tc.cc_debounce = T_RP_VALUE_CHANGE; } else if (tc.cc_debounce) { tc.cc_debounce--; } }
[ "static", "void", "sink_power_sub_states", "(", "void", ")", "{", "enum", "tc_cc_voltage_state", "cc", ";", "enum", "tc_cc_voltage_state", "new_cc_voltage", ";", "char", "const", "*", "pwr", ";", "cc", "=", "tc", ".", "cc_polarity", "?", "tc", ".", "cc2", ":", "tc", ".", "cc1", ";", "if", "(", "cc", "==", "TC_CC_VOLT_RP_DEF", ")", "{", "new_cc_voltage", "=", "TC_CC_VOLT_RP_DEF", ";", "pwr", "=", "pwr2_5_str", ";", "}", "else", "if", "(", "cc", "==", "TC_CC_VOLT_RP_1A5", ")", "{", "new_cc_voltage", "=", "TC_CC_VOLT_RP_1A5", ";", "pwr", "=", "pwr7_5_str", ";", "}", "else", "if", "(", "cc", "==", "TC_CC_VOLT_RP_3A0", ")", "{", "new_cc_voltage", "=", "TC_CC_VOLT_RP_3A0", ";", "pwr", "=", "pwr15_str", ";", "}", "else", "{", "new_cc_voltage", "=", "TC_CC_VOLT_OPEN", ";", "pwr", "=", "pwr_open_str", ";", "}", "if", "(", "new_cc_voltage", "!=", "tc", ".", "cc_voltage", ")", "{", "tc", ".", "cc_voltage", "=", "new_cc_voltage", ";", "tc", ".", "cc_debounce", "=", "T_RP_VALUE_CHANGE", ";", "}", "else", "if", "(", "tc", ".", "cc_debounce", ")", "{", "tc", ".", "cc_debounce", "--", ";", "}", "}" ]
@brief Sink power sub states.
[ "@brief", "Sink", "power", "sub", "states", "." ]
[ "/* Debounce the cc state */", "/* Update timer */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
0457b5193c9633780172170065c9ab05cf4f249d
ParticleBeamHQ/zephyr
samples/boards/stm32/usbc/sink/src/usbc_snk.c
[ "Apache-2.0" ]
C
display_pdo
void
static void display_pdo(int idx, uint32_t pdo_value) { union pd_fixed_supply_pdo_source pdo; /* Default to fixed supply pdo source until type is detected */ pdo.raw_value = pdo_value; LOG_INF("PDO %d:", idx); switch (pdo.type) { case PDO_FIXED: { LOG_INF("\tType: FIXED"); LOG_INF("\tCurrent: %d", PD_CONVERT_FIXED_PDO_CURRENT_TO_MA(pdo.max_current)); LOG_INF("\tVoltage: %d", PD_CONVERT_FIXED_PDO_VOLTAGE_TO_MV(pdo.voltage)); LOG_INF("\tPeak Current: %d", pdo.peak_current); LOG_INF("\tUnchunked Support: %d", pdo.unchunked_ext_msg_supported); LOG_INF("\tDual Role Data: %d", pdo.dual_role_data); LOG_INF("\tUSB Comms: %d", pdo.usb_comms_capable); LOG_INF("\tUnconstrained Pwr: %d", pdo.unconstrained_power); LOG_INF("\tUSB Suspend: %d", pdo.usb_suspend_supported); LOG_INF("\tDual Role Power: %d", pdo.dual_role_power); } break; case PDO_BATTERY: { union pd_battery_supply_pdo_source pdo; pdo.raw_value = pdo_value; LOG_INF("\tType: BATTERY"); LOG_INF("\tMin Voltage: %d", PD_CONVERT_BATTERY_PDO_VOLTAGE_TO_MV(pdo.min_voltage)); LOG_INF("\tMax Voltage: %d", PD_CONVERT_BATTERY_PDO_VOLTAGE_TO_MV(pdo.max_voltage)); LOG_INF("\tMax Power: %d", PD_CONVERT_BATTERY_PDO_POWER_TO_MW(pdo.max_power)); } break; case PDO_VARIABLE: { union pd_variable_supply_pdo_source pdo; pdo.raw_value = pdo_value; LOG_INF("\tType: VARIABLE"); LOG_INF("\tMin Voltage: %d", PD_CONVERT_VARIABLE_PDO_VOLTAGE_TO_MV(pdo.min_voltage)); LOG_INF("\tMax Voltage: %d", PD_CONVERT_VARIABLE_PDO_VOLTAGE_TO_MV(pdo.max_voltage)); LOG_INF("\tMax Current: %d", PD_CONVERT_VARIABLE_PDO_CURRENT_TO_MA(pdo.max_current)); } break; case PDO_AUGMENTED: { union pd_augmented_supply_pdo_source pdo; pdo.raw_value = pdo_value; LOG_INF("\tType: AUGMENTED"); LOG_INF("\tMin Voltage: %d", PD_CONVERT_AUGMENTED_PDO_VOLTAGE_TO_MV(pdo.min_voltage)); LOG_INF("\tMax Voltage: %d", PD_CONVERT_AUGMENTED_PDO_VOLTAGE_TO_MV(pdo.max_voltage)); LOG_INF("\tMax Current: %d", PD_CONVERT_AUGMENTED_PDO_CURRENT_TO_MA(pdo.max_current)); LOG_INF("\tPPS Power Limited: %d", pdo.pps_power_limited); } break; } }
/** * @brief Display a single Power Delivery Object */
@brief Display a single Power Delivery Object
[ "@brief", "Display", "a", "single", "Power", "Delivery", "Object" ]
static void display_pdo(int idx, uint32_t pdo_value) { union pd_fixed_supply_pdo_source pdo; pdo.raw_value = pdo_value; LOG_INF("PDO %d:", idx); switch (pdo.type) { case PDO_FIXED: { LOG_INF("\tType: FIXED"); LOG_INF("\tCurrent: %d", PD_CONVERT_FIXED_PDO_CURRENT_TO_MA(pdo.max_current)); LOG_INF("\tVoltage: %d", PD_CONVERT_FIXED_PDO_VOLTAGE_TO_MV(pdo.voltage)); LOG_INF("\tPeak Current: %d", pdo.peak_current); LOG_INF("\tUnchunked Support: %d", pdo.unchunked_ext_msg_supported); LOG_INF("\tDual Role Data: %d", pdo.dual_role_data); LOG_INF("\tUSB Comms: %d", pdo.usb_comms_capable); LOG_INF("\tUnconstrained Pwr: %d", pdo.unconstrained_power); LOG_INF("\tUSB Suspend: %d", pdo.usb_suspend_supported); LOG_INF("\tDual Role Power: %d", pdo.dual_role_power); } break; case PDO_BATTERY: { union pd_battery_supply_pdo_source pdo; pdo.raw_value = pdo_value; LOG_INF("\tType: BATTERY"); LOG_INF("\tMin Voltage: %d", PD_CONVERT_BATTERY_PDO_VOLTAGE_TO_MV(pdo.min_voltage)); LOG_INF("\tMax Voltage: %d", PD_CONVERT_BATTERY_PDO_VOLTAGE_TO_MV(pdo.max_voltage)); LOG_INF("\tMax Power: %d", PD_CONVERT_BATTERY_PDO_POWER_TO_MW(pdo.max_power)); } break; case PDO_VARIABLE: { union pd_variable_supply_pdo_source pdo; pdo.raw_value = pdo_value; LOG_INF("\tType: VARIABLE"); LOG_INF("\tMin Voltage: %d", PD_CONVERT_VARIABLE_PDO_VOLTAGE_TO_MV(pdo.min_voltage)); LOG_INF("\tMax Voltage: %d", PD_CONVERT_VARIABLE_PDO_VOLTAGE_TO_MV(pdo.max_voltage)); LOG_INF("\tMax Current: %d", PD_CONVERT_VARIABLE_PDO_CURRENT_TO_MA(pdo.max_current)); } break; case PDO_AUGMENTED: { union pd_augmented_supply_pdo_source pdo; pdo.raw_value = pdo_value; LOG_INF("\tType: AUGMENTED"); LOG_INF("\tMin Voltage: %d", PD_CONVERT_AUGMENTED_PDO_VOLTAGE_TO_MV(pdo.min_voltage)); LOG_INF("\tMax Voltage: %d", PD_CONVERT_AUGMENTED_PDO_VOLTAGE_TO_MV(pdo.max_voltage)); LOG_INF("\tMax Current: %d", PD_CONVERT_AUGMENTED_PDO_CURRENT_TO_MA(pdo.max_current)); LOG_INF("\tPPS Power Limited: %d", pdo.pps_power_limited); } break; } }
[ "static", "void", "display_pdo", "(", "int", "idx", ",", "uint32_t", "pdo_value", ")", "{", "union", "pd_fixed_supply_pdo_source", "pdo", ";", "pdo", ".", "raw_value", "=", "pdo_value", ";", "LOG_INF", "(", "\"", "\"", ",", "idx", ")", ";", "switch", "(", "pdo", ".", "type", ")", "{", "case", "PDO_FIXED", ":", "{", "LOG_INF", "(", "\"", "\\t", "\"", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_FIXED_PDO_CURRENT_TO_MA", "(", "pdo", ".", "max_current", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_FIXED_PDO_VOLTAGE_TO_MV", "(", "pdo", ".", "voltage", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "peak_current", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "unchunked_ext_msg_supported", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "dual_role_data", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "usb_comms_capable", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "unconstrained_power", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "usb_suspend_supported", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "dual_role_power", ")", ";", "}", "break", ";", "case", "PDO_BATTERY", ":", "{", "union", "pd_battery_supply_pdo_source", "pdo", ";", "pdo", ".", "raw_value", "=", "pdo_value", ";", "LOG_INF", "(", "\"", "\\t", "\"", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_BATTERY_PDO_VOLTAGE_TO_MV", "(", "pdo", ".", "min_voltage", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_BATTERY_PDO_VOLTAGE_TO_MV", "(", "pdo", ".", "max_voltage", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_BATTERY_PDO_POWER_TO_MW", "(", "pdo", ".", "max_power", ")", ")", ";", "}", "break", ";", "case", "PDO_VARIABLE", ":", "{", "union", "pd_variable_supply_pdo_source", "pdo", ";", "pdo", ".", "raw_value", "=", "pdo_value", ";", "LOG_INF", "(", "\"", "\\t", "\"", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_VARIABLE_PDO_VOLTAGE_TO_MV", "(", "pdo", ".", "min_voltage", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_VARIABLE_PDO_VOLTAGE_TO_MV", "(", "pdo", ".", "max_voltage", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_VARIABLE_PDO_CURRENT_TO_MA", "(", "pdo", ".", "max_current", ")", ")", ";", "}", "break", ";", "case", "PDO_AUGMENTED", ":", "{", "union", "pd_augmented_supply_pdo_source", "pdo", ";", "pdo", ".", "raw_value", "=", "pdo_value", ";", "LOG_INF", "(", "\"", "\\t", "\"", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_AUGMENTED_PDO_VOLTAGE_TO_MV", "(", "pdo", ".", "min_voltage", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_AUGMENTED_PDO_VOLTAGE_TO_MV", "(", "pdo", ".", "max_voltage", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "PD_CONVERT_AUGMENTED_PDO_CURRENT_TO_MA", "(", "pdo", ".", "max_current", ")", ")", ";", "LOG_INF", "(", "\"", "\\t", "\"", ",", "pdo", ".", "pps_power_limited", ")", ";", "}", "break", ";", "}", "}" ]
@brief Display a single Power Delivery Object
[ "@brief", "Display", "a", "single", "Power", "Delivery", "Object" ]
[ "/* Default to fixed supply pdo source until type is detected */" ]
[ { "param": "idx", "type": "int" }, { "param": "pdo_value", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "idx", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pdo_value", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0457b5193c9633780172170065c9ab05cf4f249d
ParticleBeamHQ/zephyr
samples/boards/stm32/usbc/sink/src/usbc_snk.c
[ "Apache-2.0" ]
C
alert_handler
void
static void alert_handler(const struct device *dev, void *data, enum tcpc_alert alert) { struct tc_t *tc = data; switch (alert) { case TCPC_ALERT_CC_STATUS: tc->flag |= FLAG_CC_EVENT; break; case TCPC_ALERT_POWER_STATUS: break; case TCPC_ALERT_MSG_STATUS: tc->flag |= FLAG_PDMSG_RECEIVED; break; case TCPC_ALERT_HARD_RESET_RECEIVED: tc->flag |= FLAG_HARD_RESET_RECEIVED; break; case TCPC_ALERT_TRANSMIT_MSG_FAILED: tc->flag |= FLAG_PDMSG_FAILED; break; case TCPC_ALERT_TRANSMIT_MSG_DISCARDED: tc->flag |= FLAG_PDMSG_DISCARDED; break; case TCPC_ALERT_TRANSMIT_MSG_SUCCESS: tc->flag |= FLAG_PDMSG_SENT; break; /* These alerts are ignored */ default: break; } }
/** * @brief Alert Handler called by the TCPC driver */
@brief Alert Handler called by the TCPC driver
[ "@brief", "Alert", "Handler", "called", "by", "the", "TCPC", "driver" ]
static void alert_handler(const struct device *dev, void *data, enum tcpc_alert alert) { struct tc_t *tc = data; switch (alert) { case TCPC_ALERT_CC_STATUS: tc->flag |= FLAG_CC_EVENT; break; case TCPC_ALERT_POWER_STATUS: break; case TCPC_ALERT_MSG_STATUS: tc->flag |= FLAG_PDMSG_RECEIVED; break; case TCPC_ALERT_HARD_RESET_RECEIVED: tc->flag |= FLAG_HARD_RESET_RECEIVED; break; case TCPC_ALERT_TRANSMIT_MSG_FAILED: tc->flag |= FLAG_PDMSG_FAILED; break; case TCPC_ALERT_TRANSMIT_MSG_DISCARDED: tc->flag |= FLAG_PDMSG_DISCARDED; break; case TCPC_ALERT_TRANSMIT_MSG_SUCCESS: tc->flag |= FLAG_PDMSG_SENT; break; default: break; } }
[ "static", "void", "alert_handler", "(", "const", "struct", "device", "*", "dev", ",", "void", "*", "data", ",", "enum", "tcpc_alert", "alert", ")", "{", "struct", "tc_t", "*", "tc", "=", "data", ";", "switch", "(", "alert", ")", "{", "case", "TCPC_ALERT_CC_STATUS", ":", "tc", "->", "flag", "|=", "FLAG_CC_EVENT", ";", "break", ";", "case", "TCPC_ALERT_POWER_STATUS", ":", "break", ";", "case", "TCPC_ALERT_MSG_STATUS", ":", "tc", "->", "flag", "|=", "FLAG_PDMSG_RECEIVED", ";", "break", ";", "case", "TCPC_ALERT_HARD_RESET_RECEIVED", ":", "tc", "->", "flag", "|=", "FLAG_HARD_RESET_RECEIVED", ";", "break", ";", "case", "TCPC_ALERT_TRANSMIT_MSG_FAILED", ":", "tc", "->", "flag", "|=", "FLAG_PDMSG_FAILED", ";", "break", ";", "case", "TCPC_ALERT_TRANSMIT_MSG_DISCARDED", ":", "tc", "->", "flag", "|=", "FLAG_PDMSG_DISCARDED", ";", "break", ";", "case", "TCPC_ALERT_TRANSMIT_MSG_SUCCESS", ":", "tc", "->", "flag", "|=", "FLAG_PDMSG_SENT", ";", "break", ";", "default", ":", "break", ";", "}", "}" ]
@brief Alert Handler called by the TCPC driver
[ "@brief", "Alert", "Handler", "called", "by", "the", "TCPC", "driver" ]
[ "/* These alerts are ignored */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "data", "type": "void" }, { "param": "alert", "type": "enum tcpc_alert" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "alert", "type": "enum tcpc_alert", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c24e4abcebfd256fa41285e4df354cb00d8a789f
ParticleBeamHQ/zephyr
drivers/i2c/i2c_mchp_xec.c
[ "Apache-2.0" ]
C
wait_completion
int
static int wait_completion(const struct device *dev) { const struct i2c_xec_config *config = (const struct i2c_xec_config *const) (dev->config); int ret; int counter = 0; uint32_t ba = config->base_addr; while (1) { uint8_t status = MCHP_I2C_SMB_STS_RO(ba); /* Is bus error ? */ if (status & MCHP_I2C_SMB_STS_BER) { recover_from_error(dev); return -EBUSY; } /* Is Lost arbitration ? */ status = MCHP_I2C_SMB_STS_RO(ba); if (status & MCHP_I2C_SMB_STS_LAB) { return -EPERM; } status = MCHP_I2C_SMB_STS_RO(ba); /* PIN -> 0 indicates I2C is done */ if (!(status & MCHP_I2C_SMB_STS_PIN)) { /* PIN == 0. LRB contains state of 9th bit */ if (status & MCHP_I2C_SMB_STS_LRB_AD0) { /* NACK? */ /* Send STOP */ MCHP_I2C_SMB_CTRL_WO(ba) = MCHP_I2C_SMB_CTRL_PIN | MCHP_I2C_SMB_CTRL_ESO | MCHP_I2C_SMB_CTRL_STO | MCHP_I2C_SMB_CTRL_ACK; k_busy_wait(BUS_IDLE_US_DFLT); return -EIO; } break; /* success: ACK */ } ret = xec_spin_yield(&counter); if (ret < 0) { return ret; } } return 0; }
/* * Wait with timeout for I2C controller to finish transmit/receive of one * byte(address or data). * When transmit/receive operation is started the I2C PIN status is 1. Upon * normal completion I2C PIN status asserts(0). * We loop checking I2C status for the following events: * Bus Error: * Reset controller and return -EBUSY * Lost Arbitration: * Return -EPERM. We lost bus to another controller. No reset. * PIN == 0: I2C Status LRB is valid and contains ACK/NACK data on 9th clock. * ACK return 0 (success) * NACK Issue STOP, wait for bus minimum idle time, return -EIO. * Timeout: * Reset controller and return -ETIMEDOUT * * NOTE: After generating a STOP the controller will not generate a START until * Bus Minimum Idle time has expired. */
Wait with timeout for I2C controller to finish transmit/receive of one byte(address or data). When transmit/receive operation is started the I2C PIN status is 1. Upon normal completion I2C PIN status asserts(0). We loop checking I2C status for the following events: Bus Error: Reset controller and return -EBUSY Lost Arbitration: Return -EPERM. We lost bus to another controller. No reset. PIN == 0: I2C Status LRB is valid and contains ACK/NACK data on 9th clock. ACK return 0 (success) NACK Issue STOP, wait for bus minimum idle time, return -EIO. Timeout: Reset controller and return -ETIMEDOUT After generating a STOP the controller will not generate a START until Bus Minimum Idle time has expired.
[ "Wait", "with", "timeout", "for", "I2C", "controller", "to", "finish", "transmit", "/", "receive", "of", "one", "byte", "(", "address", "or", "data", ")", ".", "When", "transmit", "/", "receive", "operation", "is", "started", "the", "I2C", "PIN", "status", "is", "1", ".", "Upon", "normal", "completion", "I2C", "PIN", "status", "asserts", "(", "0", ")", ".", "We", "loop", "checking", "I2C", "status", "for", "the", "following", "events", ":", "Bus", "Error", ":", "Reset", "controller", "and", "return", "-", "EBUSY", "Lost", "Arbitration", ":", "Return", "-", "EPERM", ".", "We", "lost", "bus", "to", "another", "controller", ".", "No", "reset", ".", "PIN", "==", "0", ":", "I2C", "Status", "LRB", "is", "valid", "and", "contains", "ACK", "/", "NACK", "data", "on", "9th", "clock", ".", "ACK", "return", "0", "(", "success", ")", "NACK", "Issue", "STOP", "wait", "for", "bus", "minimum", "idle", "time", "return", "-", "EIO", ".", "Timeout", ":", "Reset", "controller", "and", "return", "-", "ETIMEDOUT", "After", "generating", "a", "STOP", "the", "controller", "will", "not", "generate", "a", "START", "until", "Bus", "Minimum", "Idle", "time", "has", "expired", "." ]
static int wait_completion(const struct device *dev) { const struct i2c_xec_config *config = (const struct i2c_xec_config *const) (dev->config); int ret; int counter = 0; uint32_t ba = config->base_addr; while (1) { uint8_t status = MCHP_I2C_SMB_STS_RO(ba); if (status & MCHP_I2C_SMB_STS_BER) { recover_from_error(dev); return -EBUSY; } status = MCHP_I2C_SMB_STS_RO(ba); if (status & MCHP_I2C_SMB_STS_LAB) { return -EPERM; } status = MCHP_I2C_SMB_STS_RO(ba); if (!(status & MCHP_I2C_SMB_STS_PIN)) { if (status & MCHP_I2C_SMB_STS_LRB_AD0) { MCHP_I2C_SMB_CTRL_WO(ba) = MCHP_I2C_SMB_CTRL_PIN | MCHP_I2C_SMB_CTRL_ESO | MCHP_I2C_SMB_CTRL_STO | MCHP_I2C_SMB_CTRL_ACK; k_busy_wait(BUS_IDLE_US_DFLT); return -EIO; } break; } ret = xec_spin_yield(&counter); if (ret < 0) { return ret; } } return 0; }
[ "static", "int", "wait_completion", "(", "const", "struct", "device", "*", "dev", ")", "{", "const", "struct", "i2c_xec_config", "*", "config", "=", "(", "const", "struct", "i2c_xec_config", "*", "const", ")", "(", "dev", "->", "config", ")", ";", "int", "ret", ";", "int", "counter", "=", "0", ";", "uint32_t", "ba", "=", "config", "->", "base_addr", ";", "while", "(", "1", ")", "{", "uint8_t", "status", "=", "MCHP_I2C_SMB_STS_RO", "(", "ba", ")", ";", "if", "(", "status", "&", "MCHP_I2C_SMB_STS_BER", ")", "{", "recover_from_error", "(", "dev", ")", ";", "return", "-", "EBUSY", ";", "}", "status", "=", "MCHP_I2C_SMB_STS_RO", "(", "ba", ")", ";", "if", "(", "status", "&", "MCHP_I2C_SMB_STS_LAB", ")", "{", "return", "-", "EPERM", ";", "}", "status", "=", "MCHP_I2C_SMB_STS_RO", "(", "ba", ")", ";", "if", "(", "!", "(", "status", "&", "MCHP_I2C_SMB_STS_PIN", ")", ")", "{", "if", "(", "status", "&", "MCHP_I2C_SMB_STS_LRB_AD0", ")", "{", "MCHP_I2C_SMB_CTRL_WO", "(", "ba", ")", "=", "MCHP_I2C_SMB_CTRL_PIN", "|", "MCHP_I2C_SMB_CTRL_ESO", "|", "MCHP_I2C_SMB_CTRL_STO", "|", "MCHP_I2C_SMB_CTRL_ACK", ";", "k_busy_wait", "(", "BUS_IDLE_US_DFLT", ")", ";", "return", "-", "EIO", ";", "}", "break", ";", "}", "ret", "=", "xec_spin_yield", "(", "&", "counter", ")", ";", "if", "(", "ret", "<", "0", ")", "{", "return", "ret", ";", "}", "}", "return", "0", ";", "}" ]
Wait with timeout for I2C controller to finish transmit/receive of one byte(address or data).
[ "Wait", "with", "timeout", "for", "I2C", "controller", "to", "finish", "transmit", "/", "receive", "of", "one", "byte", "(", "address", "or", "data", ")", "." ]
[ "/* Is bus error ? */", "/* Is Lost arbitration ? */", "/* PIN -> 0 indicates I2C is done */", "/* PIN == 0. LRB contains state of 9th bit */", "/* NACK? */", "/* Send STOP */", "/* success: ACK */" ]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c24e4abcebfd256fa41285e4df354cb00d8a789f
ParticleBeamHQ/zephyr
drivers/i2c/i2c_mchp_xec.c
[ "Apache-2.0" ]
C
check_lines_high
bool
static bool check_lines_high(const struct device *dev) { const struct i2c_xec_config *config = (const struct i2c_xec_config *const)(dev->config); struct i2c_xec_data *data = (struct i2c_xec_data *const)(dev->data); gpio_port_value_t sda = 0, scl = 0; if (gpio_port_get_raw(data->sda_gpio, &sda)) { LOG_ERR("gpio_port_get_raw for %s SDA failed", dev->name); return false; } /* both pins could be on same GPIO group */ if (data->sda_gpio == data->scl_gpio) { scl = sda; } else { if (gpio_port_get_raw(data->scl_gpio, &scl)) { LOG_ERR("gpio_port_get_raw for %s SCL failed", dev->name); return false; } } return (sda & BIT(config->sda_pos)) && (scl & BIT(config->scl_pos)); }
/* * Call GPIO driver to read state of pins. * Return boolean true if both lines HIGH else return boolean false */
Call GPIO driver to read state of pins. Return boolean true if both lines HIGH else return boolean false
[ "Call", "GPIO", "driver", "to", "read", "state", "of", "pins", ".", "Return", "boolean", "true", "if", "both", "lines", "HIGH", "else", "return", "boolean", "false" ]
static bool check_lines_high(const struct device *dev) { const struct i2c_xec_config *config = (const struct i2c_xec_config *const)(dev->config); struct i2c_xec_data *data = (struct i2c_xec_data *const)(dev->data); gpio_port_value_t sda = 0, scl = 0; if (gpio_port_get_raw(data->sda_gpio, &sda)) { LOG_ERR("gpio_port_get_raw for %s SDA failed", dev->name); return false; } if (data->sda_gpio == data->scl_gpio) { scl = sda; } else { if (gpio_port_get_raw(data->scl_gpio, &scl)) { LOG_ERR("gpio_port_get_raw for %s SCL failed", dev->name); return false; } } return (sda & BIT(config->sda_pos)) && (scl & BIT(config->scl_pos)); }
[ "static", "bool", "check_lines_high", "(", "const", "struct", "device", "*", "dev", ")", "{", "const", "struct", "i2c_xec_config", "*", "config", "=", "(", "const", "struct", "i2c_xec_config", "*", "const", ")", "(", "dev", "->", "config", ")", ";", "struct", "i2c_xec_data", "*", "data", "=", "(", "struct", "i2c_xec_data", "*", "const", ")", "(", "dev", "->", "data", ")", ";", "gpio_port_value_t", "sda", "=", "0", ",", "scl", "=", "0", ";", "if", "(", "gpio_port_get_raw", "(", "data", "->", "sda_gpio", ",", "&", "sda", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "dev", "->", "name", ")", ";", "return", "false", ";", "}", "if", "(", "data", "->", "sda_gpio", "==", "data", "->", "scl_gpio", ")", "{", "scl", "=", "sda", ";", "}", "else", "{", "if", "(", "gpio_port_get_raw", "(", "data", "->", "scl_gpio", ",", "&", "scl", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "dev", "->", "name", ")", ";", "return", "false", ";", "}", "}", "return", "(", "sda", "&", "BIT", "(", "config", "->", "sda_pos", ")", ")", "&&", "(", "scl", "&", "BIT", "(", "config", "->", "scl_pos", ")", ")", ";", "}" ]
Call GPIO driver to read state of pins.
[ "Call", "GPIO", "driver", "to", "read", "state", "of", "pins", "." ]
[ "/* both pins could be on same GPIO group */" ]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3fa5a0d6827e5089cba6c3c5d2e908bfe8dc0c70
ParticleBeamHQ/zephyr
subsys/shell/backends/shell_mqtt.c
[ "Apache-2.0" ]
C
sh_mqtt_close_and_cleanup
void
static void sh_mqtt_close_and_cleanup(void) { /* Initialize to negative value so that the mqtt_abort case can run */ int rc = -1; /* If both network & mqtt connected, mqtt_disconnect will send a * disconnection packet to the broker, it will invoke * mqtt_evt_handler:MQTT_EVT_DISCONNECT if success */ if ((sh_mqtt->network_state == SHELL_MQTT_NETWORK_CONNECTED) && (sh_mqtt->transport_state == SHELL_MQTT_TRANSPORT_CONNECTED)) { rc = mqtt_disconnect(&sh_mqtt->mqtt_cli); } /* If network/mqtt disconnected, or mqtt_disconnect failed, do mqtt_abort */ if (rc) { /* mqtt_abort doesn't send disconnection packet to the broker, but it * makes sure that the MQTT connection is aborted locally and will * always invoke mqtt_evt_handler:MQTT_EVT_DISCONNECT */ (void)mqtt_abort(&sh_mqtt->mqtt_cli); } /* Cleanup socket */ clear_fds(); }
/* Close MQTT connection properly and cleanup socket */
Close MQTT connection properly and cleanup socket
[ "Close", "MQTT", "connection", "properly", "and", "cleanup", "socket" ]
static void sh_mqtt_close_and_cleanup(void) { int rc = -1; if ((sh_mqtt->network_state == SHELL_MQTT_NETWORK_CONNECTED) && (sh_mqtt->transport_state == SHELL_MQTT_TRANSPORT_CONNECTED)) { rc = mqtt_disconnect(&sh_mqtt->mqtt_cli); } if (rc) { (void)mqtt_abort(&sh_mqtt->mqtt_cli); } clear_fds(); }
[ "static", "void", "sh_mqtt_close_and_cleanup", "(", "void", ")", "{", "int", "rc", "=", "-1", ";", "if", "(", "(", "sh_mqtt", "->", "network_state", "==", "SHELL_MQTT_NETWORK_CONNECTED", ")", "&&", "(", "sh_mqtt", "->", "transport_state", "==", "SHELL_MQTT_TRANSPORT_CONNECTED", ")", ")", "{", "rc", "=", "mqtt_disconnect", "(", "&", "sh_mqtt", "->", "mqtt_cli", ")", ";", "}", "if", "(", "rc", ")", "{", "(", "void", ")", "mqtt_abort", "(", "&", "sh_mqtt", "->", "mqtt_cli", ")", ";", "}", "clear_fds", "(", ")", ";", "}" ]
Close MQTT connection properly and cleanup socket
[ "Close", "MQTT", "connection", "properly", "and", "cleanup", "socket" ]
[ "/* Initialize to negative value so that the mqtt_abort case can run */", "/* If both network & mqtt connected, mqtt_disconnect will send a\n\t * disconnection packet to the broker, it will invoke\n\t * mqtt_evt_handler:MQTT_EVT_DISCONNECT if success\n\t */", "/* If network/mqtt disconnected, or mqtt_disconnect failed, do mqtt_abort */", "/* mqtt_abort doesn't send disconnection packet to the broker, but it\n\t\t * makes sure that the MQTT connection is aborted locally and will\n\t\t * always invoke mqtt_evt_handler:MQTT_EVT_DISCONNECT\n\t\t */", "/* Cleanup socket */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
3fa5a0d6827e5089cba6c3c5d2e908bfe8dc0c70
ParticleBeamHQ/zephyr
subsys/shell/backends/shell_mqtt.c
[ "Apache-2.0" ]
C
sh_mqtt_process_handler
void
static void sh_mqtt_process_handler(struct k_work *work) { ARG_UNUSED(work); int rc; int64_t remaining = LISTEN_TIMEOUT_MS; int64_t start_time = k_uptime_get(); if (sh_mqtt->network_state != SHELL_MQTT_NETWORK_CONNECTED) { LOG_DBG("%s_work while %s", "process", "network disconnected"); return; } /* If context can't be locked, that means net conn cb locked it */ if (sh_mqtt_context_lock(K_NO_WAIT)) { /* In that case we should simply return */ LOG_DBG("%s_work unable to lock context", "process"); return; } if (sh_mqtt->transport_state != SHELL_MQTT_TRANSPORT_CONNECTED) { LOG_DBG("MQTT %s", "not connected"); goto process_error; } if (sh_mqtt->subscribe_state != SHELL_MQTT_SUBSCRIBED) { LOG_DBG("%s_work while %s", "process", "MQTT not subscribed"); goto process_error; } LOG_DBG("MQTT %s", "Processing"); /* Listen to the port for a duration defined by LISTEN_TIMEOUT_MS */ while ((remaining > 0) && (sh_mqtt->network_state == SHELL_MQTT_NETWORK_CONNECTED) && (sh_mqtt->transport_state == SHELL_MQTT_TRANSPORT_CONNECTED) && (sh_mqtt->subscribe_state == SHELL_MQTT_SUBSCRIBED)) { LOG_DBG("Listening to socket"); if (wait(remaining)) { LOG_DBG("Process socket for MQTT packet"); rc = mqtt_input(&sh_mqtt->mqtt_cli); if (rc != 0) { LOG_ERR("%s error: %d", "processed: mqtt_input", rc); goto process_error; } } LOG_DBG("MQTT %s", "Keepalive"); rc = mqtt_live(&sh_mqtt->mqtt_cli); if (rc != 0 && rc != -EAGAIN) { LOG_ERR("%s error: %d", "mqtt_live", rc); goto process_error; } remaining = LISTEN_TIMEOUT_MS + start_time - k_uptime_get(); } /* Reschedule the process work */ LOG_DBG("Scheduling %s work", "process"); (void)sh_mqtt_work_reschedule(&sh_mqtt->process_dwork, K_SECONDS(2)); sh_mqtt_context_unlock(); return; process_error: LOG_DBG("%s: close MQTT, cleanup socket & reconnect", "connect"); sh_mqtt_close_and_cleanup(); (void)sh_mqtt_work_reschedule(&sh_mqtt->connect_dwork, K_SECONDS(1)); sh_mqtt_context_unlock(); }
/* Work routine to process MQTT packet and keep alive MQTT connection */
Work routine to process MQTT packet and keep alive MQTT connection
[ "Work", "routine", "to", "process", "MQTT", "packet", "and", "keep", "alive", "MQTT", "connection" ]
static void sh_mqtt_process_handler(struct k_work *work) { ARG_UNUSED(work); int rc; int64_t remaining = LISTEN_TIMEOUT_MS; int64_t start_time = k_uptime_get(); if (sh_mqtt->network_state != SHELL_MQTT_NETWORK_CONNECTED) { LOG_DBG("%s_work while %s", "process", "network disconnected"); return; } if (sh_mqtt_context_lock(K_NO_WAIT)) { LOG_DBG("%s_work unable to lock context", "process"); return; } if (sh_mqtt->transport_state != SHELL_MQTT_TRANSPORT_CONNECTED) { LOG_DBG("MQTT %s", "not connected"); goto process_error; } if (sh_mqtt->subscribe_state != SHELL_MQTT_SUBSCRIBED) { LOG_DBG("%s_work while %s", "process", "MQTT not subscribed"); goto process_error; } LOG_DBG("MQTT %s", "Processing"); while ((remaining > 0) && (sh_mqtt->network_state == SHELL_MQTT_NETWORK_CONNECTED) && (sh_mqtt->transport_state == SHELL_MQTT_TRANSPORT_CONNECTED) && (sh_mqtt->subscribe_state == SHELL_MQTT_SUBSCRIBED)) { LOG_DBG("Listening to socket"); if (wait(remaining)) { LOG_DBG("Process socket for MQTT packet"); rc = mqtt_input(&sh_mqtt->mqtt_cli); if (rc != 0) { LOG_ERR("%s error: %d", "processed: mqtt_input", rc); goto process_error; } } LOG_DBG("MQTT %s", "Keepalive"); rc = mqtt_live(&sh_mqtt->mqtt_cli); if (rc != 0 && rc != -EAGAIN) { LOG_ERR("%s error: %d", "mqtt_live", rc); goto process_error; } remaining = LISTEN_TIMEOUT_MS + start_time - k_uptime_get(); } LOG_DBG("Scheduling %s work", "process"); (void)sh_mqtt_work_reschedule(&sh_mqtt->process_dwork, K_SECONDS(2)); sh_mqtt_context_unlock(); return; process_error: LOG_DBG("%s: close MQTT, cleanup socket & reconnect", "connect"); sh_mqtt_close_and_cleanup(); (void)sh_mqtt_work_reschedule(&sh_mqtt->connect_dwork, K_SECONDS(1)); sh_mqtt_context_unlock(); }
[ "static", "void", "sh_mqtt_process_handler", "(", "struct", "k_work", "*", "work", ")", "{", "ARG_UNUSED", "(", "work", ")", ";", "int", "rc", ";", "int64_t", "remaining", "=", "LISTEN_TIMEOUT_MS", ";", "int64_t", "start_time", "=", "k_uptime_get", "(", ")", ";", "if", "(", "sh_mqtt", "->", "network_state", "!=", "SHELL_MQTT_NETWORK_CONNECTED", ")", "{", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "return", ";", "}", "if", "(", "sh_mqtt_context_lock", "(", "K_NO_WAIT", ")", ")", "{", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "return", ";", "}", "if", "(", "sh_mqtt", "->", "transport_state", "!=", "SHELL_MQTT_TRANSPORT_CONNECTED", ")", "{", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "goto", "process_error", ";", "}", "if", "(", "sh_mqtt", "->", "subscribe_state", "!=", "SHELL_MQTT_SUBSCRIBED", ")", "{", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "goto", "process_error", ";", "}", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "while", "(", "(", "remaining", ">", "0", ")", "&&", "(", "sh_mqtt", "->", "network_state", "==", "SHELL_MQTT_NETWORK_CONNECTED", ")", "&&", "(", "sh_mqtt", "->", "transport_state", "==", "SHELL_MQTT_TRANSPORT_CONNECTED", ")", "&&", "(", "sh_mqtt", "->", "subscribe_state", "==", "SHELL_MQTT_SUBSCRIBED", ")", ")", "{", "LOG_DBG", "(", "\"", "\"", ")", ";", "if", "(", "wait", "(", "remaining", ")", ")", "{", "LOG_DBG", "(", "\"", "\"", ")", ";", "rc", "=", "mqtt_input", "(", "&", "sh_mqtt", "->", "mqtt_cli", ")", ";", "if", "(", "rc", "!=", "0", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "\"", "\"", ",", "rc", ")", ";", "goto", "process_error", ";", "}", "}", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "rc", "=", "mqtt_live", "(", "&", "sh_mqtt", "->", "mqtt_cli", ")", ";", "if", "(", "rc", "!=", "0", "&&", "rc", "!=", "-", "EAGAIN", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "\"", "\"", ",", "rc", ")", ";", "goto", "process_error", ";", "}", "remaining", "=", "LISTEN_TIMEOUT_MS", "+", "start_time", "-", "k_uptime_get", "(", ")", ";", "}", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "(", "void", ")", "sh_mqtt_work_reschedule", "(", "&", "sh_mqtt", "->", "process_dwork", ",", "K_SECONDS", "(", "2", ")", ")", ";", "sh_mqtt_context_unlock", "(", ")", ";", "return", ";", "process_error", ":", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "sh_mqtt_close_and_cleanup", "(", ")", ";", "(", "void", ")", "sh_mqtt_work_reschedule", "(", "&", "sh_mqtt", "->", "connect_dwork", ",", "K_SECONDS", "(", "1", ")", ")", ";", "sh_mqtt_context_unlock", "(", ")", ";", "}" ]
Work routine to process MQTT packet and keep alive MQTT connection
[ "Work", "routine", "to", "process", "MQTT", "packet", "and", "keep", "alive", "MQTT", "connection" ]
[ "/* If context can't be locked, that means net conn cb locked it */", "/* In that case we should simply return */", "/* Listen to the port for a duration defined by LISTEN_TIMEOUT_MS */", "/* Reschedule the process work */" ]
[ { "param": "work", "type": "struct k_work" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "work", "type": "struct k_work", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3fa5a0d6827e5089cba6c3c5d2e908bfe8dc0c70
ParticleBeamHQ/zephyr
subsys/shell/backends/shell_mqtt.c
[ "Apache-2.0" ]
C
sh_mqtt_connect_handler
void
static void sh_mqtt_connect_handler(struct k_work *work) { ARG_UNUSED(work); int rc; if (sh_mqtt->network_state != SHELL_MQTT_NETWORK_CONNECTED) { LOG_DBG("%s_work while %s", "connect", "network disconnected"); return; } /* If context can't be locked, that means net conn cb locked it */ if (sh_mqtt_context_lock(K_NO_WAIT)) { /* In that case we should simply return */ LOG_DBG("%s_work unable to lock context", "connect"); return; } if (sh_mqtt->transport_state == SHELL_MQTT_TRANSPORT_CONNECTED) { __ASSERT(0, "MQTT shouldn't be already connected"); LOG_ERR("MQTT shouldn't be already connected"); goto connect_error; } /* Resolve the broker URL */ LOG_DBG("Resolving DNS"); rc = get_mqtt_broker_addrinfo(); if (rc) { (void)sh_mqtt_work_reschedule(&sh_mqtt->connect_dwork, K_SECONDS(1)); sh_mqtt_context_unlock(); return; } LOG_DBG("Initializing MQTT client"); broker_init(); client_init(); /* Try to connect to mqtt */ LOG_DBG("Connecting to MQTT broker"); rc = mqtt_connect(&sh_mqtt->mqtt_cli); if (rc != 0) { LOG_ERR("%s error: %d", "mqtt_connect", rc); goto connect_error; } /* Prepare port config */ LOG_DBG("Preparing socket"); prepare_fds(); /* Wait for mqtt's connack */ LOG_DBG("Listening to socket"); if (wait(CONNECT_TIMEOUT_MS)) { LOG_DBG("Process socket for MQTT packet"); rc = mqtt_input(&sh_mqtt->mqtt_cli); if (rc != 0) { LOG_ERR("%s error: %d", "connect: mqtt_input", rc); goto connect_error; } } /* No connack, fail */ if (sh_mqtt->transport_state != SHELL_MQTT_TRANSPORT_CONNECTED) { goto connect_error; } LOG_DBG("Scheduling %s work", "subscribe"); (void)sh_mqtt_work_reschedule(&sh_mqtt->subscribe_dwork, K_SECONDS(2)); sh_mqtt_context_unlock(); return; connect_error: LOG_DBG("%s: close MQTT, cleanup socket & reconnect", "connect"); sh_mqtt_close_and_cleanup(); (void)sh_mqtt_work_reschedule(&sh_mqtt->connect_dwork, K_SECONDS(2)); sh_mqtt_context_unlock(); }
/* Work routine to connect to MQTT */
Work routine to connect to MQTT
[ "Work", "routine", "to", "connect", "to", "MQTT" ]
static void sh_mqtt_connect_handler(struct k_work *work) { ARG_UNUSED(work); int rc; if (sh_mqtt->network_state != SHELL_MQTT_NETWORK_CONNECTED) { LOG_DBG("%s_work while %s", "connect", "network disconnected"); return; } if (sh_mqtt_context_lock(K_NO_WAIT)) { LOG_DBG("%s_work unable to lock context", "connect"); return; } if (sh_mqtt->transport_state == SHELL_MQTT_TRANSPORT_CONNECTED) { __ASSERT(0, "MQTT shouldn't be already connected"); LOG_ERR("MQTT shouldn't be already connected"); goto connect_error; } LOG_DBG("Resolving DNS"); rc = get_mqtt_broker_addrinfo(); if (rc) { (void)sh_mqtt_work_reschedule(&sh_mqtt->connect_dwork, K_SECONDS(1)); sh_mqtt_context_unlock(); return; } LOG_DBG("Initializing MQTT client"); broker_init(); client_init(); LOG_DBG("Connecting to MQTT broker"); rc = mqtt_connect(&sh_mqtt->mqtt_cli); if (rc != 0) { LOG_ERR("%s error: %d", "mqtt_connect", rc); goto connect_error; } LOG_DBG("Preparing socket"); prepare_fds(); LOG_DBG("Listening to socket"); if (wait(CONNECT_TIMEOUT_MS)) { LOG_DBG("Process socket for MQTT packet"); rc = mqtt_input(&sh_mqtt->mqtt_cli); if (rc != 0) { LOG_ERR("%s error: %d", "connect: mqtt_input", rc); goto connect_error; } } if (sh_mqtt->transport_state != SHELL_MQTT_TRANSPORT_CONNECTED) { goto connect_error; } LOG_DBG("Scheduling %s work", "subscribe"); (void)sh_mqtt_work_reschedule(&sh_mqtt->subscribe_dwork, K_SECONDS(2)); sh_mqtt_context_unlock(); return; connect_error: LOG_DBG("%s: close MQTT, cleanup socket & reconnect", "connect"); sh_mqtt_close_and_cleanup(); (void)sh_mqtt_work_reschedule(&sh_mqtt->connect_dwork, K_SECONDS(2)); sh_mqtt_context_unlock(); }
[ "static", "void", "sh_mqtt_connect_handler", "(", "struct", "k_work", "*", "work", ")", "{", "ARG_UNUSED", "(", "work", ")", ";", "int", "rc", ";", "if", "(", "sh_mqtt", "->", "network_state", "!=", "SHELL_MQTT_NETWORK_CONNECTED", ")", "{", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "return", ";", "}", "if", "(", "sh_mqtt_context_lock", "(", "K_NO_WAIT", ")", ")", "{", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "return", ";", "}", "if", "(", "sh_mqtt", "->", "transport_state", "==", "SHELL_MQTT_TRANSPORT_CONNECTED", ")", "{", "__ASSERT", "(", "0", ",", "\"", "\"", ")", ";", "LOG_ERR", "(", "\"", "\"", ")", ";", "goto", "connect_error", ";", "}", "LOG_DBG", "(", "\"", "\"", ")", ";", "rc", "=", "get_mqtt_broker_addrinfo", "(", ")", ";", "if", "(", "rc", ")", "{", "(", "void", ")", "sh_mqtt_work_reschedule", "(", "&", "sh_mqtt", "->", "connect_dwork", ",", "K_SECONDS", "(", "1", ")", ")", ";", "sh_mqtt_context_unlock", "(", ")", ";", "return", ";", "}", "LOG_DBG", "(", "\"", "\"", ")", ";", "broker_init", "(", ")", ";", "client_init", "(", ")", ";", "LOG_DBG", "(", "\"", "\"", ")", ";", "rc", "=", "mqtt_connect", "(", "&", "sh_mqtt", "->", "mqtt_cli", ")", ";", "if", "(", "rc", "!=", "0", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "\"", "\"", ",", "rc", ")", ";", "goto", "connect_error", ";", "}", "LOG_DBG", "(", "\"", "\"", ")", ";", "prepare_fds", "(", ")", ";", "LOG_DBG", "(", "\"", "\"", ")", ";", "if", "(", "wait", "(", "CONNECT_TIMEOUT_MS", ")", ")", "{", "LOG_DBG", "(", "\"", "\"", ")", ";", "rc", "=", "mqtt_input", "(", "&", "sh_mqtt", "->", "mqtt_cli", ")", ";", "if", "(", "rc", "!=", "0", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "\"", "\"", ",", "rc", ")", ";", "goto", "connect_error", ";", "}", "}", "if", "(", "sh_mqtt", "->", "transport_state", "!=", "SHELL_MQTT_TRANSPORT_CONNECTED", ")", "{", "goto", "connect_error", ";", "}", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "(", "void", ")", "sh_mqtt_work_reschedule", "(", "&", "sh_mqtt", "->", "subscribe_dwork", ",", "K_SECONDS", "(", "2", ")", ")", ";", "sh_mqtt_context_unlock", "(", ")", ";", "return", ";", "connect_error", ":", "LOG_DBG", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "sh_mqtt_close_and_cleanup", "(", ")", ";", "(", "void", ")", "sh_mqtt_work_reschedule", "(", "&", "sh_mqtt", "->", "connect_dwork", ",", "K_SECONDS", "(", "2", ")", ")", ";", "sh_mqtt_context_unlock", "(", ")", ";", "}" ]
Work routine to connect to MQTT
[ "Work", "routine", "to", "connect", "to", "MQTT" ]
[ "/* If context can't be locked, that means net conn cb locked it */", "/* In that case we should simply return */", "/* Resolve the broker URL */", "/* Try to connect to mqtt */", "/* Prepare port config */", "/* Wait for mqtt's connack */", "/* No connack, fail */" ]
[ { "param": "work", "type": "struct k_work" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "work", "type": "struct k_work", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
76944c087e822d03b69682394c6722515ccd30b2
ParticleBeamHQ/zephyr
subsys/testsuite/include/interrupt_util.h
[ "Apache-2.0" ]
C
trigger_irq
void
static inline void trigger_irq(int vector) { #ifdef CONFIG_X2APIC x86_write_x2apic(LOAPIC_SELF_IPI, ((VECTOR_MASK & vector))); #else #ifdef CONFIG_SMP int cpu_id = arch_curr_cpu()->id; #else int cpu_id = 0; #endif z_loapic_ipi(cpu_id, LOAPIC_ICR_IPI_TEST, vector); #endif /* CONFIG_X2APIC */ }
/* * We can emulate the interrupt by sending the IPI to * core itself by the LOAPIC for x86 platform. * * In APIC mode, Write LOAPIC's ICR to trigger IPI, * the LOAPIC_ICR_IPI_TEST 0x00004000U means: * Delivery Mode: Fixed * Destination Mode: Physical * Level: Assert * Trigger Mode: Edge * Destination Shorthand: No Shorthand * Destination: depends on cpu_id * * In X2APIC mode, this no longer works. We emulate the * interrupt by writing the IA32_X2APIC_SELF_IPI MSR * to send IPI to the core itself via LOAPIC also. * According to SDM vol.3 chapter 10.12.11, the bit[7:0] * for setting the vector is only needed. */
We can emulate the interrupt by sending the IPI to core itself by the LOAPIC for x86 platform. In X2APIC mode, this no longer works. We emulate the interrupt by writing the IA32_X2APIC_SELF_IPI MSR to send IPI to the core itself via LOAPIC also. According to SDM vol.3 chapter 10.12.11, the bit[7:0] for setting the vector is only needed.
[ "We", "can", "emulate", "the", "interrupt", "by", "sending", "the", "IPI", "to", "core", "itself", "by", "the", "LOAPIC", "for", "x86", "platform", ".", "In", "X2APIC", "mode", "this", "no", "longer", "works", ".", "We", "emulate", "the", "interrupt", "by", "writing", "the", "IA32_X2APIC_SELF_IPI", "MSR", "to", "send", "IPI", "to", "the", "core", "itself", "via", "LOAPIC", "also", ".", "According", "to", "SDM", "vol", ".", "3", "chapter", "10", ".", "12", ".", "11", "the", "bit", "[", "7", ":", "0", "]", "for", "setting", "the", "vector", "is", "only", "needed", "." ]
static inline void trigger_irq(int vector) { #ifdef CONFIG_X2APIC x86_write_x2apic(LOAPIC_SELF_IPI, ((VECTOR_MASK & vector))); #else #ifdef CONFIG_SMP int cpu_id = arch_curr_cpu()->id; #else int cpu_id = 0; #endif z_loapic_ipi(cpu_id, LOAPIC_ICR_IPI_TEST, vector); #endif }
[ "static", "inline", "void", "trigger_irq", "(", "int", "vector", ")", "{", "#ifdef", "CONFIG_X2APIC", "x86_write_x2apic", "(", "LOAPIC_SELF_IPI", ",", "(", "(", "VECTOR_MASK", "&", "vector", ")", ")", ")", ";", "#else", "#ifdef", "CONFIG_SMP", "int", "cpu_id", "=", "arch_curr_cpu", "(", ")", "->", "id", ";", "#else", "int", "cpu_id", "=", "0", ";", "#endif", "z_loapic_ipi", "(", "cpu_id", ",", "LOAPIC_ICR_IPI_TEST", ",", "vector", ")", ";", "#endif", "}" ]
We can emulate the interrupt by sending the IPI to core itself by the LOAPIC for x86 platform.
[ "We", "can", "emulate", "the", "interrupt", "by", "sending", "the", "IPI", "to", "core", "itself", "by", "the", "LOAPIC", "for", "x86", "platform", "." ]
[ "/* CONFIG_X2APIC */" ]
[ { "param": "vector", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vector", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1084efe4b7688494687e90c135c6287b5b4fefcc
ParticleBeamHQ/zephyr
include/zephyr/logging/log_backend.h
[ "Apache-2.0" ]
C
log_backend_msg2_process
void
static inline void log_backend_msg2_process( const struct log_backend *const backend, union log_msg2_generic *msg) { __ASSERT_NO_MSG(backend != NULL); __ASSERT_NO_MSG(msg != NULL); backend->api->process(backend, msg); }
/** * @brief Process message. * * Function is used in deferred and immediate mode. On return, message content * is processed by the backend and memory can be freed. * * @param[in] backend Pointer to the backend instance. * @param[in] msg Pointer to message with log entry. */
@brief Process message. Function is used in deferred and immediate mode. On return, message content is processed by the backend and memory can be freed. @param[in] backend Pointer to the backend instance. @param[in] msg Pointer to message with log entry.
[ "@brief", "Process", "message", ".", "Function", "is", "used", "in", "deferred", "and", "immediate", "mode", ".", "On", "return", "message", "content", "is", "processed", "by", "the", "backend", "and", "memory", "can", "be", "freed", ".", "@param", "[", "in", "]", "backend", "Pointer", "to", "the", "backend", "instance", ".", "@param", "[", "in", "]", "msg", "Pointer", "to", "message", "with", "log", "entry", "." ]
static inline void log_backend_msg2_process( const struct log_backend *const backend, union log_msg2_generic *msg) { __ASSERT_NO_MSG(backend != NULL); __ASSERT_NO_MSG(msg != NULL); backend->api->process(backend, msg); }
[ "static", "inline", "void", "log_backend_msg2_process", "(", "const", "struct", "log_backend", "*", "const", "backend", ",", "union", "log_msg2_generic", "*", "msg", ")", "{", "__ASSERT_NO_MSG", "(", "backend", "!=", "NULL", ")", ";", "__ASSERT_NO_MSG", "(", "msg", "!=", "NULL", ")", ";", "backend", "->", "api", "->", "process", "(", "backend", ",", "msg", ")", ";", "}" ]
@brief Process message.
[ "@brief", "Process", "message", "." ]
[]
[ { "param": "backend", "type": "struct log_backend" }, { "param": "msg", "type": "union log_msg2_generic" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "backend", "type": "struct log_backend", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "union log_msg2_generic", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c510f671bd900739707eff2af603078f3eb7588b
ParticleBeamHQ/zephyr
drivers/i2c/i2c_ite_enhance.c
[ "Apache-2.0" ]
C
i2c_enhanced_port_set_frequency
void
static void i2c_enhanced_port_set_frequency(const struct device *dev, int freq_hz) { const struct i2c_enhance_config *config = dev->config; uint32_t clk_div, psr, pll_clock; uint8_t *base = config->base; pll_clock = chip_get_pll_freq(); /* * Let psr(Prescale) = IT8XXX2_I2C_PSR(p_ch) * Then, 1 SCL cycle = 2 x (psr + 2) x SMBus clock cycle * SMBus clock = pll_clock / clk_div * SMBus clock cycle = 1 / SMBus clock * 1 SCL cycle = 1 / freq * 1 / freq = 2 x (psr + 2) x (1 / (pll_clock / clk_div)) * psr = ((pll_clock / clk_div) x (1 / freq) x (1 / 2)) - 2 */ if (freq_hz) { /* Get SMBus clock divide value */ clk_div = (IT8XXX2_ECPM_SCDCR2 & 0x0F) + 1U; /* Calculate PSR value */ psr = (pll_clock / (clk_div * (2U * freq_hz))) - 2U; /* Set psr value under 0xFD */ if (psr > 0xFD) { psr = 0xFD; } /* Adjust SCL low period prescale */ psr += config->prescale_scl_low; /* Set I2C Speed */ IT8XXX2_I2C_PSR(base) = psr & 0xFF; IT8XXX2_I2C_HSPR(base) = psr & 0xFF; } }
/* Set clock frequency for i2c port D, E , or F */
Set clock frequency for i2c port D, E , or F
[ "Set", "clock", "frequency", "for", "i2c", "port", "D", "E", "or", "F" ]
static void i2c_enhanced_port_set_frequency(const struct device *dev, int freq_hz) { const struct i2c_enhance_config *config = dev->config; uint32_t clk_div, psr, pll_clock; uint8_t *base = config->base; pll_clock = chip_get_pll_freq(); if (freq_hz) { clk_div = (IT8XXX2_ECPM_SCDCR2 & 0x0F) + 1U; psr = (pll_clock / (clk_div * (2U * freq_hz))) - 2U; if (psr > 0xFD) { psr = 0xFD; } psr += config->prescale_scl_low; IT8XXX2_I2C_PSR(base) = psr & 0xFF; IT8XXX2_I2C_HSPR(base) = psr & 0xFF; } }
[ "static", "void", "i2c_enhanced_port_set_frequency", "(", "const", "struct", "device", "*", "dev", ",", "int", "freq_hz", ")", "{", "const", "struct", "i2c_enhance_config", "*", "config", "=", "dev", "->", "config", ";", "uint32_t", "clk_div", ",", "psr", ",", "pll_clock", ";", "uint8_t", "*", "base", "=", "config", "->", "base", ";", "pll_clock", "=", "chip_get_pll_freq", "(", ")", ";", "if", "(", "freq_hz", ")", "{", "clk_div", "=", "(", "IT8XXX2_ECPM_SCDCR2", "&", "0x0F", ")", "+", "1U", ";", "psr", "=", "(", "pll_clock", "/", "(", "clk_div", "*", "(", "2U", "*", "freq_hz", ")", ")", ")", "-", "2U", ";", "if", "(", "psr", ">", "0xFD", ")", "{", "psr", "=", "0xFD", ";", "}", "psr", "+=", "config", "->", "prescale_scl_low", ";", "IT8XXX2_I2C_PSR", "(", "base", ")", "=", "psr", "&", "0xFF", ";", "IT8XXX2_I2C_HSPR", "(", "base", ")", "=", "psr", "&", "0xFF", ";", "}", "}" ]
Set clock frequency for i2c port D, E , or F
[ "Set", "clock", "frequency", "for", "i2c", "port", "D", "E", "or", "F" ]
[ "/*\n\t * Let psr(Prescale) = IT8XXX2_I2C_PSR(p_ch)\n\t * Then, 1 SCL cycle = 2 x (psr + 2) x SMBus clock cycle\n\t * SMBus clock = pll_clock / clk_div\n\t * SMBus clock cycle = 1 / SMBus clock\n\t * 1 SCL cycle = 1 / freq\n\t * 1 / freq = 2 x (psr + 2) x (1 / (pll_clock / clk_div))\n\t * psr = ((pll_clock / clk_div) x (1 / freq) x (1 / 2)) - 2\n\t */", "/* Get SMBus clock divide value */", "/* Calculate PSR value */", "/* Set psr value under 0xFD */", "/* Adjust SCL low period prescale */", "/* Set I2C Speed */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "freq_hz", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "freq_hz", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8de26138efa70c41fef392a03028f89dafdf1cd0
ParticleBeamHQ/zephyr
tests/subsys/pm/power_domain/src/main.c
[ "Apache-2.0" ]
C
devb_pm_action
int
static int devb_pm_action(const struct device *dev, enum pm_device_action pm_action) { int ret = 0; ARG_UNUSED(dev); if (testing_domain_on_notitication > 0) { if (pm_action == PM_DEVICE_ACTION_TURN_ON) { ret = -ENOTSUP; testing_domain_on_notitication--; } } else if (testing_domain_off_notitication > 0) { if (pm_action == PM_DEVICE_ACTION_TURN_OFF) { ret = -ENOTSUP; testing_domain_off_notitication--; } } return ret; }
/* * Device B will return -ENOTSUP for TURN_ON and TURN_OFF actions. * This way we can check if the subsystem properly handled its state. */
Device B will return -ENOTSUP for TURN_ON and TURN_OFF actions. This way we can check if the subsystem properly handled its state.
[ "Device", "B", "will", "return", "-", "ENOTSUP", "for", "TURN_ON", "and", "TURN_OFF", "actions", ".", "This", "way", "we", "can", "check", "if", "the", "subsystem", "properly", "handled", "its", "state", "." ]
static int devb_pm_action(const struct device *dev, enum pm_device_action pm_action) { int ret = 0; ARG_UNUSED(dev); if (testing_domain_on_notitication > 0) { if (pm_action == PM_DEVICE_ACTION_TURN_ON) { ret = -ENOTSUP; testing_domain_on_notitication--; } } else if (testing_domain_off_notitication > 0) { if (pm_action == PM_DEVICE_ACTION_TURN_OFF) { ret = -ENOTSUP; testing_domain_off_notitication--; } } return ret; }
[ "static", "int", "devb_pm_action", "(", "const", "struct", "device", "*", "dev", ",", "enum", "pm_device_action", "pm_action", ")", "{", "int", "ret", "=", "0", ";", "ARG_UNUSED", "(", "dev", ")", ";", "if", "(", "testing_domain_on_notitication", ">", "0", ")", "{", "if", "(", "pm_action", "==", "PM_DEVICE_ACTION_TURN_ON", ")", "{", "ret", "=", "-", "ENOTSUP", ";", "testing_domain_on_notitication", "--", ";", "}", "}", "else", "if", "(", "testing_domain_off_notitication", ">", "0", ")", "{", "if", "(", "pm_action", "==", "PM_DEVICE_ACTION_TURN_OFF", ")", "{", "ret", "=", "-", "ENOTSUP", ";", "testing_domain_off_notitication", "--", ";", "}", "}", "return", "ret", ";", "}" ]
Device B will return -ENOTSUP for TURN_ON and TURN_OFF actions.
[ "Device", "B", "will", "return", "-", "ENOTSUP", "for", "TURN_ON", "and", "TURN_OFF", "actions", "." ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "pm_action", "type": "enum pm_device_action" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pm_action", "type": "enum pm_device_action", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
101a13d4e52baf0c7aac159faf1d4590160f294a
ParticleBeamHQ/zephyr
drivers/pinctrl/pinctrl_stm32.c
[ "Apache-2.0" ]
C
stm32_pins_remap
int
static int stm32_pins_remap(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt) { uint32_t reg_val; uint16_t remap; remap = (uint16_t)STM32_DT_PINMUX_REMAP(pins[0].pinmux); /* not remappable */ if (remap == NO_REMAP) { return 0; } for (size_t i = 1U; i < pin_cnt; i++) { if (STM32_DT_PINMUX_REMAP(pins[i].pinmux) != remap) { return -EINVAL; } } /* A valid remapping configuration is available */ /* Apply remapping before proceeding with pin configuration */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); if (STM32_REMAP_REG_GET(remap) == 0U) { /* read initial value, ignore write-only SWJ_CFG */ reg_val = AFIO->MAPR & ~AFIO_MAPR_SWJ_CFG; reg_val |= STM32_REMAP_VAL_GET(remap) << STM32_REMAP_SHIFT_GET(remap); /* apply undocumented '111' (AFIO_MAPR_SWJ_CFG) to affirm SWJ_CFG */ /* the pins are not remapped without that (when SWJ_CFG is not default) */ AFIO->MAPR = reg_val | AFIO_MAPR_SWJ_CFG; } else { reg_val = AFIO->MAPR2; reg_val |= STM32_REMAP_VAL_GET(remap) << STM32_REMAP_SHIFT_GET(remap); AFIO->MAPR2 = reg_val; } return 0; }
/** * @brief Helper function to check and apply provided pinctrl remap * configuration. * * Check operation verifies that pin remapping configuration is the same on all * pins. If configuration is valid AFIO clock is enabled and remap is applied * * @param pins List of pins to be configured. * @param pin_cnt Number of pins. * * @retval 0 If successful * @retval -EINVAL If pins have an incompatible set of remaps. */
@brief Helper function to check and apply provided pinctrl remap configuration. Check operation verifies that pin remapping configuration is the same on all pins. If configuration is valid AFIO clock is enabled and remap is applied @param pins List of pins to be configured. @param pin_cnt Number of pins. @retval 0 If successful @retval -EINVAL If pins have an incompatible set of remaps.
[ "@brief", "Helper", "function", "to", "check", "and", "apply", "provided", "pinctrl", "remap", "configuration", ".", "Check", "operation", "verifies", "that", "pin", "remapping", "configuration", "is", "the", "same", "on", "all", "pins", ".", "If", "configuration", "is", "valid", "AFIO", "clock", "is", "enabled", "and", "remap", "is", "applied", "@param", "pins", "List", "of", "pins", "to", "be", "configured", ".", "@param", "pin_cnt", "Number", "of", "pins", ".", "@retval", "0", "If", "successful", "@retval", "-", "EINVAL", "If", "pins", "have", "an", "incompatible", "set", "of", "remaps", "." ]
static int stm32_pins_remap(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt) { uint32_t reg_val; uint16_t remap; remap = (uint16_t)STM32_DT_PINMUX_REMAP(pins[0].pinmux); if (remap == NO_REMAP) { return 0; } for (size_t i = 1U; i < pin_cnt; i++) { if (STM32_DT_PINMUX_REMAP(pins[i].pinmux) != remap) { return -EINVAL; } } LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); if (STM32_REMAP_REG_GET(remap) == 0U) { reg_val = AFIO->MAPR & ~AFIO_MAPR_SWJ_CFG; reg_val |= STM32_REMAP_VAL_GET(remap) << STM32_REMAP_SHIFT_GET(remap); AFIO->MAPR = reg_val | AFIO_MAPR_SWJ_CFG; } else { reg_val = AFIO->MAPR2; reg_val |= STM32_REMAP_VAL_GET(remap) << STM32_REMAP_SHIFT_GET(remap); AFIO->MAPR2 = reg_val; } return 0; }
[ "static", "int", "stm32_pins_remap", "(", "const", "pinctrl_soc_pin_t", "*", "pins", ",", "uint8_t", "pin_cnt", ")", "{", "uint32_t", "reg_val", ";", "uint16_t", "remap", ";", "remap", "=", "(", "uint16_t", ")", "STM32_DT_PINMUX_REMAP", "(", "pins", "[", "0", "]", ".", "pinmux", ")", ";", "if", "(", "remap", "==", "NO_REMAP", ")", "{", "return", "0", ";", "}", "for", "(", "size_t", "i", "=", "1U", ";", "i", "<", "pin_cnt", ";", "i", "++", ")", "{", "if", "(", "STM32_DT_PINMUX_REMAP", "(", "pins", "[", "i", "]", ".", "pinmux", ")", "!=", "remap", ")", "{", "return", "-", "EINVAL", ";", "}", "}", "LL_APB2_GRP1_EnableClock", "(", "LL_APB2_GRP1_PERIPH_AFIO", ")", ";", "if", "(", "STM32_REMAP_REG_GET", "(", "remap", ")", "==", "0U", ")", "{", "reg_val", "=", "AFIO", "->", "MAPR", "&", "~", "AFIO_MAPR_SWJ_CFG", ";", "reg_val", "|=", "STM32_REMAP_VAL_GET", "(", "remap", ")", "<<", "STM32_REMAP_SHIFT_GET", "(", "remap", ")", ";", "AFIO", "->", "MAPR", "=", "reg_val", "|", "AFIO_MAPR_SWJ_CFG", ";", "}", "else", "{", "reg_val", "=", "AFIO", "->", "MAPR2", ";", "reg_val", "|=", "STM32_REMAP_VAL_GET", "(", "remap", ")", "<<", "STM32_REMAP_SHIFT_GET", "(", "remap", ")", ";", "AFIO", "->", "MAPR2", "=", "reg_val", ";", "}", "return", "0", ";", "}" ]
@brief Helper function to check and apply provided pinctrl remap configuration.
[ "@brief", "Helper", "function", "to", "check", "and", "apply", "provided", "pinctrl", "remap", "configuration", "." ]
[ "/* not remappable */", "/* A valid remapping configuration is available */", "/* Apply remapping before proceeding with pin configuration */", "/* read initial value, ignore write-only SWJ_CFG */", "/* apply undocumented '111' (AFIO_MAPR_SWJ_CFG) to affirm SWJ_CFG */", "/* the pins are not remapped without that (when SWJ_CFG is not default) */" ]
[ { "param": "pins", "type": "pinctrl_soc_pin_t" }, { "param": "pin_cnt", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pins", "type": "pinctrl_soc_pin_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pin_cnt", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
80d3561cbe31558af97a4051a5ef8c63bce3ddfa
ParticleBeamHQ/zephyr
lib/posix/pthread_mutex.c
[ "Apache-2.0" ]
C
pthread_mutex_timedlock
int
int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *abstime) { int32_t timeout = (int32_t)timespec_to_timeoutms(abstime); return acquire_mutex(m, K_MSEC(timeout)); }
/** * @brief Lock POSIX mutex with timeout. * * * See IEEE 1003.1 */
@brief Lock POSIX mutex with timeout.
[ "@brief", "Lock", "POSIX", "mutex", "with", "timeout", "." ]
int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *abstime) { int32_t timeout = (int32_t)timespec_to_timeoutms(abstime); return acquire_mutex(m, K_MSEC(timeout)); }
[ "int", "pthread_mutex_timedlock", "(", "pthread_mutex_t", "*", "m", ",", "const", "struct", "timespec", "*", "abstime", ")", "{", "int32_t", "timeout", "=", "(", "int32_t", ")", "timespec_to_timeoutms", "(", "abstime", ")", ";", "return", "acquire_mutex", "(", "m", ",", "K_MSEC", "(", "timeout", ")", ")", ";", "}" ]
@brief Lock POSIX mutex with timeout.
[ "@brief", "Lock", "POSIX", "mutex", "with", "timeout", "." ]
[]
[ { "param": "m", "type": "pthread_mutex_t" }, { "param": "abstime", "type": "struct timespec" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "m", "type": "pthread_mutex_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "abstime", "type": "struct timespec", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
84184f4437fe7705bbd25d8dd7c79d5b150b74c8
ParticleBeamHQ/zephyr
drivers/ipm/ipm_cavs_host.c
[ "Apache-2.0" ]
C
send
int
static int send(const struct device *ipmdev, int wait, uint32_t id, const void *data, int size) { if (!cavs_ipc_is_complete(CAVS_HOST_DEV)) { return -EBUSY; } if (size > MAX_MSG) { return -EMSGSIZE; } if ((id & 0xc0000000) != 0) { /* cAVS IDR register has only 30 usable bits */ return -EINVAL; } uint32_t ext_data = 0; /* Protocol variant (used by SOF "ipc4"): store the first word * of the message in the IPC scratch registers */ if (IS_ENABLED(CONFIG_IPM_CAVS_HOST_REGWORD) && size >= 4) { ext_data = ((uint32_t *)data)[0]; data = &((const uint32_t *)data)[1]; size -= 4; } memcpy(MSG_OUTBUF, data, size); bool ok = cavs_ipc_send_message(CAVS_HOST_DEV, id, ext_data); /* The IPM docs call for "busy waiting" here, but in fact * there's a blocking synchronous call available that might be * better. But then we'd have to check whether we're in * interrupt context, and it's not clear to me that SOF would * benefit anyway as all its usage is async. This is OK for * now. */ if (ok && wait) { while (!cavs_ipc_is_complete(CAVS_HOST_DEV)) { k_busy_wait(1); } } return ok ? 0 : -EBUSY; }
/* Note: this call is unsynchronized. The IPM docs are silent as to * whether this is required, and the SOF code that will be using this * is externally synchronized already. */
this call is unsynchronized. The IPM docs are silent as to whether this is required, and the SOF code that will be using this is externally synchronized already.
[ "this", "call", "is", "unsynchronized", ".", "The", "IPM", "docs", "are", "silent", "as", "to", "whether", "this", "is", "required", "and", "the", "SOF", "code", "that", "will", "be", "using", "this", "is", "externally", "synchronized", "already", "." ]
static int send(const struct device *ipmdev, int wait, uint32_t id, const void *data, int size) { if (!cavs_ipc_is_complete(CAVS_HOST_DEV)) { return -EBUSY; } if (size > MAX_MSG) { return -EMSGSIZE; } if ((id & 0xc0000000) != 0) { return -EINVAL; } uint32_t ext_data = 0; if (IS_ENABLED(CONFIG_IPM_CAVS_HOST_REGWORD) && size >= 4) { ext_data = ((uint32_t *)data)[0]; data = &((const uint32_t *)data)[1]; size -= 4; } memcpy(MSG_OUTBUF, data, size); bool ok = cavs_ipc_send_message(CAVS_HOST_DEV, id, ext_data); if (ok && wait) { while (!cavs_ipc_is_complete(CAVS_HOST_DEV)) { k_busy_wait(1); } } return ok ? 0 : -EBUSY; }
[ "static", "int", "send", "(", "const", "struct", "device", "*", "ipmdev", ",", "int", "wait", ",", "uint32_t", "id", ",", "const", "void", "*", "data", ",", "int", "size", ")", "{", "if", "(", "!", "cavs_ipc_is_complete", "(", "CAVS_HOST_DEV", ")", ")", "{", "return", "-", "EBUSY", ";", "}", "if", "(", "size", ">", "MAX_MSG", ")", "{", "return", "-", "EMSGSIZE", ";", "}", "if", "(", "(", "id", "&", "0xc0000000", ")", "!=", "0", ")", "{", "return", "-", "EINVAL", ";", "}", "uint32_t", "ext_data", "=", "0", ";", "if", "(", "IS_ENABLED", "(", "CONFIG_IPM_CAVS_HOST_REGWORD", ")", "&&", "size", ">=", "4", ")", "{", "ext_data", "=", "(", "(", "uint32_t", "*", ")", "data", ")", "[", "0", "]", ";", "data", "=", "&", "(", "(", "const", "uint32_t", "*", ")", "data", ")", "[", "1", "]", ";", "size", "-=", "4", ";", "}", "memcpy", "(", "MSG_OUTBUF", ",", "data", ",", "size", ")", ";", "bool", "ok", "=", "cavs_ipc_send_message", "(", "CAVS_HOST_DEV", ",", "id", ",", "ext_data", ")", ";", "if", "(", "ok", "&&", "wait", ")", "{", "while", "(", "!", "cavs_ipc_is_complete", "(", "CAVS_HOST_DEV", ")", ")", "{", "k_busy_wait", "(", "1", ")", ";", "}", "}", "return", "ok", "?", "0", ":", "-", "EBUSY", ";", "}" ]
Note: this call is unsynchronized.
[ "Note", ":", "this", "call", "is", "unsynchronized", "." ]
[ "/* cAVS IDR register has only 30 usable bits */", "/* Protocol variant (used by SOF \"ipc4\"): store the first word\n\t * of the message in the IPC scratch registers\n\t */", "/* The IPM docs call for \"busy waiting\" here, but in fact\n\t * there's a blocking synchronous call available that might be\n\t * better. But then we'd have to check whether we're in\n\t * interrupt context, and it's not clear to me that SOF would\n\t * benefit anyway as all its usage is async. This is OK for\n\t * now.\n\t */" ]
[ { "param": "ipmdev", "type": "struct device" }, { "param": "wait", "type": "int" }, { "param": "id", "type": "uint32_t" }, { "param": "data", "type": "void" }, { "param": "size", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ipmdev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wait", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "id", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c9f5b72a81ab0951b95aa80e342d1f341170385c
ParticleBeamHQ/zephyr
soc/arm/nxp_imx/rt/power_rt11xx.c
[ "Apache-2.0" ]
C
gpc_set_core_mappings
void
static void gpc_set_core_mappings(void) { uint8_t i, j; uint32_t tmp; #ifdef CONFIG_CPU_CORTEX_M7 uint8_t mapping[SET_POINT_COUNT][SET_POINT_COUNT] = CPU0_COMPATIBLE_SP_TABLE; #elif CONFIG_CPU_CORTEX_M4 uint8_t mapping[SET_POINT_COUNT][SET_POINT_COUNT] = CPU1_COMPATIBLE_SP_TABLE; #else #error "RT11xx power code supports M4 and M7 cores only" #endif /* Cortex Set point mappings */ for (i = 0; i < SET_POINT_COUNT; i++) { tmp = 0x0; for (j = 0; j < SET_POINT_COUNT; j++) { tmp |= mapping[i][j] << mapping[0][j]; } GPC_CM_SetSetPointMapping(GPC_CPU_MODE_CTRL, mapping[i][0], tmp); } }
/* Configure the set point mappings for Cortex M4 and M7 cores */
Configure the set point mappings for Cortex M4 and M7 cores
[ "Configure", "the", "set", "point", "mappings", "for", "Cortex", "M4", "and", "M7", "cores" ]
static void gpc_set_core_mappings(void) { uint8_t i, j; uint32_t tmp; #ifdef CONFIG_CPU_CORTEX_M7 uint8_t mapping[SET_POINT_COUNT][SET_POINT_COUNT] = CPU0_COMPATIBLE_SP_TABLE; #elif CONFIG_CPU_CORTEX_M4 uint8_t mapping[SET_POINT_COUNT][SET_POINT_COUNT] = CPU1_COMPATIBLE_SP_TABLE; #else #error "RT11xx power code supports M4 and M7 cores only" #endif for (i = 0; i < SET_POINT_COUNT; i++) { tmp = 0x0; for (j = 0; j < SET_POINT_COUNT; j++) { tmp |= mapping[i][j] << mapping[0][j]; } GPC_CM_SetSetPointMapping(GPC_CPU_MODE_CTRL, mapping[i][0], tmp); } }
[ "static", "void", "gpc_set_core_mappings", "(", "void", ")", "{", "uint8_t", "i", ",", "j", ";", "uint32_t", "tmp", ";", "#ifdef", "CONFIG_CPU_CORTEX_M7", "uint8_t", "mapping", "[", "SET_POINT_COUNT", "]", "[", "SET_POINT_COUNT", "]", "=", "CPU0_COMPATIBLE_SP_TABLE", ";", "#elif", "CONFIG_CPU_CORTEX_M4", "\n", "uint8_t", "mapping", "[", "SET_POINT_COUNT", "]", "[", "SET_POINT_COUNT", "]", "=", "CPU1_COMPATIBLE_SP_TABLE", ";", "#else", "#error", " \"RT11xx power code supports M4 and M7 cores only\"", "\n", "#endif", "for", "(", "i", "=", "0", ";", "i", "<", "SET_POINT_COUNT", ";", "i", "++", ")", "{", "tmp", "=", "0x0", ";", "for", "(", "j", "=", "0", ";", "j", "<", "SET_POINT_COUNT", ";", "j", "++", ")", "{", "tmp", "|=", "mapping", "[", "i", "]", "[", "j", "]", "<<", "mapping", "[", "0", "]", "[", "j", "]", ";", "}", "GPC_CM_SetSetPointMapping", "(", "GPC_CPU_MODE_CTRL", ",", "mapping", "[", "i", "]", "[", "0", "]", ",", "tmp", ")", ";", "}", "}" ]
Configure the set point mappings for Cortex M4 and M7 cores
[ "Configure", "the", "set", "point", "mappings", "for", "Cortex", "M4", "and", "M7", "cores" ]
[ "/* Cortex Set point mappings */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c9f5b72a81ab0951b95aa80e342d1f341170385c
ParticleBeamHQ/zephyr
soc/arm/nxp_imx/rt/power_rt11xx.c
[ "Apache-2.0" ]
C
gpc_set_transition_flow
void
static void gpc_set_transition_flow(void) { gpc_tran_step_config_t step_cfg; step_cfg.enableStep = true; step_cfg.cntMode = kGPC_StepCounterDisableMode; /* Cortex M7 */ GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepSsar, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepLpcg, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepPll, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepIso, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepReset, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepPower, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupPower, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupReset, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupIso, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupPll, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupLpcg, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupSsar, &step_cfg); /* Enable all steps in flow of set point transition */ GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_SsarSave, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LpcgOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_GroupDown, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_RootDown, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PllOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_IsoOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_ResetEarly, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PowerOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BiasOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BandgapPllLdoOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LdoPre, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_DcdcDown, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_DcdcUp, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LdoPost, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BandgapPllLdoOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BiasOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PowerOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_ResetLate, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_IsoOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PllOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_RootUp, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_GroupUp, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LpcgOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_SsarRestore, &step_cfg); /* Enable all steps in standby transition */ GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LpcgIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PllIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BiasIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PldoIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BandgapIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LdoIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_DcdcIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PmicIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PmicOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_DcdcOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LdoOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BandgapOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PldoOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BiasOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PllOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LpcgOut, &step_cfg); }
/* Configure GPC transition steps to enabled */
Configure GPC transition steps to enabled
[ "Configure", "GPC", "transition", "steps", "to", "enabled" ]
static void gpc_set_transition_flow(void) { gpc_tran_step_config_t step_cfg; step_cfg.enableStep = true; step_cfg.cntMode = kGPC_StepCounterDisableMode; GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepSsar, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepLpcg, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepPll, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepIso, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepReset, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_SleepPower, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupPower, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupReset, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupIso, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupPll, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupLpcg, &step_cfg); GPC_CM_ConfigCpuModeTransitionStep(GPC_CPU_MODE_CTRL, kGPC_CM_WakeupSsar, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_SsarSave, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LpcgOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_GroupDown, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_RootDown, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PllOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_IsoOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_ResetEarly, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PowerOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BiasOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BandgapPllLdoOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LdoPre, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_DcdcDown, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_DcdcUp, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LdoPost, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BandgapPllLdoOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_BiasOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PowerOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_ResetLate, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_IsoOff, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_PllOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_RootUp, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_GroupUp, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_LpcgOn, &step_cfg); GPC_SP_ConfigSetPointTransitionStep(GPC_SET_POINT_CTRL, kGPC_SP_SsarRestore, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LpcgIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PllIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BiasIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PldoIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BandgapIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LdoIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_DcdcIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PmicIn, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PmicOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_DcdcOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LdoOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BandgapOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PldoOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_BiasOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_PllOut, &step_cfg); GPC_STBY_ConfigStandbyTransitionStep(GPC_STBY_CTRL, kGPC_STBY_LpcgOut, &step_cfg); }
[ "static", "void", "gpc_set_transition_flow", "(", "void", ")", "{", "gpc_tran_step_config_t", "step_cfg", ";", "step_cfg", ".", "enableStep", "=", "true", ";", "step_cfg", ".", "cntMode", "=", "kGPC_StepCounterDisableMode", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_SleepSsar", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_SleepLpcg", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_SleepPll", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_SleepIso", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_SleepReset", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_SleepPower", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_WakeupPower", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_WakeupReset", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_WakeupIso", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_WakeupPll", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_WakeupLpcg", ",", "&", "step_cfg", ")", ";", "GPC_CM_ConfigCpuModeTransitionStep", "(", "GPC_CPU_MODE_CTRL", ",", "kGPC_CM_WakeupSsar", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_SsarSave", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_LpcgOff", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_GroupDown", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_RootDown", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_PllOff", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_IsoOn", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_ResetEarly", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_PowerOff", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_BiasOff", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_BandgapPllLdoOff", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_LdoPre", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_DcdcDown", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_DcdcUp", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_LdoPost", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_BandgapPllLdoOn", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_BiasOn", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_PowerOn", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_ResetLate", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_IsoOff", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_PllOn", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_RootUp", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_GroupUp", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_LpcgOn", ",", "&", "step_cfg", ")", ";", "GPC_SP_ConfigSetPointTransitionStep", "(", "GPC_SET_POINT_CTRL", ",", "kGPC_SP_SsarRestore", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_LpcgIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_PllIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_BiasIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_PldoIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_BandgapIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_LdoIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_DcdcIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_PmicIn", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_PmicOut", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_DcdcOut", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_LdoOut", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_BandgapOut", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_PldoOut", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_BiasOut", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_PllOut", ",", "&", "step_cfg", ")", ";", "GPC_STBY_ConfigStandbyTransitionStep", "(", "GPC_STBY_CTRL", ",", "kGPC_STBY_LpcgOut", ",", "&", "step_cfg", ")", ";", "}" ]
Configure GPC transition steps to enabled
[ "Configure", "GPC", "transition", "steps", "to", "enabled" ]
[ "/* Cortex M7 */", "/* Enable all steps in flow of set point transition */", "/* Enable all steps in standby transition */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c9f5b72a81ab0951b95aa80e342d1f341170385c
ParticleBeamHQ/zephyr
soc/arm/nxp_imx/rt/power_rt11xx.c
[ "Apache-2.0" ]
C
dcdc_init
void
static void dcdc_init(void) { dcdc_config_t dcdc_config; dcdc_setpoint_config_t dcdc_setpoint_config; dcdc_buck_mode_1P8_target_vol_t buck1_8_voltage[16] = DCDC_1P8_BUCK_MODE_CONFIGURATION_TABLE; dcdc_buck_mode_1P0_target_vol_t buck1_0_voltage[16] = DCDC_1P0_BUCK_MODE_CONFIGURATION_TABLE; dcdc_standby_mode_1P8_target_vol_t standby1_8_voltage[16] = DCDC_1P8_STANDBY_MODE_CONFIGURATION_TABLE; dcdc_standby_mode_1P0_target_vol_t standby1_0_voltage[16] = DCDC_1P0_STANDBY_MODE_CONFIGURATION_TABLE; DCDC_BootIntoDCM(DCDC); dcdc_setpoint_config.enableDCDCMap = DCDC_ONOFF_SP_VAL; dcdc_setpoint_config.enableDigLogicMap = DCDC_DIG_ONOFF_SP_VAL; dcdc_setpoint_config.lowpowerMap = DCDC_LP_MODE_SP_VAL; dcdc_setpoint_config.standbyMap = DCDC_ONOFF_STBY_VAL; dcdc_setpoint_config.standbyLowpowerMap = DCDC_LP_MODE_STBY_VAL; dcdc_setpoint_config.buckVDD1P8TargetVoltage = buck1_8_voltage; dcdc_setpoint_config.buckVDD1P0TargetVoltage = buck1_0_voltage; dcdc_setpoint_config.standbyVDD1P8TargetVoltage = standby1_8_voltage; dcdc_setpoint_config.standbyVDD1P0TargetVoltage = standby1_0_voltage; DCDC_SetPointInit(DCDC, &dcdc_setpoint_config); DCDC_GetDefaultConfig(&dcdc_config); dcdc_config.controlMode = kDCDC_SetPointControl; DCDC_Init(DCDC, &dcdc_config); }
/* Initializes DCDC converter with power saving settings */
Initializes DCDC converter with power saving settings
[ "Initializes", "DCDC", "converter", "with", "power", "saving", "settings" ]
static void dcdc_init(void) { dcdc_config_t dcdc_config; dcdc_setpoint_config_t dcdc_setpoint_config; dcdc_buck_mode_1P8_target_vol_t buck1_8_voltage[16] = DCDC_1P8_BUCK_MODE_CONFIGURATION_TABLE; dcdc_buck_mode_1P0_target_vol_t buck1_0_voltage[16] = DCDC_1P0_BUCK_MODE_CONFIGURATION_TABLE; dcdc_standby_mode_1P8_target_vol_t standby1_8_voltage[16] = DCDC_1P8_STANDBY_MODE_CONFIGURATION_TABLE; dcdc_standby_mode_1P0_target_vol_t standby1_0_voltage[16] = DCDC_1P0_STANDBY_MODE_CONFIGURATION_TABLE; DCDC_BootIntoDCM(DCDC); dcdc_setpoint_config.enableDCDCMap = DCDC_ONOFF_SP_VAL; dcdc_setpoint_config.enableDigLogicMap = DCDC_DIG_ONOFF_SP_VAL; dcdc_setpoint_config.lowpowerMap = DCDC_LP_MODE_SP_VAL; dcdc_setpoint_config.standbyMap = DCDC_ONOFF_STBY_VAL; dcdc_setpoint_config.standbyLowpowerMap = DCDC_LP_MODE_STBY_VAL; dcdc_setpoint_config.buckVDD1P8TargetVoltage = buck1_8_voltage; dcdc_setpoint_config.buckVDD1P0TargetVoltage = buck1_0_voltage; dcdc_setpoint_config.standbyVDD1P8TargetVoltage = standby1_8_voltage; dcdc_setpoint_config.standbyVDD1P0TargetVoltage = standby1_0_voltage; DCDC_SetPointInit(DCDC, &dcdc_setpoint_config); DCDC_GetDefaultConfig(&dcdc_config); dcdc_config.controlMode = kDCDC_SetPointControl; DCDC_Init(DCDC, &dcdc_config); }
[ "static", "void", "dcdc_init", "(", "void", ")", "{", "dcdc_config_t", "dcdc_config", ";", "dcdc_setpoint_config_t", "dcdc_setpoint_config", ";", "dcdc_buck_mode_1P8_target_vol_t", "buck1_8_voltage", "[", "16", "]", "=", "DCDC_1P8_BUCK_MODE_CONFIGURATION_TABLE", ";", "dcdc_buck_mode_1P0_target_vol_t", "buck1_0_voltage", "[", "16", "]", "=", "DCDC_1P0_BUCK_MODE_CONFIGURATION_TABLE", ";", "dcdc_standby_mode_1P8_target_vol_t", "standby1_8_voltage", "[", "16", "]", "=", "DCDC_1P8_STANDBY_MODE_CONFIGURATION_TABLE", ";", "dcdc_standby_mode_1P0_target_vol_t", "standby1_0_voltage", "[", "16", "]", "=", "DCDC_1P0_STANDBY_MODE_CONFIGURATION_TABLE", ";", "DCDC_BootIntoDCM", "(", "DCDC", ")", ";", "dcdc_setpoint_config", ".", "enableDCDCMap", "=", "DCDC_ONOFF_SP_VAL", ";", "dcdc_setpoint_config", ".", "enableDigLogicMap", "=", "DCDC_DIG_ONOFF_SP_VAL", ";", "dcdc_setpoint_config", ".", "lowpowerMap", "=", "DCDC_LP_MODE_SP_VAL", ";", "dcdc_setpoint_config", ".", "standbyMap", "=", "DCDC_ONOFF_STBY_VAL", ";", "dcdc_setpoint_config", ".", "standbyLowpowerMap", "=", "DCDC_LP_MODE_STBY_VAL", ";", "dcdc_setpoint_config", ".", "buckVDD1P8TargetVoltage", "=", "buck1_8_voltage", ";", "dcdc_setpoint_config", ".", "buckVDD1P0TargetVoltage", "=", "buck1_0_voltage", ";", "dcdc_setpoint_config", ".", "standbyVDD1P8TargetVoltage", "=", "standby1_8_voltage", ";", "dcdc_setpoint_config", ".", "standbyVDD1P0TargetVoltage", "=", "standby1_0_voltage", ";", "DCDC_SetPointInit", "(", "DCDC", ",", "&", "dcdc_setpoint_config", ")", ";", "DCDC_GetDefaultConfig", "(", "&", "dcdc_config", ")", ";", "dcdc_config", ".", "controlMode", "=", "kDCDC_SetPointControl", ";", "DCDC_Init", "(", "DCDC", ",", "&", "dcdc_config", ")", ";", "}" ]
Initializes DCDC converter with power saving settings
[ "Initializes", "DCDC", "converter", "with", "power", "saving", "settings" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
328bf86c55b7df4bbeff793cf4eda6a0fe3fff9c
ParticleBeamHQ/zephyr
drivers/espi/espi_mchp_xec_host_v2.c
[ "Apache-2.0" ]
C
mbox0_isr
void
static void mbox0_isr(const struct device *dev) { uint8_t girq = MCHP_XEC_ECIA_GIRQ(xec_mbox0_cfg.ecia_info); uint8_t bitpos = MCHP_XEC_ECIA_GIRQ_POS(xec_mbox0_cfg.ecia_info); /* clear GIRQ source, inline version */ mchp_soc_ecia_girq_src_clr(girq, bitpos); }
/* dev is a pointer to espi0 (parent) device */
dev is a pointer to espi0 (parent) device
[ "dev", "is", "a", "pointer", "to", "espi0", "(", "parent", ")", "device" ]
static void mbox0_isr(const struct device *dev) { uint8_t girq = MCHP_XEC_ECIA_GIRQ(xec_mbox0_cfg.ecia_info); uint8_t bitpos = MCHP_XEC_ECIA_GIRQ_POS(xec_mbox0_cfg.ecia_info); mchp_soc_ecia_girq_src_clr(girq, bitpos); }
[ "static", "void", "mbox0_isr", "(", "const", "struct", "device", "*", "dev", ")", "{", "uint8_t", "girq", "=", "MCHP_XEC_ECIA_GIRQ", "(", "xec_mbox0_cfg", ".", "ecia_info", ")", ";", "uint8_t", "bitpos", "=", "MCHP_XEC_ECIA_GIRQ_POS", "(", "xec_mbox0_cfg", ".", "ecia_info", ")", ";", "mchp_soc_ecia_girq_src_clr", "(", "girq", ",", "bitpos", ")", ";", "}" ]
dev is a pointer to espi0 (parent) device
[ "dev", "is", "a", "pointer", "to", "espi0", "(", "parent", ")", "device" ]
[ "/* clear GIRQ source, inline version */" ]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
328bf86c55b7df4bbeff793cf4eda6a0fe3fff9c
ParticleBeamHQ/zephyr
drivers/espi/espi_mchp_xec_host_v2.c
[ "Apache-2.0" ]
C
init_mbox0
int
static int init_mbox0(const struct device *dev) { struct espi_xec_config *const cfg = ESPI_XEC_CONFIG(dev); struct espi_iom_regs *regs = (struct espi_iom_regs *)cfg->base_addr; regs->IOHBAR[IOB_MBOX] = ESPI_XEC_MBOX_BAR_ADDRESS | MCHP_ESPI_IO_BAR_HOST_VALID; return 0; }
/* Called by eSPI Bus init, eSPI reset de-assertion, and eSPI Platform Reset * de-assertion. */
Called by eSPI Bus init, eSPI reset de-assertion, and eSPI Platform Reset de-assertion.
[ "Called", "by", "eSPI", "Bus", "init", "eSPI", "reset", "de", "-", "assertion", "and", "eSPI", "Platform", "Reset", "de", "-", "assertion", "." ]
static int init_mbox0(const struct device *dev) { struct espi_xec_config *const cfg = ESPI_XEC_CONFIG(dev); struct espi_iom_regs *regs = (struct espi_iom_regs *)cfg->base_addr; regs->IOHBAR[IOB_MBOX] = ESPI_XEC_MBOX_BAR_ADDRESS | MCHP_ESPI_IO_BAR_HOST_VALID; return 0; }
[ "static", "int", "init_mbox0", "(", "const", "struct", "device", "*", "dev", ")", "{", "struct", "espi_xec_config", "*", "const", "cfg", "=", "ESPI_XEC_CONFIG", "(", "dev", ")", ";", "struct", "espi_iom_regs", "*", "regs", "=", "(", "struct", "espi_iom_regs", "*", ")", "cfg", "->", "base_addr", ";", "regs", "->", "IOHBAR", "[", "IOB_MBOX", "]", "=", "ESPI_XEC_MBOX_BAR_ADDRESS", "|", "MCHP_ESPI_IO_BAR_HOST_VALID", ";", "return", "0", ";", "}" ]
Called by eSPI Bus init, eSPI reset de-assertion, and eSPI Platform Reset de-assertion.
[ "Called", "by", "eSPI", "Bus", "init", "eSPI", "reset", "de", "-", "assertion", "and", "eSPI", "Platform", "Reset", "de", "-", "assertion", "." ]
[]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
328bf86c55b7df4bbeff793cf4eda6a0fe3fff9c
ParticleBeamHQ/zephyr
drivers/espi/espi_mchp_xec_host_v2.c
[ "Apache-2.0" ]
C
kbc0_rd_req
int
static int kbc0_rd_req(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data) { struct kbc_regs *kbc_hw = (struct kbc_regs *)xec_kbc0_cfg.regbase; ARG_UNUSED(dev); if (op >= E8042_START_OPCODE && op <= E8042_MAX_OPCODE) { /* Make sure kbc 8042 is on */ if (!(kbc_hw->KBC_CTRL & MCHP_KBC_CTRL_OBFEN)) { return -ENOTSUP; } switch (op) { case E8042_OBF_HAS_CHAR: /* EC has written data back to host. OBF is * automatically cleared after host reads * the data */ *data = kbc_hw->EC_KBC_STS & MCHP_KBC_STS_OBF ? 1 : 0; break; case E8042_IBF_HAS_CHAR: *data = kbc_hw->EC_KBC_STS & MCHP_KBC_STS_IBF ? 1 : 0; break; case E8042_READ_KB_STS: *data = kbc_hw->EC_KBC_STS; break; default: return -EINVAL; } } else { return -ENOTSUP; } return 0; }
/* dev is a pointer to espi0 device */
dev is a pointer to espi0 device
[ "dev", "is", "a", "pointer", "to", "espi0", "device" ]
static int kbc0_rd_req(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data) { struct kbc_regs *kbc_hw = (struct kbc_regs *)xec_kbc0_cfg.regbase; ARG_UNUSED(dev); if (op >= E8042_START_OPCODE && op <= E8042_MAX_OPCODE) { if (!(kbc_hw->KBC_CTRL & MCHP_KBC_CTRL_OBFEN)) { return -ENOTSUP; } switch (op) { case E8042_OBF_HAS_CHAR: *data = kbc_hw->EC_KBC_STS & MCHP_KBC_STS_OBF ? 1 : 0; break; case E8042_IBF_HAS_CHAR: *data = kbc_hw->EC_KBC_STS & MCHP_KBC_STS_IBF ? 1 : 0; break; case E8042_READ_KB_STS: *data = kbc_hw->EC_KBC_STS; break; default: return -EINVAL; } } else { return -ENOTSUP; } return 0; }
[ "static", "int", "kbc0_rd_req", "(", "const", "struct", "device", "*", "dev", ",", "enum", "lpc_peripheral_opcode", "op", ",", "uint32_t", "*", "data", ")", "{", "struct", "kbc_regs", "*", "kbc_hw", "=", "(", "struct", "kbc_regs", "*", ")", "xec_kbc0_cfg", ".", "regbase", ";", "ARG_UNUSED", "(", "dev", ")", ";", "if", "(", "op", ">=", "E8042_START_OPCODE", "&&", "op", "<=", "E8042_MAX_OPCODE", ")", "{", "if", "(", "!", "(", "kbc_hw", "->", "KBC_CTRL", "&", "MCHP_KBC_CTRL_OBFEN", ")", ")", "{", "return", "-", "ENOTSUP", ";", "}", "switch", "(", "op", ")", "{", "case", "E8042_OBF_HAS_CHAR", ":", "*", "data", "=", "kbc_hw", "->", "EC_KBC_STS", "&", "MCHP_KBC_STS_OBF", "?", "1", ":", "0", ";", "break", ";", "case", "E8042_IBF_HAS_CHAR", ":", "*", "data", "=", "kbc_hw", "->", "EC_KBC_STS", "&", "MCHP_KBC_STS_IBF", "?", "1", ":", "0", ";", "break", ";", "case", "E8042_READ_KB_STS", ":", "*", "data", "=", "kbc_hw", "->", "EC_KBC_STS", ";", "break", ";", "default", ":", "return", "-", "EINVAL", ";", "}", "}", "else", "{", "return", "-", "ENOTSUP", ";", "}", "return", "0", ";", "}" ]
dev is a pointer to espi0 device
[ "dev", "is", "a", "pointer", "to", "espi0", "device" ]
[ "/* Make sure kbc 8042 is on */", "/* EC has written data back to host. OBF is\n\t\t\t * automatically cleared after host reads\n\t\t\t * the data\n\t\t\t */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "op", "type": "enum lpc_peripheral_opcode" }, { "param": "data", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "op", "type": "enum lpc_peripheral_opcode", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
328bf86c55b7df4bbeff793cf4eda6a0fe3fff9c
ParticleBeamHQ/zephyr
drivers/espi/espi_mchp_xec_host_v2.c
[ "Apache-2.0" ]
C
kbc0_wr_req
int
static int kbc0_wr_req(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data) { struct kbc_regs *kbc_hw = (struct kbc_regs *)xec_kbc0_cfg.regbase; volatile uint32_t __attribute__((unused)) dummy; ARG_UNUSED(dev); if (op >= E8042_START_OPCODE && op <= E8042_MAX_OPCODE) { /* Make sure kbc 8042 is on */ if (!(kbc_hw->KBC_CTRL & MCHP_KBC_CTRL_OBFEN)) { return -ENOTSUP; } switch (op) { case E8042_WRITE_KB_CHAR: kbc_hw->EC_DATA = *data & 0xff; break; case E8042_WRITE_MB_CHAR: kbc_hw->EC_AUX_DATA = *data & 0xff; break; case E8042_RESUME_IRQ: mchp_xec_ecia_info_girq_src_clr( xec_kbc0_cfg.ibf_ecia_info); mchp_xec_ecia_info_girq_src_en( xec_kbc0_cfg.ibf_ecia_info); break; case E8042_PAUSE_IRQ: mchp_xec_ecia_info_girq_src_dis( xec_kbc0_cfg.ibf_ecia_info); break; case E8042_CLEAR_OBF: dummy = kbc_hw->HOST_AUX_DATA; break; case E8042_SET_FLAG: /* FW shouldn't modify these flags directly */ *data &= ~(MCHP_KBC_STS_OBF | MCHP_KBC_STS_IBF | MCHP_KBC_STS_AUXOBF); kbc_hw->EC_KBC_STS |= *data; break; case E8042_CLEAR_FLAG: /* FW shouldn't modify these flags directly */ *data |= (MCHP_KBC_STS_OBF | MCHP_KBC_STS_IBF | MCHP_KBC_STS_AUXOBF); kbc_hw->EC_KBC_STS &= ~(*data); break; default: return -EINVAL; } } else { return -ENOTSUP; } return 0; }
/* dev is a pointer to espi0 device */
dev is a pointer to espi0 device
[ "dev", "is", "a", "pointer", "to", "espi0", "device" ]
static int kbc0_wr_req(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data) { struct kbc_regs *kbc_hw = (struct kbc_regs *)xec_kbc0_cfg.regbase; volatile uint32_t __attribute__((unused)) dummy; ARG_UNUSED(dev); if (op >= E8042_START_OPCODE && op <= E8042_MAX_OPCODE) { if (!(kbc_hw->KBC_CTRL & MCHP_KBC_CTRL_OBFEN)) { return -ENOTSUP; } switch (op) { case E8042_WRITE_KB_CHAR: kbc_hw->EC_DATA = *data & 0xff; break; case E8042_WRITE_MB_CHAR: kbc_hw->EC_AUX_DATA = *data & 0xff; break; case E8042_RESUME_IRQ: mchp_xec_ecia_info_girq_src_clr( xec_kbc0_cfg.ibf_ecia_info); mchp_xec_ecia_info_girq_src_en( xec_kbc0_cfg.ibf_ecia_info); break; case E8042_PAUSE_IRQ: mchp_xec_ecia_info_girq_src_dis( xec_kbc0_cfg.ibf_ecia_info); break; case E8042_CLEAR_OBF: dummy = kbc_hw->HOST_AUX_DATA; break; case E8042_SET_FLAG: *data &= ~(MCHP_KBC_STS_OBF | MCHP_KBC_STS_IBF | MCHP_KBC_STS_AUXOBF); kbc_hw->EC_KBC_STS |= *data; break; case E8042_CLEAR_FLAG: *data |= (MCHP_KBC_STS_OBF | MCHP_KBC_STS_IBF | MCHP_KBC_STS_AUXOBF); kbc_hw->EC_KBC_STS &= ~(*data); break; default: return -EINVAL; } } else { return -ENOTSUP; } return 0; }
[ "static", "int", "kbc0_wr_req", "(", "const", "struct", "device", "*", "dev", ",", "enum", "lpc_peripheral_opcode", "op", ",", "uint32_t", "*", "data", ")", "{", "struct", "kbc_regs", "*", "kbc_hw", "=", "(", "struct", "kbc_regs", "*", ")", "xec_kbc0_cfg", ".", "regbase", ";", "volatile", "uint32_t", "__attribute__", "(", "(", "unused", ")", ")", "dummy", ";", "ARG_UNUSED", "(", "dev", ")", ";", "if", "(", "op", ">=", "E8042_START_OPCODE", "&&", "op", "<=", "E8042_MAX_OPCODE", ")", "{", "if", "(", "!", "(", "kbc_hw", "->", "KBC_CTRL", "&", "MCHP_KBC_CTRL_OBFEN", ")", ")", "{", "return", "-", "ENOTSUP", ";", "}", "switch", "(", "op", ")", "{", "case", "E8042_WRITE_KB_CHAR", ":", "kbc_hw", "->", "EC_DATA", "=", "*", "data", "&", "0xff", ";", "break", ";", "case", "E8042_WRITE_MB_CHAR", ":", "kbc_hw", "->", "EC_AUX_DATA", "=", "*", "data", "&", "0xff", ";", "break", ";", "case", "E8042_RESUME_IRQ", ":", "mchp_xec_ecia_info_girq_src_clr", "(", "xec_kbc0_cfg", ".", "ibf_ecia_info", ")", ";", "mchp_xec_ecia_info_girq_src_en", "(", "xec_kbc0_cfg", ".", "ibf_ecia_info", ")", ";", "break", ";", "case", "E8042_PAUSE_IRQ", ":", "mchp_xec_ecia_info_girq_src_dis", "(", "xec_kbc0_cfg", ".", "ibf_ecia_info", ")", ";", "break", ";", "case", "E8042_CLEAR_OBF", ":", "dummy", "=", "kbc_hw", "->", "HOST_AUX_DATA", ";", "break", ";", "case", "E8042_SET_FLAG", ":", "*", "data", "&=", "~", "(", "MCHP_KBC_STS_OBF", "|", "MCHP_KBC_STS_IBF", "|", "MCHP_KBC_STS_AUXOBF", ")", ";", "kbc_hw", "->", "EC_KBC_STS", "|=", "*", "data", ";", "break", ";", "case", "E8042_CLEAR_FLAG", ":", "*", "data", "|=", "(", "MCHP_KBC_STS_OBF", "|", "MCHP_KBC_STS_IBF", "|", "MCHP_KBC_STS_AUXOBF", ")", ";", "kbc_hw", "->", "EC_KBC_STS", "&=", "~", "(", "*", "data", ")", ";", "break", ";", "default", ":", "return", "-", "EINVAL", ";", "}", "}", "else", "{", "return", "-", "ENOTSUP", ";", "}", "return", "0", ";", "}" ]
dev is a pointer to espi0 device
[ "dev", "is", "a", "pointer", "to", "espi0", "device" ]
[ "/* Make sure kbc 8042 is on */", "/* FW shouldn't modify these flags directly */", "/* FW shouldn't modify these flags directly */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "op", "type": "enum lpc_peripheral_opcode" }, { "param": "data", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "op", "type": "enum lpc_peripheral_opcode", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
328bf86c55b7df4bbeff793cf4eda6a0fe3fff9c
ParticleBeamHQ/zephyr
drivers/espi/espi_mchp_xec_host_v2.c
[ "Apache-2.0" ]
C
p80bd0_isr
void
static void p80bd0_isr(const struct device *dev) { struct espi_xec_data *const data = (struct espi_xec_data *const)dev->data; struct p80bd_regs *p80regs = (struct p80bd_regs *)xec_p80bd0_cfg.regbase; struct espi_event evt = { ESPI_BUS_PERIPHERAL_NOTIFICATION, 0, ESPI_PERIPHERAL_NODATA }; int count = 8; /* limit ISR to 8 bytes */ uint32_t dattr = p80regs->EC_DA; /* b[7:0]=8-bit value written, b[15:8]=attributes */ while ((dattr & MCHP_P80BD_ECDA_NE) && (count--)) { /* Not empty? */ /* espi_event protocol No Data value is 0 so pick a bit and * set it. This depends on the application. */ evt.evt_data = (dattr & 0xffu) | BIT(16); switch (dattr & MCHP_P80BD_ECDA_LANE_MSK) { case MCHP_P80BD_ECDA_LANE_0: evt.evt_details |= (ESPI_PERIPHERAL_INDEX_0 << 16) | ESPI_PERIPHERAL_DEBUG_PORT80; break; case MCHP_P80BD_ECDA_LANE_1: evt.evt_details |= (ESPI_PERIPHERAL_INDEX_1 << 16) | ESPI_PERIPHERAL_DEBUG_PORT80; break; case MCHP_P80BD_ECDA_LANE_2: break; case MCHP_P80BD_ECDA_LANE_3: break; default: break; } if (evt.evt_details) { espi_send_callbacks(&data->callbacks, dev, evt); evt.evt_details = 0; } } /* clear GIRQ status */ mchp_xec_ecia_info_girq_src_clr(xec_p80bd0_cfg.ecia_info); }
/* * MEC172x P80 BIOS Debug Port hardware captures writes to its 4-byte I/O range * Hardware provides status indicating byte lane(s) of each write. * We must decode the byte lane information and produce one or more * notification packets. */
MEC172x P80 BIOS Debug Port hardware captures writes to its 4-byte I/O range Hardware provides status indicating byte lane(s) of each write. We must decode the byte lane information and produce one or more notification packets.
[ "MEC172x", "P80", "BIOS", "Debug", "Port", "hardware", "captures", "writes", "to", "its", "4", "-", "byte", "I", "/", "O", "range", "Hardware", "provides", "status", "indicating", "byte", "lane", "(", "s", ")", "of", "each", "write", ".", "We", "must", "decode", "the", "byte", "lane", "information", "and", "produce", "one", "or", "more", "notification", "packets", "." ]
static void p80bd0_isr(const struct device *dev) { struct espi_xec_data *const data = (struct espi_xec_data *const)dev->data; struct p80bd_regs *p80regs = (struct p80bd_regs *)xec_p80bd0_cfg.regbase; struct espi_event evt = { ESPI_BUS_PERIPHERAL_NOTIFICATION, 0, ESPI_PERIPHERAL_NODATA }; int count = 8; uint32_t dattr = p80regs->EC_DA; while ((dattr & MCHP_P80BD_ECDA_NE) && (count--)) { evt.evt_data = (dattr & 0xffu) | BIT(16); switch (dattr & MCHP_P80BD_ECDA_LANE_MSK) { case MCHP_P80BD_ECDA_LANE_0: evt.evt_details |= (ESPI_PERIPHERAL_INDEX_0 << 16) | ESPI_PERIPHERAL_DEBUG_PORT80; break; case MCHP_P80BD_ECDA_LANE_1: evt.evt_details |= (ESPI_PERIPHERAL_INDEX_1 << 16) | ESPI_PERIPHERAL_DEBUG_PORT80; break; case MCHP_P80BD_ECDA_LANE_2: break; case MCHP_P80BD_ECDA_LANE_3: break; default: break; } if (evt.evt_details) { espi_send_callbacks(&data->callbacks, dev, evt); evt.evt_details = 0; } } mchp_xec_ecia_info_girq_src_clr(xec_p80bd0_cfg.ecia_info); }
[ "static", "void", "p80bd0_isr", "(", "const", "struct", "device", "*", "dev", ")", "{", "struct", "espi_xec_data", "*", "const", "data", "=", "(", "struct", "espi_xec_data", "*", "const", ")", "dev", "->", "data", ";", "struct", "p80bd_regs", "*", "p80regs", "=", "(", "struct", "p80bd_regs", "*", ")", "xec_p80bd0_cfg", ".", "regbase", ";", "struct", "espi_event", "evt", "=", "{", "ESPI_BUS_PERIPHERAL_NOTIFICATION", ",", "0", ",", "ESPI_PERIPHERAL_NODATA", "}", ";", "int", "count", "=", "8", ";", "uint32_t", "dattr", "=", "p80regs", "->", "EC_DA", ";", "while", "(", "(", "dattr", "&", "MCHP_P80BD_ECDA_NE", ")", "&&", "(", "count", "--", ")", ")", "{", "evt", ".", "evt_data", "=", "(", "dattr", "&", "0xffu", ")", "|", "BIT", "(", "16", ")", ";", "switch", "(", "dattr", "&", "MCHP_P80BD_ECDA_LANE_MSK", ")", "{", "case", "MCHP_P80BD_ECDA_LANE_0", ":", "evt", ".", "evt_details", "|=", "(", "ESPI_PERIPHERAL_INDEX_0", "<<", "16", ")", "|", "ESPI_PERIPHERAL_DEBUG_PORT80", ";", "break", ";", "case", "MCHP_P80BD_ECDA_LANE_1", ":", "evt", ".", "evt_details", "|=", "(", "ESPI_PERIPHERAL_INDEX_1", "<<", "16", ")", "|", "ESPI_PERIPHERAL_DEBUG_PORT80", ";", "break", ";", "case", "MCHP_P80BD_ECDA_LANE_2", ":", "break", ";", "case", "MCHP_P80BD_ECDA_LANE_3", ":", "break", ";", "default", ":", "break", ";", "}", "if", "(", "evt", ".", "evt_details", ")", "{", "espi_send_callbacks", "(", "&", "data", "->", "callbacks", ",", "dev", ",", "evt", ")", ";", "evt", ".", "evt_details", "=", "0", ";", "}", "}", "mchp_xec_ecia_info_girq_src_clr", "(", "xec_p80bd0_cfg", ".", "ecia_info", ")", ";", "}" ]
MEC172x P80 BIOS Debug Port hardware captures writes to its 4-byte I/O range Hardware provides status indicating byte lane(s) of each write.
[ "MEC172x", "P80", "BIOS", "Debug", "Port", "hardware", "captures", "writes", "to", "its", "4", "-", "byte", "I", "/", "O", "range", "Hardware", "provides", "status", "indicating", "byte", "lane", "(", "s", ")", "of", "each", "write", "." ]
[ "/* limit ISR to 8 bytes */", "/* b[7:0]=8-bit value written, b[15:8]=attributes */", "/* Not empty? */", "/* espi_event protocol No Data value is 0 so pick a bit and\n\t\t * set it. This depends on the application.\n\t\t */", "/* clear GIRQ status */" ]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
328bf86c55b7df4bbeff793cf4eda6a0fe3fff9c
ParticleBeamHQ/zephyr
drivers/espi/espi_mchp_xec_host_v2.c
[ "Apache-2.0" ]
C
espi_xec_read_lpc_request
int
int espi_xec_read_lpc_request(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data) { return espi_xec_lpc_req(dev, op, data, 0); }
/* dev = pointer to espi0 device */
dev = pointer to espi0 device
[ "dev", "=", "pointer", "to", "espi0", "device" ]
int espi_xec_read_lpc_request(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data) { return espi_xec_lpc_req(dev, op, data, 0); }
[ "int", "espi_xec_read_lpc_request", "(", "const", "struct", "device", "*", "dev", ",", "enum", "lpc_peripheral_opcode", "op", ",", "uint32_t", "*", "data", ")", "{", "return", "espi_xec_lpc_req", "(", "dev", ",", "op", ",", "data", ",", "0", ")", ";", "}" ]
dev = pointer to espi0 device
[ "dev", "=", "pointer", "to", "espi0", "device" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "op", "type": "enum lpc_peripheral_opcode" }, { "param": "data", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "op", "type": "enum lpc_peripheral_opcode", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_msg_is_good_crc
bool
static bool ucpd_msg_is_good_crc(union pd_header header) { /* * Good CRC is a control message (no data objects) with GOOD_CRC * message type in the header. */ return (header.number_of_data_objects == 0 && header.extended == 0 && header.message_type == PD_CTRL_GOOD_CRC); }
/** * @brief Test for a goodCRC message * * @returns true if message is goodCRC, else false */
@brief Test for a goodCRC message @returns true if message is goodCRC, else false
[ "@brief", "Test", "for", "a", "goodCRC", "message", "@returns", "true", "if", "message", "is", "goodCRC", "else", "false" ]
static bool ucpd_msg_is_good_crc(union pd_header header) { return (header.number_of_data_objects == 0 && header.extended == 0 && header.message_type == PD_CTRL_GOOD_CRC); }
[ "static", "bool", "ucpd_msg_is_good_crc", "(", "union", "pd_header", "header", ")", "{", "return", "(", "header", ".", "number_of_data_objects", "==", "0", "&&", "header", ".", "extended", "==", "0", "&&", "header", ".", "message_type", "==", "PD_CTRL_GOOD_CRC", ")", ";", "}" ]
@brief Test for a goodCRC message @returns true if message is goodCRC, else false
[ "@brief", "Test", "for", "a", "goodCRC", "message", "@returns", "true", "if", "message", "is", "goodCRC", "else", "false" ]
[ "/*\n\t * Good CRC is a control message (no data objects) with GOOD_CRC\n\t * message type in the header.\n\t */" ]
[ { "param": "header", "type": "union pd_header" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "header", "type": "union pd_header", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
update_stm32g0x_cc_line
void
static void update_stm32g0x_cc_line(UCPD_TypeDef *ucpd_port) { if ((uint32_t)(ucpd_port) == UCPD1_BASE) { SYSCFG->CFGR1 |= SYSCFG_CFGR1_UCPD1_STROBE_Msk; } else { SYSCFG->CFGR1 |= SYSCFG_CFGR1_UCPD2_STROBE_Msk; } }
/** * @brief Apply the UCPD CC1 and CC2 pin configurations. * * UCPDx_STROBE: UCPDx pull-down configuration strobe: * when UCPDx is enabled, with CC1 and CC2 pin UCPD * control bits configured: apply that configuration. */
@brief Apply the UCPD CC1 and CC2 pin configurations. UCPDx_STROBE: UCPDx pull-down configuration strobe: when UCPDx is enabled, with CC1 and CC2 pin UCPD control bits configured: apply that configuration.
[ "@brief", "Apply", "the", "UCPD", "CC1", "and", "CC2", "pin", "configurations", ".", "UCPDx_STROBE", ":", "UCPDx", "pull", "-", "down", "configuration", "strobe", ":", "when", "UCPDx", "is", "enabled", "with", "CC1", "and", "CC2", "pin", "UCPD", "control", "bits", "configured", ":", "apply", "that", "configuration", "." ]
static void update_stm32g0x_cc_line(UCPD_TypeDef *ucpd_port) { if ((uint32_t)(ucpd_port) == UCPD1_BASE) { SYSCFG->CFGR1 |= SYSCFG_CFGR1_UCPD1_STROBE_Msk; } else { SYSCFG->CFGR1 |= SYSCFG_CFGR1_UCPD2_STROBE_Msk; } }
[ "static", "void", "update_stm32g0x_cc_line", "(", "UCPD_TypeDef", "*", "ucpd_port", ")", "{", "if", "(", "(", "uint32_t", ")", "(", "ucpd_port", ")", "==", "UCPD1_BASE", ")", "{", "SYSCFG", "->", "CFGR1", "|=", "SYSCFG_CFGR1_UCPD1_STROBE_Msk", ";", "}", "else", "{", "SYSCFG", "->", "CFGR1", "|=", "SYSCFG_CFGR1_UCPD2_STROBE_Msk", ";", "}", "}" ]
@brief Apply the UCPD CC1 and CC2 pin configurations.
[ "@brief", "Apply", "the", "UCPD", "CC1", "and", "CC2", "pin", "configurations", "." ]
[]
[ { "param": "ucpd_port", "type": "UCPD_TypeDef" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ucpd_port", "type": "UCPD_TypeDef", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_tx_data_byte
void
static void ucpd_tx_data_byte(const struct device *dev) { struct tcpc_data *data = dev->data; const struct tcpc_config *const config = dev->config; int index = data->ucpd_tx_active_buffer->msg_index++; LL_UCPD_WriteData(config->ucpd_port, data->ucpd_tx_active_buffer->data.msg[index]); }
/** * @brief Transmits a data byte from the TX data buffer */
@brief Transmits a data byte from the TX data buffer
[ "@brief", "Transmits", "a", "data", "byte", "from", "the", "TX", "data", "buffer" ]
static void ucpd_tx_data_byte(const struct device *dev) { struct tcpc_data *data = dev->data; const struct tcpc_config *const config = dev->config; int index = data->ucpd_tx_active_buffer->msg_index++; LL_UCPD_WriteData(config->ucpd_port, data->ucpd_tx_active_buffer->data.msg[index]); }
[ "static", "void", "ucpd_tx_data_byte", "(", "const", "struct", "device", "*", "dev", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "int", "index", "=", "data", "->", "ucpd_tx_active_buffer", "->", "msg_index", "++", ";", "LL_UCPD_WriteData", "(", "config", "->", "ucpd_port", ",", "data", "->", "ucpd_tx_active_buffer", "->", "data", ".", "msg", "[", "index", "]", ")", ";", "}" ]
@brief Transmits a data byte from the TX data buffer
[ "@brief", "Transmits", "a", "data", "byte", "from", "the", "TX", "data", "buffer" ]
[]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_rx_data_byte
void
static void ucpd_rx_data_byte(const struct device *dev) { struct tcpc_data *data = dev->data; const struct tcpc_config *const config = dev->config; if (data->ucpd_rx_byte_count < UCPD_BUF_LEN) { data->ucpd_rx_buffer[data->ucpd_rx_byte_count++] = LL_UCPD_ReadData(config->ucpd_port); } }
/** * @brief Receives a data byte and store it in the RX data buffer */
@brief Receives a data byte and store it in the RX data buffer
[ "@brief", "Receives", "a", "data", "byte", "and", "store", "it", "in", "the", "RX", "data", "buffer" ]
static void ucpd_rx_data_byte(const struct device *dev) { struct tcpc_data *data = dev->data; const struct tcpc_config *const config = dev->config; if (data->ucpd_rx_byte_count < UCPD_BUF_LEN) { data->ucpd_rx_buffer[data->ucpd_rx_byte_count++] = LL_UCPD_ReadData(config->ucpd_port); } }
[ "static", "void", "ucpd_rx_data_byte", "(", "const", "struct", "device", "*", "dev", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "if", "(", "data", "->", "ucpd_rx_byte_count", "<", "UCPD_BUF_LEN", ")", "{", "data", "->", "ucpd_rx_buffer", "[", "data", "->", "ucpd_rx_byte_count", "++", "]", "=", "LL_UCPD_ReadData", "(", "config", "->", "ucpd_port", ")", ";", "}", "}" ]
@brief Receives a data byte and store it in the RX data buffer
[ "@brief", "Receives", "a", "data", "byte", "and", "store", "it", "in", "the", "RX", "data", "buffer" ]
[]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_tx_interrupts_enable
void
static void ucpd_tx_interrupts_enable(const struct device *dev, bool enable) { const struct tcpc_config *const config = dev->config; uint32_t imr; imr = LL_UCPD_ReadReg(config->ucpd_port, IMR); if (enable) { LL_UCPD_WriteReg(config->ucpd_port, ICR, UCPD_ICR_TX_INT_MASK); LL_UCPD_WriteReg(config->ucpd_port, IMR, imr | UCPD_IMR_TX_INT_MASK); } else { LL_UCPD_WriteReg(config->ucpd_port, IMR, imr & ~UCPD_IMR_TX_INT_MASK); } }
/** * @brief Enables or Disables TX interrupts */
@brief Enables or Disables TX interrupts
[ "@brief", "Enables", "or", "Disables", "TX", "interrupts" ]
static void ucpd_tx_interrupts_enable(const struct device *dev, bool enable) { const struct tcpc_config *const config = dev->config; uint32_t imr; imr = LL_UCPD_ReadReg(config->ucpd_port, IMR); if (enable) { LL_UCPD_WriteReg(config->ucpd_port, ICR, UCPD_ICR_TX_INT_MASK); LL_UCPD_WriteReg(config->ucpd_port, IMR, imr | UCPD_IMR_TX_INT_MASK); } else { LL_UCPD_WriteReg(config->ucpd_port, IMR, imr & ~UCPD_IMR_TX_INT_MASK); } }
[ "static", "void", "ucpd_tx_interrupts_enable", "(", "const", "struct", "device", "*", "dev", ",", "bool", "enable", ")", "{", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "uint32_t", "imr", ";", "imr", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "IMR", ")", ";", "if", "(", "enable", ")", "{", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "ICR", ",", "UCPD_ICR_TX_INT_MASK", ")", ";", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "IMR", ",", "imr", "|", "UCPD_IMR_TX_INT_MASK", ")", ";", "}", "else", "{", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "IMR", ",", "imr", "&", "~", "UCPD_IMR_TX_INT_MASK", ")", ";", "}", "}" ]
@brief Enables or Disables TX interrupts
[ "@brief", "Enables", "or", "Disables", "TX", "interrupts" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "enable", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "enable", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
stm32_ucpd_state_init
void
static void stm32_ucpd_state_init(const struct device *dev) { struct tcpc_data *data = dev->data; /* Init variables used to manage tx process */ data->ucpd_tx_request = 0; data->tx_retry_count = 0; data->ucpd_tx_state = STATE_IDLE; /* Init variables used to manage rx */ data->ucpd_rx_sop_prime_enabled = false; data->ucpd_rx_msg_active = false; data->ucpd_rx_bist_mode = false; /* Vconn tracking variable */ data->ucpd_vconn_enable = false; }
/** * @brief Initializes the RX and TX state machine variables */
@brief Initializes the RX and TX state machine variables
[ "@brief", "Initializes", "the", "RX", "and", "TX", "state", "machine", "variables" ]
static void stm32_ucpd_state_init(const struct device *dev) { struct tcpc_data *data = dev->data; data->ucpd_tx_request = 0; data->tx_retry_count = 0; data->ucpd_tx_state = STATE_IDLE; data->ucpd_rx_sop_prime_enabled = false; data->ucpd_rx_msg_active = false; data->ucpd_rx_bist_mode = false; data->ucpd_vconn_enable = false; }
[ "static", "void", "stm32_ucpd_state_init", "(", "const", "struct", "device", "*", "dev", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "ucpd_tx_request", "=", "0", ";", "data", "->", "tx_retry_count", "=", "0", ";", "data", "->", "ucpd_tx_state", "=", "STATE_IDLE", ";", "data", "->", "ucpd_rx_sop_prime_enabled", "=", "false", ";", "data", "->", "ucpd_rx_msg_active", "=", "false", ";", "data", "->", "ucpd_rx_bist_mode", "=", "false", ";", "data", "->", "ucpd_vconn_enable", "=", "false", ";", "}" ]
@brief Initializes the RX and TX state machine variables
[ "@brief", "Initializes", "the", "RX", "and", "TX", "state", "machine", "variables" ]
[ "/* Init variables used to manage tx process */", "/* Init variables used to manage rx */", "/* Vconn tracking variable */" ]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_get_cc
int
static int ucpd_get_cc(const struct device *dev, enum tc_cc_voltage_state *cc1, enum tc_cc_voltage_state *cc2) { const struct tcpc_config *const config = dev->config; int vstate_cc1; int vstate_cc2; int anamode; uint32_t sr; /* * cc_voltage_state is determined from vstate_cc bit field in the * status register. The meaning of the value vstate_cc depends on * current value of ANAMODE (src/snk). * * vstate_cc maps directly to cc_state from tcpci spec when * ANAMODE(snk) = 1, but needs to be modified slightly for case * ANAMODE(src) = 0. * * If presenting Rp (source), then need to do a circular shift of * vstate_ccx value: * vstate_cc | cc_state * ------------------ * 0 -> 1 * 1 -> 2 * 2 -> 0 */ /* Get vstate_ccx values and power role */ sr = LL_UCPD_ReadReg(config->ucpd_port, SR); /* Get Rp or Rd active */ anamode = LL_UCPD_GetRole(config->ucpd_port); vstate_cc1 = (sr & UCPD_SR_TYPEC_VSTATE_CC1_Msk) >> UCPD_SR_TYPEC_VSTATE_CC1_Pos; vstate_cc2 = (sr & UCPD_SR_TYPEC_VSTATE_CC2_Msk) >> UCPD_SR_TYPEC_VSTATE_CC2_Pos; /* Do circular shift if port == source */ if (anamode) { if (vstate_cc1 != STM32_UCPD_SR_VSTATE_RA) { vstate_cc1 += 4; } if (vstate_cc2 != STM32_UCPD_SR_VSTATE_RA) { vstate_cc2 += 4; } } else { if (vstate_cc1 != STM32_UCPD_SR_VSTATE_OPEN) { vstate_cc1 = (vstate_cc1 + 1) % 3; } if (vstate_cc2 != STM32_UCPD_SR_VSTATE_OPEN) { vstate_cc2 = (vstate_cc2 + 1) % 3; } } *cc1 = vstate_cc1; *cc2 = vstate_cc2; return 0; }
/** * @brief Get the state of the CC1 and CC2 lines * * @return 0 on success * @return -EIO on failure */
@brief Get the state of the CC1 and CC2 lines @return 0 on success @return -EIO on failure
[ "@brief", "Get", "the", "state", "of", "the", "CC1", "and", "CC2", "lines", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_get_cc(const struct device *dev, enum tc_cc_voltage_state *cc1, enum tc_cc_voltage_state *cc2) { const struct tcpc_config *const config = dev->config; int vstate_cc1; int vstate_cc2; int anamode; uint32_t sr; sr = LL_UCPD_ReadReg(config->ucpd_port, SR); anamode = LL_UCPD_GetRole(config->ucpd_port); vstate_cc1 = (sr & UCPD_SR_TYPEC_VSTATE_CC1_Msk) >> UCPD_SR_TYPEC_VSTATE_CC1_Pos; vstate_cc2 = (sr & UCPD_SR_TYPEC_VSTATE_CC2_Msk) >> UCPD_SR_TYPEC_VSTATE_CC2_Pos; if (anamode) { if (vstate_cc1 != STM32_UCPD_SR_VSTATE_RA) { vstate_cc1 += 4; } if (vstate_cc2 != STM32_UCPD_SR_VSTATE_RA) { vstate_cc2 += 4; } } else { if (vstate_cc1 != STM32_UCPD_SR_VSTATE_OPEN) { vstate_cc1 = (vstate_cc1 + 1) % 3; } if (vstate_cc2 != STM32_UCPD_SR_VSTATE_OPEN) { vstate_cc2 = (vstate_cc2 + 1) % 3; } } *cc1 = vstate_cc1; *cc2 = vstate_cc2; return 0; }
[ "static", "int", "ucpd_get_cc", "(", "const", "struct", "device", "*", "dev", ",", "enum", "tc_cc_voltage_state", "*", "cc1", ",", "enum", "tc_cc_voltage_state", "*", "cc2", ")", "{", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "int", "vstate_cc1", ";", "int", "vstate_cc2", ";", "int", "anamode", ";", "uint32_t", "sr", ";", "sr", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "SR", ")", ";", "anamode", "=", "LL_UCPD_GetRole", "(", "config", "->", "ucpd_port", ")", ";", "vstate_cc1", "=", "(", "sr", "&", "UCPD_SR_TYPEC_VSTATE_CC1_Msk", ")", ">>", "UCPD_SR_TYPEC_VSTATE_CC1_Pos", ";", "vstate_cc2", "=", "(", "sr", "&", "UCPD_SR_TYPEC_VSTATE_CC2_Msk", ")", ">>", "UCPD_SR_TYPEC_VSTATE_CC2_Pos", ";", "if", "(", "anamode", ")", "{", "if", "(", "vstate_cc1", "!=", "STM32_UCPD_SR_VSTATE_RA", ")", "{", "vstate_cc1", "+=", "4", ";", "}", "if", "(", "vstate_cc2", "!=", "STM32_UCPD_SR_VSTATE_RA", ")", "{", "vstate_cc2", "+=", "4", ";", "}", "}", "else", "{", "if", "(", "vstate_cc1", "!=", "STM32_UCPD_SR_VSTATE_OPEN", ")", "{", "vstate_cc1", "=", "(", "vstate_cc1", "+", "1", ")", "%", "3", ";", "}", "if", "(", "vstate_cc2", "!=", "STM32_UCPD_SR_VSTATE_OPEN", ")", "{", "vstate_cc2", "=", "(", "vstate_cc2", "+", "1", ")", "%", "3", ";", "}", "}", "*", "cc1", "=", "vstate_cc1", ";", "*", "cc2", "=", "vstate_cc2", ";", "return", "0", ";", "}" ]
@brief Get the state of the CC1 and CC2 lines @return 0 on success @return -EIO on failure
[ "@brief", "Get", "the", "state", "of", "the", "CC1", "and", "CC2", "lines", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[ "/*\n\t * cc_voltage_state is determined from vstate_cc bit field in the\n\t * status register. The meaning of the value vstate_cc depends on\n\t * current value of ANAMODE (src/snk).\n\t *\n\t * vstate_cc maps directly to cc_state from tcpci spec when\n\t * ANAMODE(snk) = 1, but needs to be modified slightly for case\n\t * ANAMODE(src) = 0.\n\t *\n\t * If presenting Rp (source), then need to do a circular shift of\n\t * vstate_ccx value:\n\t * vstate_cc | cc_state\n\t * ------------------\n\t * 0 -> 1\n\t * 1 -> 2\n\t * 2 -> 0\n\t */", "/* Get vstate_ccx values and power role */", "/* Get Rp or Rd active */", "/* Do circular shift if port == source */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "cc1", "type": "enum tc_cc_voltage_state" }, { "param": "cc2", "type": "enum tc_cc_voltage_state" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cc1", "type": "enum tc_cc_voltage_state", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cc2", "type": "enum tc_cc_voltage_state", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_vconn
int
static int ucpd_set_vconn(const struct device *dev, bool enable) { struct tcpc_data *data = dev->data; const struct tcpc_config *const config = dev->config; int cr; int ret; if (data->vconn_cb == NULL) { return -ENOTSUP; } /* Update VCONN on/off status. Do this before getting cc enable mask */ data->ucpd_vconn_enable = enable; cr = LL_UCPD_ReadReg(config->ucpd_port, CR); cr &= ~UCPD_CR_CCENABLE_Msk; cr |= ucpd_get_cc_enable_mask(dev); /* Apply cc pull resistor change */ LL_UCPD_WriteReg(config->ucpd_port, CR, cr); #ifdef CONFIG_SOC_SERIES_STM32G0X update_stm32g0x_cc_line(config->ucpd_port); #endif /* Call user supplied callback to set vconn */ ret = data->vconn_cb(dev, enable); return ret; }
/** * @brief Enable or Disable VCONN * * @return 0 on success * @return -EIO on failure * @return -ENOTSUP if not supported */
@brief Enable or Disable VCONN @return 0 on success @return -EIO on failure @return -ENOTSUP if not supported
[ "@brief", "Enable", "or", "Disable", "VCONN", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure", "@return", "-", "ENOTSUP", "if", "not", "supported" ]
static int ucpd_set_vconn(const struct device *dev, bool enable) { struct tcpc_data *data = dev->data; const struct tcpc_config *const config = dev->config; int cr; int ret; if (data->vconn_cb == NULL) { return -ENOTSUP; } data->ucpd_vconn_enable = enable; cr = LL_UCPD_ReadReg(config->ucpd_port, CR); cr &= ~UCPD_CR_CCENABLE_Msk; cr |= ucpd_get_cc_enable_mask(dev); LL_UCPD_WriteReg(config->ucpd_port, CR, cr); #ifdef CONFIG_SOC_SERIES_STM32G0X update_stm32g0x_cc_line(config->ucpd_port); #endif ret = data->vconn_cb(dev, enable); return ret; }
[ "static", "int", "ucpd_set_vconn", "(", "const", "struct", "device", "*", "dev", ",", "bool", "enable", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "int", "cr", ";", "int", "ret", ";", "if", "(", "data", "->", "vconn_cb", "==", "NULL", ")", "{", "return", "-", "ENOTSUP", ";", "}", "data", "->", "ucpd_vconn_enable", "=", "enable", ";", "cr", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CR", ")", ";", "cr", "&=", "~", "UCPD_CR_CCENABLE_Msk", ";", "cr", "|=", "ucpd_get_cc_enable_mask", "(", "dev", ")", ";", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "CR", ",", "cr", ")", ";", "#ifdef", "CONFIG_SOC_SERIES_STM32G0X", "update_stm32g0x_cc_line", "(", "config", "->", "ucpd_port", ")", ";", "#endif", "ret", "=", "data", "->", "vconn_cb", "(", "dev", ",", "enable", ")", ";", "return", "ret", ";", "}" ]
@brief Enable or Disable VCONN @return 0 on success @return -EIO on failure @return -ENOTSUP if not supported
[ "@brief", "Enable", "or", "Disable", "VCONN", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure", "@return", "-", "ENOTSUP", "if", "not", "supported" ]
[ "/* Update VCONN on/off status. Do this before getting cc enable mask */", "/* Apply cc pull resistor change */", "/* Call user supplied callback to set vconn */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "enable", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "enable", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_get_rp_value
int
static int ucpd_get_rp_value(const struct device *dev, enum tc_rp_value *rp) { struct tcpc_data *data = dev->data; *rp = data->rp; return 0; }
/** * @brief Gets the value of the CC pull up resistor used when operating as a Source * * @return 0 on success */
@brief Gets the value of the CC pull up resistor used when operating as a Source @return 0 on success
[ "@brief", "Gets", "the", "value", "of", "the", "CC", "pull", "up", "resistor", "used", "when", "operating", "as", "a", "Source", "@return", "0", "on", "success" ]
static int ucpd_get_rp_value(const struct device *dev, enum tc_rp_value *rp) { struct tcpc_data *data = dev->data; *rp = data->rp; return 0; }
[ "static", "int", "ucpd_get_rp_value", "(", "const", "struct", "device", "*", "dev", ",", "enum", "tc_rp_value", "*", "rp", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "*", "rp", "=", "data", "->", "rp", ";", "return", "0", ";", "}" ]
@brief Gets the value of the CC pull up resistor used when operating as a Source @return 0 on success
[ "@brief", "Gets", "the", "value", "of", "the", "CC", "pull", "up", "resistor", "used", "when", "operating", "as", "a", "Source", "@return", "0", "on", "success" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "rp", "type": "enum tc_rp_value" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rp", "type": "enum tc_rp_value", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_cc
int
static int ucpd_set_cc(const struct device *dev, enum tc_cc_pull cc_pull) { const struct tcpc_config *const config = dev->config; struct tcpc_data *data = dev->data; uint32_t cr; cr = LL_UCPD_ReadReg(config->ucpd_port, CR); /* * Always set ANASUBMODE to match desired Rp. TCPM layer has a valid * range of 0, 1, or 2. This range maps to 1, 2, or 3 in ucpd for * ANASUBMODE. */ cr &= ~UCPD_CR_ANASUBMODE_Msk; cr |= STM32_UCPD_CR_ANASUBMODE_VAL(UCPD_RP_TO_ANASUB(data->rp)); /* Disconnect both pull from both CC lines for R_open case */ cr &= ~UCPD_CR_CCENABLE_Msk; /* Set ANAMODE if cc_pull is Rd */ if (cc_pull == TC_CC_RD) { cr |= (UCPD_CR_ANAMODE | UCPD_CR_CCENABLE_Msk); /* Clear ANAMODE if cc_pull is Rp */ } else if (cc_pull == TC_CC_RP) { cr &= ~(UCPD_CR_ANAMODE); cr |= ucpd_get_cc_enable_mask(dev); } /* Update pull values */ LL_UCPD_WriteReg(config->ucpd_port, CR, cr); #ifdef CONFIG_SOC_SERIES_STM32G0X update_stm32g0x_cc_line(config->ucpd_port); #endif return 0; }
/** * @brief Set the CC pull up or pull down resistors * * @return 0 on success * @return -EIO on failure */
@brief Set the CC pull up or pull down resistors @return 0 on success @return -EIO on failure
[ "@brief", "Set", "the", "CC", "pull", "up", "or", "pull", "down", "resistors", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_set_cc(const struct device *dev, enum tc_cc_pull cc_pull) { const struct tcpc_config *const config = dev->config; struct tcpc_data *data = dev->data; uint32_t cr; cr = LL_UCPD_ReadReg(config->ucpd_port, CR); cr &= ~UCPD_CR_ANASUBMODE_Msk; cr |= STM32_UCPD_CR_ANASUBMODE_VAL(UCPD_RP_TO_ANASUB(data->rp)); cr &= ~UCPD_CR_CCENABLE_Msk; if (cc_pull == TC_CC_RD) { cr |= (UCPD_CR_ANAMODE | UCPD_CR_CCENABLE_Msk); } else if (cc_pull == TC_CC_RP) { cr &= ~(UCPD_CR_ANAMODE); cr |= ucpd_get_cc_enable_mask(dev); } LL_UCPD_WriteReg(config->ucpd_port, CR, cr); #ifdef CONFIG_SOC_SERIES_STM32G0X update_stm32g0x_cc_line(config->ucpd_port); #endif return 0; }
[ "static", "int", "ucpd_set_cc", "(", "const", "struct", "device", "*", "dev", ",", "enum", "tc_cc_pull", "cc_pull", ")", "{", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "uint32_t", "cr", ";", "cr", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CR", ")", ";", "cr", "&=", "~", "UCPD_CR_ANASUBMODE_Msk", ";", "cr", "|=", "STM32_UCPD_CR_ANASUBMODE_VAL", "(", "UCPD_RP_TO_ANASUB", "(", "data", "->", "rp", ")", ")", ";", "cr", "&=", "~", "UCPD_CR_CCENABLE_Msk", ";", "if", "(", "cc_pull", "==", "TC_CC_RD", ")", "{", "cr", "|=", "(", "UCPD_CR_ANAMODE", "|", "UCPD_CR_CCENABLE_Msk", ")", ";", "}", "else", "if", "(", "cc_pull", "==", "TC_CC_RP", ")", "{", "cr", "&=", "~", "(", "UCPD_CR_ANAMODE", ")", ";", "cr", "|=", "ucpd_get_cc_enable_mask", "(", "dev", ")", ";", "}", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "CR", ",", "cr", ")", ";", "#ifdef", "CONFIG_SOC_SERIES_STM32G0X", "update_stm32g0x_cc_line", "(", "config", "->", "ucpd_port", ")", ";", "#endif", "return", "0", ";", "}" ]
@brief Set the CC pull up or pull down resistors @return 0 on success @return -EIO on failure
[ "@brief", "Set", "the", "CC", "pull", "up", "or", "pull", "down", "resistors", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[ "/*\n\t * Always set ANASUBMODE to match desired Rp. TCPM layer has a valid\n\t * range of 0, 1, or 2. This range maps to 1, 2, or 3 in ucpd for\n\t * ANASUBMODE.\n\t */", "/* Disconnect both pull from both CC lines for R_open case */", "/* Set ANAMODE if cc_pull is Rd */", "/* Clear ANAMODE if cc_pull is Rp */", "/* Update pull values */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "cc_pull", "type": "enum tc_cc_pull" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cc_pull", "type": "enum tc_cc_pull", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_cc_set_polarity
int
static int ucpd_cc_set_polarity(const struct device *dev, enum tc_cc_polarity polarity) { const struct tcpc_config *const config = dev->config; uint32_t cr; cr = LL_UCPD_ReadReg(config->ucpd_port, CR); /* * Polarity impacts the PHYCCSEL, CCENABLE, and CCxTCDIS fields. This * function is called when polarity is updated at TCPM layer. STM32Gx * only supports POLARITY_CC1 or POLARITY_CC2 and this is stored in the * PHYCCSEL bit in the CR register. */ if (polarity == TC_POLARITY_CC1) { cr &= ~UCPD_CR_PHYCCSEL; } else if (polarity == TC_POLARITY_CC2) { cr |= UCPD_CR_PHYCCSEL; } else { return -ENOTSUP; } /* Update polarity */ LL_UCPD_WriteReg(config->ucpd_port, CR, cr); return 0; }
/** * @brief Set the polarity of the CC line, which is the active CC line * used for power delivery. * * @return 0 on success * @return -EIO on failure * @return -ENOTSUP if polarity is not supported */
@brief Set the polarity of the CC line, which is the active CC line used for power delivery. @return 0 on success @return -EIO on failure @return -ENOTSUP if polarity is not supported
[ "@brief", "Set", "the", "polarity", "of", "the", "CC", "line", "which", "is", "the", "active", "CC", "line", "used", "for", "power", "delivery", ".", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure", "@return", "-", "ENOTSUP", "if", "polarity", "is", "not", "supported" ]
static int ucpd_cc_set_polarity(const struct device *dev, enum tc_cc_polarity polarity) { const struct tcpc_config *const config = dev->config; uint32_t cr; cr = LL_UCPD_ReadReg(config->ucpd_port, CR); if (polarity == TC_POLARITY_CC1) { cr &= ~UCPD_CR_PHYCCSEL; } else if (polarity == TC_POLARITY_CC2) { cr |= UCPD_CR_PHYCCSEL; } else { return -ENOTSUP; } LL_UCPD_WriteReg(config->ucpd_port, CR, cr); return 0; }
[ "static", "int", "ucpd_cc_set_polarity", "(", "const", "struct", "device", "*", "dev", ",", "enum", "tc_cc_polarity", "polarity", ")", "{", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "uint32_t", "cr", ";", "cr", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CR", ")", ";", "if", "(", "polarity", "==", "TC_POLARITY_CC1", ")", "{", "cr", "&=", "~", "UCPD_CR_PHYCCSEL", ";", "}", "else", "if", "(", "polarity", "==", "TC_POLARITY_CC2", ")", "{", "cr", "|=", "UCPD_CR_PHYCCSEL", ";", "}", "else", "{", "return", "-", "ENOTSUP", ";", "}", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "CR", ",", "cr", ")", ";", "return", "0", ";", "}" ]
@brief Set the polarity of the CC line, which is the active CC line used for power delivery.
[ "@brief", "Set", "the", "polarity", "of", "the", "CC", "line", "which", "is", "the", "active", "CC", "line", "used", "for", "power", "delivery", "." ]
[ "/*\n\t * Polarity impacts the PHYCCSEL, CCENABLE, and CCxTCDIS fields. This\n\t * function is called when polarity is updated at TCPM layer. STM32Gx\n\t * only supports POLARITY_CC1 or POLARITY_CC2 and this is stored in the\n\t * PHYCCSEL bit in the CR register.\n\t */", "/* Update polarity */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "polarity", "type": "enum tc_cc_polarity" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "polarity", "type": "enum tc_cc_polarity", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_rx_enable
int
static int ucpd_set_rx_enable(const struct device *dev, bool enable) { const struct tcpc_config *const config = dev->config; uint32_t imr; uint32_t cr; imr = LL_UCPD_ReadReg(config->ucpd_port, IMR); cr = LL_UCPD_ReadReg(config->ucpd_port, CR); /* * USB PD receiver enable is controlled by the bit PHYRXEN in * UCPD_CR. Enable Rx interrupts when RX PD decoder is active. */ if (enable) { /* Clear the RX alerts bits */ LL_UCPD_WriteReg(config->ucpd_port, ICR, UCPD_ICR_RX_INT_MASK); imr |= UCPD_IMR_RX_INT_MASK; cr |= UCPD_CR_PHYRXEN; LL_UCPD_WriteReg(config->ucpd_port, IMR, imr); LL_UCPD_WriteReg(config->ucpd_port, CR, cr); } else { imr &= ~UCPD_IMR_RX_INT_MASK; cr &= ~UCPD_CR_PHYRXEN; LL_UCPD_WriteReg(config->ucpd_port, CR, cr); LL_UCPD_WriteReg(config->ucpd_port, IMR, imr); } return 0; }
/** * @brief Enable or Disable Power Delivery * * @return 0 on success * @return -EIO on failure */
@brief Enable or Disable Power Delivery @return 0 on success @return -EIO on failure
[ "@brief", "Enable", "or", "Disable", "Power", "Delivery", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_set_rx_enable(const struct device *dev, bool enable) { const struct tcpc_config *const config = dev->config; uint32_t imr; uint32_t cr; imr = LL_UCPD_ReadReg(config->ucpd_port, IMR); cr = LL_UCPD_ReadReg(config->ucpd_port, CR); if (enable) { LL_UCPD_WriteReg(config->ucpd_port, ICR, UCPD_ICR_RX_INT_MASK); imr |= UCPD_IMR_RX_INT_MASK; cr |= UCPD_CR_PHYRXEN; LL_UCPD_WriteReg(config->ucpd_port, IMR, imr); LL_UCPD_WriteReg(config->ucpd_port, CR, cr); } else { imr &= ~UCPD_IMR_RX_INT_MASK; cr &= ~UCPD_CR_PHYRXEN; LL_UCPD_WriteReg(config->ucpd_port, CR, cr); LL_UCPD_WriteReg(config->ucpd_port, IMR, imr); } return 0; }
[ "static", "int", "ucpd_set_rx_enable", "(", "const", "struct", "device", "*", "dev", ",", "bool", "enable", ")", "{", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "uint32_t", "imr", ";", "uint32_t", "cr", ";", "imr", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "IMR", ")", ";", "cr", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CR", ")", ";", "if", "(", "enable", ")", "{", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "ICR", ",", "UCPD_ICR_RX_INT_MASK", ")", ";", "imr", "|=", "UCPD_IMR_RX_INT_MASK", ";", "cr", "|=", "UCPD_CR_PHYRXEN", ";", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "IMR", ",", "imr", ")", ";", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "CR", ",", "cr", ")", ";", "}", "else", "{", "imr", "&=", "~", "UCPD_IMR_RX_INT_MASK", ";", "cr", "&=", "~", "UCPD_CR_PHYRXEN", ";", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "CR", ",", "cr", ")", ";", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "IMR", ",", "imr", ")", ";", "}", "return", "0", ";", "}" ]
@brief Enable or Disable Power Delivery @return 0 on success @return -EIO on failure
[ "@brief", "Enable", "or", "Disable", "Power", "Delivery", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[ "/*\n\t * USB PD receiver enable is controlled by the bit PHYRXEN in\n\t * UCPD_CR. Enable Rx interrupts when RX PD decoder is active.\n\t */", "/* Clear the RX alerts bits */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "enable", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "enable", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_roles
int
static int ucpd_set_roles(const struct device *dev, enum tc_power_role power_role, enum tc_data_role data_role) { struct tcpc_data *data = dev->data; data->msg_header.pr = power_role; data->msg_header.dr = data_role; return 0; }
/** * @brief Set the Power and Data role used when sending goodCRC messages * * @return 0 on success * @return -EIO on failure */
@brief Set the Power and Data role used when sending goodCRC messages @return 0 on success @return -EIO on failure
[ "@brief", "Set", "the", "Power", "and", "Data", "role", "used", "when", "sending", "goodCRC", "messages", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_set_roles(const struct device *dev, enum tc_power_role power_role, enum tc_data_role data_role) { struct tcpc_data *data = dev->data; data->msg_header.pr = power_role; data->msg_header.dr = data_role; return 0; }
[ "static", "int", "ucpd_set_roles", "(", "const", "struct", "device", "*", "dev", ",", "enum", "tc_power_role", "power_role", ",", "enum", "tc_data_role", "data_role", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "msg_header", ".", "pr", "=", "power_role", ";", "data", "->", "msg_header", ".", "dr", "=", "data_role", ";", "return", "0", ";", "}" ]
@brief Set the Power and Data role used when sending goodCRC messages @return 0 on success @return -EIO on failure
[ "@brief", "Set", "the", "Power", "and", "Data", "role", "used", "when", "sending", "goodCRC", "messages", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "power_role", "type": "enum tc_power_role" }, { "param": "data_role", "type": "enum tc_data_role" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "power_role", "type": "enum tc_power_role", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data_role", "type": "enum tc_data_role", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_sop_prime_enable
int
static int ucpd_sop_prime_enable(const struct device *dev, bool enable) { struct tcpc_data *data = dev->data; /* Update static variable used to filter SOP//SOP'' messages */ data->ucpd_rx_sop_prime_enabled = enable; return 0; }
/** * @brief Enable the reception of SOP Prime messages * * @return 0 on success * @return -EIO on failure */
@brief Enable the reception of SOP Prime messages @return 0 on success @return -EIO on failure
[ "@brief", "Enable", "the", "reception", "of", "SOP", "Prime", "messages", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_sop_prime_enable(const struct device *dev, bool enable) { struct tcpc_data *data = dev->data; data->ucpd_rx_sop_prime_enabled = enable; return 0; }
[ "static", "int", "ucpd_sop_prime_enable", "(", "const", "struct", "device", "*", "dev", ",", "bool", "enable", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "ucpd_rx_sop_prime_enabled", "=", "enable", ";", "return", "0", ";", "}" ]
@brief Enable the reception of SOP Prime messages @return 0 on success @return -EIO on failure
[ "@brief", "Enable", "the", "reception", "of", "SOP", "Prime", "messages", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[ "/* Update static variable used to filter SOP//SOP'' messages */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "enable", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "enable", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_tx_state
void
static void ucpd_set_tx_state(const struct device *dev, enum ucpd_state state) { struct tcpc_data *data = dev->data; data->ucpd_tx_state = state; }
/** * @brief Set the current state of the TX state machine */
@brief Set the current state of the TX state machine
[ "@brief", "Set", "the", "current", "state", "of", "the", "TX", "state", "machine" ]
static void ucpd_set_tx_state(const struct device *dev, enum ucpd_state state) { struct tcpc_data *data = dev->data; data->ucpd_tx_state = state; }
[ "static", "void", "ucpd_set_tx_state", "(", "const", "struct", "device", "*", "dev", ",", "enum", "ucpd_state", "state", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "ucpd_tx_state", "=", "state", ";", "}" ]
@brief Set the current state of the TX state machine
[ "@brief", "Set", "the", "current", "state", "of", "the", "TX", "state", "machine" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "state", "type": "enum ucpd_state" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "state", "type": "enum ucpd_state", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_notify_handler
void
static void ucpd_notify_handler(struct alert_info *info, enum tcpc_alert alert) { if (info->handler) { info->handler(info->dev, info->data, alert); } }
/** * @brief Wrapper function for calling alert handler */
@brief Wrapper function for calling alert handler
[ "@brief", "Wrapper", "function", "for", "calling", "alert", "handler" ]
static void ucpd_notify_handler(struct alert_info *info, enum tcpc_alert alert) { if (info->handler) { info->handler(info->dev, info->data, alert); } }
[ "static", "void", "ucpd_notify_handler", "(", "struct", "alert_info", "*", "info", ",", "enum", "tcpc_alert", "alert", ")", "{", "if", "(", "info", "->", "handler", ")", "{", "info", "->", "handler", "(", "info", "->", "dev", ",", "info", "->", "data", ",", "alert", ")", ";", "}", "}" ]
@brief Wrapper function for calling alert handler
[ "@brief", "Wrapper", "function", "for", "calling", "alert", "handler" ]
[]
[ { "param": "info", "type": "struct alert_info" }, { "param": "alert", "type": "enum tcpc_alert" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "info", "type": "struct alert_info", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "alert", "type": "enum tcpc_alert", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_manage_tx
void
static void ucpd_manage_tx(struct alert_info *info) { struct tcpc_data *data = info->dev->data; enum ucpd_tx_msg msg_src = TX_MSG_NONE; union pd_header hdr; if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_HR_REQ)) { /* * Hard reset control messages are treated as a priority. The * control message will already be set up as it comes from the * PRL layer like any other PD ctrl/data message. So just need * to indicate the correct message source and set the state to * hard reset here. */ ucpd_set_tx_state(info->dev, STATE_HARD_RESET); msg_src = TX_MSG_TCPM; data->ucpd_tx_request &= ~BIT(msg_src); } switch (data->ucpd_tx_state) { case STATE_IDLE: if (data->ucpd_tx_request & MSG_GOOD_CRC_MASK) { ucpd_set_tx_state(info->dev, STATE_ACTIVE_CRC); msg_src = TX_MSG_GOOD_CRC; } else if (data->ucpd_tx_request & MSG_TCPM_MASK) { if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_MSG)) { /* * USB-PD Specification rev 3.0, section 6.10 * On receiving a received message, the protocol * layer shall discard any pending message. * * Since the pending message from the PRL has * not been sent yet, it needs to be discarded * based on the received message event. */ ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_DISCARDED); data->ucpd_tx_request &= ~MSG_TCPM_MASK; } else if (!data->ucpd_rx_msg_active) { ucpd_set_tx_state(info->dev, STATE_ACTIVE_TCPM); msg_src = TX_MSG_TCPM; /* Save msgID required for GoodCRC check */ hdr.raw_value = data->ucpd_tx_buffers[TX_MSG_TCPM].data.header; data->msg_id_match = hdr.message_id; data->tx_retry_max = hdr.specification_revision == PD_REV30 ? UCPD_N_RETRY_COUNT_REV30 : UCPD_N_RETRY_COUNT_REV20; } } /* If state is not idle, then start tx message */ if (data->ucpd_tx_state != STATE_IDLE) { data->ucpd_tx_request &= ~BIT(msg_src); data->tx_retry_count = 0; } break; case STATE_ACTIVE_TCPM: /* * Check if tx msg has finished. For TCPM messages * transmit is not complete until a GoodCRC message * matching the msgID just sent is received. But, a tx * message can fail due to collision or underrun, * etc. If that failure occurs, dont' wait for GoodCrc * and just go to failure path. */ if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_SUCCESS)) { ucpd_set_tx_state(info->dev, STATE_WAIT_CRC_ACK); } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_DISC) || atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL)) { if (data->tx_retry_count < data->tx_retry_max) { if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_MSG)) { /* * A message was received so there is no * need to retry this tx message which * had failed to send previously. * Likely, due to the wire * being active from the message that * was just received. */ ucpd_set_tx_state(info->dev, STATE_IDLE); ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_DISCARDED); ucpd_set_tx_state(info->dev, STATE_IDLE); } else { /* * Tx attempt failed. Remain in this * state, but trigger new tx attempt. */ msg_src = TX_MSG_TCPM; data->tx_retry_count++; } } else { enum tcpc_alert status; status = (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL)) ? TCPC_ALERT_TRANSMIT_MSG_FAILED : TCPC_ALERT_TRANSMIT_MSG_DISCARDED; ucpd_set_tx_state(info->dev, STATE_IDLE); ucpd_notify_handler(info, status); } } break; case STATE_ACTIVE_CRC: if (atomic_test_bit(&info->evt, UCPD_EVT_TX_MSG_SUCCESS) || atomic_test_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL) || atomic_test_bit(&info->evt, UCPD_EVT_TX_MSG_DISC)) { atomic_clear_bit(&info->evt, UCPD_EVT_TX_MSG_SUCCESS); atomic_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL); atomic_clear_bit(&info->evt, UCPD_EVT_TX_MSG_DISC); ucpd_set_tx_state(info->dev, STATE_IDLE); if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL)) { LOG_INF("ucpd: Failed to send GoodCRC!"); } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_DISC)) { LOG_INF("ucpd: GoodCRC message discarded!"); } } break; case STATE_WAIT_CRC_ACK: if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_GOOD_CRC) && data->ucpd_crc_id == data->msg_id_match) { /* GoodCRC with matching ID was received */ ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_SUCCESS); ucpd_set_tx_state(info->dev, STATE_IDLE); } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_GOOD_CRC)) { /* GoodCRC w/out match or timeout waiting */ if (data->tx_retry_count < data->tx_retry_max) { ucpd_set_tx_state(info->dev, STATE_ACTIVE_TCPM); msg_src = TX_MSG_TCPM; data->tx_retry_count++; } else { ucpd_set_tx_state(info->dev, STATE_IDLE); ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_FAILED); } } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_MSG)) { /* * In the case of a collision, it's possible the port * partner may not send a GoodCRC and instead send the * message that was colliding. If a message is received * in this state, then treat it as a discard from an * incoming message. */ ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_DISCARDED); ucpd_set_tx_state(info->dev, STATE_IDLE); } break; case STATE_HARD_RESET: if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_HR_DONE)) { /* HR complete, reset tx state values */ ucpd_set_tx_state(info->dev, STATE_IDLE); data->ucpd_tx_request = 0; data->tx_retry_count = 0; } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_HR_FAIL)) { ucpd_set_tx_state(info->dev, STATE_IDLE); data->ucpd_tx_request = 0; data->tx_retry_count = 0; } break; } /* * NOTE: TX_MSG_GOOD_CRC messages are sent from the ISR to reduce latency * when sending those messages, so don't resend them here. * * If msg_src is valid and not a TX_MSG_GOOD_CRC, then start transmit. */ if (msg_src != TX_MSG_GOOD_CRC && msg_src > TX_MSG_NONE) { ucpd_start_transmit(info->dev, msg_src); } }
/** * @brief This is the TX state machine */
@brief This is the TX state machine
[ "@brief", "This", "is", "the", "TX", "state", "machine" ]
static void ucpd_manage_tx(struct alert_info *info) { struct tcpc_data *data = info->dev->data; enum ucpd_tx_msg msg_src = TX_MSG_NONE; union pd_header hdr; if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_HR_REQ)) { ucpd_set_tx_state(info->dev, STATE_HARD_RESET); msg_src = TX_MSG_TCPM; data->ucpd_tx_request &= ~BIT(msg_src); } switch (data->ucpd_tx_state) { case STATE_IDLE: if (data->ucpd_tx_request & MSG_GOOD_CRC_MASK) { ucpd_set_tx_state(info->dev, STATE_ACTIVE_CRC); msg_src = TX_MSG_GOOD_CRC; } else if (data->ucpd_tx_request & MSG_TCPM_MASK) { if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_MSG)) { ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_DISCARDED); data->ucpd_tx_request &= ~MSG_TCPM_MASK; } else if (!data->ucpd_rx_msg_active) { ucpd_set_tx_state(info->dev, STATE_ACTIVE_TCPM); msg_src = TX_MSG_TCPM; hdr.raw_value = data->ucpd_tx_buffers[TX_MSG_TCPM].data.header; data->msg_id_match = hdr.message_id; data->tx_retry_max = hdr.specification_revision == PD_REV30 ? UCPD_N_RETRY_COUNT_REV30 : UCPD_N_RETRY_COUNT_REV20; } } if (data->ucpd_tx_state != STATE_IDLE) { data->ucpd_tx_request &= ~BIT(msg_src); data->tx_retry_count = 0; } break; case STATE_ACTIVE_TCPM: if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_SUCCESS)) { ucpd_set_tx_state(info->dev, STATE_WAIT_CRC_ACK); } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_DISC) || atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL)) { if (data->tx_retry_count < data->tx_retry_max) { if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_MSG)) { ucpd_set_tx_state(info->dev, STATE_IDLE); ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_DISCARDED); ucpd_set_tx_state(info->dev, STATE_IDLE); } else { msg_src = TX_MSG_TCPM; data->tx_retry_count++; } } else { enum tcpc_alert status; status = (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL)) ? TCPC_ALERT_TRANSMIT_MSG_FAILED : TCPC_ALERT_TRANSMIT_MSG_DISCARDED; ucpd_set_tx_state(info->dev, STATE_IDLE); ucpd_notify_handler(info, status); } } break; case STATE_ACTIVE_CRC: if (atomic_test_bit(&info->evt, UCPD_EVT_TX_MSG_SUCCESS) || atomic_test_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL) || atomic_test_bit(&info->evt, UCPD_EVT_TX_MSG_DISC)) { atomic_clear_bit(&info->evt, UCPD_EVT_TX_MSG_SUCCESS); atomic_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL); atomic_clear_bit(&info->evt, UCPD_EVT_TX_MSG_DISC); ucpd_set_tx_state(info->dev, STATE_IDLE); if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_FAIL)) { LOG_INF("ucpd: Failed to send GoodCRC!"); } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_TX_MSG_DISC)) { LOG_INF("ucpd: GoodCRC message discarded!"); } } break; case STATE_WAIT_CRC_ACK: if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_GOOD_CRC) && data->ucpd_crc_id == data->msg_id_match) { ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_SUCCESS); ucpd_set_tx_state(info->dev, STATE_IDLE); } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_GOOD_CRC)) { if (data->tx_retry_count < data->tx_retry_max) { ucpd_set_tx_state(info->dev, STATE_ACTIVE_TCPM); msg_src = TX_MSG_TCPM; data->tx_retry_count++; } else { ucpd_set_tx_state(info->dev, STATE_IDLE); ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_FAILED); } } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_RX_MSG)) { ucpd_notify_handler(info, TCPC_ALERT_TRANSMIT_MSG_DISCARDED); ucpd_set_tx_state(info->dev, STATE_IDLE); } break; case STATE_HARD_RESET: if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_HR_DONE)) { ucpd_set_tx_state(info->dev, STATE_IDLE); data->ucpd_tx_request = 0; data->tx_retry_count = 0; } else if (atomic_test_and_clear_bit(&info->evt, UCPD_EVT_HR_FAIL)) { ucpd_set_tx_state(info->dev, STATE_IDLE); data->ucpd_tx_request = 0; data->tx_retry_count = 0; } break; } if (msg_src != TX_MSG_GOOD_CRC && msg_src > TX_MSG_NONE) { ucpd_start_transmit(info->dev, msg_src); } }
[ "static", "void", "ucpd_manage_tx", "(", "struct", "alert_info", "*", "info", ")", "{", "struct", "tcpc_data", "*", "data", "=", "info", "->", "dev", "->", "data", ";", "enum", "ucpd_tx_msg", "msg_src", "=", "TX_MSG_NONE", ";", "union", "pd_header", "hdr", ";", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_HR_REQ", ")", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_HARD_RESET", ")", ";", "msg_src", "=", "TX_MSG_TCPM", ";", "data", "->", "ucpd_tx_request", "&=", "~", "BIT", "(", "msg_src", ")", ";", "}", "switch", "(", "data", "->", "ucpd_tx_state", ")", "{", "case", "STATE_IDLE", ":", "if", "(", "data", "->", "ucpd_tx_request", "&", "MSG_GOOD_CRC_MASK", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_ACTIVE_CRC", ")", ";", "msg_src", "=", "TX_MSG_GOOD_CRC", ";", "}", "else", "if", "(", "data", "->", "ucpd_tx_request", "&", "MSG_TCPM_MASK", ")", "{", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_RX_MSG", ")", ")", "{", "ucpd_notify_handler", "(", "info", ",", "TCPC_ALERT_TRANSMIT_MSG_DISCARDED", ")", ";", "data", "->", "ucpd_tx_request", "&=", "~", "MSG_TCPM_MASK", ";", "}", "else", "if", "(", "!", "data", "->", "ucpd_rx_msg_active", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_ACTIVE_TCPM", ")", ";", "msg_src", "=", "TX_MSG_TCPM", ";", "hdr", ".", "raw_value", "=", "data", "->", "ucpd_tx_buffers", "[", "TX_MSG_TCPM", "]", ".", "data", ".", "header", ";", "data", "->", "msg_id_match", "=", "hdr", ".", "message_id", ";", "data", "->", "tx_retry_max", "=", "hdr", ".", "specification_revision", "==", "PD_REV30", "?", "UCPD_N_RETRY_COUNT_REV30", ":", "UCPD_N_RETRY_COUNT_REV20", ";", "}", "}", "if", "(", "data", "->", "ucpd_tx_state", "!=", "STATE_IDLE", ")", "{", "data", "->", "ucpd_tx_request", "&=", "~", "BIT", "(", "msg_src", ")", ";", "data", "->", "tx_retry_count", "=", "0", ";", "}", "break", ";", "case", "STATE_ACTIVE_TCPM", ":", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_SUCCESS", ")", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_WAIT_CRC_ACK", ")", ";", "}", "else", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_DISC", ")", "||", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_FAIL", ")", ")", "{", "if", "(", "data", "->", "tx_retry_count", "<", "data", "->", "tx_retry_max", ")", "{", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_RX_MSG", ")", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "ucpd_notify_handler", "(", "info", ",", "TCPC_ALERT_TRANSMIT_MSG_DISCARDED", ")", ";", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "}", "else", "{", "msg_src", "=", "TX_MSG_TCPM", ";", "data", "->", "tx_retry_count", "++", ";", "}", "}", "else", "{", "enum", "tcpc_alert", "status", ";", "status", "=", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_FAIL", ")", ")", "?", "TCPC_ALERT_TRANSMIT_MSG_FAILED", ":", "TCPC_ALERT_TRANSMIT_MSG_DISCARDED", ";", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "ucpd_notify_handler", "(", "info", ",", "status", ")", ";", "}", "}", "break", ";", "case", "STATE_ACTIVE_CRC", ":", "if", "(", "atomic_test_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_SUCCESS", ")", "||", "atomic_test_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_FAIL", ")", "||", "atomic_test_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_DISC", ")", ")", "{", "atomic_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_SUCCESS", ")", ";", "atomic_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_FAIL", ")", ";", "atomic_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_DISC", ")", ";", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_FAIL", ")", ")", "{", "LOG_INF", "(", "\"", "\"", ")", ";", "}", "else", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_TX_MSG_DISC", ")", ")", "{", "LOG_INF", "(", "\"", "\"", ")", ";", "}", "}", "break", ";", "case", "STATE_WAIT_CRC_ACK", ":", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_RX_GOOD_CRC", ")", "&&", "data", "->", "ucpd_crc_id", "==", "data", "->", "msg_id_match", ")", "{", "ucpd_notify_handler", "(", "info", ",", "TCPC_ALERT_TRANSMIT_MSG_SUCCESS", ")", ";", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "}", "else", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_RX_GOOD_CRC", ")", ")", "{", "if", "(", "data", "->", "tx_retry_count", "<", "data", "->", "tx_retry_max", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_ACTIVE_TCPM", ")", ";", "msg_src", "=", "TX_MSG_TCPM", ";", "data", "->", "tx_retry_count", "++", ";", "}", "else", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "ucpd_notify_handler", "(", "info", ",", "TCPC_ALERT_TRANSMIT_MSG_FAILED", ")", ";", "}", "}", "else", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_RX_MSG", ")", ")", "{", "ucpd_notify_handler", "(", "info", ",", "TCPC_ALERT_TRANSMIT_MSG_DISCARDED", ")", ";", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "}", "break", ";", "case", "STATE_HARD_RESET", ":", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_HR_DONE", ")", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "data", "->", "ucpd_tx_request", "=", "0", ";", "data", "->", "tx_retry_count", "=", "0", ";", "}", "else", "if", "(", "atomic_test_and_clear_bit", "(", "&", "info", "->", "evt", ",", "UCPD_EVT_HR_FAIL", ")", ")", "{", "ucpd_set_tx_state", "(", "info", "->", "dev", ",", "STATE_IDLE", ")", ";", "data", "->", "ucpd_tx_request", "=", "0", ";", "data", "->", "tx_retry_count", "=", "0", ";", "}", "break", ";", "}", "if", "(", "msg_src", "!=", "TX_MSG_GOOD_CRC", "&&", "msg_src", ">", "TX_MSG_NONE", ")", "{", "ucpd_start_transmit", "(", "info", "->", "dev", ",", "msg_src", ")", ";", "}", "}" ]
@brief This is the TX state machine
[ "@brief", "This", "is", "the", "TX", "state", "machine" ]
[ "/*\n\t\t * Hard reset control messages are treated as a priority. The\n\t\t * control message will already be set up as it comes from the\n\t\t * PRL layer like any other PD ctrl/data message. So just need\n\t\t * to indicate the correct message source and set the state to\n\t\t * hard reset here.\n\t\t */", "/*\n\t\t\t\t * USB-PD Specification rev 3.0, section 6.10\n\t\t\t\t * On receiving a received message, the protocol\n\t\t\t\t * layer shall discard any pending message.\n\t\t\t\t *\n\t\t\t\t * Since the pending message from the PRL has\n\t\t\t\t * not been sent yet, it needs to be discarded\n\t\t\t\t * based on the received message event.\n\t\t\t\t */", "/* Save msgID required for GoodCRC check */", "/* If state is not idle, then start tx message */", "/*\n\t\t * Check if tx msg has finished. For TCPM messages\n\t\t * transmit is not complete until a GoodCRC message\n\t\t * matching the msgID just sent is received. But, a tx\n\t\t * message can fail due to collision or underrun,\n\t\t * etc. If that failure occurs, dont' wait for GoodCrc\n\t\t * and just go to failure path.\n\t\t */", "/*\n\t\t\t\t\t * A message was received so there is no\n\t\t\t\t\t * need to retry this tx message which\n\t\t\t\t\t * had failed to send previously.\n\t\t\t\t\t * Likely, due to the wire\n\t\t\t\t\t * being active from the message that\n\t\t\t\t\t * was just received.\n\t\t\t\t\t */", "/*\n\t\t\t\t\t * Tx attempt failed. Remain in this\n\t\t\t\t\t * state, but trigger new tx attempt.\n\t\t\t\t\t */", "/* GoodCRC with matching ID was received */", "/* GoodCRC w/out match or timeout waiting */", "/*\n\t\t\t * In the case of a collision, it's possible the port\n\t\t\t * partner may not send a GoodCRC and instead send the\n\t\t\t * message that was colliding. If a message is received\n\t\t\t * in this state, then treat it as a discard from an\n\t\t\t * incoming message.\n\t\t\t */", "/* HR complete, reset tx state values */", "/*\n\t * NOTE: TX_MSG_GOOD_CRC messages are sent from the ISR to reduce latency\n\t * when sending those messages, so don't resend them here.\n\t *\n\t * If msg_src is valid and not a TX_MSG_GOOD_CRC, then start transmit.\n\t */" ]
[ { "param": "info", "type": "struct alert_info" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "info", "type": "struct alert_info", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_transmit_data
int
static int ucpd_transmit_data(const struct device *dev, struct pd_msg *msg) { struct tcpc_data *data = dev->data; /* Length in bytes = (4 * object len) + 2 header bytes */ int len = PD_CONVERT_PD_HEADER_COUNT_TO_BYTES(msg->header.number_of_data_objects) + 2; if (len > UCPD_BUF_LEN) { return -EFAULT; } /* Store tx msg info in TCPM msg descriptor */ data->ucpd_tx_buffers[TX_MSG_TCPM].msg_len = len; data->ucpd_tx_buffers[TX_MSG_TCPM].type = msg->type; data->ucpd_tx_buffers[TX_MSG_TCPM].data.header = msg->header.raw_value; /* Copy msg objects to ucpd data buffer, after 2 header bytes */ memcpy(data->ucpd_tx_buffers[TX_MSG_TCPM].data.msg + 2, (uint8_t *)msg->data, len - 2); /* * Check for hard reset message here. A different event is used for hard * resets as they are able to interrupt ongoing transmit, and should * have priority over any pending message. */ if (msg->type == PD_PACKET_TX_HARD_RESET) { atomic_set_bit(&data->alert_info.evt, UCPD_EVT_HR_REQ); } else { atomic_set_bit(&data->alert_info.evt, UCPD_EVT_TCPM_MSG_REQ); } /* Start transmission */ k_work_submit(&data->alert_info.work); return 0; }
/** * @brief Transmit a power delivery message * * @return 0 on success * @return -EFAULT on failure */
@brief Transmit a power delivery message @return 0 on success @return -EFAULT on failure
[ "@brief", "Transmit", "a", "power", "delivery", "message", "@return", "0", "on", "success", "@return", "-", "EFAULT", "on", "failure" ]
static int ucpd_transmit_data(const struct device *dev, struct pd_msg *msg) { struct tcpc_data *data = dev->data; int len = PD_CONVERT_PD_HEADER_COUNT_TO_BYTES(msg->header.number_of_data_objects) + 2; if (len > UCPD_BUF_LEN) { return -EFAULT; } data->ucpd_tx_buffers[TX_MSG_TCPM].msg_len = len; data->ucpd_tx_buffers[TX_MSG_TCPM].type = msg->type; data->ucpd_tx_buffers[TX_MSG_TCPM].data.header = msg->header.raw_value; memcpy(data->ucpd_tx_buffers[TX_MSG_TCPM].data.msg + 2, (uint8_t *)msg->data, len - 2); if (msg->type == PD_PACKET_TX_HARD_RESET) { atomic_set_bit(&data->alert_info.evt, UCPD_EVT_HR_REQ); } else { atomic_set_bit(&data->alert_info.evt, UCPD_EVT_TCPM_MSG_REQ); } k_work_submit(&data->alert_info.work); return 0; }
[ "static", "int", "ucpd_transmit_data", "(", "const", "struct", "device", "*", "dev", ",", "struct", "pd_msg", "*", "msg", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "int", "len", "=", "PD_CONVERT_PD_HEADER_COUNT_TO_BYTES", "(", "msg", "->", "header", ".", "number_of_data_objects", ")", "+", "2", ";", "if", "(", "len", ">", "UCPD_BUF_LEN", ")", "{", "return", "-", "EFAULT", ";", "}", "data", "->", "ucpd_tx_buffers", "[", "TX_MSG_TCPM", "]", ".", "msg_len", "=", "len", ";", "data", "->", "ucpd_tx_buffers", "[", "TX_MSG_TCPM", "]", ".", "type", "=", "msg", "->", "type", ";", "data", "->", "ucpd_tx_buffers", "[", "TX_MSG_TCPM", "]", ".", "data", ".", "header", "=", "msg", "->", "header", ".", "raw_value", ";", "memcpy", "(", "data", "->", "ucpd_tx_buffers", "[", "TX_MSG_TCPM", "]", ".", "data", ".", "msg", "+", "2", ",", "(", "uint8_t", "*", ")", "msg", "->", "data", ",", "len", "-", "2", ")", ";", "if", "(", "msg", "->", "type", "==", "PD_PACKET_TX_HARD_RESET", ")", "{", "atomic_set_bit", "(", "&", "data", "->", "alert_info", ".", "evt", ",", "UCPD_EVT_HR_REQ", ")", ";", "}", "else", "{", "atomic_set_bit", "(", "&", "data", "->", "alert_info", ".", "evt", ",", "UCPD_EVT_TCPM_MSG_REQ", ")", ";", "}", "k_work_submit", "(", "&", "data", "->", "alert_info", ".", "work", ")", ";", "return", "0", ";", "}" ]
@brief Transmit a power delivery message @return 0 on success @return -EFAULT on failure
[ "@brief", "Transmit", "a", "power", "delivery", "message", "@return", "0", "on", "success", "@return", "-", "EFAULT", "on", "failure" ]
[ "/* Length in bytes = (4 * object len) + 2 header bytes */", "/* Store tx msg info in TCPM msg descriptor */", "/* Copy msg objects to ucpd data buffer, after 2 header bytes */", "/*\n\t * Check for hard reset message here. A different event is used for hard\n\t * resets as they are able to interrupt ongoing transmit, and should\n\t * have priority over any pending message.\n\t */", "/* Start transmission */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "msg", "type": "struct pd_msg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "struct pd_msg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_is_rx_pending_msg
bool
static bool ucpd_is_rx_pending_msg(const struct device *dev, enum pd_packet_type *type) { struct tcpc_data *data = dev->data; bool ret; ret = (*(uint32_t *)data->ucpd_rx_buffer > 0); if (ret & (type != NULL)) { *type = *(uint16_t *)data->ucpd_rx_buffer; } return ret; }
/** * @brief Tests if a received Power Delivery message is pending * * @return true if message is pending, else false */
@brief Tests if a received Power Delivery message is pending @return true if message is pending, else false
[ "@brief", "Tests", "if", "a", "received", "Power", "Delivery", "message", "is", "pending", "@return", "true", "if", "message", "is", "pending", "else", "false" ]
static bool ucpd_is_rx_pending_msg(const struct device *dev, enum pd_packet_type *type) { struct tcpc_data *data = dev->data; bool ret; ret = (*(uint32_t *)data->ucpd_rx_buffer > 0); if (ret & (type != NULL)) { *type = *(uint16_t *)data->ucpd_rx_buffer; } return ret; }
[ "static", "bool", "ucpd_is_rx_pending_msg", "(", "const", "struct", "device", "*", "dev", ",", "enum", "pd_packet_type", "*", "type", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "bool", "ret", ";", "ret", "=", "(", "*", "(", "uint32_t", "*", ")", "data", "->", "ucpd_rx_buffer", ">", "0", ")", ";", "if", "(", "ret", "&", "(", "type", "!=", "NULL", ")", ")", "{", "*", "type", "=", "*", "(", "uint16_t", "*", ")", "data", "->", "ucpd_rx_buffer", ";", "}", "return", "ret", ";", "}" ]
@brief Tests if a received Power Delivery message is pending @return true if message is pending, else false
[ "@brief", "Tests", "if", "a", "received", "Power", "Delivery", "message", "is", "pending", "@return", "true", "if", "message", "is", "pending", "else", "false" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "type", "type": "enum pd_packet_type" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "type", "type": "enum pd_packet_type", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_receive_data
int
static int ucpd_receive_data(const struct device *dev, struct pd_msg *msg) { struct tcpc_data *data = dev->data; int ret = 0; if (msg == NULL) { return -EFAULT; } /* Make sure we have a message to retrieve */ if (!ucpd_is_rx_pending_msg(dev, NULL)) { return -EIO; } msg->type = *(uint16_t *)data->ucpd_rx_buffer; msg->header.raw_value = *((uint16_t *)data->ucpd_rx_buffer + 1); msg->len = PD_CONVERT_PD_HEADER_COUNT_TO_BYTES(msg->header.number_of_data_objects); memcpy(msg->data, (data->ucpd_rx_buffer + PACKET_TYPE_SIZE + MSG_HEADER_SIZE), msg->len); ret = msg->len + MSG_HEADER_SIZE; /* All done. Clear type and header */ *(uint32_t *)data->ucpd_rx_buffer = 0; return ret; }
/** * @brief Retrieves the Power Delivery message from the TCPC * * @return number of bytes received * @return -EIO on no message to retrieve * @return -EFAULT on buf being NULL */
@brief Retrieves the Power Delivery message from the TCPC @return number of bytes received @return -EIO on no message to retrieve @return -EFAULT on buf being NULL
[ "@brief", "Retrieves", "the", "Power", "Delivery", "message", "from", "the", "TCPC", "@return", "number", "of", "bytes", "received", "@return", "-", "EIO", "on", "no", "message", "to", "retrieve", "@return", "-", "EFAULT", "on", "buf", "being", "NULL" ]
static int ucpd_receive_data(const struct device *dev, struct pd_msg *msg) { struct tcpc_data *data = dev->data; int ret = 0; if (msg == NULL) { return -EFAULT; } if (!ucpd_is_rx_pending_msg(dev, NULL)) { return -EIO; } msg->type = *(uint16_t *)data->ucpd_rx_buffer; msg->header.raw_value = *((uint16_t *)data->ucpd_rx_buffer + 1); msg->len = PD_CONVERT_PD_HEADER_COUNT_TO_BYTES(msg->header.number_of_data_objects); memcpy(msg->data, (data->ucpd_rx_buffer + PACKET_TYPE_SIZE + MSG_HEADER_SIZE), msg->len); ret = msg->len + MSG_HEADER_SIZE; *(uint32_t *)data->ucpd_rx_buffer = 0; return ret; }
[ "static", "int", "ucpd_receive_data", "(", "const", "struct", "device", "*", "dev", ",", "struct", "pd_msg", "*", "msg", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "int", "ret", "=", "0", ";", "if", "(", "msg", "==", "NULL", ")", "{", "return", "-", "EFAULT", ";", "}", "if", "(", "!", "ucpd_is_rx_pending_msg", "(", "dev", ",", "NULL", ")", ")", "{", "return", "-", "EIO", ";", "}", "msg", "->", "type", "=", "*", "(", "uint16_t", "*", ")", "data", "->", "ucpd_rx_buffer", ";", "msg", "->", "header", ".", "raw_value", "=", "*", "(", "(", "uint16_t", "*", ")", "data", "->", "ucpd_rx_buffer", "+", "1", ")", ";", "msg", "->", "len", "=", "PD_CONVERT_PD_HEADER_COUNT_TO_BYTES", "(", "msg", "->", "header", ".", "number_of_data_objects", ")", ";", "memcpy", "(", "msg", "->", "data", ",", "(", "data", "->", "ucpd_rx_buffer", "+", "PACKET_TYPE_SIZE", "+", "MSG_HEADER_SIZE", ")", ",", "msg", "->", "len", ")", ";", "ret", "=", "msg", "->", "len", "+", "MSG_HEADER_SIZE", ";", "*", "(", "uint32_t", "*", ")", "data", "->", "ucpd_rx_buffer", "=", "0", ";", "return", "ret", ";", "}" ]
@brief Retrieves the Power Delivery message from the TCPC @return number of bytes received @return -EIO on no message to retrieve @return -EFAULT on buf being NULL
[ "@brief", "Retrieves", "the", "Power", "Delivery", "message", "from", "the", "TCPC", "@return", "number", "of", "bytes", "received", "@return", "-", "EIO", "on", "no", "message", "to", "retrieve", "@return", "-", "EFAULT", "on", "buf", "being", "NULL" ]
[ "/* Make sure we have a message to retrieve */", "/* All done. Clear type and header */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "msg", "type": "struct pd_msg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "struct pd_msg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_dump_std_reg
int
static int ucpd_dump_std_reg(const struct device *dev) { const struct tcpc_config *const config = dev->config; LOG_INF("CFGR1: %08x", LL_UCPD_ReadReg(config->ucpd_port, CFG1)); LOG_INF("CFGR2: %08x", LL_UCPD_ReadReg(config->ucpd_port, CFG2)); LOG_INF("CR: %08x", LL_UCPD_ReadReg(config->ucpd_port, CR)); LOG_INF("IMR: %08x", LL_UCPD_ReadReg(config->ucpd_port, IMR)); LOG_INF("SR: %08x", LL_UCPD_ReadReg(config->ucpd_port, SR)); LOG_INF("ICR: %08x\n", LL_UCPD_ReadReg(config->ucpd_port, ICR)); return 0; }
/** * @brief Dump a set of TCPC registers * * @return 0 on success * @return -EIO on failure */
@brief Dump a set of TCPC registers @return 0 on success @return -EIO on failure
[ "@brief", "Dump", "a", "set", "of", "TCPC", "registers", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_dump_std_reg(const struct device *dev) { const struct tcpc_config *const config = dev->config; LOG_INF("CFGR1: %08x", LL_UCPD_ReadReg(config->ucpd_port, CFG1)); LOG_INF("CFGR2: %08x", LL_UCPD_ReadReg(config->ucpd_port, CFG2)); LOG_INF("CR: %08x", LL_UCPD_ReadReg(config->ucpd_port, CR)); LOG_INF("IMR: %08x", LL_UCPD_ReadReg(config->ucpd_port, IMR)); LOG_INF("SR: %08x", LL_UCPD_ReadReg(config->ucpd_port, SR)); LOG_INF("ICR: %08x\n", LL_UCPD_ReadReg(config->ucpd_port, ICR)); return 0; }
[ "static", "int", "ucpd_dump_std_reg", "(", "const", "struct", "device", "*", "dev", ")", "{", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "LOG_INF", "(", "\"", "\"", ",", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CFG1", ")", ")", ";", "LOG_INF", "(", "\"", "\"", ",", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CFG2", ")", ")", ";", "LOG_INF", "(", "\"", "\"", ",", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CR", ")", ")", ";", "LOG_INF", "(", "\"", "\"", ",", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "IMR", ")", ")", ";", "LOG_INF", "(", "\"", "\"", ",", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "SR", ")", ")", ";", "LOG_INF", "(", "\"", "\\n", "\"", ",", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "ICR", ")", ")", ";", "return", "0", ";", "}" ]
@brief Dump a set of TCPC registers @return 0 on success @return -EIO on failure
[ "@brief", "Dump", "a", "set", "of", "TCPC", "registers", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_alert_handler_cb
int
static int ucpd_set_alert_handler_cb(const struct device *dev, tcpc_alert_handler_cb_t handler, void *alert_data) { struct tcpc_data *data = dev->data; data->alert_info.handler = handler; data->alert_info.data = alert_data; return 0; }
/** * @brief Sets the alert function that's called when an interrupt is triggered * due to a TCPC alert * * @return 0 on success * @return -EINVAL on failure */
@brief Sets the alert function that's called when an interrupt is triggered due to a TCPC alert @return 0 on success @return -EINVAL on failure
[ "@brief", "Sets", "the", "alert", "function", "that", "'", "s", "called", "when", "an", "interrupt", "is", "triggered", "due", "to", "a", "TCPC", "alert", "@return", "0", "on", "success", "@return", "-", "EINVAL", "on", "failure" ]
static int ucpd_set_alert_handler_cb(const struct device *dev, tcpc_alert_handler_cb_t handler, void *alert_data) { struct tcpc_data *data = dev->data; data->alert_info.handler = handler; data->alert_info.data = alert_data; return 0; }
[ "static", "int", "ucpd_set_alert_handler_cb", "(", "const", "struct", "device", "*", "dev", ",", "tcpc_alert_handler_cb_t", "handler", ",", "void", "*", "alert_data", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "alert_info", ".", "handler", "=", "handler", ";", "data", "->", "alert_info", ".", "data", "=", "alert_data", ";", "return", "0", ";", "}" ]
@brief Sets the alert function that's called when an interrupt is triggered due to a TCPC alert
[ "@brief", "Sets", "the", "alert", "function", "that", "'", "s", "called", "when", "an", "interrupt", "is", "triggered", "due", "to", "a", "TCPC", "alert" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "handler", "type": "tcpc_alert_handler_cb_t" }, { "param": "alert_data", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "handler", "type": "tcpc_alert_handler_cb_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "alert_data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_vconn_cb
void
static void ucpd_set_vconn_cb(const struct device *dev, tcpc_vconn_control_cb_t vconn_cb) { struct tcpc_data *data = dev->data; data->vconn_cb = vconn_cb; }
/** * @brief Sets a callback that can enable or disable VCONN if the TCPC is * unable to or the system is configured in a way that does not use * the VCONN control capabilities of the TCPC * */
@brief Sets a callback that can enable or disable VCONN if the TCPC is unable to or the system is configured in a way that does not use the VCONN control capabilities of the TCPC
[ "@brief", "Sets", "a", "callback", "that", "can", "enable", "or", "disable", "VCONN", "if", "the", "TCPC", "is", "unable", "to", "or", "the", "system", "is", "configured", "in", "a", "way", "that", "does", "not", "use", "the", "VCONN", "control", "capabilities", "of", "the", "TCPC" ]
static void ucpd_set_vconn_cb(const struct device *dev, tcpc_vconn_control_cb_t vconn_cb) { struct tcpc_data *data = dev->data; data->vconn_cb = vconn_cb; }
[ "static", "void", "ucpd_set_vconn_cb", "(", "const", "struct", "device", "*", "dev", ",", "tcpc_vconn_control_cb_t", "vconn_cb", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "vconn_cb", "=", "vconn_cb", ";", "}" ]
@brief Sets a callback that can enable or disable VCONN if the TCPC is unable to or the system is configured in a way that does not use the VCONN control capabilities of the TCPC
[ "@brief", "Sets", "a", "callback", "that", "can", "enable", "or", "disable", "VCONN", "if", "the", "TCPC", "is", "unable", "to", "or", "the", "system", "is", "configured", "in", "a", "way", "that", "does", "not", "use", "the", "VCONN", "control", "capabilities", "of", "the", "TCPC" ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "vconn_cb", "type": "tcpc_vconn_control_cb_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vconn_cb", "type": "tcpc_vconn_control_cb_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_vbus_measure_cb
void
static void ucpd_set_vbus_measure_cb(const struct device *dev, tcpc_vbus_cb_t vbus_cb) { struct tcpc_data *data = dev->data; data->vbus_cb = vbus_cb; }
/** * @brief Sets a callback that can measure the value of VBUS if the TCPC is * unable to or the system is configured in a way that does not use * the VBUS measurement and detection capabilities of the TCPC. * */
@brief Sets a callback that can measure the value of VBUS if the TCPC is unable to or the system is configured in a way that does not use the VBUS measurement and detection capabilities of the TCPC.
[ "@brief", "Sets", "a", "callback", "that", "can", "measure", "the", "value", "of", "VBUS", "if", "the", "TCPC", "is", "unable", "to", "or", "the", "system", "is", "configured", "in", "a", "way", "that", "does", "not", "use", "the", "VBUS", "measurement", "and", "detection", "capabilities", "of", "the", "TCPC", "." ]
static void ucpd_set_vbus_measure_cb(const struct device *dev, tcpc_vbus_cb_t vbus_cb) { struct tcpc_data *data = dev->data; data->vbus_cb = vbus_cb; }
[ "static", "void", "ucpd_set_vbus_measure_cb", "(", "const", "struct", "device", "*", "dev", ",", "tcpc_vbus_cb_t", "vbus_cb", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "vbus_cb", "=", "vbus_cb", ";", "}" ]
@brief Sets a callback that can measure the value of VBUS if the TCPC is unable to or the system is configured in a way that does not use the VBUS measurement and detection capabilities of the TCPC.
[ "@brief", "Sets", "a", "callback", "that", "can", "measure", "the", "value", "of", "VBUS", "if", "the", "TCPC", "is", "unable", "to", "or", "the", "system", "is", "configured", "in", "a", "way", "that", "does", "not", "use", "the", "VBUS", "measurement", "and", "detection", "capabilities", "of", "the", "TCPC", "." ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "vbus_cb", "type": "tcpc_vbus_cb_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vbus_cb", "type": "tcpc_vbus_cb_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_discharge_vbus_cb
void
static void ucpd_set_discharge_vbus_cb(const struct device *dev, tcpc_discharge_vbus_cb_t discharge_vbus_cb) { struct tcpc_data *data = dev->data; data->discharge_vbus_cb = discharge_vbus_cb; }
/** * @brief Sets a callback that can discharge VBUS if the TCPC is * unable to or the system is configured in a way that does not use * the discharge VBUS capabilities of the TCPC. * */
@brief Sets a callback that can discharge VBUS if the TCPC is unable to or the system is configured in a way that does not use the discharge VBUS capabilities of the TCPC.
[ "@brief", "Sets", "a", "callback", "that", "can", "discharge", "VBUS", "if", "the", "TCPC", "is", "unable", "to", "or", "the", "system", "is", "configured", "in", "a", "way", "that", "does", "not", "use", "the", "discharge", "VBUS", "capabilities", "of", "the", "TCPC", "." ]
static void ucpd_set_discharge_vbus_cb(const struct device *dev, tcpc_discharge_vbus_cb_t discharge_vbus_cb) { struct tcpc_data *data = dev->data; data->discharge_vbus_cb = discharge_vbus_cb; }
[ "static", "void", "ucpd_set_discharge_vbus_cb", "(", "const", "struct", "device", "*", "dev", ",", "tcpc_discharge_vbus_cb_t", "discharge_vbus_cb", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "data", "->", "discharge_vbus_cb", "=", "discharge_vbus_cb", ";", "}" ]
@brief Sets a callback that can discharge VBUS if the TCPC is unable to or the system is configured in a way that does not use the discharge VBUS capabilities of the TCPC.
[ "@brief", "Sets", "a", "callback", "that", "can", "discharge", "VBUS", "if", "the", "TCPC", "is", "unable", "to", "or", "the", "system", "is", "configured", "in", "a", "way", "that", "does", "not", "use", "the", "discharge", "VBUS", "capabilities", "of", "the", "TCPC", "." ]
[]
[ { "param": "dev", "type": "struct device" }, { "param": "discharge_vbus_cb", "type": "tcpc_discharge_vbus_cb_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "discharge_vbus_cb", "type": "tcpc_discharge_vbus_cb_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_check_vbus_level
bool
static bool ucpd_check_vbus_level(const struct device *dev, enum tc_vbus_level level) { struct tcpc_data *data = dev->data; int vbus_meas; int ret; if (data->vbus_cb == NULL) { return false; } /* Call user supplied callback to measure VBUS */ ret = data->vbus_cb(dev, &vbus_meas); if (ret) { return false; } switch (level) { case TC_VBUS_SAFE0V: return (vbus_meas < PD_V_SAFE_0V_MAX_MV); case TC_VBUS_PRESENT: return (vbus_meas >= PD_V_SAFE_5V_MIN_MV); case TC_VBUS_REMOVED: return (vbus_meas < TC_V_SINK_DISCONNECT_MAX_MV); } return false; }
/** * @brief Checks if VBUS is at a particular level * * @return true if VBUS is at the level voltage, else false */
@brief Checks if VBUS is at a particular level @return true if VBUS is at the level voltage, else false
[ "@brief", "Checks", "if", "VBUS", "is", "at", "a", "particular", "level", "@return", "true", "if", "VBUS", "is", "at", "the", "level", "voltage", "else", "false" ]
static bool ucpd_check_vbus_level(const struct device *dev, enum tc_vbus_level level) { struct tcpc_data *data = dev->data; int vbus_meas; int ret; if (data->vbus_cb == NULL) { return false; } ret = data->vbus_cb(dev, &vbus_meas); if (ret) { return false; } switch (level) { case TC_VBUS_SAFE0V: return (vbus_meas < PD_V_SAFE_0V_MAX_MV); case TC_VBUS_PRESENT: return (vbus_meas >= PD_V_SAFE_5V_MIN_MV); case TC_VBUS_REMOVED: return (vbus_meas < TC_V_SINK_DISCONNECT_MAX_MV); } return false; }
[ "static", "bool", "ucpd_check_vbus_level", "(", "const", "struct", "device", "*", "dev", ",", "enum", "tc_vbus_level", "level", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "int", "vbus_meas", ";", "int", "ret", ";", "if", "(", "data", "->", "vbus_cb", "==", "NULL", ")", "{", "return", "false", ";", "}", "ret", "=", "data", "->", "vbus_cb", "(", "dev", ",", "&", "vbus_meas", ")", ";", "if", "(", "ret", ")", "{", "return", "false", ";", "}", "switch", "(", "level", ")", "{", "case", "TC_VBUS_SAFE0V", ":", "return", "(", "vbus_meas", "<", "PD_V_SAFE_0V_MAX_MV", ")", ";", "case", "TC_VBUS_PRESENT", ":", "return", "(", "vbus_meas", ">=", "PD_V_SAFE_5V_MIN_MV", ")", ";", "case", "TC_VBUS_REMOVED", ":", "return", "(", "vbus_meas", "<", "TC_V_SINK_DISCONNECT_MAX_MV", ")", ";", "}", "return", "false", ";", "}" ]
@brief Checks if VBUS is at a particular level @return true if VBUS is at the level voltage, else false
[ "@brief", "Checks", "if", "VBUS", "is", "at", "a", "particular", "level", "@return", "true", "if", "VBUS", "is", "at", "the", "level", "voltage", "else", "false" ]
[ "/* Call user supplied callback to measure VBUS */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "level", "type": "enum tc_vbus_level" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "level", "type": "enum tc_vbus_level", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_get_vbus
int
static int ucpd_get_vbus(const struct device *dev, int *vbus_meas) { struct tcpc_data *data = dev->data; int ret; if (vbus_meas == NULL) { return -EFAULT; } if (data->vbus_cb == NULL) { return -EIO; } /* Call user supplied callback to measure VBUS */ ret = data->vbus_cb(dev, vbus_meas); return ret; }
/** * @brief Reads and returns VBUS measured in mV * * @return 0 on success * @return -EIO on failure * @return -EFAULT on buf being NULL */
@brief Reads and returns VBUS measured in mV @return 0 on success @return -EIO on failure @return -EFAULT on buf being NULL
[ "@brief", "Reads", "and", "returns", "VBUS", "measured", "in", "mV", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure", "@return", "-", "EFAULT", "on", "buf", "being", "NULL" ]
static int ucpd_get_vbus(const struct device *dev, int *vbus_meas) { struct tcpc_data *data = dev->data; int ret; if (vbus_meas == NULL) { return -EFAULT; } if (data->vbus_cb == NULL) { return -EIO; } ret = data->vbus_cb(dev, vbus_meas); return ret; }
[ "static", "int", "ucpd_get_vbus", "(", "const", "struct", "device", "*", "dev", ",", "int", "*", "vbus_meas", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "int", "ret", ";", "if", "(", "vbus_meas", "==", "NULL", ")", "{", "return", "-", "EFAULT", ";", "}", "if", "(", "data", "->", "vbus_cb", "==", "NULL", ")", "{", "return", "-", "EIO", ";", "}", "ret", "=", "data", "->", "vbus_cb", "(", "dev", ",", "vbus_meas", ")", ";", "return", "ret", ";", "}" ]
@brief Reads and returns VBUS measured in mV @return 0 on success @return -EIO on failure @return -EFAULT on buf being NULL
[ "@brief", "Reads", "and", "returns", "VBUS", "measured", "in", "mV", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure", "@return", "-", "EFAULT", "on", "buf", "being", "NULL" ]
[ "/* Call user supplied callback to measure VBUS */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "vbus_meas", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vbus_meas", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_set_discharge_vbus
int
static int ucpd_set_discharge_vbus(const struct device *dev, bool enable) { struct tcpc_data *data = dev->data; int ret; if (data->discharge_vbus_cb == NULL) { return -EIO; } /* Call user supplied callback to discharge VBUS */ ret = data->discharge_vbus_cb(dev, enable); return ret; }
/** * @brief Enable or Disable Discharging of VBUS * * @return 0 on success * @return -EIO on failure */
@brief Enable or Disable Discharging of VBUS @return 0 on success @return -EIO on failure
[ "@brief", "Enable", "or", "Disable", "Discharging", "of", "VBUS", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_set_discharge_vbus(const struct device *dev, bool enable) { struct tcpc_data *data = dev->data; int ret; if (data->discharge_vbus_cb == NULL) { return -EIO; } ret = data->discharge_vbus_cb(dev, enable); return ret; }
[ "static", "int", "ucpd_set_discharge_vbus", "(", "const", "struct", "device", "*", "dev", ",", "bool", "enable", ")", "{", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "int", "ret", ";", "if", "(", "data", "->", "discharge_vbus_cb", "==", "NULL", ")", "{", "return", "-", "EIO", ";", "}", "ret", "=", "data", "->", "discharge_vbus_cb", "(", "dev", ",", "enable", ")", ";", "return", "ret", ";", "}" ]
@brief Enable or Disable Discharging of VBUS @return 0 on success @return -EIO on failure
[ "@brief", "Enable", "or", "Disable", "Discharging", "of", "VBUS", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[ "/* Call user supplied callback to discharge VBUS */" ]
[ { "param": "dev", "type": "struct device" }, { "param": "enable", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "enable", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
febb21a39a8bdf74c75bee4acd8856999e24d764
ParticleBeamHQ/zephyr
drivers/usbc/tcpc/ucpd_stm32.c
[ "Apache-2.0" ]
C
ucpd_init
int
static int ucpd_init(const struct device *dev) { const struct tcpc_config *const config = dev->config; struct tcpc_data *data = dev->data; uint32_t cfg1; int ret; /* * The UCPD port is disabled in the LL_UCPD_Init function * * NOTE: For proper Power Management operation, this function * should not be used because it circumvents the zephyr * clock API. Instead, DTS clock settings and the zephyr * clock API should be used to enable clocks. */ ret = LL_UCPD_Init(config->ucpd_port, (LL_UCPD_InitTypeDef *)&config->ucpd_params); if (ret == SUCCESS) { /* Init Rp to USB */ data->rp = TC_RP_USB; /* * Set RXORDSETEN field to control which types of ordered sets the PD * receiver must receive. */ cfg1 = LL_UCPD_ReadReg(config->ucpd_port, CFG1); cfg1 |= LL_UCPD_ORDERSET_SOP | LL_UCPD_ORDERSET_SOP1 | LL_UCPD_ORDERSET_SOP2 | LL_UCPD_ORDERSET_HARDRST; LL_UCPD_WriteReg(config->ucpd_port, CFG1, cfg1); /* Enable UCPD port */ LL_UCPD_Enable(config->ucpd_port); /* Initialize the isr */ ucpd_isr_init(dev); } else { return -EIO; } return 0; }
/** * @brief Initializes the TCPC * * @return 0 on success * @return -EIO on failure */
@brief Initializes the TCPC @return 0 on success @return -EIO on failure
[ "@brief", "Initializes", "the", "TCPC", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
static int ucpd_init(const struct device *dev) { const struct tcpc_config *const config = dev->config; struct tcpc_data *data = dev->data; uint32_t cfg1; int ret; ret = LL_UCPD_Init(config->ucpd_port, (LL_UCPD_InitTypeDef *)&config->ucpd_params); if (ret == SUCCESS) { data->rp = TC_RP_USB; cfg1 = LL_UCPD_ReadReg(config->ucpd_port, CFG1); cfg1 |= LL_UCPD_ORDERSET_SOP | LL_UCPD_ORDERSET_SOP1 | LL_UCPD_ORDERSET_SOP2 | LL_UCPD_ORDERSET_HARDRST; LL_UCPD_WriteReg(config->ucpd_port, CFG1, cfg1); LL_UCPD_Enable(config->ucpd_port); ucpd_isr_init(dev); } else { return -EIO; } return 0; }
[ "static", "int", "ucpd_init", "(", "const", "struct", "device", "*", "dev", ")", "{", "const", "struct", "tcpc_config", "*", "const", "config", "=", "dev", "->", "config", ";", "struct", "tcpc_data", "*", "data", "=", "dev", "->", "data", ";", "uint32_t", "cfg1", ";", "int", "ret", ";", "ret", "=", "LL_UCPD_Init", "(", "config", "->", "ucpd_port", ",", "(", "LL_UCPD_InitTypeDef", "*", ")", "&", "config", "->", "ucpd_params", ")", ";", "if", "(", "ret", "==", "SUCCESS", ")", "{", "data", "->", "rp", "=", "TC_RP_USB", ";", "cfg1", "=", "LL_UCPD_ReadReg", "(", "config", "->", "ucpd_port", ",", "CFG1", ")", ";", "cfg1", "|=", "LL_UCPD_ORDERSET_SOP", "|", "LL_UCPD_ORDERSET_SOP1", "|", "LL_UCPD_ORDERSET_SOP2", "|", "LL_UCPD_ORDERSET_HARDRST", ";", "LL_UCPD_WriteReg", "(", "config", "->", "ucpd_port", ",", "CFG1", ",", "cfg1", ")", ";", "LL_UCPD_Enable", "(", "config", "->", "ucpd_port", ")", ";", "ucpd_isr_init", "(", "dev", ")", ";", "}", "else", "{", "return", "-", "EIO", ";", "}", "return", "0", ";", "}" ]
@brief Initializes the TCPC @return 0 on success @return -EIO on failure
[ "@brief", "Initializes", "the", "TCPC", "@return", "0", "on", "success", "@return", "-", "EIO", "on", "failure" ]
[ "/*\n\t * The UCPD port is disabled in the LL_UCPD_Init function\n\t *\n\t * NOTE: For proper Power Management operation, this function\n\t * should not be used because it circumvents the zephyr\n\t *\t clock API. Instead, DTS clock settings and the zephyr\n\t *\t clock API should be used to enable clocks.\n\t */", "/* Init Rp to USB */", "/*\n\t\t * Set RXORDSETEN field to control which types of ordered sets the PD\n\t\t * receiver must receive.\n\t\t */", "/* Enable UCPD port */", "/* Initialize the isr */" ]
[ { "param": "dev", "type": "struct device" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
e446de2ee804f9fe2689ceb9cd974512f4cae0e3
ParticleBeamHQ/zephyr
include/zephyr/logging/log_ctrl.h
[ "Apache-2.0" ]
C
log_data_pending
bool
static inline bool log_data_pending(void) { if (IS_ENABLED(CONFIG_LOG_MODE_DEFERRED)) { return IS_ENABLED(CONFIG_LOG2) ? z_log_msg2_pending() : (log_msg_mem_get_used() > 0); } return false; }
/** * @brief Check if there is pending data to be processed by the logging subsystem. * * Function can be used to determine if all logs have been flushed. Function * returns false when deferred mode is not enabled. * * @retval true There is pending data. * @retval false No pending data to process. */
@brief Check if there is pending data to be processed by the logging subsystem. Function can be used to determine if all logs have been flushed. Function returns false when deferred mode is not enabled. @retval true There is pending data. @retval false No pending data to process.
[ "@brief", "Check", "if", "there", "is", "pending", "data", "to", "be", "processed", "by", "the", "logging", "subsystem", ".", "Function", "can", "be", "used", "to", "determine", "if", "all", "logs", "have", "been", "flushed", ".", "Function", "returns", "false", "when", "deferred", "mode", "is", "not", "enabled", ".", "@retval", "true", "There", "is", "pending", "data", ".", "@retval", "false", "No", "pending", "data", "to", "process", "." ]
static inline bool log_data_pending(void) { if (IS_ENABLED(CONFIG_LOG_MODE_DEFERRED)) { return IS_ENABLED(CONFIG_LOG2) ? z_log_msg2_pending() : (log_msg_mem_get_used() > 0); } return false; }
[ "static", "inline", "bool", "log_data_pending", "(", "void", ")", "{", "if", "(", "IS_ENABLED", "(", "CONFIG_LOG_MODE_DEFERRED", ")", ")", "{", "return", "IS_ENABLED", "(", "CONFIG_LOG2", ")", "?", "z_log_msg2_pending", "(", ")", ":", "(", "log_msg_mem_get_used", "(", ")", ">", "0", ")", ";", "}", "return", "false", ";", "}" ]
@brief Check if there is pending data to be processed by the logging subsystem.
[ "@brief", "Check", "if", "there", "is", "pending", "data", "to", "be", "processed", "by", "the", "logging", "subsystem", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
27f266bbc09bc2d420a41712ee6609bd5c499f18
ParticleBeamHQ/zephyr
subsys/bluetooth/controller/ll_sw/isoal.c
[ "Apache-2.0" ]
C
isoal_tx_pdu_emit
isoal_status_t
static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, const struct isoal_pdu_produced *produced_pdu, const uint8_t pdu_ll_id, const isoal_pdu_len_t payload_size) { struct node_tx_iso *node_tx; isoal_status_t status; uint16_t handle; /* Retrieve CIS / BIS handle */ handle = bt_iso_handle(source_ctx->session.handle); /* Retrieve Node handle */ node_tx = produced_pdu->contents.handle; /* Set PDU LLID */ produced_pdu->contents.pdu->ll_id = pdu_ll_id; /* Set PDU length */ produced_pdu->contents.pdu->length = (uint8_t)payload_size; /* Attempt to enqueue the node towards the LL */ status = source_ctx->session.pdu_emit(node_tx, handle); if (status != ISOAL_STATUS_OK) { /* If it fails, the node will be released and no further attempt * will be possible */ BT_ERR("Failed to enqueue node (%p)", node_tx); source_ctx->session.pdu_release(node_tx, handle, status); } return status; }
/** * Queue the PDU in production in the relevant LL transmit queue. If the * attmept to release the PDU fails, the buffer linked to the PDU will be released * and it will not be possible to retry the emit operation on the same PDU. * @param[in] source_ctx ISO-AL source reference for this CIS / BIS * @param[in] produced_pdu PDU in production * @param[in] pdu_ll_id LLID to be set indicating the type of fragment * @param[in] payload_size Length of the data written to the PDU * @return Error status of the operation */
Queue the PDU in production in the relevant LL transmit queue. If the attmept to release the PDU fails, the buffer linked to the PDU will be released and it will not be possible to retry the emit operation on the same PDU.
[ "Queue", "the", "PDU", "in", "production", "in", "the", "relevant", "LL", "transmit", "queue", ".", "If", "the", "attmept", "to", "release", "the", "PDU", "fails", "the", "buffer", "linked", "to", "the", "PDU", "will", "be", "released", "and", "it", "will", "not", "be", "possible", "to", "retry", "the", "emit", "operation", "on", "the", "same", "PDU", "." ]
static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, const struct isoal_pdu_produced *produced_pdu, const uint8_t pdu_ll_id, const isoal_pdu_len_t payload_size) { struct node_tx_iso *node_tx; isoal_status_t status; uint16_t handle; handle = bt_iso_handle(source_ctx->session.handle); node_tx = produced_pdu->contents.handle; produced_pdu->contents.pdu->ll_id = pdu_ll_id; produced_pdu->contents.pdu->length = (uint8_t)payload_size; status = source_ctx->session.pdu_emit(node_tx, handle); if (status != ISOAL_STATUS_OK) { BT_ERR("Failed to enqueue node (%p)", node_tx); source_ctx->session.pdu_release(node_tx, handle, status); } return status; }
[ "static", "isoal_status_t", "isoal_tx_pdu_emit", "(", "const", "struct", "isoal_source", "*", "source_ctx", ",", "const", "struct", "isoal_pdu_produced", "*", "produced_pdu", ",", "const", "uint8_t", "pdu_ll_id", ",", "const", "isoal_pdu_len_t", "payload_size", ")", "{", "struct", "node_tx_iso", "*", "node_tx", ";", "isoal_status_t", "status", ";", "uint16_t", "handle", ";", "handle", "=", "bt_iso_handle", "(", "source_ctx", "->", "session", ".", "handle", ")", ";", "node_tx", "=", "produced_pdu", "->", "contents", ".", "handle", ";", "produced_pdu", "->", "contents", ".", "pdu", "->", "ll_id", "=", "pdu_ll_id", ";", "produced_pdu", "->", "contents", ".", "pdu", "->", "length", "=", "(", "uint8_t", ")", "payload_size", ";", "status", "=", "source_ctx", "->", "session", ".", "pdu_emit", "(", "node_tx", ",", "handle", ")", ";", "if", "(", "status", "!=", "ISOAL_STATUS_OK", ")", "{", "BT_ERR", "(", "\"", "\"", ",", "node_tx", ")", ";", "source_ctx", "->", "session", ".", "pdu_release", "(", "node_tx", ",", "handle", ",", "status", ")", ";", "}", "return", "status", ";", "}" ]
Queue the PDU in production in the relevant LL transmit queue.
[ "Queue", "the", "PDU", "in", "production", "in", "the", "relevant", "LL", "transmit", "queue", "." ]
[ "/* Retrieve CIS / BIS handle */", "/* Retrieve Node handle */", "/* Set PDU LLID */", "/* Set PDU length */", "/* Attempt to enqueue the node towards the LL */", "/* If it fails, the node will be released and no further attempt\n\t\t * will be possible\n\t\t */" ]
[ { "param": "source_ctx", "type": "struct isoal_source" }, { "param": "produced_pdu", "type": "struct isoal_pdu_produced" }, { "param": "pdu_ll_id", "type": "uint8_t" }, { "param": "payload_size", "type": "isoal_pdu_len_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "source_ctx", "type": "struct isoal_source", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "produced_pdu", "type": "struct isoal_pdu_produced", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pdu_ll_id", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "payload_size", "type": "isoal_pdu_len_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
27f266bbc09bc2d420a41712ee6609bd5c499f18
ParticleBeamHQ/zephyr
subsys/bluetooth/controller/ll_sw/isoal.c
[ "Apache-2.0" ]
C
isoal_tx_unframed_produce
isoal_status_t
static isoal_status_t isoal_tx_unframed_produce(struct isoal_source *source, const struct isoal_sdu_tx *tx_sdu) { struct isoal_source_session *session; isoal_sdu_len_t packet_available; struct isoal_pdu_production *pp; const uint8_t *sdu_payload; bool zero_length_sdu; isoal_status_t err; bool padding_pdu; uint8_t ll_id; session = &source->session; pp = &source->pdu_production; padding_pdu = false; err = ISOAL_STATUS_OK; packet_available = tx_sdu->size; sdu_payload = tx_sdu->dbuf; LL_ASSERT(sdu_payload); zero_length_sdu = (packet_available == 0 && tx_sdu->sdu_state == BT_ISO_SINGLE); if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { /* Start of a new SDU */ /* Update sequence number for received SDU * * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: * 2 ISOAL Features : * SDUs received by the ISOAL from the upper layer shall be * given a sequence number which is initialized to 0 when the * CIS or BIS is created. * * NOTE: The upper layer may synchronize its sequence number * with the sequence number in the ISOAL once the Datapath is * configured and the link is established. */ session->seqn++; /* Reset PDU fragmentation count for this SDU */ pp->pdu_cnt = 0; } /* PDUs should be created until the SDU fragment has been fragmented or * if this is the last fragment of the SDU, until the required padding * PDU(s) are sent. */ while ((err == ISOAL_STATUS_OK) && ((packet_available > 0) || padding_pdu || zero_length_sdu)) { const isoal_status_t err_alloc = isoal_tx_allocate_pdu(source, tx_sdu); struct isoal_pdu_produced *pdu = &pp->pdu; err |= err_alloc; /* * For this PDU we can only consume of packet, bounded by: * - What can fit in the destination PDU. * - What remains of the packet. */ const size_t consume_len = MIN( packet_available, pp->pdu_available ); if (consume_len > 0) { err |= session->pdu_write(&pdu->contents, pp->pdu_written, sdu_payload, consume_len); sdu_payload += consume_len; pp->pdu_written += consume_len; pp->pdu_available -= consume_len; packet_available -= consume_len; } /* End of the SDU is reached at the end of the last SDU fragment * or if this is a single fragment SDU */ bool end_of_sdu = (packet_available == 0) && ((tx_sdu->sdu_state == BT_ISO_SINGLE) || (tx_sdu->sdu_state == BT_ISO_END)); /* Decide PDU type * * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: * 2.1 Unframed PDU : * LLID 0b00 PDU_BIS_LLID_COMPLETE_END: * (1) When the payload of the ISO Data PDU contains the end * fragment of an SDU. * (2) When the payload of the ISO Data PDU contains a complete * SDU. * (3) When an SDU contains zero length data, the corresponding * PDU shall be of zero length and the LLID field shall be * set to 0b00. * * LLID 0b01 PDU_BIS_LLID_COMPLETE_END: * (1) When the payload of the ISO Data PDU contains a start or * a continuation fragment of an SDU. * (2) When the ISO Data PDU is used as padding. */ ll_id = PDU_BIS_LLID_COMPLETE_END; if (!end_of_sdu || padding_pdu) { ll_id = PDU_BIS_LLID_START_CONTINUE; } const isoal_status_t err_emit = isoal_tx_try_emit_pdu(source, end_of_sdu, ll_id); err |= err_emit; /* Send padding PDU(s) if required * * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: * 2.1 Unframed PDU : * Each SDU shall generate BN ÷ (ISO_Interval ÷ SDU_Interval) * fragments. If an SDU generates less than this number of * fragments, empty payloads shall be used to make up the * number. */ padding_pdu = (end_of_sdu && (pp->pdu_cnt < session->pdus_per_sdu)); zero_length_sdu = false; } return err; }
/** * @brief Fragment received SDU and produce unframed PDUs * @details Destination source may have an already partially built PDU * * @param source[in,out] Destination source with bookkeeping state * @param tx_sdu[in] SDU with packet boundary information * * @return Status */
@brief Fragment received SDU and produce unframed PDUs @details Destination source may have an already partially built PDU @param source[in,out] Destination source with bookkeeping state @param tx_sdu[in] SDU with packet boundary information @return Status
[ "@brief", "Fragment", "received", "SDU", "and", "produce", "unframed", "PDUs", "@details", "Destination", "source", "may", "have", "an", "already", "partially", "built", "PDU", "@param", "source", "[", "in", "out", "]", "Destination", "source", "with", "bookkeeping", "state", "@param", "tx_sdu", "[", "in", "]", "SDU", "with", "packet", "boundary", "information", "@return", "Status" ]
static isoal_status_t isoal_tx_unframed_produce(struct isoal_source *source, const struct isoal_sdu_tx *tx_sdu) { struct isoal_source_session *session; isoal_sdu_len_t packet_available; struct isoal_pdu_production *pp; const uint8_t *sdu_payload; bool zero_length_sdu; isoal_status_t err; bool padding_pdu; uint8_t ll_id; session = &source->session; pp = &source->pdu_production; padding_pdu = false; err = ISOAL_STATUS_OK; packet_available = tx_sdu->size; sdu_payload = tx_sdu->dbuf; LL_ASSERT(sdu_payload); zero_length_sdu = (packet_available == 0 && tx_sdu->sdu_state == BT_ISO_SINGLE); if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { session->seqn++; pp->pdu_cnt = 0; } while ((err == ISOAL_STATUS_OK) && ((packet_available > 0) || padding_pdu || zero_length_sdu)) { const isoal_status_t err_alloc = isoal_tx_allocate_pdu(source, tx_sdu); struct isoal_pdu_produced *pdu = &pp->pdu; err |= err_alloc; const size_t consume_len = MIN( packet_available, pp->pdu_available ); if (consume_len > 0) { err |= session->pdu_write(&pdu->contents, pp->pdu_written, sdu_payload, consume_len); sdu_payload += consume_len; pp->pdu_written += consume_len; pp->pdu_available -= consume_len; packet_available -= consume_len; } bool end_of_sdu = (packet_available == 0) && ((tx_sdu->sdu_state == BT_ISO_SINGLE) || (tx_sdu->sdu_state == BT_ISO_END)); ll_id = PDU_BIS_LLID_COMPLETE_END; if (!end_of_sdu || padding_pdu) { ll_id = PDU_BIS_LLID_START_CONTINUE; } const isoal_status_t err_emit = isoal_tx_try_emit_pdu(source, end_of_sdu, ll_id); err |= err_emit; padding_pdu = (end_of_sdu && (pp->pdu_cnt < session->pdus_per_sdu)); zero_length_sdu = false; } return err; }
[ "static", "isoal_status_t", "isoal_tx_unframed_produce", "(", "struct", "isoal_source", "*", "source", ",", "const", "struct", "isoal_sdu_tx", "*", "tx_sdu", ")", "{", "struct", "isoal_source_session", "*", "session", ";", "isoal_sdu_len_t", "packet_available", ";", "struct", "isoal_pdu_production", "*", "pp", ";", "const", "uint8_t", "*", "sdu_payload", ";", "bool", "zero_length_sdu", ";", "isoal_status_t", "err", ";", "bool", "padding_pdu", ";", "uint8_t", "ll_id", ";", "session", "=", "&", "source", "->", "session", ";", "pp", "=", "&", "source", "->", "pdu_production", ";", "padding_pdu", "=", "false", ";", "err", "=", "ISOAL_STATUS_OK", ";", "packet_available", "=", "tx_sdu", "->", "size", ";", "sdu_payload", "=", "tx_sdu", "->", "dbuf", ";", "LL_ASSERT", "(", "sdu_payload", ")", ";", "zero_length_sdu", "=", "(", "packet_available", "==", "0", "&&", "tx_sdu", "->", "sdu_state", "==", "BT_ISO_SINGLE", ")", ";", "if", "(", "tx_sdu", "->", "sdu_state", "==", "BT_ISO_START", "||", "tx_sdu", "->", "sdu_state", "==", "BT_ISO_SINGLE", ")", "{", "session", "->", "seqn", "++", ";", "pp", "->", "pdu_cnt", "=", "0", ";", "}", "while", "(", "(", "err", "==", "ISOAL_STATUS_OK", ")", "&&", "(", "(", "packet_available", ">", "0", ")", "||", "padding_pdu", "||", "zero_length_sdu", ")", ")", "{", "const", "isoal_status_t", "err_alloc", "=", "isoal_tx_allocate_pdu", "(", "source", ",", "tx_sdu", ")", ";", "struct", "isoal_pdu_produced", "*", "pdu", "=", "&", "pp", "->", "pdu", ";", "err", "|=", "err_alloc", ";", "const", "size_t", "consume_len", "=", "MIN", "(", "packet_available", ",", "pp", "->", "pdu_available", ")", ";", "if", "(", "consume_len", ">", "0", ")", "{", "err", "|=", "session", "->", "pdu_write", "(", "&", "pdu", "->", "contents", ",", "pp", "->", "pdu_written", ",", "sdu_payload", ",", "consume_len", ")", ";", "sdu_payload", "+=", "consume_len", ";", "pp", "->", "pdu_written", "+=", "consume_len", ";", "pp", "->", "pdu_available", "-=", "consume_len", ";", "packet_available", "-=", "consume_len", ";", "}", "bool", "end_of_sdu", "=", "(", "packet_available", "==", "0", ")", "&&", "(", "(", "tx_sdu", "->", "sdu_state", "==", "BT_ISO_SINGLE", ")", "||", "(", "tx_sdu", "->", "sdu_state", "==", "BT_ISO_END", ")", ")", ";", "ll_id", "=", "PDU_BIS_LLID_COMPLETE_END", ";", "if", "(", "!", "end_of_sdu", "||", "padding_pdu", ")", "{", "ll_id", "=", "PDU_BIS_LLID_START_CONTINUE", ";", "}", "const", "isoal_status_t", "err_emit", "=", "isoal_tx_try_emit_pdu", "(", "source", ",", "end_of_sdu", ",", "ll_id", ")", ";", "err", "|=", "err_emit", ";", "padding_pdu", "=", "(", "end_of_sdu", "&&", "(", "pp", "->", "pdu_cnt", "<", "session", "->", "pdus_per_sdu", ")", ")", ";", "zero_length_sdu", "=", "false", ";", "}", "return", "err", ";", "}" ]
@brief Fragment received SDU and produce unframed PDUs @details Destination source may have an already partially built PDU
[ "@brief", "Fragment", "received", "SDU", "and", "produce", "unframed", "PDUs", "@details", "Destination", "source", "may", "have", "an", "already", "partially", "built", "PDU" ]
[ "/* Start of a new SDU */", "/* Update sequence number for received SDU\n\t\t *\n\t\t * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL:\n\t\t * 2 ISOAL Features :\n\t\t * SDUs received by the ISOAL from the upper layer shall be\n\t\t * given a sequence number which is initialized to 0 when the\n\t\t * CIS or BIS is created.\n\t\t *\n\t\t * NOTE: The upper layer may synchronize its sequence number\n\t\t * with the sequence number in the ISOAL once the Datapath is\n\t\t * configured and the link is established.\n\t\t */", "/* Reset PDU fragmentation count for this SDU */", "/* PDUs should be created until the SDU fragment has been fragmented or\n\t * if this is the last fragment of the SDU, until the required padding\n\t * PDU(s) are sent.\n\t */", "/*\n\t\t * For this PDU we can only consume of packet, bounded by:\n\t\t * - What can fit in the destination PDU.\n\t\t * - What remains of the packet.\n\t\t */", "/* End of the SDU is reached at the end of the last SDU fragment\n\t\t * or if this is a single fragment SDU\n\t\t */", "/* Decide PDU type\n\t\t *\n\t\t * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL:\n\t\t * 2.1 Unframed PDU :\n\t\t * LLID 0b00 PDU_BIS_LLID_COMPLETE_END:\n\t\t * (1) When the payload of the ISO Data PDU contains the end\n\t\t * fragment of an SDU.\n\t\t * (2) When the payload of the ISO Data PDU contains a complete\n\t\t * SDU.\n\t\t * (3) When an SDU contains zero length data, the corresponding\n\t\t * PDU shall be of zero length and the LLID field shall be\n\t\t * set to 0b00.\n\t\t *\n\t\t * LLID 0b01 PDU_BIS_LLID_COMPLETE_END:\n\t\t * (1) When the payload of the ISO Data PDU contains a start or\n\t\t * a continuation fragment of an SDU.\n\t\t * (2) When the ISO Data PDU is used as padding.\n\t\t */", "/* Send padding PDU(s) if required\n\t\t *\n\t\t * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL:\n\t\t * 2.1 Unframed PDU :\n\t\t * Each SDU shall generate BN ÷ (ISO_Interval ÷ SDU_Interval)\n\t\t * fragments. If an SDU generates less than this number of\n\t\t * fragments, empty payloads shall be used to make up the\n\t\t * number.\n\t\t */" ]
[ { "param": "source", "type": "struct isoal_source" }, { "param": "tx_sdu", "type": "struct isoal_sdu_tx" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "source", "type": "struct isoal_source", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "tx_sdu", "type": "struct isoal_sdu_tx", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
27f266bbc09bc2d420a41712ee6609bd5c499f18
ParticleBeamHQ/zephyr
subsys/bluetooth/controller/ll_sw/isoal.c
[ "Apache-2.0" ]
C
isoal_tx_sdu_fragment
isoal_status_t
isoal_status_t isoal_tx_sdu_fragment(isoal_source_handle_t source_hdl, const struct isoal_sdu_tx *tx_sdu) { struct isoal_source *source = &isoal_global.source_state[source_hdl]; isoal_status_t err = ISOAL_STATUS_ERR_PDU_ALLOC; if (source->pdu_production.mode != ISOAL_PRODUCTION_MODE_DISABLED) { /* TODO: consider how to separate framed and unframed production * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: * 2 ISOAL Features : * (1) Unframed PDUs shall only be used when the ISO_Interval * is equal to or an integer multiple of the SDU_Interval * and a constant time offset alignment is maintained * between the SDU generation and the timing in the * isochronous transport. * (2) When the Host requests the use of framed PDUs, the * Controller shall use framed PDUs. */ bool pdu_framed = false; if (pdu_framed) { /* TODO: add framed handling */ } else { err = isoal_tx_unframed_produce(source, tx_sdu); } } return err; }
/** * @brief Deep copy a SDU, fragment into PDU(s) * @details Fragmentation will occur individually for every enabled source * * @param source_hdl[in] Handle of destination source * @param tx_sdu[in] SDU along with packet boudary state * @return Status */
@brief Deep copy a SDU, fragment into PDU(s) @details Fragmentation will occur individually for every enabled source @param source_hdl[in] Handle of destination source @param tx_sdu[in] SDU along with packet boudary state @return Status
[ "@brief", "Deep", "copy", "a", "SDU", "fragment", "into", "PDU", "(", "s", ")", "@details", "Fragmentation", "will", "occur", "individually", "for", "every", "enabled", "source", "@param", "source_hdl", "[", "in", "]", "Handle", "of", "destination", "source", "@param", "tx_sdu", "[", "in", "]", "SDU", "along", "with", "packet", "boudary", "state", "@return", "Status" ]
isoal_status_t isoal_tx_sdu_fragment(isoal_source_handle_t source_hdl, const struct isoal_sdu_tx *tx_sdu) { struct isoal_source *source = &isoal_global.source_state[source_hdl]; isoal_status_t err = ISOAL_STATUS_ERR_PDU_ALLOC; if (source->pdu_production.mode != ISOAL_PRODUCTION_MODE_DISABLED) { bool pdu_framed = false; if (pdu_framed) { } else { err = isoal_tx_unframed_produce(source, tx_sdu); } } return err; }
[ "isoal_status_t", "isoal_tx_sdu_fragment", "(", "isoal_source_handle_t", "source_hdl", ",", "const", "struct", "isoal_sdu_tx", "*", "tx_sdu", ")", "{", "struct", "isoal_source", "*", "source", "=", "&", "isoal_global", ".", "source_state", "[", "source_hdl", "]", ";", "isoal_status_t", "err", "=", "ISOAL_STATUS_ERR_PDU_ALLOC", ";", "if", "(", "source", "->", "pdu_production", ".", "mode", "!=", "ISOAL_PRODUCTION_MODE_DISABLED", ")", "{", "bool", "pdu_framed", "=", "false", ";", "if", "(", "pdu_framed", ")", "{", "}", "else", "{", "err", "=", "isoal_tx_unframed_produce", "(", "source", ",", "tx_sdu", ")", ";", "}", "}", "return", "err", ";", "}" ]
@brief Deep copy a SDU, fragment into PDU(s) @details Fragmentation will occur individually for every enabled source
[ "@brief", "Deep", "copy", "a", "SDU", "fragment", "into", "PDU", "(", "s", ")", "@details", "Fragmentation", "will", "occur", "individually", "for", "every", "enabled", "source" ]
[ "/* TODO: consider how to separate framed and unframed production\n\t\t * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL:\n\t\t * 2 ISOAL Features :\n\t\t * (1) Unframed PDUs shall only be used when the ISO_Interval\n\t\t * is equal to or an integer multiple of the SDU_Interval\n\t\t * and a constant time offset alignment is maintained\n\t\t * between the SDU generation and the timing in the\n\t\t * isochronous transport.\n\t\t * (2) When the Host requests the use of framed PDUs, the\n\t\t * Controller shall use framed PDUs.\n\t\t */", "/* TODO: add framed handling */" ]
[ { "param": "source_hdl", "type": "isoal_source_handle_t" }, { "param": "tx_sdu", "type": "struct isoal_sdu_tx" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "source_hdl", "type": "isoal_source_handle_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "tx_sdu", "type": "struct isoal_sdu_tx", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
27a22eb36e292069979ad01bdd99698e9e3c8edd
ParticleBeamHQ/zephyr
drivers/pinctrl/pinctrl_b91.c
[ "Apache-2.0" ]
C
pinctrl_b91_get_offset
int
static inline int pinctrl_b91_get_offset(uint32_t pin, uint8_t *offset) { switch (B91_PINMUX_GET_PIN_ID(pin)) { case B91_PIN_0: *offset = B91_PIN_0_FUNC_POS; break; case B91_PIN_1: *offset = B91_PIN_1_FUNC_POS; break; case B91_PIN_2: *offset = B91_PIN_2_FUNC_POS; break; case B91_PIN_3: *offset = B91_PIN_3_FUNC_POS; break; case B91_PIN_4: *offset = B91_PIN_4_FUNC_POS; break; case B91_PIN_5: *offset = B91_PIN_5_FUNC_POS; break; case B91_PIN_6: *offset = B91_PIN_6_FUNC_POS; break; case B91_PIN_7: *offset = B91_PIN_7_FUNC_POS; break; default: return -EINVAL; } return 0; }
/* Get function value bits start position (offset) */
Get function value bits start position (offset)
[ "Get", "function", "value", "bits", "start", "position", "(", "offset", ")" ]
static inline int pinctrl_b91_get_offset(uint32_t pin, uint8_t *offset) { switch (B91_PINMUX_GET_PIN_ID(pin)) { case B91_PIN_0: *offset = B91_PIN_0_FUNC_POS; break; case B91_PIN_1: *offset = B91_PIN_1_FUNC_POS; break; case B91_PIN_2: *offset = B91_PIN_2_FUNC_POS; break; case B91_PIN_3: *offset = B91_PIN_3_FUNC_POS; break; case B91_PIN_4: *offset = B91_PIN_4_FUNC_POS; break; case B91_PIN_5: *offset = B91_PIN_5_FUNC_POS; break; case B91_PIN_6: *offset = B91_PIN_6_FUNC_POS; break; case B91_PIN_7: *offset = B91_PIN_7_FUNC_POS; break; default: return -EINVAL; } return 0; }
[ "static", "inline", "int", "pinctrl_b91_get_offset", "(", "uint32_t", "pin", ",", "uint8_t", "*", "offset", ")", "{", "switch", "(", "B91_PINMUX_GET_PIN_ID", "(", "pin", ")", ")", "{", "case", "B91_PIN_0", ":", "*", "offset", "=", "B91_PIN_0_FUNC_POS", ";", "break", ";", "case", "B91_PIN_1", ":", "*", "offset", "=", "B91_PIN_1_FUNC_POS", ";", "break", ";", "case", "B91_PIN_2", ":", "*", "offset", "=", "B91_PIN_2_FUNC_POS", ";", "break", ";", "case", "B91_PIN_3", ":", "*", "offset", "=", "B91_PIN_3_FUNC_POS", ";", "break", ";", "case", "B91_PIN_4", ":", "*", "offset", "=", "B91_PIN_4_FUNC_POS", ";", "break", ";", "case", "B91_PIN_5", ":", "*", "offset", "=", "B91_PIN_5_FUNC_POS", ";", "break", ";", "case", "B91_PIN_6", ":", "*", "offset", "=", "B91_PIN_6_FUNC_POS", ";", "break", ";", "case", "B91_PIN_7", ":", "*", "offset", "=", "B91_PIN_7_FUNC_POS", ";", "break", ";", "default", ":", "return", "-", "EINVAL", ";", "}", "return", "0", ";", "}" ]
Get function value bits start position (offset)
[ "Get", "function", "value", "bits", "start", "position", "(", "offset", ")" ]
[]
[ { "param": "pin", "type": "uint32_t" }, { "param": "offset", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pin", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "offset", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
08623fdaef76bf3794e228f2de8142635fc61377
ParticleBeamHQ/zephyr
include/zephyr/sys/util.h
[ "Apache-2.0" ]
C
bytecpy
void
static inline void bytecpy(void *dst, const void *src, size_t size) { size_t i; for (i = 0; i < size; ++i) { ((volatile uint8_t *)dst)[i] = ((volatile const uint8_t *)src)[i]; } }
/** * @brief byte by byte memcpy. * * Copy `size` bytes of `src` into `dest`. This is guaranteed to be done byte by byte. * * @param dst Pointer to the destination memory. * @param src Pointer to the source of the data. * @param size The number of bytes to copy. */
@brief byte by byte memcpy. @param dst Pointer to the destination memory. @param src Pointer to the source of the data. @param size The number of bytes to copy.
[ "@brief", "byte", "by", "byte", "memcpy", ".", "@param", "dst", "Pointer", "to", "the", "destination", "memory", ".", "@param", "src", "Pointer", "to", "the", "source", "of", "the", "data", ".", "@param", "size", "The", "number", "of", "bytes", "to", "copy", "." ]
static inline void bytecpy(void *dst, const void *src, size_t size) { size_t i; for (i = 0; i < size; ++i) { ((volatile uint8_t *)dst)[i] = ((volatile const uint8_t *)src)[i]; } }
[ "static", "inline", "void", "bytecpy", "(", "void", "*", "dst", ",", "const", "void", "*", "src", ",", "size_t", "size", ")", "{", "size_t", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "size", ";", "++", "i", ")", "{", "(", "(", "volatile", "uint8_t", "*", ")", "dst", ")", "[", "i", "]", "=", "(", "(", "volatile", "const", "uint8_t", "*", ")", "src", ")", "[", "i", "]", ";", "}", "}" ]
@brief byte by byte memcpy.
[ "@brief", "byte", "by", "byte", "memcpy", "." ]
[]
[ { "param": "dst", "type": "void" }, { "param": "src", "type": "void" }, { "param": "size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dst", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "src", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
08623fdaef76bf3794e228f2de8142635fc61377
ParticleBeamHQ/zephyr
include/zephyr/sys/util.h
[ "Apache-2.0" ]
C
byteswp
void
static inline void byteswp(void *a, void *b, size_t size) { uint8_t t; uint8_t *aa = (uint8_t *)a; uint8_t *bb = (uint8_t *)b; for (; size > 0; --size) { t = *aa; *aa++ = *bb; *bb++ = t; } }
/** * @brief byte by byte swap. * * Swap @a size bytes between memory regions @a a and @a b. This is * guaranteed to be done byte by byte. * * @param a Pointer to the the first memory region. * @param b Pointer to the the second memory region. * @param size The number of bytes to swap. */
@brief byte by byte swap. Swap @a size bytes between memory regions @a a and @a b. This is guaranteed to be done byte by byte. @param a Pointer to the the first memory region. @param b Pointer to the the second memory region. @param size The number of bytes to swap.
[ "@brief", "byte", "by", "byte", "swap", ".", "Swap", "@a", "size", "bytes", "between", "memory", "regions", "@a", "a", "and", "@a", "b", ".", "This", "is", "guaranteed", "to", "be", "done", "byte", "by", "byte", ".", "@param", "a", "Pointer", "to", "the", "the", "first", "memory", "region", ".", "@param", "b", "Pointer", "to", "the", "the", "second", "memory", "region", ".", "@param", "size", "The", "number", "of", "bytes", "to", "swap", "." ]
static inline void byteswp(void *a, void *b, size_t size) { uint8_t t; uint8_t *aa = (uint8_t *)a; uint8_t *bb = (uint8_t *)b; for (; size > 0; --size) { t = *aa; *aa++ = *bb; *bb++ = t; } }
[ "static", "inline", "void", "byteswp", "(", "void", "*", "a", ",", "void", "*", "b", ",", "size_t", "size", ")", "{", "uint8_t", "t", ";", "uint8_t", "*", "aa", "=", "(", "uint8_t", "*", ")", "a", ";", "uint8_t", "*", "bb", "=", "(", "uint8_t", "*", ")", "b", ";", "for", "(", ";", "size", ">", "0", ";", "--", "size", ")", "{", "t", "=", "*", "aa", ";", "*", "aa", "++", "=", "*", "bb", ";", "*", "bb", "++", "=", "t", ";", "}", "}" ]
@brief byte by byte swap.
[ "@brief", "byte", "by", "byte", "swap", "." ]
[]
[ { "param": "a", "type": "void" }, { "param": "b", "type": "void" }, { "param": "size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "a", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "b", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
32045e564daf5090683856108662fa6f27a7fb9d
onsimini/ChipBot
sw/cam_test/Core/Src/main.c
[ "MIT" ]
C
SystemClock_Config
void
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; /** Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4; RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1; PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } }
/** * @brief System Clock Configuration * @retval None */
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4; RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1; PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } }
[ "void", "SystemClock_Config", "(", "void", ")", "{", "RCC_OscInitTypeDef", "RCC_OscInitStruct", "=", "{", "0", "}", ";", "RCC_ClkInitTypeDef", "RCC_ClkInitStruct", "=", "{", "0", "}", ";", "RCC_PeriphCLKInitTypeDef", "PeriphClkInit", "=", "{", "0", "}", ";", "__HAL_PWR_VOLTAGESCALING_CONFIG", "(", "PWR_REGULATOR_VOLTAGE_SCALE1", ")", ";", "RCC_OscInitStruct", ".", "OscillatorType", "=", "RCC_OSCILLATORTYPE_HSI", ";", "RCC_OscInitStruct", ".", "HSIState", "=", "RCC_HSI_ON", ";", "RCC_OscInitStruct", ".", "HSICalibrationValue", "=", "RCC_HSICALIBRATION_DEFAULT", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLState", "=", "RCC_PLL_ON", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLSource", "=", "RCC_PLLSOURCE_HSI", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLMUL", "=", "RCC_PLLMUL_4", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLDIV", "=", "RCC_PLLDIV_2", ";", "if", "(", "HAL_RCC_OscConfig", "(", "&", "RCC_OscInitStruct", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "RCC_ClkInitStruct", ".", "ClockType", "=", "RCC_CLOCKTYPE_HCLK", "|", "RCC_CLOCKTYPE_SYSCLK", "|", "RCC_CLOCKTYPE_PCLK1", "|", "RCC_CLOCKTYPE_PCLK2", ";", "RCC_ClkInitStruct", ".", "SYSCLKSource", "=", "RCC_SYSCLKSOURCE_PLLCLK", ";", "RCC_ClkInitStruct", ".", "AHBCLKDivider", "=", "RCC_SYSCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB1CLKDivider", "=", "RCC_HCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB2CLKDivider", "=", "RCC_HCLK_DIV1", ";", "if", "(", "HAL_RCC_ClockConfig", "(", "&", "RCC_ClkInitStruct", ",", "FLASH_LATENCY_1", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "PeriphClkInit", ".", "PeriphClockSelection", "=", "RCC_PERIPHCLK_I2C1", ";", "PeriphClkInit", ".", "I2c1ClockSelection", "=", "RCC_I2C1CLKSOURCE_PCLK1", ";", "if", "(", "HAL_RCCEx_PeriphCLKConfig", "(", "&", "PeriphClkInit", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
[ "/** Configure the main internal regulator output voltage\r\n */", "/** Initializes the RCC Oscillators according to the specified parameters\r\n * in the RCC_OscInitTypeDef structure.\r\n */", "/** Initializes the CPU, AHB and APB buses clocks\r\n */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
32045e564daf5090683856108662fa6f27a7fb9d
onsimini/ChipBot
sw/cam_test/Core/Src/main.c
[ "MIT" ]
C
MX_GPIO_Init
void
static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, cam_pwd_Pin|cam_rst_Pin, GPIO_PIN_RESET); /*Configure GPIO pins : cam_pwd_Pin cam_rst_Pin */ GPIO_InitStruct.Pin = cam_pwd_Pin|cam_rst_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); }
/** * @brief GPIO Initialization Function * @param None * @retval None */
@brief GPIO Initialization Function @param None @retval None
[ "@brief", "GPIO", "Initialization", "Function", "@param", "None", "@retval", "None" ]
static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); HAL_GPIO_WritePin(GPIOB, cam_pwd_Pin|cam_rst_Pin, GPIO_PIN_RESET); GPIO_InitStruct.Pin = cam_pwd_Pin|cam_rst_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); }
[ "static", "void", "MX_GPIO_Init", "(", "void", ")", "{", "GPIO_InitTypeDef", "GPIO_InitStruct", "=", "{", "0", "}", ";", "__HAL_RCC_GPIOA_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_GPIOB_CLK_ENABLE", "(", ")", ";", "HAL_GPIO_WritePin", "(", "GPIOB", ",", "cam_pwd_Pin", "|", "cam_rst_Pin", ",", "GPIO_PIN_RESET", ")", ";", "GPIO_InitStruct", ".", "Pin", "=", "cam_pwd_Pin", "|", "cam_rst_Pin", ";", "GPIO_InitStruct", ".", "Mode", "=", "GPIO_MODE_OUTPUT_PP", ";", "GPIO_InitStruct", ".", "Pull", "=", "GPIO_NOPULL", ";", "GPIO_InitStruct", ".", "Speed", "=", "GPIO_SPEED_FREQ_LOW", ";", "HAL_GPIO_Init", "(", "GPIOB", ",", "&", "GPIO_InitStruct", ")", ";", "}" ]
@brief GPIO Initialization Function @param None @retval None
[ "@brief", "GPIO", "Initialization", "Function", "@param", "None", "@retval", "None" ]
[ "/* GPIO Ports Clock Enable */", "/*Configure GPIO pin Output Level */", "/*Configure GPIO pins : cam_pwd_Pin cam_rst_Pin */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
cb745b072b29bb686bffc2520c844f4cb83bb377
Francesco149/q3playground
main.c
[ "Unlicense" ]
C
bsp_find_leaf
int
int bsp_find_leaf(struct bsp_file* file, float* camera_pos) { int index; index = 0; while (index >= 0) { float distance; struct bsp_node* node; struct bsp_plane* plane; node = &file->nodes[index]; plane = &file->planes[node->plane]; distance = dot3(camera_pos, plane->normal) - plane->dist; if (distance >= 0) { index = node->child[0]; } else { index = node->child[1]; } } return (-index) - 1; }
/* * the plane dist is the distance from the origin along the normal so if * we project the camera position onto the normal with the dot product and * subtract dist, we get the distance between the camera position and the * plane * * note that leaf indices are negative, and that's how we tell we hit a * leaf while navigating the bsp tree * * since 0 is taken by positive indices, leaf index -1 maps to leaf 0, * -2 to 1, and so on */
the plane dist is the distance from the origin along the normal so if we project the camera position onto the normal with the dot product and subtract dist, we get the distance between the camera position and the plane note that leaf indices are negative, and that's how we tell we hit a leaf while navigating the bsp tree since 0 is taken by positive indices, leaf index -1 maps to leaf 0, -2 to 1, and so on
[ "the", "plane", "dist", "is", "the", "distance", "from", "the", "origin", "along", "the", "normal", "so", "if", "we", "project", "the", "camera", "position", "onto", "the", "normal", "with", "the", "dot", "product", "and", "subtract", "dist", "we", "get", "the", "distance", "between", "the", "camera", "position", "and", "the", "plane", "note", "that", "leaf", "indices", "are", "negative", "and", "that", "'", "s", "how", "we", "tell", "we", "hit", "a", "leaf", "while", "navigating", "the", "bsp", "tree", "since", "0", "is", "taken", "by", "positive", "indices", "leaf", "index", "-", "1", "maps", "to", "leaf", "0", "-", "2", "to", "1", "and", "so", "on" ]
int bsp_find_leaf(struct bsp_file* file, float* camera_pos) { int index; index = 0; while (index >= 0) { float distance; struct bsp_node* node; struct bsp_plane* plane; node = &file->nodes[index]; plane = &file->planes[node->plane]; distance = dot3(camera_pos, plane->normal) - plane->dist; if (distance >= 0) { index = node->child[0]; } else { index = node->child[1]; } } return (-index) - 1; }
[ "int", "bsp_find_leaf", "(", "struct", "bsp_file", "*", "file", ",", "float", "*", "camera_pos", ")", "{", "int", "index", ";", "index", "=", "0", ";", "while", "(", "index", ">=", "0", ")", "{", "float", "distance", ";", "struct", "bsp_node", "*", "node", ";", "struct", "bsp_plane", "*", "plane", ";", "node", "=", "&", "file", "->", "nodes", "[", "index", "]", ";", "plane", "=", "&", "file", "->", "planes", "[", "node", "->", "plane", "]", ";", "distance", "=", "dot3", "(", "camera_pos", ",", "plane", "->", "normal", ")", "-", "plane", "->", "dist", ";", "if", "(", "distance", ">=", "0", ")", "{", "index", "=", "node", "->", "child", "[", "0", "]", ";", "}", "else", "{", "index", "=", "node", "->", "child", "[", "1", "]", ";", "}", "}", "return", "(", "-", "index", ")", "-", "1", ";", "}" ]
the plane dist is the distance from the origin along the normal so if we project the camera position onto the normal with the dot product and subtract dist, we get the distance between the camera position and the plane
[ "the", "plane", "dist", "is", "the", "distance", "from", "the", "origin", "along", "the", "normal", "so", "if", "we", "project", "the", "camera", "position", "onto", "the", "normal", "with", "the", "dot", "product", "and", "subtract", "dist", "we", "get", "the", "distance", "between", "the", "camera", "position", "and", "the", "plane" ]
[]
[ { "param": "file", "type": "struct bsp_file" }, { "param": "camera_pos", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "struct bsp_file", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "camera_pos", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cb745b072b29bb686bffc2520c844f4cb83bb377
Francesco149/q3playground
main.c
[ "Unlicense" ]
C
bsp_cluster_visible
int
int bsp_cluster_visible(struct bsp_file* file, int from, int target) { int index; index = from * file->visdata->sz_vecs + target / 8; return (file->visdata_vecs[index] & (1 << (target % 8))) != 0; }
/* * the visdata vecs are huge bitmasks. each bit is one y step and each * sz_vecs bytes is one x step * * cluster x is visible from cluster y if the y-th bit in the x-th bitmask * is set. it's basically a visibility matrix with every possible * combination of clusters packed as bitmask */
the visdata vecs are huge bitmasks. each bit is one y step and each sz_vecs bytes is one x step cluster x is visible from cluster y if the y-th bit in the x-th bitmask is set. it's basically a visibility matrix with every possible combination of clusters packed as bitmask
[ "the", "visdata", "vecs", "are", "huge", "bitmasks", ".", "each", "bit", "is", "one", "y", "step", "and", "each", "sz_vecs", "bytes", "is", "one", "x", "step", "cluster", "x", "is", "visible", "from", "cluster", "y", "if", "the", "y", "-", "th", "bit", "in", "the", "x", "-", "th", "bitmask", "is", "set", ".", "it", "'", "s", "basically", "a", "visibility", "matrix", "with", "every", "possible", "combination", "of", "clusters", "packed", "as", "bitmask" ]
int bsp_cluster_visible(struct bsp_file* file, int from, int target) { int index; index = from * file->visdata->sz_vecs + target / 8; return (file->visdata_vecs[index] & (1 << (target % 8))) != 0; }
[ "int", "bsp_cluster_visible", "(", "struct", "bsp_file", "*", "file", ",", "int", "from", ",", "int", "target", ")", "{", "int", "index", ";", "index", "=", "from", "*", "file", "->", "visdata", "->", "sz_vecs", "+", "target", "/", "8", ";", "return", "(", "file", "->", "visdata_vecs", "[", "index", "]", "&", "(", "1", "<<", "(", "target", "%", "8", ")", ")", ")", "!=", "0", ";", "}" ]
the visdata vecs are huge bitmasks.
[ "the", "visdata", "vecs", "are", "huge", "bitmasks", "." ]
[]
[ { "param": "file", "type": "struct bsp_file" }, { "param": "from", "type": "int" }, { "param": "target", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "struct bsp_file", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "from", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "target", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cb745b072b29bb686bffc2520c844f4cb83bb377
Francesco149/q3playground
main.c
[ "Unlicense" ]
C
mul_vertex
null
struct bsp_vertex mul_vertex(struct bsp_vertex* vertex, float scalar) { struct bsp_vertex res; res = *vertex; mul3_scalar(res.position, scalar); mul2_scalar(res.texcoord[0], scalar); mul2_scalar(res.texcoord[1], scalar); mul3_scalar(res.normal, scalar); return res; }
/* * this is slow but it makes code look nicer and we only use it on init * anyway so it's not a real performance hit */
this is slow but it makes code look nicer and we only use it on init anyway so it's not a real performance hit
[ "this", "is", "slow", "but", "it", "makes", "code", "look", "nicer", "and", "we", "only", "use", "it", "on", "init", "anyway", "so", "it", "'", "s", "not", "a", "real", "performance", "hit" ]
struct bsp_vertex mul_vertex(struct bsp_vertex* vertex, float scalar) { struct bsp_vertex res; res = *vertex; mul3_scalar(res.position, scalar); mul2_scalar(res.texcoord[0], scalar); mul2_scalar(res.texcoord[1], scalar); mul3_scalar(res.normal, scalar); return res; }
[ "struct", "bsp_vertex", "mul_vertex", "(", "struct", "bsp_vertex", "*", "vertex", ",", "float", "scalar", ")", "{", "struct", "bsp_vertex", "res", ";", "res", "=", "*", "vertex", ";", "mul3_scalar", "(", "res", ".", "position", ",", "scalar", ")", ";", "mul2_scalar", "(", "res", ".", "texcoord", "[", "0", "]", ",", "scalar", ")", ";", "mul2_scalar", "(", "res", ".", "texcoord", "[", "1", "]", ",", "scalar", ")", ";", "mul3_scalar", "(", "res", ".", "normal", ",", "scalar", ")", ";", "return", "res", ";", "}" ]
this is slow but it makes code look nicer and we only use it on init anyway so it's not a real performance hit
[ "this", "is", "slow", "but", "it", "makes", "code", "look", "nicer", "and", "we", "only", "use", "it", "on", "init", "anyway", "so", "it", "'", "s", "not", "a", "real", "performance", "hit" ]
[]
[ { "param": "vertex", "type": "struct bsp_vertex" }, { "param": "scalar", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vertex", "type": "struct bsp_vertex", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "scalar", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cb745b072b29bb686bffc2520c844f4cb83bb377
Francesco149/q3playground
main.c
[ "Unlicense" ]
C
trace_brush
void
void trace_brush(struct trace_work* work, struct bsp_brush* brush) { int i; float start_frac; float end_frac; struct bsp_plane* closest_plane; /* TODO: do optimized check for the first 6 planes which are axial */ start_frac = -1; end_frac = 1; for (i = 0; i < brush->n_brushsides; ++i) { int side_index; int plane_index; struct bsp_plane* plane; int signbits; float dist; float start_distance, end_distance; float frac; side_index = brush->brushside + i; plane_index = map.brushsides[side_index].plane; plane = &map.planes[plane_index]; signbits = planes[plane_index].signbits; dist = plane->dist - dot3(work->offsets[signbits], plane->normal); start_distance = dot3(work->start, plane->normal) - dist; end_distance = dot3(work->end, plane->normal) - dist; /* TODO: * for some reason these checks incorrectly report all solid * when they shouldn't. for now I'm just ignoring them */ if (start_distance > 0) { work->flags |= TW_STARTS_OUT; } if (end_distance > 0) { work->flags |= TW_ENDS_OUT; } if (start_distance > 0 && (end_distance >= SURF_CLIP_EPSILON || end_distance >= start_distance)) { return; } if (start_distance <= 0 && end_distance <= 0) { continue; } if (start_distance > end_distance) { frac = (start_distance - SURF_CLIP_EPSILON) / (start_distance - end_distance); if (frac > start_frac) { start_frac = frac; closest_plane = plane; } } else { frac = (start_distance + SURF_CLIP_EPSILON) / (start_distance - end_distance); end_frac = SDL_min(end_frac, frac); } } if (start_frac < end_frac && start_frac > -1 && start_frac < work->frac) { work->frac = SDL_max(start_frac, 0); work->plane = closest_plane; } if (!(work->flags & (TW_STARTS_OUT | TW_ENDS_OUT))) { work->frac = 0; } }
/* * - adjust plane dist to account for the bounding box * - if both points are in front of the plane, we're done with this brush * - if both points are behind the plane, we continue looping expecting * other planes to clip us * - if we are entering the brush, clip start_frac to the distance * between the starting point and the brush minus the epsilon so we don't * actually touch * - if we are exiting the brush, clip end_frac to the distance between * the starting point and the brush plus the epsilon so we don't * actually touch * - keep collecting the maximum start_frac and minimum end_faction so * we get as close as possible to touching the brush but not quite * - store the minimum start_frac out of all the brushes so we * clip against the closest brush * - if the trace starts and ends inside the brush, negate the move * * (I assume this means that the brush sides are sorted from back to front) */
(I assume this means that the brush sides are sorted from back to front)
[ "(", "I", "assume", "this", "means", "that", "the", "brush", "sides", "are", "sorted", "from", "back", "to", "front", ")" ]
void trace_brush(struct trace_work* work, struct bsp_brush* brush) { int i; float start_frac; float end_frac; struct bsp_plane* closest_plane; start_frac = -1; end_frac = 1; for (i = 0; i < brush->n_brushsides; ++i) { int side_index; int plane_index; struct bsp_plane* plane; int signbits; float dist; float start_distance, end_distance; float frac; side_index = brush->brushside + i; plane_index = map.brushsides[side_index].plane; plane = &map.planes[plane_index]; signbits = planes[plane_index].signbits; dist = plane->dist - dot3(work->offsets[signbits], plane->normal); start_distance = dot3(work->start, plane->normal) - dist; end_distance = dot3(work->end, plane->normal) - dist; if (start_distance > 0) { work->flags |= TW_STARTS_OUT; } if (end_distance > 0) { work->flags |= TW_ENDS_OUT; } if (start_distance > 0 && (end_distance >= SURF_CLIP_EPSILON || end_distance >= start_distance)) { return; } if (start_distance <= 0 && end_distance <= 0) { continue; } if (start_distance > end_distance) { frac = (start_distance - SURF_CLIP_EPSILON) / (start_distance - end_distance); if (frac > start_frac) { start_frac = frac; closest_plane = plane; } } else { frac = (start_distance + SURF_CLIP_EPSILON) / (start_distance - end_distance); end_frac = SDL_min(end_frac, frac); } } if (start_frac < end_frac && start_frac > -1 && start_frac < work->frac) { work->frac = SDL_max(start_frac, 0); work->plane = closest_plane; } if (!(work->flags & (TW_STARTS_OUT | TW_ENDS_OUT))) { work->frac = 0; } }
[ "void", "trace_brush", "(", "struct", "trace_work", "*", "work", ",", "struct", "bsp_brush", "*", "brush", ")", "{", "int", "i", ";", "float", "start_frac", ";", "float", "end_frac", ";", "struct", "bsp_plane", "*", "closest_plane", ";", "start_frac", "=", "-1", ";", "end_frac", "=", "1", ";", "for", "(", "i", "=", "0", ";", "i", "<", "brush", "->", "n_brushsides", ";", "++", "i", ")", "{", "int", "side_index", ";", "int", "plane_index", ";", "struct", "bsp_plane", "*", "plane", ";", "int", "signbits", ";", "float", "dist", ";", "float", "start_distance", ",", "end_distance", ";", "float", "frac", ";", "side_index", "=", "brush", "->", "brushside", "+", "i", ";", "plane_index", "=", "map", ".", "brushsides", "[", "side_index", "]", ".", "plane", ";", "plane", "=", "&", "map", ".", "planes", "[", "plane_index", "]", ";", "signbits", "=", "planes", "[", "plane_index", "]", ".", "signbits", ";", "dist", "=", "plane", "->", "dist", "-", "dot3", "(", "work", "->", "offsets", "[", "signbits", "]", ",", "plane", "->", "normal", ")", ";", "start_distance", "=", "dot3", "(", "work", "->", "start", ",", "plane", "->", "normal", ")", "-", "dist", ";", "end_distance", "=", "dot3", "(", "work", "->", "end", ",", "plane", "->", "normal", ")", "-", "dist", ";", "if", "(", "start_distance", ">", "0", ")", "{", "work", "->", "flags", "|=", "TW_STARTS_OUT", ";", "}", "if", "(", "end_distance", ">", "0", ")", "{", "work", "->", "flags", "|=", "TW_ENDS_OUT", ";", "}", "if", "(", "start_distance", ">", "0", "&&", "(", "end_distance", ">=", "SURF_CLIP_EPSILON", "||", "end_distance", ">=", "start_distance", ")", ")", "{", "return", ";", "}", "if", "(", "start_distance", "<=", "0", "&&", "end_distance", "<=", "0", ")", "{", "continue", ";", "}", "if", "(", "start_distance", ">", "end_distance", ")", "{", "frac", "=", "(", "start_distance", "-", "SURF_CLIP_EPSILON", ")", "/", "(", "start_distance", "-", "end_distance", ")", ";", "if", "(", "frac", ">", "start_frac", ")", "{", "start_frac", "=", "frac", ";", "closest_plane", "=", "plane", ";", "}", "}", "else", "{", "frac", "=", "(", "start_distance", "+", "SURF_CLIP_EPSILON", ")", "/", "(", "start_distance", "-", "end_distance", ")", ";", "end_frac", "=", "SDL_min", "(", "end_frac", ",", "frac", ")", ";", "}", "}", "if", "(", "start_frac", "<", "end_frac", "&&", "start_frac", ">", "-1", "&&", "start_frac", "<", "work", "->", "frac", ")", "{", "work", "->", "frac", "=", "SDL_max", "(", "start_frac", ",", "0", ")", ";", "work", "->", "plane", "=", "closest_plane", ";", "}", "if", "(", "!", "(", "work", "->", "flags", "&", "(", "TW_STARTS_OUT", "|", "TW_ENDS_OUT", ")", ")", ")", "{", "work", "->", "frac", "=", "0", ";", "}", "}" ]
- adjust plane dist to account for the bounding box - if both points are in front of the plane, we're done with this brush - if both points are behind the plane, we continue looping expecting other planes to clip us - if we are entering the brush, clip start_frac to the distance between the starting point and the brush minus the epsilon so we don't actually touch - if we are exiting the brush, clip end_frac to the distance between the starting point and the brush plus the epsilon so we don't actually touch - keep collecting the maximum start_frac and minimum end_faction so we get as close as possible to touching the brush but not quite - store the minimum start_frac out of all the brushes so we clip against the closest brush - if the trace starts and ends inside the brush, negate the move
[ "-", "adjust", "plane", "dist", "to", "account", "for", "the", "bounding", "box", "-", "if", "both", "points", "are", "in", "front", "of", "the", "plane", "we", "'", "re", "done", "with", "this", "brush", "-", "if", "both", "points", "are", "behind", "the", "plane", "we", "continue", "looping", "expecting", "other", "planes", "to", "clip", "us", "-", "if", "we", "are", "entering", "the", "brush", "clip", "start_frac", "to", "the", "distance", "between", "the", "starting", "point", "and", "the", "brush", "minus", "the", "epsilon", "so", "we", "don", "'", "t", "actually", "touch", "-", "if", "we", "are", "exiting", "the", "brush", "clip", "end_frac", "to", "the", "distance", "between", "the", "starting", "point", "and", "the", "brush", "plus", "the", "epsilon", "so", "we", "don", "'", "t", "actually", "touch", "-", "keep", "collecting", "the", "maximum", "start_frac", "and", "minimum", "end_faction", "so", "we", "get", "as", "close", "as", "possible", "to", "touching", "the", "brush", "but", "not", "quite", "-", "store", "the", "minimum", "start_frac", "out", "of", "all", "the", "brushes", "so", "we", "clip", "against", "the", "closest", "brush", "-", "if", "the", "trace", "starts", "and", "ends", "inside", "the", "brush", "negate", "the", "move" ]
[ "/* TODO: do optimized check for the first 6 planes which are axial */", "/* TODO:\n * for some reason these checks incorrectly report all solid\n * when they shouldn't. for now I'm just ignoring them\n */" ]
[ { "param": "work", "type": "struct trace_work" }, { "param": "brush", "type": "struct bsp_brush" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "work", "type": "struct trace_work", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "brush", "type": "struct bsp_brush", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cb745b072b29bb686bffc2520c844f4cb83bb377
Francesco149/q3playground
main.c
[ "Unlicense" ]
C
trace
void
void trace(struct trace_work* work, float* start, float* end, float* mins, float* maxs) { int i; work->frac = 1; work->flags = 0; for (i = 0; i < 3; ++i) { float offset; offset = (mins[i] + maxs[i]) * 0.5f; work->mins[i] = mins[i] - offset; work->maxs[i] = maxs[i] - offset; work->start[i] = start[i] + offset; work->end[i] = end[i] + offset; } work->offsets[0][0] = work->mins[0]; work->offsets[0][1] = work->mins[1]; work->offsets[0][2] = work->mins[2]; work->offsets[1][0] = work->maxs[0]; work->offsets[1][1] = work->mins[1]; work->offsets[1][2] = work->mins[2]; work->offsets[2][0] = work->mins[0]; work->offsets[2][1] = work->maxs[1]; work->offsets[2][2] = work->mins[2]; work->offsets[3][0] = work->maxs[0]; work->offsets[3][1] = work->maxs[1]; work->offsets[3][2] = work->mins[2]; work->offsets[4][0] = work->mins[0]; work->offsets[4][1] = work->mins[1]; work->offsets[4][2] = work->maxs[2]; work->offsets[5][0] = work->maxs[0]; work->offsets[5][1] = work->mins[1]; work->offsets[5][2] = work->maxs[2]; work->offsets[6][0] = work->mins[0]; work->offsets[6][1] = work->maxs[1]; work->offsets[6][2] = work->maxs[2]; work->offsets[7][0] = work->maxs[0]; work->offsets[7][1] = work->maxs[1]; work->offsets[7][2] = work->maxs[2]; trace_node(work, 0, 0, 1, work->start, work->end); if (work->frac == 1) { cpy3(work->endpos, end); } else { int i; for (i = 0; i < 3; ++i) { work->endpos[i] = start[i] + work->frac * (end[i] - start[i]); } } }
/* * - adjust bounding box so it's symmetric. this is simply done by finding * the middle point and moving start/end to align with it * - initialize offsets. this is a lookup table for mins/maxs with any * sign combination for the plane's normal. it ensures that we account * for the hitbox in the right orientation in trace_brush * - do the tracing * - if we hit anything, calculate end from the unmodified start/end */
- adjust bounding box so it's symmetric. this is simply done by finding the middle point and moving start/end to align with it - initialize offsets. this is a lookup table for mins/maxs with any sign combination for the plane's normal. it ensures that we account for the hitbox in the right orientation in trace_brush - do the tracing - if we hit anything, calculate end from the unmodified start/end
[ "-", "adjust", "bounding", "box", "so", "it", "'", "s", "symmetric", ".", "this", "is", "simply", "done", "by", "finding", "the", "middle", "point", "and", "moving", "start", "/", "end", "to", "align", "with", "it", "-", "initialize", "offsets", ".", "this", "is", "a", "lookup", "table", "for", "mins", "/", "maxs", "with", "any", "sign", "combination", "for", "the", "plane", "'", "s", "normal", ".", "it", "ensures", "that", "we", "account", "for", "the", "hitbox", "in", "the", "right", "orientation", "in", "trace_brush", "-", "do", "the", "tracing", "-", "if", "we", "hit", "anything", "calculate", "end", "from", "the", "unmodified", "start", "/", "end" ]
void trace(struct trace_work* work, float* start, float* end, float* mins, float* maxs) { int i; work->frac = 1; work->flags = 0; for (i = 0; i < 3; ++i) { float offset; offset = (mins[i] + maxs[i]) * 0.5f; work->mins[i] = mins[i] - offset; work->maxs[i] = maxs[i] - offset; work->start[i] = start[i] + offset; work->end[i] = end[i] + offset; } work->offsets[0][0] = work->mins[0]; work->offsets[0][1] = work->mins[1]; work->offsets[0][2] = work->mins[2]; work->offsets[1][0] = work->maxs[0]; work->offsets[1][1] = work->mins[1]; work->offsets[1][2] = work->mins[2]; work->offsets[2][0] = work->mins[0]; work->offsets[2][1] = work->maxs[1]; work->offsets[2][2] = work->mins[2]; work->offsets[3][0] = work->maxs[0]; work->offsets[3][1] = work->maxs[1]; work->offsets[3][2] = work->mins[2]; work->offsets[4][0] = work->mins[0]; work->offsets[4][1] = work->mins[1]; work->offsets[4][2] = work->maxs[2]; work->offsets[5][0] = work->maxs[0]; work->offsets[5][1] = work->mins[1]; work->offsets[5][2] = work->maxs[2]; work->offsets[6][0] = work->mins[0]; work->offsets[6][1] = work->maxs[1]; work->offsets[6][2] = work->maxs[2]; work->offsets[7][0] = work->maxs[0]; work->offsets[7][1] = work->maxs[1]; work->offsets[7][2] = work->maxs[2]; trace_node(work, 0, 0, 1, work->start, work->end); if (work->frac == 1) { cpy3(work->endpos, end); } else { int i; for (i = 0; i < 3; ++i) { work->endpos[i] = start[i] + work->frac * (end[i] - start[i]); } } }
[ "void", "trace", "(", "struct", "trace_work", "*", "work", ",", "float", "*", "start", ",", "float", "*", "end", ",", "float", "*", "mins", ",", "float", "*", "maxs", ")", "{", "int", "i", ";", "work", "->", "frac", "=", "1", ";", "work", "->", "flags", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "3", ";", "++", "i", ")", "{", "float", "offset", ";", "offset", "=", "(", "mins", "[", "i", "]", "+", "maxs", "[", "i", "]", ")", "*", "0.5f", ";", "work", "->", "mins", "[", "i", "]", "=", "mins", "[", "i", "]", "-", "offset", ";", "work", "->", "maxs", "[", "i", "]", "=", "maxs", "[", "i", "]", "-", "offset", ";", "work", "->", "start", "[", "i", "]", "=", "start", "[", "i", "]", "+", "offset", ";", "work", "->", "end", "[", "i", "]", "=", "end", "[", "i", "]", "+", "offset", ";", "}", "work", "->", "offsets", "[", "0", "]", "[", "0", "]", "=", "work", "->", "mins", "[", "0", "]", ";", "work", "->", "offsets", "[", "0", "]", "[", "1", "]", "=", "work", "->", "mins", "[", "1", "]", ";", "work", "->", "offsets", "[", "0", "]", "[", "2", "]", "=", "work", "->", "mins", "[", "2", "]", ";", "work", "->", "offsets", "[", "1", "]", "[", "0", "]", "=", "work", "->", "maxs", "[", "0", "]", ";", "work", "->", "offsets", "[", "1", "]", "[", "1", "]", "=", "work", "->", "mins", "[", "1", "]", ";", "work", "->", "offsets", "[", "1", "]", "[", "2", "]", "=", "work", "->", "mins", "[", "2", "]", ";", "work", "->", "offsets", "[", "2", "]", "[", "0", "]", "=", "work", "->", "mins", "[", "0", "]", ";", "work", "->", "offsets", "[", "2", "]", "[", "1", "]", "=", "work", "->", "maxs", "[", "1", "]", ";", "work", "->", "offsets", "[", "2", "]", "[", "2", "]", "=", "work", "->", "mins", "[", "2", "]", ";", "work", "->", "offsets", "[", "3", "]", "[", "0", "]", "=", "work", "->", "maxs", "[", "0", "]", ";", "work", "->", "offsets", "[", "3", "]", "[", "1", "]", "=", "work", "->", "maxs", "[", "1", "]", ";", "work", "->", "offsets", "[", "3", "]", "[", "2", "]", "=", "work", "->", "mins", "[", "2", "]", ";", "work", "->", "offsets", "[", "4", "]", "[", "0", "]", "=", "work", "->", "mins", "[", "0", "]", ";", "work", "->", "offsets", "[", "4", "]", "[", "1", "]", "=", "work", "->", "mins", "[", "1", "]", ";", "work", "->", "offsets", "[", "4", "]", "[", "2", "]", "=", "work", "->", "maxs", "[", "2", "]", ";", "work", "->", "offsets", "[", "5", "]", "[", "0", "]", "=", "work", "->", "maxs", "[", "0", "]", ";", "work", "->", "offsets", "[", "5", "]", "[", "1", "]", "=", "work", "->", "mins", "[", "1", "]", ";", "work", "->", "offsets", "[", "5", "]", "[", "2", "]", "=", "work", "->", "maxs", "[", "2", "]", ";", "work", "->", "offsets", "[", "6", "]", "[", "0", "]", "=", "work", "->", "mins", "[", "0", "]", ";", "work", "->", "offsets", "[", "6", "]", "[", "1", "]", "=", "work", "->", "maxs", "[", "1", "]", ";", "work", "->", "offsets", "[", "6", "]", "[", "2", "]", "=", "work", "->", "maxs", "[", "2", "]", ";", "work", "->", "offsets", "[", "7", "]", "[", "0", "]", "=", "work", "->", "maxs", "[", "0", "]", ";", "work", "->", "offsets", "[", "7", "]", "[", "1", "]", "=", "work", "->", "maxs", "[", "1", "]", ";", "work", "->", "offsets", "[", "7", "]", "[", "2", "]", "=", "work", "->", "maxs", "[", "2", "]", ";", "trace_node", "(", "work", ",", "0", ",", "0", ",", "1", ",", "work", "->", "start", ",", "work", "->", "end", ")", ";", "if", "(", "work", "->", "frac", "==", "1", ")", "{", "cpy3", "(", "work", "->", "endpos", ",", "end", ")", ";", "}", "else", "{", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "3", ";", "++", "i", ")", "{", "work", "->", "endpos", "[", "i", "]", "=", "start", "[", "i", "]", "+", "work", "->", "frac", "*", "(", "end", "[", "i", "]", "-", "start", "[", "i", "]", ")", ";", "}", "}", "}" ]
- adjust bounding box so it's symmetric.
[ "-", "adjust", "bounding", "box", "so", "it", "'", "s", "symmetric", "." ]
[]
[ { "param": "work", "type": "struct trace_work" }, { "param": "start", "type": "float" }, { "param": "end", "type": "float" }, { "param": "mins", "type": "float" }, { "param": "maxs", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "work", "type": "struct trace_work", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "start", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "end", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mins", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "maxs", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1d34bd1668b7259e071ad491d6a03e9900c1ecb5
watercolor/algorithm
list.c
[ "Apache-2.0" ]
C
list_revert
list_node
list_node* list_revert(list_node *list) { list_node *last = NULL; list_node *next; while (list) { next = list->next; list->next = last; last = list; list = next; } return last; }
/* revert a list and return head after revert */
revert a list and return head after revert
[ "revert", "a", "list", "and", "return", "head", "after", "revert" ]
list_node* list_revert(list_node *list) { list_node *last = NULL; list_node *next; while (list) { next = list->next; list->next = last; last = list; list = next; } return last; }
[ "list_node", "*", "list_revert", "(", "list_node", "*", "list", ")", "{", "list_node", "*", "last", "=", "NULL", ";", "list_node", "*", "next", ";", "while", "(", "list", ")", "{", "next", "=", "list", "->", "next", ";", "list", "->", "next", "=", "last", ";", "last", "=", "list", ";", "list", "=", "next", ";", "}", "return", "last", ";", "}" ]
revert a list and return head after revert
[ "revert", "a", "list", "and", "return", "head", "after", "revert" ]
[]
[ { "param": "list", "type": "list_node" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "list", "type": "list_node", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
dc8df7b2c1a3eaf072dfb65280155f2c34bf8703
NikosKoutroumanis/Acrostics-generator-in-c
list.c
[ "MIT" ]
C
insert_empty
void
void insert_empty( char *str2,int len) { wordList *new; new=(wordList*)malloc(sizeof(wordList)); if(new==NULL) { printf("no space \n"); exit(0); } new->word=(char*)malloc(len*sizeof(char)); if(new->word==NULL) { printf("no space \n"); exit(0); } strcpy(new->word,str2); words++; printf("sth lista bhke:"); puts(new->word); elements(new,len); new->next=NULL; new->previous=NULL; head=new; last=new; }
// synarthseis pou sxetizontai me thn lista
synarthseis pou sxetizontai me thn lista
[ "synarthseis", "pou", "sxetizontai", "me", "thn", "lista" ]
void insert_empty( char *str2,int len) { wordList *new; new=(wordList*)malloc(sizeof(wordList)); if(new==NULL) { printf("no space \n"); exit(0); } new->word=(char*)malloc(len*sizeof(char)); if(new->word==NULL) { printf("no space \n"); exit(0); } strcpy(new->word,str2); words++; printf("sth lista bhke:"); puts(new->word); elements(new,len); new->next=NULL; new->previous=NULL; head=new; last=new; }
[ "void", "insert_empty", "(", "char", "*", "str2", ",", "int", "len", ")", "{", "wordList", "*", "new", ";", "new", "=", "(", "wordList", "*", ")", "malloc", "(", "sizeof", "(", "wordList", ")", ")", ";", "if", "(", "new", "==", "NULL", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "exit", "(", "0", ")", ";", "}", "new", "->", "word", "=", "(", "char", "*", ")", "malloc", "(", "len", "*", "sizeof", "(", "char", ")", ")", ";", "if", "(", "new", "->", "word", "==", "NULL", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "exit", "(", "0", ")", ";", "}", "strcpy", "(", "new", "->", "word", ",", "str2", ")", ";", "words", "++", ";", "printf", "(", "\"", "\"", ")", ";", "puts", "(", "new", "->", "word", ")", ";", "elements", "(", "new", ",", "len", ")", ";", "new", "->", "next", "=", "NULL", ";", "new", "->", "previous", "=", "NULL", ";", "head", "=", "new", ";", "last", "=", "new", ";", "}" ]
synarthseis pou sxetizontai me thn lista
[ "synarthseis", "pou", "sxetizontai", "me", "thn", "lista" ]
[]
[ { "param": "str2", "type": "char" }, { "param": "len", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "str2", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d87f34c9d6064282f495df30b6af6dd17aa16cf4
AlanFromJapan/alanWebSites
static/files/HPD.c
[ "MIT" ]
C
init_timer1_OVF
void
void init_timer1_OVF() { //timer 1 prescaler : makes clock / 64 -> tick every 1/4 sec roughly TCCR1B=0x03; //trigger the interrupt vector TIMER1_OVF_vect when timer 1 is overflow TIMSK = 0x80; //sets the interruptions to enabled sei(); }
//inits timer 1 to do interrupt on overflow (calls ISR(TIMER1_OVF_vect))
inits timer 1 to do interrupt on overflow (calls ISR(TIMER1_OVF_vect))
[ "inits", "timer", "1", "to", "do", "interrupt", "on", "overflow", "(", "calls", "ISR", "(", "TIMER1_OVF_vect", "))" ]
void init_timer1_OVF() { TCCR1B=0x03; TIMSK = 0x80; sei(); }
[ "void", "init_timer1_OVF", "(", ")", "{", "TCCR1B", "=", "0x03", ";", "TIMSK", "=", "0x80", ";", "sei", "(", ")", ";", "}" ]
inits timer 1 to do interrupt on overflow (calls ISR(TIMER1_OVF_vect))
[ "inits", "timer", "1", "to", "do", "interrupt", "on", "overflow", "(", "calls", "ISR", "(", "TIMER1_OVF_vect", "))" ]
[ "//timer 1 prescaler : makes clock / 64 -> tick every 1/4 sec roughly\r", "//trigger the interrupt vector TIMER1_OVF_vect when timer 1 is overflow\r", "//sets the interruptions to enabled\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
d87f34c9d6064282f495df30b6af6dd17aa16cf4
AlanFromJapan/alanWebSites
static/files/HPD.c
[ "MIT" ]
C
init_timer0_PWM
void
void init_timer0_PWM() { /* Set Fast PWM mode. */ TCCR0A |= (1<<WGM00) | (1<<WGM01); /* Clear 0C0A on compare. */ TCCR0A |= (1<<COM0A1); /* Start timer, no prescaling. */ TCCR0B |= (1<<CS00); /* Duty cycle 0% */ OCR0A = 0; }
//Inits timer 0 to do PWM on pin B2
Inits timer 0 to do PWM on pin B2
[ "Inits", "timer", "0", "to", "do", "PWM", "on", "pin", "B2" ]
void init_timer0_PWM() { TCCR0A |= (1<<WGM00) | (1<<WGM01); TCCR0A |= (1<<COM0A1); TCCR0B |= (1<<CS00); OCR0A = 0; }
[ "void", "init_timer0_PWM", "(", ")", "{", "TCCR0A", "|=", "(", "1", "<<", "WGM00", ")", "|", "(", "1", "<<", "WGM01", ")", ";", "TCCR0A", "|=", "(", "1", "<<", "COM0A1", ")", ";", "TCCR0B", "|=", "(", "1", "<<", "CS00", ")", ";", "OCR0A", "=", "0", ";", "}" ]
Inits timer 0 to do PWM on pin B2
[ "Inits", "timer", "0", "to", "do", "PWM", "on", "pin", "B2" ]
[ "/* Set Fast PWM mode. */", "/* Clear 0C0A on compare. */", "/* Start timer, no prescaling. */", "/* Duty cycle 0% */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
249eda590c4747a16d68d58586f79472792ac1f1
TrinityCollegeFIRST/Project-M8
src/main.c
[ "BSD-3-Clause" ]
C
Init
void
void Init() { nVolume = 4; // Maximum Volume ControllerA.ControllerID = 0; ControllerB.ControllerID = 1; Init_Teleop(); }
/* * Initialize the Robot and ensure that the software is ready to operate. */
Initialize the Robot and ensure that the software is ready to operate.
[ "Initialize", "the", "Robot", "and", "ensure", "that", "the", "software", "is", "ready", "to", "operate", "." ]
void Init() { nVolume = 4; ControllerA.ControllerID = 0; ControllerB.ControllerID = 1; Init_Teleop(); }
[ "void", "Init", "(", ")", "{", "nVolume", "=", "4", ";", "ControllerA", ".", "ControllerID", "=", "0", ";", "ControllerB", ".", "ControllerID", "=", "1", ";", "Init_Teleop", "(", ")", ";", "}" ]
Initialize the Robot and ensure that the software is ready to operate.
[ "Initialize", "the", "Robot", "and", "ensure", "that", "the", "software", "is", "ready", "to", "operate", "." ]
[ "// Maximum Volume" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
249eda590c4747a16d68d58586f79472792ac1f1
TrinityCollegeFIRST/Project-M8
src/main.c
[ "BSD-3-Clause" ]
C
Update
void
void Update() { alive(); Update_Teleop(); // Update Drive Mode if (ControllerA.Buttons.Start == ButtonState_Pressed) EndState(); if (ControllerA.Buttons.LeftStick == ButtonState_Active) playImmediateTone(400, 1); // Input Test aka Horn }
/* * Call the main update functions of all the inuse functionality * Update the current mode that the robot is using. Autonomous/Drive */
Call the main update functions of all the inuse functionality Update the current mode that the robot is using. Autonomous/Drive
[ "Call", "the", "main", "update", "functions", "of", "all", "the", "inuse", "functionality", "Update", "the", "current", "mode", "that", "the", "robot", "is", "using", ".", "Autonomous", "/", "Drive" ]
void Update() { alive(); Update_Teleop(); if (ControllerA.Buttons.Start == ButtonState_Pressed) EndState(); if (ControllerA.Buttons.LeftStick == ButtonState_Active) playImmediateTone(400, 1); }
[ "void", "Update", "(", ")", "{", "alive", "(", ")", ";", "Update_Teleop", "(", ")", ";", "if", "(", "ControllerA", ".", "Buttons", ".", "Start", "==", "ButtonState_Pressed", ")", "EndState", "(", ")", ";", "if", "(", "ControllerA", ".", "Buttons", ".", "LeftStick", "==", "ButtonState_Active", ")", "playImmediateTone", "(", "400", ",", "1", ")", ";", "}" ]
Call the main update functions of all the inuse functionality Update the current mode that the robot is using.
[ "Call", "the", "main", "update", "functions", "of", "all", "the", "inuse", "functionality", "Update", "the", "current", "mode", "that", "the", "robot", "is", "using", "." ]
[ "// Update Drive Mode", "// Input Test aka Horn" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
cec3f0a91260906bd24dcb58666bfee888cd4109
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.h
[ "Apache-2.0" ]
C
coap_register_request_handler
void
static inline void coap_register_request_handler(coap_context_t *context, coap_request_handler_t handler) { context->request_handler = handler; }
/** * Registers a new message handler that is called whenever a request * was received that matches an ongoing transaction. * * @param context The context to register the handler for. * @param handler The response handler to register. */
Registers a new message handler that is called whenever a request was received that matches an ongoing transaction. @param context The context to register the handler for. @param handler The response handler to register.
[ "Registers", "a", "new", "message", "handler", "that", "is", "called", "whenever", "a", "request", "was", "received", "that", "matches", "an", "ongoing", "transaction", ".", "@param", "context", "The", "context", "to", "register", "the", "handler", "for", ".", "@param", "handler", "The", "response", "handler", "to", "register", "." ]
static inline void coap_register_request_handler(coap_context_t *context, coap_request_handler_t handler) { context->request_handler = handler; }
[ "static", "inline", "void", "coap_register_request_handler", "(", "coap_context_t", "*", "context", ",", "coap_request_handler_t", "handler", ")", "{", "context", "->", "request_handler", "=", "handler", ";", "}" ]
Registers a new message handler that is called whenever a request was received that matches an ongoing transaction.
[ "Registers", "a", "new", "message", "handler", "that", "is", "called", "whenever", "a", "request", "was", "received", "that", "matches", "an", "ongoing", "transaction", "." ]
[]
[ { "param": "context", "type": "coap_context_t" }, { "param": "handler", "type": "coap_request_handler_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "handler", "type": "coap_request_handler_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cec3f0a91260906bd24dcb58666bfee888cd4109
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.h
[ "Apache-2.0" ]
C
coap_register_response_handler
void
static inline void coap_register_response_handler(coap_context_t *context, coap_response_handler_t handler) { context->response_handler = handler; }
/** * Registers a new message handler that is called whenever a response * was received that matches an ongoing transaction. * * @param context The context to register the handler for. * @param handler The response handler to register. */
Registers a new message handler that is called whenever a response was received that matches an ongoing transaction. @param context The context to register the handler for. @param handler The response handler to register.
[ "Registers", "a", "new", "message", "handler", "that", "is", "called", "whenever", "a", "response", "was", "received", "that", "matches", "an", "ongoing", "transaction", ".", "@param", "context", "The", "context", "to", "register", "the", "handler", "for", ".", "@param", "handler", "The", "response", "handler", "to", "register", "." ]
static inline void coap_register_response_handler(coap_context_t *context, coap_response_handler_t handler) { context->response_handler = handler; }
[ "static", "inline", "void", "coap_register_response_handler", "(", "coap_context_t", "*", "context", ",", "coap_response_handler_t", "handler", ")", "{", "context", "->", "response_handler", "=", "handler", ";", "}" ]
Registers a new message handler that is called whenever a response was received that matches an ongoing transaction.
[ "Registers", "a", "new", "message", "handler", "that", "is", "called", "whenever", "a", "response", "was", "received", "that", "matches", "an", "ongoing", "transaction", "." ]
[]
[ { "param": "context", "type": "coap_context_t" }, { "param": "handler", "type": "coap_response_handler_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "handler", "type": "coap_response_handler_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cec3f0a91260906bd24dcb58666bfee888cd4109
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.h
[ "Apache-2.0" ]
C
coap_register_ack_rst_handler
void
static inline void coap_register_ack_rst_handler(coap_context_t *context, coap_ack_rst_handler_t handler) { context->ack_rst_handler = handler; }
/** * Registers a new message handler that is called whenever ack or rst * was received that matches an ongoing transaction. * * @param context The context to register the handler for. * @param handler The handler to register. */
Registers a new message handler that is called whenever ack or rst was received that matches an ongoing transaction. @param context The context to register the handler for. @param handler The handler to register.
[ "Registers", "a", "new", "message", "handler", "that", "is", "called", "whenever", "ack", "or", "rst", "was", "received", "that", "matches", "an", "ongoing", "transaction", ".", "@param", "context", "The", "context", "to", "register", "the", "handler", "for", ".", "@param", "handler", "The", "handler", "to", "register", "." ]
static inline void coap_register_ack_rst_handler(coap_context_t *context, coap_ack_rst_handler_t handler) { context->ack_rst_handler = handler; }
[ "static", "inline", "void", "coap_register_ack_rst_handler", "(", "coap_context_t", "*", "context", ",", "coap_ack_rst_handler_t", "handler", ")", "{", "context", "->", "ack_rst_handler", "=", "handler", ";", "}" ]
Registers a new message handler that is called whenever ack or rst was received that matches an ongoing transaction.
[ "Registers", "a", "new", "message", "handler", "that", "is", "called", "whenever", "ack", "or", "rst", "was", "received", "that", "matches", "an", "ongoing", "transaction", "." ]
[]
[ { "param": "context", "type": "coap_context_t" }, { "param": "handler", "type": "coap_ack_rst_handler_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "handler", "type": "coap_ack_rst_handler_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cec3f0a91260906bd24dcb58666bfee888cd4109
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.h
[ "Apache-2.0" ]
C
coap_new_message_id
null
static inline unsigned short coap_new_message_id(coap_context_t *context) { ++(context->message_id); #ifdef WITH_ARDUINO return ((context->message_id << 8) | ((context->message_id >> 8) & (0xFF))); #elif WITH_CONTIKI return uip_htons(context->message_id); #else return htons(context->message_id); #endif }
/** * Returns a new message id and updates @p context->message_id * accordingly. The message id is returned in network byte order * to make it easier to read in tracing tools. * * @param context the current coap_context_t object * @return incremented message id in network byte order */
Returns a new message id and updates @p context->message_id accordingly. The message id is returned in network byte order to make it easier to read in tracing tools. @param context the current coap_context_t object @return incremented message id in network byte order
[ "Returns", "a", "new", "message", "id", "and", "updates", "@p", "context", "-", ">", "message_id", "accordingly", ".", "The", "message", "id", "is", "returned", "in", "network", "byte", "order", "to", "make", "it", "easier", "to", "read", "in", "tracing", "tools", ".", "@param", "context", "the", "current", "coap_context_t", "object", "@return", "incremented", "message", "id", "in", "network", "byte", "order" ]
static inline unsigned short coap_new_message_id(coap_context_t *context) { ++(context->message_id); #ifdef WITH_ARDUINO return ((context->message_id << 8) | ((context->message_id >> 8) & (0xFF))); #elif WITH_CONTIKI return uip_htons(context->message_id); #else return htons(context->message_id); #endif }
[ "static", "inline", "unsigned", "short", "coap_new_message_id", "(", "coap_context_t", "*", "context", ")", "{", "++", "(", "context", "->", "message_id", ")", ";", "#ifdef", "WITH_ARDUINO", "return", "(", "(", "context", "->", "message_id", "<<", "8", ")", "|", "(", "(", "context", "->", "message_id", ">>", "8", ")", "&", "(", "0xFF", ")", ")", ")", ";", "#elif", "WITH_CONTIKI", "\n", "return", "uip_htons", "(", "context", "->", "message_id", ")", ";", "#else", "return", "htons", "(", "context", "->", "message_id", ")", ";", "#endif", "}" ]
Returns a new message id and updates @p context->message_id accordingly.
[ "Returns", "a", "new", "message", "id", "and", "updates", "@p", "context", "-", ">", "message_id", "accordingly", "." ]
[]
[ { "param": "context", "type": "coap_context_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cec3f0a91260906bd24dcb58666bfee888cd4109
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.h
[ "Apache-2.0" ]
C
coap_send_rst
coap_tid_t
static inline coap_tid_t coap_send_rst(coap_context_t *context, const coap_address_t *dst, coap_pdu_t *request, coap_send_flags_t flag) { return coap_send_message_type(context, dst, request, flag, COAP_MESSAGE_RST); }
/** * Sends an RST message with code @c 0 for the specified @p request to * @p dst. This function returns the corresponding transaction id if * the message was sent or @c COAP_INVALID_TID on error. * * @param context The context to use. * @param dst The destination address. * @param request The request to be reset. * @param flag Options for sending the reset message. * * @return The transaction id if RST was sent or @c COAP_INVALID_TID * on error. */
Sends an RST message with code @c 0 for the specified @p request to @p dst. This function returns the corresponding transaction id if the message was sent or @c COAP_INVALID_TID on error. @param context The context to use. @param dst The destination address. @param request The request to be reset. @param flag Options for sending the reset message. @return The transaction id if RST was sent or @c COAP_INVALID_TID on error.
[ "Sends", "an", "RST", "message", "with", "code", "@c", "0", "for", "the", "specified", "@p", "request", "to", "@p", "dst", ".", "This", "function", "returns", "the", "corresponding", "transaction", "id", "if", "the", "message", "was", "sent", "or", "@c", "COAP_INVALID_TID", "on", "error", ".", "@param", "context", "The", "context", "to", "use", ".", "@param", "dst", "The", "destination", "address", ".", "@param", "request", "The", "request", "to", "be", "reset", ".", "@param", "flag", "Options", "for", "sending", "the", "reset", "message", ".", "@return", "The", "transaction", "id", "if", "RST", "was", "sent", "or", "@c", "COAP_INVALID_TID", "on", "error", "." ]
static inline coap_tid_t coap_send_rst(coap_context_t *context, const coap_address_t *dst, coap_pdu_t *request, coap_send_flags_t flag) { return coap_send_message_type(context, dst, request, flag, COAP_MESSAGE_RST); }
[ "static", "inline", "coap_tid_t", "coap_send_rst", "(", "coap_context_t", "*", "context", ",", "const", "coap_address_t", "*", "dst", ",", "coap_pdu_t", "*", "request", ",", "coap_send_flags_t", "flag", ")", "{", "return", "coap_send_message_type", "(", "context", ",", "dst", ",", "request", ",", "flag", ",", "COAP_MESSAGE_RST", ")", ";", "}" ]
Sends an RST message with code @c 0 for the specified @p request to @p dst.
[ "Sends", "an", "RST", "message", "with", "code", "@c", "0", "for", "the", "specified", "@p", "request", "to", "@p", "dst", "." ]
[]
[ { "param": "context", "type": "coap_context_t" }, { "param": "dst", "type": "coap_address_t" }, { "param": "request", "type": "coap_pdu_t" }, { "param": "flag", "type": "coap_send_flags_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dst", "type": "coap_address_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "request", "type": "coap_pdu_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "flag", "type": "coap_send_flags_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4acea0f1fe52b877d5f75978b5db5f967af3df24
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.c
[ "Apache-2.0" ]
C
received_package
void
static void received_package(void *arg, struct udp_pcb *upcb, struct pbuf *p, ip_addr_t *addr, u16_t port) { struct coap_context_t *context = (coap_context_t *)arg; LWIP_ASSERT("pending_package was not cleared.", context->pending_package == NULL); context->pending_package = p; /* we don't free it, coap_read has to do that */ context->pending_address.addr = addr->addr; /* FIXME: this has to become address-type independent, probably there'll be an lwip function for that */ context->pending_port = port; coap_read(context, -1); /* we want to read from unicast socket */ }
/** Callback to udp_recv when using lwIP. Gets called by lwIP on arriving * packages, places a reference in context->pending_package, and calls * coap_read to process the package. Thus, coap_read needs not be called in * lwIP main loops. (When modifying this for thread-like operation, ie. if you * remove the coap_read call from this, make sure that coap_read gets a chance * to run before this callback is entered the next time.) */
Callback to udp_recv when using lwIP. Gets called by lwIP on arriving packages, places a reference in context->pending_package, and calls coap_read to process the package. Thus, coap_read needs not be called in lwIP main loops. (When modifying this for thread-like operation, ie. if you remove the coap_read call from this, make sure that coap_read gets a chance to run before this callback is entered the next time.)
[ "Callback", "to", "udp_recv", "when", "using", "lwIP", ".", "Gets", "called", "by", "lwIP", "on", "arriving", "packages", "places", "a", "reference", "in", "context", "-", ">", "pending_package", "and", "calls", "coap_read", "to", "process", "the", "package", ".", "Thus", "coap_read", "needs", "not", "be", "called", "in", "lwIP", "main", "loops", ".", "(", "When", "modifying", "this", "for", "thread", "-", "like", "operation", "ie", ".", "if", "you", "remove", "the", "coap_read", "call", "from", "this", "make", "sure", "that", "coap_read", "gets", "a", "chance", "to", "run", "before", "this", "callback", "is", "entered", "the", "next", "time", ".", ")" ]
static void received_package(void *arg, struct udp_pcb *upcb, struct pbuf *p, ip_addr_t *addr, u16_t port) { struct coap_context_t *context = (coap_context_t *)arg; LWIP_ASSERT("pending_package was not cleared.", context->pending_package == NULL); context->pending_package = p; context->pending_address.addr = addr->addr; context->pending_port = port; coap_read(context, -1); }
[ "static", "void", "received_package", "(", "void", "*", "arg", ",", "struct", "udp_pcb", "*", "upcb", ",", "struct", "pbuf", "*", "p", ",", "ip_addr_t", "*", "addr", ",", "u16_t", "port", ")", "{", "struct", "coap_context_t", "*", "context", "=", "(", "coap_context_t", "*", ")", "arg", ";", "LWIP_ASSERT", "(", "\"", "\"", ",", "context", "->", "pending_package", "==", "NULL", ")", ";", "context", "->", "pending_package", "=", "p", ";", "context", "->", "pending_address", ".", "addr", "=", "addr", "->", "addr", ";", "context", "->", "pending_port", "=", "port", ";", "coap_read", "(", "context", ",", "-1", ")", ";", "}" ]
Callback to udp_recv when using lwIP.
[ "Callback", "to", "udp_recv", "when", "using", "lwIP", "." ]
[ "/* we don't free it, coap_read has to do that */", "/* FIXME: this has to become address-type independent, probably there'll be an lwip function for that */", "/* we want to read from unicast socket */" ]
[ { "param": "arg", "type": "void" }, { "param": "upcb", "type": "struct udp_pcb" }, { "param": "p", "type": "struct pbuf" }, { "param": "addr", "type": "ip_addr_t" }, { "param": "port", "type": "u16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "upcb", "type": "struct udp_pcb", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p", "type": "struct pbuf", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "addr", "type": "ip_addr_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "port", "type": "u16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4acea0f1fe52b877d5f75978b5db5f967af3df24
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.c
[ "Apache-2.0" ]
C
is_wkc
int
int is_wkc(coap_key_t k) { static coap_key_t wkc; static unsigned char _initialized = 0; if (!_initialized) { _initialized = coap_hash_path((unsigned char *)COAP_DEFAULT_URI_WELLKNOWN, sizeof(COAP_DEFAULT_URI_WELLKNOWN) - 1, wkc); } return memcmp(k, wkc, sizeof(coap_key_t)) == 0; }
/* Implements a singleton to store a hash key for the .wellknown/core * resources. */
Implements a singleton to store a hash key for the .wellknown/core resources.
[ "Implements", "a", "singleton", "to", "store", "a", "hash", "key", "for", "the", ".", "wellknown", "/", "core", "resources", "." ]
int is_wkc(coap_key_t k) { static coap_key_t wkc; static unsigned char _initialized = 0; if (!_initialized) { _initialized = coap_hash_path((unsigned char *)COAP_DEFAULT_URI_WELLKNOWN, sizeof(COAP_DEFAULT_URI_WELLKNOWN) - 1, wkc); } return memcmp(k, wkc, sizeof(coap_key_t)) == 0; }
[ "int", "is_wkc", "(", "coap_key_t", "k", ")", "{", "static", "coap_key_t", "wkc", ";", "static", "unsigned", "char", "_initialized", "=", "0", ";", "if", "(", "!", "_initialized", ")", "{", "_initialized", "=", "coap_hash_path", "(", "(", "unsigned", "char", "*", ")", "COAP_DEFAULT_URI_WELLKNOWN", ",", "sizeof", "(", "COAP_DEFAULT_URI_WELLKNOWN", ")", "-", "1", ",", "wkc", ")", ";", "}", "return", "memcmp", "(", "k", ",", "wkc", ",", "sizeof", "(", "coap_key_t", ")", ")", "==", "0", ";", "}" ]
Implements a singleton to store a hash key for the .wellknown/core resources.
[ "Implements", "a", "singleton", "to", "store", "a", "hash", "key", "for", "the", ".", "wellknown", "/", "core", "resources", "." ]
[]
[ { "param": "k", "type": "coap_key_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "k", "type": "coap_key_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4acea0f1fe52b877d5f75978b5db5f967af3df24
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.c
[ "Apache-2.0" ]
C
check_opt_size
int
static inline int check_opt_size(coap_opt_t *opt, unsigned char *maxpos) { if (opt && opt < maxpos) { if (((*opt & 0x0f) < 0x0f) || (opt + 1 < maxpos)) return opt + COAP_OPT_SIZE(opt) < maxpos; } return 0; }
/** * Checks if @p opt fits into the message that ends with @p maxpos. * This function returns @c 1 on success, or @c 0 if the option @p opt * would exceed @p maxpos. */
Checks if @p opt fits into the message that ends with @p maxpos. This function returns @c 1 on success, or @c 0 if the option @p opt would exceed @p maxpos.
[ "Checks", "if", "@p", "opt", "fits", "into", "the", "message", "that", "ends", "with", "@p", "maxpos", ".", "This", "function", "returns", "@c", "1", "on", "success", "or", "@c", "0", "if", "the", "option", "@p", "opt", "would", "exceed", "@p", "maxpos", "." ]
static inline int check_opt_size(coap_opt_t *opt, unsigned char *maxpos) { if (opt && opt < maxpos) { if (((*opt & 0x0f) < 0x0f) || (opt + 1 < maxpos)) return opt + COAP_OPT_SIZE(opt) < maxpos; } return 0; }
[ "static", "inline", "int", "check_opt_size", "(", "coap_opt_t", "*", "opt", ",", "unsigned", "char", "*", "maxpos", ")", "{", "if", "(", "opt", "&&", "opt", "<", "maxpos", ")", "{", "if", "(", "(", "(", "*", "opt", "&", "0x0f", ")", "<", "0x0f", ")", "||", "(", "opt", "+", "1", "<", "maxpos", ")", ")", "return", "opt", "+", "COAP_OPT_SIZE", "(", "opt", ")", "<", "maxpos", ";", "}", "return", "0", ";", "}" ]
Checks if @p opt fits into the message that ends with @p maxpos.
[ "Checks", "if", "@p", "opt", "fits", "into", "the", "message", "that", "ends", "with", "@p", "maxpos", "." ]
[]
[ { "param": "opt", "type": "coap_opt_t" }, { "param": "maxpos", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "opt", "type": "coap_opt_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "maxpos", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4acea0f1fe52b877d5f75978b5db5f967af3df24
mandeepshetty/iotivity
resource/csdk/libcoap-4.1.1/net.c
[ "Apache-2.0" ]
C
coap_retransmittimer_execute
void
static void coap_retransmittimer_execute(void *arg) { coap_context_t *ctx = (coap_context_t*)arg; coap_tick_t now; coap_tick_t elapsed; coap_queue_t *nextinqueue; ctx->timer_configured = 0; coap_ticks(&now); elapsed = now - ctx->sendqueue_basetime; /* that's positive for sure, and unless we haven't been called for a complete wrapping cycle, did not wrap */ nextinqueue = coap_peek_next(ctx); while (nextinqueue != NULL) { if (nextinqueue->t > elapsed) { nextinqueue->t -= elapsed; break; } else { elapsed -= nextinqueue->t; coap_retransmit(ctx, coap_pop_next(ctx)); nextinqueue = coap_peek_next(ctx); } } ctx->sendqueue_basetime = now; coap_retransmittimer_restart(ctx); }
/* FIXME: retransmits that are not required any more due to incoming packages * do *not* get cleared at the moment, the wakeup when the transmission is due * is silently accepted. this is mainly due to the fact that the required * checks are similar in two places in the code (when receiving ACK and RST) * and that they cause more than one patch chunk, as it must be first checked * whether the sendqueue item to be dropped is the next one pending, and later * the restart function has to be called. nothing insurmountable, but it can * also be implemented when things have stabilized, and the performance * penality is minimal * * also, this completely ignores COAP_RESOURCE_CHECK_TIME. * */
retransmits that are not required any more due to incoming packages do *not* get cleared at the moment, the wakeup when the transmission is due is silently accepted. this is mainly due to the fact that the required checks are similar in two places in the code (when receiving ACK and RST) and that they cause more than one patch chunk, as it must be first checked whether the sendqueue item to be dropped is the next one pending, and later the restart function has to be called. nothing insurmountable, but it can also be implemented when things have stabilized, and the performance penality is minimal also, this completely ignores COAP_RESOURCE_CHECK_TIME.
[ "retransmits", "that", "are", "not", "required", "any", "more", "due", "to", "incoming", "packages", "do", "*", "not", "*", "get", "cleared", "at", "the", "moment", "the", "wakeup", "when", "the", "transmission", "is", "due", "is", "silently", "accepted", ".", "this", "is", "mainly", "due", "to", "the", "fact", "that", "the", "required", "checks", "are", "similar", "in", "two", "places", "in", "the", "code", "(", "when", "receiving", "ACK", "and", "RST", ")", "and", "that", "they", "cause", "more", "than", "one", "patch", "chunk", "as", "it", "must", "be", "first", "checked", "whether", "the", "sendqueue", "item", "to", "be", "dropped", "is", "the", "next", "one", "pending", "and", "later", "the", "restart", "function", "has", "to", "be", "called", ".", "nothing", "insurmountable", "but", "it", "can", "also", "be", "implemented", "when", "things", "have", "stabilized", "and", "the", "performance", "penality", "is", "minimal", "also", "this", "completely", "ignores", "COAP_RESOURCE_CHECK_TIME", "." ]
static void coap_retransmittimer_execute(void *arg) { coap_context_t *ctx = (coap_context_t*)arg; coap_tick_t now; coap_tick_t elapsed; coap_queue_t *nextinqueue; ctx->timer_configured = 0; coap_ticks(&now); elapsed = now - ctx->sendqueue_basetime; nextinqueue = coap_peek_next(ctx); while (nextinqueue != NULL) { if (nextinqueue->t > elapsed) { nextinqueue->t -= elapsed; break; } else { elapsed -= nextinqueue->t; coap_retransmit(ctx, coap_pop_next(ctx)); nextinqueue = coap_peek_next(ctx); } } ctx->sendqueue_basetime = now; coap_retransmittimer_restart(ctx); }
[ "static", "void", "coap_retransmittimer_execute", "(", "void", "*", "arg", ")", "{", "coap_context_t", "*", "ctx", "=", "(", "coap_context_t", "*", ")", "arg", ";", "coap_tick_t", "now", ";", "coap_tick_t", "elapsed", ";", "coap_queue_t", "*", "nextinqueue", ";", "ctx", "->", "timer_configured", "=", "0", ";", "coap_ticks", "(", "&", "now", ")", ";", "elapsed", "=", "now", "-", "ctx", "->", "sendqueue_basetime", ";", "nextinqueue", "=", "coap_peek_next", "(", "ctx", ")", ";", "while", "(", "nextinqueue", "!=", "NULL", ")", "{", "if", "(", "nextinqueue", "->", "t", ">", "elapsed", ")", "{", "nextinqueue", "->", "t", "-=", "elapsed", ";", "break", ";", "}", "else", "{", "elapsed", "-=", "nextinqueue", "->", "t", ";", "coap_retransmit", "(", "ctx", ",", "coap_pop_next", "(", "ctx", ")", ")", ";", "nextinqueue", "=", "coap_peek_next", "(", "ctx", ")", ";", "}", "}", "ctx", "->", "sendqueue_basetime", "=", "now", ";", "coap_retransmittimer_restart", "(", "ctx", ")", ";", "}" ]
FIXME: retransmits that are not required any more due to incoming packages do *not* get cleared at the moment, the wakeup when the transmission is due is silently accepted.
[ "FIXME", ":", "retransmits", "that", "are", "not", "required", "any", "more", "due", "to", "incoming", "packages", "do", "*", "not", "*", "get", "cleared", "at", "the", "moment", "the", "wakeup", "when", "the", "transmission", "is", "due", "is", "silently", "accepted", "." ]
[ "/* that's positive for sure, and unless we haven't been called for a complete wrapping cycle, did not wrap */" ]
[ { "param": "arg", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1727c26060494520fd7743c573b6b21173612911
mandeepshetty/iotivity
resource/csdk/occoap/src/occoaphelper.c
[ "Apache-2.0" ]
C
ParseCoAPPdu
OCStackResult
OCStackResult ParseCoAPPdu(coap_pdu_t * pdu, unsigned char * uriBuf, unsigned char * queryBuf, uint32_t * observeOption, uint32_t * maxAgeOption, uint8_t * numVendorSpecificHeaderOptions, OCHeaderOption * vendorSpecificHeaderOptions, coap_block_t * block1, coap_block_t * block2, uint16_t * size1, uint16_t * size2, unsigned char * payload) { coap_opt_filter_t filter; coap_opt_iterator_t opt_iter; coap_opt_t *option = NULL; size_t optLen = 0; unsigned char * optVal = NULL; size_t uriBufLen = 0; size_t queryBufLen = 0; unsigned char * payloadLoc = NULL; size_t payloadLength = 0; coap_option_filter_clear(filter); if(uriBuf) { coap_option_setb(filter, COAP_OPTION_URI_PATH); } if(queryBuf) { coap_option_setb(filter, COAP_OPTION_URI_QUERY); } if(observeOption) { coap_option_setb(filter, COAP_OPTION_OBSERVE); } if(maxAgeOption) { coap_option_setb(filter, COAP_OPTION_MAXAGE); } if(block1) { coap_option_setb(filter, COAP_OPTION_BLOCK1); } if(block2) { coap_option_setb(filter, COAP_OPTION_BLOCK2); } if(size1) { coap_option_setb(filter, COAP_OPTION_SIZE1); } if(size2) { coap_option_setb(filter, COAP_OPTION_SIZE2); } if(vendorSpecificHeaderOptions) { coap_option_setbVendor(filter); } if(payload) { coap_get_data(pdu, &payloadLength, &payloadLoc); memcpy(payload, payloadLoc, payloadLength); } coap_option_iterator_init(pdu, &opt_iter, filter); while ((option = coap_option_next(&opt_iter))) { optLen = COAP_OPT_LENGTH(option); optVal = COAP_OPT_VALUE(option); switch(opt_iter.type) { case COAP_OPTION_URI_PATH: if (uriBufLen + 1 + optLen < MAX_URI_LENGTH) { //we still have room in the buffer uriBuf[uriBufLen++] = '/'; memcpy(uriBuf + uriBufLen, optVal, optLen); uriBufLen += optLen; } else { return OC_STACK_NO_MEMORY; } break; case COAP_OPTION_URI_QUERY: if (queryBufLen + 1 + optLen < MAX_QUERY_LENGTH) { //we still have room in the buffer memcpy(queryBuf + queryBufLen, optVal, optLen); queryBufLen += optLen; queryBuf[queryBufLen++] = '&'; } else { // TODO: we should check that resources do not have long uri // at the resource creation return OC_STACK_NO_MEMORY; } break; case COAP_OPTION_OBSERVE: memcpy(observeOption, optVal, optLen); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing the observe option %u", *observeOption); break; case COAP_OPTION_MAXAGE: memcpy(maxAgeOption, optVal, optLen); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing the max age option %u", *maxAgeOption); break; case COAP_OPTION_BLOCK1: block1->szx = COAP_OPT_BLOCK_SZX(option); block1->num = coap_opt_block_num(option); block1->m = 0; if(COAP_OPT_BLOCK_MORE(option)) { block1->m = 1; } OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing block1 %u:%u:%u", block1->num, block1->m, block1->szx); break; case COAP_OPTION_BLOCK2: block2->szx = COAP_OPT_BLOCK_SZX(option); block2->num = coap_opt_block_num(option); block2->m = 0; if(COAP_OPT_BLOCK_MORE(option)) { block2->m = 1; } OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing block2 %u:%u:%u", block1->num, block1->m, block1->szx); break; case COAP_OPTION_SIZE1: break; case COAP_OPTION_SIZE2: break; default: if(*numVendorSpecificHeaderOptions >= MAX_HEADER_OPTIONS || optLen > MAX_HEADER_OPTION_DATA_LENGTH) { return OC_STACK_NO_MEMORY; } vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].protocolID = OC_COAP_ID; vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionID = opt_iter.type; vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionLength = optLen; memcpy(vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionData, optVal, optLen); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing vendor specific option %u", vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionID); OC_LOG_BUFFER(DEBUG, TAG, vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionData, vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionLength); (*numVendorSpecificHeaderOptions)++; } } if(uriBuf) { uriBuf[uriBufLen] = '\0'; } // delete last '&' in the query if(queryBuf) { queryBuf[queryBufLen?queryBufLen-1:queryBufLen] = '\0'; } OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^The final parsed uri is %s", uriBuf); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^The final parsed query is %s", queryBuf); return OC_STACK_OK; }
// Retrieve Uri and Query from received coap pdu
Retrieve Uri and Query from received coap pdu
[ "Retrieve", "Uri", "and", "Query", "from", "received", "coap", "pdu" ]
OCStackResult ParseCoAPPdu(coap_pdu_t * pdu, unsigned char * uriBuf, unsigned char * queryBuf, uint32_t * observeOption, uint32_t * maxAgeOption, uint8_t * numVendorSpecificHeaderOptions, OCHeaderOption * vendorSpecificHeaderOptions, coap_block_t * block1, coap_block_t * block2, uint16_t * size1, uint16_t * size2, unsigned char * payload) { coap_opt_filter_t filter; coap_opt_iterator_t opt_iter; coap_opt_t *option = NULL; size_t optLen = 0; unsigned char * optVal = NULL; size_t uriBufLen = 0; size_t queryBufLen = 0; unsigned char * payloadLoc = NULL; size_t payloadLength = 0; coap_option_filter_clear(filter); if(uriBuf) { coap_option_setb(filter, COAP_OPTION_URI_PATH); } if(queryBuf) { coap_option_setb(filter, COAP_OPTION_URI_QUERY); } if(observeOption) { coap_option_setb(filter, COAP_OPTION_OBSERVE); } if(maxAgeOption) { coap_option_setb(filter, COAP_OPTION_MAXAGE); } if(block1) { coap_option_setb(filter, COAP_OPTION_BLOCK1); } if(block2) { coap_option_setb(filter, COAP_OPTION_BLOCK2); } if(size1) { coap_option_setb(filter, COAP_OPTION_SIZE1); } if(size2) { coap_option_setb(filter, COAP_OPTION_SIZE2); } if(vendorSpecificHeaderOptions) { coap_option_setbVendor(filter); } if(payload) { coap_get_data(pdu, &payloadLength, &payloadLoc); memcpy(payload, payloadLoc, payloadLength); } coap_option_iterator_init(pdu, &opt_iter, filter); while ((option = coap_option_next(&opt_iter))) { optLen = COAP_OPT_LENGTH(option); optVal = COAP_OPT_VALUE(option); switch(opt_iter.type) { case COAP_OPTION_URI_PATH: if (uriBufLen + 1 + optLen < MAX_URI_LENGTH) { uriBuf[uriBufLen++] = '/'; memcpy(uriBuf + uriBufLen, optVal, optLen); uriBufLen += optLen; } else { return OC_STACK_NO_MEMORY; } break; case COAP_OPTION_URI_QUERY: if (queryBufLen + 1 + optLen < MAX_QUERY_LENGTH) { memcpy(queryBuf + queryBufLen, optVal, optLen); queryBufLen += optLen; queryBuf[queryBufLen++] = '&'; } else { return OC_STACK_NO_MEMORY; } break; case COAP_OPTION_OBSERVE: memcpy(observeOption, optVal, optLen); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing the observe option %u", *observeOption); break; case COAP_OPTION_MAXAGE: memcpy(maxAgeOption, optVal, optLen); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing the max age option %u", *maxAgeOption); break; case COAP_OPTION_BLOCK1: block1->szx = COAP_OPT_BLOCK_SZX(option); block1->num = coap_opt_block_num(option); block1->m = 0; if(COAP_OPT_BLOCK_MORE(option)) { block1->m = 1; } OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing block1 %u:%u:%u", block1->num, block1->m, block1->szx); break; case COAP_OPTION_BLOCK2: block2->szx = COAP_OPT_BLOCK_SZX(option); block2->num = coap_opt_block_num(option); block2->m = 0; if(COAP_OPT_BLOCK_MORE(option)) { block2->m = 1; } OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing block2 %u:%u:%u", block1->num, block1->m, block1->szx); break; case COAP_OPTION_SIZE1: break; case COAP_OPTION_SIZE2: break; default: if(*numVendorSpecificHeaderOptions >= MAX_HEADER_OPTIONS || optLen > MAX_HEADER_OPTION_DATA_LENGTH) { return OC_STACK_NO_MEMORY; } vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].protocolID = OC_COAP_ID; vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionID = opt_iter.type; vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionLength = optLen; memcpy(vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionData, optVal, optLen); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing vendor specific option %u", vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionID); OC_LOG_BUFFER(DEBUG, TAG, vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionData, vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionLength); (*numVendorSpecificHeaderOptions)++; } } if(uriBuf) { uriBuf[uriBufLen] = '\0'; } if(queryBuf) { queryBuf[queryBufLen?queryBufLen-1:queryBufLen] = '\0'; } OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^The final parsed uri is %s", uriBuf); OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^The final parsed query is %s", queryBuf); return OC_STACK_OK; }
[ "OCStackResult", "ParseCoAPPdu", "(", "coap_pdu_t", "*", "pdu", ",", "unsigned", "char", "*", "uriBuf", ",", "unsigned", "char", "*", "queryBuf", ",", "uint32_t", "*", "observeOption", ",", "uint32_t", "*", "maxAgeOption", ",", "uint8_t", "*", "numVendorSpecificHeaderOptions", ",", "OCHeaderOption", "*", "vendorSpecificHeaderOptions", ",", "coap_block_t", "*", "block1", ",", "coap_block_t", "*", "block2", ",", "uint16_t", "*", "size1", ",", "uint16_t", "*", "size2", ",", "unsigned", "char", "*", "payload", ")", "{", "coap_opt_filter_t", "filter", ";", "coap_opt_iterator_t", "opt_iter", ";", "coap_opt_t", "*", "option", "=", "NULL", ";", "size_t", "optLen", "=", "0", ";", "unsigned", "char", "*", "optVal", "=", "NULL", ";", "size_t", "uriBufLen", "=", "0", ";", "size_t", "queryBufLen", "=", "0", ";", "unsigned", "char", "*", "payloadLoc", "=", "NULL", ";", "size_t", "payloadLength", "=", "0", ";", "coap_option_filter_clear", "(", "filter", ")", ";", "if", "(", "uriBuf", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_URI_PATH", ")", ";", "}", "if", "(", "queryBuf", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_URI_QUERY", ")", ";", "}", "if", "(", "observeOption", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_OBSERVE", ")", ";", "}", "if", "(", "maxAgeOption", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_MAXAGE", ")", ";", "}", "if", "(", "block1", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_BLOCK1", ")", ";", "}", "if", "(", "block2", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_BLOCK2", ")", ";", "}", "if", "(", "size1", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_SIZE1", ")", ";", "}", "if", "(", "size2", ")", "{", "coap_option_setb", "(", "filter", ",", "COAP_OPTION_SIZE2", ")", ";", "}", "if", "(", "vendorSpecificHeaderOptions", ")", "{", "coap_option_setbVendor", "(", "filter", ")", ";", "}", "if", "(", "payload", ")", "{", "coap_get_data", "(", "pdu", ",", "&", "payloadLength", ",", "&", "payloadLoc", ")", ";", "memcpy", "(", "payload", ",", "payloadLoc", ",", "payloadLength", ")", ";", "}", "coap_option_iterator_init", "(", "pdu", ",", "&", "opt_iter", ",", "filter", ")", ";", "while", "(", "(", "option", "=", "coap_option_next", "(", "&", "opt_iter", ")", ")", ")", "{", "optLen", "=", "COAP_OPT_LENGTH", "(", "option", ")", ";", "optVal", "=", "COAP_OPT_VALUE", "(", "option", ")", ";", "switch", "(", "opt_iter", ".", "type", ")", "{", "case", "COAP_OPTION_URI_PATH", ":", "if", "(", "uriBufLen", "+", "1", "+", "optLen", "<", "MAX_URI_LENGTH", ")", "{", "uriBuf", "[", "uriBufLen", "++", "]", "=", "'", "'", ";", "memcpy", "(", "uriBuf", "+", "uriBufLen", ",", "optVal", ",", "optLen", ")", ";", "uriBufLen", "+=", "optLen", ";", "}", "else", "{", "return", "OC_STACK_NO_MEMORY", ";", "}", "break", ";", "case", "COAP_OPTION_URI_QUERY", ":", "if", "(", "queryBufLen", "+", "1", "+", "optLen", "<", "MAX_QUERY_LENGTH", ")", "{", "memcpy", "(", "queryBuf", "+", "queryBufLen", ",", "optVal", ",", "optLen", ")", ";", "queryBufLen", "+=", "optLen", ";", "queryBuf", "[", "queryBufLen", "++", "]", "=", "'", "'", ";", "}", "else", "{", "return", "OC_STACK_NO_MEMORY", ";", "}", "break", ";", "case", "COAP_OPTION_OBSERVE", ":", "memcpy", "(", "observeOption", ",", "optVal", ",", "optLen", ")", ";", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "*", "observeOption", ")", ";", "break", ";", "case", "COAP_OPTION_MAXAGE", ":", "memcpy", "(", "maxAgeOption", ",", "optVal", ",", "optLen", ")", ";", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "*", "maxAgeOption", ")", ";", "break", ";", "case", "COAP_OPTION_BLOCK1", ":", "block1", "->", "szx", "=", "COAP_OPT_BLOCK_SZX", "(", "option", ")", ";", "block1", "->", "num", "=", "coap_opt_block_num", "(", "option", ")", ";", "block1", "->", "m", "=", "0", ";", "if", "(", "COAP_OPT_BLOCK_MORE", "(", "option", ")", ")", "{", "block1", "->", "m", "=", "1", ";", "}", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "block1", "->", "num", ",", "block1", "->", "m", ",", "block1", "->", "szx", ")", ";", "break", ";", "case", "COAP_OPTION_BLOCK2", ":", "block2", "->", "szx", "=", "COAP_OPT_BLOCK_SZX", "(", "option", ")", ";", "block2", "->", "num", "=", "coap_opt_block_num", "(", "option", ")", ";", "block2", "->", "m", "=", "0", ";", "if", "(", "COAP_OPT_BLOCK_MORE", "(", "option", ")", ")", "{", "block2", "->", "m", "=", "1", ";", "}", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "block1", "->", "num", ",", "block1", "->", "m", ",", "block1", "->", "szx", ")", ";", "break", ";", "case", "COAP_OPTION_SIZE1", ":", "break", ";", "case", "COAP_OPTION_SIZE2", ":", "break", ";", "default", ":", "if", "(", "*", "numVendorSpecificHeaderOptions", ">=", "MAX_HEADER_OPTIONS", "||", "optLen", ">", "MAX_HEADER_OPTION_DATA_LENGTH", ")", "{", "return", "OC_STACK_NO_MEMORY", ";", "}", "vendorSpecificHeaderOptions", "[", "*", "numVendorSpecificHeaderOptions", "]", ".", "protocolID", "=", "OC_COAP_ID", ";", "vendorSpecificHeaderOptions", "[", "*", "numVendorSpecificHeaderOptions", "]", ".", "optionID", "=", "opt_iter", ".", "type", ";", "vendorSpecificHeaderOptions", "[", "*", "numVendorSpecificHeaderOptions", "]", ".", "optionLength", "=", "optLen", ";", "memcpy", "(", "vendorSpecificHeaderOptions", "[", "*", "numVendorSpecificHeaderOptions", "]", ".", "optionData", ",", "optVal", ",", "optLen", ")", ";", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "vendorSpecificHeaderOptions", "[", "*", "numVendorSpecificHeaderOptions", "]", ".", "optionID", ")", ";", "OC_LOG_BUFFER", "(", "DEBUG", ",", "TAG", ",", "vendorSpecificHeaderOptions", "[", "*", "numVendorSpecificHeaderOptions", "]", ".", "optionData", ",", "vendorSpecificHeaderOptions", "[", "*", "numVendorSpecificHeaderOptions", "]", ".", "optionLength", ")", ";", "(", "*", "numVendorSpecificHeaderOptions", ")", "++", ";", "}", "}", "if", "(", "uriBuf", ")", "{", "uriBuf", "[", "uriBufLen", "]", "=", "'", "\\0", "'", ";", "}", "if", "(", "queryBuf", ")", "{", "queryBuf", "[", "queryBufLen", "?", "queryBufLen", "-", "1", ":", "queryBufLen", "]", "=", "'", "\\0", "'", ";", "}", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "uriBuf", ")", ";", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "queryBuf", ")", ";", "return", "OC_STACK_OK", ";", "}" ]
Retrieve Uri and Query from received coap pdu
[ "Retrieve", "Uri", "and", "Query", "from", "received", "coap", "pdu" ]
[ "//we still have room in the buffer", "//we still have room in the buffer", "// TODO: we should check that resources do not have long uri", "// at the resource creation", "// delete last '&' in the query" ]
[ { "param": "pdu", "type": "coap_pdu_t" }, { "param": "uriBuf", "type": "unsigned char" }, { "param": "queryBuf", "type": "unsigned char" }, { "param": "observeOption", "type": "uint32_t" }, { "param": "maxAgeOption", "type": "uint32_t" }, { "param": "numVendorSpecificHeaderOptions", "type": "uint8_t" }, { "param": "vendorSpecificHeaderOptions", "type": "OCHeaderOption" }, { "param": "block1", "type": "coap_block_t" }, { "param": "block2", "type": "coap_block_t" }, { "param": "size1", "type": "uint16_t" }, { "param": "size2", "type": "uint16_t" }, { "param": "payload", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pdu", "type": "coap_pdu_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "uriBuf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "queryBuf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "observeOption", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "maxAgeOption", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "numVendorSpecificHeaderOptions", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vendorSpecificHeaderOptions", "type": "OCHeaderOption", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "block1", "type": "coap_block_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "block2", "type": "coap_block_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size1", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size2", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "payload", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1727c26060494520fd7743c573b6b21173612911
mandeepshetty/iotivity
resource/csdk/occoap/src/occoaphelper.c
[ "Apache-2.0" ]
C
RetrieveOCCoAPToken
void
void RetrieveOCCoAPToken(const coap_pdu_t * pdu, OCCoAPToken * rcvdToken) { if (pdu && rcvdToken) { rcvdToken->tokenLength = pdu->hdr->token_length; memcpy(rcvdToken->token, pdu->hdr->token, rcvdToken->tokenLength); } }
// Retrieve the token from the PDU
Retrieve the token from the PDU
[ "Retrieve", "the", "token", "from", "the", "PDU" ]
void RetrieveOCCoAPToken(const coap_pdu_t * pdu, OCCoAPToken * rcvdToken) { if (pdu && rcvdToken) { rcvdToken->tokenLength = pdu->hdr->token_length; memcpy(rcvdToken->token, pdu->hdr->token, rcvdToken->tokenLength); } }
[ "void", "RetrieveOCCoAPToken", "(", "const", "coap_pdu_t", "*", "pdu", ",", "OCCoAPToken", "*", "rcvdToken", ")", "{", "if", "(", "pdu", "&&", "rcvdToken", ")", "{", "rcvdToken", "->", "tokenLength", "=", "pdu", "->", "hdr", "->", "token_length", ";", "memcpy", "(", "rcvdToken", "->", "token", ",", "pdu", "->", "hdr", "->", "token", ",", "rcvdToken", "->", "tokenLength", ")", ";", "}", "}" ]
Retrieve the token from the PDU
[ "Retrieve", "the", "token", "from", "the", "PDU" ]
[]
[ { "param": "pdu", "type": "coap_pdu_t" }, { "param": "rcvdToken", "type": "OCCoAPToken" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pdu", "type": "coap_pdu_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rcvdToken", "type": "OCCoAPToken", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1727c26060494520fd7743c573b6b21173612911
mandeepshetty/iotivity
resource/csdk/occoap/src/occoaphelper.c
[ "Apache-2.0" ]
C
OrderOptions
int
int OrderOptions(void *a, void *b) { if (!a || !b) { return a < b ? -1 : 1; } if (COAP_OPTION_KEY(*(coap_option *)a) < COAP_OPTION_KEY(*(coap_option *)b) ) { return -1; } return COAP_OPTION_KEY(*(coap_option *)a) == COAP_OPTION_KEY(*(coap_option *)b) ; }
//a function to help in ordering coap options
a function to help in ordering coap options
[ "a", "function", "to", "help", "in", "ordering", "coap", "options" ]
int OrderOptions(void *a, void *b) { if (!a || !b) { return a < b ? -1 : 1; } if (COAP_OPTION_KEY(*(coap_option *)a) < COAP_OPTION_KEY(*(coap_option *)b) ) { return -1; } return COAP_OPTION_KEY(*(coap_option *)a) == COAP_OPTION_KEY(*(coap_option *)b) ; }
[ "int", "OrderOptions", "(", "void", "*", "a", ",", "void", "*", "b", ")", "{", "if", "(", "!", "a", "||", "!", "b", ")", "{", "return", "a", "<", "b", "?", "-1", ":", "1", ";", "}", "if", "(", "COAP_OPTION_KEY", "(", "*", "(", "coap_option", "*", ")", "a", ")", "<", "COAP_OPTION_KEY", "(", "*", "(", "coap_option", "*", ")", "b", ")", ")", "{", "return", "-1", ";", "}", "return", "COAP_OPTION_KEY", "(", "*", "(", "coap_option", "*", ")", "a", ")", "==", "COAP_OPTION_KEY", "(", "*", "(", "coap_option", "*", ")", "b", ")", ";", "}" ]
a function to help in ordering coap options
[ "a", "function", "to", "help", "in", "ordering", "coap", "options" ]
[]
[ { "param": "a", "type": "void" }, { "param": "b", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "a", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "b", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1727c26060494520fd7743c573b6b21173612911
mandeepshetty/iotivity
resource/csdk/occoap/src/occoaphelper.c
[ "Apache-2.0" ]
C
CreateNewOptionNode
coap_list_t
coap_list_t * CreateNewOptionNode(unsigned short key, unsigned int length, unsigned char *data) { coap_option *option = NULL; coap_list_t *node; VERIFY_NON_NULL(data); option = (coap_option *)coap_malloc(sizeof(coap_option) + length); VERIFY_NON_NULL(option); COAP_OPTION_KEY(*option) = key; COAP_OPTION_LENGTH(*option) = length; memcpy(COAP_OPTION_DATA(*option), data, length); /* we can pass NULL here as delete function since option is released automatically */ node = coap_new_listnode(option, NULL); if (node) { return node; } exit: OC_LOG(ERROR,TAG, PCF("new_option_node: malloc: was not created")); coap_free(option); return NULL; }
//a function to create a coap option
a function to create a coap option
[ "a", "function", "to", "create", "a", "coap", "option" ]
coap_list_t * CreateNewOptionNode(unsigned short key, unsigned int length, unsigned char *data) { coap_option *option = NULL; coap_list_t *node; VERIFY_NON_NULL(data); option = (coap_option *)coap_malloc(sizeof(coap_option) + length); VERIFY_NON_NULL(option); COAP_OPTION_KEY(*option) = key; COAP_OPTION_LENGTH(*option) = length; memcpy(COAP_OPTION_DATA(*option), data, length); node = coap_new_listnode(option, NULL); if (node) { return node; } exit: OC_LOG(ERROR,TAG, PCF("new_option_node: malloc: was not created")); coap_free(option); return NULL; }
[ "coap_list_t", "*", "CreateNewOptionNode", "(", "unsigned", "short", "key", ",", "unsigned", "int", "length", ",", "unsigned", "char", "*", "data", ")", "{", "coap_option", "*", "option", "=", "NULL", ";", "coap_list_t", "*", "node", ";", "VERIFY_NON_NULL", "(", "data", ")", ";", "option", "=", "(", "coap_option", "*", ")", "coap_malloc", "(", "sizeof", "(", "coap_option", ")", "+", "length", ")", ";", "VERIFY_NON_NULL", "(", "option", ")", ";", "COAP_OPTION_KEY", "(", "*", "option", ")", "=", "key", ";", "COAP_OPTION_LENGTH", "(", "*", "option", ")", "=", "length", ";", "memcpy", "(", "COAP_OPTION_DATA", "(", "*", "option", ")", ",", "data", ",", "length", ")", ";", "node", "=", "coap_new_listnode", "(", "option", ",", "NULL", ")", ";", "if", "(", "node", ")", "{", "return", "node", ";", "}", "exit", ":", "OC_LOG", "(", "ERROR", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "coap_free", "(", "option", ")", ";", "return", "NULL", ";", "}" ]
a function to create a coap option
[ "a", "function", "to", "create", "a", "coap", "option" ]
[ "/* we can pass NULL here as delete function since option is released automatically */" ]
[ { "param": "key", "type": "unsigned short" }, { "param": "length", "type": "unsigned int" }, { "param": "data", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "key", "type": "unsigned short", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "length", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1727c26060494520fd7743c573b6b21173612911
mandeepshetty/iotivity
resource/csdk/occoap/src/occoaphelper.c
[ "Apache-2.0" ]
C
HandleSendQueue
void
void HandleSendQueue(coap_context_t * ctx) { coap_tick_t now; coap_queue_t *nextQueue = NULL; coap_ticks(&now); nextQueue = coap_peek_next( ctx ); while (nextQueue && nextQueue->t <= now - ctx->sendqueue_basetime) { nextQueue = coap_pop_next( ctx ); if((uint8_t)nextQueue->delayedResNeeded) { OC_LOG_V(DEBUG, TAG, "Sending Delayed response TID %d", nextQueue->id); if(SendCoAPPdu(ctx, &nextQueue->remote, nextQueue->pdu, (coap_send_flags_t)(nextQueue->secure ? SEND_SECURE_PORT : 0)) == OC_STACK_COMM_ERROR) { OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu")); HandleFailedCommunication(ctx, nextQueue); } nextQueue->pdu = NULL; coap_delete_node(nextQueue); } else { OC_LOG_V(DEBUG, TAG, "Retrying a CON pdu TID %d",nextQueue->id); if(ReTXCoAPQueue(ctx, nextQueue) == OC_STACK_COMM_ERROR) { OC_LOG(DEBUG, TAG, PCF("A problem occurred in retransmitting a pdu")); HandleFailedCommunication(ctx, nextQueue); coap_delete_node(nextQueue); } } nextQueue = coap_peek_next( ctx ); } }
// a function to handle the send queue in the passed context
a function to handle the send queue in the passed context
[ "a", "function", "to", "handle", "the", "send", "queue", "in", "the", "passed", "context" ]
void HandleSendQueue(coap_context_t * ctx) { coap_tick_t now; coap_queue_t *nextQueue = NULL; coap_ticks(&now); nextQueue = coap_peek_next( ctx ); while (nextQueue && nextQueue->t <= now - ctx->sendqueue_basetime) { nextQueue = coap_pop_next( ctx ); if((uint8_t)nextQueue->delayedResNeeded) { OC_LOG_V(DEBUG, TAG, "Sending Delayed response TID %d", nextQueue->id); if(SendCoAPPdu(ctx, &nextQueue->remote, nextQueue->pdu, (coap_send_flags_t)(nextQueue->secure ? SEND_SECURE_PORT : 0)) == OC_STACK_COMM_ERROR) { OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu")); HandleFailedCommunication(ctx, nextQueue); } nextQueue->pdu = NULL; coap_delete_node(nextQueue); } else { OC_LOG_V(DEBUG, TAG, "Retrying a CON pdu TID %d",nextQueue->id); if(ReTXCoAPQueue(ctx, nextQueue) == OC_STACK_COMM_ERROR) { OC_LOG(DEBUG, TAG, PCF("A problem occurred in retransmitting a pdu")); HandleFailedCommunication(ctx, nextQueue); coap_delete_node(nextQueue); } } nextQueue = coap_peek_next( ctx ); } }
[ "void", "HandleSendQueue", "(", "coap_context_t", "*", "ctx", ")", "{", "coap_tick_t", "now", ";", "coap_queue_t", "*", "nextQueue", "=", "NULL", ";", "coap_ticks", "(", "&", "now", ")", ";", "nextQueue", "=", "coap_peek_next", "(", "ctx", ")", ";", "while", "(", "nextQueue", "&&", "nextQueue", "->", "t", "<=", "now", "-", "ctx", "->", "sendqueue_basetime", ")", "{", "nextQueue", "=", "coap_pop_next", "(", "ctx", ")", ";", "if", "(", "(", "uint8_t", ")", "nextQueue", "->", "delayedResNeeded", ")", "{", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "nextQueue", "->", "id", ")", ";", "if", "(", "SendCoAPPdu", "(", "ctx", ",", "&", "nextQueue", "->", "remote", ",", "nextQueue", "->", "pdu", ",", "(", "coap_send_flags_t", ")", "(", "nextQueue", "->", "secure", "?", "SEND_SECURE_PORT", ":", "0", ")", ")", "==", "OC_STACK_COMM_ERROR", ")", "{", "OC_LOG", "(", "DEBUG", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "HandleFailedCommunication", "(", "ctx", ",", "nextQueue", ")", ";", "}", "nextQueue", "->", "pdu", "=", "NULL", ";", "coap_delete_node", "(", "nextQueue", ")", ";", "}", "else", "{", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "nextQueue", "->", "id", ")", ";", "if", "(", "ReTXCoAPQueue", "(", "ctx", ",", "nextQueue", ")", "==", "OC_STACK_COMM_ERROR", ")", "{", "OC_LOG", "(", "DEBUG", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "HandleFailedCommunication", "(", "ctx", ",", "nextQueue", ")", ";", "coap_delete_node", "(", "nextQueue", ")", ";", "}", "}", "nextQueue", "=", "coap_peek_next", "(", "ctx", ")", ";", "}", "}" ]
a function to handle the send queue in the passed context
[ "a", "function", "to", "handle", "the", "send", "queue", "in", "the", "passed", "context" ]
[]
[ { "param": "ctx", "type": "coap_context_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
63aa982eba647c163fb56a1a46989b7c5ce458ff
mandeepshetty/iotivity
resource/csdk/occoap/src/occoap.c
[ "Apache-2.0" ]
C
HandleCoAPAckRst
void
static void HandleCoAPAckRst(struct coap_context_t * ctx, uint8_t msgType, const coap_queue_t * sentQueue){ // silence warnings (void) ctx; coap_pdu_t * sentPdu = sentQueue->pdu; OCStackResult result = OC_STACK_ERROR; uint32_t observationOption = OC_OBSERVE_NO_OPTION; // {{0}} to eliminate warning for known compiler bug 53119 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 OCCoAPToken sentToken = {{0}}; result = ParseCoAPPdu(sentPdu, NULL, NULL, &observationOption, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); VERIFY_SUCCESS(result, OC_STACK_OK); // fill OCCoAPToken structure RetrieveOCCoAPToken(sentPdu, &sentToken); if(msgType == COAP_MESSAGE_RST) { if(myStackMode != OC_CLIENT) { result = OCStackFeedBack(&sentToken, OC_OBSERVER_NOT_INTERESTED); if(result == OC_STACK_OK) { OC_LOG_V(DEBUG, TAG, "Received RST, removing all queues associated with Token %d bytes", sentToken.tokenLength); OC_LOG_BUFFER(INFO, TAG, sentToken.token, sentToken.tokenLength); coap_cancel_all_messages(ctx, &sentQueue->remote, sentToken.token, sentToken.tokenLength); } } } else if(observationOption != OC_OBSERVE_NO_OPTION && msgType == COAP_MESSAGE_ACK) { OC_LOG_V(DEBUG, TAG, "Received ACK, for Token %d bytes",sentToken.tokenLength); OC_LOG_BUFFER(INFO, TAG, sentToken.token, sentToken.tokenLength); // now the observer is still interested if(myStackMode != OC_CLIENT) { OCStackFeedBack(&sentToken, OC_OBSERVER_STILL_INTERESTED); } } exit: return; }
//This function is called back by libcoap when ack or rst are received
This function is called back by libcoap when ack or rst are received
[ "This", "function", "is", "called", "back", "by", "libcoap", "when", "ack", "or", "rst", "are", "received" ]
static void HandleCoAPAckRst(struct coap_context_t * ctx, uint8_t msgType, const coap_queue_t * sentQueue){ (void) ctx; coap_pdu_t * sentPdu = sentQueue->pdu; OCStackResult result = OC_STACK_ERROR; uint32_t observationOption = OC_OBSERVE_NO_OPTION; OCCoAPToken sentToken = {{0}}; result = ParseCoAPPdu(sentPdu, NULL, NULL, &observationOption, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); VERIFY_SUCCESS(result, OC_STACK_OK); RetrieveOCCoAPToken(sentPdu, &sentToken); if(msgType == COAP_MESSAGE_RST) { if(myStackMode != OC_CLIENT) { result = OCStackFeedBack(&sentToken, OC_OBSERVER_NOT_INTERESTED); if(result == OC_STACK_OK) { OC_LOG_V(DEBUG, TAG, "Received RST, removing all queues associated with Token %d bytes", sentToken.tokenLength); OC_LOG_BUFFER(INFO, TAG, sentToken.token, sentToken.tokenLength); coap_cancel_all_messages(ctx, &sentQueue->remote, sentToken.token, sentToken.tokenLength); } } } else if(observationOption != OC_OBSERVE_NO_OPTION && msgType == COAP_MESSAGE_ACK) { OC_LOG_V(DEBUG, TAG, "Received ACK, for Token %d bytes",sentToken.tokenLength); OC_LOG_BUFFER(INFO, TAG, sentToken.token, sentToken.tokenLength); if(myStackMode != OC_CLIENT) { OCStackFeedBack(&sentToken, OC_OBSERVER_STILL_INTERESTED); } } exit: return; }
[ "static", "void", "HandleCoAPAckRst", "(", "struct", "coap_context_t", "*", "ctx", ",", "uint8_t", "msgType", ",", "const", "coap_queue_t", "*", "sentQueue", ")", "{", "(", "void", ")", "ctx", ";", "coap_pdu_t", "*", "sentPdu", "=", "sentQueue", "->", "pdu", ";", "OCStackResult", "result", "=", "OC_STACK_ERROR", ";", "uint32_t", "observationOption", "=", "OC_OBSERVE_NO_OPTION", ";", "OCCoAPToken", "sentToken", "=", "{", "{", "0", "}", "}", ";", "result", "=", "ParseCoAPPdu", "(", "sentPdu", ",", "NULL", ",", "NULL", ",", "&", "observationOption", ",", "NULL", ",", "NULL", ",", "NULL", ",", "NULL", ",", "NULL", ",", "NULL", ",", "NULL", ",", "NULL", ")", ";", "VERIFY_SUCCESS", "(", "result", ",", "OC_STACK_OK", ")", ";", "RetrieveOCCoAPToken", "(", "sentPdu", ",", "&", "sentToken", ")", ";", "if", "(", "msgType", "==", "COAP_MESSAGE_RST", ")", "{", "if", "(", "myStackMode", "!=", "OC_CLIENT", ")", "{", "result", "=", "OCStackFeedBack", "(", "&", "sentToken", ",", "OC_OBSERVER_NOT_INTERESTED", ")", ";", "if", "(", "result", "==", "OC_STACK_OK", ")", "{", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "sentToken", ".", "tokenLength", ")", ";", "OC_LOG_BUFFER", "(", "INFO", ",", "TAG", ",", "sentToken", ".", "token", ",", "sentToken", ".", "tokenLength", ")", ";", "coap_cancel_all_messages", "(", "ctx", ",", "&", "sentQueue", "->", "remote", ",", "sentToken", ".", "token", ",", "sentToken", ".", "tokenLength", ")", ";", "}", "}", "}", "else", "if", "(", "observationOption", "!=", "OC_OBSERVE_NO_OPTION", "&&", "msgType", "==", "COAP_MESSAGE_ACK", ")", "{", "OC_LOG_V", "(", "DEBUG", ",", "TAG", ",", "\"", "\"", ",", "sentToken", ".", "tokenLength", ")", ";", "OC_LOG_BUFFER", "(", "INFO", ",", "TAG", ",", "sentToken", ".", "token", ",", "sentToken", ".", "tokenLength", ")", ";", "if", "(", "myStackMode", "!=", "OC_CLIENT", ")", "{", "OCStackFeedBack", "(", "&", "sentToken", ",", "OC_OBSERVER_STILL_INTERESTED", ")", ";", "}", "}", "exit", ":", "return", ";", "}" ]
This function is called back by libcoap when ack or rst are received
[ "This", "function", "is", "called", "back", "by", "libcoap", "when", "ack", "or", "rst", "are", "received" ]
[ "// silence warnings", "// {{0}} to eliminate warning for known compiler bug 53119", "// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119", "// fill OCCoAPToken structure", "// now the observer is still interested" ]
[ { "param": "ctx", "type": "struct coap_context_t" }, { "param": "msgType", "type": "uint8_t" }, { "param": "sentQueue", "type": "coap_queue_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "struct coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msgType", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sentQueue", "type": "coap_queue_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
63aa982eba647c163fb56a1a46989b7c5ce458ff
mandeepshetty/iotivity
resource/csdk/occoap/src/occoap.c
[ "Apache-2.0" ]
C
HandleCoAPRequests
void
static void HandleCoAPRequests(struct coap_context_t *ctx, const coap_queue_t * rcvdRequest) { // silence warnings (void) ctx; OCServerProtocolRequest protocolRequest = {(OCMethod)0}; coap_block_t rcvdBlock1; coap_block_t rcvdBlock2; memset(&rcvdBlock1, COAP_BLOCK_FILL_VALUE, sizeof(coap_block_t)); memset(&rcvdBlock2, COAP_BLOCK_FILL_VALUE, sizeof(coap_block_t)); uint16_t rcvdSize1 = 0; coap_pdu_t * rcvdPdu = rcvdRequest->pdu; coap_pdu_t * sendPdu = NULL; coap_send_flags_t sendFlag; OCStackResult result = OC_STACK_ERROR; OCStackResult requestResult = OC_STACK_ERROR; if(myStackMode == OC_CLIENT) { //TODO: should the client be responding to requests? return; } protocolRequest.observationOption = OC_OBSERVE_NO_OPTION; protocolRequest.qos = (rcvdPdu->hdr->type == COAP_MESSAGE_CON) ? OC_HIGH_QOS : OC_LOW_QOS; protocolRequest.coapID = rcvdPdu->hdr->id; protocolRequest.delayedResNeeded = rcvdRequest->delayedResNeeded; protocolRequest.secured = rcvdRequest->secure; // fill OCCoAPToken structure RetrieveOCCoAPToken(rcvdPdu, &protocolRequest.requestToken); OC_LOG_V(INFO, TAG, " Token received %d bytes", protocolRequest.requestToken.tokenLength); OC_LOG_BUFFER(INFO, TAG, protocolRequest.requestToken.token, protocolRequest.requestToken.tokenLength); // fill OCDevAddr memcpy(&protocolRequest.requesterAddr, (OCDevAddr *) &rcvdRequest->remote, sizeof(OCDevAddr)); // Retrieve Uri and Query from received coap pdu result = ParseCoAPPdu(rcvdPdu, protocolRequest.resourceUrl, protocolRequest.query, &(protocolRequest.observationOption), NULL, &(protocolRequest.numRcvdVendorSpecificHeaderOptions), protocolRequest.rcvdVendorSpecificHeaderOptions, &rcvdBlock1, &rcvdBlock2, &rcvdSize1, NULL, protocolRequest.reqJSONPayload); VERIFY_SUCCESS(result, OC_STACK_OK); switch (rcvdPdu->hdr->code) { case COAP_REQUEST_GET: { protocolRequest.method = OC_REST_GET; break; } case COAP_REQUEST_POST: { protocolRequest.method = OC_REST_POST; break; } case COAP_REQUEST_DELETE: { protocolRequest.method = OC_REST_DELETE; break; } case COAP_REQUEST_PUT: { protocolRequest.method = OC_REST_PUT; break; } default: { OC_LOG_V(ERROR, TAG, "Received CoAP method %d not supported", rcvdPdu->hdr->code); goto exit; } } if(rcvdBlock1.szx != 7) { protocolRequest.reqPacketSize = 1 << (rcvdBlock1.szx + 4); protocolRequest.reqMorePacket = rcvdBlock1.m; protocolRequest.reqPacketNum = rcvdBlock1.num; } else { // No block1 received rcvdSize1 = strlen((const char *)protocolRequest.reqJSONPayload)+1; protocolRequest.reqTotalSize = rcvdSize1; } if(rcvdBlock2.szx != 7) { protocolRequest.resPacketSize = 1 << (rcvdBlock2.szx + 4); protocolRequest.resPacketNum = rcvdBlock2.num; } requestResult = HandleStackRequests(&protocolRequest); if(requestResult == OC_STACK_VIRTUAL_DO_NOT_HANDLE || requestResult == OC_STACK_OK || requestResult == OC_STACK_RESOURCE_CREATED || requestResult == OC_STACK_RESOURCE_DELETED || requestResult == OC_STACK_INVALID_DEVICE_INFO) { goto exit; } else if(requestResult == OC_STACK_NO_MEMORY || requestResult == OC_STACK_ERROR || requestResult == OC_STACK_NOTIMPL || requestResult == OC_STACK_NO_RESOURCE || requestResult == OC_STACK_RESOURCE_ERROR) { // TODO: should we send an error also when we receive a non-secured request to a secure resource? // TODO: should we consider some sort of error response OC_LOG(DEBUG, TAG, PCF("We should send some sort of error message")); // generate the pdu, if the request was CON, then the response is ACK, otherwire NON sendPdu = GenerateCoAPPdu((rcvdPdu->hdr->type == COAP_MESSAGE_CON)? COAP_MESSAGE_ACK : COAP_MESSAGE_NON, OCToCoAPResponseCode(requestResult), rcvdPdu->hdr->id, &protocolRequest.requestToken, NULL, NULL); VERIFY_NON_NULL(sendPdu); coap_show_pdu(sendPdu); sendFlag = (coap_send_flags_t)(rcvdRequest->secure ? SEND_SECURE_PORT : 0); if(SendCoAPPdu(gCoAPCtx, (coap_address_t*) &(rcvdRequest->remote), sendPdu, sendFlag) != OC_STACK_OK){ OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu")); } goto exit; } else if(requestResult == OC_STACK_SLOW_RESOURCE || requestResult == OC_STACK_DUPLICATE_REQUEST) { if(rcvdPdu->hdr->type == COAP_MESSAGE_CON) { // generate the pdu, if the request was CON, then the response is ACK, otherwire NON sendPdu = GenerateCoAPPdu(COAP_MESSAGE_ACK, 0, rcvdPdu->hdr->id, NULL, NULL, NULL); VERIFY_NON_NULL(sendPdu); coap_show_pdu(sendPdu); sendFlag = (coap_send_flags_t)(rcvdRequest->secure ? SEND_SECURE_PORT : 0); if(SendCoAPPdu(gCoAPCtx, (coap_address_t*) &(rcvdRequest->remote), sendPdu, sendFlag) != OC_STACK_OK){ OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu")); } } else { goto exit; } } exit: return; }
//This function is called back by libcoap when a request is received
This function is called back by libcoap when a request is received
[ "This", "function", "is", "called", "back", "by", "libcoap", "when", "a", "request", "is", "received" ]
static void HandleCoAPRequests(struct coap_context_t *ctx, const coap_queue_t * rcvdRequest) { (void) ctx; OCServerProtocolRequest protocolRequest = {(OCMethod)0}; coap_block_t rcvdBlock1; coap_block_t rcvdBlock2; memset(&rcvdBlock1, COAP_BLOCK_FILL_VALUE, sizeof(coap_block_t)); memset(&rcvdBlock2, COAP_BLOCK_FILL_VALUE, sizeof(coap_block_t)); uint16_t rcvdSize1 = 0; coap_pdu_t * rcvdPdu = rcvdRequest->pdu; coap_pdu_t * sendPdu = NULL; coap_send_flags_t sendFlag; OCStackResult result = OC_STACK_ERROR; OCStackResult requestResult = OC_STACK_ERROR; if(myStackMode == OC_CLIENT) { return; } protocolRequest.observationOption = OC_OBSERVE_NO_OPTION; protocolRequest.qos = (rcvdPdu->hdr->type == COAP_MESSAGE_CON) ? OC_HIGH_QOS : OC_LOW_QOS; protocolRequest.coapID = rcvdPdu->hdr->id; protocolRequest.delayedResNeeded = rcvdRequest->delayedResNeeded; protocolRequest.secured = rcvdRequest->secure; RetrieveOCCoAPToken(rcvdPdu, &protocolRequest.requestToken); OC_LOG_V(INFO, TAG, " Token received %d bytes", protocolRequest.requestToken.tokenLength); OC_LOG_BUFFER(INFO, TAG, protocolRequest.requestToken.token, protocolRequest.requestToken.tokenLength); memcpy(&protocolRequest.requesterAddr, (OCDevAddr *) &rcvdRequest->remote, sizeof(OCDevAddr)); result = ParseCoAPPdu(rcvdPdu, protocolRequest.resourceUrl, protocolRequest.query, &(protocolRequest.observationOption), NULL, &(protocolRequest.numRcvdVendorSpecificHeaderOptions), protocolRequest.rcvdVendorSpecificHeaderOptions, &rcvdBlock1, &rcvdBlock2, &rcvdSize1, NULL, protocolRequest.reqJSONPayload); VERIFY_SUCCESS(result, OC_STACK_OK); switch (rcvdPdu->hdr->code) { case COAP_REQUEST_GET: { protocolRequest.method = OC_REST_GET; break; } case COAP_REQUEST_POST: { protocolRequest.method = OC_REST_POST; break; } case COAP_REQUEST_DELETE: { protocolRequest.method = OC_REST_DELETE; break; } case COAP_REQUEST_PUT: { protocolRequest.method = OC_REST_PUT; break; } default: { OC_LOG_V(ERROR, TAG, "Received CoAP method %d not supported", rcvdPdu->hdr->code); goto exit; } } if(rcvdBlock1.szx != 7) { protocolRequest.reqPacketSize = 1 << (rcvdBlock1.szx + 4); protocolRequest.reqMorePacket = rcvdBlock1.m; protocolRequest.reqPacketNum = rcvdBlock1.num; } else { rcvdSize1 = strlen((const char *)protocolRequest.reqJSONPayload)+1; protocolRequest.reqTotalSize = rcvdSize1; } if(rcvdBlock2.szx != 7) { protocolRequest.resPacketSize = 1 << (rcvdBlock2.szx + 4); protocolRequest.resPacketNum = rcvdBlock2.num; } requestResult = HandleStackRequests(&protocolRequest); if(requestResult == OC_STACK_VIRTUAL_DO_NOT_HANDLE || requestResult == OC_STACK_OK || requestResult == OC_STACK_RESOURCE_CREATED || requestResult == OC_STACK_RESOURCE_DELETED || requestResult == OC_STACK_INVALID_DEVICE_INFO) { goto exit; } else if(requestResult == OC_STACK_NO_MEMORY || requestResult == OC_STACK_ERROR || requestResult == OC_STACK_NOTIMPL || requestResult == OC_STACK_NO_RESOURCE || requestResult == OC_STACK_RESOURCE_ERROR) { OC_LOG(DEBUG, TAG, PCF("We should send some sort of error message")); sendPdu = GenerateCoAPPdu((rcvdPdu->hdr->type == COAP_MESSAGE_CON)? COAP_MESSAGE_ACK : COAP_MESSAGE_NON, OCToCoAPResponseCode(requestResult), rcvdPdu->hdr->id, &protocolRequest.requestToken, NULL, NULL); VERIFY_NON_NULL(sendPdu); coap_show_pdu(sendPdu); sendFlag = (coap_send_flags_t)(rcvdRequest->secure ? SEND_SECURE_PORT : 0); if(SendCoAPPdu(gCoAPCtx, (coap_address_t*) &(rcvdRequest->remote), sendPdu, sendFlag) != OC_STACK_OK){ OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu")); } goto exit; } else if(requestResult == OC_STACK_SLOW_RESOURCE || requestResult == OC_STACK_DUPLICATE_REQUEST) { if(rcvdPdu->hdr->type == COAP_MESSAGE_CON) { sendPdu = GenerateCoAPPdu(COAP_MESSAGE_ACK, 0, rcvdPdu->hdr->id, NULL, NULL, NULL); VERIFY_NON_NULL(sendPdu); coap_show_pdu(sendPdu); sendFlag = (coap_send_flags_t)(rcvdRequest->secure ? SEND_SECURE_PORT : 0); if(SendCoAPPdu(gCoAPCtx, (coap_address_t*) &(rcvdRequest->remote), sendPdu, sendFlag) != OC_STACK_OK){ OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu")); } } else { goto exit; } } exit: return; }
[ "static", "void", "HandleCoAPRequests", "(", "struct", "coap_context_t", "*", "ctx", ",", "const", "coap_queue_t", "*", "rcvdRequest", ")", "{", "(", "void", ")", "ctx", ";", "OCServerProtocolRequest", "protocolRequest", "=", "{", "(", "OCMethod", ")", "0", "}", ";", "coap_block_t", "rcvdBlock1", ";", "coap_block_t", "rcvdBlock2", ";", "memset", "(", "&", "rcvdBlock1", ",", "COAP_BLOCK_FILL_VALUE", ",", "sizeof", "(", "coap_block_t", ")", ")", ";", "memset", "(", "&", "rcvdBlock2", ",", "COAP_BLOCK_FILL_VALUE", ",", "sizeof", "(", "coap_block_t", ")", ")", ";", "uint16_t", "rcvdSize1", "=", "0", ";", "coap_pdu_t", "*", "rcvdPdu", "=", "rcvdRequest", "->", "pdu", ";", "coap_pdu_t", "*", "sendPdu", "=", "NULL", ";", "coap_send_flags_t", "sendFlag", ";", "OCStackResult", "result", "=", "OC_STACK_ERROR", ";", "OCStackResult", "requestResult", "=", "OC_STACK_ERROR", ";", "if", "(", "myStackMode", "==", "OC_CLIENT", ")", "{", "return", ";", "}", "protocolRequest", ".", "observationOption", "=", "OC_OBSERVE_NO_OPTION", ";", "protocolRequest", ".", "qos", "=", "(", "rcvdPdu", "->", "hdr", "->", "type", "==", "COAP_MESSAGE_CON", ")", "?", "OC_HIGH_QOS", ":", "OC_LOW_QOS", ";", "protocolRequest", ".", "coapID", "=", "rcvdPdu", "->", "hdr", "->", "id", ";", "protocolRequest", ".", "delayedResNeeded", "=", "rcvdRequest", "->", "delayedResNeeded", ";", "protocolRequest", ".", "secured", "=", "rcvdRequest", "->", "secure", ";", "RetrieveOCCoAPToken", "(", "rcvdPdu", ",", "&", "protocolRequest", ".", "requestToken", ")", ";", "OC_LOG_V", "(", "INFO", ",", "TAG", ",", "\"", "\"", ",", "protocolRequest", ".", "requestToken", ".", "tokenLength", ")", ";", "OC_LOG_BUFFER", "(", "INFO", ",", "TAG", ",", "protocolRequest", ".", "requestToken", ".", "token", ",", "protocolRequest", ".", "requestToken", ".", "tokenLength", ")", ";", "memcpy", "(", "&", "protocolRequest", ".", "requesterAddr", ",", "(", "OCDevAddr", "*", ")", "&", "rcvdRequest", "->", "remote", ",", "sizeof", "(", "OCDevAddr", ")", ")", ";", "result", "=", "ParseCoAPPdu", "(", "rcvdPdu", ",", "protocolRequest", ".", "resourceUrl", ",", "protocolRequest", ".", "query", ",", "&", "(", "protocolRequest", ".", "observationOption", ")", ",", "NULL", ",", "&", "(", "protocolRequest", ".", "numRcvdVendorSpecificHeaderOptions", ")", ",", "protocolRequest", ".", "rcvdVendorSpecificHeaderOptions", ",", "&", "rcvdBlock1", ",", "&", "rcvdBlock2", ",", "&", "rcvdSize1", ",", "NULL", ",", "protocolRequest", ".", "reqJSONPayload", ")", ";", "VERIFY_SUCCESS", "(", "result", ",", "OC_STACK_OK", ")", ";", "switch", "(", "rcvdPdu", "->", "hdr", "->", "code", ")", "{", "case", "COAP_REQUEST_GET", ":", "{", "protocolRequest", ".", "method", "=", "OC_REST_GET", ";", "break", ";", "}", "case", "COAP_REQUEST_POST", ":", "{", "protocolRequest", ".", "method", "=", "OC_REST_POST", ";", "break", ";", "}", "case", "COAP_REQUEST_DELETE", ":", "{", "protocolRequest", ".", "method", "=", "OC_REST_DELETE", ";", "break", ";", "}", "case", "COAP_REQUEST_PUT", ":", "{", "protocolRequest", ".", "method", "=", "OC_REST_PUT", ";", "break", ";", "}", "default", ":", "{", "OC_LOG_V", "(", "ERROR", ",", "TAG", ",", "\"", "\"", ",", "rcvdPdu", "->", "hdr", "->", "code", ")", ";", "goto", "exit", ";", "}", "}", "if", "(", "rcvdBlock1", ".", "szx", "!=", "7", ")", "{", "protocolRequest", ".", "reqPacketSize", "=", "1", "<<", "(", "rcvdBlock1", ".", "szx", "+", "4", ")", ";", "protocolRequest", ".", "reqMorePacket", "=", "rcvdBlock1", ".", "m", ";", "protocolRequest", ".", "reqPacketNum", "=", "rcvdBlock1", ".", "num", ";", "}", "else", "{", "rcvdSize1", "=", "strlen", "(", "(", "const", "char", "*", ")", "protocolRequest", ".", "reqJSONPayload", ")", "+", "1", ";", "protocolRequest", ".", "reqTotalSize", "=", "rcvdSize1", ";", "}", "if", "(", "rcvdBlock2", ".", "szx", "!=", "7", ")", "{", "protocolRequest", ".", "resPacketSize", "=", "1", "<<", "(", "rcvdBlock2", ".", "szx", "+", "4", ")", ";", "protocolRequest", ".", "resPacketNum", "=", "rcvdBlock2", ".", "num", ";", "}", "requestResult", "=", "HandleStackRequests", "(", "&", "protocolRequest", ")", ";", "if", "(", "requestResult", "==", "OC_STACK_VIRTUAL_DO_NOT_HANDLE", "||", "requestResult", "==", "OC_STACK_OK", "||", "requestResult", "==", "OC_STACK_RESOURCE_CREATED", "||", "requestResult", "==", "OC_STACK_RESOURCE_DELETED", "||", "requestResult", "==", "OC_STACK_INVALID_DEVICE_INFO", ")", "{", "goto", "exit", ";", "}", "else", "if", "(", "requestResult", "==", "OC_STACK_NO_MEMORY", "||", "requestResult", "==", "OC_STACK_ERROR", "||", "requestResult", "==", "OC_STACK_NOTIMPL", "||", "requestResult", "==", "OC_STACK_NO_RESOURCE", "||", "requestResult", "==", "OC_STACK_RESOURCE_ERROR", ")", "{", "OC_LOG", "(", "DEBUG", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "sendPdu", "=", "GenerateCoAPPdu", "(", "(", "rcvdPdu", "->", "hdr", "->", "type", "==", "COAP_MESSAGE_CON", ")", "?", "COAP_MESSAGE_ACK", ":", "COAP_MESSAGE_NON", ",", "OCToCoAPResponseCode", "(", "requestResult", ")", ",", "rcvdPdu", "->", "hdr", "->", "id", ",", "&", "protocolRequest", ".", "requestToken", ",", "NULL", ",", "NULL", ")", ";", "VERIFY_NON_NULL", "(", "sendPdu", ")", ";", "coap_show_pdu", "(", "sendPdu", ")", ";", "sendFlag", "=", "(", "coap_send_flags_t", ")", "(", "rcvdRequest", "->", "secure", "?", "SEND_SECURE_PORT", ":", "0", ")", ";", "if", "(", "SendCoAPPdu", "(", "gCoAPCtx", ",", "(", "coap_address_t", "*", ")", "&", "(", "rcvdRequest", "->", "remote", ")", ",", "sendPdu", ",", "sendFlag", ")", "!=", "OC_STACK_OK", ")", "{", "OC_LOG", "(", "DEBUG", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "}", "goto", "exit", ";", "}", "else", "if", "(", "requestResult", "==", "OC_STACK_SLOW_RESOURCE", "||", "requestResult", "==", "OC_STACK_DUPLICATE_REQUEST", ")", "{", "if", "(", "rcvdPdu", "->", "hdr", "->", "type", "==", "COAP_MESSAGE_CON", ")", "{", "sendPdu", "=", "GenerateCoAPPdu", "(", "COAP_MESSAGE_ACK", ",", "0", ",", "rcvdPdu", "->", "hdr", "->", "id", ",", "NULL", ",", "NULL", ",", "NULL", ")", ";", "VERIFY_NON_NULL", "(", "sendPdu", ")", ";", "coap_show_pdu", "(", "sendPdu", ")", ";", "sendFlag", "=", "(", "coap_send_flags_t", ")", "(", "rcvdRequest", "->", "secure", "?", "SEND_SECURE_PORT", ":", "0", ")", ";", "if", "(", "SendCoAPPdu", "(", "gCoAPCtx", ",", "(", "coap_address_t", "*", ")", "&", "(", "rcvdRequest", "->", "remote", ")", ",", "sendPdu", ",", "sendFlag", ")", "!=", "OC_STACK_OK", ")", "{", "OC_LOG", "(", "DEBUG", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "}", "}", "else", "{", "goto", "exit", ";", "}", "}", "exit", ":", "return", ";", "}" ]
This function is called back by libcoap when a request is received
[ "This", "function", "is", "called", "back", "by", "libcoap", "when", "a", "request", "is", "received" ]
[ "// silence warnings", "//TODO: should the client be responding to requests?", "// fill OCCoAPToken structure", "// fill OCDevAddr", "// Retrieve Uri and Query from received coap pdu", "// No block1 received", "// TODO: should we send an error also when we receive a non-secured request to a secure resource?", "// TODO: should we consider some sort of error response", "// generate the pdu, if the request was CON, then the response is ACK, otherwire NON", "// generate the pdu, if the request was CON, then the response is ACK, otherwire NON" ]
[ { "param": "ctx", "type": "struct coap_context_t" }, { "param": "rcvdRequest", "type": "coap_queue_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "struct coap_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rcvdRequest", "type": "coap_queue_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
63aa982eba647c163fb56a1a46989b7c5ce458ff
mandeepshetty/iotivity
resource/csdk/occoap/src/occoap.c
[ "Apache-2.0" ]
C
OCInitCoAP
OCStackResult
OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode) { OCStackResult ret = OC_STACK_ERROR; TODO ("Below should go away and be replaced by OC_LOG"); coap_log_t log_level = (coap_log_t)(LOG_DEBUG + 1); OCDevAddr mcastAddr; uint8_t ipAddr[4] = { 0 }; uint16_t parsedPort = 0; OC_LOG(INFO, TAG, PCF("Entering OCInitCoAP")); coap_set_log_level(log_level); if (address) { if (!ParseIPv4Address((unsigned char *) address, ipAddr, &parsedPort)) { ret = OC_STACK_ERROR; goto exit; } OC_LOG_V(INFO, TAG, "Parsed IP Address %d.%d.%d.%d", ipAddr[0],ipAddr[1],ipAddr[2],ipAddr[3]); } gCoAPCtx = coap_new_context(ipAddr, port); VERIFY_NON_NULL(gCoAPCtx); // To allow presence notification work we need to init socket gCoAPCtx->sockfd_wellknown // for servers as well as clients OCBuildIPv4Address(COAP_WK_IPAddr_0, COAP_WK_IPAddr_1, COAP_WK_IPAddr_2, COAP_WK_IPAddr_3, COAP_DEFAULT_PORT, &mcastAddr); VERIFY_SUCCESS( coap_join_wellknown_group(gCoAPCtx, (coap_address_t* )&mcastAddr), 0); coap_register_request_handler(gCoAPCtx, HandleCoAPRequests); coap_register_response_handler(gCoAPCtx, HandleCoAPResponses); coap_register_ack_rst_handler(gCoAPCtx, HandleCoAPAckRst); ret = OC_STACK_OK; exit: if (ret != OC_STACK_OK) { OCStopCoAP(); } return ret; }
/** * Initialize the CoAP client or server with its IPv4 address and CoAP port * * @param ipAddr * IP Address of host device * @param port * Port of host device * @param mode * Host device is client, server, or client-server * * @return * 0 - success * TBD - TBD error */
Initialize the CoAP client or server with its IPv4 address and CoAP port @param ipAddr IP Address of host device @param port Port of host device @param mode Host device is client, server, or client-server @return 0 - success TBD - TBD error
[ "Initialize", "the", "CoAP", "client", "or", "server", "with", "its", "IPv4", "address", "and", "CoAP", "port", "@param", "ipAddr", "IP", "Address", "of", "host", "device", "@param", "port", "Port", "of", "host", "device", "@param", "mode", "Host", "device", "is", "client", "server", "or", "client", "-", "server", "@return", "0", "-", "success", "TBD", "-", "TBD", "error" ]
OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode) { OCStackResult ret = OC_STACK_ERROR; TODO ("Below should go away and be replaced by OC_LOG"); coap_log_t log_level = (coap_log_t)(LOG_DEBUG + 1); OCDevAddr mcastAddr; uint8_t ipAddr[4] = { 0 }; uint16_t parsedPort = 0; OC_LOG(INFO, TAG, PCF("Entering OCInitCoAP")); coap_set_log_level(log_level); if (address) { if (!ParseIPv4Address((unsigned char *) address, ipAddr, &parsedPort)) { ret = OC_STACK_ERROR; goto exit; } OC_LOG_V(INFO, TAG, "Parsed IP Address %d.%d.%d.%d", ipAddr[0],ipAddr[1],ipAddr[2],ipAddr[3]); } gCoAPCtx = coap_new_context(ipAddr, port); VERIFY_NON_NULL(gCoAPCtx); OCBuildIPv4Address(COAP_WK_IPAddr_0, COAP_WK_IPAddr_1, COAP_WK_IPAddr_2, COAP_WK_IPAddr_3, COAP_DEFAULT_PORT, &mcastAddr); VERIFY_SUCCESS( coap_join_wellknown_group(gCoAPCtx, (coap_address_t* )&mcastAddr), 0); coap_register_request_handler(gCoAPCtx, HandleCoAPRequests); coap_register_response_handler(gCoAPCtx, HandleCoAPResponses); coap_register_ack_rst_handler(gCoAPCtx, HandleCoAPAckRst); ret = OC_STACK_OK; exit: if (ret != OC_STACK_OK) { OCStopCoAP(); } return ret; }
[ "OCStackResult", "OCInitCoAP", "(", "const", "char", "*", "address", ",", "uint16_t", "port", ",", "OCMode", "mode", ")", "{", "OCStackResult", "ret", "=", "OC_STACK_ERROR", ";", "TODO", "(", "\"", "\"", ")", ";", "coap_log_t", "log_level", "=", "(", "coap_log_t", ")", "(", "LOG_DEBUG", "+", "1", ")", ";", "OCDevAddr", "mcastAddr", ";", "uint8_t", "ipAddr", "[", "4", "]", "=", "{", "0", "}", ";", "uint16_t", "parsedPort", "=", "0", ";", "OC_LOG", "(", "INFO", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "coap_set_log_level", "(", "log_level", ")", ";", "if", "(", "address", ")", "{", "if", "(", "!", "ParseIPv4Address", "(", "(", "unsigned", "char", "*", ")", "address", ",", "ipAddr", ",", "&", "parsedPort", ")", ")", "{", "ret", "=", "OC_STACK_ERROR", ";", "goto", "exit", ";", "}", "OC_LOG_V", "(", "INFO", ",", "TAG", ",", "\"", "\"", ",", "ipAddr", "[", "0", "]", ",", "ipAddr", "[", "1", "]", ",", "ipAddr", "[", "2", "]", ",", "ipAddr", "[", "3", "]", ")", ";", "}", "gCoAPCtx", "=", "coap_new_context", "(", "ipAddr", ",", "port", ")", ";", "VERIFY_NON_NULL", "(", "gCoAPCtx", ")", ";", "OCBuildIPv4Address", "(", "COAP_WK_IPAddr_0", ",", "COAP_WK_IPAddr_1", ",", "COAP_WK_IPAddr_2", ",", "COAP_WK_IPAddr_3", ",", "COAP_DEFAULT_PORT", ",", "&", "mcastAddr", ")", ";", "VERIFY_SUCCESS", "(", "coap_join_wellknown_group", "(", "gCoAPCtx", ",", "(", "coap_address_t", "*", ")", "&", "mcastAddr", ")", ",", "0", ")", ";", "coap_register_request_handler", "(", "gCoAPCtx", ",", "HandleCoAPRequests", ")", ";", "coap_register_response_handler", "(", "gCoAPCtx", ",", "HandleCoAPResponses", ")", ";", "coap_register_ack_rst_handler", "(", "gCoAPCtx", ",", "HandleCoAPAckRst", ")", ";", "ret", "=", "OC_STACK_OK", ";", "exit", ":", "if", "(", "ret", "!=", "OC_STACK_OK", ")", "{", "OCStopCoAP", "(", ")", ";", "}", "return", "ret", ";", "}" ]
Initialize the CoAP client or server with its IPv4 address and CoAP port @param ipAddr IP Address of host device @param port Port of host device @param mode Host device is client, server, or client-server
[ "Initialize", "the", "CoAP", "client", "or", "server", "with", "its", "IPv4", "address", "and", "CoAP", "port", "@param", "ipAddr", "IP", "Address", "of", "host", "device", "@param", "port", "Port", "of", "host", "device", "@param", "mode", "Host", "device", "is", "client", "server", "or", "client", "-", "server" ]
[ "// To allow presence notification work we need to init socket gCoAPCtx->sockfd_wellknown", "// for servers as well as clients" ]
[ { "param": "address", "type": "char" }, { "param": "port", "type": "uint16_t" }, { "param": "mode", "type": "OCMode" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "address", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "port", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mode", "type": "OCMode", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
63aa982eba647c163fb56a1a46989b7c5ce458ff
mandeepshetty/iotivity
resource/csdk/occoap/src/occoap.c
[ "Apache-2.0" ]
C
OCStopCoAP
OCStackResult
OCStackResult OCStopCoAP() { OC_LOG(INFO, TAG, PCF("Entering OCStopCoAP")); coap_free_context(gCoAPCtx); gCoAPCtx = NULL; return OC_STACK_OK; }
/** * Stop the CoAP client or server processing * * @return 0 - success, else - TBD error */
Stop the CoAP client or server processing @return 0 - success, else - TBD error
[ "Stop", "the", "CoAP", "client", "or", "server", "processing", "@return", "0", "-", "success", "else", "-", "TBD", "error" ]
OCStackResult OCStopCoAP() { OC_LOG(INFO, TAG, PCF("Entering OCStopCoAP")); coap_free_context(gCoAPCtx); gCoAPCtx = NULL; return OC_STACK_OK; }
[ "OCStackResult", "OCStopCoAP", "(", ")", "{", "OC_LOG", "(", "INFO", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "coap_free_context", "(", "gCoAPCtx", ")", ";", "gCoAPCtx", "=", "NULL", ";", "return", "OC_STACK_OK", ";", "}" ]
Stop the CoAP client or server processing @return 0 - success, else - TBD error
[ "Stop", "the", "CoAP", "client", "or", "server", "processing", "@return", "0", "-", "success", "else", "-", "TBD", "error" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
63aa982eba647c163fb56a1a46989b7c5ce458ff
mandeepshetty/iotivity
resource/csdk/occoap/src/occoap.c
[ "Apache-2.0" ]
C
OCGetResourceEndPointInfo
OCStackResult
OCStackResult OCGetResourceEndPointInfo (OCResource *resPtr, void *info) { OCStackResult result = OC_STACK_ERROR; int sfd; OC_LOG(INFO, TAG, PCF("Entering OCGetResourceEndPointInfo")); VERIFY_NON_NULL(resPtr); VERIFY_NON_NULL(info); sfd = (resPtr->resourceProperties & OC_SECURE) ? gCoAPCtx->sockfd_dtls : gCoAPCtx->sockfd; if (OCGetSocketInfo(sfd, (uint16_t*)info) == ERR_SUCCESS) result = OC_STACK_OK; exit: return result; }
/** * Retrieve the info about the end-point where resource is being hosted. * Currently, this method only provides the IP port with which the socket * is bound. * * @return 0 - success, else - TBD error */
Retrieve the info about the end-point where resource is being hosted. Currently, this method only provides the IP port with which the socket is bound. @return 0 - success, else - TBD error
[ "Retrieve", "the", "info", "about", "the", "end", "-", "point", "where", "resource", "is", "being", "hosted", ".", "Currently", "this", "method", "only", "provides", "the", "IP", "port", "with", "which", "the", "socket", "is", "bound", ".", "@return", "0", "-", "success", "else", "-", "TBD", "error" ]
OCStackResult OCGetResourceEndPointInfo (OCResource *resPtr, void *info) { OCStackResult result = OC_STACK_ERROR; int sfd; OC_LOG(INFO, TAG, PCF("Entering OCGetResourceEndPointInfo")); VERIFY_NON_NULL(resPtr); VERIFY_NON_NULL(info); sfd = (resPtr->resourceProperties & OC_SECURE) ? gCoAPCtx->sockfd_dtls : gCoAPCtx->sockfd; if (OCGetSocketInfo(sfd, (uint16_t*)info) == ERR_SUCCESS) result = OC_STACK_OK; exit: return result; }
[ "OCStackResult", "OCGetResourceEndPointInfo", "(", "OCResource", "*", "resPtr", ",", "void", "*", "info", ")", "{", "OCStackResult", "result", "=", "OC_STACK_ERROR", ";", "int", "sfd", ";", "OC_LOG", "(", "INFO", ",", "TAG", ",", "PCF", "(", "\"", "\"", ")", ")", ";", "VERIFY_NON_NULL", "(", "resPtr", ")", ";", "VERIFY_NON_NULL", "(", "info", ")", ";", "sfd", "=", "(", "resPtr", "->", "resourceProperties", "&", "OC_SECURE", ")", "?", "gCoAPCtx", "->", "sockfd_dtls", ":", "gCoAPCtx", "->", "sockfd", ";", "if", "(", "OCGetSocketInfo", "(", "sfd", ",", "(", "uint16_t", "*", ")", "info", ")", "==", "ERR_SUCCESS", ")", "result", "=", "OC_STACK_OK", ";", "exit", ":", "return", "result", ";", "}" ]
Retrieve the info about the end-point where resource is being hosted.
[ "Retrieve", "the", "info", "about", "the", "end", "-", "point", "where", "resource", "is", "being", "hosted", "." ]
[]
[ { "param": "resPtr", "type": "OCResource" }, { "param": "info", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "resPtr", "type": "OCResource", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "info", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
adb22ef79c94d4d0d18971124e46e3a528acbc90
R1yuu/void_utility
void_dict.h
[ "MIT" ]
C
vdict_hash
DICT_SIZE_TYPE
DICT_SIZE_TYPE vdict_hash(const struct void_dict* vdict, const void* key) { const unsigned char* data = (const unsigned char*)key; unsigned char byte; DICT_SIZE_TYPE hash = 5381; for (DICT_SIZE_TYPE i = 0; i < vdict->key_size; i++) { if ((byte = *(data + i))) { hash = ((hash << 5) + hash) ^ byte; } } return hash % vdict->hash_pool; }
/** * Generates Hash of key for given Void Dict * * @param vdict Void Dict to build hash for * @param key Key to build hash of * @return Hash in Hash-Pool */
Generates Hash of key for given Void Dict @param vdict Void Dict to build hash for @param key Key to build hash of @return Hash in Hash-Pool
[ "Generates", "Hash", "of", "key", "for", "given", "Void", "Dict", "@param", "vdict", "Void", "Dict", "to", "build", "hash", "for", "@param", "key", "Key", "to", "build", "hash", "of", "@return", "Hash", "in", "Hash", "-", "Pool" ]
DICT_SIZE_TYPE vdict_hash(const struct void_dict* vdict, const void* key) { const unsigned char* data = (const unsigned char*)key; unsigned char byte; DICT_SIZE_TYPE hash = 5381; for (DICT_SIZE_TYPE i = 0; i < vdict->key_size; i++) { if ((byte = *(data + i))) { hash = ((hash << 5) + hash) ^ byte; } } return hash % vdict->hash_pool; }
[ "DICT_SIZE_TYPE", "vdict_hash", "(", "const", "struct", "void_dict", "*", "vdict", ",", "const", "void", "*", "key", ")", "{", "const", "unsigned", "char", "*", "data", "=", "(", "const", "unsigned", "char", "*", ")", "key", ";", "unsigned", "char", "byte", ";", "DICT_SIZE_TYPE", "hash", "=", "5381", ";", "for", "(", "DICT_SIZE_TYPE", "i", "=", "0", ";", "i", "<", "vdict", "->", "key_size", ";", "i", "++", ")", "{", "if", "(", "(", "byte", "=", "*", "(", "data", "+", "i", ")", ")", ")", "{", "hash", "=", "(", "(", "hash", "<<", "5", ")", "+", "hash", ")", "^", "byte", ";", "}", "}", "return", "hash", "%", "vdict", "->", "hash_pool", ";", "}" ]
Generates Hash of key for given Void Dict
[ "Generates", "Hash", "of", "key", "for", "given", "Void", "Dict" ]
[]
[ { "param": "vdict", "type": "struct void_dict" }, { "param": "key", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vdict", "type": "struct void_dict", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "key", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
adb22ef79c94d4d0d18971124e46e3a528acbc90
R1yuu/void_utility
void_dict.h
[ "MIT" ]
C
vdict_hash_bsearch
DICT_SIZE_TYPE
DICT_SIZE_TYPE* vdict_hash_bsearch(const struct void_dict* vdict, const DICT_SIZE_TYPE hash, DICT_SIZE_TYPE* idx) { DICT_SIZE_TYPE* needle = NULL; DICT_SIZE_TYPE needle_idx = 0; if (vdict->size) { DICT_SIZE_TYPE f_idx = 0, l_idx = vdict->size - 1; while (f_idx <= l_idx) { needle_idx = (f_idx + l_idx) >> 1; if (vdict->hashes[needle_idx] < hash && needle_idx != 0) { f_idx = needle_idx + 1; } else if (vdict->hashes[needle_idx] > hash && needle_idx != 0) { l_idx = needle_idx - 1; } else { break; } } if (f_idx <= l_idx && vdict->hashes[needle_idx] == hash) { needle = vdict->hashes + needle_idx; } } if (idx != NULL) { *idx = needle_idx; } return needle; }
/** * Searches for given hash in hash-array of Void Dict * * @param vdict Void Dict in which to search for hash * @param hash Hash to be searched for * @param idx Index of found Hash or last searched index * @return Pointer to found hash or NULL */
Searches for given hash in hash-array of Void Dict @param vdict Void Dict in which to search for hash @param hash Hash to be searched for @param idx Index of found Hash or last searched index @return Pointer to found hash or NULL
[ "Searches", "for", "given", "hash", "in", "hash", "-", "array", "of", "Void", "Dict", "@param", "vdict", "Void", "Dict", "in", "which", "to", "search", "for", "hash", "@param", "hash", "Hash", "to", "be", "searched", "for", "@param", "idx", "Index", "of", "found", "Hash", "or", "last", "searched", "index", "@return", "Pointer", "to", "found", "hash", "or", "NULL" ]
DICT_SIZE_TYPE* vdict_hash_bsearch(const struct void_dict* vdict, const DICT_SIZE_TYPE hash, DICT_SIZE_TYPE* idx) { DICT_SIZE_TYPE* needle = NULL; DICT_SIZE_TYPE needle_idx = 0; if (vdict->size) { DICT_SIZE_TYPE f_idx = 0, l_idx = vdict->size - 1; while (f_idx <= l_idx) { needle_idx = (f_idx + l_idx) >> 1; if (vdict->hashes[needle_idx] < hash && needle_idx != 0) { f_idx = needle_idx + 1; } else if (vdict->hashes[needle_idx] > hash && needle_idx != 0) { l_idx = needle_idx - 1; } else { break; } } if (f_idx <= l_idx && vdict->hashes[needle_idx] == hash) { needle = vdict->hashes + needle_idx; } } if (idx != NULL) { *idx = needle_idx; } return needle; }
[ "DICT_SIZE_TYPE", "*", "vdict_hash_bsearch", "(", "const", "struct", "void_dict", "*", "vdict", ",", "const", "DICT_SIZE_TYPE", "hash", ",", "DICT_SIZE_TYPE", "*", "idx", ")", "{", "DICT_SIZE_TYPE", "*", "needle", "=", "NULL", ";", "DICT_SIZE_TYPE", "needle_idx", "=", "0", ";", "if", "(", "vdict", "->", "size", ")", "{", "DICT_SIZE_TYPE", "f_idx", "=", "0", ",", "l_idx", "=", "vdict", "->", "size", "-", "1", ";", "while", "(", "f_idx", "<=", "l_idx", ")", "{", "needle_idx", "=", "(", "f_idx", "+", "l_idx", ")", ">>", "1", ";", "if", "(", "vdict", "->", "hashes", "[", "needle_idx", "]", "<", "hash", "&&", "needle_idx", "!=", "0", ")", "{", "f_idx", "=", "needle_idx", "+", "1", ";", "}", "else", "if", "(", "vdict", "->", "hashes", "[", "needle_idx", "]", ">", "hash", "&&", "needle_idx", "!=", "0", ")", "{", "l_idx", "=", "needle_idx", "-", "1", ";", "}", "else", "{", "break", ";", "}", "}", "if", "(", "f_idx", "<=", "l_idx", "&&", "vdict", "->", "hashes", "[", "needle_idx", "]", "==", "hash", ")", "{", "needle", "=", "vdict", "->", "hashes", "+", "needle_idx", ";", "}", "}", "if", "(", "idx", "!=", "NULL", ")", "{", "*", "idx", "=", "needle_idx", ";", "}", "return", "needle", ";", "}" ]
Searches for given hash in hash-array of Void Dict
[ "Searches", "for", "given", "hash", "in", "hash", "-", "array", "of", "Void", "Dict" ]
[]
[ { "param": "vdict", "type": "struct void_dict" }, { "param": "hash", "type": "DICT_SIZE_TYPE" }, { "param": "idx", "type": "DICT_SIZE_TYPE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vdict", "type": "struct void_dict", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "hash", "type": "DICT_SIZE_TYPE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "idx", "type": "DICT_SIZE_TYPE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
adb22ef79c94d4d0d18971124e46e3a528acbc90
R1yuu/void_utility
void_dict.h
[ "MIT" ]
C
vdict_add_pair
int
int vdict_add_pair(struct void_dict* vdict, void* key, void* value) { if (vdict->size == vdict->hash_pool) { return VDICT_ERROR ^ VDICT_FULL; } else if (memcmp(key, vdict->key_zero_field, vdict->key_size) == 0) { return VDICT_ERROR ^ VDICT_ZERO_KEY; } DICT_SIZE_TYPE hash = vdict_hash(vdict, key); DICT_SIZE_TYPE needle_idx; while (vdict_hash_bsearch(vdict, hash, &needle_idx)) { hash = (hash + 1) % vdict->hash_pool; } memcpy(vdict->key_bytes + hash * vdict->key_size, key, vdict->key_size); memcpy(vdict->value_bytes + hash * vdict->value_size, value, vdict->value_size); if (vdict->size && vdict->hashes[needle_idx] < hash) needle_idx = (needle_idx + 1) % vdict->hash_pool; memmove(vdict->hashes + needle_idx + 1, vdict->hashes + needle_idx, sizeof(DICT_SIZE_TYPE) * (vdict->size - needle_idx)); vdict->hashes[needle_idx] = hash; vdict->size++; return VDICT_SUCCESS; }
/** * Adds given Key-Value Pair to Void Dict * * @param vdict Void Dict to add Key-Value Pair to * @param key Key to Add * @param value Value to Add * @return Error Code */
Adds given Key-Value Pair to Void Dict @param vdict Void Dict to add Key-Value Pair to @param key Key to Add @param value Value to Add @return Error Code
[ "Adds", "given", "Key", "-", "Value", "Pair", "to", "Void", "Dict", "@param", "vdict", "Void", "Dict", "to", "add", "Key", "-", "Value", "Pair", "to", "@param", "key", "Key", "to", "Add", "@param", "value", "Value", "to", "Add", "@return", "Error", "Code" ]
int vdict_add_pair(struct void_dict* vdict, void* key, void* value) { if (vdict->size == vdict->hash_pool) { return VDICT_ERROR ^ VDICT_FULL; } else if (memcmp(key, vdict->key_zero_field, vdict->key_size) == 0) { return VDICT_ERROR ^ VDICT_ZERO_KEY; } DICT_SIZE_TYPE hash = vdict_hash(vdict, key); DICT_SIZE_TYPE needle_idx; while (vdict_hash_bsearch(vdict, hash, &needle_idx)) { hash = (hash + 1) % vdict->hash_pool; } memcpy(vdict->key_bytes + hash * vdict->key_size, key, vdict->key_size); memcpy(vdict->value_bytes + hash * vdict->value_size, value, vdict->value_size); if (vdict->size && vdict->hashes[needle_idx] < hash) needle_idx = (needle_idx + 1) % vdict->hash_pool; memmove(vdict->hashes + needle_idx + 1, vdict->hashes + needle_idx, sizeof(DICT_SIZE_TYPE) * (vdict->size - needle_idx)); vdict->hashes[needle_idx] = hash; vdict->size++; return VDICT_SUCCESS; }
[ "int", "vdict_add_pair", "(", "struct", "void_dict", "*", "vdict", ",", "void", "*", "key", ",", "void", "*", "value", ")", "{", "if", "(", "vdict", "->", "size", "==", "vdict", "->", "hash_pool", ")", "{", "return", "VDICT_ERROR", "^", "VDICT_FULL", ";", "}", "else", "if", "(", "memcmp", "(", "key", ",", "vdict", "->", "key_zero_field", ",", "vdict", "->", "key_size", ")", "==", "0", ")", "{", "return", "VDICT_ERROR", "^", "VDICT_ZERO_KEY", ";", "}", "DICT_SIZE_TYPE", "hash", "=", "vdict_hash", "(", "vdict", ",", "key", ")", ";", "DICT_SIZE_TYPE", "needle_idx", ";", "while", "(", "vdict_hash_bsearch", "(", "vdict", ",", "hash", ",", "&", "needle_idx", ")", ")", "{", "hash", "=", "(", "hash", "+", "1", ")", "%", "vdict", "->", "hash_pool", ";", "}", "memcpy", "(", "vdict", "->", "key_bytes", "+", "hash", "*", "vdict", "->", "key_size", ",", "key", ",", "vdict", "->", "key_size", ")", ";", "memcpy", "(", "vdict", "->", "value_bytes", "+", "hash", "*", "vdict", "->", "value_size", ",", "value", ",", "vdict", "->", "value_size", ")", ";", "if", "(", "vdict", "->", "size", "&&", "vdict", "->", "hashes", "[", "needle_idx", "]", "<", "hash", ")", "needle_idx", "=", "(", "needle_idx", "+", "1", ")", "%", "vdict", "->", "hash_pool", ";", "memmove", "(", "vdict", "->", "hashes", "+", "needle_idx", "+", "1", ",", "vdict", "->", "hashes", "+", "needle_idx", ",", "sizeof", "(", "DICT_SIZE_TYPE", ")", "*", "(", "vdict", "->", "size", "-", "needle_idx", ")", ")", ";", "vdict", "->", "hashes", "[", "needle_idx", "]", "=", "hash", ";", "vdict", "->", "size", "++", ";", "return", "VDICT_SUCCESS", ";", "}" ]
Adds given Key-Value Pair to Void Dict
[ "Adds", "given", "Key", "-", "Value", "Pair", "to", "Void", "Dict" ]
[]
[ { "param": "vdict", "type": "struct void_dict" }, { "param": "key", "type": "void" }, { "param": "value", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vdict", "type": "struct void_dict", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "key", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "value", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
adb22ef79c94d4d0d18971124e46e3a528acbc90
R1yuu/void_utility
void_dict.h
[ "MIT" ]
C
vdict_get_value
void
void* vdict_get_value(const struct void_dict* vdict, const void* key) { DICT_SIZE_TYPE hash = vdict_hash(vdict, key); if (vdict->size && vdict_hash_bsearch(vdict, hash, NULL)) { unsigned char found = 0; DICT_SIZE_TYPE checked = 0; while (!found && checked < vdict->size) { if (memcmp(vdict->key_bytes + vdict->key_size * hash, vdict->key_zero_field, vdict->key_size) == 0) { break; } else if (memcmp(vdict->key_bytes + vdict->key_size * hash, key, vdict->key_size) == 0) { found = 1; break; } else { hash = (hash + 1) % vdict->hash_pool; checked++; } } if (found) { return vdict->value_bytes + vdict->value_size * hash; } } return NULL; }
/** * Returns Pointer to Value of given Key * * @param vdict Void Dict to get Value from * @param key Key to get Value with * @return Pointer to Value (NULL if idx out of range) */
Returns Pointer to Value of given Key @param vdict Void Dict to get Value from @param key Key to get Value with @return Pointer to Value (NULL if idx out of range)
[ "Returns", "Pointer", "to", "Value", "of", "given", "Key", "@param", "vdict", "Void", "Dict", "to", "get", "Value", "from", "@param", "key", "Key", "to", "get", "Value", "with", "@return", "Pointer", "to", "Value", "(", "NULL", "if", "idx", "out", "of", "range", ")" ]
void* vdict_get_value(const struct void_dict* vdict, const void* key) { DICT_SIZE_TYPE hash = vdict_hash(vdict, key); if (vdict->size && vdict_hash_bsearch(vdict, hash, NULL)) { unsigned char found = 0; DICT_SIZE_TYPE checked = 0; while (!found && checked < vdict->size) { if (memcmp(vdict->key_bytes + vdict->key_size * hash, vdict->key_zero_field, vdict->key_size) == 0) { break; } else if (memcmp(vdict->key_bytes + vdict->key_size * hash, key, vdict->key_size) == 0) { found = 1; break; } else { hash = (hash + 1) % vdict->hash_pool; checked++; } } if (found) { return vdict->value_bytes + vdict->value_size * hash; } } return NULL; }
[ "void", "*", "vdict_get_value", "(", "const", "struct", "void_dict", "*", "vdict", ",", "const", "void", "*", "key", ")", "{", "DICT_SIZE_TYPE", "hash", "=", "vdict_hash", "(", "vdict", ",", "key", ")", ";", "if", "(", "vdict", "->", "size", "&&", "vdict_hash_bsearch", "(", "vdict", ",", "hash", ",", "NULL", ")", ")", "{", "unsigned", "char", "found", "=", "0", ";", "DICT_SIZE_TYPE", "checked", "=", "0", ";", "while", "(", "!", "found", "&&", "checked", "<", "vdict", "->", "size", ")", "{", "if", "(", "memcmp", "(", "vdict", "->", "key_bytes", "+", "vdict", "->", "key_size", "*", "hash", ",", "vdict", "->", "key_zero_field", ",", "vdict", "->", "key_size", ")", "==", "0", ")", "{", "break", ";", "}", "else", "if", "(", "memcmp", "(", "vdict", "->", "key_bytes", "+", "vdict", "->", "key_size", "*", "hash", ",", "key", ",", "vdict", "->", "key_size", ")", "==", "0", ")", "{", "found", "=", "1", ";", "break", ";", "}", "else", "{", "hash", "=", "(", "hash", "+", "1", ")", "%", "vdict", "->", "hash_pool", ";", "checked", "++", ";", "}", "}", "if", "(", "found", ")", "{", "return", "vdict", "->", "value_bytes", "+", "vdict", "->", "value_size", "*", "hash", ";", "}", "}", "return", "NULL", ";", "}" ]
Returns Pointer to Value of given Key
[ "Returns", "Pointer", "to", "Value", "of", "given", "Key" ]
[]
[ { "param": "vdict", "type": "struct void_dict" }, { "param": "key", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vdict", "type": "struct void_dict", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "key", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
adb22ef79c94d4d0d18971124e46e3a528acbc90
R1yuu/void_utility
void_dict.h
[ "MIT" ]
C
vdict_get_keys
void
void* vdict_get_keys(const struct void_dict* vdict, void* key_array) { unsigned char* byte_key_array = (unsigned char*)key_array; for (DICT_SIZE_TYPE i = 0; i < vdict->size; i++) { memcpy(byte_key_array + (vdict->key_size * i), vdict->key_bytes + (vdict->key_size * vdict->hashes[i]), vdict->key_size); } return key_array; }
/** * Stores all keys into given array * * @param vdict Void Dict to get the keys of * @param key_array Array to store keys into * @return key_array */
Stores all keys into given array @param vdict Void Dict to get the keys of @param key_array Array to store keys into @return key_array
[ "Stores", "all", "keys", "into", "given", "array", "@param", "vdict", "Void", "Dict", "to", "get", "the", "keys", "of", "@param", "key_array", "Array", "to", "store", "keys", "into", "@return", "key_array" ]
void* vdict_get_keys(const struct void_dict* vdict, void* key_array) { unsigned char* byte_key_array = (unsigned char*)key_array; for (DICT_SIZE_TYPE i = 0; i < vdict->size; i++) { memcpy(byte_key_array + (vdict->key_size * i), vdict->key_bytes + (vdict->key_size * vdict->hashes[i]), vdict->key_size); } return key_array; }
[ "void", "*", "vdict_get_keys", "(", "const", "struct", "void_dict", "*", "vdict", ",", "void", "*", "key_array", ")", "{", "unsigned", "char", "*", "byte_key_array", "=", "(", "unsigned", "char", "*", ")", "key_array", ";", "for", "(", "DICT_SIZE_TYPE", "i", "=", "0", ";", "i", "<", "vdict", "->", "size", ";", "i", "++", ")", "{", "memcpy", "(", "byte_key_array", "+", "(", "vdict", "->", "key_size", "*", "i", ")", ",", "vdict", "->", "key_bytes", "+", "(", "vdict", "->", "key_size", "*", "vdict", "->", "hashes", "[", "i", "]", ")", ",", "vdict", "->", "key_size", ")", ";", "}", "return", "key_array", ";", "}" ]
Stores all keys into given array
[ "Stores", "all", "keys", "into", "given", "array" ]
[]
[ { "param": "vdict", "type": "struct void_dict" }, { "param": "key_array", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vdict", "type": "struct void_dict", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "key_array", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }