Example #1
0
void uart_rx(int length) {
    if (!sock_connected) {
        uart_rx_one_char(UART);
        return;
    }


    int i = 0;
    unsigned char c;
    bool rb_full = false;

    if (xSemaphoreTakeFromISR(ringbuf_mutex, NULL)) {
        while (ringbuf_get(&ringbuf_t, &c) == 0) {
            if (ringbuf_owr(&ringbuf_m, c)) {
                rb_full = true;
            }
        }

        for (i = 0; i < length; i++) {
            if (ringbuf_owr(&ringbuf_m, uart_rx_one_char(UART0))) {
                rb_full = true;
            }
        }
        xSemaphoreGiveFromISR(ringbuf_mutex, NULL);
    } else {
        DBG("uart_rx: failed to take semphr");

        // ringbuf is taken by send task
        // all uart data is copied in temporary ringbuffer that will be copied in main ringbuffer once it is available
        for (i = 0; i < length; i++) {
            if (ringbuf_owr(&ringbuf_t, uart_rx_one_char(UART0))) {
                rb_full = true;
            }
        }
    }

    //DBG("uart_rx: %d b", length);

    // notify send task that there is data to be sent
    xQueueSendToBackFromISR(tx_queue, &length, NULL);

    if (rb_full) {
        // not every byte could be put in one of the two ringbuffers
        // we can just print a message about it
        DBG("uart_rx: ringbuff overflow");
    }
}
Example #2
0
void uart_rx(int len) {

    int i;
    for (i = 0; i < len; i++) {
        //DBG("rx:%d", uart_rx_one_char(UART));
        uart_parse(uart_rx_one_char(UART));
    }

}
Example #3
0
void unity_run_menu()
{
    int test_count = print_test_menu();
    while (true)
    {
        char cmdline[256] = { 0 };
        while(strlen(cmdline) == 0)
        {
            /* Flush anything already in the RX buffer */
            while(uart_rx_one_char((uint8_t *) cmdline) == OK) {
            }
            /* Read input */
            UartRxString((uint8_t*) cmdline, sizeof(cmdline) - 1);
            trim_trailing_space(cmdline);
            if(strlen(cmdline) == 0) {
                /* if input was newline, print a new menu */
                print_test_menu();
            }
        }

        UNITY_BEGIN();

        size_t idx = 0;
        if (cmdline[idx] == '!')
        {
            s_invert = true;
            ++idx;
        }
        else
        {
            s_invert = false;
        }

        if (cmdline[idx] == '*')
        {
            unity_run_all_tests();
        }
        else if (cmdline[idx] =='[')
        {
            unity_run_tests_with_filter(cmdline + idx);
        }
        else if (cmdline[idx] =='"')
        {
            unity_run_single_test_by_name(cmdline + idx);
        }
        else if (isdigit((unsigned char)cmdline[idx]))
        {
            unity_run_single_test_by_index_parse(cmdline + idx, test_count);
        }

        UNITY_END();

        printf("Enter next test, or 'enter' to see menu\n");
    }
}
Example #4
0
static int esp32_uart_rx(struct device *dev, unsigned char *p_char)
{
	ARG_UNUSED(dev);

	switch (uart_rx_one_char(p_char)) {
	case OK:
		return 0;
	case PENDING:
		return -EINPROGRESS;
	case BUSY:
		return -EBUSY;
	case CANCEL:
		return -ECANCELED;
	default:
		return -EIO;
	}
}
Example #5
0
void unity_gets(char *dst, size_t len)
{
    size_t unity_input_from_gdb_len = strlen(unity_input_from_gdb);
    if (unity_input_from_gdb_len > 0 && unity_input_from_gdb_len < len - 1) {
        memcpy(dst, unity_input_from_gdb, unity_input_from_gdb_len);
        dst[unity_input_from_gdb_len] = '\n';
        dst[unity_input_from_gdb_len + 1] = 0;
        memset(unity_input_from_gdb, 0, sizeof(unity_input_from_gdb));
        return;
    }
    /* UartRxString length argument is uint8_t */
    if (len >= UINT8_MAX) {
        len = UINT8_MAX;
    }
    /* Flush anything already in the RX buffer */
    uint8_t ignore;
    while (uart_rx_one_char(&ignore) == OK) {
    }
    /* Read input */
    UartRxString((uint8_t *) dst, len);
}
Example #6
0
/*** Loop ***/
static void ICACHE_FLASH_ATTR loop(os_event_t *events) {
	char c;
	int res = uart_rx_one_char(&c);

	if(res != 1) {
		if (c != '\r' && c != '\n') {
			if (cmd_buf_iter + 1 < CMD_BUF_SIZE)
				cmd_buf[cmd_buf_iter++] = c;
		} else {
			cmd_buf[cmd_buf_iter] = 0x00;
			cmd_buf_iter = 0;
			if (os_strcmp(cmd_buf, "time") == 0) {
				if (time_valid) {
					os_printf("Zeit: %d.%d.%d, %d:%d:%d, DOW %d\r\n", time.date, time.month, time.year, time.hours, time.minutes, time.seconds, time.dow);
				} else {
					os_printf("No valid time information yet!\r\n");
				}
			} else if (os_strcmp(cmd_buf, "dcf") == 0) {
				os_printf("DCF77 status information:\r\n");
				os_printf("Received bits this minute: %d\r\n", signal_iter);
				os_printf("High count %d, Low count %d, Total %d\r\n", dcf_hc, dcf_lc, dcf_hc + dcf_lc);
				os_printf("Signal buffer:\r\n");
				uint8_t i;
				for (i = 0; i < 60; i++) os_printf("%d", signal[i]);
				os_printf("\r\n");
			} else if (os_strcmp(cmd_buf, "time_get") == 0) {
				if (time_valid) {
					os_printf("%d %d %d %d %d %d %d\r\n", time.seconds, time.minutes, time.hours, time.date, time.month, time.year, time.dow);
				} else {
					os_printf("x\r\n");
				}
			} else if (os_strcmp(cmd_buf, "hello") == 0) {
				os_printf("hel_ok\r\n");
			}
		}
	}
	system_os_post(user_procTaskPrio, 0, 0);
}
Example #7
0
/**
 * get_answer
 * Writes answer in global ans_buf variable
 * Ignores answers that are longer than ANS_BUF_SIZE
 * Returns false if no answer was received, otherwise true
 *
 * ms_to_answer maximum 1000ms due to watchdog!
 */
bool get_answer(uint16_t ms_to_answer) {
	ans_buf_iter = 0;
	uint16_t time_ms = 0;

	while (time_ms <= ms_to_answer) {
		char c;
		int res = uart_rx_one_char(&c);

		if (res == 1) {
			os_delay_us(1000);
			time_ms++;
		} else {
			if (c != '\r' && c != '\n') {
				if (ans_buf_iter + 1 < ANS_BUF_SIZE)
					ans_buf[ans_buf_iter++] = c;
			} else {
				ans_buf[ans_buf_iter] = 0x00;
				return true;
			}
		}
	}

	return false;
}