Skip to content
Snippets Groups Projects
Select Git revision
  • e8b877be6018893f1250c87424c3886f115b0051
  • wip-bootstrap default
  • dualcore
  • ch3/leds
  • ch3/time
  • master
6 results

run-tests

Blame
  • serial.c 6.94 KiB
    #include "epicardium.h"
    #include "modules/log.h"
    #include "modules/modules.h"
    
    #include "max32665.h"
    #include "usb/cdcacm.h"
    #include "uart.h"
    
    #include "FreeRTOS.h"
    #include "task.h"
    #include "queue.h"
    #include "stream_buffer.h"
    
    #include <stdint.h>
    #include <stdio.h>
    
    /* The serial console in use (UART0) */
    extern mxc_uart_regs_t *ConsoleUart;
    
    /* Task ID for the serial handler */
    TaskHandle_t serial_task_id = NULL;
    
    /* Read queue, filled by both UART and CDCACM */
    static QueueHandle_t read_queue;
    /* Stream Buffer for handling all writes to serial */
    static StreamBufferHandle_t write_stream_buffer = NULL;
    
    void serial_init()
    {
    	/* Setup read queue */
    	static uint8_t buffer[sizeof(char) * SERIAL_READ_BUFFER_SIZE];
    	static StaticQueue_t read_queue_data;
    	read_queue = xQueueCreateStatic(
    		SERIAL_READ_BUFFER_SIZE, sizeof(char), buffer, &read_queue_data
    	);
    
    	/* Setup write queue */
    	static uint8_t ucWrite_stream_buffer[SERIAL_WRITE_STREAM_BUFFER_SIZE];
    	static StaticStreamBuffer_t xStream_buffer_struct;
    	write_stream_buffer = xStreamBufferCreateStatic(
    		sizeof(ucWrite_stream_buffer),
    		1,
    		ucWrite_stream_buffer,
    		&xStream_buffer_struct
    	);
    }
    
    void serial_return_to_synchronous()
    {
    	write_stream_buffer = NULL;
    }
    
    /*
     * API-call to write a string.  Output goes to both CDCACM and UART
     */
    void epic_uart_write_str(const char *str, size_t length)
    {
    	if (length == 0) {
    		return;
    	}
    
    	/*
    	 * Check if the stream buffer is even initialized yet
    	 */
    	if (write_stream_buffer == NULL) {
    		UART_Write(ConsoleUart, (uint8_t *)str, length);
    		cdcacm_write((uint8_t *)str, length);
    		return;
    	}