Skip to content
Snippets Groups Projects
Select Git revision
  • 40ae65a4cb7cab5f6372921c8f5cc03152908446
  • master default protected
  • backslash
  • nickname-match-configs
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • ios-workarounds
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
34 results

serial.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    serial.c 5.74 KiB
    #include "epicardium.h"
    #include "api/interrupt-sender.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
    	);
    }
    
    /*
     * API-call to write a string.  Output goes to both CDCACM and UART
     */
    void epic_uart_write_str(const char *str, intptr_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;
    	}
    
    	if (xPortIsInsideInterrupt()) {
    		BaseType_t resched1 = pdFALSE;
    		BaseType_t resched2 = pdFALSE;