void gen_audio(void *data, uint8_t *stream, int len) { int i; int16_t *p = (void *)stream; int b; while(rb_used(rb_audio) < len/2) { unsigned v = 0; if(rb_used(rb_data) > 0) { unsigned c = rb_pop(rb_data); v = (((c ^ 0xff) << 1) | 0x1); } for(b=0; b<10; b++) { for(i=0; i<(SRATE / BRATE); i++) { int16_t y = cos(t * M_PI * 2) * 32000; rb_push(rb_audio, y); if(v & 1) { t += FREQ_1 / SRATE; } else { t += FREQ_0 / SRATE; } } v >>= 1; } } for(i=0; i<len/2; i++) { *p++ = rb_pop(rb_audio); } }
/** * get a byte from USART. This * call is alway blocking. if input buffer * is enabled use usart[N]_hasData() to check * if data is available * * @return received byte */ uint8_t usart1_getc(void) { #ifdef NO_USART1_BUFFERED_INPUT while(USART1_RX_IS_BUSY()); return UDR1; #else uint8_t data; while(rb_pop(&usart1_inBuff, &data) != 0); return data; #endif }
void ant_handle_msg(void) { uint8_t msg_n = 0;; uint8_t in_msg = FALSE; pop_value value; while(1) { value = rb_pop(&rx_ring); // Nothing to read and we're not waiting on a message if (value.success == 0 && in_msg == FALSE) return; // We must be waiting for a byte if (value.success == 0 && in_msg == TRUE) continue; if ((value.byte == MESG_TX_SYNC) && (in_msg == FALSE)) { msg_n = 0; // Always reset when we receive a sync header in_msg = TRUE; rx_buf[msg_n] = value.byte; msg_n++; } else if (msg_n == 1) { // Size rx_buf[msg_n] = value.byte; msg_n++; } else if (msg_n == 2) { // Type rx_buf[msg_n] = value.byte; msg_n++; } else if (msg_n < rx_buf[1] + 3) { rx_buf[msg_n] = value.byte; msg_n++; } else { in_msg = FALSE; rx_buf[msg_n] = value.byte; if (checksum(rx_buf, msg_n) == rx_buf[msg_n]) { dispatch_msg(msg_n); } else { printf("checksum failed\n"); } break; } } }