Exemplo n.º 1
0
Arquivo: tx.c Projeto: zevv/rgbufo
int send_byte(uint8_t b)
{
	if(b >= 0xfe) {
		rb_push(rb_data, 0xfe);
		rb_push(rb_data, b);
		printf("fe %02x ", b);
		return 2;
	} else {
		printf("%02x ", b);
		rb_push(rb_data, b);
		return 1;
	}
}
Exemplo n.º 2
0
Arquivo: tx.c Projeto: zevv/rgbufo
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);
        }
}
Exemplo n.º 3
0
Arquivo: tx.c Projeto: zevv/rgbufo
void send(void *buf, size_t len)
{
	uint8_t *p = buf;
	uint8_t sum = 0;
	int i;

	if(rb_used(rb_data) > 0) return;
	
	for(i=0; i<len; i++) {
		send_byte(p[i]);
		sum += p[i];
	}
	send_byte(sum ^ 0xff);
	rb_push(rb_data, 0xff);

	printf("\n");
}
Exemplo n.º 4
0
	/**
	 * Put a byte on USART. unless
	 * USART1_NON_UNIX_LIKE_LINE_ENDINGS is
	 * defined this will put a '\r' before every '\n'
	 * to mimic unix like line endings
	 *
	 * @param  c Byte to transmit
	 * @return   positive if success
	 */
	int usart1_putc(const uint8_t c) {
	#ifndef USART1_NON_UNIX_LIKE_LINE_ENDINGS
		if(c == '\n'){
			usart1_putc('\r');
		}
	#endif

	#ifdef NO_USART1_BUFFERED_OUTPUT
		while (USART1_TX_IS_BUSY());
		UDR1 = c;
	#else
		// Wait for free space in buffer
		while (rb_push(&usart1_outBuff, c) != 0);
		USART1_ENABLE_DATA_REG_EMPTY_INTERRUPT();
	#endif

		return c;
	}
Exemplo n.º 5
0
void rb_pushStr(rb *x, uint8_t *str) {
  while (*str) {
    rb_push(x, *str);
    str++;
  }
}