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
c4cbe25ff3b6baefacf15569646d2c285c3aa4d7
Steel46/shadow
src/main/routing/shd-topology.c
[ "BSD-3-Clause" ]
C
_topology_findGraphAttributeString
gboolean
static gboolean _topology_findGraphAttributeString(Topology* top, GraphAttribute attr, const gchar** valueOut) { MAGIC_ASSERT(top); const gchar* name = _topology_graphAttributeToString(attr); if(igraph_cattribute_has_attr(&top->graph, IGRAPH_ATTRIBUTE_GRAPH, name)) { const gchar* value = igraph_cattribute_GAS(&top->graph, name); if(value != NULL && value[0] != '\0') { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
/* the graph lock should be held when calling this function, since it accesses igraph. * if the value is found and not NULL, it's value is returned in valueOut. * returns true if valueOut has been set, false otherwise */
the graph lock should be held when calling this function, since it accesses igraph. if the value is found and not NULL, it's value is returned in valueOut. returns true if valueOut has been set, false otherwise
[ "the", "graph", "lock", "should", "be", "held", "when", "calling", "this", "function", "since", "it", "accesses", "igraph", ".", "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", ".", "returns", "true", "if", "valueOut", "has", "been", "set", "false", "otherwise" ]
static gboolean _topology_findGraphAttributeString(Topology* top, GraphAttribute attr, const gchar** valueOut) { MAGIC_ASSERT(top); const gchar* name = _topology_graphAttributeToString(attr); if(igraph_cattribute_has_attr(&top->graph, IGRAPH_ATTRIBUTE_GRAPH, name)) { const gchar* value = igraph_cattribute_GAS(&top->graph, name); if(value != NULL && value[0] != '\0') { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
[ "static", "gboolean", "_topology_findGraphAttributeString", "(", "Topology", "*", "top", ",", "GraphAttribute", "attr", ",", "const", "gchar", "*", "*", "valueOut", ")", "{", "MAGIC_ASSERT", "(", "top", ")", ";", "const", "gchar", "*", "name", "=", "_topology_graphAttributeToString", "(", "attr", ")", ";", "if", "(", "igraph_cattribute_has_attr", "(", "&", "top", "->", "graph", ",", "IGRAPH_ATTRIBUTE_GRAPH", ",", "name", ")", ")", "{", "const", "gchar", "*", "value", "=", "igraph_cattribute_GAS", "(", "&", "top", "->", "graph", ",", "name", ")", ";", "if", "(", "value", "!=", "NULL", "&&", "value", "[", "0", "]", "!=", "'", "\\0", "'", ")", "{", "if", "(", "valueOut", "!=", "NULL", ")", "{", "*", "valueOut", "=", "value", ";", "return", "TRUE", ";", "}", "}", "}", "return", "FALSE", ";", "}" ]
the graph lock should be held when calling this function, since it accesses igraph.
[ "the", "graph", "lock", "should", "be", "held", "when", "calling", "this", "function", "since", "it", "accesses", "igraph", "." ]
[]
[ { "param": "top", "type": "Topology" }, { "param": "attr", "type": "GraphAttribute" }, { "param": "valueOut", "type": "gchar" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "top", "type": "Topology", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "attr", "type": "GraphAttribute", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "valueOut", "type": "gchar", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c4cbe25ff3b6baefacf15569646d2c285c3aa4d7
Steel46/shadow
src/main/routing/shd-topology.c
[ "BSD-3-Clause" ]
C
_topology_findVertexAttributeDouble
gboolean
static gboolean _topology_findVertexAttributeDouble(Topology* top, igraph_integer_t vertexIndex, VertexAttribute attr, gdouble* valueOut) { MAGIC_ASSERT(top); const gchar* name = _topology_vertexAttributeToString(attr); if(igraph_cattribute_has_attr(&top->graph, IGRAPH_ATTRIBUTE_VERTEX, name)) { gdouble value = (gdouble) igraph_cattribute_VAN(&top->graph, name, vertexIndex); if(isnan(value) == 0) { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
/* the graph lock should be held when calling this function, since it accesses igraph. * if the value is found and not NULL, it's value is returned in valueOut. * returns true if valueOut has been set, false otherwise */
the graph lock should be held when calling this function, since it accesses igraph. if the value is found and not NULL, it's value is returned in valueOut. returns true if valueOut has been set, false otherwise
[ "the", "graph", "lock", "should", "be", "held", "when", "calling", "this", "function", "since", "it", "accesses", "igraph", ".", "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", ".", "returns", "true", "if", "valueOut", "has", "been", "set", "false", "otherwise" ]
static gboolean _topology_findVertexAttributeDouble(Topology* top, igraph_integer_t vertexIndex, VertexAttribute attr, gdouble* valueOut) { MAGIC_ASSERT(top); const gchar* name = _topology_vertexAttributeToString(attr); if(igraph_cattribute_has_attr(&top->graph, IGRAPH_ATTRIBUTE_VERTEX, name)) { gdouble value = (gdouble) igraph_cattribute_VAN(&top->graph, name, vertexIndex); if(isnan(value) == 0) { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
[ "static", "gboolean", "_topology_findVertexAttributeDouble", "(", "Topology", "*", "top", ",", "igraph_integer_t", "vertexIndex", ",", "VertexAttribute", "attr", ",", "gdouble", "*", "valueOut", ")", "{", "MAGIC_ASSERT", "(", "top", ")", ";", "const", "gchar", "*", "name", "=", "_topology_vertexAttributeToString", "(", "attr", ")", ";", "if", "(", "igraph_cattribute_has_attr", "(", "&", "top", "->", "graph", ",", "IGRAPH_ATTRIBUTE_VERTEX", ",", "name", ")", ")", "{", "gdouble", "value", "=", "(", "gdouble", ")", "igraph_cattribute_VAN", "(", "&", "top", "->", "graph", ",", "name", ",", "vertexIndex", ")", ";", "if", "(", "isnan", "(", "value", ")", "==", "0", ")", "{", "if", "(", "valueOut", "!=", "NULL", ")", "{", "*", "valueOut", "=", "value", ";", "return", "TRUE", ";", "}", "}", "}", "return", "FALSE", ";", "}" ]
the graph lock should be held when calling this function, since it accesses igraph.
[ "the", "graph", "lock", "should", "be", "held", "when", "calling", "this", "function", "since", "it", "accesses", "igraph", "." ]
[]
[ { "param": "top", "type": "Topology" }, { "param": "vertexIndex", "type": "igraph_integer_t" }, { "param": "attr", "type": "VertexAttribute" }, { "param": "valueOut", "type": "gdouble" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "top", "type": "Topology", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vertexIndex", "type": "igraph_integer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "attr", "type": "VertexAttribute", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "valueOut", "type": "gdouble", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c4cbe25ff3b6baefacf15569646d2c285c3aa4d7
Steel46/shadow
src/main/routing/shd-topology.c
[ "BSD-3-Clause" ]
C
_topology_isComplete
gboolean
static gboolean _topology_isComplete(Topology* top, gboolean *result) { MAGIC_ASSERT(top); g_assert(result); igraph_t *graph = &top->graph; igraph_vs_t vs; igraph_vit_t vit; int ret = 0; igraph_integer_t vcount = igraph_vcount(graph); igraph_bool_t is_directed = igraph_is_directed(&top->graph); gboolean is_success = FALSE; gboolean is_complete = FALSE; /* * Determines if a graph is complete by: * - knowning how many vertexes there are * - for each vertex, count the indcident edges * - if less than the number of vertexes, it isn't a complete graph * - otherwise the graph is complete * * Notice: In order to be considered complete, every vertex must have an * edge beginning and ending at itself too. */ /* vert selector. We wall all verts */ ret = igraph_vs_all(&vs); if (ret != IGRAPH_SUCCESS) { critical("igraph_vs_all returned non-success code %i", ret); is_success = FALSE; goto done; } ret = igraph_vit_create(graph, vs, &vit); if (ret != IGRAPH_SUCCESS) { critical("igraph_vit_create returned non-success code %i", ret); is_success = FALSE; goto done; } while (!IGRAPH_VIT_END(vit)) { igraph_integer_t vertexID = 0; vertexID = IGRAPH_VIT_GET(vit); igraph_vector_t iedges; igraph_vector_init(&iedges, 0); ret = igraph_incident(graph, &iedges, vertexID, IGRAPH_OUT); if (ret != IGRAPH_SUCCESS) { critical("error computing igraph_incident\n"); is_success = FALSE; igraph_vector_destroy(&iedges); goto done; } igraph_integer_t ecount = igraph_vector_size(&iedges); /* If the graph is undirected and there is a self-loop edge (an edge * that begins and ends at the same vertex) on this vertex, then igraph * will have double counted it and we need to correct that. */ if (!is_directed) { igraph_integer_t edge_id = 0; gint result = _topology_getEdgeHelper(top, vertexID, vertexID, &edge_id, NULL, NULL); /* If the edge does not exist, then -1 will be stored in edge_id. * If it is found, then it will be >= 0 */ if (result == IGRAPH_SUCCESS && edge_id >= 0) { debug("Subtracting one from vert id=%li's edge count because " "this is an undirected graph and this vertex's " "self-looping edge has been counted twice", (long int)vertexID); ecount -= 1; } } if (ecount < vcount) { info("Vert id=%li has %li incident edges to %li total verts " "and thus this isn't a complete graph", (long int)vertexID, (long int)ecount, (long int)vcount); is_success = TRUE; is_complete = FALSE; igraph_vector_destroy(&iedges); goto done; } else { debug("Vert id=%li has %li incident edges to %li total verts " "and thus doesn't determine whether this graph is incomplete. " "Must keep searching.", (long int)vertexID, (long int)ecount, (long int)vcount); } igraph_vector_destroy(&iedges); IGRAPH_VIT_NEXT(vit); } info("Determined this graph is complete."); is_complete = TRUE; is_success = TRUE; done: igraph_vs_destroy(&vs); igraph_vit_destroy(&vit); *result = is_complete; return is_success; }
/** Returns FALSE if issue parsing graph, otherwise returns TRUE. * If returning FALSE, consider result to be undefined. * If returning TRUE, whether or not the graph is complete is stored in result. */
Returns FALSE if issue parsing graph, otherwise returns TRUE. If returning FALSE, consider result to be undefined. If returning TRUE, whether or not the graph is complete is stored in result.
[ "Returns", "FALSE", "if", "issue", "parsing", "graph", "otherwise", "returns", "TRUE", ".", "If", "returning", "FALSE", "consider", "result", "to", "be", "undefined", ".", "If", "returning", "TRUE", "whether", "or", "not", "the", "graph", "is", "complete", "is", "stored", "in", "result", "." ]
static gboolean _topology_isComplete(Topology* top, gboolean *result) { MAGIC_ASSERT(top); g_assert(result); igraph_t *graph = &top->graph; igraph_vs_t vs; igraph_vit_t vit; int ret = 0; igraph_integer_t vcount = igraph_vcount(graph); igraph_bool_t is_directed = igraph_is_directed(&top->graph); gboolean is_success = FALSE; gboolean is_complete = FALSE; ret = igraph_vs_all(&vs); if (ret != IGRAPH_SUCCESS) { critical("igraph_vs_all returned non-success code %i", ret); is_success = FALSE; goto done; } ret = igraph_vit_create(graph, vs, &vit); if (ret != IGRAPH_SUCCESS) { critical("igraph_vit_create returned non-success code %i", ret); is_success = FALSE; goto done; } while (!IGRAPH_VIT_END(vit)) { igraph_integer_t vertexID = 0; vertexID = IGRAPH_VIT_GET(vit); igraph_vector_t iedges; igraph_vector_init(&iedges, 0); ret = igraph_incident(graph, &iedges, vertexID, IGRAPH_OUT); if (ret != IGRAPH_SUCCESS) { critical("error computing igraph_incident\n"); is_success = FALSE; igraph_vector_destroy(&iedges); goto done; } igraph_integer_t ecount = igraph_vector_size(&iedges); if (!is_directed) { igraph_integer_t edge_id = 0; gint result = _topology_getEdgeHelper(top, vertexID, vertexID, &edge_id, NULL, NULL); if (result == IGRAPH_SUCCESS && edge_id >= 0) { debug("Subtracting one from vert id=%li's edge count because " "this is an undirected graph and this vertex's " "self-looping edge has been counted twice", (long int)vertexID); ecount -= 1; } } if (ecount < vcount) { info("Vert id=%li has %li incident edges to %li total verts " "and thus this isn't a complete graph", (long int)vertexID, (long int)ecount, (long int)vcount); is_success = TRUE; is_complete = FALSE; igraph_vector_destroy(&iedges); goto done; } else { debug("Vert id=%li has %li incident edges to %li total verts " "and thus doesn't determine whether this graph is incomplete. " "Must keep searching.", (long int)vertexID, (long int)ecount, (long int)vcount); } igraph_vector_destroy(&iedges); IGRAPH_VIT_NEXT(vit); } info("Determined this graph is complete."); is_complete = TRUE; is_success = TRUE; done: igraph_vs_destroy(&vs); igraph_vit_destroy(&vit); *result = is_complete; return is_success; }
[ "static", "gboolean", "_topology_isComplete", "(", "Topology", "*", "top", ",", "gboolean", "*", "result", ")", "{", "MAGIC_ASSERT", "(", "top", ")", ";", "g_assert", "(", "result", ")", ";", "igraph_t", "*", "graph", "=", "&", "top", "->", "graph", ";", "igraph_vs_t", "vs", ";", "igraph_vit_t", "vit", ";", "int", "ret", "=", "0", ";", "igraph_integer_t", "vcount", "=", "igraph_vcount", "(", "graph", ")", ";", "igraph_bool_t", "is_directed", "=", "igraph_is_directed", "(", "&", "top", "->", "graph", ")", ";", "gboolean", "is_success", "=", "FALSE", ";", "gboolean", "is_complete", "=", "FALSE", ";", "ret", "=", "igraph_vs_all", "(", "&", "vs", ")", ";", "if", "(", "ret", "!=", "IGRAPH_SUCCESS", ")", "{", "critical", "(", "\"", "\"", ",", "ret", ")", ";", "is_success", "=", "FALSE", ";", "goto", "done", ";", "}", "ret", "=", "igraph_vit_create", "(", "graph", ",", "vs", ",", "&", "vit", ")", ";", "if", "(", "ret", "!=", "IGRAPH_SUCCESS", ")", "{", "critical", "(", "\"", "\"", ",", "ret", ")", ";", "is_success", "=", "FALSE", ";", "goto", "done", ";", "}", "while", "(", "!", "IGRAPH_VIT_END", "(", "vit", ")", ")", "{", "igraph_integer_t", "vertexID", "=", "0", ";", "vertexID", "=", "IGRAPH_VIT_GET", "(", "vit", ")", ";", "igraph_vector_t", "iedges", ";", "igraph_vector_init", "(", "&", "iedges", ",", "0", ")", ";", "ret", "=", "igraph_incident", "(", "graph", ",", "&", "iedges", ",", "vertexID", ",", "IGRAPH_OUT", ")", ";", "if", "(", "ret", "!=", "IGRAPH_SUCCESS", ")", "{", "critical", "(", "\"", "\\n", "\"", ")", ";", "is_success", "=", "FALSE", ";", "igraph_vector_destroy", "(", "&", "iedges", ")", ";", "goto", "done", ";", "}", "igraph_integer_t", "ecount", "=", "igraph_vector_size", "(", "&", "iedges", ")", ";", "if", "(", "!", "is_directed", ")", "{", "igraph_integer_t", "edge_id", "=", "0", ";", "gint", "result", "=", "_topology_getEdgeHelper", "(", "top", ",", "vertexID", ",", "vertexID", ",", "&", "edge_id", ",", "NULL", ",", "NULL", ")", ";", "if", "(", "result", "==", "IGRAPH_SUCCESS", "&&", "edge_id", ">=", "0", ")", "{", "debug", "(", "\"", "\"", "\"", "\"", "\"", "\"", ",", "(", "long", "int", ")", "vertexID", ")", ";", "ecount", "-=", "1", ";", "}", "}", "if", "(", "ecount", "<", "vcount", ")", "{", "info", "(", "\"", "\"", "\"", "\"", ",", "(", "long", "int", ")", "vertexID", ",", "(", "long", "int", ")", "ecount", ",", "(", "long", "int", ")", "vcount", ")", ";", "is_success", "=", "TRUE", ";", "is_complete", "=", "FALSE", ";", "igraph_vector_destroy", "(", "&", "iedges", ")", ";", "goto", "done", ";", "}", "else", "{", "debug", "(", "\"", "\"", "\"", "\"", "\"", "\"", ",", "(", "long", "int", ")", "vertexID", ",", "(", "long", "int", ")", "ecount", ",", "(", "long", "int", ")", "vcount", ")", ";", "}", "igraph_vector_destroy", "(", "&", "iedges", ")", ";", "IGRAPH_VIT_NEXT", "(", "vit", ")", ";", "}", "info", "(", "\"", "\"", ")", ";", "is_complete", "=", "TRUE", ";", "is_success", "=", "TRUE", ";", "done", ":", "igraph_vs_destroy", "(", "&", "vs", ")", ";", "igraph_vit_destroy", "(", "&", "vit", ")", ";", "*", "result", "=", "is_complete", ";", "return", "is_success", ";", "}" ]
Returns FALSE if issue parsing graph, otherwise returns TRUE.
[ "Returns", "FALSE", "if", "issue", "parsing", "graph", "otherwise", "returns", "TRUE", "." ]
[ "/*\n * Determines if a graph is complete by:\n * - knowning how many vertexes there are\n * - for each vertex, count the indcident edges\n * - if less than the number of vertexes, it isn't a complete graph\n * - otherwise the graph is complete\n *\n * Notice: In order to be considered complete, every vertex must have an\n * edge beginning and ending at itself too.\n */", "/* vert selector. We wall all verts */", "/* If the graph is undirected and there is a self-loop edge (an edge\n * that begins and ends at the same vertex) on this vertex, then igraph\n * will have double counted it and we need to correct that. */", "/* If the edge does not exist, then -1 will be stored in edge_id.\n * If it is found, then it will be >= 0 */" ]
[ { "param": "top", "type": "Topology" }, { "param": "result", "type": "gboolean" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "top", "type": "Topology", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "result", "type": "gboolean", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8ec2ff1e2872fb40c10a24d67b21005efac9af4b
Ismael-VC/latino-nuevo
src/latino.c
[ "MIT" ]
C
lat_ayuda
void
void lat_ayuda(){ lat_logo(); lat_version(); printf("%s\n", "Uso de latino: latino [opcion] [archivo]"); printf("\n"); printf("%s\n", "Opciones:"); printf("%s\n", "-a : Muestra la ayuda de Latino"); printf("%s\n", "-i : Inicia el interprete de Latino (Modo interactivo)"); printf("%s\n", "-v : Muestra la version de Latino"); printf("%s\n", "archivo : Nombre del archivo con extension .lat"); printf("%s\n", "Ctrl-C : Para cerrar"); printf("\n"); printf("%s\n", "Variables de entorno:"); printf("%s\n", "_____________________"); printf("%s%s\n", "LATINO_PATH : ", getenv("LATINO_PATH")); printf("%s%s\n", "LATINO_LIB : ", getenv("LATINO_LIB")); printf("%s%s\n", "LC_LANG : ", getenv("LC_LANG")); printf("%s%s\n", "HOME : ", getenv("HOME")); }
/** * Muestra la ayuda en la consola */
Muestra la ayuda en la consola
[ "Muestra", "la", "ayuda", "en", "la", "consola" ]
void lat_ayuda(){ lat_logo(); lat_version(); printf("%s\n", "Uso de latino: latino [opcion] [archivo]"); printf("\n"); printf("%s\n", "Opciones:"); printf("%s\n", "-a : Muestra la ayuda de Latino"); printf("%s\n", "-i : Inicia el interprete de Latino (Modo interactivo)"); printf("%s\n", "-v : Muestra la version de Latino"); printf("%s\n", "archivo : Nombre del archivo con extension .lat"); printf("%s\n", "Ctrl-C : Para cerrar"); printf("\n"); printf("%s\n", "Variables de entorno:"); printf("%s\n", "_____________________"); printf("%s%s\n", "LATINO_PATH : ", getenv("LATINO_PATH")); printf("%s%s\n", "LATINO_LIB : ", getenv("LATINO_LIB")); printf("%s%s\n", "LC_LANG : ", getenv("LC_LANG")); printf("%s%s\n", "HOME : ", getenv("HOME")); }
[ "void", "lat_ayuda", "(", ")", "{", "lat_logo", "(", ")", ";", "lat_version", "(", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ",", "getenv", "(", "\"", "\"", ")", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ",", "getenv", "(", "\"", "\"", ")", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ",", "getenv", "(", "\"", "\"", ")", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ",", "getenv", "(", "\"", "\"", ")", ")", ";", "}" ]
Muestra la ayuda en la consola
[ "Muestra", "la", "ayuda", "en", "la", "consola" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
375a293e1eb57cb0bbcef3ebe6598779fc4b8244
Ismael-VC/latino-nuevo
src/lex.c
[ "MIT" ]
C
yy_get_previous_state
yy_state_type
static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { register yy_state_type yy_current_state; register char *yy_cp; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yy_current_state = yyg->yy_start; for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 148 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; } return yy_current_state; }
/* yy_get_previous_state - get the state just before the EOB char was reached */
get the state just before the EOB char was reached
[ "get", "the", "state", "just", "before", "the", "EOB", "char", "was", "reached" ]
static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { register yy_state_type yy_current_state; register char *yy_cp; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yy_current_state = yyg->yy_start; for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 148 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; } return yy_current_state; }
[ "static", "yy_state_type", "yy_get_previous_state", "(", "yyscan_t", "yyscanner", ")", "{", "register", "yy_state_type", "yy_current_state", ";", "register", "char", "*", "yy_cp", ";", "struct", "yyguts_t", "*", "yyg", "=", "(", "struct", "yyguts_t", "*", ")", "yyscanner", ";", "yy_current_state", "=", "yyg", "->", "yy_start", ";", "for", "(", "yy_cp", "=", "yyg", "->", "yytext_ptr", "+", "YY_MORE_ADJ", ";", "yy_cp", "<", "yyg", "->", "yy_c_buf_p", ";", "++", "yy_cp", ")", "{", "register", "YY_CHAR", "yy_c", "=", "(", "*", "yy_cp", "?", "yy_ec", "[", "YY_SC_TO_UI", "(", "*", "yy_cp", ")", "]", ":", "1", ")", ";", "if", "(", "yy_accept", "[", "yy_current_state", "]", ")", "{", "yyg", "->", "yy_last_accepting_state", "=", "yy_current_state", ";", "yyg", "->", "yy_last_accepting_cpos", "=", "yy_cp", ";", "}", "while", "(", "yy_chk", "[", "yy_base", "[", "yy_current_state", "]", "+", "yy_c", "]", "!=", "yy_current_state", ")", "{", "yy_current_state", "=", "(", "int", ")", "yy_def", "[", "yy_current_state", "]", ";", "if", "(", "yy_current_state", ">=", "148", ")", "yy_c", "=", "yy_meta", "[", "(", "unsigned", "int", ")", "yy_c", "]", ";", "}", "yy_current_state", "=", "yy_nxt", "[", "yy_base", "[", "yy_current_state", "]", "+", "(", "unsigned", "int", ")", "yy_c", "]", ";", "}", "return", "yy_current_state", ";", "}" ]
yy_get_previous_state - get the state just before the EOB char was reached
[ "yy_get_previous_state", "-", "get", "the", "state", "just", "before", "the", "EOB", "char", "was", "reached" ]
[]
[ { "param": "yyscanner", "type": "yyscan_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "yyscanner", "type": "yyscan_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
375a293e1eb57cb0bbcef3ebe6598779fc4b8244
Ismael-VC/latino-nuevo
src/lex.c
[ "MIT" ]
C
yy_create_buffer
YY_BUFFER_STATE
YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ,yyscanner ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; yy_init_buffer(b,file ,yyscanner); return b; }
/** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. * @param yyscanner The scanner object. * @return the allocated buffer state. */
Allocate and initialize an input buffer state. @param file A readable stream. @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. @param yyscanner The scanner object. @return the allocated buffer state.
[ "Allocate", "and", "initialize", "an", "input", "buffer", "state", ".", "@param", "file", "A", "readable", "stream", ".", "@param", "size", "The", "character", "buffer", "size", "in", "bytes", ".", "When", "in", "doubt", "use", "@c", "YY_BUF_SIZE", ".", "@param", "yyscanner", "The", "scanner", "object", ".", "@return", "the", "allocated", "buffer", "state", "." ]
YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_buf_size = size; b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ,yyscanner ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; yy_init_buffer(b,file ,yyscanner); return b; }
[ "YY_BUFFER_STATE", "yy_create_buffer", "(", "FILE", "*", "file", ",", "int", "size", ",", "yyscan_t", "yyscanner", ")", "{", "YY_BUFFER_STATE", "b", ";", "b", "=", "(", "YY_BUFFER_STATE", ")", "yyalloc", "(", "sizeof", "(", "struct", "yy_buffer_state", ")", ",", "yyscanner", ")", ";", "if", "(", "!", "b", ")", "YY_FATAL_ERROR", "(", "\"", "\"", ")", ";", "b", "->", "yy_buf_size", "=", "size", ";", "b", "->", "yy_ch_buf", "=", "(", "char", "*", ")", "yyalloc", "(", "b", "->", "yy_buf_size", "+", "2", ",", "yyscanner", ")", ";", "if", "(", "!", "b", "->", "yy_ch_buf", ")", "YY_FATAL_ERROR", "(", "\"", "\"", ")", ";", "b", "->", "yy_is_our_buffer", "=", "1", ";", "yy_init_buffer", "(", "b", ",", "file", ",", "yyscanner", ")", ";", "return", "b", ";", "}" ]
Allocate and initialize an input buffer state.
[ "Allocate", "and", "initialize", "an", "input", "buffer", "state", "." ]
[ "/* yy_ch_buf has to be 2 characters longer than the size given because\n\t * we need to put in 2 end-of-buffer characters.\n\t */" ]
[ { "param": "file", "type": "FILE" }, { "param": "size", "type": "int" }, { "param": "yyscanner", "type": "yyscan_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yyscanner", "type": "yyscan_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
375a293e1eb57cb0bbcef3ebe6598779fc4b8244
Ismael-VC/latino-nuevo
src/lex.c
[ "MIT" ]
C
yy_init_buffer
void
static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) { int oerrno = errno; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yy_flush_buffer(b ,yyscanner); b->yy_input_file = file; b->yy_fill_buffer = 1; /* If b is the current buffer, then yy_init_buffer was _probably_ * called from yyrestart() or through yy_get_next_buffer. * In that case, we don't want to reset the lineno or column. */ if (b != YY_CURRENT_BUFFER){ b->yy_bs_lineno = 1; b->yy_bs_column = 0; } b->yy_is_interactive = 0; errno = oerrno; }
/* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */
Initializes or reinitializes a buffer. This function is sometimes called more than once on the same buffer, such as during a yyrestart() or at EOF.
[ "Initializes", "or", "reinitializes", "a", "buffer", ".", "This", "function", "is", "sometimes", "called", "more", "than", "once", "on", "the", "same", "buffer", "such", "as", "during", "a", "yyrestart", "()", "or", "at", "EOF", "." ]
static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) { int oerrno = errno; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yy_flush_buffer(b ,yyscanner); b->yy_input_file = file; b->yy_fill_buffer = 1; if (b != YY_CURRENT_BUFFER){ b->yy_bs_lineno = 1; b->yy_bs_column = 0; } b->yy_is_interactive = 0; errno = oerrno; }
[ "static", "void", "yy_init_buffer", "(", "YY_BUFFER_STATE", "b", ",", "FILE", "*", "file", ",", "yyscan_t", "yyscanner", ")", "{", "int", "oerrno", "=", "errno", ";", "struct", "yyguts_t", "*", "yyg", "=", "(", "struct", "yyguts_t", "*", ")", "yyscanner", ";", "yy_flush_buffer", "(", "b", ",", "yyscanner", ")", ";", "b", "->", "yy_input_file", "=", "file", ";", "b", "->", "yy_fill_buffer", "=", "1", ";", "if", "(", "b", "!=", "YY_CURRENT_BUFFER", ")", "{", "b", "->", "yy_bs_lineno", "=", "1", ";", "b", "->", "yy_bs_column", "=", "0", ";", "}", "b", "->", "yy_is_interactive", "=", "0", ";", "errno", "=", "oerrno", ";", "}" ]
Initializes or reinitializes a buffer.
[ "Initializes", "or", "reinitializes", "a", "buffer", "." ]
[ "/* If b is the current buffer, then yy_init_buffer was _probably_\n * called from yyrestart() or through yy_get_next_buffer.\n * In that case, we don't want to reset the lineno or column.\n */" ]
[ { "param": "b", "type": "YY_BUFFER_STATE" }, { "param": "file", "type": "FILE" }, { "param": "yyscanner", "type": "yyscan_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "b", "type": "YY_BUFFER_STATE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "file", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yyscanner", "type": "yyscan_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
375a293e1eb57cb0bbcef3ebe6598779fc4b8244
Ismael-VC/latino-nuevo
src/lex.c
[ "MIT" ]
C
yyensure_buffer_stack
void
static void yyensure_buffer_stack (yyscan_t yyscanner) { yy_size_t num_to_alloc; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; if (!yyg->yy_buffer_stack) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); yyg->yy_buffer_stack_max = num_to_alloc; yyg->yy_buffer_stack_top = 0; return; } if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = yyg->yy_buffer_stack_max + grow_size; yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); yyg->yy_buffer_stack_max = num_to_alloc; } }
/* Allocates the stack if it does not exist. * Guarantees space for at least one push. */
Allocates the stack if it does not exist. Guarantees space for at least one push.
[ "Allocates", "the", "stack", "if", "it", "does", "not", "exist", ".", "Guarantees", "space", "for", "at", "least", "one", "push", "." ]
static void yyensure_buffer_stack (yyscan_t yyscanner) { yy_size_t num_to_alloc; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; if (!yyg->yy_buffer_stack) { num_to_alloc = 1; yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); yyg->yy_buffer_stack_max = num_to_alloc; yyg->yy_buffer_stack_top = 0; return; } if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ int grow_size = 8 ; num_to_alloc = yyg->yy_buffer_stack_max + grow_size; yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); yyg->yy_buffer_stack_max = num_to_alloc; } }
[ "static", "void", "yyensure_buffer_stack", "(", "yyscan_t", "yyscanner", ")", "{", "yy_size_t", "num_to_alloc", ";", "struct", "yyguts_t", "*", "yyg", "=", "(", "struct", "yyguts_t", "*", ")", "yyscanner", ";", "if", "(", "!", "yyg", "->", "yy_buffer_stack", ")", "{", "num_to_alloc", "=", "1", ";", "yyg", "->", "yy_buffer_stack", "=", "(", "struct", "yy_buffer_state", "*", "*", ")", "yyalloc", "(", "num_to_alloc", "*", "sizeof", "(", "struct", "yy_buffer_state", "*", ")", ",", "yyscanner", ")", ";", "if", "(", "!", "yyg", "->", "yy_buffer_stack", ")", "YY_FATAL_ERROR", "(", "\"", "\"", ")", ";", "memset", "(", "yyg", "->", "yy_buffer_stack", ",", "0", ",", "num_to_alloc", "*", "sizeof", "(", "struct", "yy_buffer_state", "*", ")", ")", ";", "yyg", "->", "yy_buffer_stack_max", "=", "num_to_alloc", ";", "yyg", "->", "yy_buffer_stack_top", "=", "0", ";", "return", ";", "}", "if", "(", "yyg", "->", "yy_buffer_stack_top", ">=", "(", "yyg", "->", "yy_buffer_stack_max", ")", "-", "1", ")", "{", "int", "grow_size", "=", "8", ";", "num_to_alloc", "=", "yyg", "->", "yy_buffer_stack_max", "+", "grow_size", ";", "yyg", "->", "yy_buffer_stack", "=", "(", "struct", "yy_buffer_state", "*", "*", ")", "yyrealloc", "(", "yyg", "->", "yy_buffer_stack", ",", "num_to_alloc", "*", "sizeof", "(", "struct", "yy_buffer_state", "*", ")", ",", "yyscanner", ")", ";", "if", "(", "!", "yyg", "->", "yy_buffer_stack", ")", "YY_FATAL_ERROR", "(", "\"", "\"", ")", ";", "memset", "(", "yyg", "->", "yy_buffer_stack", "+", "yyg", "->", "yy_buffer_stack_max", ",", "0", ",", "grow_size", "*", "sizeof", "(", "struct", "yy_buffer_state", "*", ")", ")", ";", "yyg", "->", "yy_buffer_stack_max", "=", "num_to_alloc", ";", "}", "}" ]
Allocates the stack if it does not exist.
[ "Allocates", "the", "stack", "if", "it", "does", "not", "exist", "." ]
[ "/* First allocation is just for 2 elements, since we don't know if this\n\t\t * scanner will even need a stack. We use 2 instead of 1 to avoid an\n\t\t * immediate realloc on the next call.\n */", "/* Increase the buffer to prepare for a possible push. */", "/* arbitrary grow size */", "/* zero only the new slots.*/" ]
[ { "param": "yyscanner", "type": "yyscan_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "yyscanner", "type": "yyscan_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
375a293e1eb57cb0bbcef3ebe6598779fc4b8244
Ismael-VC/latino-nuevo
src/lex.c
[ "MIT" ]
C
yyset_lineno
void
void yyset_lineno (int line_number , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* lineno is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); yylineno = line_number; }
/** Set the current line number. * @param line_number * @param yyscanner The scanner object. */
Set the current line number. @param line_number @param yyscanner The scanner object.
[ "Set", "the", "current", "line", "number", ".", "@param", "line_number", "@param", "yyscanner", "The", "scanner", "object", "." ]
void yyset_lineno (int line_number , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; if (! YY_CURRENT_BUFFER ) YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); yylineno = line_number; }
[ "void", "yyset_lineno", "(", "int", "line_number", ",", "yyscan_t", "yyscanner", ")", "{", "struct", "yyguts_t", "*", "yyg", "=", "(", "struct", "yyguts_t", "*", ")", "yyscanner", ";", "if", "(", "!", "YY_CURRENT_BUFFER", ")", "YY_FATAL_ERROR", "(", "\"", "\"", ")", ";", "yylineno", "=", "line_number", ";", "}" ]
Set the current line number.
[ "Set", "the", "current", "line", "number", "." ]
[ "/* lineno is only valid if an input buffer exists. */" ]
[ { "param": "line_number", "type": "int" }, { "param": "yyscanner", "type": "yyscan_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "line_number", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yyscanner", "type": "yyscan_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
375a293e1eb57cb0bbcef3ebe6598779fc4b8244
Ismael-VC/latino-nuevo
src/lex.c
[ "MIT" ]
C
yyset_column
void
void yyset_column (int column_no , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* column is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) YY_FATAL_ERROR( "yyset_column called with no buffer" ); yycolumn = column_no; }
/** Set the current column. * @param line_number * @param yyscanner The scanner object. */
Set the current column. @param line_number @param yyscanner The scanner object.
[ "Set", "the", "current", "column", ".", "@param", "line_number", "@param", "yyscanner", "The", "scanner", "object", "." ]
void yyset_column (int column_no , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; if (! YY_CURRENT_BUFFER ) YY_FATAL_ERROR( "yyset_column called with no buffer" ); yycolumn = column_no; }
[ "void", "yyset_column", "(", "int", "column_no", ",", "yyscan_t", "yyscanner", ")", "{", "struct", "yyguts_t", "*", "yyg", "=", "(", "struct", "yyguts_t", "*", ")", "yyscanner", ";", "if", "(", "!", "YY_CURRENT_BUFFER", ")", "YY_FATAL_ERROR", "(", "\"", "\"", ")", ";", "yycolumn", "=", "column_no", ";", "}" ]
Set the current column.
[ "Set", "the", "current", "column", "." ]
[ "/* column is only valid if an input buffer exists. */" ]
[ { "param": "column_no", "type": "int" }, { "param": "yyscanner", "type": "yyscan_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "column_no", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yyscanner", "type": "yyscan_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
375a293e1eb57cb0bbcef3ebe6598779fc4b8244
Ismael-VC/latino-nuevo
src/lex.c
[ "MIT" ]
C
yyset_in
void
void yyset_in (FILE * in_str , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yyin = in_str ; }
/** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. * @param yyscanner The scanner object. * @see yy_switch_to_buffer */
Set the input stream. This does not discard the current input buffer. @param in_str A readable stream. @param yyscanner The scanner object.
[ "Set", "the", "input", "stream", ".", "This", "does", "not", "discard", "the", "current", "input", "buffer", ".", "@param", "in_str", "A", "readable", "stream", ".", "@param", "yyscanner", "The", "scanner", "object", "." ]
void yyset_in (FILE * in_str , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yyin = in_str ; }
[ "void", "yyset_in", "(", "FILE", "*", "in_str", ",", "yyscan_t", "yyscanner", ")", "{", "struct", "yyguts_t", "*", "yyg", "=", "(", "struct", "yyguts_t", "*", ")", "yyscanner", ";", "yyin", "=", "in_str", ";", "}" ]
Set the input stream.
[ "Set", "the", "input", "stream", "." ]
[]
[ { "param": "in_str", "type": "FILE" }, { "param": "yyscanner", "type": "yyscan_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "in_str", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yyscanner", "type": "yyscan_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
714a6995ae3e08790f4441e79fd9b5b37968be2a
vietnguyen1989/UDx-Examples
Java-and-C++/HelperLibraries/CoroutineHelpers.h
[ "BSD-3-Clause" ]
C
start
void
void start(CoroutineMethod main, void *context) { ContextArgHacker fn((void*)main); ContextArgHacker args(context); makecontext(&pcontext, (void(*)())callFnPtr, 4, fn.getA0(), fn.getA1(), args.getA0(), args.getA1()); }
/** * Kick off the internal coroutine. * * Note that makecontext() (particularly as provided by some of * the older libc versions supported by Vertica) is a very * old-school C x86 function. No OO functions; arguments must * all be int32's; etc. Hence the hackish workaround. */
Kick off the internal coroutine. Note that makecontext() (particularly as provided by some of the older libc versions supported by Vertica) is a very old-school C x86 function. No OO functions; arguments must all be int32's; etc. Hence the hackish workaround.
[ "Kick", "off", "the", "internal", "coroutine", ".", "Note", "that", "makecontext", "()", "(", "particularly", "as", "provided", "by", "some", "of", "the", "older", "libc", "versions", "supported", "by", "Vertica", ")", "is", "a", "very", "old", "-", "school", "C", "x86", "function", ".", "No", "OO", "functions", ";", "arguments", "must", "all", "be", "int32", "'", "s", ";", "etc", ".", "Hence", "the", "hackish", "workaround", "." ]
void start(CoroutineMethod main, void *context) { ContextArgHacker fn((void*)main); ContextArgHacker args(context); makecontext(&pcontext, (void(*)())callFnPtr, 4, fn.getA0(), fn.getA1(), args.getA0(), args.getA1()); }
[ "void", "start", "(", "CoroutineMethod", "main", ",", "void", "*", "context", ")", "{", "ContextArgHacker", "fn", "(", "", "(", "void", "*", ")", "main", ")", ";", "ContextArgHacker", "args", "(", "context", ")", ";", "makecontext", "(", "&", "pcontext", ",", "(", "void", "(", "*", ")", "(", ")", ")", "callFnPtr", ",", "4", ",", "fn", ".", "getA0", "(", ")", ",", "fn", ".", "getA1", "(", ")", ",", "args", ".", "getA0", "(", ")", ",", "args", ".", "getA1", "(", ")", ")", ";", "}" ]
Kick off the internal coroutine.
[ "Kick", "off", "the", "internal", "coroutine", "." ]
[]
[ { "param": "main", "type": "CoroutineMethod" }, { "param": "context", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "main", "type": "CoroutineMethod", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "context", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
714a6995ae3e08790f4441e79fd9b5b37968be2a
vietnguyen1989/UDx-Examples
Java-and-C++/HelperLibraries/CoroutineHelpers.h
[ "BSD-3-Clause" ]
C
callFnPtr
int
static int callFnPtr(int fn0, int fn1, int a0, int a1) { ContextArgHacker fn(fn0, fn1); ContextArgHacker arg(a0, a1); return (*(CoroutineMethod)fn.getPtr())(arg.getPtr()); }
// Part of an x86_64-specific hack used by Coroutine to work around // makecontext() being limited to 32-bit pointers by taking two pairs // of 32-bit pointer parts and convert them into a pair of 64-bit pointers. // @cond INTERNAL
Part of an x86_64-specific hack used by Coroutine to work around makecontext() being limited to 32-bit pointers by taking two pairs of 32-bit pointer parts and convert them into a pair of 64-bit pointers.
[ "Part", "of", "an", "x86_64", "-", "specific", "hack", "used", "by", "Coroutine", "to", "work", "around", "makecontext", "()", "being", "limited", "to", "32", "-", "bit", "pointers", "by", "taking", "two", "pairs", "of", "32", "-", "bit", "pointer", "parts", "and", "convert", "them", "into", "a", "pair", "of", "64", "-", "bit", "pointers", "." ]
static int callFnPtr(int fn0, int fn1, int a0, int a1) { ContextArgHacker fn(fn0, fn1); ContextArgHacker arg(a0, a1); return (*(CoroutineMethod)fn.getPtr())(arg.getPtr()); }
[ "static", "int", "callFnPtr", "(", "int", "fn0", ",", "int", "fn1", ",", "int", "a0", ",", "int", "a1", ")", "{", "ContextArgHacker", "fn", "(", "fn0", ",", "fn1", ")", ";", "ContextArgHacker", "arg", "(", "a0", ",", "a1", ")", ";", "return", "(", "*", "(", "CoroutineMethod", ")", "fn", ".", "getPtr", "(", ")", ")", "(", "arg", ".", "getPtr", "(", ")", ")", ";", "}" ]
Part of an x86_64-specific hack used by Coroutine to work around makecontext() being limited to 32-bit pointers by taking two pairs of 32-bit pointer parts and convert them into a pair of 64-bit pointers.
[ "Part", "of", "an", "x86_64", "-", "specific", "hack", "used", "by", "Coroutine", "to", "work", "around", "makecontext", "()", "being", "limited", "to", "32", "-", "bit", "pointers", "by", "taking", "two", "pairs", "of", "32", "-", "bit", "pointer", "parts", "and", "convert", "them", "into", "a", "pair", "of", "64", "-", "bit", "pointers", "." ]
[]
[ { "param": "fn0", "type": "int" }, { "param": "fn1", "type": "int" }, { "param": "a0", "type": "int" }, { "param": "a1", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fn0", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fn1", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "a0", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "a1", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [ { "identifier": "cond", "docstring": null, "docstring_tokens": [ "None" ] } ] }
714a6995ae3e08790f4441e79fd9b5b37968be2a
vietnguyen1989/UDx-Examples
Java-and-C++/HelperLibraries/CoroutineHelpers.h
[ "BSD-3-Clause" ]
C
read
size_t
size_t read(void *buf, size_t n) { size_t reserved = reserve(n); memcpy(buf, getDataPtr(), reserved); return seek(reserved); }
/** * Reads up to `n` bytes from the input stream, * and copies them into the input buffer. * * A wrapper on top of reserve() and seek(). * * Because read() calls seek(), it also invalidates getDataPtr(). * See the documentation for that function call if using * read() and getDataPtr() in the same UDParser implementation. * * Note that read() is incompatible with row rejection at this time * because the row to be rejected is no longer available to Vertica * once it has been seek()'ed past. See the reserve()/seek() API * for an alternative that doesn't have this limitation. */
Reads up to `n` bytes from the input stream, and copies them into the input buffer. A wrapper on top of reserve() and seek(). Because read() calls seek(), it also invalidates getDataPtr(). See the documentation for that function call if using read() and getDataPtr() in the same UDParser implementation. Note that read() is incompatible with row rejection at this time because the row to be rejected is no longer available to Vertica once it has been seek()'ed past. See the reserve()/seek() API for an alternative that doesn't have this limitation.
[ "Reads", "up", "to", "`", "n", "`", "bytes", "from", "the", "input", "stream", "and", "copies", "them", "into", "the", "input", "buffer", ".", "A", "wrapper", "on", "top", "of", "reserve", "()", "and", "seek", "()", ".", "Because", "read", "()", "calls", "seek", "()", "it", "also", "invalidates", "getDataPtr", "()", ".", "See", "the", "documentation", "for", "that", "function", "call", "if", "using", "read", "()", "and", "getDataPtr", "()", "in", "the", "same", "UDParser", "implementation", ".", "Note", "that", "read", "()", "is", "incompatible", "with", "row", "rejection", "at", "this", "time", "because", "the", "row", "to", "be", "rejected", "is", "no", "longer", "available", "to", "Vertica", "once", "it", "has", "been", "seek", "()", "'", "ed", "past", ".", "See", "the", "reserve", "()", "/", "seek", "()", "API", "for", "an", "alternative", "that", "doesn", "'", "t", "have", "this", "limitation", "." ]
size_t read(void *buf, size_t n) { size_t reserved = reserve(n); memcpy(buf, getDataPtr(), reserved); return seek(reserved); }
[ "size_t", "read", "(", "void", "*", "buf", ",", "size_t", "n", ")", "{", "size_t", "reserved", "=", "reserve", "(", "n", ")", ";", "memcpy", "(", "buf", ",", "getDataPtr", "(", ")", ",", "reserved", ")", ";", "return", "seek", "(", "reserved", ")", ";", "}" ]
Reads up to `n` bytes from the input stream, and copies them into the input buffer.
[ "Reads", "up", "to", "`", "n", "`", "bytes", "from", "the", "input", "stream", "and", "copies", "them", "into", "the", "input", "buffer", "." ]
[]
[ { "param": "buf", "type": "void" }, { "param": "n", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "n", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
714a6995ae3e08790f4441e79fd9b5b37968be2a
vietnguyen1989/UDx-Examples
Java-and-C++/HelperLibraries/CoroutineHelpers.h
[ "BSD-3-Clause" ]
C
write
size_t
size_t write(const void *buf, size_t n) { size_t reserved = reserve(n); memcpy(getDataPtr(), buf, reserved); return seek(reserved); }
/** * Writes up to `n` bytes from buf to the output stream. * * Returns the number of bytes successfully written. * * Will write exactly `n` bytes unless the output stream closes * before the last byte has been written. * * write() is a wrapper on top of reserve() and seek(). * Because write() calls seek(), it also invalidates getDataPtr(). * See the documentation for that function call if using * write() and getDataPtr() in the same UDParser implementation. * * Note that write() is incompatible with row rejection at this time * because the row to be rejected is no longer available to Vertica * once it has been seek()'ed past. See the reserve()/seek() API * for an alternative that doesn't have this limitation. */
Writes up to `n` bytes from buf to the output stream. Returns the number of bytes successfully written. Will write exactly `n` bytes unless the output stream closes before the last byte has been written. write() is a wrapper on top of reserve() and seek(). Because write() calls seek(), it also invalidates getDataPtr(). See the documentation for that function call if using write() and getDataPtr() in the same UDParser implementation. Note that write() is incompatible with row rejection at this time because the row to be rejected is no longer available to Vertica once it has been seek()'ed past. See the reserve()/seek() API for an alternative that doesn't have this limitation.
[ "Writes", "up", "to", "`", "n", "`", "bytes", "from", "buf", "to", "the", "output", "stream", ".", "Returns", "the", "number", "of", "bytes", "successfully", "written", ".", "Will", "write", "exactly", "`", "n", "`", "bytes", "unless", "the", "output", "stream", "closes", "before", "the", "last", "byte", "has", "been", "written", ".", "write", "()", "is", "a", "wrapper", "on", "top", "of", "reserve", "()", "and", "seek", "()", ".", "Because", "write", "()", "calls", "seek", "()", "it", "also", "invalidates", "getDataPtr", "()", ".", "See", "the", "documentation", "for", "that", "function", "call", "if", "using", "write", "()", "and", "getDataPtr", "()", "in", "the", "same", "UDParser", "implementation", ".", "Note", "that", "write", "()", "is", "incompatible", "with", "row", "rejection", "at", "this", "time", "because", "the", "row", "to", "be", "rejected", "is", "no", "longer", "available", "to", "Vertica", "once", "it", "has", "been", "seek", "()", "'", "ed", "past", ".", "See", "the", "reserve", "()", "/", "seek", "()", "API", "for", "an", "alternative", "that", "doesn", "'", "t", "have", "this", "limitation", "." ]
size_t write(const void *buf, size_t n) { size_t reserved = reserve(n); memcpy(getDataPtr(), buf, reserved); return seek(reserved); }
[ "size_t", "write", "(", "const", "void", "*", "buf", ",", "size_t", "n", ")", "{", "size_t", "reserved", "=", "reserve", "(", "n", ")", ";", "memcpy", "(", "getDataPtr", "(", ")", ",", "buf", ",", "reserved", ")", ";", "return", "seek", "(", "reserved", ")", ";", "}" ]
Writes up to `n` bytes from buf to the output stream.
[ "Writes", "up", "to", "`", "n", "`", "bytes", "from", "buf", "to", "the", "output", "stream", "." ]
[]
[ { "param": "buf", "type": "void" }, { "param": "n", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "n", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
01e2969994d16263a5d0395e29c7c83828b93314
lili-lilili/skiboo
core/errorlog.c
[ "Apache-2.0" ]
C
log_add_section
void
void log_add_section(struct errorlog *buf, uint32_t tag) { size_t size = sizeof(struct elog_user_data_section) - 1; struct elog_user_data_section *tmp; if (!buf) { prerror("ELOG: Cannot add user data section. " "Buffer is invalid\n"); return; } if ((buf->user_section_size + size) > OPAL_LOG_MAX_DUMP) { prerror("ELOG: Size of dump data overruns buffer\n"); return; } tmp = (struct elog_user_data_section *)(buf->user_data_dump + buf->user_section_size); /* Use DESC if no other tag provided */ tmp->tag = tag ? tag : 0x44455343; tmp->size = size; buf->user_section_size += tmp->size; buf->user_section_count++; }
/* Add a new user data section to an existing error log */
Add a new user data section to an existing error log
[ "Add", "a", "new", "user", "data", "section", "to", "an", "existing", "error", "log" ]
void log_add_section(struct errorlog *buf, uint32_t tag) { size_t size = sizeof(struct elog_user_data_section) - 1; struct elog_user_data_section *tmp; if (!buf) { prerror("ELOG: Cannot add user data section. " "Buffer is invalid\n"); return; } if ((buf->user_section_size + size) > OPAL_LOG_MAX_DUMP) { prerror("ELOG: Size of dump data overruns buffer\n"); return; } tmp = (struct elog_user_data_section *)(buf->user_data_dump + buf->user_section_size); tmp->tag = tag ? tag : 0x44455343; tmp->size = size; buf->user_section_size += tmp->size; buf->user_section_count++; }
[ "void", "log_add_section", "(", "struct", "errorlog", "*", "buf", ",", "uint32_t", "tag", ")", "{", "size_t", "size", "=", "sizeof", "(", "struct", "elog_user_data_section", ")", "-", "1", ";", "struct", "elog_user_data_section", "*", "tmp", ";", "if", "(", "!", "buf", ")", "{", "prerror", "(", "\"", "\"", "\"", "\\n", "\"", ")", ";", "return", ";", "}", "if", "(", "(", "buf", "->", "user_section_size", "+", "size", ")", ">", "OPAL_LOG_MAX_DUMP", ")", "{", "prerror", "(", "\"", "\\n", "\"", ")", ";", "return", ";", "}", "tmp", "=", "(", "struct", "elog_user_data_section", "*", ")", "(", "buf", "->", "user_data_dump", "+", "buf", "->", "user_section_size", ")", ";", "tmp", "->", "tag", "=", "tag", "?", "tag", ":", "0x44455343", ";", "tmp", "->", "size", "=", "size", ";", "buf", "->", "user_section_size", "+=", "tmp", "->", "size", ";", "buf", "->", "user_section_count", "++", ";", "}" ]
Add a new user data section to an existing error log
[ "Add", "a", "new", "user", "data", "section", "to", "an", "existing", "error", "log" ]
[ "/* Use DESC if no other tag provided */" ]
[ { "param": "buf", "type": "struct errorlog" }, { "param": "tag", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "struct errorlog", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "tag", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
edb88a174ca45c824ccb834fa86048ca3489cc33
tomwei7/redsocks
encrypt.c
[ "Apache-2.0" ]
C
ss_calc_buffer_size
size_t
size_t ss_calc_buffer_size(struct enc_ctx * ctx, size_t ilen) { int method = ctx->info->method; const cipher_kt_t *cipher = get_cipher_type(method); if (ctx->init) return ilen + EVP_CIPHER_block_size(cipher); else return EVP_CIPHER_iv_length(cipher) + ilen + EVP_CIPHER_block_size(cipher); }
/* Calculate buffer size required for encrypt/decrypt data */
Calculate buffer size required for encrypt/decrypt data
[ "Calculate", "buffer", "size", "required", "for", "encrypt", "/", "decrypt", "data" ]
size_t ss_calc_buffer_size(struct enc_ctx * ctx, size_t ilen) { int method = ctx->info->method; const cipher_kt_t *cipher = get_cipher_type(method); if (ctx->init) return ilen + EVP_CIPHER_block_size(cipher); else return EVP_CIPHER_iv_length(cipher) + ilen + EVP_CIPHER_block_size(cipher); }
[ "size_t", "ss_calc_buffer_size", "(", "struct", "enc_ctx", "*", "ctx", ",", "size_t", "ilen", ")", "{", "int", "method", "=", "ctx", "->", "info", "->", "method", ";", "const", "cipher_kt_t", "*", "cipher", "=", "get_cipher_type", "(", "method", ")", ";", "if", "(", "ctx", "->", "init", ")", "return", "ilen", "+", "EVP_CIPHER_block_size", "(", "cipher", ")", ";", "else", "return", "EVP_CIPHER_iv_length", "(", "cipher", ")", "+", "ilen", "+", "EVP_CIPHER_block_size", "(", "cipher", ")", ";", "}" ]
Calculate buffer size required for encrypt/decrypt data
[ "Calculate", "buffer", "size", "required", "for", "encrypt", "/", "decrypt", "data" ]
[]
[ { "param": "ctx", "type": "struct enc_ctx" }, { "param": "ilen", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "struct enc_ctx", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ilen", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bc587cd948767a341bc8d45aae521d78750fb88
nickwanninger/game-render-test
src/render.c
[ "MIT" ]
C
renderwall
void
static inline void renderwall (display_t *d, camera_t *cam, double x0, double y0, double x1, double y1, uint32_t c) { y0 *= -1; y1 *= -1; /** * * Walls in this engine are rendered by giving the * left position and the right position in and x,y * plane. * * You can visualize this with this diagram. * * +z +-------------+ * | | * | | * | WALL | * | | * -z +-------------+ * ^ ^ * (x0, y0) (x1, y1) * * It will only ever draw the wall if the left side is the * coordinate for (x0, y0) as it draws left to right */ /** * Here we get quick access to the position of the camera, * The accessing and order is strange because in graphics * Z is not up and down, */ double xCam = camera.x - 0.5; double yCam = -camera.y + 0.5; double zCam = -camera.z; double rCos = -cos(camera.rot); double rSin = sin(camera.rot); // Get the center of the screen for future use double xCenter = d->width / 2; double yCenter = d->height / 2; /** * Throught the engine, the fov is the height of the window */ int fov = d->height; /** * Offset one end of the wall to the correct location * Without this, the left part of the wall would be drawn * so that it appears to pass through the camera's location * but start off to the left. */ double xc0 = ((x0 - 0.5) - xCam) * 2; double yc0 = ((y0 - 0.5) - yCam) * 2; /** * Shift that edge to somewhere along the center of * the screen based on the camera's angle relative to the * edge of the wall * zz0 is the z distance (how far away from the camera) * the corner of the wall is. * * zz0 and zz1 can be visualized like this. * +-------------+ * | | * | | * | WALL | * | | * +-------------+ * ^ ^ * (x0, y0) (x1, y1) * +- \ / -+ * | \ / | * | \ / | * zz0 > | \ / | < zz1 * | \ / | * | \ / | * +- Camera -+ * * */ double xx0 = xc0 * rCos - yc0 * rSin; double u0 = ((-0.5) - zCam) * 2; double l0 = ((+0.5) - zCam) * 2; double zz0 = yc0 * rCos + xc0 * rSin; /* * And now we do the same thing, but with the other edge * of the wall, we shift it over and position it in * perspective space. */ double xc1 = ((x1 - 0.5) - xCam) * 2; double yc1 = ((y1 - 0.5) - yCam) * 2; /** * Yet again, shift that right edge to some location along * the screen so that we can lerp between the two */ double xx1 = xc1 * rCos - yc1 * rSin; double u1 = ((-0.5) - zCam) * 2; double l1 = ((+0.5) - zCam) * 2; double zz1 = yc1 * rCos + xc1 * rSin; // The texture of the wall double xt0 = 0; double xt1 = 1; xt0 *= 16; xt1 *= 16; int tex = 0; int col = 0; double zClip = 0.1; /** * Dont render the wall if it is too far out of frame */ if (zz0 < zClip && zz1 < zClip) return; /** * Do further clipping because if the camera's angle * to the wall is too shallow, and the wall is out of * view, it draws the texture spread out to infinity. * Here we clip the left side: */ if (zz0 < zClip) { double p = (zClip - zz0) / (zz1 - zz0); zz0 = zz0 + (zz1 - zz0) * p; xx0 = xx0 + (xx1 - xx0) * p; xt0 = xt0 + (xt1 - xt0) * p; } /** * Here we clip the right side */ if (zz1 < zClip) { double p = (zClip - zz0) / (zz1 - zz0); zz1 = zz0 + (zz1 - zz0) * p; xx1 = xx0 + (xx1 - xx0) * p; xt1 = xt0 + (xt1 - xt0) * p; } /** * Here it is decided where the left and right * side of the wall are located on the screen * +z +-------------+ * | | * | | * | | * | | * -z +-------------+ * ^ ^ * xPixel0 xPixel1 * */ double xPixel0 = xCenter - (xx0 / zz0 * fov); double xPixel1 = xCenter - (xx1 / zz1 * fov); /** * If the locations overlap, or are reversed, stop rendering the wall */ if (xPixel0 >= xPixel1) return; /** * convert the float values for the x locations into ints so we can * use them to draw pixels to th e screen */ int xp0 = (int) ceil(xPixel0); int xp1 = (int) ceil(xPixel1); /** * Make sure to bound the wall so it doesn't seg fault by rendering outside * the screen */ if (xp0 < 0) xp0 = 0; if (xp1 > d->width) xp1 = d->width; /** * This is getting the Y position on the screen * of all 4 corners of the wall, from here on, we * just need to rasterize the texture on the wall */ double yTopLeft = (u0 / zz0 * fov + yCenter); double yBottomLeft = (l0 / zz0 * fov + yCenter); double yTopRight = (u1 / zz1 * fov + yCenter); double yBottomRight = (l1 / zz1 * fov + yCenter); /** * Now that we have the x and y locations of every * corner of the wall, we can draw it to the screen */ double iz0 = 1 / zz0; double iz1 = 1 / zz1; double iza = iz1 - iz0; double ixt0 = xt0 * iz0; double ixta = xt1 * iz1 - ixt0; double iw = 1 / (xPixel1 - xPixel0); for (int x = xp0; x < xp1; x++) { double pr = (x - xPixel0) * iw; double iz = iz0 + iza * pr; double zd = iz * 255; if (d->zBufferWall[x] > zd) { continue; } d->zBufferWall[x] = zd; int xTex = (int) ((ixt0 + ixta * pr) / iz); double yPixel0 = yTopLeft + (yTopRight - yTopLeft) * pr - 0.5; double yPixel1 = yBottomLeft + (yBottomRight - yBottomLeft) * pr; int yp0 = (int) ceil(yPixel0); int yp1 = (int) ceil(yPixel1); if (yp0 < 0) yp0 = 0; if (yp1 > d->height) yp1 = d->height; double ih = 1 / (yPixel1 - yPixel0); for (int y = yp0; y < yp1; y++) { double pry = (y - yPixel0) * ih; int yTex = (int) (16 * pry); int xt = yTex + (tex % 8) * 16; int yt = xTex + (col / 8) * 16; int color = gpixel(textures, xt, yt); d->pixels[x + y * d->width] = color; d->zBuffer[x + y * d->width] = 1 / iz * 4; } } }
/** * renderwall * * This function takes a display, zBuffers, a camera reference, and locations * The order of locations are important as they determine the side of the wall to draw textures to */
renderwall This function takes a display, zBuffers, a camera reference, and locations The order of locations are important as they determine the side of the wall to draw textures to
[ "renderwall", "This", "function", "takes", "a", "display", "zBuffers", "a", "camera", "reference", "and", "locations", "The", "order", "of", "locations", "are", "important", "as", "they", "determine", "the", "side", "of", "the", "wall", "to", "draw", "textures", "to" ]
static inline void renderwall (display_t *d, camera_t *cam, double x0, double y0, double x1, double y1, uint32_t c) { y0 *= -1; y1 *= -1; double xCam = camera.x - 0.5; double yCam = -camera.y + 0.5; double zCam = -camera.z; double rCos = -cos(camera.rot); double rSin = sin(camera.rot); double xCenter = d->width / 2; double yCenter = d->height / 2; int fov = d->height; double xc0 = ((x0 - 0.5) - xCam) * 2; double yc0 = ((y0 - 0.5) - yCam) * 2; double xx0 = xc0 * rCos - yc0 * rSin; double u0 = ((-0.5) - zCam) * 2; double l0 = ((+0.5) - zCam) * 2; double zz0 = yc0 * rCos + xc0 * rSin; double xc1 = ((x1 - 0.5) - xCam) * 2; double yc1 = ((y1 - 0.5) - yCam) * 2; double xx1 = xc1 * rCos - yc1 * rSin; double u1 = ((-0.5) - zCam) * 2; double l1 = ((+0.5) - zCam) * 2; double zz1 = yc1 * rCos + xc1 * rSin; double xt0 = 0; double xt1 = 1; xt0 *= 16; xt1 *= 16; int tex = 0; int col = 0; double zClip = 0.1; if (zz0 < zClip && zz1 < zClip) return; if (zz0 < zClip) { double p = (zClip - zz0) / (zz1 - zz0); zz0 = zz0 + (zz1 - zz0) * p; xx0 = xx0 + (xx1 - xx0) * p; xt0 = xt0 + (xt1 - xt0) * p; } if (zz1 < zClip) { double p = (zClip - zz0) / (zz1 - zz0); zz1 = zz0 + (zz1 - zz0) * p; xx1 = xx0 + (xx1 - xx0) * p; xt1 = xt0 + (xt1 - xt0) * p; } double xPixel0 = xCenter - (xx0 / zz0 * fov); double xPixel1 = xCenter - (xx1 / zz1 * fov); if (xPixel0 >= xPixel1) return; int xp0 = (int) ceil(xPixel0); int xp1 = (int) ceil(xPixel1); if (xp0 < 0) xp0 = 0; if (xp1 > d->width) xp1 = d->width; double yTopLeft = (u0 / zz0 * fov + yCenter); double yBottomLeft = (l0 / zz0 * fov + yCenter); double yTopRight = (u1 / zz1 * fov + yCenter); double yBottomRight = (l1 / zz1 * fov + yCenter); double iz0 = 1 / zz0; double iz1 = 1 / zz1; double iza = iz1 - iz0; double ixt0 = xt0 * iz0; double ixta = xt1 * iz1 - ixt0; double iw = 1 / (xPixel1 - xPixel0); for (int x = xp0; x < xp1; x++) { double pr = (x - xPixel0) * iw; double iz = iz0 + iza * pr; double zd = iz * 255; if (d->zBufferWall[x] > zd) { continue; } d->zBufferWall[x] = zd; int xTex = (int) ((ixt0 + ixta * pr) / iz); double yPixel0 = yTopLeft + (yTopRight - yTopLeft) * pr - 0.5; double yPixel1 = yBottomLeft + (yBottomRight - yBottomLeft) * pr; int yp0 = (int) ceil(yPixel0); int yp1 = (int) ceil(yPixel1); if (yp0 < 0) yp0 = 0; if (yp1 > d->height) yp1 = d->height; double ih = 1 / (yPixel1 - yPixel0); for (int y = yp0; y < yp1; y++) { double pry = (y - yPixel0) * ih; int yTex = (int) (16 * pry); int xt = yTex + (tex % 8) * 16; int yt = xTex + (col / 8) * 16; int color = gpixel(textures, xt, yt); d->pixels[x + y * d->width] = color; d->zBuffer[x + y * d->width] = 1 / iz * 4; } } }
[ "static", "inline", "void", "renderwall", "(", "display_t", "*", "d", ",", "camera_t", "*", "cam", ",", "double", "x0", ",", "double", "y0", ",", "double", "x1", ",", "double", "y1", ",", "uint32_t", "c", ")", "{", "y0", "*=", "-1", ";", "y1", "*=", "-1", ";", "double", "xCam", "=", "camera", ".", "x", "-", "0.5", ";", "double", "yCam", "=", "-", "camera", ".", "y", "+", "0.5", ";", "double", "zCam", "=", "-", "camera", ".", "z", ";", "double", "rCos", "=", "-", "cos", "(", "camera", ".", "rot", ")", ";", "double", "rSin", "=", "sin", "(", "camera", ".", "rot", ")", ";", "double", "xCenter", "=", "d", "->", "width", "/", "2", ";", "double", "yCenter", "=", "d", "->", "height", "/", "2", ";", "int", "fov", "=", "d", "->", "height", ";", "double", "xc0", "=", "(", "(", "x0", "-", "0.5", ")", "-", "xCam", ")", "*", "2", ";", "double", "yc0", "=", "(", "(", "y0", "-", "0.5", ")", "-", "yCam", ")", "*", "2", ";", "double", "xx0", "=", "xc0", "*", "rCos", "-", "yc0", "*", "rSin", ";", "double", "u0", "=", "(", "(", "-0.5", ")", "-", "zCam", ")", "*", "2", ";", "double", "l0", "=", "(", "(", "+0.5", ")", "-", "zCam", ")", "*", "2", ";", "double", "zz0", "=", "yc0", "*", "rCos", "+", "xc0", "*", "rSin", ";", "double", "xc1", "=", "(", "(", "x1", "-", "0.5", ")", "-", "xCam", ")", "*", "2", ";", "double", "yc1", "=", "(", "(", "y1", "-", "0.5", ")", "-", "yCam", ")", "*", "2", ";", "double", "xx1", "=", "xc1", "*", "rCos", "-", "yc1", "*", "rSin", ";", "double", "u1", "=", "(", "(", "-0.5", ")", "-", "zCam", ")", "*", "2", ";", "double", "l1", "=", "(", "(", "+0.5", ")", "-", "zCam", ")", "*", "2", ";", "double", "zz1", "=", "yc1", "*", "rCos", "+", "xc1", "*", "rSin", ";", "double", "xt0", "=", "0", ";", "double", "xt1", "=", "1", ";", "xt0", "*=", "16", ";", "xt1", "*=", "16", ";", "int", "tex", "=", "0", ";", "int", "col", "=", "0", ";", "double", "zClip", "=", "0.1", ";", "if", "(", "zz0", "<", "zClip", "&&", "zz1", "<", "zClip", ")", "return", ";", "if", "(", "zz0", "<", "zClip", ")", "{", "double", "p", "=", "(", "zClip", "-", "zz0", ")", "/", "(", "zz1", "-", "zz0", ")", ";", "zz0", "=", "zz0", "+", "(", "zz1", "-", "zz0", ")", "*", "p", ";", "xx0", "=", "xx0", "+", "(", "xx1", "-", "xx0", ")", "*", "p", ";", "xt0", "=", "xt0", "+", "(", "xt1", "-", "xt0", ")", "*", "p", ";", "}", "if", "(", "zz1", "<", "zClip", ")", "{", "double", "p", "=", "(", "zClip", "-", "zz0", ")", "/", "(", "zz1", "-", "zz0", ")", ";", "zz1", "=", "zz0", "+", "(", "zz1", "-", "zz0", ")", "*", "p", ";", "xx1", "=", "xx0", "+", "(", "xx1", "-", "xx0", ")", "*", "p", ";", "xt1", "=", "xt0", "+", "(", "xt1", "-", "xt0", ")", "*", "p", ";", "}", "double", "xPixel0", "=", "xCenter", "-", "(", "xx0", "/", "zz0", "*", "fov", ")", ";", "double", "xPixel1", "=", "xCenter", "-", "(", "xx1", "/", "zz1", "*", "fov", ")", ";", "if", "(", "xPixel0", ">=", "xPixel1", ")", "return", ";", "int", "xp0", "=", "(", "int", ")", "ceil", "(", "xPixel0", ")", ";", "int", "xp1", "=", "(", "int", ")", "ceil", "(", "xPixel1", ")", ";", "if", "(", "xp0", "<", "0", ")", "xp0", "=", "0", ";", "if", "(", "xp1", ">", "d", "->", "width", ")", "xp1", "=", "d", "->", "width", ";", "double", "yTopLeft", "=", "(", "u0", "/", "zz0", "*", "fov", "+", "yCenter", ")", ";", "double", "yBottomLeft", "=", "(", "l0", "/", "zz0", "*", "fov", "+", "yCenter", ")", ";", "double", "yTopRight", "=", "(", "u1", "/", "zz1", "*", "fov", "+", "yCenter", ")", ";", "double", "yBottomRight", "=", "(", "l1", "/", "zz1", "*", "fov", "+", "yCenter", ")", ";", "double", "iz0", "=", "1", "/", "zz0", ";", "double", "iz1", "=", "1", "/", "zz1", ";", "double", "iza", "=", "iz1", "-", "iz0", ";", "double", "ixt0", "=", "xt0", "*", "iz0", ";", "double", "ixta", "=", "xt1", "*", "iz1", "-", "ixt0", ";", "double", "iw", "=", "1", "/", "(", "xPixel1", "-", "xPixel0", ")", ";", "for", "(", "int", "x", "=", "xp0", ";", "x", "<", "xp1", ";", "x", "++", ")", "{", "double", "pr", "=", "(", "x", "-", "xPixel0", ")", "*", "iw", ";", "double", "iz", "=", "iz0", "+", "iza", "*", "pr", ";", "double", "zd", "=", "iz", "*", "255", ";", "if", "(", "d", "->", "zBufferWall", "[", "x", "]", ">", "zd", ")", "{", "continue", ";", "}", "d", "->", "zBufferWall", "[", "x", "]", "=", "zd", ";", "int", "xTex", "=", "(", "int", ")", "(", "(", "ixt0", "+", "ixta", "*", "pr", ")", "/", "iz", ")", ";", "double", "yPixel0", "=", "yTopLeft", "+", "(", "yTopRight", "-", "yTopLeft", ")", "*", "pr", "-", "0.5", ";", "double", "yPixel1", "=", "yBottomLeft", "+", "(", "yBottomRight", "-", "yBottomLeft", ")", "*", "pr", ";", "int", "yp0", "=", "(", "int", ")", "ceil", "(", "yPixel0", ")", ";", "int", "yp1", "=", "(", "int", ")", "ceil", "(", "yPixel1", ")", ";", "if", "(", "yp0", "<", "0", ")", "yp0", "=", "0", ";", "if", "(", "yp1", ">", "d", "->", "height", ")", "yp1", "=", "d", "->", "height", ";", "double", "ih", "=", "1", "/", "(", "yPixel1", "-", "yPixel0", ")", ";", "for", "(", "int", "y", "=", "yp0", ";", "y", "<", "yp1", ";", "y", "++", ")", "{", "double", "pry", "=", "(", "y", "-", "yPixel0", ")", "*", "ih", ";", "int", "yTex", "=", "(", "int", ")", "(", "16", "*", "pry", ")", ";", "int", "xt", "=", "yTex", "+", "(", "tex", "%", "8", ")", "*", "16", ";", "int", "yt", "=", "xTex", "+", "(", "col", "/", "8", ")", "*", "16", ";", "int", "color", "=", "gpixel", "(", "textures", ",", "xt", ",", "yt", ")", ";", "d", "->", "pixels", "[", "x", "+", "y", "*", "d", "->", "width", "]", "=", "color", ";", "d", "->", "zBuffer", "[", "x", "+", "y", "*", "d", "->", "width", "]", "=", "1", "/", "iz", "*", "4", ";", "}", "}", "}" ]
renderwall
[ "renderwall" ]
[ "/**\n\t * \n\t * Walls in this engine are rendered by giving the\n\t * left position and the right position in and x,y\n\t * plane.\n\t * \n\t * You can visualize this with this diagram.\n\t * \n\t * +z +-------------+\n\t * | |\n\t * | |\n\t * | WALL |\n\t * | |\n\t * -z +-------------+\n\t * ^ ^\n\t * (x0, y0) (x1, y1)\n\t * \n\t * It will only ever draw the wall if the left side is the\n\t * coordinate for (x0, y0) as it draws left to right\n\t */", "/**\n\t * Here we get quick access to the position of the camera,\n\t * The accessing and order is strange because in graphics\n\t * Z is not up and down, \n\t */", "// Get the center of the screen for future use", "/**\n\t * Throught the engine, the fov is the height of the window\n\t */", "/**\n\t * Offset one end of the wall to the correct location\n\t * Without this, the left part of the wall would be drawn\n\t * so that it appears to pass through the camera's location\n\t * but start off to the left.\n\t */", "/**\n\t * Shift that edge to somewhere along the center of\n\t * the screen based on the camera's angle relative to the\n\t * edge of the wall\n\t * zz0 is the z distance (how far away from the camera)\n\t * the corner of the wall is.\n\t * \n\t * zz0 and zz1 can be visualized like this.\n\t * +-------------+\n\t * | |\n\t * | |\n\t * | WALL |\n\t * | |\n\t * +-------------+\n\t * ^ ^\n\t * (x0, y0) (x1, y1)\n\t * +- \\ / -+\n\t * | \\ / |\n\t * | \\ / |\n\t * zz0 > | \\ / | < zz1\n\t * | \\ / |\n\t * | \\ / |\n\t * +- Camera -+\n\t * \n\t * \n\t */", "/*\n\t * And now we do the same thing, but with the other edge\n\t * of the wall, we shift it over and position it in\n\t * perspective space.\n\t */", "/**\n\t * Yet again, shift that right edge to some location along\n\t * the screen so that we can lerp between the two\n\t */", "// The texture of the wall", "/**\n\t * Dont render the wall if it is too far out of frame\n\t */", "/**\n\t * Do further clipping because if the camera's angle\n\t * to the wall is too shallow, and the wall is out of\n\t * view, it draws the texture spread out to infinity.\n\t * Here we clip the left side:\n\t */", "/**\n\t * Here we clip the right side\n\t */", "/**\n\t * Here it is decided where the left and right\n\t * side of the wall are located on the screen\n\t * +z +-------------+\n\t * | |\n\t * | |\n\t * | |\n\t * | |\n\t * -z +-------------+\n\t * ^ ^\n\t * xPixel0 xPixel1\n\t * \n\t */", "/**\n\t * If the locations overlap, or are reversed, stop rendering the wall\n\t */", "/**\n\t * convert the float values for the x locations into ints so we can\n\t * use them to draw pixels to th e screen\n\t */", "/**\n\t * Make sure to bound the wall so it doesn't seg fault by rendering outside\n\t * the screen\n\t */", "/**\n\t * This is getting the Y position on the screen\n\t * of all 4 corners of the wall, from here on, we\n\t * just need to rasterize the texture on the wall\n\t */", "/**\n\t * Now that we have the x and y locations of every\n\t * corner of the wall, we can draw it to the screen\n\t */" ]
[ { "param": "d", "type": "display_t" }, { "param": "cam", "type": "camera_t" }, { "param": "x0", "type": "double" }, { "param": "y0", "type": "double" }, { "param": "x1", "type": "double" }, { "param": "y1", "type": "double" }, { "param": "c", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "d", "type": "display_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cam", "type": "camera_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x0", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "y0", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x1", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "y1", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "c", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bc587cd948767a341bc8d45aae521d78750fb88
nickwanninger/game-render-test
src/render.c
[ "MIT" ]
C
gprintf
void
void gprintf(display_t d, int x, int y, const char* format, ...) { int i = 0; char buffer[255]; va_list args; va_start(args, format); int r = vsnprintf(buffer, 255, format, args); buffer[r] = 0; va_end(args); for (i = 0; i < strlen(buffer); i++) gdrawchar(d, x + (i * FONT_CHAR_W), y, buffer[i]); }
/** gprintf * takes a <d>isplay, and <x> and a <y> and prints * a formatted string to the screen starting at that * location. * * The string starts where the top left of the string * is at (<x>, <y>) */
gprintf takes a isplay, and and a and prints a formatted string to the screen starting at that location. The string starts where the top left of the string is at (, )
[ "gprintf", "takes", "a", "isplay", "and", "and", "a", "and", "prints", "a", "formatted", "string", "to", "the", "screen", "starting", "at", "that", "location", ".", "The", "string", "starts", "where", "the", "top", "left", "of", "the", "string", "is", "at", "(", ")" ]
void gprintf(display_t d, int x, int y, const char* format, ...) { int i = 0; char buffer[255]; va_list args; va_start(args, format); int r = vsnprintf(buffer, 255, format, args); buffer[r] = 0; va_end(args); for (i = 0; i < strlen(buffer); i++) gdrawchar(d, x + (i * FONT_CHAR_W), y, buffer[i]); }
[ "void", "gprintf", "(", "display_t", "d", ",", "int", "x", ",", "int", "y", ",", "const", "char", "*", "format", ",", "...", ")", "{", "int", "i", "=", "0", ";", "char", "buffer", "[", "255", "]", ";", "va_list", "args", ";", "va_start", "(", "args", ",", "format", ")", ";", "int", "r", "=", "vsnprintf", "(", "buffer", ",", "255", ",", "format", ",", "args", ")", ";", "buffer", "[", "r", "]", "=", "0", ";", "va_end", "(", "args", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "strlen", "(", "buffer", ")", ";", "i", "++", ")", "gdrawchar", "(", "d", ",", "x", "+", "(", "i", "*", "FONT_CHAR_W", ")", ",", "y", ",", "buffer", "[", "i", "]", ")", ";", "}" ]
gprintf takes a <d>isplay, and <x> and a <y> and prints a formatted string to the screen starting at that location.
[ "gprintf", "takes", "a", "<d", ">", "isplay", "and", "<x", ">", "and", "a", "<y", ">", "and", "prints", "a", "formatted", "string", "to", "the", "screen", "starting", "at", "that", "location", "." ]
[]
[ { "param": "d", "type": "display_t" }, { "param": "x", "type": "int" }, { "param": "y", "type": "int" }, { "param": "format", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "d", "type": "display_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "y", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "format", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bc587cd948767a341bc8d45aae521d78750fb88
nickwanninger/game-render-test
src/render.c
[ "MIT" ]
C
gdrawchar
void
void gdrawchar(display_t d, int x, int y, char c) { int w = 6; int h = 8; if (c >= 32 && c < 127) { char co = c - 32; // int offset = co * w; for (int xo = 0; xo < w; xo++) { for (int yo = 0; yo < h; yo++) { int xx = xo + (co % 16) * w; int yy = yo + co / 16 * h; int pixel = gpixel(font_tex, yy, xx); if (pixel == 0xffffff) { setpixel(d, x + xo, y + yo, textcolor); setpixel(d, x + xo, y + yo + 1, colormul(textcolor, 0.4)); // setpixel(d, x + xo + 2, y + yo + 2, colormul(textcolor, 0.4)); } } } } }
/** gdrawchar * Takes a <d>isplay, an <x>, a <y> and draws the char <c> * to that display at that x, y location */
gdrawchar Takes a isplay, an , a and draws the char to that display at that x, y location
[ "gdrawchar", "Takes", "a", "isplay", "an", "a", "and", "draws", "the", "char", "to", "that", "display", "at", "that", "x", "y", "location" ]
void gdrawchar(display_t d, int x, int y, char c) { int w = 6; int h = 8; if (c >= 32 && c < 127) { char co = c - 32; for (int xo = 0; xo < w; xo++) { for (int yo = 0; yo < h; yo++) { int xx = xo + (co % 16) * w; int yy = yo + co / 16 * h; int pixel = gpixel(font_tex, yy, xx); if (pixel == 0xffffff) { setpixel(d, x + xo, y + yo, textcolor); setpixel(d, x + xo, y + yo + 1, colormul(textcolor, 0.4)); } } } } }
[ "void", "gdrawchar", "(", "display_t", "d", ",", "int", "x", ",", "int", "y", ",", "char", "c", ")", "{", "int", "w", "=", "6", ";", "int", "h", "=", "8", ";", "if", "(", "c", ">=", "32", "&&", "c", "<", "127", ")", "{", "char", "co", "=", "c", "-", "32", ";", "for", "(", "int", "xo", "=", "0", ";", "xo", "<", "w", ";", "xo", "++", ")", "{", "for", "(", "int", "yo", "=", "0", ";", "yo", "<", "h", ";", "yo", "++", ")", "{", "int", "xx", "=", "xo", "+", "(", "co", "%", "16", ")", "*", "w", ";", "int", "yy", "=", "yo", "+", "co", "/", "16", "*", "h", ";", "int", "pixel", "=", "gpixel", "(", "font_tex", ",", "yy", ",", "xx", ")", ";", "if", "(", "pixel", "==", "0xffffff", ")", "{", "setpixel", "(", "d", ",", "x", "+", "xo", ",", "y", "+", "yo", ",", "textcolor", ")", ";", "setpixel", "(", "d", ",", "x", "+", "xo", ",", "y", "+", "yo", "+", "1", ",", "colormul", "(", "textcolor", ",", "0.4", ")", ")", ";", "}", "}", "}", "}", "}" ]
gdrawchar Takes a <d>isplay, an <x>, a <y> and draws the char <c> to that display at that x, y location
[ "gdrawchar", "Takes", "a", "<d", ">", "isplay", "an", "<x", ">", "a", "<y", ">", "and", "draws", "the", "char", "<c", ">", "to", "that", "display", "at", "that", "x", "y", "location" ]
[ "// int offset = co * w;", "// setpixel(d, x + xo + 2, y + yo + 2, colormul(textcolor, 0.4));" ]
[ { "param": "d", "type": "display_t" }, { "param": "x", "type": "int" }, { "param": "y", "type": "int" }, { "param": "c", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "d", "type": "display_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "y", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "c", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c64cd6401f8da3d07275a0e29920cd45a97056be
metc/fw-nrfconnect-zephyr
arch/x86/core/ia32/x86_mmu.c
[ "Apache-2.0" ]
C
thread_pt_create
uintptr_t
static uintptr_t thread_pt_create(uintptr_t pages, struct x86_mmu_pdpt *thread_pdpt, struct x86_mmu_pdpt *master_pdpt) { uintptr_t pos = pages, phys_addr = Z_X86_PT_START; for (int i = 0; i < Z_X86_NUM_PT; i++, phys_addr += Z_X86_PT_AREA) { union x86_mmu_pde_pt *pde; struct x86_mmu_pt *master_pt, *dest_pt; /* Same as we did with the directories, obtain PT in master * tables for the address range and copy into per-thread PT * for this range */ master_pt = X86_MMU_GET_PT_ADDR(master_pdpt, phys_addr); dest_pt = (struct x86_mmu_pt *)pos; (void)memcpy(dest_pt, master_pt, sizeof(struct x86_mmu_pd)); /* And then wire this up to the relevant per-thread * page directory entry */ pde = X86_MMU_GET_PDE(thread_pdpt, phys_addr); pde->pt = pos >> MMU_PAGE_SHIFT; pos += MMU_PAGE_SIZE; } return pos; }
/* thread_pdpt must be initialized, as well as all the page directories */
thread_pdpt must be initialized, as well as all the page directories
[ "thread_pdpt", "must", "be", "initialized", "as", "well", "as", "all", "the", "page", "directories" ]
static uintptr_t thread_pt_create(uintptr_t pages, struct x86_mmu_pdpt *thread_pdpt, struct x86_mmu_pdpt *master_pdpt) { uintptr_t pos = pages, phys_addr = Z_X86_PT_START; for (int i = 0; i < Z_X86_NUM_PT; i++, phys_addr += Z_X86_PT_AREA) { union x86_mmu_pde_pt *pde; struct x86_mmu_pt *master_pt, *dest_pt; master_pt = X86_MMU_GET_PT_ADDR(master_pdpt, phys_addr); dest_pt = (struct x86_mmu_pt *)pos; (void)memcpy(dest_pt, master_pt, sizeof(struct x86_mmu_pd)); pde = X86_MMU_GET_PDE(thread_pdpt, phys_addr); pde->pt = pos >> MMU_PAGE_SHIFT; pos += MMU_PAGE_SIZE; } return pos; }
[ "static", "uintptr_t", "thread_pt_create", "(", "uintptr_t", "pages", ",", "struct", "x86_mmu_pdpt", "*", "thread_pdpt", ",", "struct", "x86_mmu_pdpt", "*", "master_pdpt", ")", "{", "uintptr_t", "pos", "=", "pages", ",", "phys_addr", "=", "Z_X86_PT_START", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "Z_X86_NUM_PT", ";", "i", "++", ",", "phys_addr", "+=", "Z_X86_PT_AREA", ")", "{", "union", "x86_mmu_pde_pt", "*", "pde", ";", "struct", "x86_mmu_pt", "*", "master_pt", ",", "*", "dest_pt", ";", "master_pt", "=", "X86_MMU_GET_PT_ADDR", "(", "master_pdpt", ",", "phys_addr", ")", ";", "dest_pt", "=", "(", "struct", "x86_mmu_pt", "*", ")", "pos", ";", "(", "void", ")", "memcpy", "(", "dest_pt", ",", "master_pt", ",", "sizeof", "(", "struct", "x86_mmu_pd", ")", ")", ";", "pde", "=", "X86_MMU_GET_PDE", "(", "thread_pdpt", ",", "phys_addr", ")", ";", "pde", "->", "pt", "=", "pos", ">>", "MMU_PAGE_SHIFT", ";", "pos", "+=", "MMU_PAGE_SIZE", ";", "}", "return", "pos", ";", "}" ]
thread_pdpt must be initialized, as well as all the page directories
[ "thread_pdpt", "must", "be", "initialized", "as", "well", "as", "all", "the", "page", "directories" ]
[ "/* Same as we did with the directories, obtain PT in master\n\t\t * tables for the address range and copy into per-thread PT\n\t\t * for this range\n\t\t */", "/* And then wire this up to the relevant per-thread\n\t\t * page directory entry\n\t\t */" ]
[ { "param": "pages", "type": "uintptr_t" }, { "param": "thread_pdpt", "type": "struct x86_mmu_pdpt" }, { "param": "master_pdpt", "type": "struct x86_mmu_pdpt" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pages", "type": "uintptr_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "thread_pdpt", "type": "struct x86_mmu_pdpt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "master_pdpt", "type": "struct x86_mmu_pdpt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c64cd6401f8da3d07275a0e29920cd45a97056be
metc/fw-nrfconnect-zephyr
arch/x86/core/ia32/x86_mmu.c
[ "Apache-2.0" ]
C
copy_page_tables
void
static void copy_page_tables(struct k_thread *thread, struct x86_mmu_pdpt *master_pdpt) { uintptr_t pos, start; struct x86_mmu_pdpt *thread_pdpt = z_x86_pdpt_get(thread); struct z_x86_thread_stack_header *header = (struct z_x86_thread_stack_header *)thread->stack_obj; __ASSERT(thread->stack_obj != NULL, "no stack object assigned"); __ASSERT(z_x86_page_tables_get() != thread_pdpt, "PDPT is active"); __ASSERT(((uintptr_t)thread_pdpt & 0x1f) == 0, "unaligned pdpt at %p", thread_pdpt); (void)memcpy(thread_pdpt, master_pdpt, sizeof(struct x86_mmu_pdpt)); /* pos represents the page we are working with in the reserved area * in the stack buffer for per-thread tables. As we create tables in * this area, pos is incremented to the next free page. * * The layout of the stack object, when this is done: * * +---------------------------+ <- thread->stack_obj * | PDE(0) | * +---------------------------+ * | ... | * +---------------------------+ * | PDE(Z_X86_NUM_PD - 1) | * +---------------------------+ * | PTE(0) | * +---------------------------+ * | ... | * +---------------------------+ * | PTE(Z_X86_NUM_PT - 1) | * +---------------------------+ <- pos once this logic completes * | Stack guard | * +---------------------------+ * | Privilege elevation stack | * | PDPT | * +---------------------------+ <- thread->stack_info.start * | Thread stack | * | ... | * */ start = (uintptr_t)(&header->page_tables); pos = thread_pd_create(start, thread_pdpt, master_pdpt); pos = thread_pt_create(pos, thread_pdpt, master_pdpt); __ASSERT(pos == (start + Z_X86_THREAD_PT_AREA), "wrong amount of stack object memory used"); }
/* Initialize the page tables for a thread. This will contain, once done, * the boot-time configuration for a user thread page tables. There are * no pre-conditions on the existing state of the per-thread tables. */
Initialize the page tables for a thread. This will contain, once done, the boot-time configuration for a user thread page tables. There are no pre-conditions on the existing state of the per-thread tables.
[ "Initialize", "the", "page", "tables", "for", "a", "thread", ".", "This", "will", "contain", "once", "done", "the", "boot", "-", "time", "configuration", "for", "a", "user", "thread", "page", "tables", ".", "There", "are", "no", "pre", "-", "conditions", "on", "the", "existing", "state", "of", "the", "per", "-", "thread", "tables", "." ]
static void copy_page_tables(struct k_thread *thread, struct x86_mmu_pdpt *master_pdpt) { uintptr_t pos, start; struct x86_mmu_pdpt *thread_pdpt = z_x86_pdpt_get(thread); struct z_x86_thread_stack_header *header = (struct z_x86_thread_stack_header *)thread->stack_obj; __ASSERT(thread->stack_obj != NULL, "no stack object assigned"); __ASSERT(z_x86_page_tables_get() != thread_pdpt, "PDPT is active"); __ASSERT(((uintptr_t)thread_pdpt & 0x1f) == 0, "unaligned pdpt at %p", thread_pdpt); (void)memcpy(thread_pdpt, master_pdpt, sizeof(struct x86_mmu_pdpt)); start = (uintptr_t)(&header->page_tables); pos = thread_pd_create(start, thread_pdpt, master_pdpt); pos = thread_pt_create(pos, thread_pdpt, master_pdpt); __ASSERT(pos == (start + Z_X86_THREAD_PT_AREA), "wrong amount of stack object memory used"); }
[ "static", "void", "copy_page_tables", "(", "struct", "k_thread", "*", "thread", ",", "struct", "x86_mmu_pdpt", "*", "master_pdpt", ")", "{", "uintptr_t", "pos", ",", "start", ";", "struct", "x86_mmu_pdpt", "*", "thread_pdpt", "=", "z_x86_pdpt_get", "(", "thread", ")", ";", "struct", "z_x86_thread_stack_header", "*", "header", "=", "(", "struct", "z_x86_thread_stack_header", "*", ")", "thread", "->", "stack_obj", ";", "__ASSERT", "(", "thread", "->", "stack_obj", "!=", "NULL", ",", "\"", "\"", ")", ";", "__ASSERT", "(", "z_x86_page_tables_get", "(", ")", "!=", "thread_pdpt", ",", "\"", "\"", ")", ";", "__ASSERT", "(", "(", "(", "uintptr_t", ")", "thread_pdpt", "&", "0x1f", ")", "==", "0", ",", "\"", "\"", ",", "thread_pdpt", ")", ";", "(", "void", ")", "memcpy", "(", "thread_pdpt", ",", "master_pdpt", ",", "sizeof", "(", "struct", "x86_mmu_pdpt", ")", ")", ";", "start", "=", "(", "uintptr_t", ")", "(", "&", "header", "->", "page_tables", ")", ";", "pos", "=", "thread_pd_create", "(", "start", ",", "thread_pdpt", ",", "master_pdpt", ")", ";", "pos", "=", "thread_pt_create", "(", "pos", ",", "thread_pdpt", ",", "master_pdpt", ")", ";", "__ASSERT", "(", "pos", "==", "(", "start", "+", "Z_X86_THREAD_PT_AREA", ")", ",", "\"", "\"", ")", ";", "}" ]
Initialize the page tables for a thread.
[ "Initialize", "the", "page", "tables", "for", "a", "thread", "." ]
[ "/* pos represents the page we are working with in the reserved area\n\t * in the stack buffer for per-thread tables. As we create tables in\n\t * this area, pos is incremented to the next free page.\n\t *\n\t * The layout of the stack object, when this is done:\n\t *\n\t * +---------------------------+ <- thread->stack_obj\n\t * | PDE(0) |\n\t * +---------------------------+\n\t * | ... |\n\t * +---------------------------+\n\t * | PDE(Z_X86_NUM_PD - 1) |\n\t * +---------------------------+\n\t * | PTE(0) |\n\t * +---------------------------+\n\t * | ... |\n\t * +---------------------------+\n\t * | PTE(Z_X86_NUM_PT - 1) |\n\t * +---------------------------+ <- pos once this logic completes\n\t * | Stack guard |\n\t * +---------------------------+\n\t * | Privilege elevation stack |\n\t * | PDPT |\n\t * +---------------------------+ <- thread->stack_info.start\n\t * | Thread stack |\n\t * | ... |\n\t *\n\t */" ]
[ { "param": "thread", "type": "struct k_thread" }, { "param": "master_pdpt", "type": "struct x86_mmu_pdpt" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "thread", "type": "struct k_thread", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "master_pdpt", "type": "struct x86_mmu_pdpt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c64cd6401f8da3d07275a0e29920cd45a97056be
metc/fw-nrfconnect-zephyr
arch/x86/core/ia32/x86_mmu.c
[ "Apache-2.0" ]
C
z_x86_thread_pt_init
void
void z_x86_thread_pt_init(struct k_thread *thread) { struct x86_mmu_pdpt *pdpt = z_x86_pdpt_get(thread); /* USER_PDPT contains the page tables with the boot time memory * policy. We use it as a template to set up the per-thread page * tables. * * With KPTI, this is a distinct set of tables z_x86_user_pdpt from the * kernel page tables in z_x86_kernel_pdpt; it has all non user * accessible pages except the trampoline page marked as non-present. * Without KPTI, they are the same object. */ copy_page_tables(thread, &USER_PDPT); /* Enable access to the thread's own stack buffer */ z_x86_mmu_set_flags(pdpt, (void *)thread->stack_info.start, ROUND_UP(thread->stack_info.size, MMU_PAGE_SIZE), MMU_ENTRY_PRESENT | K_MEM_PARTITION_P_RW_U_RW, MMU_PTE_P_MASK | K_MEM_PARTITION_PERM_MASK, false); }
/* Called on creation of a user thread or when a supervisor thread drops to * user mode. * * Sets up the per-thread page tables, such that when they are activated on * context switch, everything is ready to go. */
Called on creation of a user thread or when a supervisor thread drops to user mode. Sets up the per-thread page tables, such that when they are activated on context switch, everything is ready to go.
[ "Called", "on", "creation", "of", "a", "user", "thread", "or", "when", "a", "supervisor", "thread", "drops", "to", "user", "mode", ".", "Sets", "up", "the", "per", "-", "thread", "page", "tables", "such", "that", "when", "they", "are", "activated", "on", "context", "switch", "everything", "is", "ready", "to", "go", "." ]
void z_x86_thread_pt_init(struct k_thread *thread) { struct x86_mmu_pdpt *pdpt = z_x86_pdpt_get(thread); copy_page_tables(thread, &USER_PDPT); z_x86_mmu_set_flags(pdpt, (void *)thread->stack_info.start, ROUND_UP(thread->stack_info.size, MMU_PAGE_SIZE), MMU_ENTRY_PRESENT | K_MEM_PARTITION_P_RW_U_RW, MMU_PTE_P_MASK | K_MEM_PARTITION_PERM_MASK, false); }
[ "void", "z_x86_thread_pt_init", "(", "struct", "k_thread", "*", "thread", ")", "{", "struct", "x86_mmu_pdpt", "*", "pdpt", "=", "z_x86_pdpt_get", "(", "thread", ")", ";", "copy_page_tables", "(", "thread", ",", "&", "USER_PDPT", ")", ";", "z_x86_mmu_set_flags", "(", "pdpt", ",", "(", "void", "*", ")", "thread", "->", "stack_info", ".", "start", ",", "ROUND_UP", "(", "thread", "->", "stack_info", ".", "size", ",", "MMU_PAGE_SIZE", ")", ",", "MMU_ENTRY_PRESENT", "|", "K_MEM_PARTITION_P_RW_U_RW", ",", "MMU_PTE_P_MASK", "|", "K_MEM_PARTITION_PERM_MASK", ",", "false", ")", ";", "}" ]
Called on creation of a user thread or when a supervisor thread drops to user mode.
[ "Called", "on", "creation", "of", "a", "user", "thread", "or", "when", "a", "supervisor", "thread", "drops", "to", "user", "mode", "." ]
[ "/* USER_PDPT contains the page tables with the boot time memory\n\t * policy. We use it as a template to set up the per-thread page\n\t * tables.\n\t *\n\t * With KPTI, this is a distinct set of tables z_x86_user_pdpt from the\n\t * kernel page tables in z_x86_kernel_pdpt; it has all non user\n\t * accessible pages except the trampoline page marked as non-present.\n\t * Without KPTI, they are the same object.\n\t */", "/* Enable access to the thread's own stack buffer */" ]
[ { "param": "thread", "type": "struct k_thread" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "thread", "type": "struct k_thread", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0fe0a5cb203e2b1b4cf07b2bfd9e948e45fcc70e
trisulnsm/piranha
src/p_sqldump.c
[ "Apache-2.0" ]
C
p_sqldump_check_file
void
void p_sqldump_check_file(struct peer_t *peer, int id, struct timeval *ts) { if (strlen(peer[id].sqldbname) == 0 ) { p_sqldump_open_file(peer,id,ts); } }
/* check if need to reopen a new file */
check if need to reopen a new file
[ "check", "if", "need", "to", "reopen", "a", "new", "file" ]
void p_sqldump_check_file(struct peer_t *peer, int id, struct timeval *ts) { if (strlen(peer[id].sqldbname) == 0 ) { p_sqldump_open_file(peer,id,ts); } }
[ "void", "p_sqldump_check_file", "(", "struct", "peer_t", "*", "peer", ",", "int", "id", ",", "struct", "timeval", "*", "ts", ")", "{", "if", "(", "strlen", "(", "peer", "[", "id", "]", ".", "sqldbname", ")", "==", "0", ")", "{", "p_sqldump_open_file", "(", "peer", ",", "id", ",", "ts", ")", ";", "}", "}" ]
check if need to reopen a new file
[ "check", "if", "need", "to", "reopen", "a", "new", "file" ]
[]
[ { "param": "peer", "type": "struct peer_t" }, { "param": "id", "type": "int" }, { "param": "ts", "type": "struct timeval" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "peer", "type": "struct peer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "id", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ts", "type": "struct timeval", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5dd1995078c46efbb5f67d7642c8b64a33ad645f
fjuma/test-again
libwfssl/src/clientcert.c
[ "Apache-2.0" ]
C
SSL_callback_SSL_verify
int
int SSL_callback_SSL_verify(int ok, X509_STORE_CTX *ctx) { /* Get Apache context back through OpenSSL context */ SSL *ssl = crypto_methods.X509_STORE_CTX_get_ex_data(ctx, ssl_methods.SSL_get_ex_data_X509_STORE_CTX_idx()); tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)ssl_methods.SSL_get_ex_data(ssl, 0); /* Get verify ingredients */ int errnum = crypto_methods.X509_STORE_CTX_get_error(ctx); int errdepth = crypto_methods.X509_STORE_CTX_get_error_depth(ctx); int verify = con->ctx->verify_mode; int depth = con->ctx->verify_depth; if (verify == SSL_CVERIFY_UNSET || verify == SSL_CVERIFY_NONE) return 1; if (SSL_VERIFY_ERROR_IS_OPTIONAL(errnum) && (verify == SSL_CVERIFY_OPTIONAL_NO_CA)) { ok = 1; ssl_methods.SSL_set_verify_result(ssl, X509_V_OK); } #ifdef HAVE_OCSP_STAPLING /* First perform OCSP validation if possible */ if (ok) { /* If there was an optional verification error, it's not * possible to perform OCSP validation since the issuer may be * missing/untrusted. Fail in that case. */ if (SSL_VERIFY_ERROR_IS_OPTIONAL(errnum)) { crypto_methods.X509_STORE_CTX_set_error(ctx, X509_V_ERR_APPLICATION_VERIFICATION); errnum = X509_V_ERR_APPLICATION_VERIFICATION; ok = 0; } else { int ocsp_response = ssl_verify_OCSP(ok, ctx); if (ocsp_response == OCSP_STATUS_OK) { skip_crl = 1; /* we know it is valid we skip crl evaluation */ } else if (ocsp_response == OCSP_STATUS_REVOKED) { ok = 0 ; errnum = crypto_methods.X509_STORE_CTX_get_error(ctx); } else if (ocsp_response == OCSP_STATUS_UNKNOWN) { /* TODO: do nothing for time being, continue with CRL */ ; } } } #endif /* * If we already know it's not ok, log the real reason */ if (!ok) { /* TODO: Some logging * Certificate Verification: Error */ if (con->peer) { crypto_methods.X509_free(con->peer); con->peer = NULL; } } if (errdepth > depth) { /* TODO: Some logging * Certificate Verification: Certificate Chain too long */ ok = 0; } return ok; }
/* * This OpenSSL callback function is called when OpenSSL * does client authentication and verifies the certificate chain. */
This OpenSSL callback function is called when OpenSSL does client authentication and verifies the certificate chain.
[ "This", "OpenSSL", "callback", "function", "is", "called", "when", "OpenSSL", "does", "client", "authentication", "and", "verifies", "the", "certificate", "chain", "." ]
int SSL_callback_SSL_verify(int ok, X509_STORE_CTX *ctx) { SSL *ssl = crypto_methods.X509_STORE_CTX_get_ex_data(ctx, ssl_methods.SSL_get_ex_data_X509_STORE_CTX_idx()); tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)ssl_methods.SSL_get_ex_data(ssl, 0); int errnum = crypto_methods.X509_STORE_CTX_get_error(ctx); int errdepth = crypto_methods.X509_STORE_CTX_get_error_depth(ctx); int verify = con->ctx->verify_mode; int depth = con->ctx->verify_depth; if (verify == SSL_CVERIFY_UNSET || verify == SSL_CVERIFY_NONE) return 1; if (SSL_VERIFY_ERROR_IS_OPTIONAL(errnum) && (verify == SSL_CVERIFY_OPTIONAL_NO_CA)) { ok = 1; ssl_methods.SSL_set_verify_result(ssl, X509_V_OK); } #ifdef HAVE_OCSP_STAPLING if (ok) { if (SSL_VERIFY_ERROR_IS_OPTIONAL(errnum)) { crypto_methods.X509_STORE_CTX_set_error(ctx, X509_V_ERR_APPLICATION_VERIFICATION); errnum = X509_V_ERR_APPLICATION_VERIFICATION; ok = 0; } else { int ocsp_response = ssl_verify_OCSP(ok, ctx); if (ocsp_response == OCSP_STATUS_OK) { skip_crl = 1; } else if (ocsp_response == OCSP_STATUS_REVOKED) { ok = 0 ; errnum = crypto_methods.X509_STORE_CTX_get_error(ctx); } else if (ocsp_response == OCSP_STATUS_UNKNOWN) { ; } } } #endif if (!ok) { if (con->peer) { crypto_methods.X509_free(con->peer); con->peer = NULL; } } if (errdepth > depth) { ok = 0; } return ok; }
[ "int", "SSL_callback_SSL_verify", "(", "int", "ok", ",", "X509_STORE_CTX", "*", "ctx", ")", "{", "SSL", "*", "ssl", "=", "crypto_methods", ".", "X509_STORE_CTX_get_ex_data", "(", "ctx", ",", "ssl_methods", ".", "SSL_get_ex_data_X509_STORE_CTX_idx", "(", ")", ")", ";", "tcn_ssl_conn_t", "*", "con", "=", "(", "tcn_ssl_conn_t", "*", ")", "ssl_methods", ".", "SSL_get_ex_data", "(", "ssl", ",", "0", ")", ";", "int", "errnum", "=", "crypto_methods", ".", "X509_STORE_CTX_get_error", "(", "ctx", ")", ";", "int", "errdepth", "=", "crypto_methods", ".", "X509_STORE_CTX_get_error_depth", "(", "ctx", ")", ";", "int", "verify", "=", "con", "->", "ctx", "->", "verify_mode", ";", "int", "depth", "=", "con", "->", "ctx", "->", "verify_depth", ";", "if", "(", "verify", "==", "SSL_CVERIFY_UNSET", "||", "verify", "==", "SSL_CVERIFY_NONE", ")", "return", "1", ";", "if", "(", "SSL_VERIFY_ERROR_IS_OPTIONAL", "(", "errnum", ")", "&&", "(", "verify", "==", "SSL_CVERIFY_OPTIONAL_NO_CA", ")", ")", "{", "ok", "=", "1", ";", "ssl_methods", ".", "SSL_set_verify_result", "(", "ssl", ",", "X509_V_OK", ")", ";", "}", "#ifdef", "HAVE_OCSP_STAPLING", "if", "(", "ok", ")", "{", "if", "(", "SSL_VERIFY_ERROR_IS_OPTIONAL", "(", "errnum", ")", ")", "{", "crypto_methods", ".", "X509_STORE_CTX_set_error", "(", "ctx", ",", "X509_V_ERR_APPLICATION_VERIFICATION", ")", ";", "errnum", "=", "X509_V_ERR_APPLICATION_VERIFICATION", ";", "ok", "=", "0", ";", "}", "else", "{", "int", "ocsp_response", "=", "ssl_verify_OCSP", "(", "ok", ",", "ctx", ")", ";", "if", "(", "ocsp_response", "==", "OCSP_STATUS_OK", ")", "{", "skip_crl", "=", "1", ";", "}", "else", "if", "(", "ocsp_response", "==", "OCSP_STATUS_REVOKED", ")", "{", "ok", "=", "0", ";", "errnum", "=", "crypto_methods", ".", "X509_STORE_CTX_get_error", "(", "ctx", ")", ";", "}", "else", "if", "(", "ocsp_response", "==", "OCSP_STATUS_UNKNOWN", ")", "{", ";", "}", "}", "}", "#endif", "if", "(", "!", "ok", ")", "{", "if", "(", "con", "->", "peer", ")", "{", "crypto_methods", ".", "X509_free", "(", "con", "->", "peer", ")", ";", "con", "->", "peer", "=", "NULL", ";", "}", "}", "if", "(", "errdepth", ">", "depth", ")", "{", "ok", "=", "0", ";", "}", "return", "ok", ";", "}" ]
This OpenSSL callback function is called when OpenSSL does client authentication and verifies the certificate chain.
[ "This", "OpenSSL", "callback", "function", "is", "called", "when", "OpenSSL", "does", "client", "authentication", "and", "verifies", "the", "certificate", "chain", "." ]
[ "/* Get Apache context back through OpenSSL context */", "/* Get verify ingredients */", "/* First perform OCSP validation if possible */", "/* If there was an optional verification error, it's not\n * possible to perform OCSP validation since the issuer may be\n * missing/untrusted. Fail in that case.\n */", "/* we know it is valid we skip crl evaluation */", "/* TODO: do nothing for time being, continue with CRL */", "/*\n * If we already know it's not ok, log the real reason\n */", "/* TODO: Some logging\n * Certificate Verification: Error\n */", "/* TODO: Some logging\n * Certificate Verification: Certificate Chain too long\n */" ]
[ { "param": "ok", "type": "int" }, { "param": "ctx", "type": "X509_STORE_CTX" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ok", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ctx", "type": "X509_STORE_CTX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
13c53d0f97a4214dc29e7f8e9dba52515fabd1dd
chikashimiyama/Peacock_classic
peacock_bup.c
[ "MIT" ]
C
spiX_put
char
char spiX_put( unsigned char val ) { // Check if transmission in progress, // i.e. USI counter unequal to zero. if( (USISR & 0x0F) != 0 ) { // Indicate write collision and return. spiX_status.writeCollision = 1; return 1; } // Reinit flags. spiX_status.transferComplete = 0; spiX_status.writeCollision = 0; // Put data in USI data register. USIDR = val; // Master should now enable compare match interrupts. if( spiX_status.masterMode == 1 ) { TIFR |= (1<<OCF0A); // Clear compare match flag. TIMSK |= (1<<OCIE0A); // Enable compare match interrupt. } if( spiX_status.writeCollision == 0 ) return 1; return 0; }
/*! \brief Put one byte on bus. * * Use this function like you would write to the SPDR register in the native SPI module. * Calling this function in master mode starts a transfer, while in slave mode, a * byte will be prepared for the next transfer initiated by the master device. * If a transfer is in progress, this function will set the write collision flag * and return without altering the data registers. * * \returns 0 if a write collision occurred, 1 otherwise. */
\brief Put one byte on bus. Use this function like you would write to the SPDR register in the native SPI module. Calling this function in master mode starts a transfer, while in slave mode, a byte will be prepared for the next transfer initiated by the master device. If a transfer is in progress, this function will set the write collision flag and return without altering the data registers. \returns 0 if a write collision occurred, 1 otherwise.
[ "\\", "brief", "Put", "one", "byte", "on", "bus", ".", "Use", "this", "function", "like", "you", "would", "write", "to", "the", "SPDR", "register", "in", "the", "native", "SPI", "module", ".", "Calling", "this", "function", "in", "master", "mode", "starts", "a", "transfer", "while", "in", "slave", "mode", "a", "byte", "will", "be", "prepared", "for", "the", "next", "transfer", "initiated", "by", "the", "master", "device", ".", "If", "a", "transfer", "is", "in", "progress", "this", "function", "will", "set", "the", "write", "collision", "flag", "and", "return", "without", "altering", "the", "data", "registers", ".", "\\", "returns", "0", "if", "a", "write", "collision", "occurred", "1", "otherwise", "." ]
char spiX_put( unsigned char val ) { if( (USISR & 0x0F) != 0 ) { spiX_status.writeCollision = 1; return 1; } spiX_status.transferComplete = 0; spiX_status.writeCollision = 0; USIDR = val; if( spiX_status.masterMode == 1 ) { TIFR |= (1<<OCF0A); TIMSK |= (1<<OCIE0A); } if( spiX_status.writeCollision == 0 ) return 1; return 0; }
[ "char", "spiX_put", "(", "unsigned", "char", "val", ")", "{", "if", "(", "(", "USISR", "&", "0x0F", ")", "!=", "0", ")", "{", "spiX_status", ".", "writeCollision", "=", "1", ";", "return", "1", ";", "}", "spiX_status", ".", "transferComplete", "=", "0", ";", "spiX_status", ".", "writeCollision", "=", "0", ";", "USIDR", "=", "val", ";", "if", "(", "spiX_status", ".", "masterMode", "==", "1", ")", "{", "TIFR", "|=", "(", "1", "<<", "OCF0A", ")", ";", "TIMSK", "|=", "(", "1", "<<", "OCIE0A", ")", ";", "}", "if", "(", "spiX_status", ".", "writeCollision", "==", "0", ")", "return", "1", ";", "return", "0", ";", "}" ]
\brief Put one byte on bus.
[ "\\", "brief", "Put", "one", "byte", "on", "bus", "." ]
[ "// Check if transmission in progress,", "// i.e. USI counter unequal to zero.", "// Indicate write collision and return.", "// Reinit flags.", "// Put data in USI data register.", "// Master should now enable compare match interrupts.", "// Clear compare match flag.", "// Enable compare match interrupt." ]
[ { "param": "val", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "val", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c15b5d6bfe1a0a51b86215a21e921fefc533c84d
philrawlings/bluepill-usb-cdc-test
USB_DEVICE/App/usb_device.c
[ "MIT" ]
C
MX_USB_DEVICE_Init
void
void MX_USB_DEVICE_Init(void) { /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ // Force host to re-enumerate the device. The blue pill has a pull up resistor on the // USB_DP (PA12) line, so we set it low initially. GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); HAL_Delay(100); /* USER CODE END USB_DEVICE_Init_PreTreatment */ /* Init Device Library, add supported class and start the library. */ if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) { Error_Handler(); } if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { Error_Handler(); } if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { Error_Handler(); } if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { Error_Handler(); } /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ /* USER CODE END USB_DEVICE_Init_PostTreatment */ }
/** * Init USB device Library, add supported class and start the library * @retval None */
Init USB device Library, add supported class and start the library @retval None
[ "Init", "USB", "device", "Library", "add", "supported", "class", "and", "start", "the", "library", "@retval", "None" ]
void MX_USB_DEVICE_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); HAL_Delay(100); if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) { Error_Handler(); } if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { Error_Handler(); } if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { Error_Handler(); } if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { Error_Handler(); } }
[ "void", "MX_USB_DEVICE_Init", "(", "void", ")", "{", "GPIO_InitTypeDef", "GPIO_InitStruct", "=", "{", "0", "}", ";", "GPIO_InitStruct", ".", "Pin", "=", "GPIO_PIN_12", ";", "GPIO_InitStruct", ".", "Mode", "=", "GPIO_MODE_OUTPUT_PP", ";", "GPIO_InitStruct", ".", "Pull", "=", "GPIO_PULLDOWN", ";", "GPIO_InitStruct", ".", "Speed", "=", "GPIO_SPEED_HIGH", ";", "HAL_GPIO_Init", "(", "GPIOA", ",", "&", "GPIO_InitStruct", ")", ";", "HAL_GPIO_WritePin", "(", "GPIOA", ",", "GPIO_PIN_12", ",", "GPIO_PIN_RESET", ")", ";", "HAL_Delay", "(", "100", ")", ";", "if", "(", "USBD_Init", "(", "&", "hUsbDeviceFS", ",", "&", "FS_Desc", ",", "DEVICE_FS", ")", "!=", "USBD_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "if", "(", "USBD_RegisterClass", "(", "&", "hUsbDeviceFS", ",", "&", "USBD_CDC", ")", "!=", "USBD_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "if", "(", "USBD_CDC_RegisterInterface", "(", "&", "hUsbDeviceFS", ",", "&", "USBD_Interface_fops_FS", ")", "!=", "USBD_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "if", "(", "USBD_Start", "(", "&", "hUsbDeviceFS", ")", "!=", "USBD_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
Init USB device Library, add supported class and start the library @retval None
[ "Init", "USB", "device", "Library", "add", "supported", "class", "and", "start", "the", "library", "@retval", "None" ]
[ "/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */", "// Force host to re-enumerate the device. The blue pill has a pull up resistor on the", "// USB_DP (PA12) line, so we set it low initially.", "/* USER CODE END USB_DEVICE_Init_PreTreatment */", "/* Init Device Library, add supported class and start the library. */", "/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */", "/* USER CODE END USB_DEVICE_Init_PostTreatment */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
9f4a5a0fea7598c819973f70d521ea29bc07febe
philrawlings/bluepill-usb-cdc-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_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); /*Configure GPIO pin : LED_Pin */ GPIO_InitStruct.Pin = LED_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LED_GPIO_Port, &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_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); GPIO_InitStruct.Pin = LED_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct); }
[ "static", "void", "MX_GPIO_Init", "(", "void", ")", "{", "GPIO_InitTypeDef", "GPIO_InitStruct", "=", "{", "0", "}", ";", "__HAL_RCC_GPIOC_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_GPIOD_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_GPIOA_CLK_ENABLE", "(", ")", ";", "HAL_GPIO_WritePin", "(", "LED_GPIO_Port", ",", "LED_Pin", ",", "GPIO_PIN_RESET", ")", ";", "GPIO_InitStruct", ".", "Pin", "=", "LED_Pin", ";", "GPIO_InitStruct", ".", "Mode", "=", "GPIO_MODE_OUTPUT_PP", ";", "GPIO_InitStruct", ".", "Pull", "=", "GPIO_PULLUP", ";", "GPIO_InitStruct", ".", "Speed", "=", "GPIO_SPEED_FREQ_LOW", ";", "HAL_GPIO_Init", "(", "LED_GPIO_Port", ",", "&", "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 pin : LED_Pin */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
59ffda6fac0d55dcc35c37b7988b500500087d92
LoveKino/my-knowledge-learning-atlas
algorithm/introduction to algorithms/raw/algo_indroduce/part1/mediansAndOrderStatistics.c
[ "MIT" ]
C
partition
int
int partition(int * A, int p, int r) { int key = A[r]; int i = p - 1; for(int j = p; j <= r - 1; j++) { if(A[j] <= key) { i++; swap(A, i, j); } } swap(A, i + 1, r); return i + 1; }
/** * ith order statistic of a set of n elements is the ith smallest element. * * input: A[0..n-1] and i * output: x in A and is larger than exactly i - 1 other elements of A */
ith order statistic of a set of n elements is the ith smallest element. input: A[0..n-1] and i output: x in A and is larger than exactly i - 1 other elements of A
[ "ith", "order", "statistic", "of", "a", "set", "of", "n", "elements", "is", "the", "ith", "smallest", "element", ".", "input", ":", "A", "[", "0", "..", "n", "-", "1", "]", "and", "i", "output", ":", "x", "in", "A", "and", "is", "larger", "than", "exactly", "i", "-", "1", "other", "elements", "of", "A" ]
int partition(int * A, int p, int r) { int key = A[r]; int i = p - 1; for(int j = p; j <= r - 1; j++) { if(A[j] <= key) { i++; swap(A, i, j); } } swap(A, i + 1, r); return i + 1; }
[ "int", "partition", "(", "int", "*", "A", ",", "int", "p", ",", "int", "r", ")", "{", "int", "key", "=", "A", "[", "r", "]", ";", "int", "i", "=", "p", "-", "1", ";", "for", "(", "int", "j", "=", "p", ";", "j", "<=", "r", "-", "1", ";", "j", "++", ")", "{", "if", "(", "A", "[", "j", "]", "<=", "key", ")", "{", "i", "++", ";", "swap", "(", "A", ",", "i", ",", "j", ")", ";", "}", "}", "swap", "(", "A", ",", "i", "+", "1", ",", "r", ")", ";", "return", "i", "+", "1", ";", "}" ]
ith order statistic of a set of n elements is the ith smallest element.
[ "ith", "order", "statistic", "of", "a", "set", "of", "n", "elements", "is", "the", "ith", "smallest", "element", "." ]
[]
[ { "param": "A", "type": "int" }, { "param": "p", "type": "int" }, { "param": "r", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "A", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "r", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bac51b7504ea52064477f6bf9541f45459201d36
vaisakh806/xdialserver
server/plat/gdial-plat-app.c
[ "BSD-2-Clause" ]
C
gdial_plat_application_start
GDialAppError
GDialAppError gdial_plat_application_start(const gchar *app_name, const gchar *payload, const gchar *query, const gchar *additional_data_url, gint *instance_id) { g_return_val_if_fail(app_name != NULL, GDIAL_APP_ERROR_BAD_REQUEST); g_return_val_if_fail(instance_id != NULL, GDIAL_APP_ERROR_BAD_REQUEST); /* * Different app have different cmdline arguments and formats. */ return gdial_os_application_start(app_name, payload, query, additional_data_url, instance_id); }
/* * upon return, the app must be in running state. An immediate 2nd invocation of this API * for singleton app should not cause a 2nd instance. */
upon return, the app must be in running state. An immediate 2nd invocation of this API for singleton app should not cause a 2nd instance.
[ "upon", "return", "the", "app", "must", "be", "in", "running", "state", ".", "An", "immediate", "2nd", "invocation", "of", "this", "API", "for", "singleton", "app", "should", "not", "cause", "a", "2nd", "instance", "." ]
GDialAppError gdial_plat_application_start(const gchar *app_name, const gchar *payload, const gchar *query, const gchar *additional_data_url, gint *instance_id) { g_return_val_if_fail(app_name != NULL, GDIAL_APP_ERROR_BAD_REQUEST); g_return_val_if_fail(instance_id != NULL, GDIAL_APP_ERROR_BAD_REQUEST); return gdial_os_application_start(app_name, payload, query, additional_data_url, instance_id); }
[ "GDialAppError", "gdial_plat_application_start", "(", "const", "gchar", "*", "app_name", ",", "const", "gchar", "*", "payload", ",", "const", "gchar", "*", "query", ",", "const", "gchar", "*", "additional_data_url", ",", "gint", "*", "instance_id", ")", "{", "g_return_val_if_fail", "(", "app_name", "!=", "NULL", ",", "GDIAL_APP_ERROR_BAD_REQUEST", ")", ";", "g_return_val_if_fail", "(", "instance_id", "!=", "NULL", ",", "GDIAL_APP_ERROR_BAD_REQUEST", ")", ";", "return", "gdial_os_application_start", "(", "app_name", ",", "payload", ",", "query", ",", "additional_data_url", ",", "instance_id", ")", ";", "}" ]
upon return, the app must be in running state.
[ "upon", "return", "the", "app", "must", "be", "in", "running", "state", "." ]
[ "/*\n * Different app have different cmdline arguments and formats.\n */" ]
[ { "param": "app_name", "type": "gchar" }, { "param": "payload", "type": "gchar" }, { "param": "query", "type": "gchar" }, { "param": "additional_data_url", "type": "gchar" }, { "param": "instance_id", "type": "gint" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "app_name", "type": "gchar", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "payload", "type": "gchar", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "query", "type": "gchar", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "additional_data_url", "type": "gchar", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "instance_id", "type": "gint", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9c2e3d4dc1e3e6d331a22596760690266b791a7b
XenizoGames/algos_and_ds
CI/ch1_7_rotate_matrix_90.c
[ "MIT" ]
C
rotate
void
void rotate(int matrix[][3], int matrixSize, int* matrixColSize){ int tmp = 0; //How many rows to process //3x3 - only outer matrix (same for 2x2 and 1x1) //4x4 - outer matrix and inner matrix (same for 5x5) //6x6 - int totalRowsToProcess = *matrixColSize < 3 ? 1 : *matrixColSize / 2; int row = 0; while (row < totalRowsToProcess) { int currRow = row; for (int i=row; i < (matrixSize-1-row); i++) { //(0,0) curr=1 int currCol = i; int currVal = matrix[currRow][currCol]; //4 times to rotate 90deg (360 / 90 = 4) for (int j=0; j < 4; j++) { //(0,2) = 1 int nextRow = currCol; int nextCol = matrixSize - currRow - 1; //printf ("\n currRowCol %d,%d: ", currRow,currCol); //printf ("\n nextRowCol %d,%d: ", nextRow,nextCol); //Get current spot and next spot int nextVal = matrix[nextRow][nextCol]; tmp = nextVal; //tmp = 3 matrix[nextRow][nextCol] = currVal; //next = 1 currVal = tmp; currRow = nextRow; currCol = nextCol; } } row++; } }
//In place matrix rotation //Assume - Always square
In place matrix rotation Assume - Always square
[ "In", "place", "matrix", "rotation", "Assume", "-", "Always", "square" ]
void rotate(int matrix[][3], int matrixSize, int* matrixColSize){ int tmp = 0; int totalRowsToProcess = *matrixColSize < 3 ? 1 : *matrixColSize / 2; int row = 0; while (row < totalRowsToProcess) { int currRow = row; for (int i=row; i < (matrixSize-1-row); i++) { int currCol = i; int currVal = matrix[currRow][currCol]; for (int j=0; j < 4; j++) { int nextRow = currCol; int nextCol = matrixSize - currRow - 1; int nextVal = matrix[nextRow][nextCol]; tmp = nextVal; matrix[nextRow][nextCol] = currVal; currVal = tmp; currRow = nextRow; currCol = nextCol; } } row++; } }
[ "void", "rotate", "(", "int", "matrix", "[", "]", "[", "3", "]", ",", "int", "matrixSize", ",", "int", "*", "matrixColSize", ")", "{", "int", "tmp", "=", "0", ";", "int", "totalRowsToProcess", "=", "*", "matrixColSize", "<", "3", "?", "1", ":", "*", "matrixColSize", "/", "2", ";", "int", "row", "=", "0", ";", "while", "(", "row", "<", "totalRowsToProcess", ")", "{", "int", "currRow", "=", "row", ";", "for", "(", "int", "i", "=", "row", ";", "i", "<", "(", "matrixSize", "-", "1", "-", "row", ")", ";", "i", "++", ")", "{", "int", "currCol", "=", "i", ";", "int", "currVal", "=", "matrix", "[", "currRow", "]", "[", "currCol", "]", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "4", ";", "j", "++", ")", "{", "int", "nextRow", "=", "currCol", ";", "int", "nextCol", "=", "matrixSize", "-", "currRow", "-", "1", ";", "int", "nextVal", "=", "matrix", "[", "nextRow", "]", "[", "nextCol", "]", ";", "tmp", "=", "nextVal", ";", "matrix", "[", "nextRow", "]", "[", "nextCol", "]", "=", "currVal", ";", "currVal", "=", "tmp", ";", "currRow", "=", "nextRow", ";", "currCol", "=", "nextCol", ";", "}", "}", "row", "++", ";", "}", "}" ]
In place matrix rotation Assume - Always square
[ "In", "place", "matrix", "rotation", "Assume", "-", "Always", "square" ]
[ "//How many rows to process", "//3x3 - only outer matrix (same for 2x2 and 1x1)", "//4x4 - outer matrix and inner matrix (same for 5x5)", "//6x6 - ", "//(0,0) curr=1", "//4 times to rotate 90deg (360 / 90 = 4)", "//(0,2) = 1", "//printf (\"\\n currRowCol %d,%d: \", currRow,currCol);", "//printf (\"\\n nextRowCol %d,%d: \", nextRow,nextCol);", "//Get current spot and next spot", "//tmp = 3", "//next = 1" ]
[ { "param": "matrix", "type": "int" }, { "param": "matrixSize", "type": "int" }, { "param": "matrixColSize", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "matrix", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "matrixSize", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "matrixColSize", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
87bccefb4fed1b3082c9eafad2211eb3e097b17d
smartanthill/smartanthill1_0-embedded
src/crc.c
[ "MIT" ]
C
crc_update
crc_t
crc_t crc_update(crc_t crc, const unsigned char *data, size_t data_len) { unsigned int tbl_idx; while (data_len--) { tbl_idx = crc ^ (*data >> (0 * 4)); crc = crc_table[tbl_idx & 0x0f] ^ (crc >> 4); tbl_idx = crc ^ (*data >> (1 * 4)); crc = crc_table[tbl_idx & 0x0f] ^ (crc >> 4); data++; } return crc & 0xffff; }
/** * Update the crc value with new data. * * \param crc The current crc value. * \param data Pointer to a buffer of \a data_len bytes. * \param data_len Number of bytes in the \a data buffer. * \return The updated crc value. *****************************************************************************/
Update the crc value with new data. \param crc The current crc value. \param data Pointer to a buffer of \a data_len bytes. \param data_len Number of bytes in the \a data buffer. \return The updated crc value.
[ "Update", "the", "crc", "value", "with", "new", "data", ".", "\\", "param", "crc", "The", "current", "crc", "value", ".", "\\", "param", "data", "Pointer", "to", "a", "buffer", "of", "\\", "a", "data_len", "bytes", ".", "\\", "param", "data_len", "Number", "of", "bytes", "in", "the", "\\", "a", "data", "buffer", ".", "\\", "return", "The", "updated", "crc", "value", "." ]
crc_t crc_update(crc_t crc, const unsigned char *data, size_t data_len) { unsigned int tbl_idx; while (data_len--) { tbl_idx = crc ^ (*data >> (0 * 4)); crc = crc_table[tbl_idx & 0x0f] ^ (crc >> 4); tbl_idx = crc ^ (*data >> (1 * 4)); crc = crc_table[tbl_idx & 0x0f] ^ (crc >> 4); data++; } return crc & 0xffff; }
[ "crc_t", "crc_update", "(", "crc_t", "crc", ",", "const", "unsigned", "char", "*", "data", ",", "size_t", "data_len", ")", "{", "unsigned", "int", "tbl_idx", ";", "while", "(", "data_len", "--", ")", "{", "tbl_idx", "=", "crc", "^", "(", "*", "data", ">>", "(", "0", "*", "4", ")", ")", ";", "crc", "=", "crc_table", "[", "tbl_idx", "&", "0x0f", "]", "^", "(", "crc", ">>", "4", ")", ";", "tbl_idx", "=", "crc", "^", "(", "*", "data", ">>", "(", "1", "*", "4", ")", ")", ";", "crc", "=", "crc_table", "[", "tbl_idx", "&", "0x0f", "]", "^", "(", "crc", ">>", "4", ")", ";", "data", "++", ";", "}", "return", "crc", "&", "0xffff", ";", "}" ]
Update the crc value with new data.
[ "Update", "the", "crc", "value", "with", "new", "data", "." ]
[]
[ { "param": "crc", "type": "crc_t" }, { "param": "data", "type": "unsigned char" }, { "param": "data_len", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "crc", "type": "crc_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data_len", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
258fcf02b77b0b1038c2d2e87ef85f1c290310d4
CJ-783/osmud
src/mud_manager.c
[ "Apache-2.0" ]
C
executeNewDhcpAction
void
void executeNewDhcpAction(DhcpEvent *dhcpEvent) { char logMsgBuf[4096]; buildDhcpEventContext(logMsgBuf, "NEW", dhcpEvent); logOmsGeneralMessage(OMS_INFO, OMS_SUBSYS_GENERAL, logMsgBuf); if ((dhcpEvent) && (dhcpEvent->mudFileURL)) { dhcpEvent->mudSigURL = createSigUrlFromMudUrl(dhcpEvent->mudFileURL); dhcpEvent->mudFileStorageLocation = createStorageLocation(dhcpEvent->mudFileURL); dhcpEvent->mudSigFileStorageLocation = createStorageLocation(dhcpEvent->mudSigURL); /* We are processing a MUD aware device. Go to the MUD file server and get the usage description */ /* non-zero return code indicates error during communications */ /* Mud files and signature files are stored in their computed storage locations for future reference */ if (!getOpenMudFile(dhcpEvent->mudFileURL, dhcpEvent->mudFileStorageLocation)) { /* For debugging purposes only, allow the p7s verification to be optional when the "-i" option * is provided. This feature will be removed from a future release and is only provided now * until certificates compatible with OPENSSL CMS VERIFY commands are in ready use. */ if ((!getOpenMudFile(dhcpEvent->mudSigURL, dhcpEvent->mudSigFileStorageLocation)) || (noFailOnMudValidation)) { logOmsGeneralMessage(OMS_DEBUG, OMS_SUBSYS_MUD_FILE, "IN ****NEW**** MUD and SIG FILE RETRIEVED!!!"); if ((validateMudFileWithSig(dhcpEvent) == VALID_MUD_FILE_SIG) || (noFailOnMudValidation)) { /* * All files downloaded and signature valid. * CALL INTERFACE TO CARRY OUT MUD ACTION HERE */ executeMudWithDhcpContext(dhcpEvent); installMudDbDeviceEntry(mudFileDataDirectory, dhcpEvent->ipAddress, dhcpEvent->macAddress, dhcpEvent->mudFileURL, dhcpEvent->mudFileStorageLocation, dhcpEvent->hostName); } else { logOmsGeneralMessage(OMS_ERROR, OMS_SUBSYS_MUD_FILE, "ERROR: ****NEW**** BAD SIGNATURE - FAILED VALIDATION!!!"); } } else { logOmsGeneralMessage(OMS_ERROR, OMS_SUBSYS_MUD_FILE, "ERROR: ****NEW**** NO SIG FILE RETRIEVED!!!"); } } else { logOmsGeneralMessage(OMS_ERROR, OMS_SUBSYS_MUD_FILE, "ERROR: ****NEW**** NO MUD FILE RETRIEVED!!!"); } } else { /* This is a legacy non-MUD aware device. */ logOmsGeneralMessage(OMS_DEBUG, OMS_SUBSYS_MUD_FILE, "IN ****NEW**** LEGACY DEVICE -- no mud file declared."); doDhcpLegacyAction(dhcpEvent); installMudDbDeviceEntry(mudFileDataDirectory, dhcpEvent->ipAddress, dhcpEvent->macAddress, NULL, NULL, dhcpEvent->hostName); } }
/* * This takes a DHCP event and performs the following: * 1) Validates the MUD file (maybe via yanglint when spec is finalized) * 2) parses the MUD file into a OSMUD data structure representing the MUD file * 3) Calls the device specific implementations to implement the features in the mud file */
This takes a DHCP event and performs the following: 1) Validates the MUD file (maybe via yanglint when spec is finalized) 2) parses the MUD file into a OSMUD data structure representing the MUD file 3) Calls the device specific implementations to implement the features in the mud file
[ "This", "takes", "a", "DHCP", "event", "and", "performs", "the", "following", ":", "1", ")", "Validates", "the", "MUD", "file", "(", "maybe", "via", "yanglint", "when", "spec", "is", "finalized", ")", "2", ")", "parses", "the", "MUD", "file", "into", "a", "OSMUD", "data", "structure", "representing", "the", "MUD", "file", "3", ")", "Calls", "the", "device", "specific", "implementations", "to", "implement", "the", "features", "in", "the", "mud", "file" ]
void executeNewDhcpAction(DhcpEvent *dhcpEvent) { char logMsgBuf[4096]; buildDhcpEventContext(logMsgBuf, "NEW", dhcpEvent); logOmsGeneralMessage(OMS_INFO, OMS_SUBSYS_GENERAL, logMsgBuf); if ((dhcpEvent) && (dhcpEvent->mudFileURL)) { dhcpEvent->mudSigURL = createSigUrlFromMudUrl(dhcpEvent->mudFileURL); dhcpEvent->mudFileStorageLocation = createStorageLocation(dhcpEvent->mudFileURL); dhcpEvent->mudSigFileStorageLocation = createStorageLocation(dhcpEvent->mudSigURL); if (!getOpenMudFile(dhcpEvent->mudFileURL, dhcpEvent->mudFileStorageLocation)) { if ((!getOpenMudFile(dhcpEvent->mudSigURL, dhcpEvent->mudSigFileStorageLocation)) || (noFailOnMudValidation)) { logOmsGeneralMessage(OMS_DEBUG, OMS_SUBSYS_MUD_FILE, "IN ****NEW**** MUD and SIG FILE RETRIEVED!!!"); if ((validateMudFileWithSig(dhcpEvent) == VALID_MUD_FILE_SIG) || (noFailOnMudValidation)) { executeMudWithDhcpContext(dhcpEvent); installMudDbDeviceEntry(mudFileDataDirectory, dhcpEvent->ipAddress, dhcpEvent->macAddress, dhcpEvent->mudFileURL, dhcpEvent->mudFileStorageLocation, dhcpEvent->hostName); } else { logOmsGeneralMessage(OMS_ERROR, OMS_SUBSYS_MUD_FILE, "ERROR: ****NEW**** BAD SIGNATURE - FAILED VALIDATION!!!"); } } else { logOmsGeneralMessage(OMS_ERROR, OMS_SUBSYS_MUD_FILE, "ERROR: ****NEW**** NO SIG FILE RETRIEVED!!!"); } } else { logOmsGeneralMessage(OMS_ERROR, OMS_SUBSYS_MUD_FILE, "ERROR: ****NEW**** NO MUD FILE RETRIEVED!!!"); } } else { logOmsGeneralMessage(OMS_DEBUG, OMS_SUBSYS_MUD_FILE, "IN ****NEW**** LEGACY DEVICE -- no mud file declared."); doDhcpLegacyAction(dhcpEvent); installMudDbDeviceEntry(mudFileDataDirectory, dhcpEvent->ipAddress, dhcpEvent->macAddress, NULL, NULL, dhcpEvent->hostName); } }
[ "void", "executeNewDhcpAction", "(", "DhcpEvent", "*", "dhcpEvent", ")", "{", "char", "logMsgBuf", "[", "4096", "]", ";", "buildDhcpEventContext", "(", "logMsgBuf", ",", "\"", "\"", ",", "dhcpEvent", ")", ";", "logOmsGeneralMessage", "(", "OMS_INFO", ",", "OMS_SUBSYS_GENERAL", ",", "logMsgBuf", ")", ";", "if", "(", "(", "dhcpEvent", ")", "&&", "(", "dhcpEvent", "->", "mudFileURL", ")", ")", "{", "dhcpEvent", "->", "mudSigURL", "=", "createSigUrlFromMudUrl", "(", "dhcpEvent", "->", "mudFileURL", ")", ";", "dhcpEvent", "->", "mudFileStorageLocation", "=", "createStorageLocation", "(", "dhcpEvent", "->", "mudFileURL", ")", ";", "dhcpEvent", "->", "mudSigFileStorageLocation", "=", "createStorageLocation", "(", "dhcpEvent", "->", "mudSigURL", ")", ";", "if", "(", "!", "getOpenMudFile", "(", "dhcpEvent", "->", "mudFileURL", ",", "dhcpEvent", "->", "mudFileStorageLocation", ")", ")", "{", "if", "(", "(", "!", "getOpenMudFile", "(", "dhcpEvent", "->", "mudSigURL", ",", "dhcpEvent", "->", "mudSigFileStorageLocation", ")", ")", "||", "(", "noFailOnMudValidation", ")", ")", "{", "logOmsGeneralMessage", "(", "OMS_DEBUG", ",", "OMS_SUBSYS_MUD_FILE", ",", "\"", "\"", ")", ";", "if", "(", "(", "validateMudFileWithSig", "(", "dhcpEvent", ")", "==", "VALID_MUD_FILE_SIG", ")", "||", "(", "noFailOnMudValidation", ")", ")", "{", "executeMudWithDhcpContext", "(", "dhcpEvent", ")", ";", "installMudDbDeviceEntry", "(", "mudFileDataDirectory", ",", "dhcpEvent", "->", "ipAddress", ",", "dhcpEvent", "->", "macAddress", ",", "dhcpEvent", "->", "mudFileURL", ",", "dhcpEvent", "->", "mudFileStorageLocation", ",", "dhcpEvent", "->", "hostName", ")", ";", "}", "else", "{", "logOmsGeneralMessage", "(", "OMS_ERROR", ",", "OMS_SUBSYS_MUD_FILE", ",", "\"", "\"", ")", ";", "}", "}", "else", "{", "logOmsGeneralMessage", "(", "OMS_ERROR", ",", "OMS_SUBSYS_MUD_FILE", ",", "\"", "\"", ")", ";", "}", "}", "else", "{", "logOmsGeneralMessage", "(", "OMS_ERROR", ",", "OMS_SUBSYS_MUD_FILE", ",", "\"", "\"", ")", ";", "}", "}", "else", "{", "logOmsGeneralMessage", "(", "OMS_DEBUG", ",", "OMS_SUBSYS_MUD_FILE", ",", "\"", "\"", ")", ";", "doDhcpLegacyAction", "(", "dhcpEvent", ")", ";", "installMudDbDeviceEntry", "(", "mudFileDataDirectory", ",", "dhcpEvent", "->", "ipAddress", ",", "dhcpEvent", "->", "macAddress", ",", "NULL", ",", "NULL", ",", "dhcpEvent", "->", "hostName", ")", ";", "}", "}" ]
This takes a DHCP event and performs the following: 1) Validates the MUD file (maybe via yanglint when spec is finalized) 2) parses the MUD file into a OSMUD data structure representing the MUD file 3) Calls the device specific implementations to implement the features in the mud file
[ "This", "takes", "a", "DHCP", "event", "and", "performs", "the", "following", ":", "1", ")", "Validates", "the", "MUD", "file", "(", "maybe", "via", "yanglint", "when", "spec", "is", "finalized", ")", "2", ")", "parses", "the", "MUD", "file", "into", "a", "OSMUD", "data", "structure", "representing", "the", "MUD", "file", "3", ")", "Calls", "the", "device", "specific", "implementations", "to", "implement", "the", "features", "in", "the", "mud", "file" ]
[ "/* We are processing a MUD aware device. Go to the MUD file server and get the usage description */", "/* non-zero return code indicates error during communications */", "/* Mud files and signature files are stored in their computed storage locations for future reference */", "/* For debugging purposes only, allow the p7s verification to be optional when the \"-i\" option\n\t\t\t * is provided. This feature will be removed from a future release and is only provided now\n\t\t\t * until certificates compatible with OPENSSL CMS VERIFY commands are in ready use.\n\t\t\t */", "/*\n\t\t\t\t\t * All files downloaded and signature valid.\n\t\t\t\t\t * CALL INTERFACE TO CARRY OUT MUD ACTION HERE\n\t\t\t\t\t */", "/* This is a legacy non-MUD aware device. */" ]
[ { "param": "dhcpEvent", "type": "DhcpEvent" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dhcpEvent", "type": "DhcpEvent", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40987d2d14a15c663701a9ff1d434a62de5bea18
CJ-783/osmud
src/sampleDevice/testDevice.c
[ "Apache-2.0" ]
C
installDnsRule
int
int installDnsRule(char *targetDomainName, char *srcIpAddr, char *srcMacAddr, char *srcHostName, char *dnsFileNameWithPath) { FILE *fp= NULL; int retval = 0; fp = fopen (dnsFileNameWithPath, "a"); if (fp != NULL) { fprintf(fp, "%s %s %s %s\n", targetDomainName, srcHostName, srcIpAddr, srcMacAddr); fflush(fp); fclose(fp); } else { logOmsGeneralMessage(OMS_CRIT, OMS_SUBSYS_DEVICE_INTERFACE, "Could not write DNS rule to file."); retval = 1; } return retval; }
// Appends a DNS entry to the DNS whitelist
Appends a DNS entry to the DNS whitelist
[ "Appends", "a", "DNS", "entry", "to", "the", "DNS", "whitelist" ]
int installDnsRule(char *targetDomainName, char *srcIpAddr, char *srcMacAddr, char *srcHostName, char *dnsFileNameWithPath) { FILE *fp= NULL; int retval = 0; fp = fopen (dnsFileNameWithPath, "a"); if (fp != NULL) { fprintf(fp, "%s %s %s %s\n", targetDomainName, srcHostName, srcIpAddr, srcMacAddr); fflush(fp); fclose(fp); } else { logOmsGeneralMessage(OMS_CRIT, OMS_SUBSYS_DEVICE_INTERFACE, "Could not write DNS rule to file."); retval = 1; } return retval; }
[ "int", "installDnsRule", "(", "char", "*", "targetDomainName", ",", "char", "*", "srcIpAddr", ",", "char", "*", "srcMacAddr", ",", "char", "*", "srcHostName", ",", "char", "*", "dnsFileNameWithPath", ")", "{", "FILE", "*", "fp", "=", "NULL", ";", "int", "retval", "=", "0", ";", "fp", "=", "fopen", "(", "dnsFileNameWithPath", ",", "\"", "\"", ")", ";", "if", "(", "fp", "!=", "NULL", ")", "{", "fprintf", "(", "fp", ",", "\"", "\\n", "\"", ",", "targetDomainName", ",", "srcHostName", ",", "srcIpAddr", ",", "srcMacAddr", ")", ";", "fflush", "(", "fp", ")", ";", "fclose", "(", "fp", ")", ";", "}", "else", "{", "logOmsGeneralMessage", "(", "OMS_CRIT", ",", "OMS_SUBSYS_DEVICE_INTERFACE", ",", "\"", "\"", ")", ";", "retval", "=", "1", ";", "}", "return", "retval", ";", "}" ]
Appends a DNS entry to the DNS whitelist
[ "Appends", "a", "DNS", "entry", "to", "the", "DNS", "whitelist" ]
[]
[ { "param": "targetDomainName", "type": "char" }, { "param": "srcIpAddr", "type": "char" }, { "param": "srcMacAddr", "type": "char" }, { "param": "srcHostName", "type": "char" }, { "param": "dnsFileNameWithPath", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "targetDomainName", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "srcIpAddr", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "srcMacAddr", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "srcHostName", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dnsFileNameWithPath", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40987d2d14a15c663701a9ff1d434a62de5bea18
CJ-783/osmud
src/sampleDevice/testDevice.c
[ "Apache-2.0" ]
C
removeDnsRule
int
int removeDnsRule(char *targetDomainName, char *srcIpAddr, char *srcMacAddr, char *dnsFileNameWithPath) { return 0; }
// Removes a DNS entry from the DNS whitelist
Removes a DNS entry from the DNS whitelist
[ "Removes", "a", "DNS", "entry", "from", "the", "DNS", "whitelist" ]
int removeDnsRule(char *targetDomainName, char *srcIpAddr, char *srcMacAddr, char *dnsFileNameWithPath) { return 0; }
[ "int", "removeDnsRule", "(", "char", "*", "targetDomainName", ",", "char", "*", "srcIpAddr", ",", "char", "*", "srcMacAddr", ",", "char", "*", "dnsFileNameWithPath", ")", "{", "return", "0", ";", "}" ]
Removes a DNS entry from the DNS whitelist
[ "Removes", "a", "DNS", "entry", "from", "the", "DNS", "whitelist" ]
[]
[ { "param": "targetDomainName", "type": "char" }, { "param": "srcIpAddr", "type": "char" }, { "param": "srcMacAddr", "type": "char" }, { "param": "dnsFileNameWithPath", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "targetDomainName", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "srcIpAddr", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "srcMacAddr", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dnsFileNameWithPath", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
327a143ce89db97f80e51b9fc3e748ebf3ab092c
CJ-783/osmud
src/dhcp_event.c
[ "Apache-2.0" ]
C
createStorageLocation
char
char *createStorageLocation(char *mudURL) { char *fileName; char *fullPath; if (!mudURL) return NULL; if ((fileName = basename(mudURL)) == NULL) return NULL; if ((fullPath = safe_malloc(strlen (mudFileDataDirectory) + strlen(fileName) + 1)) == NULL) return NULL; sprintf(fullPath, "%s/%s", mudFileDataDirectory, fileName); return fullPath; }
/* * This will create a filesystem based storage location based on the mudURL argument * The fileName will be pulled off the end of the URL and concatinated with the default path * * This allocates storage so the caller is responsible for freeing memory for returned string when done */
This will create a filesystem based storage location based on the mudURL argument The fileName will be pulled off the end of the URL and concatinated with the default path This allocates storage so the caller is responsible for freeing memory for returned string when done
[ "This", "will", "create", "a", "filesystem", "based", "storage", "location", "based", "on", "the", "mudURL", "argument", "The", "fileName", "will", "be", "pulled", "off", "the", "end", "of", "the", "URL", "and", "concatinated", "with", "the", "default", "path", "This", "allocates", "storage", "so", "the", "caller", "is", "responsible", "for", "freeing", "memory", "for", "returned", "string", "when", "done" ]
char *createStorageLocation(char *mudURL) { char *fileName; char *fullPath; if (!mudURL) return NULL; if ((fileName = basename(mudURL)) == NULL) return NULL; if ((fullPath = safe_malloc(strlen (mudFileDataDirectory) + strlen(fileName) + 1)) == NULL) return NULL; sprintf(fullPath, "%s/%s", mudFileDataDirectory, fileName); return fullPath; }
[ "char", "*", "createStorageLocation", "(", "char", "*", "mudURL", ")", "{", "char", "*", "fileName", ";", "char", "*", "fullPath", ";", "if", "(", "!", "mudURL", ")", "return", "NULL", ";", "if", "(", "(", "fileName", "=", "basename", "(", "mudURL", ")", ")", "==", "NULL", ")", "return", "NULL", ";", "if", "(", "(", "fullPath", "=", "safe_malloc", "(", "strlen", "(", "mudFileDataDirectory", ")", "+", "strlen", "(", "fileName", ")", "+", "1", ")", ")", "==", "NULL", ")", "return", "NULL", ";", "sprintf", "(", "fullPath", ",", "\"", "\"", ",", "mudFileDataDirectory", ",", "fileName", ")", ";", "return", "fullPath", ";", "}" ]
This will create a filesystem based storage location based on the mudURL argument The fileName will be pulled off the end of the URL and concatinated with the default path
[ "This", "will", "create", "a", "filesystem", "based", "storage", "location", "based", "on", "the", "mudURL", "argument", "The", "fileName", "will", "be", "pulled", "off", "the", "end", "of", "the", "URL", "and", "concatinated", "with", "the", "default", "path" ]
[]
[ { "param": "mudURL", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mudURL", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087d1c8db1235897ad2abacf1d9132a5ec058b73
CJ-783/osmud
src/oms_utils.c
[ "Apache-2.0" ]
C
remove_ext
char
char * remove_ext (char* mystr, char dot, char sep) { char *retstr, *lastdot, *lastsep; // Error checks and allocate string. if (mystr == NULL) return NULL; if ((retstr = safe_malloc (strlen (mystr) + 1)) == NULL) return NULL; // Make a copy and find the relevant characters. strcpy (retstr, mystr); lastdot = strrchr (retstr, dot); lastsep = (sep == 0) ? NULL : strrchr (retstr, sep); // If it has an extension separator. if (lastdot != NULL) { // and it's before the extenstion separator. if (lastsep != NULL) { if (lastsep < lastdot) { // then remove it. *lastdot = '\0'; } } else { // Has extension separator with no path separator. *lastdot = '\0'; } } // Return the modified string. return retstr; }
// remove_ext: removes the "extension" from a file spec. // mystr is the string to process. // dot is the extension separator. // sep is the path separator (0 means to ignore). // Returns an allocated string identical to the original but // with the extension removed. It must be freed when you're // finished with it. // If you pass in NULL or the new string can't be allocated, // it returns NULL.
removes the "extension" from a file spec. mystr is the string to process. dot is the extension separator. sep is the path separator (0 means to ignore). Returns an allocated string identical to the original but with the extension removed. It must be freed when you're finished with it. If you pass in NULL or the new string can't be allocated, it returns NULL.
[ "removes", "the", "\"", "extension", "\"", "from", "a", "file", "spec", ".", "mystr", "is", "the", "string", "to", "process", ".", "dot", "is", "the", "extension", "separator", ".", "sep", "is", "the", "path", "separator", "(", "0", "means", "to", "ignore", ")", ".", "Returns", "an", "allocated", "string", "identical", "to", "the", "original", "but", "with", "the", "extension", "removed", ".", "It", "must", "be", "freed", "when", "you", "'", "re", "finished", "with", "it", ".", "If", "you", "pass", "in", "NULL", "or", "the", "new", "string", "can", "'", "t", "be", "allocated", "it", "returns", "NULL", "." ]
char * remove_ext (char* mystr, char dot, char sep) { char *retstr, *lastdot, *lastsep; if (mystr == NULL) return NULL; if ((retstr = safe_malloc (strlen (mystr) + 1)) == NULL) return NULL; strcpy (retstr, mystr); lastdot = strrchr (retstr, dot); lastsep = (sep == 0) ? NULL : strrchr (retstr, sep); if (lastdot != NULL) { if (lastsep != NULL) { if (lastsep < lastdot) { *lastdot = '\0'; } } else { *lastdot = '\0'; } } return retstr; }
[ "char", "*", "remove_ext", "(", "char", "*", "mystr", ",", "char", "dot", ",", "char", "sep", ")", "{", "char", "*", "retstr", ",", "*", "lastdot", ",", "*", "lastsep", ";", "if", "(", "mystr", "==", "NULL", ")", "return", "NULL", ";", "if", "(", "(", "retstr", "=", "safe_malloc", "(", "strlen", "(", "mystr", ")", "+", "1", ")", ")", "==", "NULL", ")", "return", "NULL", ";", "strcpy", "(", "retstr", ",", "mystr", ")", ";", "lastdot", "=", "strrchr", "(", "retstr", ",", "dot", ")", ";", "lastsep", "=", "(", "sep", "==", "0", ")", "?", "NULL", ":", "strrchr", "(", "retstr", ",", "sep", ")", ";", "if", "(", "lastdot", "!=", "NULL", ")", "{", "if", "(", "lastsep", "!=", "NULL", ")", "{", "if", "(", "lastsep", "<", "lastdot", ")", "{", "*", "lastdot", "=", "'", "\\0", "'", ";", "}", "}", "else", "{", "*", "lastdot", "=", "'", "\\0", "'", ";", "}", "}", "return", "retstr", ";", "}" ]
remove_ext: removes the "extension" from a file spec.
[ "remove_ext", ":", "removes", "the", "\"", "extension", "\"", "from", "a", "file", "spec", "." ]
[ "// Error checks and allocate string.", "// Make a copy and find the relevant characters.", "// If it has an extension separator.", "// and it's before the extenstion separator.", "// then remove it.", "// Has extension separator with no path separator.", "// Return the modified string." ]
[ { "param": "mystr", "type": "char" }, { "param": "dot", "type": "char" }, { "param": "sep", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mystr", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dot", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sep", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087d1c8db1235897ad2abacf1d9132a5ec058b73
CJ-783/osmud
src/oms_utils.c
[ "Apache-2.0" ]
C
replaceExtension
char
char * replaceExtension(char* fileUrl, char *newExtension) { char *retstr; char *base; char *lastdot; if (fileUrl == NULL) return NULL; if (newExtension == NULL) return NULL; if ((base = safe_malloc(strlen (fileUrl) + 1)) == NULL) return NULL; if ((retstr = safe_malloc(strlen (fileUrl) + strlen(newExtension) + 1)) == NULL) return NULL; strcpy (base, fileUrl); lastdot = strrchr (base, '.'); if (lastdot != NULL) { *lastdot = '\0'; } sprintf(retstr, "%s.%s", base, newExtension); safe_free(base); return retstr; }
/* * This will look for the last "." character in fileUrl and replace * afterward with newExtension. * * Caller is responsible for freeing this memory */
This will look for the last "." character in fileUrl and replace afterward with newExtension. Caller is responsible for freeing this memory
[ "This", "will", "look", "for", "the", "last", "\"", ".", "\"", "character", "in", "fileUrl", "and", "replace", "afterward", "with", "newExtension", ".", "Caller", "is", "responsible", "for", "freeing", "this", "memory" ]
char * replaceExtension(char* fileUrl, char *newExtension) { char *retstr; char *base; char *lastdot; if (fileUrl == NULL) return NULL; if (newExtension == NULL) return NULL; if ((base = safe_malloc(strlen (fileUrl) + 1)) == NULL) return NULL; if ((retstr = safe_malloc(strlen (fileUrl) + strlen(newExtension) + 1)) == NULL) return NULL; strcpy (base, fileUrl); lastdot = strrchr (base, '.'); if (lastdot != NULL) { *lastdot = '\0'; } sprintf(retstr, "%s.%s", base, newExtension); safe_free(base); return retstr; }
[ "char", "*", "replaceExtension", "(", "char", "*", "fileUrl", ",", "char", "*", "newExtension", ")", "{", "char", "*", "retstr", ";", "char", "*", "base", ";", "char", "*", "lastdot", ";", "if", "(", "fileUrl", "==", "NULL", ")", "return", "NULL", ";", "if", "(", "newExtension", "==", "NULL", ")", "return", "NULL", ";", "if", "(", "(", "base", "=", "safe_malloc", "(", "strlen", "(", "fileUrl", ")", "+", "1", ")", ")", "==", "NULL", ")", "return", "NULL", ";", "if", "(", "(", "retstr", "=", "safe_malloc", "(", "strlen", "(", "fileUrl", ")", "+", "strlen", "(", "newExtension", ")", "+", "1", ")", ")", "==", "NULL", ")", "return", "NULL", ";", "strcpy", "(", "base", ",", "fileUrl", ")", ";", "lastdot", "=", "strrchr", "(", "base", ",", "'", "'", ")", ";", "if", "(", "lastdot", "!=", "NULL", ")", "{", "*", "lastdot", "=", "'", "\\0", "'", ";", "}", "sprintf", "(", "retstr", ",", "\"", "\"", ",", "base", ",", "newExtension", ")", ";", "safe_free", "(", "base", ")", ";", "return", "retstr", ";", "}" ]
This will look for the last "."
[ "This", "will", "look", "for", "the", "last", "\"", ".", "\"" ]
[]
[ { "param": "fileUrl", "type": "char" }, { "param": "newExtension", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fileUrl", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "newExtension", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087d1c8db1235897ad2abacf1d9132a5ec058b73
CJ-783/osmud
src/oms_utils.c
[ "Apache-2.0" ]
C
mkdir_path
int
int mkdir_path(char *path) { int result = 0; char *sep = strrchr(path, '/' ); if(sep != NULL) { *sep = 0; if ((result = mkdir_path(path))) { /* There was a problem making the path - stop and return error */ return 1; } *sep = '/'; } if (*path) { if( mkdir(path,0755) && errno != EEXIST ) { return 1; } else { return 0; } } /* else, a null path does not cause an error - it's skipped */ return 0; }
/* * Recursive function that will create a list of directories. It uses stack memory * and assumes the path input is memory that can be modified. * Returns 0 - successful path creation * 1 - something went wrong */
Recursive function that will create a list of directories. It uses stack memory and assumes the path input is memory that can be modified. Returns 0 - successful path creation 1 - something went wrong
[ "Recursive", "function", "that", "will", "create", "a", "list", "of", "directories", ".", "It", "uses", "stack", "memory", "and", "assumes", "the", "path", "input", "is", "memory", "that", "can", "be", "modified", ".", "Returns", "0", "-", "successful", "path", "creation", "1", "-", "something", "went", "wrong" ]
int mkdir_path(char *path) { int result = 0; char *sep = strrchr(path, '/' ); if(sep != NULL) { *sep = 0; if ((result = mkdir_path(path))) { return 1; } *sep = '/'; } if (*path) { if( mkdir(path,0755) && errno != EEXIST ) { return 1; } else { return 0; } } return 0; }
[ "int", "mkdir_path", "(", "char", "*", "path", ")", "{", "int", "result", "=", "0", ";", "char", "*", "sep", "=", "strrchr", "(", "path", ",", "'", "'", ")", ";", "if", "(", "sep", "!=", "NULL", ")", "{", "*", "sep", "=", "0", ";", "if", "(", "(", "result", "=", "mkdir_path", "(", "path", ")", ")", ")", "{", "return", "1", ";", "}", "*", "sep", "=", "'", "'", ";", "}", "if", "(", "*", "path", ")", "{", "if", "(", "mkdir", "(", "path", ",", "0755", ")", "&&", "errno", "!=", "EEXIST", ")", "{", "return", "1", ";", "}", "else", "{", "return", "0", ";", "}", "}", "return", "0", ";", "}" ]
Recursive function that will create a list of directories.
[ "Recursive", "function", "that", "will", "create", "a", "list", "of", "directories", "." ]
[ "/* There was a problem making the path - stop and return error */", "/* else, a null path does not cause an error - it's skipped */" ]
[ { "param": "path", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "path", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087d1c8db1235897ad2abacf1d9132a5ec058b73
CJ-783/osmud
src/oms_utils.c
[ "Apache-2.0" ]
C
fopen_with_path
FILE
FILE *fopen_with_path(char *path, char *mode) { char *sep = strrchr(path, '/' ); int result = 0; if (sep) { char *path_t = strdup(path); path_t[sep - path] = 0; result = mkdir_path(path_t); safe_free(path_t); } if (!result) return fopen(path, mode); else return (FILE *)0; }
/* * Attempts to open a file that includes a path. All parts of the path will try to be created * If the path cannot be created or the file cannot be opened, null will be returned */
Attempts to open a file that includes a path. All parts of the path will try to be created If the path cannot be created or the file cannot be opened, null will be returned
[ "Attempts", "to", "open", "a", "file", "that", "includes", "a", "path", ".", "All", "parts", "of", "the", "path", "will", "try", "to", "be", "created", "If", "the", "path", "cannot", "be", "created", "or", "the", "file", "cannot", "be", "opened", "null", "will", "be", "returned" ]
FILE *fopen_with_path(char *path, char *mode) { char *sep = strrchr(path, '/' ); int result = 0; if (sep) { char *path_t = strdup(path); path_t[sep - path] = 0; result = mkdir_path(path_t); safe_free(path_t); } if (!result) return fopen(path, mode); else return (FILE *)0; }
[ "FILE", "*", "fopen_with_path", "(", "char", "*", "path", ",", "char", "*", "mode", ")", "{", "char", "*", "sep", "=", "strrchr", "(", "path", ",", "'", "'", ")", ";", "int", "result", "=", "0", ";", "if", "(", "sep", ")", "{", "char", "*", "path_t", "=", "strdup", "(", "path", ")", ";", "path_t", "[", "sep", "-", "path", "]", "=", "0", ";", "result", "=", "mkdir_path", "(", "path_t", ")", ";", "safe_free", "(", "path_t", ")", ";", "}", "if", "(", "!", "result", ")", "return", "fopen", "(", "path", ",", "mode", ")", ";", "else", "return", "(", "FILE", "*", ")", "0", ";", "}" ]
Attempts to open a file that includes a path.
[ "Attempts", "to", "open", "a", "file", "that", "includes", "a", "path", "." ]
[]
[ { "param": "path", "type": "char" }, { "param": "mode", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "path", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mode", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
080eb2cddfffbe3b1a6fdeaf0519f159d4338b8c
CJ-783/osmud
src/comms.c
[ "Apache-2.0" ]
C
write_data
size_t
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) { CurlOptions *p = (CurlOptions *)userp; logOmsGeneralMessage(OMS_DEBUG, OMS_SUBSYS_COMMUNICATION, "in write data"); return fwrite(buffer, size, nmemb, p->outputFile); }
/** * Iterative call made whenever there is data to write. Data must * be appended to the output from prior calls. */
Iterative call made whenever there is data to write. Data must be appended to the output from prior calls.
[ "Iterative", "call", "made", "whenever", "there", "is", "data", "to", "write", ".", "Data", "must", "be", "appended", "to", "the", "output", "from", "prior", "calls", "." ]
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) { CurlOptions *p = (CurlOptions *)userp; logOmsGeneralMessage(OMS_DEBUG, OMS_SUBSYS_COMMUNICATION, "in write data"); return fwrite(buffer, size, nmemb, p->outputFile); }
[ "size_t", "write_data", "(", "void", "*", "buffer", ",", "size_t", "size", ",", "size_t", "nmemb", ",", "void", "*", "userp", ")", "{", "CurlOptions", "*", "p", "=", "(", "CurlOptions", "*", ")", "userp", ";", "logOmsGeneralMessage", "(", "OMS_DEBUG", ",", "OMS_SUBSYS_COMMUNICATION", ",", "\"", "\"", ")", ";", "return", "fwrite", "(", "buffer", ",", "size", ",", "nmemb", ",", "p", "->", "outputFile", ")", ";", "}" ]
Iterative call made whenever there is data to write.
[ "Iterative", "call", "made", "whenever", "there", "is", "data", "to", "write", "." ]
[]
[ { "param": "buffer", "type": "void" }, { "param": "size", "type": "size_t" }, { "param": "nmemb", "type": "size_t" }, { "param": "userp", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buffer", "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 }, { "identifier": "nmemb", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "userp", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d808391e7738380d5e1b2a91d73b416f1ccca145
specialxuan/SpaceFrame
oldversion/SpaceFrame v4.3.h
[ "MIT" ]
C
sfLCosSin
bool
bool sfLCosSin() { for (int k = 0; k < NOR; k++) { int i = rods[k].BNR - 1, j = rods[k].ENR - 1; // index of beginning and end nodes of rods rods[k].LCS[1] = nodes[j].XCN - nodes[i].XCN; rods[k].LCS[2] = nodes[j].YCN - nodes[i].YCN; rods[k].LCS[3] = nodes[j].ZCN - nodes[i].ZCN; rods[k].LCS[0] = sqrt(rods[k].LCS[1] * rods[k].LCS[1] + rods[k].LCS[2] * rods[k].LCS[2] + rods[k].LCS[3] * rods[k].LCS[3]); if (rods[k].LCS[0] < EPS) // if the length of rod is too small, then return error { sfPrintError(8); return 1; } rods[k].LCS[1] = rods[k].LCS[1] / rods[k].LCS[0]; rods[k].LCS[2] = rods[k].LCS[2] / rods[k].LCS[0]; rods[k].LCS[3] = rods[k].LCS[3] / rods[k].LCS[0]; } return 0; }
// calculate the length sine and cosine of rods
calculate the length sine and cosine of rods
[ "calculate", "the", "length", "sine", "and", "cosine", "of", "rods" ]
bool sfLCosSin() { for (int k = 0; k < NOR; k++) { int i = rods[k].BNR - 1, j = rods[k].ENR - 1; rods[k].LCS[1] = nodes[j].XCN - nodes[i].XCN; rods[k].LCS[2] = nodes[j].YCN - nodes[i].YCN; rods[k].LCS[3] = nodes[j].ZCN - nodes[i].ZCN; rods[k].LCS[0] = sqrt(rods[k].LCS[1] * rods[k].LCS[1] + rods[k].LCS[2] * rods[k].LCS[2] + rods[k].LCS[3] * rods[k].LCS[3]); if (rods[k].LCS[0] < EPS) { sfPrintError(8); return 1; } rods[k].LCS[1] = rods[k].LCS[1] / rods[k].LCS[0]; rods[k].LCS[2] = rods[k].LCS[2] / rods[k].LCS[0]; rods[k].LCS[3] = rods[k].LCS[3] / rods[k].LCS[0]; } return 0; }
[ "bool", "sfLCosSin", "(", ")", "{", "for", "(", "int", "k", "=", "0", ";", "k", "<", "NOR", ";", "k", "++", ")", "{", "int", "i", "=", "rods", "[", "k", "]", ".", "BNR", "-", "1", ",", "j", "=", "rods", "[", "k", "]", ".", "ENR", "-", "1", ";", "rods", "[", "k", "]", ".", "LCS", "[", "1", "]", "=", "nodes", "[", "j", "]", ".", "XCN", "-", "nodes", "[", "i", "]", ".", "XCN", ";", "rods", "[", "k", "]", ".", "LCS", "[", "2", "]", "=", "nodes", "[", "j", "]", ".", "YCN", "-", "nodes", "[", "i", "]", ".", "YCN", ";", "rods", "[", "k", "]", ".", "LCS", "[", "3", "]", "=", "nodes", "[", "j", "]", ".", "ZCN", "-", "nodes", "[", "i", "]", ".", "ZCN", ";", "rods", "[", "k", "]", ".", "LCS", "[", "0", "]", "=", "sqrt", "(", "rods", "[", "k", "]", ".", "LCS", "[", "1", "]", "*", "rods", "[", "k", "]", ".", "LCS", "[", "1", "]", "+", "rods", "[", "k", "]", ".", "LCS", "[", "2", "]", "*", "rods", "[", "k", "]", ".", "LCS", "[", "2", "]", "+", "rods", "[", "k", "]", ".", "LCS", "[", "3", "]", "*", "rods", "[", "k", "]", ".", "LCS", "[", "3", "]", ")", ";", "if", "(", "rods", "[", "k", "]", ".", "LCS", "[", "0", "]", "<", "EPS", ")", "{", "sfPrintError", "(", "8", ")", ";", "return", "1", ";", "}", "rods", "[", "k", "]", ".", "LCS", "[", "1", "]", "=", "rods", "[", "k", "]", ".", "LCS", "[", "1", "]", "/", "rods", "[", "k", "]", ".", "LCS", "[", "0", "]", ";", "rods", "[", "k", "]", ".", "LCS", "[", "2", "]", "=", "rods", "[", "k", "]", ".", "LCS", "[", "2", "]", "/", "rods", "[", "k", "]", ".", "LCS", "[", "0", "]", ";", "rods", "[", "k", "]", ".", "LCS", "[", "3", "]", "=", "rods", "[", "k", "]", ".", "LCS", "[", "3", "]", "/", "rods", "[", "k", "]", ".", "LCS", "[", "0", "]", ";", "}", "return", "0", ";", "}" ]
calculate the length sine and cosine of rods
[ "calculate", "the", "length", "sine", "and", "cosine", "of", "rods" ]
[ "// index of beginning and end nodes of rods", "// if the length of rod is too small, then return error" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
d808391e7738380d5e1b2a91d73b416f1ccca145
specialxuan/SpaceFrame
oldversion/SpaceFrame v4.3.h
[ "MIT" ]
C
sfConjugateGradient
bool
bool sfConjugateGradient(double *A, double *b, double *x, int N) { if (A == NULL) { sfPrintError(12); return 1; } else if (b == NULL) { sfPrintError(12); return 1; } else if (x == NULL) { sfPrintError(12); return 1; } else if (N == 0) { sfPrintError(12); return 1; } double *r = NULL, *p = NULL, *z = NULL; double gamma = 0, gamma_new = 0, gamma_new_sqrt = 0, alpha = 0, beta = 0; int percent = 0, percent_new = 0; if (ProgressBar) cout << "\rSolving equation [ 0%% ][ ]"; r = (double *)malloc(N * sizeof(double)); memset(r, 0, sizeof(double)); p = (double *)malloc(N * sizeof(double)); memset(p, 0, sizeof(double)); z = (double *)malloc(N * sizeof(double)); memset(z, 0, sizeof(double)); for (int i = 0; i < NSI; i++) A[i] = A[i] / MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] / MAXLV; // x = [0 ... 0] // r = b - A * x // p = r // gamma = r' * r gamma = 0.0; for (int i = 0; i < N; ++i) { x[i] = 0.0; r[i] = b[i]; p[i] = r[i]; gamma += r[i] * r[i]; } for (int n = 0; 1; ++n) { // z = A * p for (int i = 0; i < N; i++) { z[i] = 0.0; for (int j = 0; j < N; j++) { if (i == j) { z[i] += A[IV[i] - 1] * p[j]; } else if (j > i) { if ((IV[j] - j + i) > IV[j - 1]) z[i] += A[IV[j] - j + i - 1] * p[j]; else z[i] += 0; } else if (i > j) { if ((IV[i] - i + j) > IV[i - 1]) z[i] += A[IV[i] - i + j - 1] * p[j]; else z[i] += 0; } } } // alpha = gamma / (p' * z) alpha = 0.0; for (int i = 0; i < N; ++i) alpha += p[i] * z[i]; alpha = gamma / alpha; // x = x + alpha * p // r = r - alpha * z // gamma_new = r' * r gamma_new = 0.0; for (int i = 0; i < N; ++i) { x[i] += alpha * p[i]; r[i] -= alpha * z[i]; gamma_new += r[i] * r[i]; } gamma_new_sqrt = sqrt(gamma_new); if (gamma_new_sqrt < EPS) break; if (ProgressBar) { percent_new = (int)((1 - log10(gamma_new_sqrt / EPS) / 16) * 100); if (percent_new > percent) { percent = percent_new; cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; cout << "[ " << percent << "%% ]"; cout << "["; for (int i = 0; i < 49; i++) if (i < percent / 2) cout << "="; else cout << " "; cout << "]"; } else { cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; } } beta = gamma_new / gamma; // p = r + (gamma_new / gamma) * p; for (int i = 0; i < N; ++i) p[i] = r[i] + beta * p[i]; // gamma = gamma_new gamma = gamma_new; } for (int i = 0; i < NSI; i++) A[i] = A[i] * MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] * MAXLV; for (int i = 0; i < N; i++) x[i] = x[i] * MAXLV / MAXTS; if (ProgressBar) cout << "\rSolving equation done [ 100%% ][=================================================]\n"; free(r); free(p); free(z); return 0; }
// solve equation of matrix by conjugate gradient
solve equation of matrix by conjugate gradient
[ "solve", "equation", "of", "matrix", "by", "conjugate", "gradient" ]
bool sfConjugateGradient(double *A, double *b, double *x, int N) { if (A == NULL) { sfPrintError(12); return 1; } else if (b == NULL) { sfPrintError(12); return 1; } else if (x == NULL) { sfPrintError(12); return 1; } else if (N == 0) { sfPrintError(12); return 1; } double *r = NULL, *p = NULL, *z = NULL; double gamma = 0, gamma_new = 0, gamma_new_sqrt = 0, alpha = 0, beta = 0; int percent = 0, percent_new = 0; if (ProgressBar) cout << "\rSolving equation [ 0%% ][ ]"; r = (double *)malloc(N * sizeof(double)); memset(r, 0, sizeof(double)); p = (double *)malloc(N * sizeof(double)); memset(p, 0, sizeof(double)); z = (double *)malloc(N * sizeof(double)); memset(z, 0, sizeof(double)); for (int i = 0; i < NSI; i++) A[i] = A[i] / MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] / MAXLV; gamma = 0.0; for (int i = 0; i < N; ++i) { x[i] = 0.0; r[i] = b[i]; p[i] = r[i]; gamma += r[i] * r[i]; } for (int n = 0; 1; ++n) { for (int i = 0; i < N; i++) { z[i] = 0.0; for (int j = 0; j < N; j++) { if (i == j) { z[i] += A[IV[i] - 1] * p[j]; } else if (j > i) { if ((IV[j] - j + i) > IV[j - 1]) z[i] += A[IV[j] - j + i - 1] * p[j]; else z[i] += 0; } else if (i > j) { if ((IV[i] - i + j) > IV[i - 1]) z[i] += A[IV[i] - i + j - 1] * p[j]; else z[i] += 0; } } } alpha = 0.0; for (int i = 0; i < N; ++i) alpha += p[i] * z[i]; alpha = gamma / alpha; gamma_new = 0.0; for (int i = 0; i < N; ++i) { x[i] += alpha * p[i]; r[i] -= alpha * z[i]; gamma_new += r[i] * r[i]; } gamma_new_sqrt = sqrt(gamma_new); if (gamma_new_sqrt < EPS) break; if (ProgressBar) { percent_new = (int)((1 - log10(gamma_new_sqrt / EPS) / 16) * 100); if (percent_new > percent) { percent = percent_new; cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; cout << "[ " << percent << "%% ]"; cout << "["; for (int i = 0; i < 49; i++) if (i < percent / 2) cout << "="; else cout << " "; cout << "]"; } else { cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; } } beta = gamma_new / gamma; + (gamma_new / gamma) * p; for (int i = 0; i < N; ++i) p[i] = r[i] + beta * p[i]; gamma = gamma_new; } for (int i = 0; i < NSI; i++) A[i] = A[i] * MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] * MAXLV; for (int i = 0; i < N; i++) x[i] = x[i] * MAXLV / MAXTS; if (ProgressBar) cout << "\rSolving equation done [ 100%% ][=================================================]\n"; free(r); free(p); free(z); return 0; }
[ "bool", "sfConjugateGradient", "(", "double", "*", "A", ",", "double", "*", "b", ",", "double", "*", "x", ",", "int", "N", ")", "{", "if", "(", "A", "==", "NULL", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "else", "if", "(", "b", "==", "NULL", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "else", "if", "(", "x", "==", "NULL", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "else", "if", "(", "N", "==", "0", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "double", "*", "r", "=", "NULL", ",", "*", "p", "=", "NULL", ",", "*", "z", "=", "NULL", ";", "double", "gamma", "=", "0", ",", "gamma_new", "=", "0", ",", "gamma_new_sqrt", "=", "0", ",", "alpha", "=", "0", ",", "beta", "=", "0", ";", "int", "percent", "=", "0", ",", "percent_new", "=", "0", ";", "if", "(", "ProgressBar", ")", "cout", "<<", "\"", "\\r", "\"", ";", "r", "=", "(", "double", "*", ")", "malloc", "(", "N", "*", "sizeof", "(", "double", ")", ")", ";", "memset", "(", "r", ",", "0", ",", "sizeof", "(", "double", ")", ")", ";", "p", "=", "(", "double", "*", ")", "malloc", "(", "N", "*", "sizeof", "(", "double", ")", ")", ";", "memset", "(", "p", ",", "0", ",", "sizeof", "(", "double", ")", ")", ";", "z", "=", "(", "double", "*", ")", "malloc", "(", "N", "*", "sizeof", "(", "double", ")", ")", ";", "memset", "(", "z", ",", "0", ",", "sizeof", "(", "double", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "NSI", ";", "i", "++", ")", "A", "[", "i", "]", "=", "A", "[", "i", "]", "/", "MAXTS", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "b", "[", "i", "]", "=", "b", "[", "i", "]", "/", "MAXLV", ";", "gamma", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "{", "x", "[", "i", "]", "=", "0.0", ";", "r", "[", "i", "]", "=", "b", "[", "i", "]", ";", "p", "[", "i", "]", "=", "r", "[", "i", "]", ";", "gamma", "+=", "r", "[", "i", "]", "*", "r", "[", "i", "]", ";", "}", "for", "(", "int", "n", "=", "0", ";", "1", ";", "++", "n", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "{", "z", "[", "i", "]", "=", "0.0", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "N", ";", "j", "++", ")", "{", "if", "(", "i", "==", "j", ")", "{", "z", "[", "i", "]", "+=", "A", "[", "IV", "[", "i", "]", "-", "1", "]", "*", "p", "[", "j", "]", ";", "}", "else", "if", "(", "j", ">", "i", ")", "{", "if", "(", "(", "IV", "[", "j", "]", "-", "j", "+", "i", ")", ">", "IV", "[", "j", "-", "1", "]", ")", "z", "[", "i", "]", "+=", "A", "[", "IV", "[", "j", "]", "-", "j", "+", "i", "-", "1", "]", "*", "p", "[", "j", "]", ";", "else", "z", "[", "i", "]", "+=", "0", ";", "}", "else", "if", "(", "i", ">", "j", ")", "{", "if", "(", "(", "IV", "[", "i", "]", "-", "i", "+", "j", ")", ">", "IV", "[", "i", "-", "1", "]", ")", "z", "[", "i", "]", "+=", "A", "[", "IV", "[", "i", "]", "-", "i", "+", "j", "-", "1", "]", "*", "p", "[", "j", "]", ";", "else", "z", "[", "i", "]", "+=", "0", ";", "}", "}", "}", "alpha", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "alpha", "+=", "p", "[", "i", "]", "*", "z", "[", "i", "]", ";", "alpha", "=", "gamma", "/", "alpha", ";", "gamma_new", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "{", "x", "[", "i", "]", "+=", "alpha", "*", "p", "[", "i", "]", ";", "r", "[", "i", "]", "-=", "alpha", "*", "z", "[", "i", "]", ";", "gamma_new", "+=", "r", "[", "i", "]", "*", "r", "[", "i", "]", ";", "}", "gamma_new_sqrt", "=", "sqrt", "(", "gamma_new", ")", ";", "if", "(", "gamma_new_sqrt", "<", "EPS", ")", "break", ";", "if", "(", "ProgressBar", ")", "{", "percent_new", "=", "(", "int", ")", "(", "(", "1", "-", "log10", "(", "gamma_new_sqrt", "/", "EPS", ")", "/", "16", ")", "*", "100", ")", ";", "if", "(", "percent_new", ">", "percent", ")", "{", "percent", "=", "percent_new", ";", "cout", "<<", "\"", "\\r", "\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "4", ";", "i", "++", ")", "if", "(", "i", "<=", "n", "%", "4", ")", "cout", "<<", "\"", "\"", ";", "else", "cout", "<<", "\"", "\"", ";", "cout", "<<", "\"", "\"", "<<", "percent", "<<", "\"", "\"", ";", "cout", "<<", "\"", "\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "49", ";", "i", "++", ")", "if", "(", "i", "<", "percent", "/", "2", ")", "cout", "<<", "\"", "\"", ";", "else", "cout", "<<", "\"", "\"", ";", "cout", "<<", "\"", "\"", ";", "}", "else", "{", "cout", "<<", "\"", "\\r", "\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "4", ";", "i", "++", ")", "if", "(", "i", "<=", "n", "%", "4", ")", "cout", "<<", "\"", "\"", ";", "else", "cout", "<<", "\"", "\"", ";", "}", "}", "beta", "=", "gamma_new", "/", "gamma", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "p", "[", "i", "]", "=", "r", "[", "i", "]", "+", "beta", "*", "p", "[", "i", "]", ";", "gamma", "=", "gamma_new", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "NSI", ";", "i", "++", ")", "A", "[", "i", "]", "=", "A", "[", "i", "]", "*", "MAXTS", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "b", "[", "i", "]", "=", "b", "[", "i", "]", "*", "MAXLV", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "x", "[", "i", "]", "=", "x", "[", "i", "]", "*", "MAXLV", "/", "MAXTS", ";", "if", "(", "ProgressBar", ")", "cout", "<<", "\"", "\\r", "\\n", "\"", ";", "free", "(", "r", ")", ";", "free", "(", "p", ")", ";", "free", "(", "z", ")", ";", "return", "0", ";", "}" ]
solve equation of matrix by conjugate gradient
[ "solve", "equation", "of", "matrix", "by", "conjugate", "gradient" ]
[ "// x = [0 ... 0]", "// r = b - A * x", "// p = r", "// gamma = r' * r", "// z = A * p", "// alpha = gamma / (p' * z)", "// x = x + alpha * p", "// r = r - alpha * z", "// gamma_new = r' * r", "// p = r + (gamma_new / gamma) * p;", "// gamma = gamma_new" ]
[ { "param": "A", "type": "double" }, { "param": "b", "type": "double" }, { "param": "x", "type": "double" }, { "param": "N", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "A", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "b", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "N", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d808391e7738380d5e1b2a91d73b416f1ccca145
specialxuan/SpaceFrame
oldversion/SpaceFrame v4.3.h
[ "MIT" ]
C
sfConjugateGradientPar
bool
bool sfConjugateGradientPar(double *A, double *b, double *x, int N) { if (A == NULL) { sfPrintError(12); return 1; } else if (b == NULL) { sfPrintError(12); return 1; } else if (x == NULL) { sfPrintError(12); return 1; } else if (N == 0) { sfPrintError(12); return 1; } double *r = NULL, *p = NULL, *z = NULL; double gamma = 0, gamma_new = 0, gamma_new_sqrt = 0, alpha = 0, beta = 0; int percent = 0, percent_new = 0; if (ProgressBar) { cout << "\rSolving equation [ 0%% ][ ]"; } r = (double *)malloc(N * sizeof(double)); memset(r, 0, sizeof(double)); p = (double *)malloc(N * sizeof(double)); memset(p, 0, sizeof(double)); z = (double *)malloc(N * sizeof(double)); memset(z, 0, sizeof(double)); for (int i = 0; i < NSI; i++) A[i] = A[i] / MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] / MAXLV; // x = [0 ... 0] // r = b - A * x // p = r // gamma = r' * r gamma = 0.0; #pragma omp parallel for reduction(+ \ : gamma) for (int i = 0; i < N; ++i) { x[i] = 0.0; r[i] = b[i]; p[i] = r[i]; gamma += r[i] * r[i]; } for (int n = 0; true; ++n) { // z = A * p #pragma omp parallel for for (int i = 0; i < N; i++) { z[i] = 0.0; for (int j = 0; j < N; j++) { if (i == j) { z[i] += A[IV[i] - 1] * p[j]; } else if (j > i) { if ((IV[j] - j + i) > IV[j - 1]) z[i] += A[IV[j] - j + i - 1] * p[j]; else z[i] += 0; } else if (i > j) { if ((IV[i] - i + j) > IV[i - 1]) z[i] += A[IV[i] - i + j - 1] * p[j]; else z[i] += 0; } } } // alpha = gamma / (p' * z) alpha = 0.0; #pragma omp parallel for reduction(+ \ : alpha) for (int i = 0; i < N; ++i) alpha += p[i] * z[i]; alpha = gamma / alpha; // x = x + alpha * p // r = r - alpha * z // gamma_new = r' * r gamma_new = 0.0; #pragma omp parallel for reduction(+ \ : gamma_new) for (int i = 0; i < N; ++i) { x[i] += alpha * p[i]; r[i] -= alpha * z[i]; gamma_new += r[i] * r[i]; } gamma_new_sqrt = sqrt(gamma_new); if (gamma_new_sqrt < EPS) break; if (ProgressBar) { percent_new = (int)((1 - log10(gamma_new_sqrt * 1e15) / 16) * 100); if (percent_new > percent) { percent = percent_new; cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; cout << "[ " << percent << "%% ]"; cout << "["; for (int i = 0; i < 49; i++) if (i < percent / 2) cout << "="; else cout << " "; cout << "]"; } else { cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; } } beta = gamma_new / gamma; // p = r + (gamma_new / gamma) * p; #pragma omp parallel for for (int i = 0; i < N; ++i) p[i] = r[i] + beta * p[i]; // gamma = gamma_new gamma = gamma_new; } for (int i = 0; i < NSI; i++) A[i] = A[i] * MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] * MAXLV; for (int i = 0; i < N; i++) x[i] = x[i] * MAXLV / MAXTS; if (ProgressBar) { cout << "\rSolving equation done [ 100%% ][=================================================]\n"; } free(r); free(p); free(z); return 0; }
// solve equation of matrix by conjugate gradient parallel
solve equation of matrix by conjugate gradient parallel
[ "solve", "equation", "of", "matrix", "by", "conjugate", "gradient", "parallel" ]
bool sfConjugateGradientPar(double *A, double *b, double *x, int N) { if (A == NULL) { sfPrintError(12); return 1; } else if (b == NULL) { sfPrintError(12); return 1; } else if (x == NULL) { sfPrintError(12); return 1; } else if (N == 0) { sfPrintError(12); return 1; } double *r = NULL, *p = NULL, *z = NULL; double gamma = 0, gamma_new = 0, gamma_new_sqrt = 0, alpha = 0, beta = 0; int percent = 0, percent_new = 0; if (ProgressBar) { cout << "\rSolving equation [ 0%% ][ ]"; } r = (double *)malloc(N * sizeof(double)); memset(r, 0, sizeof(double)); p = (double *)malloc(N * sizeof(double)); memset(p, 0, sizeof(double)); z = (double *)malloc(N * sizeof(double)); memset(z, 0, sizeof(double)); for (int i = 0; i < NSI; i++) A[i] = A[i] / MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] / MAXLV; gamma = 0.0; #pragma omp parallel for reduction(+ \ : gamma) for (int i = 0; i < N; ++i) { x[i] = 0.0; r[i] = b[i]; p[i] = r[i]; gamma += r[i] * r[i]; } for (int n = 0; true; ++n) { #pragma omp parallel for for (int i = 0; i < N; i++) { z[i] = 0.0; for (int j = 0; j < N; j++) { if (i == j) { z[i] += A[IV[i] - 1] * p[j]; } else if (j > i) { if ((IV[j] - j + i) > IV[j - 1]) z[i] += A[IV[j] - j + i - 1] * p[j]; else z[i] += 0; } else if (i > j) { if ((IV[i] - i + j) > IV[i - 1]) z[i] += A[IV[i] - i + j - 1] * p[j]; else z[i] += 0; } } } alpha = 0.0; #pragma omp parallel for reduction(+ \ : alpha) for (int i = 0; i < N; ++i) alpha += p[i] * z[i]; alpha = gamma / alpha; gamma_new = 0.0; #pragma omp parallel for reduction(+ \ : gamma_new) for (int i = 0; i < N; ++i) { x[i] += alpha * p[i]; r[i] -= alpha * z[i]; gamma_new += r[i] * r[i]; } gamma_new_sqrt = sqrt(gamma_new); if (gamma_new_sqrt < EPS) break; if (ProgressBar) { percent_new = (int)((1 - log10(gamma_new_sqrt * 1e15) / 16) * 100); if (percent_new > percent) { percent = percent_new; cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; cout << "[ " << percent << "%% ]"; cout << "["; for (int i = 0; i < 49; i++) if (i < percent / 2) cout << "="; else cout << " "; cout << "]"; } else { cout << "\rSolving equation "; for (int i = 0; i <= 4; i++) if (i <= n % 4) cout << "."; else cout << " "; } } beta = gamma_new / gamma; + (gamma_new / gamma) * p; #pragma omp parallel for for (int i = 0; i < N; ++i) p[i] = r[i] + beta * p[i]; gamma = gamma_new; } for (int i = 0; i < NSI; i++) A[i] = A[i] * MAXTS; for (int i = 0; i < N; i++) b[i] = b[i] * MAXLV; for (int i = 0; i < N; i++) x[i] = x[i] * MAXLV / MAXTS; if (ProgressBar) { cout << "\rSolving equation done [ 100%% ][=================================================]\n"; } free(r); free(p); free(z); return 0; }
[ "bool", "sfConjugateGradientPar", "(", "double", "*", "A", ",", "double", "*", "b", ",", "double", "*", "x", ",", "int", "N", ")", "{", "if", "(", "A", "==", "NULL", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "else", "if", "(", "b", "==", "NULL", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "else", "if", "(", "x", "==", "NULL", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "else", "if", "(", "N", "==", "0", ")", "{", "sfPrintError", "(", "12", ")", ";", "return", "1", ";", "}", "double", "*", "r", "=", "NULL", ",", "*", "p", "=", "NULL", ",", "*", "z", "=", "NULL", ";", "double", "gamma", "=", "0", ",", "gamma_new", "=", "0", ",", "gamma_new_sqrt", "=", "0", ",", "alpha", "=", "0", ",", "beta", "=", "0", ";", "int", "percent", "=", "0", ",", "percent_new", "=", "0", ";", "if", "(", "ProgressBar", ")", "{", "cout", "<<", "\"", "\\r", "\"", ";", "}", "r", "=", "(", "double", "*", ")", "malloc", "(", "N", "*", "sizeof", "(", "double", ")", ")", ";", "memset", "(", "r", ",", "0", ",", "sizeof", "(", "double", ")", ")", ";", "p", "=", "(", "double", "*", ")", "malloc", "(", "N", "*", "sizeof", "(", "double", ")", ")", ";", "memset", "(", "p", ",", "0", ",", "sizeof", "(", "double", ")", ")", ";", "z", "=", "(", "double", "*", ")", "malloc", "(", "N", "*", "sizeof", "(", "double", ")", ")", ";", "memset", "(", "z", ",", "0", ",", "sizeof", "(", "double", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "NSI", ";", "i", "++", ")", "A", "[", "i", "]", "=", "A", "[", "i", "]", "/", "MAXTS", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "b", "[", "i", "]", "=", "b", "[", "i", "]", "/", "MAXLV", ";", "gamma", "=", "0.0", ";", "#pragma", " omp parallel for reduction(+ \\\n : gamma)", "\n", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "{", "x", "[", "i", "]", "=", "0.0", ";", "r", "[", "i", "]", "=", "b", "[", "i", "]", ";", "p", "[", "i", "]", "=", "r", "[", "i", "]", ";", "gamma", "+=", "r", "[", "i", "]", "*", "r", "[", "i", "]", ";", "}", "for", "(", "int", "n", "=", "0", ";", "true", ";", "++", "n", ")", "{", "#pragma", " omp parallel for", "\n", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "{", "z", "[", "i", "]", "=", "0.0", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "N", ";", "j", "++", ")", "{", "if", "(", "i", "==", "j", ")", "{", "z", "[", "i", "]", "+=", "A", "[", "IV", "[", "i", "]", "-", "1", "]", "*", "p", "[", "j", "]", ";", "}", "else", "if", "(", "j", ">", "i", ")", "{", "if", "(", "(", "IV", "[", "j", "]", "-", "j", "+", "i", ")", ">", "IV", "[", "j", "-", "1", "]", ")", "z", "[", "i", "]", "+=", "A", "[", "IV", "[", "j", "]", "-", "j", "+", "i", "-", "1", "]", "*", "p", "[", "j", "]", ";", "else", "z", "[", "i", "]", "+=", "0", ";", "}", "else", "if", "(", "i", ">", "j", ")", "{", "if", "(", "(", "IV", "[", "i", "]", "-", "i", "+", "j", ")", ">", "IV", "[", "i", "-", "1", "]", ")", "z", "[", "i", "]", "+=", "A", "[", "IV", "[", "i", "]", "-", "i", "+", "j", "-", "1", "]", "*", "p", "[", "j", "]", ";", "else", "z", "[", "i", "]", "+=", "0", ";", "}", "}", "}", "alpha", "=", "0.0", ";", "#pragma", " omp parallel for reduction(+ \\\n : alpha)", "\n", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "alpha", "+=", "p", "[", "i", "]", "*", "z", "[", "i", "]", ";", "alpha", "=", "gamma", "/", "alpha", ";", "gamma_new", "=", "0.0", ";", "#pragma", " omp parallel for reduction(+ \\\n : gamma_new)", "\n", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "{", "x", "[", "i", "]", "+=", "alpha", "*", "p", "[", "i", "]", ";", "r", "[", "i", "]", "-=", "alpha", "*", "z", "[", "i", "]", ";", "gamma_new", "+=", "r", "[", "i", "]", "*", "r", "[", "i", "]", ";", "}", "gamma_new_sqrt", "=", "sqrt", "(", "gamma_new", ")", ";", "if", "(", "gamma_new_sqrt", "<", "EPS", ")", "break", ";", "if", "(", "ProgressBar", ")", "{", "percent_new", "=", "(", "int", ")", "(", "(", "1", "-", "log10", "(", "gamma_new_sqrt", "*", "1e15", ")", "/", "16", ")", "*", "100", ")", ";", "if", "(", "percent_new", ">", "percent", ")", "{", "percent", "=", "percent_new", ";", "cout", "<<", "\"", "\\r", "\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "4", ";", "i", "++", ")", "if", "(", "i", "<=", "n", "%", "4", ")", "cout", "<<", "\"", "\"", ";", "else", "cout", "<<", "\"", "\"", ";", "cout", "<<", "\"", "\"", "<<", "percent", "<<", "\"", "\"", ";", "cout", "<<", "\"", "\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "49", ";", "i", "++", ")", "if", "(", "i", "<", "percent", "/", "2", ")", "cout", "<<", "\"", "\"", ";", "else", "cout", "<<", "\"", "\"", ";", "cout", "<<", "\"", "\"", ";", "}", "else", "{", "cout", "<<", "\"", "\\r", "\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "4", ";", "i", "++", ")", "if", "(", "i", "<=", "n", "%", "4", ")", "cout", "<<", "\"", "\"", ";", "else", "cout", "<<", "\"", "\"", ";", "}", "}", "beta", "=", "gamma_new", "/", "gamma", ";", "#pragma", " omp parallel for", "\n", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "++", "i", ")", "p", "[", "i", "]", "=", "r", "[", "i", "]", "+", "beta", "*", "p", "[", "i", "]", ";", "gamma", "=", "gamma_new", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "NSI", ";", "i", "++", ")", "A", "[", "i", "]", "=", "A", "[", "i", "]", "*", "MAXTS", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "b", "[", "i", "]", "=", "b", "[", "i", "]", "*", "MAXLV", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "x", "[", "i", "]", "=", "x", "[", "i", "]", "*", "MAXLV", "/", "MAXTS", ";", "if", "(", "ProgressBar", ")", "{", "cout", "<<", "\"", "\\r", "\\n", "\"", ";", "}", "free", "(", "r", ")", ";", "free", "(", "p", ")", ";", "free", "(", "z", ")", ";", "return", "0", ";", "}" ]
solve equation of matrix by conjugate gradient parallel
[ "solve", "equation", "of", "matrix", "by", "conjugate", "gradient", "parallel" ]
[ "// x = [0 ... 0]", "// r = b - A * x", "// p = r", "// gamma = r' * r", "// z = A * p", "// alpha = gamma / (p' * z)", "// x = x + alpha * p", "// r = r - alpha * z", "// gamma_new = r' * r", "// p = r + (gamma_new / gamma) * p;", "// gamma = gamma_new" ]
[ { "param": "A", "type": "double" }, { "param": "b", "type": "double" }, { "param": "x", "type": "double" }, { "param": "N", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "A", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "b", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "N", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d808391e7738380d5e1b2a91d73b416f1ccca145
specialxuan/SpaceFrame
oldversion/SpaceFrame v4.3.h
[ "MIT" ]
C
sfCtlInternalForce
bool
bool sfCtlInternalForce(int i, double xp, double *tf) // i is the number of load, xp is the distance between the section and the begining of rod, tf is internal force { if (i < 0) { sfPrintError(22); return 0; } if (tf == NULL) { sfPrintError(22); return 0; } double xq = loads[i].DLB, t = xq - xp, r = xp / xq, q = loads[i].VOL; // t and r are temperary variables int e = loads[i].PLI; switch (loads[i].KOL) // calculate section force according to kind of loads { case 1: if (xp < xq) { tf[e + 1] = -q; tf[5 - e] = q * t; } break; case 2: if (xp < xq) { tf[e + 1] = -q * t; tf[5 - e] = 0.5 * q * t * t; } break; case 3: if (xp < xq) tf[3 * e] = q; break; case 4: if (xp < xq) tf[3 * e] = q * t; break; case 5: if (xp < xq) { tf[e + 1] = -q * (1 + r) * t / 2; tf[5 - e] = q * t * t * (2 + r) / 6; } break; case 6: if (xp < xq) tf[e + 4] = (2 * e - 1) * q; break; case 7: // temperature change don't generate internal force on cantilever beam break; case 8: break; default: break; } return 0; }
// calculate internal force of cantilever beam
calculate internal force of cantilever beam
[ "calculate", "internal", "force", "of", "cantilever", "beam" ]
bool sfCtlInternalForce(int i, double xp, double *tf) { if (i < 0) { sfPrintError(22); return 0; } if (tf == NULL) { sfPrintError(22); return 0; } double xq = loads[i].DLB, t = xq - xp, r = xp / xq, q = loads[i].VOL; int e = loads[i].PLI; switch (loads[i].KOL) { case 1: if (xp < xq) { tf[e + 1] = -q; tf[5 - e] = q * t; } break; case 2: if (xp < xq) { tf[e + 1] = -q * t; tf[5 - e] = 0.5 * q * t * t; } break; case 3: if (xp < xq) tf[3 * e] = q; break; case 4: if (xp < xq) tf[3 * e] = q * t; break; case 5: if (xp < xq) { tf[e + 1] = -q * (1 + r) * t / 2; tf[5 - e] = q * t * t * (2 + r) / 6; } break; case 6: if (xp < xq) tf[e + 4] = (2 * e - 1) * q; break; case 7: break; case 8: break; default: break; } return 0; }
[ "bool", "sfCtlInternalForce", "(", "int", "i", ",", "double", "xp", ",", "double", "*", "tf", ")", "{", "if", "(", "i", "<", "0", ")", "{", "sfPrintError", "(", "22", ")", ";", "return", "0", ";", "}", "if", "(", "tf", "==", "NULL", ")", "{", "sfPrintError", "(", "22", ")", ";", "return", "0", ";", "}", "double", "xq", "=", "loads", "[", "i", "]", ".", "DLB", ",", "t", "=", "xq", "-", "xp", ",", "r", "=", "xp", "/", "xq", ",", "q", "=", "loads", "[", "i", "]", ".", "VOL", ";", "int", "e", "=", "loads", "[", "i", "]", ".", "PLI", ";", "switch", "(", "loads", "[", "i", "]", ".", "KOL", ")", "{", "case", "1", ":", "if", "(", "xp", "<", "xq", ")", "{", "tf", "[", "e", "+", "1", "]", "=", "-", "q", ";", "tf", "[", "5", "-", "e", "]", "=", "q", "*", "t", ";", "}", "break", ";", "case", "2", ":", "if", "(", "xp", "<", "xq", ")", "{", "tf", "[", "e", "+", "1", "]", "=", "-", "q", "*", "t", ";", "tf", "[", "5", "-", "e", "]", "=", "0.5", "*", "q", "*", "t", "*", "t", ";", "}", "break", ";", "case", "3", ":", "if", "(", "xp", "<", "xq", ")", "tf", "[", "3", "*", "e", "]", "=", "q", ";", "break", ";", "case", "4", ":", "if", "(", "xp", "<", "xq", ")", "tf", "[", "3", "*", "e", "]", "=", "q", "*", "t", ";", "break", ";", "case", "5", ":", "if", "(", "xp", "<", "xq", ")", "{", "tf", "[", "e", "+", "1", "]", "=", "-", "q", "*", "(", "1", "+", "r", ")", "*", "t", "/", "2", ";", "tf", "[", "5", "-", "e", "]", "=", "q", "*", "t", "*", "t", "*", "(", "2", "+", "r", ")", "/", "6", ";", "}", "break", ";", "case", "6", ":", "if", "(", "xp", "<", "xq", ")", "tf", "[", "e", "+", "4", "]", "=", "(", "2", "*", "e", "-", "1", ")", "*", "q", ";", "break", ";", "case", "7", ":", "break", ";", "case", "8", ":", "break", ";", "default", ":", "break", ";", "}", "return", "0", ";", "}" ]
calculate internal force of cantilever beam
[ "calculate", "internal", "force", "of", "cantilever", "beam" ]
[ "// i is the number of load, xp is the distance between the section and the begining of rod, tf is internal force", "// t and r are temperary variables", "// calculate section force according to kind of loads", "// temperature change don't generate internal force on cantilever beam" ]
[ { "param": "i", "type": "int" }, { "param": "xp", "type": "double" }, { "param": "tf", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "i", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "xp", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "tf", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bcdd3a3ad72068e04c85da733089195d9aacbfc
asade89/p-net
src/common/pf_snmp.c
[ "BSD-3-Clause" ]
C
pf_snmp_log_loaded_variable
void
static void pf_snmp_log_loaded_variable ( int error, const char * variable_name, const char * variable_value) { if (error) { LOG_INFO ( PF_SNMP_LOG, "SNMP(%d): Could not yet read %s from nvm. Using '%s'\n", __LINE__, variable_name, variable_value); } else { LOG_INFO ( PF_SNMP_LOG, "SNMP(%d): Did read %s from nvm. %s: %s\n", __LINE__, variable_name, variable_name, variable_value); } }
/** * Log result of variable load operation * * @param error In: Error code returned from pf_file_load(). * @param variable_name In: Name of variable loaded from file. * @param variable_value In: Value of variable loaded from file, in * case no error was detected. */
Log result of variable load operation @param error In: Error code returned from pf_file_load(). @param variable_name In: Name of variable loaded from file. @param variable_value In: Value of variable loaded from file, in case no error was detected.
[ "Log", "result", "of", "variable", "load", "operation", "@param", "error", "In", ":", "Error", "code", "returned", "from", "pf_file_load", "()", ".", "@param", "variable_name", "In", ":", "Name", "of", "variable", "loaded", "from", "file", ".", "@param", "variable_value", "In", ":", "Value", "of", "variable", "loaded", "from", "file", "in", "case", "no", "error", "was", "detected", "." ]
static void pf_snmp_log_loaded_variable ( int error, const char * variable_name, const char * variable_value) { if (error) { LOG_INFO ( PF_SNMP_LOG, "SNMP(%d): Could not yet read %s from nvm. Using '%s'\n", __LINE__, variable_name, variable_value); } else { LOG_INFO ( PF_SNMP_LOG, "SNMP(%d): Did read %s from nvm. %s: %s\n", __LINE__, variable_name, variable_name, variable_value); } }
[ "static", "void", "pf_snmp_log_loaded_variable", "(", "int", "error", ",", "const", "char", "*", "variable_name", ",", "const", "char", "*", "variable_value", ")", "{", "if", "(", "error", ")", "{", "LOG_INFO", "(", "PF_SNMP_LOG", ",", "\"", "\\n", "\"", ",", "__LINE__", ",", "variable_name", ",", "variable_value", ")", ";", "}", "else", "{", "LOG_INFO", "(", "PF_SNMP_LOG", ",", "\"", "\\n", "\"", ",", "__LINE__", ",", "variable_name", ",", "variable_name", ",", "variable_value", ")", ";", "}", "}" ]
Log result of variable load operation @param error In: Error code returned from pf_file_load().
[ "Log", "result", "of", "variable", "load", "operation", "@param", "error", "In", ":", "Error", "code", "returned", "from", "pf_file_load", "()", "." ]
[]
[ { "param": "error", "type": "int" }, { "param": "variable_name", "type": "char" }, { "param": "variable_value", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "error", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "variable_name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "variable_value", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bcdd3a3ad72068e04c85da733089195d9aacbfc
asade89/p-net
src/common/pf_snmp.c
[ "BSD-3-Clause" ]
C
pf_snmp_bit_reversed_byte
uint8_t
static uint8_t pf_snmp_bit_reversed_byte (const uint8_t byte) { uint8_t reversed = 0x00; reversed |= (byte & BIT (7)) >> 7; reversed |= (byte & BIT (0)) << 7; reversed |= (byte & BIT (6)) >> 5; reversed |= (byte & BIT (1)) << 5; reversed |= (byte & BIT (5)) >> 3; reversed |= (byte & BIT (2)) << 3; reversed |= (byte & BIT (4)) >> 1; reversed |= (byte & BIT (3)) << 1; return reversed; }
/** * Reverse bits in byte. * * @param byte In: Byte with bit pattern to reverse. * @return Bit pattern in reversed order. */
Reverse bits in byte. @param byte In: Byte with bit pattern to reverse. @return Bit pattern in reversed order.
[ "Reverse", "bits", "in", "byte", ".", "@param", "byte", "In", ":", "Byte", "with", "bit", "pattern", "to", "reverse", ".", "@return", "Bit", "pattern", "in", "reversed", "order", "." ]
static uint8_t pf_snmp_bit_reversed_byte (const uint8_t byte) { uint8_t reversed = 0x00; reversed |= (byte & BIT (7)) >> 7; reversed |= (byte & BIT (0)) << 7; reversed |= (byte & BIT (6)) >> 5; reversed |= (byte & BIT (1)) << 5; reversed |= (byte & BIT (5)) >> 3; reversed |= (byte & BIT (2)) << 3; reversed |= (byte & BIT (4)) >> 1; reversed |= (byte & BIT (3)) << 1; return reversed; }
[ "static", "uint8_t", "pf_snmp_bit_reversed_byte", "(", "const", "uint8_t", "byte", ")", "{", "uint8_t", "reversed", "=", "0x00", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "7", ")", ")", ">>", "7", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "0", ")", ")", "<<", "7", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "6", ")", ")", ">>", "5", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "1", ")", ")", "<<", "5", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "5", ")", ")", ">>", "3", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "2", ")", ")", "<<", "3", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "4", ")", ")", ">>", "1", ";", "reversed", "|=", "(", "byte", "&", "BIT", "(", "3", ")", ")", "<<", "1", ";", "return", "reversed", ";", "}" ]
Reverse bits in byte.
[ "Reverse", "bits", "in", "byte", "." ]
[]
[ { "param": "byte", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "byte", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bcdd3a3ad72068e04c85da733089195d9aacbfc
asade89/p-net
src/common/pf_snmp.c
[ "BSD-3-Clause" ]
C
pf_snmp_encode_link_status
void
static void pf_snmp_encode_link_status ( pf_snmp_link_status_t * encoded, const pf_lldp_link_status_t * plain) { /* See RFC 2579 "Textual Conventions for SMIv2": "TruthValue" */ encoded->auto_neg_supported = plain->is_autonegotiation_supported ? 1 : 2; encoded->auto_neg_enabled = plain->is_autonegotiation_enabled ? 1 : 2; encoded->oper_mau_type = plain->operational_mau_type; /* See RFC 1906 "Transport Mappings for Version 2 of the * Simple Network Management Protocol (SNMPv2)", ch. 8: * "Serialization using the Basic Encoding Rules", clause 3: * "When encoding an object whose syntax is described using the BITS * construct, the value is encoded as an OCTET STRING, in which all * the named bits in (the definition of) the bitstring, commencing * with the first bit and proceeding to the last bit, are placed in * bits 8 to 1 of the first octet, followed by bits 8 to 1 of each * subsequent octet in turn, followed by as many bits as are needed of * the final subsequent octet, commencing with bit 8. Remaining bits, * if any, of the final octet are set to zero on generation and * ignored on receipt." */ encoded->auto_neg_advertised_cap[0] = pf_snmp_bit_reversed_byte ( (plain->autonegotiation_advertised_capabilities >> 0) & 0xff); encoded->auto_neg_advertised_cap[1] = pf_snmp_bit_reversed_byte ( (plain->autonegotiation_advertised_capabilities >> 8) & 0xff); }
/** * Encode link status for use in SNMP response. * * @param encoded Out: Encoded link status. * @param plain In: Unencoded link status. */
Encode link status for use in SNMP response. @param encoded Out: Encoded link status. @param plain In: Unencoded link status.
[ "Encode", "link", "status", "for", "use", "in", "SNMP", "response", ".", "@param", "encoded", "Out", ":", "Encoded", "link", "status", ".", "@param", "plain", "In", ":", "Unencoded", "link", "status", "." ]
static void pf_snmp_encode_link_status ( pf_snmp_link_status_t * encoded, const pf_lldp_link_status_t * plain) { encoded->auto_neg_supported = plain->is_autonegotiation_supported ? 1 : 2; encoded->auto_neg_enabled = plain->is_autonegotiation_enabled ? 1 : 2; encoded->oper_mau_type = plain->operational_mau_type; encoded->auto_neg_advertised_cap[0] = pf_snmp_bit_reversed_byte ( (plain->autonegotiation_advertised_capabilities >> 0) & 0xff); encoded->auto_neg_advertised_cap[1] = pf_snmp_bit_reversed_byte ( (plain->autonegotiation_advertised_capabilities >> 8) & 0xff); }
[ "static", "void", "pf_snmp_encode_link_status", "(", "pf_snmp_link_status_t", "*", "encoded", ",", "const", "pf_lldp_link_status_t", "*", "plain", ")", "{", "encoded", "->", "auto_neg_supported", "=", "plain", "->", "is_autonegotiation_supported", "?", "1", ":", "2", ";", "encoded", "->", "auto_neg_enabled", "=", "plain", "->", "is_autonegotiation_enabled", "?", "1", ":", "2", ";", "encoded", "->", "oper_mau_type", "=", "plain", "->", "operational_mau_type", ";", "encoded", "->", "auto_neg_advertised_cap", "[", "0", "]", "=", "pf_snmp_bit_reversed_byte", "(", "(", "plain", "->", "autonegotiation_advertised_capabilities", ">>", "0", ")", "&", "0xff", ")", ";", "encoded", "->", "auto_neg_advertised_cap", "[", "1", "]", "=", "pf_snmp_bit_reversed_byte", "(", "(", "plain", "->", "autonegotiation_advertised_capabilities", ">>", "8", ")", "&", "0xff", ")", ";", "}" ]
Encode link status for use in SNMP response.
[ "Encode", "link", "status", "for", "use", "in", "SNMP", "response", "." ]
[ "/* See RFC 2579 \"Textual Conventions for SMIv2\": \"TruthValue\" */", "/* See RFC 1906 \"Transport Mappings for Version 2 of the\n * Simple Network Management Protocol (SNMPv2)\", ch. 8:\n * \"Serialization using the Basic Encoding Rules\", clause 3:\n * \"When encoding an object whose syntax is described using the BITS\n * construct, the value is encoded as an OCTET STRING, in which all\n * the named bits in (the definition of) the bitstring, commencing\n * with the first bit and proceeding to the last bit, are placed in\n * bits 8 to 1 of the first octet, followed by bits 8 to 1 of each\n * subsequent octet in turn, followed by as many bits as are needed of\n * the final subsequent octet, commencing with bit 8. Remaining bits,\n * if any, of the final octet are set to zero on generation and\n * ignored on receipt.\"\n */" ]
[ { "param": "encoded", "type": "pf_snmp_link_status_t" }, { "param": "plain", "type": "pf_lldp_link_status_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "encoded", "type": "pf_snmp_link_status_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "plain", "type": "pf_lldp_link_status_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bcdd3a3ad72068e04c85da733089195d9aacbfc
asade89/p-net
src/common/pf_snmp.c
[ "BSD-3-Clause" ]
C
pf_snmp_encode_management_address
void
static void pf_snmp_encode_management_address ( pf_snmp_management_address_t * encoded, const pf_lldp_management_address_t * plain) { encoded->subtype = plain->subtype; /* See RFC 2578 "Structure of Management Information Version 2 (SMIv2)", * section 7.7, clause 3: * "string-valued, variable-length strings (not preceded by the IMPLIED * keyword): `n+1' sub-identifiers, where `n' is the length of the * string (the first sub-identifier is `n' itself, following this, * each octet of the string is encoded in a separate sub-identifier);"" */ encoded->len = plain->len + 1; encoded->value[0] = plain->len; memcpy (&encoded->value[1], plain->value, plain->len); }
/** * Encode management address for use in SNMP response. * * @param encoded Out: Encoded management address. * @param plain In: Unencoded management address. */
Encode management address for use in SNMP response. @param encoded Out: Encoded management address. @param plain In: Unencoded management address.
[ "Encode", "management", "address", "for", "use", "in", "SNMP", "response", ".", "@param", "encoded", "Out", ":", "Encoded", "management", "address", ".", "@param", "plain", "In", ":", "Unencoded", "management", "address", "." ]
static void pf_snmp_encode_management_address ( pf_snmp_management_address_t * encoded, const pf_lldp_management_address_t * plain) { encoded->subtype = plain->subtype; encoded->len = plain->len + 1; encoded->value[0] = plain->len; memcpy (&encoded->value[1], plain->value, plain->len); }
[ "static", "void", "pf_snmp_encode_management_address", "(", "pf_snmp_management_address_t", "*", "encoded", ",", "const", "pf_lldp_management_address_t", "*", "plain", ")", "{", "encoded", "->", "subtype", "=", "plain", "->", "subtype", ";", "encoded", "->", "len", "=", "plain", "->", "len", "+", "1", ";", "encoded", "->", "value", "[", "0", "]", "=", "plain", "->", "len", ";", "memcpy", "(", "&", "encoded", "->", "value", "[", "1", "]", ",", "plain", "->", "value", ",", "plain", "->", "len", ")", ";", "}" ]
Encode management address for use in SNMP response.
[ "Encode", "management", "address", "for", "use", "in", "SNMP", "response", "." ]
[ "/* See RFC 2578 \"Structure of Management Information Version 2 (SMIv2)\",\n * section 7.7, clause 3:\n * \"string-valued, variable-length strings (not preceded by the IMPLIED\n * keyword): `n+1' sub-identifiers, where `n' is the length of the\n * string (the first sub-identifier is `n' itself, following this,\n * each octet of the string is encoded in a separate sub-identifier);\"\"\n */" ]
[ { "param": "encoded", "type": "pf_snmp_management_address_t" }, { "param": "plain", "type": "pf_lldp_management_address_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "encoded", "type": "pf_snmp_management_address_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "plain", "type": "pf_lldp_management_address_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6bcdd3a3ad72068e04c85da733089195d9aacbfc
asade89/p-net
src/common/pf_snmp.c
[ "BSD-3-Clause" ]
C
pf_snmp_encode_signal_delays
void
static void pf_snmp_encode_signal_delays ( pf_snmp_signal_delay_t * encoded, const pf_lldp_signal_delay_t * plain) { encoded->port_tx_delay_ns = plain->tx_delay_local; encoded->port_rx_delay_ns = plain->rx_delay_local; encoded->line_propagation_delay_ns = plain->cable_delay_local; }
/** * Encode signal delays for use in SNMP response. * * @param encoded Out: Encoded signal delays. * @param plain In: Unencoded signal delays. */
Encode signal delays for use in SNMP response. @param encoded Out: Encoded signal delays. @param plain In: Unencoded signal delays.
[ "Encode", "signal", "delays", "for", "use", "in", "SNMP", "response", ".", "@param", "encoded", "Out", ":", "Encoded", "signal", "delays", ".", "@param", "plain", "In", ":", "Unencoded", "signal", "delays", "." ]
static void pf_snmp_encode_signal_delays ( pf_snmp_signal_delay_t * encoded, const pf_lldp_signal_delay_t * plain) { encoded->port_tx_delay_ns = plain->tx_delay_local; encoded->port_rx_delay_ns = plain->rx_delay_local; encoded->line_propagation_delay_ns = plain->cable_delay_local; }
[ "static", "void", "pf_snmp_encode_signal_delays", "(", "pf_snmp_signal_delay_t", "*", "encoded", ",", "const", "pf_lldp_signal_delay_t", "*", "plain", ")", "{", "encoded", "->", "port_tx_delay_ns", "=", "plain", "->", "tx_delay_local", ";", "encoded", "->", "port_rx_delay_ns", "=", "plain", "->", "rx_delay_local", ";", "encoded", "->", "line_propagation_delay_ns", "=", "plain", "->", "cable_delay_local", ";", "}" ]
Encode signal delays for use in SNMP response.
[ "Encode", "signal", "delays", "for", "use", "in", "SNMP", "response", "." ]
[]
[ { "param": "encoded", "type": "pf_snmp_signal_delay_t" }, { "param": "plain", "type": "pf_lldp_signal_delay_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "encoded", "type": "pf_snmp_signal_delay_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "plain", "type": "pf_lldp_signal_delay_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
e3a65fa2570a24cf97317d5f49632172f363664e
asade89/p-net
src/device/pf_port.c
[ "BSD-3-Clause" ]
C
pf_port_init
void
void pf_port_init (pnet_t * net) { int port; pf_port_iterator_t port_iterator; pf_port_t * p_port_data = NULL; pf_port_init_iterator_over_ports (net, &port_iterator); port = pf_port_get_next (&port_iterator); while (port != 0) { p_port_data = pf_port_get_state (net, port); p_port_data->port_num = port; snprintf ( p_port_data->port_name, sizeof (p_port_data->port_name), "port-%03u", (uint8_t)port); /* Cast to avoid format-truncation */ port = pf_port_get_next (&port_iterator); } }
/** * @file * @brief Manage runtime data for multiple ports */
@file @brief Manage runtime data for multiple ports
[ "@file", "@brief", "Manage", "runtime", "data", "for", "multiple", "ports" ]
void pf_port_init (pnet_t * net) { int port; pf_port_iterator_t port_iterator; pf_port_t * p_port_data = NULL; pf_port_init_iterator_over_ports (net, &port_iterator); port = pf_port_get_next (&port_iterator); while (port != 0) { p_port_data = pf_port_get_state (net, port); p_port_data->port_num = port; snprintf ( p_port_data->port_name, sizeof (p_port_data->port_name), "port-%03u", (uint8_t)port); port = pf_port_get_next (&port_iterator); } }
[ "void", "pf_port_init", "(", "pnet_t", "*", "net", ")", "{", "int", "port", ";", "pf_port_iterator_t", "port_iterator", ";", "pf_port_t", "*", "p_port_data", "=", "NULL", ";", "pf_port_init_iterator_over_ports", "(", "net", ",", "&", "port_iterator", ")", ";", "port", "=", "pf_port_get_next", "(", "&", "port_iterator", ")", ";", "while", "(", "port", "!=", "0", ")", "{", "p_port_data", "=", "pf_port_get_state", "(", "net", ",", "port", ")", ";", "p_port_data", "->", "port_num", "=", "port", ";", "snprintf", "(", "p_port_data", "->", "port_name", ",", "sizeof", "(", "p_port_data", "->", "port_name", ")", ",", "\"", "\"", ",", "(", "uint8_t", ")", "port", ")", ";", "port", "=", "pf_port_get_next", "(", "&", "port_iterator", ")", ";", "}", "}" ]
@file @brief Manage runtime data for multiple ports
[ "@file", "@brief", "Manage", "runtime", "data", "for", "multiple", "ports" ]
[ "/* Cast to avoid format-truncation */" ]
[ { "param": "net", "type": "pnet_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "net", "type": "pnet_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f566b6d2f0987ba75187e2e940fe5f28f847ee1c
asade89/p-net
src/device/pf_pdport.c
[ "BSD-3-Clause" ]
C
pf_pdport_check_peer_station_name
void
static void pf_pdport_check_peer_station_name (pnet_t * net, int loc_port_num) { bool peer_stationname_is_correct = false; pnet_diag_source_t diag_source = {0}; pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num); pf_check_peer_t * p_wanted_peer = &p_port_data->pdport.check.peer; pf_lldp_station_name_t lldp_station_name; if (pf_lldp_get_peer_station_name (net, loc_port_num, &lldp_station_name) == 0) { pf_pdport_init_diag_source (net, &diag_source, loc_port_num); if ( strncmp ( lldp_station_name.string, (char *)p_wanted_peer->peer_station_name, lldp_station_name.len) == 0) { peer_stationname_is_correct = true; } if (peer_stationname_is_correct == false) { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Setting peer station name mismatch diagnosis: " "\"%.*s\". " "Wanted peer station name: \"%.*s\"\n", __LINE__, (int)lldp_station_name.len, lldp_station_name.string, p_wanted_peer->length_peer_station_name, p_wanted_peer->peer_station_name); (void)pf_diag_std_add ( net, &diag_source, PNET_DIAG_CH_PROP_TYPE_UNSPECIFIED, PNET_DIAG_CH_PROP_MAINT_FAULT, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_STATIONNAME_MISMATCH, 0, 0); } else { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Peer station name is correct: \"%.*s\". " "Remove diagnosis.\n", __LINE__, (int)lldp_station_name.len, lldp_station_name.string); (void)pf_diag_std_remove ( net, &diag_source, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_STATIONNAME_MISMATCH); } } }
/** * @internal * Run peer station name check * * Compare LLDP peer information with configured pdport peer. * Trigger a diagnosis if wrong peer is connected. * Remove diagnosis if expected peer data is received. * * Does nothing if no peer is available. * * @param net InOut: The p-net stack instance * @param loc_port_num In: Local port number. * Valid range: 1 .. num_physical_ports */
@internal Run peer station name check Compare LLDP peer information with configured pdport peer. Trigger a diagnosis if wrong peer is connected. Remove diagnosis if expected peer data is received. Does nothing if no peer is available. @param net InOut: The p-net stack instance @param loc_port_num In: Local port number. Valid range: 1 ..
[ "@internal", "Run", "peer", "station", "name", "check", "Compare", "LLDP", "peer", "information", "with", "configured", "pdport", "peer", ".", "Trigger", "a", "diagnosis", "if", "wrong", "peer", "is", "connected", ".", "Remove", "diagnosis", "if", "expected", "peer", "data", "is", "received", ".", "Does", "nothing", "if", "no", "peer", "is", "available", ".", "@param", "net", "InOut", ":", "The", "p", "-", "net", "stack", "instance", "@param", "loc_port_num", "In", ":", "Local", "port", "number", ".", "Valid", "range", ":", "1", ".." ]
static void pf_pdport_check_peer_station_name (pnet_t * net, int loc_port_num) { bool peer_stationname_is_correct = false; pnet_diag_source_t diag_source = {0}; pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num); pf_check_peer_t * p_wanted_peer = &p_port_data->pdport.check.peer; pf_lldp_station_name_t lldp_station_name; if (pf_lldp_get_peer_station_name (net, loc_port_num, &lldp_station_name) == 0) { pf_pdport_init_diag_source (net, &diag_source, loc_port_num); if ( strncmp ( lldp_station_name.string, (char *)p_wanted_peer->peer_station_name, lldp_station_name.len) == 0) { peer_stationname_is_correct = true; } if (peer_stationname_is_correct == false) { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Setting peer station name mismatch diagnosis: " "\"%.*s\". " "Wanted peer station name: \"%.*s\"\n", __LINE__, (int)lldp_station_name.len, lldp_station_name.string, p_wanted_peer->length_peer_station_name, p_wanted_peer->peer_station_name); (void)pf_diag_std_add ( net, &diag_source, PNET_DIAG_CH_PROP_TYPE_UNSPECIFIED, PNET_DIAG_CH_PROP_MAINT_FAULT, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_STATIONNAME_MISMATCH, 0, 0); } else { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Peer station name is correct: \"%.*s\". " "Remove diagnosis.\n", __LINE__, (int)lldp_station_name.len, lldp_station_name.string); (void)pf_diag_std_remove ( net, &diag_source, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_STATIONNAME_MISMATCH); } } }
[ "static", "void", "pf_pdport_check_peer_station_name", "(", "pnet_t", "*", "net", ",", "int", "loc_port_num", ")", "{", "bool", "peer_stationname_is_correct", "=", "false", ";", "pnet_diag_source_t", "diag_source", "=", "{", "0", "}", ";", "pf_port_t", "*", "p_port_data", "=", "pf_port_get_state", "(", "net", ",", "loc_port_num", ")", ";", "pf_check_peer_t", "*", "p_wanted_peer", "=", "&", "p_port_data", "->", "pdport", ".", "check", ".", "peer", ";", "pf_lldp_station_name_t", "lldp_station_name", ";", "if", "(", "pf_lldp_get_peer_station_name", "(", "net", ",", "loc_port_num", ",", "&", "lldp_station_name", ")", "==", "0", ")", "{", "pf_pdport_init_diag_source", "(", "net", ",", "&", "diag_source", ",", "loc_port_num", ")", ";", "if", "(", "strncmp", "(", "lldp_station_name", ".", "string", ",", "(", "char", "*", ")", "p_wanted_peer", "->", "peer_station_name", ",", "lldp_station_name", ".", "len", ")", "==", "0", ")", "{", "peer_stationname_is_correct", "=", "true", ";", "}", "if", "(", "peer_stationname_is_correct", "==", "false", ")", "{", "LOG_DEBUG", "(", "PNET_LOG", ",", "\"", "\"", "\"", "\\\"", "\\\"", "\"", "\"", "\\\"", "\\\"", "\\n", "\"", ",", "__LINE__", ",", "(", "int", ")", "lldp_station_name", ".", "len", ",", "lldp_station_name", ".", "string", ",", "p_wanted_peer", "->", "length_peer_station_name", ",", "p_wanted_peer", "->", "peer_station_name", ")", ";", "(", "void", ")", "pf_diag_std_add", "(", "net", ",", "&", "diag_source", ",", "PNET_DIAG_CH_PROP_TYPE_UNSPECIFIED", ",", "PNET_DIAG_CH_PROP_MAINT_FAULT", ",", "PF_WRT_ERROR_REMOTE_MISMATCH", ",", "PF_WRT_ERROR_PEER_STATIONNAME_MISMATCH", ",", "0", ",", "0", ")", ";", "}", "else", "{", "LOG_DEBUG", "(", "PNET_LOG", ",", "\"", "\\\"", "\\\"", "\"", "\"", "\\n", "\"", ",", "__LINE__", ",", "(", "int", ")", "lldp_station_name", ".", "len", ",", "lldp_station_name", ".", "string", ")", ";", "(", "void", ")", "pf_diag_std_remove", "(", "net", ",", "&", "diag_source", ",", "PF_WRT_ERROR_REMOTE_MISMATCH", ",", "PF_WRT_ERROR_PEER_STATIONNAME_MISMATCH", ")", ";", "}", "}", "}" ]
@internal Run peer station name check
[ "@internal", "Run", "peer", "station", "name", "check" ]
[]
[ { "param": "net", "type": "pnet_t" }, { "param": "loc_port_num", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "net", "type": "pnet_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "loc_port_num", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f566b6d2f0987ba75187e2e940fe5f28f847ee1c
asade89/p-net
src/device/pf_pdport.c
[ "BSD-3-Clause" ]
C
pf_pdport_check_peer_port_name
void
static void pf_pdport_check_peer_port_name (pnet_t * net, int loc_port_num) { bool peer_portname_is_correct = false; pnet_diag_source_t diag_source = {0}; pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num); pf_check_peer_t * p_wanted_peer = &p_port_data->pdport.check.peer; pf_lldp_port_id_t lldp_port_id; if (pf_lldp_get_peer_port_id (net, loc_port_num, &lldp_port_id) == 0) { pf_pdport_init_diag_source (net, &diag_source, loc_port_num); if ( strncmp ( lldp_port_id.string, (char *)p_wanted_peer->peer_port_name, lldp_port_id.len) == 0) { peer_portname_is_correct = true; } if (peer_portname_is_correct == false) { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Setting peer port name mismatch diagnosis: \"%.*s\". " "Wanted peer port name: \"%.*s\"\n", __LINE__, (int)lldp_port_id.len, lldp_port_id.string, p_wanted_peer->length_peer_port_name, p_wanted_peer->peer_port_name); (void)pf_diag_std_add ( net, &diag_source, PNET_DIAG_CH_PROP_TYPE_UNSPECIFIED, PNET_DIAG_CH_PROP_MAINT_FAULT, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_PORTNAME_MISMATCH, 0, 0); } else { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Peer port name is correct: \"%.*s\". " "Remove diagnosis.\n", __LINE__, (int)lldp_port_id.len, lldp_port_id.string); (void)pf_diag_std_remove ( net, &diag_source, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_PORTNAME_MISMATCH); } } }
/** * @internal * Run peer port name check * * Compare LLDP peer information with configured pdport peer. * Trigger an diagnosis if unexpected peer data is connected. * Remove diagnosis if expected peer data is received. * * Does nothing if no peer is available. * * @param net InOut: The p-net stack instance * @param loc_port_num In: Local port number. * Valid range: 1 .. num_physical_ports */
@internal Run peer port name check Compare LLDP peer information with configured pdport peer. Trigger an diagnosis if unexpected peer data is connected. Remove diagnosis if expected peer data is received. Does nothing if no peer is available. @param net InOut: The p-net stack instance @param loc_port_num In: Local port number. Valid range: 1 ..
[ "@internal", "Run", "peer", "port", "name", "check", "Compare", "LLDP", "peer", "information", "with", "configured", "pdport", "peer", ".", "Trigger", "an", "diagnosis", "if", "unexpected", "peer", "data", "is", "connected", ".", "Remove", "diagnosis", "if", "expected", "peer", "data", "is", "received", ".", "Does", "nothing", "if", "no", "peer", "is", "available", ".", "@param", "net", "InOut", ":", "The", "p", "-", "net", "stack", "instance", "@param", "loc_port_num", "In", ":", "Local", "port", "number", ".", "Valid", "range", ":", "1", ".." ]
static void pf_pdport_check_peer_port_name (pnet_t * net, int loc_port_num) { bool peer_portname_is_correct = false; pnet_diag_source_t diag_source = {0}; pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num); pf_check_peer_t * p_wanted_peer = &p_port_data->pdport.check.peer; pf_lldp_port_id_t lldp_port_id; if (pf_lldp_get_peer_port_id (net, loc_port_num, &lldp_port_id) == 0) { pf_pdport_init_diag_source (net, &diag_source, loc_port_num); if ( strncmp ( lldp_port_id.string, (char *)p_wanted_peer->peer_port_name, lldp_port_id.len) == 0) { peer_portname_is_correct = true; } if (peer_portname_is_correct == false) { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Setting peer port name mismatch diagnosis: \"%.*s\". " "Wanted peer port name: \"%.*s\"\n", __LINE__, (int)lldp_port_id.len, lldp_port_id.string, p_wanted_peer->length_peer_port_name, p_wanted_peer->peer_port_name); (void)pf_diag_std_add ( net, &diag_source, PNET_DIAG_CH_PROP_TYPE_UNSPECIFIED, PNET_DIAG_CH_PROP_MAINT_FAULT, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_PORTNAME_MISMATCH, 0, 0); } else { LOG_DEBUG ( PNET_LOG, "PDPORT(%d): Peer port name is correct: \"%.*s\". " "Remove diagnosis.\n", __LINE__, (int)lldp_port_id.len, lldp_port_id.string); (void)pf_diag_std_remove ( net, &diag_source, PF_WRT_ERROR_REMOTE_MISMATCH, PF_WRT_ERROR_PEER_PORTNAME_MISMATCH); } } }
[ "static", "void", "pf_pdport_check_peer_port_name", "(", "pnet_t", "*", "net", ",", "int", "loc_port_num", ")", "{", "bool", "peer_portname_is_correct", "=", "false", ";", "pnet_diag_source_t", "diag_source", "=", "{", "0", "}", ";", "pf_port_t", "*", "p_port_data", "=", "pf_port_get_state", "(", "net", ",", "loc_port_num", ")", ";", "pf_check_peer_t", "*", "p_wanted_peer", "=", "&", "p_port_data", "->", "pdport", ".", "check", ".", "peer", ";", "pf_lldp_port_id_t", "lldp_port_id", ";", "if", "(", "pf_lldp_get_peer_port_id", "(", "net", ",", "loc_port_num", ",", "&", "lldp_port_id", ")", "==", "0", ")", "{", "pf_pdport_init_diag_source", "(", "net", ",", "&", "diag_source", ",", "loc_port_num", ")", ";", "if", "(", "strncmp", "(", "lldp_port_id", ".", "string", ",", "(", "char", "*", ")", "p_wanted_peer", "->", "peer_port_name", ",", "lldp_port_id", ".", "len", ")", "==", "0", ")", "{", "peer_portname_is_correct", "=", "true", ";", "}", "if", "(", "peer_portname_is_correct", "==", "false", ")", "{", "LOG_DEBUG", "(", "PNET_LOG", ",", "\"", "\\\"", "\\\"", "\"", "\"", "\\\"", "\\\"", "\\n", "\"", ",", "__LINE__", ",", "(", "int", ")", "lldp_port_id", ".", "len", ",", "lldp_port_id", ".", "string", ",", "p_wanted_peer", "->", "length_peer_port_name", ",", "p_wanted_peer", "->", "peer_port_name", ")", ";", "(", "void", ")", "pf_diag_std_add", "(", "net", ",", "&", "diag_source", ",", "PNET_DIAG_CH_PROP_TYPE_UNSPECIFIED", ",", "PNET_DIAG_CH_PROP_MAINT_FAULT", ",", "PF_WRT_ERROR_REMOTE_MISMATCH", ",", "PF_WRT_ERROR_PEER_PORTNAME_MISMATCH", ",", "0", ",", "0", ")", ";", "}", "else", "{", "LOG_DEBUG", "(", "PNET_LOG", ",", "\"", "\\\"", "\\\"", "\"", "\"", "\\n", "\"", ",", "__LINE__", ",", "(", "int", ")", "lldp_port_id", ".", "len", ",", "lldp_port_id", ".", "string", ")", ";", "(", "void", ")", "pf_diag_std_remove", "(", "net", ",", "&", "diag_source", ",", "PF_WRT_ERROR_REMOTE_MISMATCH", ",", "PF_WRT_ERROR_PEER_PORTNAME_MISMATCH", ")", ";", "}", "}", "}" ]
@internal Run peer port name check
[ "@internal", "Run", "peer", "port", "name", "check" ]
[]
[ { "param": "net", "type": "pnet_t" }, { "param": "loc_port_num", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "net", "type": "pnet_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "loc_port_num", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fc381ef62717c52ebbf7955b8b080ac7d805b787
nesdoug/32_MMC1
MMC1/bank_helpers.c
[ "MIT" ]
C
banked_call
void
void banked_call(unsigned char bankId, void (*method)(void)) { bank_push(bankId); (*method)(); bank_pop(); }
// call a function in a different bank
call a function in a different bank
[ "call", "a", "function", "in", "a", "different", "bank" ]
void banked_call(unsigned char bankId, void (*method)(void)) { bank_push(bankId); (*method)(); bank_pop(); }
[ "void", "banked_call", "(", "unsigned", "char", "bankId", ",", "void", "(", "*", "method", ")", "(", "void", ")", ")", "{", "bank_push", "(", "bankId", ")", ";", "(", "*", "method", ")", "(", ")", ";", "bank_pop", "(", ")", ";", "}" ]
call a function in a different bank
[ "call", "a", "function", "in", "a", "different", "bank" ]
[]
[ { "param": "bankId", "type": "unsigned char" }, { "param": "method", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bankId", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "method", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fc381ef62717c52ebbf7955b8b080ac7d805b787
nesdoug/32_MMC1
MMC1/bank_helpers.c
[ "MIT" ]
C
bank_push
void
void bank_push(unsigned char bankId) { bankBuffer[bankLevel] = bankId; ++bankLevel; // removed error code set_prg_bank(bankId); }
// Internal function used by banked_call(), don't call this directly. // Switch to the given bank, and keep track of the // current bank, so that we may jump back to it as needed.
Internal function used by banked_call(), don't call this directly. Switch to the given bank, and keep track of the current bank, so that we may jump back to it as needed.
[ "Internal", "function", "used", "by", "banked_call", "()", "don", "'", "t", "call", "this", "directly", ".", "Switch", "to", "the", "given", "bank", "and", "keep", "track", "of", "the", "current", "bank", "so", "that", "we", "may", "jump", "back", "to", "it", "as", "needed", "." ]
void bank_push(unsigned char bankId) { bankBuffer[bankLevel] = bankId; ++bankLevel; set_prg_bank(bankId); }
[ "void", "bank_push", "(", "unsigned", "char", "bankId", ")", "{", "bankBuffer", "[", "bankLevel", "]", "=", "bankId", ";", "++", "bankLevel", ";", "set_prg_bank", "(", "bankId", ")", ";", "}" ]
Internal function used by banked_call(), don't call this directly.
[ "Internal", "function", "used", "by", "banked_call", "()", "don", "'", "t", "call", "this", "directly", "." ]
[ "// removed error code" ]
[ { "param": "bankId", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bankId", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fc381ef62717c52ebbf7955b8b080ac7d805b787
nesdoug/32_MMC1
MMC1/bank_helpers.c
[ "MIT" ]
C
bank_pop
void
void bank_pop(void) { --bankLevel; if (bankLevel > 0) { set_prg_bank(bankBuffer[bankLevel-1]); } }
// Internal function used by banked_call(), don't call this directly. // Go back to the previous bank
Internal function used by banked_call(), don't call this directly. Go back to the previous bank
[ "Internal", "function", "used", "by", "banked_call", "()", "don", "'", "t", "call", "this", "directly", ".", "Go", "back", "to", "the", "previous", "bank" ]
void bank_pop(void) { --bankLevel; if (bankLevel > 0) { set_prg_bank(bankBuffer[bankLevel-1]); } }
[ "void", "bank_pop", "(", "void", ")", "{", "--", "bankLevel", ";", "if", "(", "bankLevel", ">", "0", ")", "{", "set_prg_bank", "(", "bankBuffer", "[", "bankLevel", "-", "1", "]", ")", ";", "}", "}" ]
Internal function used by banked_call(), don't call this directly.
[ "Internal", "function", "used", "by", "banked_call", "()", "don", "'", "t", "call", "this", "directly", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
47d1e77c3ff0c1feb52e504ae834f42d30f5f19c
nesdoug/32_MMC1
hello_mmc1.c
[ "MIT" ]
C
draw_sprites
void
void draw_sprites (void) { bank_spr(1); oam_clear(); oam_spr(0x50,0x10,0,0); oam_spr(0x58,0x10,1,0); oam_spr(0x50,0x18,0x10,0); oam_spr(0x58,0x18,0x11,0); }
// testing sprites using the second tileset
testing sprites using the second tileset
[ "testing", "sprites", "using", "the", "second", "tileset" ]
void draw_sprites (void) { bank_spr(1); oam_clear(); oam_spr(0x50,0x10,0,0); oam_spr(0x58,0x10,1,0); oam_spr(0x50,0x18,0x10,0); oam_spr(0x58,0x18,0x11,0); }
[ "void", "draw_sprites", "(", "void", ")", "{", "bank_spr", "(", "1", ")", ";", "oam_clear", "(", ")", ";", "oam_spr", "(", "0x50", ",", "0x10", ",", "0", ",", "0", ")", ";", "oam_spr", "(", "0x58", ",", "0x10", ",", "1", ",", "0", ")", ";", "oam_spr", "(", "0x50", ",", "0x18", ",", "0x10", ",", "0", ")", ";", "oam_spr", "(", "0x58", ",", "0x18", ",", "0x11", ",", "0", ")", ";", "}" ]
testing sprites using the second tileset
[ "testing", "sprites", "using", "the", "second", "tileset" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f550e92849e90f092af135ce5f85cfa07066ca4e
himanshulikhar55/memorysubsystem
segmentation.c
[ "MIT" ]
C
make_entry_LDT
void
void make_entry_LDT(segment *LDT, uint8_t selector, uint64_t base, uint32_t limit) { uint8_t index = selector; if(index > MAX_LDT_ENTRIES) error("Cannot make more LDT entries"); LDT[index].base = base; LDT[index].limit = limit; LDT[index].status = 0x10; //default status bits }
//Make an entry in LDT with the help of selector
Make an entry in LDT with the help of selector
[ "Make", "an", "entry", "in", "LDT", "with", "the", "help", "of", "selector" ]
void make_entry_LDT(segment *LDT, uint8_t selector, uint64_t base, uint32_t limit) { uint8_t index = selector; if(index > MAX_LDT_ENTRIES) error("Cannot make more LDT entries"); LDT[index].base = base; LDT[index].limit = limit; LDT[index].status = 0x10; }
[ "void", "make_entry_LDT", "(", "segment", "*", "LDT", ",", "uint8_t", "selector", ",", "uint64_t", "base", ",", "uint32_t", "limit", ")", "{", "uint8_t", "index", "=", "selector", ";", "if", "(", "index", ">", "MAX_LDT_ENTRIES", ")", "error", "(", "\"", "\"", ")", ";", "LDT", "[", "index", "]", ".", "base", "=", "base", ";", "LDT", "[", "index", "]", ".", "limit", "=", "limit", ";", "LDT", "[", "index", "]", ".", "status", "=", "0x10", ";", "}" ]
Make an entry in LDT with the help of selector
[ "Make", "an", "entry", "in", "LDT", "with", "the", "help", "of", "selector" ]
[ "//default status bits" ]
[ { "param": "LDT", "type": "segment" }, { "param": "selector", "type": "uint8_t" }, { "param": "base", "type": "uint64_t" }, { "param": "limit", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "LDT", "type": "segment", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "selector", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "base", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "limit", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f550e92849e90f092af135ce5f85cfa07066ca4e
himanshulikhar55/memorysubsystem
segmentation.c
[ "MIT" ]
C
make_entry_GDT
void
void make_entry_GDT(segment *GDT, uint8_t selector, uint64_t base, uint32_t limit){ uint8_t index = selector; if(index > MAX_GDT_ENTRIES) error("Cannot make more GDT entries"); GDT[index].base = base; GDT[index].limit = limit; GDT[index].status = 0x10; //default status bits }
//Make an entry in GDT with the help of selector
Make an entry in GDT with the help of selector
[ "Make", "an", "entry", "in", "GDT", "with", "the", "help", "of", "selector" ]
void make_entry_GDT(segment *GDT, uint8_t selector, uint64_t base, uint32_t limit){ uint8_t index = selector; if(index > MAX_GDT_ENTRIES) error("Cannot make more GDT entries"); GDT[index].base = base; GDT[index].limit = limit; GDT[index].status = 0x10; }
[ "void", "make_entry_GDT", "(", "segment", "*", "GDT", ",", "uint8_t", "selector", ",", "uint64_t", "base", ",", "uint32_t", "limit", ")", "{", "uint8_t", "index", "=", "selector", ";", "if", "(", "index", ">", "MAX_GDT_ENTRIES", ")", "error", "(", "\"", "\"", ")", ";", "GDT", "[", "index", "]", ".", "base", "=", "base", ";", "GDT", "[", "index", "]", ".", "limit", "=", "limit", ";", "GDT", "[", "index", "]", ".", "status", "=", "0x10", ";", "}" ]
Make an entry in GDT with the help of selector
[ "Make", "an", "entry", "in", "GDT", "with", "the", "help", "of", "selector" ]
[ "//default status bits" ]
[ { "param": "GDT", "type": "segment" }, { "param": "selector", "type": "uint8_t" }, { "param": "base", "type": "uint64_t" }, { "param": "limit", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "GDT", "type": "segment", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "selector", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "base", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "limit", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f550e92849e90f092af135ce5f85cfa07066ca4e
himanshulikhar55/memorysubsystem
segmentation.c
[ "MIT" ]
C
search_LDT
segment
segment search_LDT(uint8_t selector, uint8_t process_num){ int8_t index = (selector & 0x78) >> 3;//01111000 uint8_t protec = selector & 0x0003;//0000000000000011 int8_t ldtr_index = process_num + 1;//getting the entry index from LDTR, 4 MSBs, so 01111000, MSB is 0 due to padding uint16_t limit = GDT[ldtr_index].limit;//length of the LDT if(index>limit) error("Address out of bound"); segment* LDT = (segment *)(GDT[ldtr_index].base);//base address of the LDT if(index > (GDT[ldtr_index].limit)) error("Index Out of LDT Bound"); return LDT[index]; }
//search for a particular entry in LDT. Go to GDT with the help of LDTR to find the start of LDT
search for a particular entry in LDT. Go to GDT with the help of LDTR to find the start of LDT
[ "search", "for", "a", "particular", "entry", "in", "LDT", ".", "Go", "to", "GDT", "with", "the", "help", "of", "LDTR", "to", "find", "the", "start", "of", "LDT" ]
segment search_LDT(uint8_t selector, uint8_t process_num){ int8_t index = (selector & 0x78) >> 3; uint8_t protec = selector & 0x0003; int8_t ldtr_index = process_num + 1; uint16_t limit = GDT[ldtr_index].limit; if(index>limit) error("Address out of bound"); segment* LDT = (segment *)(GDT[ldtr_index].base); if(index > (GDT[ldtr_index].limit)) error("Index Out of LDT Bound"); return LDT[index]; }
[ "segment", "search_LDT", "(", "uint8_t", "selector", ",", "uint8_t", "process_num", ")", "{", "int8_t", "index", "=", "(", "selector", "&", "0x78", ")", ">>", "3", ";", "uint8_t", "protec", "=", "selector", "&", "0x0003", ";", "int8_t", "ldtr_index", "=", "process_num", "+", "1", ";", "uint16_t", "limit", "=", "GDT", "[", "ldtr_index", "]", ".", "limit", ";", "if", "(", "index", ">", "limit", ")", "error", "(", "\"", "\"", ")", ";", "segment", "*", "LDT", "=", "(", "segment", "*", ")", "(", "GDT", "[", "ldtr_index", "]", ".", "base", ")", ";", "if", "(", "index", ">", "(", "GDT", "[", "ldtr_index", "]", ".", "limit", ")", ")", "error", "(", "\"", "\"", ")", ";", "return", "LDT", "[", "index", "]", ";", "}" ]
search for a particular entry in LDT.
[ "search", "for", "a", "particular", "entry", "in", "LDT", "." ]
[ "//01111000", "//0000000000000011", "//getting the entry index from LDTR, 4 MSBs, so 01111000, MSB is 0 due to padding", "//length of the LDT", "//base address of the LDT" ]
[ { "param": "selector", "type": "uint8_t" }, { "param": "process_num", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "selector", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "process_num", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f550e92849e90f092af135ce5f85cfa07066ca4e
himanshulikhar55/memorysubsystem
segmentation.c
[ "MIT" ]
C
search_GDT
segment
segment search_GDT(uint8_t selector){ int8_t index = selector & 0x78;//01111000 uint8_t protec = selector & 0x0003; return GDT[index]; if(GDT[index].status & 0x0003 >= protec){ return GDT[index]; } else error("Please ensure that you have the proper access permissions"); }
//search for a particular entry in GDT based on the selector
search for a particular entry in GDT based on the selector
[ "search", "for", "a", "particular", "entry", "in", "GDT", "based", "on", "the", "selector" ]
segment search_GDT(uint8_t selector){ int8_t index = selector & 0x78; uint8_t protec = selector & 0x0003; return GDT[index]; if(GDT[index].status & 0x0003 >= protec){ return GDT[index]; } else error("Please ensure that you have the proper access permissions"); }
[ "segment", "search_GDT", "(", "uint8_t", "selector", ")", "{", "int8_t", "index", "=", "selector", "&", "0x78", ";", "uint8_t", "protec", "=", "selector", "&", "0x0003", ";", "return", "GDT", "[", "index", "]", ";", "if", "(", "GDT", "[", "index", "]", ".", "status", "&", "0x0003", ">=", "protec", ")", "{", "return", "GDT", "[", "index", "]", ";", "}", "else", "error", "(", "\"", "\"", ")", ";", "}" ]
search for a particular entry in GDT based on the selector
[ "search", "for", "a", "particular", "entry", "in", "GDT", "based", "on", "the", "selector" ]
[ "//01111000" ]
[ { "param": "selector", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "selector", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7c11e1da7f9b5503e43a59df9097c595a41039f9
himanshulikhar55/memorysubsystem
l2_tlb.c
[ "MIT" ]
C
l2_tlb_initialize
void
void l2_tlb_initialize(){ l2_curr_position=0; l2_tlb = (tlb_entry *) malloc(sizeof(tlb_entry) * NUM_L2_TLB_ENTERIES); l2_tlb_flush(); }
// All entries in tlb are invalid in the beginning
All entries in tlb are invalid in the beginning
[ "All", "entries", "in", "tlb", "are", "invalid", "in", "the", "beginning" ]
void l2_tlb_initialize(){ l2_curr_position=0; l2_tlb = (tlb_entry *) malloc(sizeof(tlb_entry) * NUM_L2_TLB_ENTERIES); l2_tlb_flush(); }
[ "void", "l2_tlb_initialize", "(", ")", "{", "l2_curr_position", "=", "0", ";", "l2_tlb", "=", "(", "tlb_entry", "*", ")", "malloc", "(", "sizeof", "(", "tlb_entry", ")", "*", "NUM_L2_TLB_ENTERIES", ")", ";", "l2_tlb_flush", "(", ")", ";", "}" ]
All entries in tlb are invalid in the beginning
[ "All", "entries", "in", "tlb", "are", "invalid", "in", "the", "beginning" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
4e71cba5b0c19cd095f8632ea3d370691f20247d
himanshulikhar55/memorysubsystem
L2_cache_char.c
[ "MIT" ]
C
l2_initialize
void
void l2_initialize() { //CODE HERE for(int i = 0; i < 128; i++) { for(int j = 0; j < 8; j++) { //clearing the valid bit, and counter bits of all entries l2_cache[i].lines[j].v_d_c_tag = (l2_cache[i].lines[j].v_d_c_tag & 0x47FFFFFF); //storing 0s in the cache line for (int k = 0; k < 16; k++) { l2_cache[i].lines[j].cache_line[k][0] = "0"; l2_cache[i].lines[j].cache_line[k][1] = "0"; } } } }
/************************************************ l2_initialize() This procedure initializes the L2 cache ************************************************/
l2_initialize() This procedure initializes the L2 cache
[ "l2_initialize", "()", "This", "procedure", "initializes", "the", "L2", "cache" ]
void l2_initialize() { for(int i = 0; i < 128; i++) { for(int j = 0; j < 8; j++) { l2_cache[i].lines[j].v_d_c_tag = (l2_cache[i].lines[j].v_d_c_tag & 0x47FFFFFF); for (int k = 0; k < 16; k++) { l2_cache[i].lines[j].cache_line[k][0] = "0"; l2_cache[i].lines[j].cache_line[k][1] = "0"; } } } }
[ "void", "l2_initialize", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "128", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "8", ";", "j", "++", ")", "{", "l2_cache", "[", "i", "]", ".", "lines", "[", "j", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "i", "]", ".", "lines", "[", "j", "]", ".", "v_d_c_tag", "&", "0x47FFFFFF", ")", ";", "for", "(", "int", "k", "=", "0", ";", "k", "<", "16", ";", "k", "++", ")", "{", "l2_cache", "[", "i", "]", ".", "lines", "[", "j", "]", ".", "cache_line", "[", "k", "]", "[", "0", "]", "=", "\"", "\"", ";", "l2_cache", "[", "i", "]", ".", "lines", "[", "j", "]", ".", "cache_line", "[", "k", "]", "[", "1", "]", "=", "\"", "\"", ";", "}", "}", "}", "}" ]
l2_initialize() This procedure initializes the L2 cache
[ "l2_initialize", "()", "This", "procedure", "initializes", "the", "L2", "cache" ]
[ "//CODE HERE", "//clearing the valid bit, and counter bits of all entries", "//storing 0s in the cache line" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
4e71cba5b0c19cd095f8632ea3d370691f20247d
himanshulikhar55/memorysubsystem
L2_cache_char.c
[ "MIT" ]
C
update_counter_bits
void
void update_counter_bits(uint32_t temp_index, int line) { l2_cache[temp_index].lines[line].v_d_c_tag = (l2_cache[temp_index].lines[line].v_d_c_tag | L2_COUNTER_MASK); for (int i = 0; i < 8; i++){ if (i != line) { uint32_t temp_count = (l2_cache[temp_index].lines[i].v_d_c_tag & L2_COUNTER_MASK) >> 27; --temp_count; temp_count = (temp_count << 27); l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | temp_count); } } }
/********************************************************** update_counter_bits() This procedure updates the counter bits of the particular set that is mentioned in the address passed to the function. It sets the counter value of the most recently used entry to 111 and decrements the counter value by 1 of all the other entries in that set **********************************************************/
update_counter_bits() This procedure updates the counter bits of the particular set that is mentioned in the address passed to the function. It sets the counter value of the most recently used entry to 111 and decrements the counter value by 1 of all the other entries in that set
[ "update_counter_bits", "()", "This", "procedure", "updates", "the", "counter", "bits", "of", "the", "particular", "set", "that", "is", "mentioned", "in", "the", "address", "passed", "to", "the", "function", ".", "It", "sets", "the", "counter", "value", "of", "the", "most", "recently", "used", "entry", "to", "111", "and", "decrements", "the", "counter", "value", "by", "1", "of", "all", "the", "other", "entries", "in", "that", "set" ]
void update_counter_bits(uint32_t temp_index, int line) { l2_cache[temp_index].lines[line].v_d_c_tag = (l2_cache[temp_index].lines[line].v_d_c_tag | L2_COUNTER_MASK); for (int i = 0; i < 8; i++){ if (i != line) { uint32_t temp_count = (l2_cache[temp_index].lines[i].v_d_c_tag & L2_COUNTER_MASK) >> 27; --temp_count; temp_count = (temp_count << 27); l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | temp_count); } } }
[ "void", "update_counter_bits", "(", "uint32_t", "temp_index", ",", "int", "line", ")", "{", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "line", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "line", "]", ".", "v_d_c_tag", "|", "L2_COUNTER_MASK", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "if", "(", "i", "!=", "line", ")", "{", "uint32_t", "temp_count", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "L2_COUNTER_MASK", ")", ">>", "27", ";", "--", "temp_count", ";", "temp_count", "=", "(", "temp_count", "<<", "27", ")", ";", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "|", "temp_count", ")", ";", "}", "}", "}" ]
update_counter_bits() This procedure updates the counter bits of the particular set that is mentioned in the address passed to the function.
[ "update_counter_bits", "()", "This", "procedure", "updates", "the", "counter", "bits", "of", "the", "particular", "set", "that", "is", "mentioned", "in", "the", "address", "passed", "to", "the", "function", "." ]
[]
[ { "param": "temp_index", "type": "uint32_t" }, { "param": "line", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "temp_index", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "line", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4e71cba5b0c19cd095f8632ea3d370691f20247d
himanshulikhar55/memorysubsystem
L2_cache_char.c
[ "MIT" ]
C
l2_cache_read
void
void l2_cache_read(uint32_t address, char **read_data, uint8_t *status) { //Extract from the address the tag bits. //Use the L2_ADDRESS_TAG_MASK mask to mask out the appropriate //bits of the address and L2_ADDRESS_TAG_SHIFT to shift the //bits the appropriate amount. //CODE HERE uint32_t temp_tag = (address & L2_ADDRESS_TAG_MASK) >> L2_ADDRESS_TAG_SHIFT; //Extract from the address the index of the cache set in the cache. //Use the L2_SET_INDEX_MASK mask to mask out the appropriate //bits of the address and L2_SET_INDEX_SHIFT to shift the //bits the appropriate amount. //CODE HERE uint32_t temp_index = (address & L2_SET_INDEX_MASK) >> L2_SET_INDEX_SHIFT; //Extract from the address the word offset within the cache line. //Use the WORD_OFFSET_MASK to mask out the appropriate bits of //the address and WORD_OFFSET_SHIFT to shift the bits the //appropriate amount. //CODE HERE uint32_t temp_word_offset = (address & WORD_OFFSET_MASK) >> WORD_OFFSET_SHIFT; //Extract from the address the byte offset within the cache line. //CODE HERE uint32_t temp_byte_offset = (address & BYTE_OFFSET_MASK); //Within the set specified by the set index extracted from the address, //look through the cache entries for an entry that 1) has its valid //bit set AND 2) has a tag that matches the tag extracted from the address. //If no such entry exists in the set, then the result is a cache miss. //The low bit of the status output parameter should be set to 0. Look through //performed to get data from the Main Memory. //Otherwise, if an entry is found with a set valid bit and a matching tag, //then it is a cache hit. The status output parameter should be set to 1. //The appropriate byte (as specified by the byte offset extracted from //the address) of the entry's cache line data should be written to read_data. //CODE HERE for (int i = 0; i < 8; i++) { if (((l2_cache[temp_index].lines[i].v_d_c_tag & L2_VBIT_MASK) == (1 << 31)) && ((l2_cache[temp_index].lines[i].v_d_c_tag & L2_ENTRY_TAG_MASK) == temp_tag)) { status = 1; *read = l2_cache[temp_index].lines[i].cache_line[temp_word_offset][temp_byte_offset]; update_counter_bits(temp_index, i); } else status = 0; } //Performing 'Look Through' //If the status is 0 from the for-loop, then it's a cache miss. //Look through the main memory for the corresponding address and get //the resulting entry to L2: //1) Call main_memory_read with appropriate parameters from here. //2) If there is valid data in the main memory at that address, //fetch it and update one of the cache lines using l2_insert_line() //3) Copy the contents from updated line to read_data parameter from //this function itself. //4) Else data in address is invalid and hence return an error. //CODE HERE }
/*************************************************************** l2_cache_read() This procedure implements the reading of a single byte to the L2 cache. The parameters are: address: unsigned 32-bit address. This address can be anywhere within a cache line. read_data: an output parameter (thus, a pointer to it is passed). On a read operation, if there is a cache hit, the appropriate byte of the appropriate cache line in the cache is written to read_data. status: this in an 8-bit output parameter (thus, a pointer to it is passed). The lowest bit of this byte should be set to indicate whether a cache hit occurred or not: cache hit: bit 0 of status = 1 cache miss: bit 0 of status = 0 ***************************************************************/
l2_cache_read() This procedure implements the reading of a single byte to the L2 cache. The parameters are. unsigned 32-bit address. This address can be anywhere within a cache line. an output parameter (thus, a pointer to it is passed). On a read operation, if there is a cache hit, the appropriate byte of the appropriate cache line in the cache is written to read_data. this in an 8-bit output parameter (thus, a pointer to it is passed). The lowest bit of this byte should be set to indicate whether a cache hit occurred or not: cache hit: bit 0 of status = 1 cache miss: bit 0 of status = 0
[ "l2_cache_read", "()", "This", "procedure", "implements", "the", "reading", "of", "a", "single", "byte", "to", "the", "L2", "cache", ".", "The", "parameters", "are", ".", "unsigned", "32", "-", "bit", "address", ".", "This", "address", "can", "be", "anywhere", "within", "a", "cache", "line", ".", "an", "output", "parameter", "(", "thus", "a", "pointer", "to", "it", "is", "passed", ")", ".", "On", "a", "read", "operation", "if", "there", "is", "a", "cache", "hit", "the", "appropriate", "byte", "of", "the", "appropriate", "cache", "line", "in", "the", "cache", "is", "written", "to", "read_data", ".", "this", "in", "an", "8", "-", "bit", "output", "parameter", "(", "thus", "a", "pointer", "to", "it", "is", "passed", ")", ".", "The", "lowest", "bit", "of", "this", "byte", "should", "be", "set", "to", "indicate", "whether", "a", "cache", "hit", "occurred", "or", "not", ":", "cache", "hit", ":", "bit", "0", "of", "status", "=", "1", "cache", "miss", ":", "bit", "0", "of", "status", "=", "0" ]
void l2_cache_read(uint32_t address, char **read_data, uint8_t *status) { uint32_t temp_tag = (address & L2_ADDRESS_TAG_MASK) >> L2_ADDRESS_TAG_SHIFT; uint32_t temp_index = (address & L2_SET_INDEX_MASK) >> L2_SET_INDEX_SHIFT; uint32_t temp_word_offset = (address & WORD_OFFSET_MASK) >> WORD_OFFSET_SHIFT; uint32_t temp_byte_offset = (address & BYTE_OFFSET_MASK); for (int i = 0; i < 8; i++) { if (((l2_cache[temp_index].lines[i].v_d_c_tag & L2_VBIT_MASK) == (1 << 31)) && ((l2_cache[temp_index].lines[i].v_d_c_tag & L2_ENTRY_TAG_MASK) == temp_tag)) { status = 1; *read = l2_cache[temp_index].lines[i].cache_line[temp_word_offset][temp_byte_offset]; update_counter_bits(temp_index, i); } else status = 0; } }
[ "void", "l2_cache_read", "(", "uint32_t", "address", ",", "char", "*", "*", "read_data", ",", "uint8_t", "*", "status", ")", "{", "uint32_t", "temp_tag", "=", "(", "address", "&", "L2_ADDRESS_TAG_MASK", ")", ">>", "L2_ADDRESS_TAG_SHIFT", ";", "uint32_t", "temp_index", "=", "(", "address", "&", "L2_SET_INDEX_MASK", ")", ">>", "L2_SET_INDEX_SHIFT", ";", "uint32_t", "temp_word_offset", "=", "(", "address", "&", "WORD_OFFSET_MASK", ")", ">>", "WORD_OFFSET_SHIFT", ";", "uint32_t", "temp_byte_offset", "=", "(", "address", "&", "BYTE_OFFSET_MASK", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "if", "(", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "L2_VBIT_MASK", ")", "==", "(", "1", "<<", "31", ")", ")", "&&", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "L2_ENTRY_TAG_MASK", ")", "==", "temp_tag", ")", ")", "{", "status", "=", "1", ";", "*", "read", "=", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "cache_line", "[", "temp_word_offset", "]", "[", "temp_byte_offset", "]", ";", "update_counter_bits", "(", "temp_index", ",", "i", ")", ";", "}", "else", "status", "=", "0", ";", "}", "}" ]
l2_cache_read() This procedure implements the reading of a single byte to the L2 cache.
[ "l2_cache_read", "()", "This", "procedure", "implements", "the", "reading", "of", "a", "single", "byte", "to", "the", "L2", "cache", "." ]
[ "//Extract from the address the tag bits.", "//Use the L2_ADDRESS_TAG_MASK mask to mask out the appropriate", "//bits of the address and L2_ADDRESS_TAG_SHIFT to shift the ", "//bits the appropriate amount.", "//CODE HERE", "//Extract from the address the index of the cache set in the cache.", "//Use the L2_SET_INDEX_MASK mask to mask out the appropriate", "//bits of the address and L2_SET_INDEX_SHIFT to shift the ", "//bits the appropriate amount.", "//CODE HERE", "//Extract from the address the word offset within the cache line.", "//Use the WORD_OFFSET_MASK to mask out the appropriate bits of", "//the address and WORD_OFFSET_SHIFT to shift the bits the ", "//appropriate amount.", "//CODE HERE", "//Extract from the address the byte offset within the cache line.", "//CODE HERE", "//Within the set specified by the set index extracted from the address,", "//look through the cache entries for an entry that 1) has its valid ", "//bit set AND 2) has a tag that matches the tag extracted from the address.", "//If no such entry exists in the set, then the result is a cache miss.", "//The low bit of the status output parameter should be set to 0. Look through", "//performed to get data from the Main Memory.", "//Otherwise, if an entry is found with a set valid bit and a matching tag, ", "//then it is a cache hit. The status output parameter should be set to 1.", "//The appropriate byte (as specified by the byte offset extracted from ", "//the address) of the entry's cache line data should be written to read_data.", "//CODE HERE", "//Performing 'Look Through'", "//If the status is 0 from the for-loop, then it's a cache miss.", "//Look through the main memory for the corresponding address and get ", "//the resulting entry to L2: ", "//1) Call main_memory_read with appropriate parameters from here. ", "//2) If there is valid data in the main memory at that address,", "//fetch it and update one of the cache lines using l2_insert_line()", "//3) Copy the contents from updated line to read_data parameter from ", "//this function itself.", "//4) Else data in address is invalid and hence return an error.", "//CODE HERE" ]
[ { "param": "address", "type": "uint32_t" }, { "param": "read_data", "type": "char" }, { "param": "status", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "address", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "read_data", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "status", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4e71cba5b0c19cd095f8632ea3d370691f20247d
himanshulikhar55/memorysubsystem
L2_cache_char.c
[ "MIT" ]
C
l2_cache_write
void
void l2_cache_write(uint32_t address, char *write_data, uint8_t *status) { //Extract from the address the tag bits. //Use the L2_ADDRESS_TAG_MASK mask to mask out the appropriate //bits of the address and L2_ADDRESS_TAG_SHIFT to shift the //bits the appropriate amount. //CODE HERE uint32_t temp_tag = (address & L2_ADDRESS_TAG_MASK) >> L2_ADDRESS_TAG_SHIFT; //Extract from the address the index of the cache set in the cache. //Use the L2_SET_INDEX_MASK mask to mask out the appropriate //bits of the address and L2_SET_INDEX_SHIFT to shift the //bits the appropriate amount. //CODE HERE uint32_t temp_index = (address & L2_SET_INDEX_MASK) >> L2_SET_INDEX_SHIFT; //Extract from the address the word offset within the cache line. //Use the WORD_OFFSET_MASK to mask out the appropriate bits of //the address and WORD_OFFSET_SHIFT to shift the bits the //appropriate amount. //CODE HERE uint32_t temp_word_offset = (address & WORD_OFFSET_MASK) >> WORD_OFFSET_SHIFT; //Extract from the address the byte offset within the cache line. //CODE HERE uint32_t temp_byte_offset = (address & BYTE_OFFSET_MASK); //Within the set specified by the set index extracted from the address, //look through the cache entries for an entry that 1) has its valid //bit set AND 2) has a tag that matches the tag extracted from the address. //If no such entry exists in the set, then the result is a cache miss. //The low bit of the status output parameter should be set to 0. There //is nothing further to do in this case. //Otherwise, if an entry is found with a set valid bit and a matching tag, //then it is a cache hit. The status output parameter should be set to 1. //The value of write_data should be written to the appropriate word //of the entry's cache line data and the entry's dirty bit should be set. //CODE HERE for (int i = 0; i < 8; i++) { if (((l2_cache[temp_index].lines[i].v_d_c_tag & L2_VBIT_MASK) == (1 << 31)) && ((l2_cache[temp_index].lines[i].v_d_c_tag & L2_ENTRY_TAG_MASK) == temp_tag)) { status = 1; strcpy(l2_cache[temp_index].lines[i].cache_line[temp_word_offset][temp_byte_offset], write); update_counter_bits(temp_index, i); } else status = 0; } //If the status is 0 from the for-loop, then it's a cache miss. //Look through the main memory for the corresponding address and get //the resulting entry to L2: //1) Call main_memory_read with appropriate parameters from here. //2) If there is valid data in the main memory at that address, //fetch it and update one of the cache lines using l2_insert_line() //3) Copy the contents from write_data parameter to the appropriate //byte space in the cache line in this function itself. //4) Else data in address is invalid and hence return an error. //CODE HERE }
/*************************************************************** l2_cache_write() This procedure implements the writing of a single byte to the L2 cache. The parameters are: address: unsigned 32-bit address. This address can be anywhere within a cache line. write_data: an input parameter (a pointer to it is passed). On a write operation, if there is a cache hit, the appropriate byte of the appropriate cache line in the cache is replaced by contents of write_data parameter. status: this in an 8-bit output parameter (thus, a pointer to it is passed). The lowest bit of this byte should be set to indicate whether a cache hit occurred or not: cache hit: bit 0 of status = 1 cache miss: bit 0 of status = 0 ***************************************************************/
l2_cache_write() This procedure implements the writing of a single byte to the L2 cache. The parameters are. unsigned 32-bit address. This address can be anywhere within a cache line. an input parameter (a pointer to it is passed). On a write operation, if there is a cache hit, the appropriate byte of the appropriate cache line in the cache is replaced by contents of write_data parameter. this in an 8-bit output parameter (thus, a pointer to it is passed). The lowest bit of this byte should be set to indicate whether a cache hit occurred or not: cache hit: bit 0 of status = 1 cache miss: bit 0 of status = 0
[ "l2_cache_write", "()", "This", "procedure", "implements", "the", "writing", "of", "a", "single", "byte", "to", "the", "L2", "cache", ".", "The", "parameters", "are", ".", "unsigned", "32", "-", "bit", "address", ".", "This", "address", "can", "be", "anywhere", "within", "a", "cache", "line", ".", "an", "input", "parameter", "(", "a", "pointer", "to", "it", "is", "passed", ")", ".", "On", "a", "write", "operation", "if", "there", "is", "a", "cache", "hit", "the", "appropriate", "byte", "of", "the", "appropriate", "cache", "line", "in", "the", "cache", "is", "replaced", "by", "contents", "of", "write_data", "parameter", ".", "this", "in", "an", "8", "-", "bit", "output", "parameter", "(", "thus", "a", "pointer", "to", "it", "is", "passed", ")", ".", "The", "lowest", "bit", "of", "this", "byte", "should", "be", "set", "to", "indicate", "whether", "a", "cache", "hit", "occurred", "or", "not", ":", "cache", "hit", ":", "bit", "0", "of", "status", "=", "1", "cache", "miss", ":", "bit", "0", "of", "status", "=", "0" ]
void l2_cache_write(uint32_t address, char *write_data, uint8_t *status) { uint32_t temp_tag = (address & L2_ADDRESS_TAG_MASK) >> L2_ADDRESS_TAG_SHIFT; uint32_t temp_index = (address & L2_SET_INDEX_MASK) >> L2_SET_INDEX_SHIFT; uint32_t temp_word_offset = (address & WORD_OFFSET_MASK) >> WORD_OFFSET_SHIFT; uint32_t temp_byte_offset = (address & BYTE_OFFSET_MASK); for (int i = 0; i < 8; i++) { if (((l2_cache[temp_index].lines[i].v_d_c_tag & L2_VBIT_MASK) == (1 << 31)) && ((l2_cache[temp_index].lines[i].v_d_c_tag & L2_ENTRY_TAG_MASK) == temp_tag)) { status = 1; strcpy(l2_cache[temp_index].lines[i].cache_line[temp_word_offset][temp_byte_offset], write); update_counter_bits(temp_index, i); } else status = 0; } }
[ "void", "l2_cache_write", "(", "uint32_t", "address", ",", "char", "*", "write_data", ",", "uint8_t", "*", "status", ")", "{", "uint32_t", "temp_tag", "=", "(", "address", "&", "L2_ADDRESS_TAG_MASK", ")", ">>", "L2_ADDRESS_TAG_SHIFT", ";", "uint32_t", "temp_index", "=", "(", "address", "&", "L2_SET_INDEX_MASK", ")", ">>", "L2_SET_INDEX_SHIFT", ";", "uint32_t", "temp_word_offset", "=", "(", "address", "&", "WORD_OFFSET_MASK", ")", ">>", "WORD_OFFSET_SHIFT", ";", "uint32_t", "temp_byte_offset", "=", "(", "address", "&", "BYTE_OFFSET_MASK", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "if", "(", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "L2_VBIT_MASK", ")", "==", "(", "1", "<<", "31", ")", ")", "&&", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "L2_ENTRY_TAG_MASK", ")", "==", "temp_tag", ")", ")", "{", "status", "=", "1", ";", "strcpy", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "cache_line", "[", "temp_word_offset", "]", "[", "temp_byte_offset", "]", ",", "write", ")", ";", "update_counter_bits", "(", "temp_index", ",", "i", ")", ";", "}", "else", "status", "=", "0", ";", "}", "}" ]
l2_cache_write() This procedure implements the writing of a single byte to the L2 cache.
[ "l2_cache_write", "()", "This", "procedure", "implements", "the", "writing", "of", "a", "single", "byte", "to", "the", "L2", "cache", "." ]
[ "//Extract from the address the tag bits.", "//Use the L2_ADDRESS_TAG_MASK mask to mask out the appropriate", "//bits of the address and L2_ADDRESS_TAG_SHIFT to shift the ", "//bits the appropriate amount.", "//CODE HERE", "//Extract from the address the index of the cache set in the cache.", "//Use the L2_SET_INDEX_MASK mask to mask out the appropriate", "//bits of the address and L2_SET_INDEX_SHIFT to shift the ", "//bits the appropriate amount.", "//CODE HERE", "//Extract from the address the word offset within the cache line.", "//Use the WORD_OFFSET_MASK to mask out the appropriate bits of", "//the address and WORD_OFFSET_SHIFT to shift the bits the ", "//appropriate amount.", "//CODE HERE", "//Extract from the address the byte offset within the cache line.", "//CODE HERE", "//Within the set specified by the set index extracted from the address,", "//look through the cache entries for an entry that 1) has its valid ", "//bit set AND 2) has a tag that matches the tag extracted from the address.", "//If no such entry exists in the set, then the result is a cache miss.", "//The low bit of the status output parameter should be set to 0. There", "//is nothing further to do in this case.", "//Otherwise, if an entry is found with a set valid bit and a matching tag, ", "//then it is a cache hit. The status output parameter should be set to 1.", "//The value of write_data should be written to the appropriate word ", "//of the entry's cache line data and the entry's dirty bit should be set.", "//CODE HERE", "//If the status is 0 from the for-loop, then it's a cache miss.", "//Look through the main memory for the corresponding address and get ", "//the resulting entry to L2: ", "//1) Call main_memory_read with appropriate parameters from here. ", "//2) If there is valid data in the main memory at that address,", "//fetch it and update one of the cache lines using l2_insert_line()", "//3) Copy the contents from write_data parameter to the appropriate ", "//byte space in the cache line in this function itself.", "//4) Else data in address is invalid and hence return an error.", "//CODE HERE" ]
[ { "param": "address", "type": "uint32_t" }, { "param": "write_data", "type": "char" }, { "param": "status", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "address", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "write_data", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "status", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4e71cba5b0c19cd095f8632ea3d370691f20247d
himanshulikhar55/memorysubsystem
L2_cache_char.c
[ "MIT" ]
C
l2_insert_line
void
void l2_insert_line(uint32_t address, char *write_data, uint32_t *evicted_writeback_address, char evicted_writeback_data[], uint8_t *status) { //Extract from the address the index of the cache set in the cache. //see l2_cache_access above //CODE HERE uint32_t temp_index = (address & L2_SET_INDEX_MASK) >> L2_SET_INDEX_SHIFT; //Extract from the address the tag bits. //see l2_cache_access above. //CODE HERE uint32_t temp_tag = (address & L2_ADDRESS_TAG_MASK) >> L2_ADDRESS_TAG_SHIFT; //In a loop, iterate through each entry in the set. int zero_counter = 0; //LOOP STARTS HERE for (int i = 0; i < 8; i++) { //If the current entry has a zero v bit, then overwrite //the cache line in the entry with the data in write_data, //set the v bit of the entry, clear the dirty bit, update the //counter to 111, and write the new tag to the entry. //Set the low bit of the status output parameter to 0 to indicate //the evicted line does not need to be written back. There is nothing //further to do, the procedure can return. //CODE HERE if ((l2_cache[temp_index].lines[i].v_d_c_tag & L2_VBIT_MASK) == (0 << 31)) { //copying data from write_data to the cache line for (int j=0; j<16; j++) { l2_cache[temp_index].lines[i].cache_line[j] = write_data[j]; } //setting the valid bit and updating the counter bits (111) l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | L2_VBIT_MASK); update_counter_bits(temp_index, i); //clearing dirty bit l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag & 0xBFFFFFFF); //writing the new tag to entry from given address l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | temp_tag); status = 0; return; } // Otherwise, we remember the entry we encounter which has counter = 000 else if (((l2_cache[temp_index].lines[i].v_d_c_tag & L2_COUNTER_MASK) >> 25) == 0x0) { zero_counter = i; } //LOOP ENDS HERE } //When we're done looping, we choose the entry with the highest preference //on the above list to evict. //CODE HERE //Don't need //if the dirty bit of the cache entry to be evicted is set, then the data in the //cache line needs to be written back. The address to write the current entry //back to is constructed from the entry's tag and the set index in the cache by: // (evicted_entry_tag << L2_ADDRESS_TAG_SHIFT) | (set_index << L2_SET_INDEX_SHIFT) //This address should be written to the evicted_writeback_address output //parameter. The cache line data in the evicted entry should be copied to the //evicted_writeback_data array. //Also, if the dirty bit of the chosen entry is been set, the low bit of the status byte //should be set to 1 to indicate that the write-back is needed. Otherwise, //the low bit of the status byte should be set to 0. //CODE HERE if ((l2_cache[temp_index].lines[zero_counter].v_d_c_tag & L2_DIRTYBIT_MASK) == (1 << 30)) { evicted_writeback_address = (((l2_cache[temp_index].lines[zero_counter].v_d_c_tag & L2_ENTRY_TAG_MASK) << L2_ADDRESS_TAG_SHIFT) | (temp_index << L2_SET_INDEX_SHIFT)); for (int i = 0; i < 16; i++) { evicted_writeback_data = l2_cache[temp_index].lines[zero_counter].cache_line[i]; } status = 1; } else status = 0; //Then, copy the data from write_data to the cache line in the entry, //set the valid bit of the entry, clear the dirty bit of the //entry, and write the tag bits of the address into the tag of //the entry. //CODE HERE //copying data from write_data to the cache line for (int j=0; j<16; j++) { l2_cache[temp_index].lines[i].cache_line[j] = write_data[j]; } //setting the valid bit and updating the counter bits (111) l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | L2_VBIT_MASK); update_counter_bits(temp_index, i); //clearing dirty bit l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag & 0xBFFFFFFF); //writing the new tag to entry from given address l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | temp_tag); status = 0; return; }
/************************************************************ l2_insert_line() This procedure inserts a new cache line into the L2 cache. The parameters are: address: 32-bit memory address for the new cache line. write_data: an array of 32 bytes containing the cache line data to be inserted into the cache. evicted_writeback_address: a 32-bit output parameter (thus, a pointer to it is passed) that, if the cache line being evicted needs to be written back to memory, should be assigned the memory address for the evicted cache line. evicted_writeback_data: an array of 32 bytes that, if the cache line being evicted needs to be written back to memory, should be assigned the cache line data for the evicted cache line. Since there are 16 words per cache line, the actual parameter should be an array of at least 16 words. status: this in an 8-bit output parameter (thus, a pointer to it is passed). The lowest bit of this byte should be set to indicate whether the evicted cache line needs to be written back to memory or not, as follows: 0: no write-back required 1: evicted cache line needs to be written back. The cache replacement algorithm uses an LRU counter alogrithm. A cache entry (among the cache entries in the set) is chosen to be written to in the following order of preference: - valid bit = 0 - counter value is lowest *********************************************************/
l2_insert_line() This procedure inserts a new cache line into the L2 cache. The parameters are. 32-bit memory address for the new cache line. an array of 32 bytes containing the cache line data to be inserted into the cache. a 32-bit output parameter (thus, a pointer to it is passed) that, if the cache line being evicted needs to be written back to memory, should be assigned the memory address for the evicted cache line. an array of 32 bytes that, if the cache line being evicted needs to be written back to memory, should be assigned the cache line data for the evicted cache line. Since there are 16 words per cache line, the actual parameter should be an array of at least 16 words. this in an 8-bit output parameter (thus, a pointer to it is passed). The lowest bit of this byte should be set to indicate whether the evicted cache line needs to be written back to memory or not, as follows: 0: no write-back required 1: evicted cache line needs to be written back. The cache replacement algorithm uses an LRU counter alogrithm. A cache entry (among the cache entries in the set) is chosen to be written to in the following order of preference: valid bit = 0 counter value is lowest
[ "l2_insert_line", "()", "This", "procedure", "inserts", "a", "new", "cache", "line", "into", "the", "L2", "cache", ".", "The", "parameters", "are", ".", "32", "-", "bit", "memory", "address", "for", "the", "new", "cache", "line", ".", "an", "array", "of", "32", "bytes", "containing", "the", "cache", "line", "data", "to", "be", "inserted", "into", "the", "cache", ".", "a", "32", "-", "bit", "output", "parameter", "(", "thus", "a", "pointer", "to", "it", "is", "passed", ")", "that", "if", "the", "cache", "line", "being", "evicted", "needs", "to", "be", "written", "back", "to", "memory", "should", "be", "assigned", "the", "memory", "address", "for", "the", "evicted", "cache", "line", ".", "an", "array", "of", "32", "bytes", "that", "if", "the", "cache", "line", "being", "evicted", "needs", "to", "be", "written", "back", "to", "memory", "should", "be", "assigned", "the", "cache", "line", "data", "for", "the", "evicted", "cache", "line", ".", "Since", "there", "are", "16", "words", "per", "cache", "line", "the", "actual", "parameter", "should", "be", "an", "array", "of", "at", "least", "16", "words", ".", "this", "in", "an", "8", "-", "bit", "output", "parameter", "(", "thus", "a", "pointer", "to", "it", "is", "passed", ")", ".", "The", "lowest", "bit", "of", "this", "byte", "should", "be", "set", "to", "indicate", "whether", "the", "evicted", "cache", "line", "needs", "to", "be", "written", "back", "to", "memory", "or", "not", "as", "follows", ":", "0", ":", "no", "write", "-", "back", "required", "1", ":", "evicted", "cache", "line", "needs", "to", "be", "written", "back", ".", "The", "cache", "replacement", "algorithm", "uses", "an", "LRU", "counter", "alogrithm", ".", "A", "cache", "entry", "(", "among", "the", "cache", "entries", "in", "the", "set", ")", "is", "chosen", "to", "be", "written", "to", "in", "the", "following", "order", "of", "preference", ":", "valid", "bit", "=", "0", "counter", "value", "is", "lowest" ]
void l2_insert_line(uint32_t address, char *write_data, uint32_t *evicted_writeback_address, char evicted_writeback_data[], uint8_t *status) { uint32_t temp_index = (address & L2_SET_INDEX_MASK) >> L2_SET_INDEX_SHIFT; . uint32_t temp_tag = (address & L2_ADDRESS_TAG_MASK) >> L2_ADDRESS_TAG_SHIFT; int zero_counter = 0; for (int i = 0; i < 8; i++) { if ((l2_cache[temp_index].lines[i].v_d_c_tag & L2_VBIT_MASK) == (0 << 31)) { for (int j=0; j<16; j++) { l2_cache[temp_index].lines[i].cache_line[j] = write_data[j]; } l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | L2_VBIT_MASK); update_counter_bits(temp_index, i); l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag & 0xBFFFFFFF); l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | temp_tag); status = 0; return; } else if (((l2_cache[temp_index].lines[i].v_d_c_tag & L2_COUNTER_MASK) >> 25) == 0x0) { zero_counter = i; } } if ((l2_cache[temp_index].lines[zero_counter].v_d_c_tag & L2_DIRTYBIT_MASK) == (1 << 30)) { evicted_writeback_address = (((l2_cache[temp_index].lines[zero_counter].v_d_c_tag & L2_ENTRY_TAG_MASK) << L2_ADDRESS_TAG_SHIFT) | (temp_index << L2_SET_INDEX_SHIFT)); for (int i = 0; i < 16; i++) { evicted_writeback_data = l2_cache[temp_index].lines[zero_counter].cache_line[i]; } status = 1; } else status = 0; for (int j=0; j<16; j++) { l2_cache[temp_index].lines[i].cache_line[j] = write_data[j]; } l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | L2_VBIT_MASK); update_counter_bits(temp_index, i); l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag & 0xBFFFFFFF); l2_cache[temp_index].lines[i].v_d_c_tag = (l2_cache[temp_index].lines[i].v_d_c_tag | temp_tag); status = 0; return; }
[ "void", "l2_insert_line", "(", "uint32_t", "address", ",", "char", "*", "write_data", ",", "uint32_t", "*", "evicted_writeback_address", ",", "char", "evicted_writeback_data", "[", "]", ",", "uint8_t", "*", "status", ")", "{", "uint32_t", "temp_index", "=", "(", "address", "&", "L2_SET_INDEX_MASK", ")", ">>", "L2_SET_INDEX_SHIFT", ";", "uint32_t", "temp_tag", "=", "(", "address", "&", "L2_ADDRESS_TAG_MASK", ")", ">>", "L2_ADDRESS_TAG_SHIFT", ";", "int", "zero_counter", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "if", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "L2_VBIT_MASK", ")", "==", "(", "0", "<<", "31", ")", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "16", ";", "j", "++", ")", "{", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "cache_line", "[", "j", "]", "=", "write_data", "[", "j", "]", ";", "}", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "|", "L2_VBIT_MASK", ")", ";", "update_counter_bits", "(", "temp_index", ",", "i", ")", ";", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "0xBFFFFFFF", ")", ";", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "|", "temp_tag", ")", ";", "status", "=", "0", ";", "return", ";", "}", "else", "if", "(", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "L2_COUNTER_MASK", ")", ">>", "25", ")", "==", "0x0", ")", "{", "zero_counter", "=", "i", ";", "}", "}", "if", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "zero_counter", "]", ".", "v_d_c_tag", "&", "L2_DIRTYBIT_MASK", ")", "==", "(", "1", "<<", "30", ")", ")", "{", "evicted_writeback_address", "=", "(", "(", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "zero_counter", "]", ".", "v_d_c_tag", "&", "L2_ENTRY_TAG_MASK", ")", "<<", "L2_ADDRESS_TAG_SHIFT", ")", "|", "(", "temp_index", "<<", "L2_SET_INDEX_SHIFT", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "16", ";", "i", "++", ")", "{", "evicted_writeback_data", "=", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "zero_counter", "]", ".", "cache_line", "[", "i", "]", ";", "}", "status", "=", "1", ";", "}", "else", "status", "=", "0", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "16", ";", "j", "++", ")", "{", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "cache_line", "[", "j", "]", "=", "write_data", "[", "j", "]", ";", "}", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "|", "L2_VBIT_MASK", ")", ";", "update_counter_bits", "(", "temp_index", ",", "i", ")", ";", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "&", "0xBFFFFFFF", ")", ";", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "temp_index", "]", ".", "lines", "[", "i", "]", ".", "v_d_c_tag", "|", "temp_tag", ")", ";", "status", "=", "0", ";", "return", ";", "}" ]
l2_insert_line() This procedure inserts a new cache line into the L2 cache.
[ "l2_insert_line", "()", "This", "procedure", "inserts", "a", "new", "cache", "line", "into", "the", "L2", "cache", "." ]
[ "//Extract from the address the index of the cache set in the cache.", "//see l2_cache_access above", "//CODE HERE", "//Extract from the address the tag bits. ", "//see l2_cache_access above.", "//CODE HERE", "//In a loop, iterate through each entry in the set.", "//LOOP STARTS HERE", "//If the current entry has a zero v bit, then overwrite", "//the cache line in the entry with the data in write_data,", "//set the v bit of the entry, clear the dirty bit, update the ", "//counter to 111, and write the new tag to the entry.", "//Set the low bit of the status output parameter to 0 to indicate ", "//the evicted line does not need to be written back. There is nothing ", "//further to do, the procedure can return.", "//CODE HERE", "//copying data from write_data to the cache line", "//setting the valid bit and updating the counter bits (111)", "//clearing dirty bit", "//writing the new tag to entry from given address", "// Otherwise, we remember the entry we encounter which has counter = 000", "//LOOP ENDS HERE", "//When we're done looping, we choose the entry with the highest preference ", "//on the above list to evict.", "//CODE HERE", "//Don't need", "//if the dirty bit of the cache entry to be evicted is set, then the data in the ", "//cache line needs to be written back. The address to write the current entry ", "//back to is constructed from the entry's tag and the set index in the cache by:", "// (evicted_entry_tag << L2_ADDRESS_TAG_SHIFT) | (set_index << L2_SET_INDEX_SHIFT)", "//This address should be written to the evicted_writeback_address output", "//parameter. The cache line data in the evicted entry should be copied to the", "//evicted_writeback_data array.", "//Also, if the dirty bit of the chosen entry is been set, the low bit of the status byte ", "//should be set to 1 to indicate that the write-back is needed. Otherwise,", "//the low bit of the status byte should be set to 0.", "//CODE HERE", "//Then, copy the data from write_data to the cache line in the entry, ", "//set the valid bit of the entry, clear the dirty bit of the ", "//entry, and write the tag bits of the address into the tag of ", "//the entry.", "//CODE HERE", "//copying data from write_data to the cache line", "//setting the valid bit and updating the counter bits (111)", "//clearing dirty bit", "//writing the new tag to entry from given address" ]
[ { "param": "address", "type": "uint32_t" }, { "param": "write_data", "type": "char" }, { "param": "evicted_writeback_address", "type": "uint32_t" }, { "param": "evicted_writeback_data", "type": "char" }, { "param": "status", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "address", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "write_data", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "evicted_writeback_address", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "evicted_writeback_data", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "status", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4e71cba5b0c19cd095f8632ea3d370691f20247d
himanshulikhar55/memorysubsystem
L2_cache_char.c
[ "MIT" ]
C
l2_clear_c_bits
void
void l2_clear_c_bits() { //CODE HERE for(int i = 0; i < 128; i++) { for(int j = 0; j < 8; j++) { uint32_t clear_c = 0xC7FFFFFF; l2_cache[i].lines[j].v_d_c_tag = (l2_cache[i].lines[j].v_d_c_tag & clear_c); } } }
/*********************************************************** l2_clear_c_bits() This procedure clear the counter bits of each entry in each set of the L2 cache. It is called periodically to support the the LRU algorithm. ***********************************************************/
l2_clear_c_bits() This procedure clear the counter bits of each entry in each set of the L2 cache. It is called periodically to support the the LRU algorithm.
[ "l2_clear_c_bits", "()", "This", "procedure", "clear", "the", "counter", "bits", "of", "each", "entry", "in", "each", "set", "of", "the", "L2", "cache", ".", "It", "is", "called", "periodically", "to", "support", "the", "the", "LRU", "algorithm", "." ]
void l2_clear_c_bits() { for(int i = 0; i < 128; i++) { for(int j = 0; j < 8; j++) { uint32_t clear_c = 0xC7FFFFFF; l2_cache[i].lines[j].v_d_c_tag = (l2_cache[i].lines[j].v_d_c_tag & clear_c); } } }
[ "void", "l2_clear_c_bits", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "128", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "8", ";", "j", "++", ")", "{", "uint32_t", "clear_c", "=", "0xC7FFFFFF", ";", "l2_cache", "[", "i", "]", ".", "lines", "[", "j", "]", ".", "v_d_c_tag", "=", "(", "l2_cache", "[", "i", "]", ".", "lines", "[", "j", "]", ".", "v_d_c_tag", "&", "clear_c", ")", ";", "}", "}", "}" ]
l2_clear_c_bits() This procedure clear the counter bits of each entry in each set of the L2 cache.
[ "l2_clear_c_bits", "()", "This", "procedure", "clear", "the", "counter", "bits", "of", "each", "entry", "in", "each", "set", "of", "the", "L2", "cache", "." ]
[ "//CODE HERE" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
6434ea3570143f803b924bf7e54fd86f4273079d
roysammy123/C-programs
Recursion/stringpattern_reverse.c
[ "MIT" ]
C
stringpattern
void
void stringpattern(char *b, int x) { // Program ending statement as x is length of string which can't be 0 if(x == 0) { return; } // copying length of string value int n; n = x; // printing from the last position of string array int i; for (i = n-1; i>=0; i--) { printf("%c",b[i]); } printf("\n"); stringpattern(b, n-1); /* calling recursive function, but each time, reducing size of string by 1 For example, for a string of length 4, if first line output display started from b[3], it will start from b[2] in next step, then b[1], then b[0] and then program will stop */ }
// Function to print reversed string pattern
Function to print reversed string pattern
[ "Function", "to", "print", "reversed", "string", "pattern" ]
void stringpattern(char *b, int x) { if(x == 0) { return; } int n; n = x; int i; for (i = n-1; i>=0; i--) { printf("%c",b[i]); } printf("\n"); stringpattern(b, n-1); }
[ "void", "stringpattern", "(", "char", "*", "b", ",", "int", "x", ")", "{", "if", "(", "x", "==", "0", ")", "{", "return", ";", "}", "int", "n", ";", "n", "=", "x", ";", "int", "i", ";", "for", "(", "i", "=", "n", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "printf", "(", "\"", "\"", ",", "b", "[", "i", "]", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "stringpattern", "(", "b", ",", "n", "-", "1", ")", ";", "}" ]
Function to print reversed string pattern
[ "Function", "to", "print", "reversed", "string", "pattern" ]
[ "// Program ending statement as x is length of string which can't be 0", "// copying length of string value ", "// printing from the last position of string array", "/* \n calling recursive function, but each time, reducing size of string by 1\n For example, for a string of length 4, if first line output display started from b[3], \n it will start from b[2] in next step, then b[1], then b[0] and then program will stop\n */" ]
[ { "param": "b", "type": "char" }, { "param": "x", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "b", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fcb16c93fecb2ebccb62bdb86362e0b9740ae9e5
muhammedtarikyildiz/fractional-order-msbl-fpga
HDL_IP_Example_1/sysgen/xilinx_transfer_function_1_sinit.c
[ "MIT" ]
C
xilinx_transfer_function_1_LookupConfig
xilinx_transfer_function_1_Config
xilinx_transfer_function_1_Config *xilinx_transfer_function_1_LookupConfig(u16 DeviceId) { xilinx_transfer_function_1_Config *ConfigPtr = NULL; int Index; for (Index = 0; Index < XPAR_XILINX_TRANSFER_FUNCTION_1_NUM_INSTANCES; Index++) { if (xilinx_transfer_function_1_ConfigTable[Index].DeviceId == DeviceId) { ConfigPtr = &xilinx_transfer_function_1_ConfigTable[Index]; break; } } return ConfigPtr; }
/** * Lookup the device configuration based on the unique device ID. The table * ConfigTable contains the configuration info for each device in the system. * * @param DeviceId is the device identifier to lookup. * * @return * - A pointer of data type xilinx_transfer_function_1_Config which * points to the device configuration if DeviceID is found. * - NULL if DeviceID is not found. * * @note None. * */
Lookup the device configuration based on the unique device ID. The table ConfigTable contains the configuration info for each device in the system.
[ "Lookup", "the", "device", "configuration", "based", "on", "the", "unique", "device", "ID", ".", "The", "table", "ConfigTable", "contains", "the", "configuration", "info", "for", "each", "device", "in", "the", "system", "." ]
xilinx_transfer_function_1_Config *xilinx_transfer_function_1_LookupConfig(u16 DeviceId) { xilinx_transfer_function_1_Config *ConfigPtr = NULL; int Index; for (Index = 0; Index < XPAR_XILINX_TRANSFER_FUNCTION_1_NUM_INSTANCES; Index++) { if (xilinx_transfer_function_1_ConfigTable[Index].DeviceId == DeviceId) { ConfigPtr = &xilinx_transfer_function_1_ConfigTable[Index]; break; } } return ConfigPtr; }
[ "xilinx_transfer_function_1_Config", "*", "xilinx_transfer_function_1_LookupConfig", "(", "u16", "DeviceId", ")", "{", "xilinx_transfer_function_1_Config", "*", "ConfigPtr", "=", "NULL", ";", "int", "Index", ";", "for", "(", "Index", "=", "0", ";", "Index", "<", "XPAR_XILINX_TRANSFER_FUNCTION_1_NUM_INSTANCES", ";", "Index", "++", ")", "{", "if", "(", "xilinx_transfer_function_1_ConfigTable", "[", "Index", "]", ".", "DeviceId", "==", "DeviceId", ")", "{", "ConfigPtr", "=", "&", "xilinx_transfer_function_1_ConfigTable", "[", "Index", "]", ";", "break", ";", "}", "}", "return", "ConfigPtr", ";", "}" ]
Lookup the device configuration based on the unique device ID.
[ "Lookup", "the", "device", "configuration", "based", "on", "the", "unique", "device", "ID", "." ]
[]
[ { "param": "DeviceId", "type": "u16" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "DeviceId", "type": "u16", "docstring": null, "docstring_tokens": [ "None" ], "default": null, "is_optional": null } ], "outlier_params": [], "others": [ { "identifier": "return\n", "docstring": "A pointer of data type xilinx_transfer_function_1_Config which\npoints to the device configuration if DeviceID is found.\nNULL if DeviceID is not found.", "docstring_tokens": [ "A", "pointer", "of", "data", "type", "xilinx_transfer_function_1_Config", "which", "points", "to", "the", "device", "configuration", "if", "DeviceID", "is", "found", ".", "NULL", "if", "DeviceID", "is", "not", "found", "." ] }, { "identifier": "note", "docstring": null, "docstring_tokens": [ "None" ] } ] }
69f15a7548c1f1f3429f45da50d2fa4266ebfd84
HarisPasic/ProjetSecuriteS9
sender.c
[ "MIT" ]
C
file_size
null
long file_size(const char *filename) { struct stat s; if (stat(filename,&s) != 0) { printf("Error reading file stats !\n"); return 2; } return s.st_size; }
// Return the size of a file
Return the size of a file
[ "Return", "the", "size", "of", "a", "file" ]
long file_size(const char *filename) { struct stat s; if (stat(filename,&s) != 0) { printf("Error reading file stats !\n"); return 2; } return s.st_size; }
[ "long", "file_size", "(", "const", "char", "*", "filename", ")", "{", "struct", "stat", "s", ";", "if", "(", "stat", "(", "filename", ",", "&", "s", ")", "!=", "0", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "2", ";", "}", "return", "s", ".", "st_size", ";", "}" ]
Return the size of a file
[ "Return", "the", "size", "of", "a", "file" ]
[]
[ { "param": "filename", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "filename", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
69f15a7548c1f1f3429f45da50d2fa4266ebfd84
HarisPasic/ProjetSecuriteS9
sender.c
[ "MIT" ]
C
readFileContent
int
int readFileContent(char *message, char *fileName) { int c; int ctr_characters = 0; FILE *fp = fopen(fileName, "r"); if(fp == NULL) { printf("error: failed to open fileWithData\n"); return -1; } while ((c = fgetc(fp)) != EOF) { if(ctr_characters == MAX_MESSAGE_SIZE) break; message[ctr_characters] = (char) c; ++ctr_characters; } fclose(fp); return ctr_characters; }
// Read file content (store it in "message") and // return the number of characters
Read file content (store it in "message") and return the number of characters
[ "Read", "file", "content", "(", "store", "it", "in", "\"", "message", "\"", ")", "and", "return", "the", "number", "of", "characters" ]
int readFileContent(char *message, char *fileName) { int c; int ctr_characters = 0; FILE *fp = fopen(fileName, "r"); if(fp == NULL) { printf("error: failed to open fileWithData\n"); return -1; } while ((c = fgetc(fp)) != EOF) { if(ctr_characters == MAX_MESSAGE_SIZE) break; message[ctr_characters] = (char) c; ++ctr_characters; } fclose(fp); return ctr_characters; }
[ "int", "readFileContent", "(", "char", "*", "message", ",", "char", "*", "fileName", ")", "{", "int", "c", ";", "int", "ctr_characters", "=", "0", ";", "FILE", "*", "fp", "=", "fopen", "(", "fileName", ",", "\"", "\"", ")", ";", "if", "(", "fp", "==", "NULL", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "-1", ";", "}", "while", "(", "(", "c", "=", "fgetc", "(", "fp", ")", ")", "!=", "EOF", ")", "{", "if", "(", "ctr_characters", "==", "MAX_MESSAGE_SIZE", ")", "break", ";", "message", "[", "ctr_characters", "]", "=", "(", "char", ")", "c", ";", "++", "ctr_characters", ";", "}", "fclose", "(", "fp", ")", ";", "return", "ctr_characters", ";", "}" ]
Read file content (store it in "message") and return the number of characters
[ "Read", "file", "content", "(", "store", "it", "in", "\"", "message", "\"", ")", "and", "return", "the", "number", "of", "characters" ]
[]
[ { "param": "message", "type": "char" }, { "param": "fileName", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "message", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fileName", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3fc7e598c201399f90934ebde3d44805fab868bb
liuhuanjs/c-programming
function-pointer/funcptr.c
[ "MIT" ]
C
my_func
int
int my_func(int a, int b) { int c = a + b; printf("%d + %d = %d\n", a, b, c); return c; }
/* * This sample show usage of funtion pointer */
This sample show usage of funtion pointer
[ "This", "sample", "show", "usage", "of", "funtion", "pointer" ]
int my_func(int a, int b) { int c = a + b; printf("%d + %d = %d\n", a, b, c); return c; }
[ "int", "my_func", "(", "int", "a", ",", "int", "b", ")", "{", "int", "c", "=", "a", "+", "b", ";", "printf", "(", "\"", "\\n", "\"", ",", "a", ",", "b", ",", "c", ")", ";", "return", "c", ";", "}" ]
This sample show usage of funtion pointer
[ "This", "sample", "show", "usage", "of", "funtion", "pointer" ]
[]
[ { "param": "a", "type": "int" }, { "param": "b", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "a", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "b", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3fc7e598c201399f90934ebde3d44805fab868bb
liuhuanjs/c-programming
function-pointer/funcptr.c
[ "MIT" ]
C
test01
void
void test01() { typedef int(func_type)(int, int); func_type *f = my_func; (*f)(11, 22); (f)(11, 22); }
/* Example 1: define func type, then define func pointer by type */
Example 1: define func type, then define func pointer by type
[ "Example", "1", ":", "define", "func", "type", "then", "define", "func", "pointer", "by", "type" ]
void test01() { typedef int(func_type)(int, int); func_type *f = my_func; (*f)(11, 22); (f)(11, 22); }
[ "void", "test01", "(", ")", "{", "typedef", "int", "(", "func_type", ")", "(", "int", ",", "int", ")", ";", "func_type", "*", "f", "=", "my_func", ";", "(", "*", "f", ")", "(", "11", ",", "22", ")", ";", "(", "f", ")", "(", "11", ",", "22", ")", ";", "}" ]
Example 1: define func type, then define func pointer by type
[ "Example", "1", ":", "define", "func", "type", "then", "define", "func", "pointer", "by", "type" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
3fc7e598c201399f90934ebde3d44805fab868bb
liuhuanjs/c-programming
function-pointer/funcptr.c
[ "MIT" ]
C
test02
void
void test02() { typedef int(*func_pointer)(int, int); func_pointer f = my_func; (*f)(33, 44); (f)(33, 44); }
/* Example 2: define func pointer type, then define func pointer variable */
Example 2: define func pointer type, then define func pointer variable
[ "Example", "2", ":", "define", "func", "pointer", "type", "then", "define", "func", "pointer", "variable" ]
void test02() { typedef int(*func_pointer)(int, int); func_pointer f = my_func; (*f)(33, 44); (f)(33, 44); }
[ "void", "test02", "(", ")", "{", "typedef", "int", "(", "*", "func_pointer", ")", "(", "int", ",", "int", ")", ";", "func_pointer", "f", "=", "my_func", ";", "(", "*", "f", ")", "(", "33", ",", "44", ")", ";", "(", "f", ")", "(", "33", ",", "44", ")", ";", "}" ]
Example 2: define func pointer type, then define func pointer variable
[ "Example", "2", ":", "define", "func", "pointer", "type", "then", "define", "func", "pointer", "variable" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
3fc7e598c201399f90934ebde3d44805fab868bb
liuhuanjs/c-programming
function-pointer/funcptr.c
[ "MIT" ]
C
test03
void
void test03() { int (*f)(int, int) = my_func; (*f)(55, 66); (f)(55, 66); }
/* Example 3: define func pointer variable directly */
Example 3: define func pointer variable directly
[ "Example", "3", ":", "define", "func", "pointer", "variable", "directly" ]
void test03() { int (*f)(int, int) = my_func; (*f)(55, 66); (f)(55, 66); }
[ "void", "test03", "(", ")", "{", "int", "(", "*", "f", ")", "(", "int", ",", "int", ")", "=", "my_func", ";", "(", "*", "f", ")", "(", "55", ",", "66", ")", ";", "(", "f", ")", "(", "55", ",", "66", ")", ";", "}" ]
Example 3: define func pointer variable directly
[ "Example", "3", ":", "define", "func", "pointer", "variable", "directly" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
78a41fdda0a5664aeea95e65afda24ecb6fbf8b3
SergioAlberino/robot
src/motorDrive.c
[ "BSD-3-Clause" ]
C
motorDriveInit
void
void motorDriveInit( void ) { /* Configurar PWM */ valor = pwmConfig( 0, PWM_ENABLE ); valor = pwmConfig( PWM5, PWM_ENABLE_OUTPUT ); valor = pwmConfig( PWM4, PWM_ENABLE_OUTPUT ); gpioInit(dir0, GPIO_OUTPUT); gpioInit(dir1, GPIO_OUTPUT); }
/*=====[Implementations of public functions]=================================*/
[Implementations of public functions]
[ "[", "Implementations", "of", "public", "functions", "]" ]
void motorDriveInit( void ) { valor = pwmConfig( 0, PWM_ENABLE ); valor = pwmConfig( PWM5, PWM_ENABLE_OUTPUT ); valor = pwmConfig( PWM4, PWM_ENABLE_OUTPUT ); gpioInit(dir0, GPIO_OUTPUT); gpioInit(dir1, GPIO_OUTPUT); }
[ "void", "motorDriveInit", "(", "void", ")", "{", "valor", "=", "pwmConfig", "(", "0", ",", "PWM_ENABLE", ")", ";", "valor", "=", "pwmConfig", "(", "PWM5", ",", "PWM_ENABLE_OUTPUT", ")", ";", "valor", "=", "pwmConfig", "(", "PWM4", ",", "PWM_ENABLE_OUTPUT", ")", ";", "gpioInit", "(", "dir0", ",", "GPIO_OUTPUT", ")", ";", "gpioInit", "(", "dir1", ",", "GPIO_OUTPUT", ")", ";", "}" ]
[Implementations of public functions]
[ "[", "Implementations", "of", "public", "functions", "]" ]
[ "/* Configurar PWM */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
27b7fbc4d6ec3d6b9cfe7718e2bf67b81dd2bafe
SergioAlberino/robot
src/statemachine.c
[ "BSD-3-Clause" ]
C
statemachineInit
void
void statemachineInit(void) { boardInit(); gpioInit(goForward, GPIO_OUTPUT); // se inicializan LEDs para visualizar estados gpioInit(turnLeft, GPIO_OUTPUT); gpioInit(turnRight, GPIO_OUTPUT); gpioInit(stop, GPIO_OUTPUT); gpioInit(rele, GPIO_OUTPUT); gpioInit(buzzer, GPIO_OUTPUT); sensorsInit(); com_init(); motorDriveInit(); actualState = STOPPED; }
/*=====[Implementations of public functions]=================================*/
[Implementations of public functions]
[ "[", "Implementations", "of", "public", "functions", "]" ]
void statemachineInit(void) { boardInit(); gpioInit(goForward, GPIO_OUTPUT); gpioInit(turnLeft, GPIO_OUTPUT); gpioInit(turnRight, GPIO_OUTPUT); gpioInit(stop, GPIO_OUTPUT); gpioInit(rele, GPIO_OUTPUT); gpioInit(buzzer, GPIO_OUTPUT); sensorsInit(); com_init(); motorDriveInit(); actualState = STOPPED; }
[ "void", "statemachineInit", "(", "void", ")", "{", "boardInit", "(", ")", ";", "gpioInit", "(", "goForward", ",", "GPIO_OUTPUT", ")", ";", "gpioInit", "(", "turnLeft", ",", "GPIO_OUTPUT", ")", ";", "gpioInit", "(", "turnRight", ",", "GPIO_OUTPUT", ")", ";", "gpioInit", "(", "stop", ",", "GPIO_OUTPUT", ")", ";", "gpioInit", "(", "rele", ",", "GPIO_OUTPUT", ")", ";", "gpioInit", "(", "buzzer", ",", "GPIO_OUTPUT", ")", ";", "sensorsInit", "(", ")", ";", "com_init", "(", ")", ";", "motorDriveInit", "(", ")", ";", "actualState", "=", "STOPPED", ";", "}" ]
[Implementations of public functions]
[ "[", "Implementations", "of", "public", "functions", "]" ]
[ "// se inicializan LEDs para visualizar estados\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
7ab1d1c4c5bb62f1adcc19c3992214eba43d38a6
SergioAlberino/robot
src/sensors.c
[ "BSD-3-Clause" ]
C
sensorsInit
void
void sensorsInit( void ) { gpioInit(sensorF, GPIO_INPUT); gpioInit(sensorR, GPIO_INPUT); gpioInit(button, GPIO_INPUT); }
/*=====[Implementations of public functions]=================================*/
[Implementations of public functions]
[ "[", "Implementations", "of", "public", "functions", "]" ]
void sensorsInit( void ) { gpioInit(sensorF, GPIO_INPUT); gpioInit(sensorR, GPIO_INPUT); gpioInit(button, GPIO_INPUT); }
[ "void", "sensorsInit", "(", "void", ")", "{", "gpioInit", "(", "sensorF", ",", "GPIO_INPUT", ")", ";", "gpioInit", "(", "sensorR", ",", "GPIO_INPUT", ")", ";", "gpioInit", "(", "button", ",", "GPIO_INPUT", ")", ";", "}" ]
[Implementations of public functions]
[ "[", "Implementations", "of", "public", "functions", "]" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
3cc7a4108812c2e2b82e7435dc719e6fbbafae04
netatmo-drs/drs-embedded
nxp_src/nfc_deamon/SW369321/Examples/NfcrdlibEx2_AdvancedDiscoveryLoop/NfcrdlibEx2_AdvancedDiscoveryLoop.c
[ "MIT" ]
C
LoadProfile
phStatus_t
static phStatus_t LoadProfile(phacDiscLoop_Profile_t bProfile) { phStatus_t status = PH_ERR_SUCCESS; uint16_t wPasPollConfig = 0; uint16_t wActPollConfig = 0; uint16_t wPasLisConfig = 0; uint16_t wActLisConfig = 0; #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_A; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_B; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF_TAGS wPasPollConfig |= (PHAC_DISCLOOP_POS_BIT_MASK_F212 | PHAC_DISCLOOP_POS_BIT_MASK_F424); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEV_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_V; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_I18000P3M3_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_18000P3M3; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_P2P_ACTIVE wActPollConfig |= PHAC_DISCLOOP_ACT_POS_BIT_MASK_106; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF212_P2P_ACTIVE wActPollConfig |= PHAC_DISCLOOP_ACT_POS_BIT_MASK_212; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF424_P2P_ACTIVE wActPollConfig |= PHAC_DISCLOOP_ACT_POS_BIT_MASK_424; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TARGET_PASSIVE wPasLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_A; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF212_TARGET_PASSIVE wPasLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F212; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF424_TARGET_PASSIVE wPasLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F424; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TARGET_ACTIVE wActLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_A; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF212_TARGET_ACTIVE wActLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F212; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF424_TARGET_ACTIVE wActLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F424; #endif if(bProfile == PHAC_DISCLOOP_PROFILE_NFC) { /* passive Bailout bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_BAIL_OUT, 0x00); CHECK_STATUS(status); /* Set Passive poll bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_POLL_TECH_CFG, wPasPollConfig); CHECK_STATUS(status); /* Set Active poll bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_POLL_TECH_CFG, wActPollConfig); CHECK_STATUS(status); /* Set Passive listen bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_LIS_TECH_CFG, wPasLisConfig); CHECK_STATUS(status); /* Set Active listen bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_LIS_TECH_CFG, wActLisConfig); CHECK_STATUS(status); /* reset collision Pending */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_COLLISION_PENDING, PH_OFF); CHECK_STATUS(status); /* whether anti-collision is supported or not. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ANTI_COLL, PH_ON); CHECK_STATUS(status); /* Poll Mode default state*/ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE, PHAC_DISCLOOP_POLL_STATE_DETECTION); CHECK_STATUS(status); #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS /* Device limit for Type A */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT, 1); CHECK_STATUS(status); /* Passive polling Tx Guard times in micro seconds. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTA_VALUE_US, 5100); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS /* Device limit for Type B */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTB_VALUE_US, 5100); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF_TAGS /* Device limit for Type F */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEF_DEVICE_LIMIT, 1); CHECK_STATUS(status); /* Guard time for Type F. This guard time is applied when Type F poll before Type B */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTFB_VALUE_US, 20400); CHECK_STATUS(status); /* Guard time for Type F. This guard time is applied when Type B poll before Type F */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTBF_VALUE_US, 15300); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEV_TAGS /* Device limit for Type V (ISO 15693) */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEV_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTV_VALUE_US, 5200); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_I18000P3M3_TAGS /* Device limit for 18000P3M3 */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_18000P3M3_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GT18000P3M3_VALUE_US, 10000); CHECK_STATUS(status); #endif /* NFC Activity version supported */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACTIVITY_VERSION, PHAC_DISCLOOP_NFC_ACTIVITY_VERSION_1_1); CHECK_STATUS(status); /* Discovery loop Operation mode */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_OPE_MODE, RD_LIB_MODE_NFC); CHECK_STATUS(status); } else if(bProfile == PHAC_DISCLOOP_PROFILE_EMVCO) { /* EMVCO */ /* passive Bailout bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_BAIL_OUT, 0x00); CHECK_STATUS(status); /* passive poll bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_POLL_TECH_CFG, (PHAC_DISCLOOP_POS_BIT_MASK_A | PHAC_DISCLOOP_POS_BIT_MASK_B)); CHECK_STATUS(status); /* Active Listen bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_LIS_TECH_CFG, 0x00); CHECK_STATUS(status); /* Active Listen bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_LIS_TECH_CFG, 0x00); CHECK_STATUS(status); /* Active Poll bitmap config. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_POLL_TECH_CFG, 0x00); CHECK_STATUS(status); /* Bool to enable LPCD feature. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ENABLE_LPCD, PH_OFF); CHECK_STATUS(status); /* reset collision Pending */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_COLLISION_PENDING, PH_OFF); CHECK_STATUS(status); /* whether anti-collision is supported or not. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ANTI_COLL, PH_ON); CHECK_STATUS(status); /* Poll Mode default state*/ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE, PHAC_DISCLOOP_POLL_STATE_DETECTION); CHECK_STATUS(status); #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS /* Device limit for Type A */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT, 1); CHECK_STATUS(status); /* Passive polling Tx Guard times in micro seconds. */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTA_VALUE_US, 5100); CHECK_STATUS(status); /* Configure FSDI for the 14443P4A tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_FSDI, 0x08); CHECK_STATUS(status); /* Configure CID for the 14443P4A tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_CID, 0x00); CHECK_STATUS(status); /* Configure DRI for the 14443P4A tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_DRI, 0x00); CHECK_STATUS(status); /* Configure DSI for the 14443P4A tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_DSI, 0x00); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS /* Device limit for Type B */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTB_VALUE_US, 5100); CHECK_STATUS(status); /* Configure AFI for the type B tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_AFI_REQ, 0x00); CHECK_STATUS(status); /* Configure FSDI for the type B tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_FSDI, 0x08); CHECK_STATUS(status); /* Configure CID for the type B tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_CID, 0x00); CHECK_STATUS(status); /* Configure DRI for the type B tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DRI, 0x00); CHECK_STATUS(status); /* Configure DSI for the type B tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DSI, 0x00); CHECK_STATUS(status); /* Configure Extended ATQB support for the type B tags */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_EXTATQB, 0x00); CHECK_STATUS(status); #endif /* Configure reader library mode */ status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_OPE_MODE, RD_LIB_MODE_EMVCO); CHECK_STATUS(status); } else { /* Do Nothing */ } return status; }
/** * This function will load/configure Discovery loop with default values based on interested profile * Application can read these values from EEPROM area and load/configure Discovery loop via SetConfig * \param bProfile Reader Library Profile * \note Values used below are default and is for demonstration purpose. */
This function will load/configure Discovery loop with default values based on interested profile Application can read these values from EEPROM area and load/configure Discovery loop via SetConfig \param bProfile Reader Library Profile \note Values used below are default and is for demonstration purpose.
[ "This", "function", "will", "load", "/", "configure", "Discovery", "loop", "with", "default", "values", "based", "on", "interested", "profile", "Application", "can", "read", "these", "values", "from", "EEPROM", "area", "and", "load", "/", "configure", "Discovery", "loop", "via", "SetConfig", "\\", "param", "bProfile", "Reader", "Library", "Profile", "\\", "note", "Values", "used", "below", "are", "default", "and", "is", "for", "demonstration", "purpose", "." ]
static phStatus_t LoadProfile(phacDiscLoop_Profile_t bProfile) { phStatus_t status = PH_ERR_SUCCESS; uint16_t wPasPollConfig = 0; uint16_t wActPollConfig = 0; uint16_t wPasLisConfig = 0; uint16_t wActLisConfig = 0; #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_A; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_B; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF_TAGS wPasPollConfig |= (PHAC_DISCLOOP_POS_BIT_MASK_F212 | PHAC_DISCLOOP_POS_BIT_MASK_F424); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEV_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_V; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_I18000P3M3_TAGS wPasPollConfig |= PHAC_DISCLOOP_POS_BIT_MASK_18000P3M3; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_P2P_ACTIVE wActPollConfig |= PHAC_DISCLOOP_ACT_POS_BIT_MASK_106; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF212_P2P_ACTIVE wActPollConfig |= PHAC_DISCLOOP_ACT_POS_BIT_MASK_212; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF424_P2P_ACTIVE wActPollConfig |= PHAC_DISCLOOP_ACT_POS_BIT_MASK_424; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TARGET_PASSIVE wPasLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_A; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF212_TARGET_PASSIVE wPasLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F212; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF424_TARGET_PASSIVE wPasLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F424; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TARGET_ACTIVE wActLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_A; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF212_TARGET_ACTIVE wActLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F212; #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF424_TARGET_ACTIVE wActLisConfig |= PHAC_DISCLOOP_POS_BIT_MASK_F424; #endif if(bProfile == PHAC_DISCLOOP_PROFILE_NFC) { status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_BAIL_OUT, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_POLL_TECH_CFG, wPasPollConfig); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_POLL_TECH_CFG, wActPollConfig); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_LIS_TECH_CFG, wPasLisConfig); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_LIS_TECH_CFG, wActLisConfig); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_COLLISION_PENDING, PH_OFF); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ANTI_COLL, PH_ON); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE, PHAC_DISCLOOP_POLL_STATE_DETECTION); CHECK_STATUS(status); #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTA_VALUE_US, 5100); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTB_VALUE_US, 5100); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEF_TAGS status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEF_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTFB_VALUE_US, 20400); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTBF_VALUE_US, 15300); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEV_TAGS status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEV_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTV_VALUE_US, 5200); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_I18000P3M3_TAGS status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_18000P3M3_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GT18000P3M3_VALUE_US, 10000); CHECK_STATUS(status); #endif status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACTIVITY_VERSION, PHAC_DISCLOOP_NFC_ACTIVITY_VERSION_1_1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_OPE_MODE, RD_LIB_MODE_NFC); CHECK_STATUS(status); } else if(bProfile == PHAC_DISCLOOP_PROFILE_EMVCO) { status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_BAIL_OUT, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_POLL_TECH_CFG, (PHAC_DISCLOOP_POS_BIT_MASK_A | PHAC_DISCLOOP_POS_BIT_MASK_B)); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_PAS_LIS_TECH_CFG, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_LIS_TECH_CFG, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ACT_POLL_TECH_CFG, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ENABLE_LPCD, PH_OFF); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_COLLISION_PENDING, PH_OFF); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_ANTI_COLL, PH_ON); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE, PHAC_DISCLOOP_POLL_STATE_DETECTION); CHECK_STATUS(status); #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTA_VALUE_US, 5100); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_FSDI, 0x08); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_CID, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_DRI, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_DSI, 0x00); CHECK_STATUS(status); #endif #ifdef NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DEVICE_LIMIT, 1); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_GTB_VALUE_US, 5100); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_AFI_REQ, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_FSDI, 0x08); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_CID, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DRI, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_DSI, 0x00); CHECK_STATUS(status); status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEB_EXTATQB, 0x00); CHECK_STATUS(status); #endif status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_OPE_MODE, RD_LIB_MODE_EMVCO); CHECK_STATUS(status); } else { } return status; }
[ "static", "phStatus_t", "LoadProfile", "(", "phacDiscLoop_Profile_t", "bProfile", ")", "{", "phStatus_t", "status", "=", "PH_ERR_SUCCESS", ";", "uint16_t", "wPasPollConfig", "=", "0", ";", "uint16_t", "wActPollConfig", "=", "0", ";", "uint16_t", "wPasLisConfig", "=", "0", ";", "uint16_t", "wActLisConfig", "=", "0", ";", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS", "wPasPollConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_A", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS", "wPasPollConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_B", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF_TAGS", "wPasPollConfig", "|=", "(", "PHAC_DISCLOOP_POS_BIT_MASK_F212", "|", "PHAC_DISCLOOP_POS_BIT_MASK_F424", ")", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEV_TAGS", "wPasPollConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_V", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_I18000P3M3_TAGS", "wPasPollConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_18000P3M3", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEA_P2P_ACTIVE", "wActPollConfig", "|=", "PHAC_DISCLOOP_ACT_POS_BIT_MASK_106", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF212_P2P_ACTIVE", "wActPollConfig", "|=", "PHAC_DISCLOOP_ACT_POS_BIT_MASK_212", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF424_P2P_ACTIVE", "wActPollConfig", "|=", "PHAC_DISCLOOP_ACT_POS_BIT_MASK_424", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEA_TARGET_PASSIVE", "wPasLisConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_A", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF212_TARGET_PASSIVE", "wPasLisConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_F212", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF424_TARGET_PASSIVE", "wPasLisConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_F424", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEA_TARGET_ACTIVE", "wActLisConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_A", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF212_TARGET_ACTIVE", "wActLisConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_F212", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF424_TARGET_ACTIVE", "wActLisConfig", "|=", "PHAC_DISCLOOP_POS_BIT_MASK_F424", ";", "#endif", "if", "(", "bProfile", "==", "PHAC_DISCLOOP_PROFILE_NFC", ")", "{", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_BAIL_OUT", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_PAS_POLL_TECH_CFG", ",", "wPasPollConfig", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ACT_POLL_TECH_CFG", ",", "wActPollConfig", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_PAS_LIS_TECH_CFG", ",", "wPasLisConfig", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ACT_LIS_TECH_CFG", ",", "wActLisConfig", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_COLLISION_PENDING", ",", "PH_OFF", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ANTI_COLL", ",", "PH_ON", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE", ",", "PHAC_DISCLOOP_POLL_STATE_DETECTION", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT", ",", "1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GTA_VALUE_US", ",", "5100", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_DEVICE_LIMIT", ",", "1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GTB_VALUE_US", ",", "5100", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEF_TAGS", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEF_DEVICE_LIMIT", ",", "1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GTFB_VALUE_US", ",", "20400", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GTBF_VALUE_US", ",", "15300", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEV_TAGS", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEV_DEVICE_LIMIT", ",", "1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GTV_VALUE_US", ",", "5200", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_I18000P3M3_TAGS", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_18000P3M3_DEVICE_LIMIT", ",", "1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GT18000P3M3_VALUE_US", ",", "10000", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#endif", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ACTIVITY_VERSION", ",", "PHAC_DISCLOOP_NFC_ACTIVITY_VERSION_1_1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_OPE_MODE", ",", "RD_LIB_MODE_NFC", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "}", "else", "if", "(", "bProfile", "==", "PHAC_DISCLOOP_PROFILE_EMVCO", ")", "{", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_BAIL_OUT", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_PAS_POLL_TECH_CFG", ",", "(", "PHAC_DISCLOOP_POS_BIT_MASK_A", "|", "PHAC_DISCLOOP_POS_BIT_MASK_B", ")", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_PAS_LIS_TECH_CFG", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ACT_LIS_TECH_CFG", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ACT_POLL_TECH_CFG", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ENABLE_LPCD", ",", "PH_OFF", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_COLLISION_PENDING", ",", "PH_OFF", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_ANTI_COLL", ",", "PH_ON", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE", ",", "PHAC_DISCLOOP_POLL_STATE_DETECTION", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEA_TAGS", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT", ",", "1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GTA_VALUE_US", ",", "5100", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_FSDI", ",", "0x08", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_CID", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_DRI", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEA_I3P4_DSI", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#endif", "#ifdef", "NXPBUILD__PHAC_DISCLOOP_TYPEB_TAGS", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_DEVICE_LIMIT", ",", "1", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_GTB_VALUE_US", ",", "5100", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_AFI_REQ", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_FSDI", ",", "0x08", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_CID", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_DRI", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_DSI", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_TYPEB_EXTATQB", ",", "0x00", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "#endif", "status", "=", "phacDiscLoop_SetConfig", "(", "pDiscLoop", ",", "PHAC_DISCLOOP_CONFIG_OPE_MODE", ",", "RD_LIB_MODE_EMVCO", ")", ";", "CHECK_STATUS", "(", "status", ")", ";", "}", "else", "{", "}", "return", "status", ";", "}" ]
This function will load/configure Discovery loop with default values based on interested profile Application can read these values from EEPROM area and load/configure Discovery loop via SetConfig \param bProfile Reader Library Profile \note Values used below are default and is for demonstration purpose.
[ "This", "function", "will", "load", "/", "configure", "Discovery", "loop", "with", "default", "values", "based", "on", "interested", "profile", "Application", "can", "read", "these", "values", "from", "EEPROM", "area", "and", "load", "/", "configure", "Discovery", "loop", "via", "SetConfig", "\\", "param", "bProfile", "Reader", "Library", "Profile", "\\", "note", "Values", "used", "below", "are", "default", "and", "is", "for", "demonstration", "purpose", "." ]
[ "/* passive Bailout bitmap config. */", "/* Set Passive poll bitmap config. */", "/* Set Active poll bitmap config. */", "/* Set Passive listen bitmap config. */", "/* Set Active listen bitmap config. */", "/* reset collision Pending */", "/* whether anti-collision is supported or not. */", "/* Poll Mode default state*/", "/* Device limit for Type A */", "/* Passive polling Tx Guard times in micro seconds. */", "/* Device limit for Type B */", "/* Device limit for Type F */", "/* Guard time for Type F. This guard time is applied when Type F poll before Type B */", "/* Guard time for Type F. This guard time is applied when Type B poll before Type F */", "/* Device limit for Type V (ISO 15693) */", "/* Device limit for 18000P3M3 */", "/* NFC Activity version supported */", "/* Discovery loop Operation mode */", "/* EMVCO */", "/* passive Bailout bitmap config. */", "/* passive poll bitmap config. */", "/* Active Listen bitmap config. */", "/* Active Listen bitmap config. */", "/* Active Poll bitmap config. */", "/* Bool to enable LPCD feature. */", "/* reset collision Pending */", "/* whether anti-collision is supported or not. */", "/* Poll Mode default state*/", "/* Device limit for Type A */", "/* Passive polling Tx Guard times in micro seconds. */", "/* Configure FSDI for the 14443P4A tags */", "/* Configure CID for the 14443P4A tags */", "/* Configure DRI for the 14443P4A tags */", "/* Configure DSI for the 14443P4A tags */", "/* Device limit for Type B */", "/* Configure AFI for the type B tags */", "/* Configure FSDI for the type B tags */", "/* Configure CID for the type B tags */", "/* Configure DRI for the type B tags */", "/* Configure DSI for the type B tags */", "/* Configure Extended ATQB support for the type B tags */", "/* Configure reader library mode */", "/* Do Nothing */" ]
[ { "param": "bProfile", "type": "phacDiscLoop_Profile_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bProfile", "type": "phacDiscLoop_Profile_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8f71e28b9dd019d6bc1e985343b624389e3f278e
netatmo-drs/drs-embedded
app/rtttl/rtttl_api.c
[ "MIT" ]
C
rtttl_api_get_frequency
rtttl_api_error_code_e
static rtttl_api_error_code_e rtttl_api_get_frequency(rtttl_note_name_e note, unsigned char octave, short *frequency) { int n = 0; int half_steps = 0; int fn = 0; int i = 0; if (frequency == NULL) { return RTTTL_API_INVALID_ARGUMENT; } if (note == RTTTL_PAUSE) { *frequency = 0; return RTTTL_API_OK; } // Find half steps from C in one octave while ((sorted_octave[i] != note) && (i < OCTAVE_HALF_STEP_NUMBER)) { half_steps++; i++; } if (i >= OCTAVE_HALF_STEP_NUMBER) { // The note is note in the range. return RTTTL_API_INVALID_ARGUMENT; } // Add half steps due to octave. half_steps += octave * OCTAVE_HALF_STEP_NUMBER; // Compute n and (a)**n and frequency if (half_steps > A4_HALF_STEPS) { // The note is higher. n = half_steps - A4_HALF_STEPS; // Commpute (a)**n fn = TWELTH_ROOT_OF_TWO_X1000; while (n > 1) { fn *= TWELTH_ROOT_OF_TWO_X1000; // Ensure that we keep a low number to avoid the power calcution going crazy fn /= 1000; n--; } // Multiply by f0 fn *= A4_FREQUENCY; // Divide by 1000 since TWELTH_ROOT_OF_TWO_X1000 has a factor x1000. fn /= 1000; // } else if (half_steps == A4_HALF_STEPS) { // (a)**n = 1; fn = A4_FREQUENCY; } else { // The note is lower. n = A4_HALF_STEPS - half_steps; // Compute (a)**n fn = 1000; while (n > 0) { // Ensure that we have a high number so that the division will not be equal to zero. fn *= 1000; fn /= TWELTH_ROOT_OF_TWO_X1000; n--; } // Multiply by f0 fn *= A4_FREQUENCY; // Divide by 1000 since TWELTH_ROOT_OF_TWO_X1000 has a factor x1000. fn /= 1000; // } *frequency = fn; return RTTTL_API_OK; }
/* * Compute note frequency base on A4 = 440Hz. * The basic formula for the frequencies of the notes is given by * fn = f0 * (a)**n * where * f0 = the frequency of one fixed note which must be defined. Here A4 = 440 Hz. * n = the number of half steps away from the fixed note you are. If you are at a higher note, n is * positive. If you are on a lower note, n is negative. * fn = the frequency of the note n half steps away. * a = (2)1/12 = the twelth root of 2 = the number which when multiplied by itself 12 times equals 2 * = 1.059463094359... */
Compute note frequency base on A4 = 440Hz. The basic formula for the frequencies of the notes is given by fn = f0 * (a)**n where f0 = the frequency of one fixed note which must be defined.
[ "Compute", "note", "frequency", "base", "on", "A4", "=", "440Hz", ".", "The", "basic", "formula", "for", "the", "frequencies", "of", "the", "notes", "is", "given", "by", "fn", "=", "f0", "*", "(", "a", ")", "**", "n", "where", "f0", "=", "the", "frequency", "of", "one", "fixed", "note", "which", "must", "be", "defined", "." ]
static rtttl_api_error_code_e rtttl_api_get_frequency(rtttl_note_name_e note, unsigned char octave, short *frequency) { int n = 0; int half_steps = 0; int fn = 0; int i = 0; if (frequency == NULL) { return RTTTL_API_INVALID_ARGUMENT; } if (note == RTTTL_PAUSE) { *frequency = 0; return RTTTL_API_OK; } while ((sorted_octave[i] != note) && (i < OCTAVE_HALF_STEP_NUMBER)) { half_steps++; i++; } if (i >= OCTAVE_HALF_STEP_NUMBER) { return RTTTL_API_INVALID_ARGUMENT; } half_steps += octave * OCTAVE_HALF_STEP_NUMBER; if (half_steps > A4_HALF_STEPS) { n = half_steps - A4_HALF_STEPS; fn = TWELTH_ROOT_OF_TWO_X1000; while (n > 1) { fn *= TWELTH_ROOT_OF_TWO_X1000; fn /= 1000; n--; } fn *= A4_FREQUENCY; fn /= 1000; } else if (half_steps == A4_HALF_STEPS) { (a)**n = 1; fn = A4_FREQUENCY; } else { The note is lower. n = A4_HALF_STEPS - half_steps; Compute (a)**n fn = 1000; while (n > 0) { Ensure that we have a high number so that the division will not be equal to zero. fn *= 1000; fn /= TWELTH_ROOT_OF_TWO_X1000; n--; } fn *= A4_FREQUENCY; fn /= 1000; } *frequency = fn; return RTTTL_API_OK; }
[ "static", "rtttl_api_error_code_e", "rtttl_api_get_frequency", "(", "rtttl_note_name_e", "note", ",", "unsigned", "char", "octave", ",", "short", "*", "frequency", ")", "{", "int", "n", "=", "0", ";", "int", "half_steps", "=", "0", ";", "int", "fn", "=", "0", ";", "int", "i", "=", "0", ";", "if", "(", "frequency", "==", "NULL", ")", "{", "return", "RTTTL_API_INVALID_ARGUMENT", ";", "}", "if", "(", "note", "==", "RTTTL_PAUSE", ")", "{", "*", "frequency", "=", "0", ";", "return", "RTTTL_API_OK", ";", "}", "while", "(", "(", "sorted_octave", "[", "i", "]", "!=", "note", ")", "&&", "(", "i", "<", "OCTAVE_HALF_STEP_NUMBER", ")", ")", "{", "half_steps", "++", ";", "i", "++", ";", "}", "if", "(", "i", ">=", "OCTAVE_HALF_STEP_NUMBER", ")", "{", "return", "RTTTL_API_INVALID_ARGUMENT", ";", "}", "half_steps", "+=", "octave", "*", "OCTAVE_HALF_STEP_NUMBER", ";", "if", "(", "half_steps", ">", "A4_HALF_STEPS", ")", "{", "n", "=", "half_steps", "-", "A4_HALF_STEPS", ";", "fn", "=", "TWELTH_ROOT_OF_TWO_X1000", ";", "while", "(", "n", ">", "1", ")", "{", "fn", "*=", "TWELTH_ROOT_OF_TWO_X1000", ";", "fn", "/=", "1000", ";", "n", "--", ";", "}", "fn", "*=", "A4_FREQUENCY", ";", "fn", "/=", "1000", ";", "}", "else", "if", "(", "half_steps", "==", "A4_HALF_STEPS", ")", "{", "fn", "=", "A4_FREQUENCY", ";", "}", "else", "{", "n", "=", "A4_HALF_STEPS", "-", "half_steps", ";", "fn", "=", "1000", ";", "while", "(", "n", ">", "0", ")", "{", "fn", "*=", "1000", ";", "fn", "/=", "TWELTH_ROOT_OF_TWO_X1000", ";", "n", "--", ";", "}", "fn", "*=", "A4_FREQUENCY", ";", "fn", "/=", "1000", ";", "}", "*", "frequency", "=", "fn", ";", "return", "RTTTL_API_OK", ";", "}" ]
Compute note frequency base on A4 = 440Hz.
[ "Compute", "note", "frequency", "base", "on", "A4", "=", "440Hz", "." ]
[ "// Find half steps from C in one octave", "// The note is note in the range.", "// Add half steps due to octave.", "// Compute n and (a)**n and frequency", "// The note is higher.", "// Commpute (a)**n", "// Ensure that we keep a low number to avoid the power calcution going crazy", "// Multiply by f0", "// Divide by 1000 since TWELTH_ROOT_OF_TWO_X1000 has a factor x1000.", "//", "// (a)**n = 1;", "// The note is lower.", "// Compute (a)**n", "// Ensure that we have a high number so that the division will not be equal to zero.", "// Multiply by f0", "// Divide by 1000 since TWELTH_ROOT_OF_TWO_X1000 has a factor x1000.", "//" ]
[ { "param": "note", "type": "rtttl_note_name_e" }, { "param": "octave", "type": "unsigned char" }, { "param": "frequency", "type": "short" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "note", "type": "rtttl_note_name_e", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "octave", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "frequency", "type": "short", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8f71e28b9dd019d6bc1e985343b624389e3f278e
netatmo-drs/drs-embedded
app/rtttl/rtttl_api.c
[ "MIT" ]
C
rtttl_api_get_duration_ms
rtttl_api_error_code_e
static rtttl_api_error_code_e rtttl_api_get_duration_ms(unsigned char duration, rtttl_note_t note, short *duration_ms) { short beat_interval_ms = 0; if (duration_ms == NULL) { return RTTTL_API_INVALID_ARGUMENT; } // Get beat_interval from tempo (in beat per minutes) beat_interval_ms = (60 * 1000) / current_decoded_song.default_values.tempo; // Get note duration considering tempo. Duration is a divider of a whole note (4 beats). *duration_ms = (beat_interval_ms * 4) / duration; if (note.dotted) { *duration_ms = (*duration_ms * 3) / 2; } return RTTTL_API_OK; }
/* * From note frequency, note duration, song tempo and motorposition, deduct the motocmd that has to * be send to play the note. */
From note frequency, note duration, song tempo and motorposition, deduct the motocmd that has to be send to play the note.
[ "From", "note", "frequency", "note", "duration", "song", "tempo", "and", "motorposition", "deduct", "the", "motocmd", "that", "has", "to", "be", "send", "to", "play", "the", "note", "." ]
static rtttl_api_error_code_e rtttl_api_get_duration_ms(unsigned char duration, rtttl_note_t note, short *duration_ms) { short beat_interval_ms = 0; if (duration_ms == NULL) { return RTTTL_API_INVALID_ARGUMENT; } beat_interval_ms = (60 * 1000) / current_decoded_song.default_values.tempo; *duration_ms = (beat_interval_ms * 4) / duration; if (note.dotted) { *duration_ms = (*duration_ms * 3) / 2; } return RTTTL_API_OK; }
[ "static", "rtttl_api_error_code_e", "rtttl_api_get_duration_ms", "(", "unsigned", "char", "duration", ",", "rtttl_note_t", "note", ",", "short", "*", "duration_ms", ")", "{", "short", "beat_interval_ms", "=", "0", ";", "if", "(", "duration_ms", "==", "NULL", ")", "{", "return", "RTTTL_API_INVALID_ARGUMENT", ";", "}", "beat_interval_ms", "=", "(", "60", "*", "1000", ")", "/", "current_decoded_song", ".", "default_values", ".", "tempo", ";", "*", "duration_ms", "=", "(", "beat_interval_ms", "*", "4", ")", "/", "duration", ";", "if", "(", "note", ".", "dotted", ")", "{", "*", "duration_ms", "=", "(", "*", "duration_ms", "*", "3", ")", "/", "2", ";", "}", "return", "RTTTL_API_OK", ";", "}" ]
From note frequency, note duration, song tempo and motorposition, deduct the motocmd that has to be send to play the note.
[ "From", "note", "frequency", "note", "duration", "song", "tempo", "and", "motorposition", "deduct", "the", "motocmd", "that", "has", "to", "be", "send", "to", "play", "the", "note", "." ]
[ "// Get beat_interval from tempo (in beat per minutes)", "// Get note duration considering tempo. Duration is a divider of a whole note (4 beats)." ]
[ { "param": "duration", "type": "unsigned char" }, { "param": "note", "type": "rtttl_note_t" }, { "param": "duration_ms", "type": "short" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "duration", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "note", "type": "rtttl_note_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "duration_ms", "type": "short", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
917455a71225d5692452ecbe4c7a75603d79815e
mhamilt/FD_Plate_Class
AudioIOClasses/AudioOut.h
[ "MIT" ]
C
basicHeader
waveFormatHeader_t
waveFormatHeader_t * basicHeader() { waveFormatHeader_t * wh = (waveFormatHeader_t *)malloc(sizeof(waveFormatHeader_t)); memcpy(wh->chunkid, &"RIFF", 4); memcpy(wh->format, &"WAVE", 4); memcpy(wh->subchunk1id, &"fmt ", 4); //notice the space at the end! wh -> subchunk1size = 16; return wh; }
/** Define a standard 16bit PCM .wav file header. @return <#return value description#> */
Define a standard 16bit PCM .wav file header.
[ "Define", "a", "standard", "16bit", "PCM", ".", "wav", "file", "header", "." ]
waveFormatHeader_t * basicHeader() { waveFormatHeader_t * wh = (waveFormatHeader_t *)malloc(sizeof(waveFormatHeader_t)); memcpy(wh->chunkid, &"RIFF", 4); memcpy(wh->format, &"WAVE", 4); memcpy(wh->subchunk1id, &"fmt ", 4); wh -> subchunk1size = 16; return wh; }
[ "waveFormatHeader_t", "*", "basicHeader", "(", ")", "{", "waveFormatHeader_t", "*", "wh", "=", "(", "waveFormatHeader_t", "*", ")", "malloc", "(", "sizeof", "(", "waveFormatHeader_t", ")", ")", ";", "memcpy", "(", "wh", "->", "chunkid", ",", "&", "\"", "\"", ",", "4", ")", ";", "memcpy", "(", "wh", "->", "format", ",", "&", "\"", "\"", ",", "4", ")", ";", "memcpy", "(", "wh", "->", "subchunk1id", ",", "&", "\"", "\"", ",", "4", ")", ";", "wh", "->", "subchunk1size", "=", "16", ";", "return", "wh", ";", "}" ]
Define a standard 16bit PCM .wav file header.
[ "Define", "a", "standard", "16bit", "PCM", ".", "wav", "file", "header", "." ]
[ "//notice the space at the end!" ]
[]
{ "returns": [ { "docstring": "<#return value description#>", "docstring_tokens": [ "<#return", "value", "description#", ">" ], "type": null } ], "raises": [], "params": [], "outlier_params": [], "others": [] }
917455a71225d5692452ecbe4c7a75603d79815e
mhamilt/FD_Plate_Class
AudioIOClasses/AudioOut.h
[ "MIT" ]
C
stereo16bitWaveHeader
waveFormatHeader_t
waveFormatHeader_t * stereo16bitWaveHeader(double SampRate) { waveFormatHeader_t * wh = basicHeader(); wh->audioformat = 1; wh->numchannels = 2; wh -> samplerate = (uint32_t)SampRate; wh -> bitspersample = 16; wh -> byterate = wh->numchannels * wh -> samplerate * wh -> bitspersample/8; wh -> blockalign = wh->numchannels * wh -> bitspersample/8; memcpy(wh->subchunk2id, &"data", 4); return wh; }
//============================================================================== /** Fill in the gaps of basicHeader() to create a header for a Stereo .wav file @param SampRate <#SampRate description#> @return <#return value description#> */
Fill in the gaps of basicHeader() to create a header for a Stereo .wav file
[ "Fill", "in", "the", "gaps", "of", "basicHeader", "()", "to", "create", "a", "header", "for", "a", "Stereo", ".", "wav", "file" ]
waveFormatHeader_t * stereo16bitWaveHeader(double SampRate) { waveFormatHeader_t * wh = basicHeader(); wh->audioformat = 1; wh->numchannels = 2; wh -> samplerate = (uint32_t)SampRate; wh -> bitspersample = 16; wh -> byterate = wh->numchannels * wh -> samplerate * wh -> bitspersample/8; wh -> blockalign = wh->numchannels * wh -> bitspersample/8; memcpy(wh->subchunk2id, &"data", 4); return wh; }
[ "waveFormatHeader_t", "*", "stereo16bitWaveHeader", "(", "double", "SampRate", ")", "{", "waveFormatHeader_t", "*", "wh", "=", "basicHeader", "(", ")", ";", "wh", "->", "audioformat", "=", "1", ";", "wh", "->", "numchannels", "=", "2", ";", "wh", "->", "samplerate", "=", "(", "uint32_t", ")", "SampRate", ";", "wh", "->", "bitspersample", "=", "16", ";", "wh", "->", "byterate", "=", "wh", "->", "numchannels", "*", "wh", "->", "samplerate", "*", "wh", "->", "bitspersample", "/", "8", ";", "wh", "->", "blockalign", "=", "wh", "->", "numchannels", "*", "wh", "->", "bitspersample", "/", "8", ";", "memcpy", "(", "wh", "->", "subchunk2id", ",", "&", "\"", "\"", ",", "4", ")", ";", "return", "wh", ";", "}" ]
Fill in the gaps of basicHeader() to create a header for a Stereo .wav file
[ "Fill", "in", "the", "gaps", "of", "basicHeader", "()", "to", "create", "a", "header", "for", "a", "Stereo", ".", "wav", "file" ]
[]
[ { "param": "SampRate", "type": "double" } ]
{ "returns": [ { "docstring": "<#return value description#>", "docstring_tokens": [ "<#return", "value", "description#", ">" ], "type": null } ], "raises": [], "params": [ { "identifier": "SampRate", "type": "double", "docstring": null, "docstring_tokens": [ "None" ], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
917455a71225d5692452ecbe4c7a75603d79815e
mhamilt/FD_Plate_Class
AudioIOClasses/AudioOut.h
[ "MIT" ]
C
mono16bitWaveHeader
waveFormatHeader_t
waveFormatHeader_t * mono16bitWaveHeader(double SampRate) { waveFormatHeader_t * wh = basicHeader(); wh->audioformat = 1; wh->numchannels = 1; wh -> samplerate = (uint32_t)SampRate; wh -> bitspersample = 16; wh -> byterate = wh->numchannels * wh -> samplerate * wh -> bitspersample/8; wh -> blockalign = wh->numchannels * wh -> bitspersample/8; memcpy(wh->subchunk2id, &"data", 4); return wh; }
/** Fill in the gaps of basicHeader() to create a header for a Mono .wav file @param SampRate <#SampRate description#> @return <#return value description#> */
Fill in the gaps of basicHeader() to create a header for a Mono .wav file
[ "Fill", "in", "the", "gaps", "of", "basicHeader", "()", "to", "create", "a", "header", "for", "a", "Mono", ".", "wav", "file" ]
waveFormatHeader_t * mono16bitWaveHeader(double SampRate) { waveFormatHeader_t * wh = basicHeader(); wh->audioformat = 1; wh->numchannels = 1; wh -> samplerate = (uint32_t)SampRate; wh -> bitspersample = 16; wh -> byterate = wh->numchannels * wh -> samplerate * wh -> bitspersample/8; wh -> blockalign = wh->numchannels * wh -> bitspersample/8; memcpy(wh->subchunk2id, &"data", 4); return wh; }
[ "waveFormatHeader_t", "*", "mono16bitWaveHeader", "(", "double", "SampRate", ")", "{", "waveFormatHeader_t", "*", "wh", "=", "basicHeader", "(", ")", ";", "wh", "->", "audioformat", "=", "1", ";", "wh", "->", "numchannels", "=", "1", ";", "wh", "->", "samplerate", "=", "(", "uint32_t", ")", "SampRate", ";", "wh", "->", "bitspersample", "=", "16", ";", "wh", "->", "byterate", "=", "wh", "->", "numchannels", "*", "wh", "->", "samplerate", "*", "wh", "->", "bitspersample", "/", "8", ";", "wh", "->", "blockalign", "=", "wh", "->", "numchannels", "*", "wh", "->", "bitspersample", "/", "8", ";", "memcpy", "(", "wh", "->", "subchunk2id", ",", "&", "\"", "\"", ",", "4", ")", ";", "return", "wh", ";", "}" ]
Fill in the gaps of basicHeader() to create a header for a Mono .wav file
[ "Fill", "in", "the", "gaps", "of", "basicHeader", "()", "to", "create", "a", "header", "for", "a", "Mono", ".", "wav", "file" ]
[]
[ { "param": "SampRate", "type": "double" } ]
{ "returns": [ { "docstring": "<#return value description#>", "docstring_tokens": [ "<#return", "value", "description#", ">" ], "type": null } ], "raises": [], "params": [ { "identifier": "SampRate", "type": "double", "docstring": null, "docstring_tokens": [ "None" ], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
917455a71225d5692452ecbe4c7a75603d79815e
mhamilt/FD_Plate_Class
AudioIOClasses/AudioOut.h
[ "MIT" ]
C
readWav
double
double *readWav(const char *filename, int *sampsperchan, int *sampleRate) { FILE *f; waveFormatHeader hdr; double *data; short *buf; int i, length; f = fopen(filename, "rb"); if (!f) { return NULL; } fread(&hdr, 1, sizeof(hdr), f); /* quick sanity check */ if ((strncmp(&hdr.chunkid[0], "RIFF", 4)) || (strncmp(&hdr.format[0], "WAVE", 4)) || (strncmp(&hdr.subchunk1id[0], "fmt ", 4)) || (strncmp(&hdr.subchunk2id[0], "data", 4))) { fclose(f); return NULL; } /* check correct format */ if ((hdr.bitspersample != 16)) { fclose(f); printf("FILE NOT 16-BIT\n"); return NULL; } *sampleRate = hdr.samplerate; length = hdr.subchunk2size / 2; *sampsperchan = hdr.subchunk2size*8/(hdr.numchannels*hdr.bitspersample); buf = (short *)malloc((length)*sizeof(short)); if (!buf) { fclose(f); return NULL; } fread(buf, (length)*sizeof(short), 1, f); fclose(f); data = (double *)malloc((length)*sizeof(double)); if (!data) { free(buf); return NULL; } // Dividing by this will scale a .wav to between -1 and 1 double wavbitscale = pow(2,hdr.bitspersample)/2; int i2=0; for (i = 0; i < (*sampsperchan); i++) { for (int j = 0; j < hdr.numchannels; j++) { if (j==0) { data[i] = ((double)buf[i2]) / wavbitscale; } i2++; } } printf("%d samples read from %s\n",length,filename); free(buf); return data; }
// Will read first channel only on multichannel files /** <#Description#> @param filename <#filename description#> @param sampsperchan <#sampsperchan description#> @param sampleRate <#sampleRate description#> @return <#return value description#> */
Will read first channel only on multichannel files <#Description#>
[ "Will", "read", "first", "channel", "only", "on", "multichannel", "files", "<#Description#", ">" ]
double *readWav(const char *filename, int *sampsperchan, int *sampleRate) { FILE *f; waveFormatHeader hdr; double *data; short *buf; int i, length; f = fopen(filename, "rb"); if (!f) { return NULL; } fread(&hdr, 1, sizeof(hdr), f); if ((strncmp(&hdr.chunkid[0], "RIFF", 4)) || (strncmp(&hdr.format[0], "WAVE", 4)) || (strncmp(&hdr.subchunk1id[0], "fmt ", 4)) || (strncmp(&hdr.subchunk2id[0], "data", 4))) { fclose(f); return NULL; } if ((hdr.bitspersample != 16)) { fclose(f); printf("FILE NOT 16-BIT\n"); return NULL; } *sampleRate = hdr.samplerate; length = hdr.subchunk2size / 2; *sampsperchan = hdr.subchunk2size*8/(hdr.numchannels*hdr.bitspersample); buf = (short *)malloc((length)*sizeof(short)); if (!buf) { fclose(f); return NULL; } fread(buf, (length)*sizeof(short), 1, f); fclose(f); data = (double *)malloc((length)*sizeof(double)); if (!data) { free(buf); return NULL; } double wavbitscale = pow(2,hdr.bitspersample)/2; int i2=0; for (i = 0; i < (*sampsperchan); i++) { for (int j = 0; j < hdr.numchannels; j++) { if (j==0) { data[i] = ((double)buf[i2]) / wavbitscale; } i2++; } } printf("%d samples read from %s\n",length,filename); free(buf); return data; }
[ "double", "*", "readWav", "(", "const", "char", "*", "filename", ",", "int", "*", "sampsperchan", ",", "int", "*", "sampleRate", ")", "{", "FILE", "*", "f", ";", "waveFormatHeader", "hdr", ";", "double", "*", "data", ";", "short", "*", "buf", ";", "int", "i", ",", "length", ";", "f", "=", "fopen", "(", "filename", ",", "\"", "\"", ")", ";", "if", "(", "!", "f", ")", "{", "return", "NULL", ";", "}", "fread", "(", "&", "hdr", ",", "1", ",", "sizeof", "(", "hdr", ")", ",", "f", ")", ";", "if", "(", "(", "strncmp", "(", "&", "hdr", ".", "chunkid", "[", "0", "]", ",", "\"", "\"", ",", "4", ")", ")", "||", "(", "strncmp", "(", "&", "hdr", ".", "format", "[", "0", "]", ",", "\"", "\"", ",", "4", ")", ")", "||", "(", "strncmp", "(", "&", "hdr", ".", "subchunk1id", "[", "0", "]", ",", "\"", "\"", ",", "4", ")", ")", "||", "(", "strncmp", "(", "&", "hdr", ".", "subchunk2id", "[", "0", "]", ",", "\"", "\"", ",", "4", ")", ")", ")", "{", "fclose", "(", "f", ")", ";", "return", "NULL", ";", "}", "if", "(", "(", "hdr", ".", "bitspersample", "!=", "16", ")", ")", "{", "fclose", "(", "f", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "NULL", ";", "}", "*", "sampleRate", "=", "hdr", ".", "samplerate", ";", "length", "=", "hdr", ".", "subchunk2size", "/", "2", ";", "*", "sampsperchan", "=", "hdr", ".", "subchunk2size", "*", "8", "/", "(", "hdr", ".", "numchannels", "*", "hdr", ".", "bitspersample", ")", ";", "buf", "=", "(", "short", "*", ")", "malloc", "(", "(", "length", ")", "*", "sizeof", "(", "short", ")", ")", ";", "if", "(", "!", "buf", ")", "{", "fclose", "(", "f", ")", ";", "return", "NULL", ";", "}", "fread", "(", "buf", ",", "(", "length", ")", "*", "sizeof", "(", "short", ")", ",", "1", ",", "f", ")", ";", "fclose", "(", "f", ")", ";", "data", "=", "(", "double", "*", ")", "malloc", "(", "(", "length", ")", "*", "sizeof", "(", "double", ")", ")", ";", "if", "(", "!", "data", ")", "{", "free", "(", "buf", ")", ";", "return", "NULL", ";", "}", "double", "wavbitscale", "=", "pow", "(", "2", ",", "hdr", ".", "bitspersample", ")", "/", "2", ";", "int", "i2", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "(", "*", "sampsperchan", ")", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "hdr", ".", "numchannels", ";", "j", "++", ")", "{", "if", "(", "j", "==", "0", ")", "{", "data", "[", "i", "]", "=", "(", "(", "double", ")", "buf", "[", "i2", "]", ")", "/", "wavbitscale", ";", "}", "i2", "++", ";", "}", "}", "printf", "(", "\"", "\\n", "\"", ",", "length", ",", "filename", ")", ";", "free", "(", "buf", ")", ";", "return", "data", ";", "}" ]
Will read first channel only on multichannel files <#Description#>
[ "Will", "read", "first", "channel", "only", "on", "multichannel", "files", "<#Description#", ">" ]
[ "/* quick sanity check */", "/* check correct format */", "// Dividing by this will scale a .wav to between -1 and 1" ]
[ { "param": "filename", "type": "char" }, { "param": "sampsperchan", "type": "int" }, { "param": "sampleRate", "type": "int" } ]
{ "returns": [ { "docstring": "<#return value description#>", "docstring_tokens": [ "<#return", "value", "description#", ">" ], "type": null } ], "raises": [], "params": [ { "identifier": "filename", "type": "char", "docstring": null, "docstring_tokens": [ "None" ], "default": null, "is_optional": null }, { "identifier": "sampsperchan", "type": "int", "docstring": null, "docstring_tokens": [ "None" ], "default": null, "is_optional": null }, { "identifier": "sampleRate", "type": "int", "docstring": null, "docstring_tokens": [ "None" ], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
outgoingTestProcessor
void
void * outgoingTestProcessor(HANDLER_PTR handler, void * out) { static uint8_t processorIndex = 0; ECHOFRAME_PTR outgoing = (ECHOFRAME_PTR) out; //store it in opt ECHOFRAME_PTR * frames = (ECHOFRAME_PTR *) &handler->opt; if (frames[processorIndex] != NULL) { free(frames[processorIndex]); } frames[processorIndex] = outgoing; processorIndex = (processorIndex + 1) % 8; return 0; }
/** * This was an outgoing processor used instead of sending a packet out * on the network. Helped for basic testing. */
This was an outgoing processor used instead of sending a packet out on the network. Helped for basic testing.
[ "This", "was", "an", "outgoing", "processor", "used", "instead", "of", "sending", "a", "packet", "out", "on", "the", "network", ".", "Helped", "for", "basic", "testing", "." ]
void * outgoingTestProcessor(HANDLER_PTR handler, void * out) { static uint8_t processorIndex = 0; ECHOFRAME_PTR outgoing = (ECHOFRAME_PTR) out; ECHOFRAME_PTR * frames = (ECHOFRAME_PTR *) &handler->opt; if (frames[processorIndex] != NULL) { free(frames[processorIndex]); } frames[processorIndex] = outgoing; processorIndex = (processorIndex + 1) % 8; return 0; }
[ "void", "*", "outgoingTestProcessor", "(", "HANDLER_PTR", "handler", ",", "void", "*", "out", ")", "{", "static", "uint8_t", "processorIndex", "=", "0", ";", "ECHOFRAME_PTR", "outgoing", "=", "(", "ECHOFRAME_PTR", ")", "out", ";", "ECHOFRAME_PTR", "*", "frames", "=", "(", "ECHOFRAME_PTR", "*", ")", "&", "handler", "->", "opt", ";", "if", "(", "frames", "[", "processorIndex", "]", "!=", "NULL", ")", "{", "free", "(", "frames", "[", "processorIndex", "]", ")", ";", "}", "frames", "[", "processorIndex", "]", "=", "outgoing", ";", "processorIndex", "=", "(", "processorIndex", "+", "1", ")", "%", "8", ";", "return", "0", ";", "}" ]
This was an outgoing processor used instead of sending a packet out on the network.
[ "This", "was", "an", "outgoing", "processor", "used", "instead", "of", "sending", "a", "packet", "out", "on", "the", "network", "." ]
[ "//store it in opt" ]
[ { "param": "handler", "type": "HANDLER_PTR" }, { "param": "out", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "handler", "type": "HANDLER_PTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "out", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
runTestsTask
void
void runTestsTask(void * params) { PPRINTF("running tests... \n"); char * result = allTests(); if (result != 0) { PPRINTF("%s\n", result); } else { PPRINTF("ALL TESTS PASSED."); } //genuinely WTF: //if this task returns the system crashes. //so... sleep forever! while (1) { vTaskDelay(portMAX_DELAY); } }
/** * the main test task. if you want to enable tests again, create a task * that has this function as its entry point. */
the main test task. if you want to enable tests again, create a task that has this function as its entry point.
[ "the", "main", "test", "task", ".", "if", "you", "want", "to", "enable", "tests", "again", "create", "a", "task", "that", "has", "this", "function", "as", "its", "entry", "point", "." ]
void runTestsTask(void * params) { PPRINTF("running tests... \n"); char * result = allTests(); if (result != 0) { PPRINTF("%s\n", result); } else { PPRINTF("ALL TESTS PASSED."); } while (1) { vTaskDelay(portMAX_DELAY); } }
[ "void", "runTestsTask", "(", "void", "*", "params", ")", "{", "PPRINTF", "(", "\"", "\\n", "\"", ")", ";", "char", "*", "result", "=", "allTests", "(", ")", ";", "if", "(", "result", "!=", "0", ")", "{", "PPRINTF", "(", "\"", "\\n", "\"", ",", "result", ")", ";", "}", "else", "{", "PPRINTF", "(", "\"", "\"", ")", ";", "}", "while", "(", "1", ")", "{", "vTaskDelay", "(", "portMAX_DELAY", ")", ";", "}", "}" ]
the main test task.
[ "the", "main", "test", "task", "." ]
[ "//genuinely WTF:", "//if this task returns the system crashes.", "//so... sleep forever!" ]
[ { "param": "params", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "params", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
createDebugSocket
int
int createDebugSocket() { int dsock = socket(AF_INET, SOCK_STREAM, 0); if (dsock < 0) { return dsock; } struct sockaddr_in saddr; memset(&saddr, 0, sizeof(struct sockaddr_in)); saddr.sin_addr.s_addr = INADDR_ANY; saddr.sin_family = AF_INET; saddr.sin_port = ntohs(6666); int res = bind(dsock, &saddr, sizeof(saddr)); PPRINTF("Bind result: %d\n", res); if (res < 0) { return res; } return dsock; }
/** * This creates the debug socket. Unfortunately, this is quite unreliable * and not a substitute for proper debugging facilities. Use this in desperate * times only, disable it through #DOWEBLOG if not needed. */
This creates the debug socket. Unfortunately, this is quite unreliable and not a substitute for proper debugging facilities. Use this in desperate times only, disable it through #DOWEBLOG if not needed.
[ "This", "creates", "the", "debug", "socket", ".", "Unfortunately", "this", "is", "quite", "unreliable", "and", "not", "a", "substitute", "for", "proper", "debugging", "facilities", ".", "Use", "this", "in", "desperate", "times", "only", "disable", "it", "through", "#DOWEBLOG", "if", "not", "needed", "." ]
int createDebugSocket() { int dsock = socket(AF_INET, SOCK_STREAM, 0); if (dsock < 0) { return dsock; } struct sockaddr_in saddr; memset(&saddr, 0, sizeof(struct sockaddr_in)); saddr.sin_addr.s_addr = INADDR_ANY; saddr.sin_family = AF_INET; saddr.sin_port = ntohs(6666); int res = bind(dsock, &saddr, sizeof(saddr)); PPRINTF("Bind result: %d\n", res); if (res < 0) { return res; } return dsock; }
[ "int", "createDebugSocket", "(", ")", "{", "int", "dsock", "=", "socket", "(", "AF_INET", ",", "SOCK_STREAM", ",", "0", ")", ";", "if", "(", "dsock", "<", "0", ")", "{", "return", "dsock", ";", "}", "struct", "sockaddr_in", "saddr", ";", "memset", "(", "&", "saddr", ",", "0", ",", "sizeof", "(", "struct", "sockaddr_in", ")", ")", ";", "saddr", ".", "sin_addr", ".", "s_addr", "=", "INADDR_ANY", ";", "saddr", ".", "sin_family", "=", "AF_INET", ";", "saddr", ".", "sin_port", "=", "ntohs", "(", "6666", ")", ";", "int", "res", "=", "bind", "(", "dsock", ",", "&", "saddr", ",", "sizeof", "(", "saddr", ")", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "res", ")", ";", "if", "(", "res", "<", "0", ")", "{", "return", "res", ";", "}", "return", "dsock", ";", "}" ]
This creates the debug socket.
[ "This", "creates", "the", "debug", "socket", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
createMulticastSocket
int
int createMulticastSocket() { //create socket int msock = socket(AF_INET, SOCK_DGRAM, 0); PPRINTF("socket FD: %d\n", msock); if (msock < 0) { return msock; } //get local if address struct ip_info pinfo; int res = sdk_wifi_get_ip_info(0, &pinfo); PPRINTF("get_ip_info result: %d\n", res); PPRINTF("ip address: %s\n", ip_ntoa(&pinfo.ip)); PPRINTF("gateway: %s\n", ip_ntoa(&pinfo.gw)); int optlen = 8; struct ip_addr dummy; IP4_ADDR(&dummy, 224, 0, 23, 0); /*********BIND ********/ struct sockaddr_in lsaddr; memset(&lsaddr, 0, sizeof(lsaddr)); lsaddr.sin_addr.s_addr = pinfo.ip.addr; lsaddr.sin_family = AF_INET; lsaddr.sin_port = ntohs(ELITE_PORT); res = bind(msock, &lsaddr, sizeof(lsaddr)); PPRINTF("Bind result: %d\n"); /*********MULTICAST*************/ struct ip_mreq ipmreq; ipmreq.imr_multiaddr.s_addr = dummy.addr; ipmreq.imr_interface.s_addr = pinfo.ip.addr; res = setsockopt(msock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipmreq, sizeof(ipmreq)); PPRINTF("multicast setsockopt result: %d\n", res); return msock; }
/** * Creates the multicast socket that will be used for echonet lite purposes */
Creates the multicast socket that will be used for echonet lite purposes
[ "Creates", "the", "multicast", "socket", "that", "will", "be", "used", "for", "echonet", "lite", "purposes" ]
int createMulticastSocket() { int msock = socket(AF_INET, SOCK_DGRAM, 0); PPRINTF("socket FD: %d\n", msock); if (msock < 0) { return msock; } struct ip_info pinfo; int res = sdk_wifi_get_ip_info(0, &pinfo); PPRINTF("get_ip_info result: %d\n", res); PPRINTF("ip address: %s\n", ip_ntoa(&pinfo.ip)); PPRINTF("gateway: %s\n", ip_ntoa(&pinfo.gw)); int optlen = 8; struct ip_addr dummy; IP4_ADDR(&dummy, 224, 0, 23, 0); struct sockaddr_in lsaddr; memset(&lsaddr, 0, sizeof(lsaddr)); lsaddr.sin_addr.s_addr = pinfo.ip.addr; lsaddr.sin_family = AF_INET; lsaddr.sin_port = ntohs(ELITE_PORT); res = bind(msock, &lsaddr, sizeof(lsaddr)); PPRINTF("Bind result: %d\n"); struct ip_mreq ipmreq; ipmreq.imr_multiaddr.s_addr = dummy.addr; ipmreq.imr_interface.s_addr = pinfo.ip.addr; res = setsockopt(msock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipmreq, sizeof(ipmreq)); PPRINTF("multicast setsockopt result: %d\n", res); return msock; }
[ "int", "createMulticastSocket", "(", ")", "{", "int", "msock", "=", "socket", "(", "AF_INET", ",", "SOCK_DGRAM", ",", "0", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "msock", ")", ";", "if", "(", "msock", "<", "0", ")", "{", "return", "msock", ";", "}", "struct", "ip_info", "pinfo", ";", "int", "res", "=", "sdk_wifi_get_ip_info", "(", "0", ",", "&", "pinfo", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "res", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "ip_ntoa", "(", "&", "pinfo", ".", "ip", ")", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "ip_ntoa", "(", "&", "pinfo", ".", "gw", ")", ")", ";", "int", "optlen", "=", "8", ";", "struct", "ip_addr", "dummy", ";", "IP4_ADDR", "(", "&", "dummy", ",", "224", ",", "0", ",", "23", ",", "0", ")", ";", "struct", "sockaddr_in", "lsaddr", ";", "memset", "(", "&", "lsaddr", ",", "0", ",", "sizeof", "(", "lsaddr", ")", ")", ";", "lsaddr", ".", "sin_addr", ".", "s_addr", "=", "pinfo", ".", "ip", ".", "addr", ";", "lsaddr", ".", "sin_family", "=", "AF_INET", ";", "lsaddr", ".", "sin_port", "=", "ntohs", "(", "ELITE_PORT", ")", ";", "res", "=", "bind", "(", "msock", ",", "&", "lsaddr", ",", "sizeof", "(", "lsaddr", ")", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ")", ";", "struct", "ip_mreq", "ipmreq", ";", "ipmreq", ".", "imr_multiaddr", ".", "s_addr", "=", "dummy", ".", "addr", ";", "ipmreq", ".", "imr_interface", ".", "s_addr", "=", "pinfo", ".", "ip", ".", "addr", ";", "res", "=", "setsockopt", "(", "msock", ",", "IPPROTO_IP", ",", "IP_ADD_MEMBERSHIP", ",", "&", "ipmreq", ",", "sizeof", "(", "ipmreq", ")", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "res", ")", ";", "return", "msock", ";", "}" ]
Creates the multicast socket that will be used for echonet lite purposes
[ "Creates", "the", "multicast", "socket", "that", "will", "be", "used", "for", "echonet", "lite", "purposes" ]
[ "//create socket", "//get local if address", "/*********BIND ********/", "/*********MULTICAST*************/" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
eliteTask
void
void eliteTask(void) { printf("wireless start\n"); setupWirelessIF(); printf("wireless end\n"); printf("Sleeping for 5...\n"); xTaskCreate(netDebugTask, (signed char *) "netDebugTask", 256, NULL, 4, NULL); vTaskDelay(5000 / portTICK_PERIOD_MS); PPRINTF("sdk version:%s\n", sdk_system_get_sdk_version()); // xTaskCreate(runTestsTask, (signed char * )"runTestsTask", 512, NULL, 1, // NULL); int msock = createMulticastSocket(); //setup our control struct. PPRINTF("Echonet startup."); ECHOCTRL_PTR ectrl = createEchonetControl(); ectrl->msock = msock; //setup middlewareAdapter PPRINTF("madapter init"); setupUART(); MADAPTER_PTR adapter = createMiddlewareAdapter(stdin, stdout); setContext(adapter, ectrl); PPRINTF("madapter set context"); PPRINTF("receiver task"); startReceiverTask(adapter); setupObjects(ectrl, adapter); Property_PTR wakeupcall = getProperty(getObject(ectrl->oHead, PROFILEEOJ), 0xD5); for (int i = 0; i < 3; i++) { makeNotification(wakeupcall); } receiveLoop(ectrl); }
/** * entry point for the main task. Activities happening here: * 1: setup the wireless network * 2: create the debug task (comment this out here if you need, but also * dont forget #DOWEBLOG * 3: (optional) run tests * 4: initialize the multicast socket. * 5: setup the middleware adapter (tricky, initialize all members appropriately) * 6: start adapter receiver task * 7: setup all objects. * 8: perform startup notifications * 9: enter main receiver loop. * * Each step must happen for things to work correctly. However, the order of * some of the steps can be slightly changed. Pay attention to any field * initialization that didn't get handled internaly neatly in some function, * because you will have to reproduce it in your code. * * \todo refactor this? */
entry point for the main task. Each step must happen for things to work correctly. However, the order of some of the steps can be slightly changed. Pay attention to any field initialization that didn't get handled internaly neatly in some function, because you will have to reproduce it in your code.
[ "entry", "point", "for", "the", "main", "task", ".", "Each", "step", "must", "happen", "for", "things", "to", "work", "correctly", ".", "However", "the", "order", "of", "some", "of", "the", "steps", "can", "be", "slightly", "changed", ".", "Pay", "attention", "to", "any", "field", "initialization", "that", "didn", "'", "t", "get", "handled", "internaly", "neatly", "in", "some", "function", "because", "you", "will", "have", "to", "reproduce", "it", "in", "your", "code", "." ]
void eliteTask(void) { printf("wireless start\n"); setupWirelessIF(); printf("wireless end\n"); printf("Sleeping for 5...\n"); xTaskCreate(netDebugTask, (signed char *) "netDebugTask", 256, NULL, 4, NULL); vTaskDelay(5000 / portTICK_PERIOD_MS); PPRINTF("sdk version:%s\n", sdk_system_get_sdk_version()); int msock = createMulticastSocket(); PPRINTF("Echonet startup."); ECHOCTRL_PTR ectrl = createEchonetControl(); ectrl->msock = msock; PPRINTF("madapter init"); setupUART(); MADAPTER_PTR adapter = createMiddlewareAdapter(stdin, stdout); setContext(adapter, ectrl); PPRINTF("madapter set context"); PPRINTF("receiver task"); startReceiverTask(adapter); setupObjects(ectrl, adapter); Property_PTR wakeupcall = getProperty(getObject(ectrl->oHead, PROFILEEOJ), 0xD5); for (int i = 0; i < 3; i++) { makeNotification(wakeupcall); } receiveLoop(ectrl); }
[ "void", "eliteTask", "(", "void", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "setupWirelessIF", "(", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "xTaskCreate", "(", "netDebugTask", ",", "(", "signed", "char", "*", ")", "\"", "\"", ",", "256", ",", "NULL", ",", "4", ",", "NULL", ")", ";", "vTaskDelay", "(", "5000", "/", "portTICK_PERIOD_MS", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "sdk_system_get_sdk_version", "(", ")", ")", ";", "int", "msock", "=", "createMulticastSocket", "(", ")", ";", "PPRINTF", "(", "\"", "\"", ")", ";", "ECHOCTRL_PTR", "ectrl", "=", "createEchonetControl", "(", ")", ";", "ectrl", "->", "msock", "=", "msock", ";", "PPRINTF", "(", "\"", "\"", ")", ";", "setupUART", "(", ")", ";", "MADAPTER_PTR", "adapter", "=", "createMiddlewareAdapter", "(", "stdin", ",", "stdout", ")", ";", "setContext", "(", "adapter", ",", "ectrl", ")", ";", "PPRINTF", "(", "\"", "\"", ")", ";", "PPRINTF", "(", "\"", "\"", ")", ";", "startReceiverTask", "(", "adapter", ")", ";", "setupObjects", "(", "ectrl", ",", "adapter", ")", ";", "Property_PTR", "wakeupcall", "=", "getProperty", "(", "getObject", "(", "ectrl", "->", "oHead", ",", "PROFILEEOJ", ")", ",", "0xD5", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "3", ";", "i", "++", ")", "{", "makeNotification", "(", "wakeupcall", ")", ";", "}", "receiveLoop", "(", "ectrl", ")", ";", "}" ]
entry point for the main task.
[ "entry", "point", "for", "the", "main", "task", "." ]
[ "//\txTaskCreate(runTestsTask, (signed char * )\"runTestsTask\", 512, NULL, 1,", "//\t\t\tNULL);", "//setup our control struct.", "//setup middlewareAdapter" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
netDebugTask
void
void netDebugTask(void) { int sock = createDebugSocket(); if (sock < 0) { PPRINTF("netDebugTask: failed to setup debug port. Exit.\n"); return; } int res = listen(sock, 1); if (res < 0) { PPRINTF("netDebugTask: listen failed. Exit.\n"); return; } //time to setup our semaphores vSemaphoreCreateBinary(debugdowrite); vSemaphoreCreateBinary(debugsem); if (debugsem == NULL) { PPRINTF("debug mutex creation fail\n"); } else { PPRINTF("debug mutex creation success\n"); } struct sockaddr_in clientaddr; socklen_t size = sizeof(clientaddr); memset(&clientaddr, 0, size); static char greeting[] = "Hello, hope this helps!\n"; do { int clientfd = accept(sock, &clientaddr, &size); write(clientfd, greeting, sizeof(greeting)); int writeres = 0; while (writeres >= 0) { //sleep forever xSemaphoreTake(debugsem, portMAX_DELAY); writeres = write(clientfd, ndbuf, ndsize); } close(clientfd); } while (1); }
/** * the net debug task that performs the actual web logging. Uses semaphores * to coordinate with other tasks that call #WEBLOG. two semaphores are * necessary at least. Have a look at #WEBLOG to understand the interaction * through semaphores. */
the net debug task that performs the actual web logging. Uses semaphores to coordinate with other tasks that call #WEBLOG. two semaphores are necessary at least. Have a look at #WEBLOG to understand the interaction through semaphores.
[ "the", "net", "debug", "task", "that", "performs", "the", "actual", "web", "logging", ".", "Uses", "semaphores", "to", "coordinate", "with", "other", "tasks", "that", "call", "#WEBLOG", ".", "two", "semaphores", "are", "necessary", "at", "least", ".", "Have", "a", "look", "at", "#WEBLOG", "to", "understand", "the", "interaction", "through", "semaphores", "." ]
void netDebugTask(void) { int sock = createDebugSocket(); if (sock < 0) { PPRINTF("netDebugTask: failed to setup debug port. Exit.\n"); return; } int res = listen(sock, 1); if (res < 0) { PPRINTF("netDebugTask: listen failed. Exit.\n"); return; } vSemaphoreCreateBinary(debugdowrite); vSemaphoreCreateBinary(debugsem); if (debugsem == NULL) { PPRINTF("debug mutex creation fail\n"); } else { PPRINTF("debug mutex creation success\n"); } struct sockaddr_in clientaddr; socklen_t size = sizeof(clientaddr); memset(&clientaddr, 0, size); static char greeting[] = "Hello, hope this helps!\n"; do { int clientfd = accept(sock, &clientaddr, &size); write(clientfd, greeting, sizeof(greeting)); int writeres = 0; while (writeres >= 0) { xSemaphoreTake(debugsem, portMAX_DELAY); writeres = write(clientfd, ndbuf, ndsize); } close(clientfd); } while (1); }
[ "void", "netDebugTask", "(", "void", ")", "{", "int", "sock", "=", "createDebugSocket", "(", ")", ";", "if", "(", "sock", "<", "0", ")", "{", "PPRINTF", "(", "\"", "\\n", "\"", ")", ";", "return", ";", "}", "int", "res", "=", "listen", "(", "sock", ",", "1", ")", ";", "if", "(", "res", "<", "0", ")", "{", "PPRINTF", "(", "\"", "\\n", "\"", ")", ";", "return", ";", "}", "vSemaphoreCreateBinary", "(", "debugdowrite", ")", ";", "vSemaphoreCreateBinary", "(", "debugsem", ")", ";", "if", "(", "debugsem", "==", "NULL", ")", "{", "PPRINTF", "(", "\"", "\\n", "\"", ")", ";", "}", "else", "{", "PPRINTF", "(", "\"", "\\n", "\"", ")", ";", "}", "struct", "sockaddr_in", "clientaddr", ";", "socklen_t", "size", "=", "sizeof", "(", "clientaddr", ")", ";", "memset", "(", "&", "clientaddr", ",", "0", ",", "size", ")", ";", "static", "char", "greeting", "[", "]", "=", "\"", "\\n", "\"", ";", "do", "{", "int", "clientfd", "=", "accept", "(", "sock", ",", "&", "clientaddr", ",", "&", "size", ")", ";", "write", "(", "clientfd", ",", "greeting", ",", "sizeof", "(", "greeting", ")", ")", ";", "int", "writeres", "=", "0", ";", "while", "(", "writeres", ">=", "0", ")", "{", "xSemaphoreTake", "(", "debugsem", ",", "portMAX_DELAY", ")", ";", "writeres", "=", "write", "(", "clientfd", ",", "ndbuf", ",", "ndsize", ")", ";", "}", "close", "(", "clientfd", ")", ";", "}", "while", "(", "1", ")", ";", "}" ]
the net debug task that performs the actual web logging.
[ "the", "net", "debug", "task", "that", "performs", "the", "actual", "web", "logging", "." ]
[ "//time to setup our semaphores", "//sleep forever" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
testPeriodic
void
void testPeriodic(void) { int i = 0; while (1) { vTaskDelay(300 / portTICK_PERIOD_MS); PPRINTF("looping... %d\n", ++i); } }
/* * a periodic task. Strictly speaking unnecessary but provides a sense of time * disable this for release */
a periodic task. Strictly speaking unnecessary but provides a sense of time disable this for release
[ "a", "periodic", "task", ".", "Strictly", "speaking", "unnecessary", "but", "provides", "a", "sense", "of", "time", "disable", "this", "for", "release" ]
void testPeriodic(void) { int i = 0; while (1) { vTaskDelay(300 / portTICK_PERIOD_MS); PPRINTF("looping... %d\n", ++i); } }
[ "void", "testPeriodic", "(", "void", ")", "{", "int", "i", "=", "0", ";", "while", "(", "1", ")", "{", "vTaskDelay", "(", "300", "/", "portTICK_PERIOD_MS", ")", ";", "PPRINTF", "(", "\"", "\\n", "\"", ",", "++", "i", ")", ";", "}", "}" ]
a periodic task.
[ "a", "periodic", "task", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c145b43e44dec4929b484febf8a78efeb661c520
s-marios/elite
esp8266/main.c
[ "BSD-2-Clause" ]
C
user_init
void
void user_init(void) { uart_set_baud(0, 9600); //gdbstub_init(); debugsem = NULL; debugdowrite = NULL; // printf("portTICK_PERIOD_MS: %d\n", portTICK_PERIOD_MS); // printf("gief input\n"); // static char test[16]; // int res = setvbuf(stdin, freadbuf, _IONBF, 512); // for (int i = 0; i < 15; i++) { // char get = getc(stdin); // printf("char get: %c\n", get); // } // fwrite("test\n", 1, 5, stdout); //printf("fread test\n"); //this crashes //fread(test, 1, 15, stdin); //fread_unlocked(test, 1, 15, stdin); //printf("test input: %s\n", test); //main task xTaskCreate(eliteTask, (signed char *) "eliteTask", 1024, NULL, 1, NULL); //periodic looping task, comment this out if you don't need it. xTaskCreate(testPeriodic, (signed char *) "testPeriodic", 256, NULL, 1, NULL); }
//static char freadbuf[512]; /** * entry point for our code. Setup baudrate * init the semaphore pointers and startup tasks. */
static char freadbuf[512]; entry point for our code. Setup baudrate init the semaphore pointers and startup tasks.
[ "static", "char", "freadbuf", "[", "512", "]", ";", "entry", "point", "for", "our", "code", ".", "Setup", "baudrate", "init", "the", "semaphore", "pointers", "and", "startup", "tasks", "." ]
void user_init(void) { uart_set_baud(0, 9600); debugsem = NULL; debugdowrite = NULL; xTaskCreate(eliteTask, (signed char *) "eliteTask", 1024, NULL, 1, NULL); xTaskCreate(testPeriodic, (signed char *) "testPeriodic", 256, NULL, 1, NULL); }
[ "void", "user_init", "(", "void", ")", "{", "uart_set_baud", "(", "0", ",", "9600", ")", ";", "debugsem", "=", "NULL", ";", "debugdowrite", "=", "NULL", ";", "xTaskCreate", "(", "eliteTask", ",", "(", "signed", "char", "*", ")", "\"", "\"", ",", "1024", ",", "NULL", ",", "1", ",", "NULL", ")", ";", "xTaskCreate", "(", "testPeriodic", ",", "(", "signed", "char", "*", ")", "\"", "\"", ",", "256", ",", "NULL", ",", "1", ",", "NULL", ")", ";", "}" ]
static char freadbuf[512]; entry point for our code.
[ "static", "char", "freadbuf", "[", "512", "]", ";", "entry", "point", "for", "our", "code", "." ]
[ "//gdbstub_init();", "//\tprintf(\"portTICK_PERIOD_MS: %d\\n\", portTICK_PERIOD_MS);", "//\tprintf(\"gief input\\n\");", "//\tstatic char test[16];", "//\tint res = setvbuf(stdin, freadbuf, _IONBF, 512);", "//\tfor (int i = 0; i < 15; i++) {", "//\tchar get = getc(stdin);", "//\tprintf(\"char get: %c\\n\", get);", "//\t}", "//\tfwrite(\"test\\n\", 1, 5, stdout);", "//printf(\"fread test\\n\");", "//this crashes", "//fread(test, 1, 15, stdin);", "//fread_unlocked(test, 1, 15, stdin);", "//printf(\"test input: %s\\n\", test);", "//main task", "//periodic looping task, comment this out if you don't need it." ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
40462f15fe038f4c5c51b84d6487ddcf41604521
s-marios/elite
elite.c
[ "BSD-2-Clause" ]
C
readProperty
int
int readProperty(Property_PTR property, uint8_t size, unsigned char *buf) { if (property == NULL || property->readf == NULL) { return -1; } else if (buf == NULL) { return -2; } else { return property->readf(property, size, buf); } }
/** * return bytes read, zero or less in failure */
return bytes read, zero or less in failure
[ "return", "bytes", "read", "zero", "or", "less", "in", "failure" ]
int readProperty(Property_PTR property, uint8_t size, unsigned char *buf) { if (property == NULL || property->readf == NULL) { return -1; } else if (buf == NULL) { return -2; } else { return property->readf(property, size, buf); } }
[ "int", "readProperty", "(", "Property_PTR", "property", ",", "uint8_t", "size", ",", "unsigned", "char", "*", "buf", ")", "{", "if", "(", "property", "==", "NULL", "||", "property", "->", "readf", "==", "NULL", ")", "{", "return", "-1", ";", "}", "else", "if", "(", "buf", "==", "NULL", ")", "{", "return", "-2", ";", "}", "else", "{", "return", "property", "->", "readf", "(", "property", ",", "size", ",", "buf", ")", ";", "}", "}" ]
return bytes read, zero or less in failure
[ "return", "bytes", "read", "zero", "or", "less", "in", "failure" ]
[]
[ { "param": "property", "type": "Property_PTR" }, { "param": "size", "type": "uint8_t" }, { "param": "buf", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "property", "type": "Property_PTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40462f15fe038f4c5c51b84d6487ddcf41604521
s-marios/elite
elite.c
[ "BSD-2-Clause" ]
C
writeProperty
int
int writeProperty(Property_PTR property, uint8_t size, const unsigned char *buf) { if (property == NULL || property->writef == NULL) { return -1; } else if (buf == NULL) { return -2; } else { //Do we need notifications? int doNotify = 0; if (property->rwn_mode & E_NOTIFY) { if (property->rwn_mode & E_SUPPRESS_NOTIFY) { doNotify = requiresNotification(property, size, buf); } else { doNotify = 1; } } //write int result = property->writef(property, size, buf); //perform notification if necessary. if (result > 0 && doNotify) { makeNotification(property); } return result; } }
/** * return bytes written, zero or less on failure */
return bytes written, zero or less on failure
[ "return", "bytes", "written", "zero", "or", "less", "on", "failure" ]
int writeProperty(Property_PTR property, uint8_t size, const unsigned char *buf) { if (property == NULL || property->writef == NULL) { return -1; } else if (buf == NULL) { return -2; } else { int doNotify = 0; if (property->rwn_mode & E_NOTIFY) { if (property->rwn_mode & E_SUPPRESS_NOTIFY) { doNotify = requiresNotification(property, size, buf); } else { doNotify = 1; } } int result = property->writef(property, size, buf); if (result > 0 && doNotify) { makeNotification(property); } return result; } }
[ "int", "writeProperty", "(", "Property_PTR", "property", ",", "uint8_t", "size", ",", "const", "unsigned", "char", "*", "buf", ")", "{", "if", "(", "property", "==", "NULL", "||", "property", "->", "writef", "==", "NULL", ")", "{", "return", "-1", ";", "}", "else", "if", "(", "buf", "==", "NULL", ")", "{", "return", "-2", ";", "}", "else", "{", "int", "doNotify", "=", "0", ";", "if", "(", "property", "->", "rwn_mode", "&", "E_NOTIFY", ")", "{", "if", "(", "property", "->", "rwn_mode", "&", "E_SUPPRESS_NOTIFY", ")", "{", "doNotify", "=", "requiresNotification", "(", "property", ",", "size", ",", "buf", ")", ";", "}", "else", "{", "doNotify", "=", "1", ";", "}", "}", "int", "result", "=", "property", "->", "writef", "(", "property", ",", "size", ",", "buf", ")", ";", "if", "(", "result", ">", "0", "&&", "doNotify", ")", "{", "makeNotification", "(", "property", ")", ";", "}", "return", "result", ";", "}", "}" ]
return bytes written, zero or less on failure
[ "return", "bytes", "written", "zero", "or", "less", "on", "failure" ]
[ "//Do we need notifications?", "//write", "//perform notification if necessary." ]
[ { "param": "property", "type": "Property_PTR" }, { "param": "size", "type": "uint8_t" }, { "param": "buf", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "property", "type": "Property_PTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40462f15fe038f4c5c51b84d6487ddcf41604521
s-marios/elite
elite.c
[ "BSD-2-Clause" ]
C
readData
int
int readData(Property_PTR property, uint8_t size, unsigned char *buf) { DATABUFFER_PTR databuffer = (DATABUFFER_PTR) property->opt; if (databuffer->used > size) { return 0; } else { memcpy(buf, &databuffer->data, databuffer->used); return databuffer->used; } }
//read function for a "data property"
read function for a "data property"
[ "read", "function", "for", "a", "\"", "data", "property", "\"" ]
int readData(Property_PTR property, uint8_t size, unsigned char *buf) { DATABUFFER_PTR databuffer = (DATABUFFER_PTR) property->opt; if (databuffer->used > size) { return 0; } else { memcpy(buf, &databuffer->data, databuffer->used); return databuffer->used; } }
[ "int", "readData", "(", "Property_PTR", "property", ",", "uint8_t", "size", ",", "unsigned", "char", "*", "buf", ")", "{", "DATABUFFER_PTR", "databuffer", "=", "(", "DATABUFFER_PTR", ")", "property", "->", "opt", ";", "if", "(", "databuffer", "->", "used", ">", "size", ")", "{", "return", "0", ";", "}", "else", "{", "memcpy", "(", "buf", ",", "&", "databuffer", "->", "data", ",", "databuffer", "->", "used", ")", ";", "return", "databuffer", "->", "used", ";", "}", "}" ]
read function for a "data property"
[ "read", "function", "for", "a", "\"", "data", "property", "\"" ]
[]
[ { "param": "property", "type": "Property_PTR" }, { "param": "size", "type": "uint8_t" }, { "param": "buf", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "property", "type": "Property_PTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40462f15fe038f4c5c51b84d6487ddcf41604521
s-marios/elite
elite.c
[ "BSD-2-Clause" ]
C
writeData
int
int writeData(Property_PTR property, uint8_t size, const unsigned char *buf) { DATABUFFER_PTR databuffer = (DATABUFFER_PTR) property->opt; if (size > databuffer->maxsize) { return 0; } else { memcpy(&databuffer->data, buf, size); databuffer->used = size; return size; } }
//write function for a "data property"
write function for a "data property"
[ "write", "function", "for", "a", "\"", "data", "property", "\"" ]
int writeData(Property_PTR property, uint8_t size, const unsigned char *buf) { DATABUFFER_PTR databuffer = (DATABUFFER_PTR) property->opt; if (size > databuffer->maxsize) { return 0; } else { memcpy(&databuffer->data, buf, size); databuffer->used = size; return size; } }
[ "int", "writeData", "(", "Property_PTR", "property", ",", "uint8_t", "size", ",", "const", "unsigned", "char", "*", "buf", ")", "{", "DATABUFFER_PTR", "databuffer", "=", "(", "DATABUFFER_PTR", ")", "property", "->", "opt", ";", "if", "(", "size", ">", "databuffer", "->", "maxsize", ")", "{", "return", "0", ";", "}", "else", "{", "memcpy", "(", "&", "databuffer", "->", "data", ",", "buf", ",", "size", ")", ";", "databuffer", "->", "used", "=", "size", ";", "return", "size", ";", "}", "}" ]
write function for a "data property"
[ "write", "function", "for", "a", "\"", "data", "property", "\"" ]
[]
[ { "param": "property", "type": "Property_PTR" }, { "param": "size", "type": "uint8_t" }, { "param": "buf", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "property", "type": "Property_PTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40462f15fe038f4c5c51b84d6487ddcf41604521
s-marios/elite
elite.c
[ "BSD-2-Clause" ]
C
flipPropertyBit
void
void flipPropertyBit(uint8_t code, char *pbitmap) { //high nibble specifies the bit to flip through shifting //low nibble is the byte in which to flip uint8_t highnibble, lownibble; //zero-th byte is property count lownibble = (code & 0x0F) + 1; highnibble = code >> 4; //also subtract 0x08 from highnibble highnibble -= 0x08; //flip the bit pbitmap[lownibble] |= 0x01 << highnibble; }
/** * Flips the corresponding bit in the property bit map. * * This is used in type-2 (binary) property map format. * * param code the property code * param pbitmap the property bitmap to be manipulated */
Flips the corresponding bit in the property bit map. This is used in type-2 (binary) property map format. param code the property code param pbitmap the property bitmap to be manipulated
[ "Flips", "the", "corresponding", "bit", "in", "the", "property", "bit", "map", ".", "This", "is", "used", "in", "type", "-", "2", "(", "binary", ")", "property", "map", "format", ".", "param", "code", "the", "property", "code", "param", "pbitmap", "the", "property", "bitmap", "to", "be", "manipulated" ]
void flipPropertyBit(uint8_t code, char *pbitmap) { uint8_t highnibble, lownibble; lownibble = (code & 0x0F) + 1; highnibble = code >> 4; highnibble -= 0x08; pbitmap[lownibble] |= 0x01 << highnibble; }
[ "void", "flipPropertyBit", "(", "uint8_t", "code", ",", "char", "*", "pbitmap", ")", "{", "uint8_t", "highnibble", ",", "lownibble", ";", "lownibble", "=", "(", "code", "&", "0x0F", ")", "+", "1", ";", "highnibble", "=", "code", ">>", "4", ";", "highnibble", "-=", "0x08", ";", "pbitmap", "[", "lownibble", "]", "|=", "0x01", "<<", "highnibble", ";", "}" ]
Flips the corresponding bit in the property bit map.
[ "Flips", "the", "corresponding", "bit", "in", "the", "property", "bit", "map", "." ]
[ "//high nibble specifies the bit to flip through shifting", "//low nibble is the byte in which to flip", "//zero-th byte is property count", "//also subtract 0x08 from highnibble", "//flip the bit" ]
[ { "param": "code", "type": "uint8_t" }, { "param": "pbitmap", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "code", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pbitmap", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40462f15fe038f4c5c51b84d6487ddcf41604521
s-marios/elite
elite.c
[ "BSD-2-Clause" ]
C
computeClasses
int
int computeClasses(OBJ_PTR oHead, unsigned char *result) { if (result == NULL || oHead == NULL) { return -1; } memset(result, 0, 17); FOREACH(oHead, OBJ_PTR) { if (!isClassPresent(result, element->eoj)) { if (result[0] >= 8) { PPRINTF( "compute classes: out of class list \ space, ignoring class...\r\n"); } else { //check for node profile (exclude) if (CMPEOJ(element->eoj, PROFILEEOJ)) { //copy that unique class in the result buffer. memcpy(&result[1 + result[0] * 2], element->eoj, 2); result[0]++; } } } } //+1 is for property d4 return result[0] + 1; }
/** * computes the number of unique classes and creates a list of them * param result the class result (exactly 17 bytes of length) * return number of classes +1 node profile */
computes the number of unique classes and creates a list of them param result the class result (exactly 17 bytes of length) return number of classes +1 node profile
[ "computes", "the", "number", "of", "unique", "classes", "and", "creates", "a", "list", "of", "them", "param", "result", "the", "class", "result", "(", "exactly", "17", "bytes", "of", "length", ")", "return", "number", "of", "classes", "+", "1", "node", "profile" ]
int computeClasses(OBJ_PTR oHead, unsigned char *result) { if (result == NULL || oHead == NULL) { return -1; } memset(result, 0, 17); FOREACH(oHead, OBJ_PTR) { if (!isClassPresent(result, element->eoj)) { if (result[0] >= 8) { PPRINTF( "compute classes: out of class list \ space, ignoring class...\r\n"); } else { if (CMPEOJ(element->eoj, PROFILEEOJ)) { memcpy(&result[1 + result[0] * 2], element->eoj, 2); result[0]++; } } } } return result[0] + 1; }
[ "int", "computeClasses", "(", "OBJ_PTR", "oHead", ",", "unsigned", "char", "*", "result", ")", "{", "if", "(", "result", "==", "NULL", "||", "oHead", "==", "NULL", ")", "{", "return", "-1", ";", "}", "memset", "(", "result", ",", "0", ",", "17", ")", ";", "FOREACH", "(", "oHead", ",", "OBJ_PTR", ")", "", "{", "if", "(", "!", "isClassPresent", "(", "result", ",", "element", "->", "eoj", ")", ")", "{", "if", "(", "result", "[", "0", "]", ">=", "8", ")", "{", "PPRINTF", "(", "\"", "\\\n", "\\r", "\\n", "\"", ")", ";", "}", "else", "{", "if", "(", "CMPEOJ", "(", "element", "->", "eoj", ",", "PROFILEEOJ", ")", ")", "{", "memcpy", "(", "&", "result", "[", "1", "+", "result", "[", "0", "]", "*", "2", "]", ",", "element", "->", "eoj", ",", "2", ")", ";", "result", "[", "0", "]", "++", ";", "}", "}", "}", "}", "return", "result", "[", "0", "]", "+", "1", ";", "}" ]
computes the number of unique classes and creates a list of them param result the class result (exactly 17 bytes of length) return number of classes +1 node profile
[ "computes", "the", "number", "of", "unique", "classes", "and", "creates", "a", "list", "of", "them", "param", "result", "the", "class", "result", "(", "exactly", "17", "bytes", "of", "length", ")", "return", "number", "of", "classes", "+", "1", "node", "profile" ]
[ "//check for node profile (exclude)", "//copy that unique class in the result buffer.", "//+1 is for property d4" ]
[ { "param": "oHead", "type": "OBJ_PTR" }, { "param": "result", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "oHead", "type": "OBJ_PTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "result", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }