int stm32_i2c_msg_read(struct device *dev, struct i2c_msg *msg, u8_t *next_msg_flags, uint16_t slave) { const struct i2c_stm32_config *cfg = DEV_CFG(dev); I2C_TypeDef *i2c = cfg->i2c; unsigned int len = 0; u8_t *buf = msg->buf; msg_init(dev, msg, next_msg_flags, slave, LL_I2C_REQUEST_READ); len = msg->len; while (len) { while (!LL_I2C_IsActiveFlag_RXNE(i2c)) { ; } *buf = LL_I2C_ReceiveData8(i2c); buf++; len--; } msg_done(dev, msg->flags); return 0; }
static ssize_t feed_char_body(struct owfd_rtsp_decoder *dec, char ch, size_t rlen) { char *line; size_t l; /* If remaining_body was already 0, the message had no body. Note that * messages without body are finished early, so no need to call * msg_done() here. Simply forward @ch to STATE_NEW. * @rlen is usually 0. We don't care and forward it, too. */ if (!dec->remaining_body) { dec->state = STATE_NEW; return feed_char_new(dec, ch, rlen); } /* *any* character is allowed as body */ ++rlen; if (!--dec->remaining_body) { /* full body received, copy it and go to STATE_NEW */ l = (size_t)rlen; line = shl_ring_copy(&dec->ring, &l); if (!line) return -ENOMEM; dec->msg.body = line; dec->msg.body_len = l; msg_done(dec); dec->state = STATE_NEW; shl_ring_pull(&dec->ring, rlen); rlen = 0; } return rlen; }
void main_loop(void) { int i, running, msgs_left; CURLMsg *msg; /* For now do not enable SSL - make valgrind easier */ if (curl_global_init(0) || !(curlm = curl_multi_init())) { printf("Unable to initialize curl\n"); exit(1); } /* Setup for the first comics */ for (i = 0; i < thread_limit; ++i) start_next_comic(); curl_multi_perform(curlm, &running); while (start_next_comic() || outstanding) { int numfds=0; curl_multi_wait(curlm, NULL, 0, MAX_WAIT_MSECS, &numfds); curl_multi_perform(curlm, &running); while ((msg = curl_multi_info_read(curlm, &msgs_left))) if (msg->msg == CURLMSG_DONE) msg_done(msg->easy_handle); } curl_multi_cleanup(curlm); }
int stm32_i2c_msg_write(struct device *dev, struct i2c_msg *msg, u8_t *next_msg_flags, uint16_t slave) { const struct i2c_stm32_config *cfg = DEV_CFG(dev); I2C_TypeDef *i2c = cfg->i2c; unsigned int len = 0; u8_t *buf = msg->buf; msg_init(dev, msg, next_msg_flags, slave, LL_I2C_REQUEST_WRITE); len = msg->len; while (len) { while (1) { if (LL_I2C_IsActiveFlag_TXIS(i2c)) { break; } if (LL_I2C_IsActiveFlag_NACK(i2c)) { goto error; } } LL_I2C_TransmitData8(i2c, *buf); buf++; len--; } msg_done(dev, msg->flags); return 0; error: LL_I2C_ClearFlag_NACK(i2c); SYS_LOG_DBG("%s: NACK", __func__); return -EIO; }
static ssize_t feed_char_header(struct owfd_rtsp_decoder *dec, char ch, size_t rlen) { int r; switch (ch) { case '\r': if (dec->last_chr == '\r' || dec->last_chr == '\n') { /* \r\r means empty new-line. We actually allow \r\r\n, * too. \n\r means empty new-line, too, but might also * be finished off as \n\r\n so go to STATE_HEADER_NL * to optionally complete the new-line. * However, if the body is empty, we need to finish the * msg early as there might be no \n coming.. */ dec->state = STATE_HEADER_NL; /* First finish the last header line if any. Don't * include the current \r as it is already part of the * empty following line. */ r = finish_header_line(dec, rlen); if (r < 0) return r; rlen = 0; /* No remaining body. Finish message! */ if (!dec->remaining_body) msg_done(dec); ++rlen; } else { /* '\r' following any character just means newline * (optionally followed by \n). We don't do anything as * it might be a continuation line. */ ++rlen; } break; case '\n': if (dec->last_chr == '\n') { /* We got \n\n, which means we need to finish the * current header-line. If there's no remaining body, * we immediately finish the message and got to * STATE_NEW. Otherwise, we go to STATE_BODY * straight. */ /* don't include second \n in header-line */ r = finish_header_line(dec, rlen); if (r < 0) return r; rlen = 0; dec->state = STATE_BODY; if (!dec->remaining_body) { dec->state = STATE_NEW; msg_done(dec); } /* discard \n */ shl_ring_pull(&dec->ring, 1); } else if (dec->last_chr == '\r') { /* We got an \r\n. We cannot finish the header line as * it might be a continuation line. Next character * decides what to do. Don't do anything here. * \r\n\r cannot happen here as it is handled by * STATE_HEADER_NL. */ ++rlen; } else { /* Same as above, we cannot finish the line as it * might be a continuation line. Do nothing. */ ++rlen; } break; case '"': /* Last line was already completed and this is no whitespace, * thus it's not a continuation line. Finish the line. */ if (dec->last_chr == '\r' || dec->last_chr == '\n') { /* don't include new char in line */ r = finish_header_line(dec, rlen); if (r < 0) return r; rlen = 0; } /* Push character into new line and go to STATE_HEADER_QUOTE */ dec->state = STATE_HEADER_QUOTE; dec->quoted = 0; ++rlen; break; case '\t': case ' ': /* Whitespace. Simply push into buffer and don't do anything. * In case of a continuation line, nothing has to be done, * either. */ ++rlen; break; default: /* Last line was already completed and this is no whitespace, * thus it's not a continuation line. Finish the line. */ if (dec->last_chr == '\r' || dec->last_chr == '\n') { /* don't include new char in line */ r = finish_header_line(dec, rlen); if (r < 0) return r; rlen = 0; } /* Push character into new line. Nothing to be done. */ ++rlen; break; } return rlen; }