void USART1_IRQHandler(void) { portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; // Code from Original ISR uint8_t ch; //if Receive interrupt if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { ch=(uint8_t)USART_ReceiveData(USART1); //put char to the buffer BufferPut(&U1Rx, ch); xSemaphoreGiveFromISR( xSerialHandlerSemaphore, & xHigherPriorityTaskWoken); } if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) { if (BufferGet(&U1Tx, &ch) == SUCCESS)//if buffer read { USART_SendData(USART1, ch); } else//if buffer empty { //disable Transmit Data Register empty interrupt USART_ITConfig(USART1, USART_IT_TXE, DISABLE); } } portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); }
uint8_t Usart3Get(void){ uint8_t ch; //check if buffer is empty while (BufferIsEmpty(U3Rx) ==SUCCESS); BufferGet(&U3Rx, &ch); return ch; }
ErrorStatus BufferPut(__IO FIFO_TypeDef *buffer, uint8_t ch) { if (buffer->count == USARTBUFFSIZE) return ERROR;//buffer full if (strncmp(&ch, "\n", 1) == 0) { int size = buffer->in - buffer->out; if (buffer->in < buffer->out) size = buffer->out - buffer->in; char comm[size + 2]; for (int i = 0; i < size; i++) { comm[i] = BufferGet(buffer); } comm[size] = '\n'; comm[size + 1] = '\0'; RXResponseBufferPut(&Response2Rx, comm); buffer->buff[buffer->in++] = ch; if (buffer->in == USARTBUFFSIZE - 1) buffer->in = 0;//start from beginning buffer->out = buffer->in; } else { buffer->buff[buffer->in++] = ch; buffer->count++; if (buffer->in == USARTBUFFSIZE - 1) buffer->in = 0;//start from beginning } return SUCCESS; }
static bool Epimenides(EvalContext *ctx, const char *ns, const char *scope, const char *var, Rval rval, int level) { switch (rval.type) { case RVAL_TYPE_SCALAR: if (StringContainsVar(RvalScalarValue(rval), var)) { Log(LOG_LEVEL_ERR, "Scalar variable '%s' contains itself (non-convergent) '%s'", var, RvalScalarValue(rval)); return true; } if (IsCf3VarString(RvalScalarValue(rval))) { Buffer *exp = BufferNew(); ExpandScalar(ctx, ns, scope, RvalScalarValue(rval), exp); if (strcmp(BufferData(exp), RvalScalarValue(rval)) == 0) { BufferDestroy(exp); return false; } if (level > 3) { BufferDestroy(exp); return false; } if (Epimenides(ctx, ns, scope, var, (Rval) { BufferGet(exp), RVAL_TYPE_SCALAR}, level + 1)) { BufferDestroy(exp); return true; } BufferDestroy(exp); } break; case RVAL_TYPE_LIST: for (const Rlist *rp = RvalRlistValue(rval); rp != NULL; rp = rp->next) { if (Epimenides(ctx, ns, scope, var, rp->val, level)) { return true; } } break; case RVAL_TYPE_CONTAINER: case RVAL_TYPE_FNCALL: case RVAL_TYPE_NOPROMISEE: return false; } return false; }
JNIEXPORT jlong JNICALL Java_com_aio4c_buffer_Buffer_getLong(JNIEnv* jvm, jobject buffer) { Buffer* _buffer = _GetBuffer(jvm, buffer); jlong _long = 0; if (!BufferGet(_buffer, &_long, sizeof(jlong))) { _ThrowBufferUnderflow(jvm, buffer); } return _long; }
static PromiseResult ExpandPromiseAndDo(EvalContext *ctx, const Promise *pp, Rlist *lists, Rlist *containers, PromiseActuator *ActOnPromise, void *param) { const char *handle = PromiseGetHandle(pp); EvalContextStackPushPromiseFrame(ctx, pp, true); PromiseIterator *iter_ctx = NULL; size_t i = 0; PromiseResult result = PROMISE_RESULT_NOOP; Buffer *expbuf = BufferNew(); for (iter_ctx = PromiseIteratorNew(ctx, pp, lists, containers); PromiseIteratorHasMore(iter_ctx); i++, PromiseIteratorNext(iter_ctx)) { if (handle) { // This ordering is necessary to get automated canonification BufferClear(expbuf); ExpandScalar(ctx, NULL, "this", handle, expbuf); CanonifyNameInPlace(BufferGet(expbuf)); EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "handle", BufferData(expbuf), CF_DATA_TYPE_STRING, "source=promise"); } else { EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "handle", PromiseID(pp), CF_DATA_TYPE_STRING, "source=promise"); } const Promise *pexp = EvalContextStackPushPromiseIterationFrame(ctx, i, iter_ctx); if (!pexp) { // excluded result = PromiseResultUpdate(result, PROMISE_RESULT_SKIPPED); continue; } PromiseResult iteration_result = ActOnPromise(ctx, pexp, param); NotifyDependantPromises(ctx, pexp, iteration_result); result = PromiseResultUpdate(result, iteration_result); if (strcmp(pp->parent_promise_type->name, "vars") == 0 || strcmp(pp->parent_promise_type->name, "meta") == 0) { VerifyVarPromise(ctx, pexp, true); } EvalContextStackPopFrame(ctx); } BufferDestroy(expbuf); PromiseIteratorDestroy(iter_ctx); EvalContextStackPopFrame(ctx); return result; }
uint8_t comm_get(void) { #ifdef BUFFERED uint8_t ch; //check if buffer is empty while (BufferIsEmpty(U1Rx) ==SUCCESS); BufferGet(&U1Rx, &ch); return ch; #else while ( USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET); return (uint8_t)USART_ReceiveData(USART1); #endif /* while(USART_GetFlagStatus(g_usart, USART_FLAG_RXNE) == RESET) { ; } return (char)USART_ReceiveData(g_usart);*/ }
/** * Expand a #string into Buffer #out, returning the pointer to the string * itself, inside the Buffer #out. If #out is NULL then the buffer will be * created and destroyed internally. * * @retval NULL something went wrong */ char *ExpandScalar(const EvalContext *ctx, const char *ns, const char *scope, const char *string, Buffer *out) { bool out_belongs_to_us = false; if (out == NULL) { out = BufferNew(); out_belongs_to_us = true; } assert(string != NULL); assert(out != NULL); Buffer *current_item = BufferNew(); for (const char *sp = string; *sp != '\0'; sp++) { BufferClear(current_item); ExtractScalarPrefix(current_item, sp, strlen(sp)); BufferAppend(out, BufferData(current_item), BufferSize(current_item)); sp += BufferSize(current_item); if (*sp == '\0') { break; } BufferClear(current_item); char varstring = sp[1]; ExtractScalarReference(current_item, sp, strlen(sp), true); sp += BufferSize(current_item) + 2; if (IsCf3VarString(BufferData(current_item))) { Buffer *temp = BufferCopy(current_item); BufferClear(current_item); ExpandScalar(ctx, ns, scope, BufferData(temp), current_item); BufferDestroy(temp); } if (!IsExpandable(BufferData(current_item))) { VarRef *ref = VarRefParseFromNamespaceAndScope( BufferData(current_item), ns, scope, CF_NS, '.'); DataType value_type; const void *value = EvalContextVariableGet(ctx, ref, &value_type); VarRefDestroy(ref); switch (DataTypeToRvalType(value_type)) { case RVAL_TYPE_SCALAR: assert(value != NULL); BufferAppendString(out, value); continue; break; case RVAL_TYPE_CONTAINER: { assert(value != NULL); const JsonElement *jvalue = value; /* instead of casts */ if (JsonGetElementType(jvalue) == JSON_ELEMENT_TYPE_PRIMITIVE) { BufferAppendString(out, JsonPrimitiveGetAsString(jvalue)); continue; } break; } default: /* TODO Log() */ break; } } if (varstring == '{') { BufferAppendF(out, "${%s}", BufferData(current_item)); } else { BufferAppendF(out, "$(%s)", BufferData(current_item)); } } BufferDestroy(current_item); LogDebug(LOG_MOD_EXPAND, "ExpandScalar( %s : %s . %s ) => %s", SAFENULL(ns), SAFENULL(scope), string, BufferData(out)); return out_belongs_to_us ? BufferClose(out) : BufferGet(out); }