Skip to content
Snippets Groups Projects
Select Git revision
  • f7719151cda0fe9a56a18a17e7818b7204457065
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • v1.11
  • v1.10
  • 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
36 results

serial.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    • schneider's avatar
      f7719151
      fix(serial): Unblock if the queue is full · f7719151
      schneider authored
      For some reason a portYIELD() is not enough to give the serial task the
      option to run. I tried vTaskDelay() and that works. To not block more than
      needed portYIELD() is still called when the queue is not full and only
      call vTaskDelay() when it is full.
      
      Closes #218
      f7719151
      History
      fix(serial): Unblock if the queue is full
      schneider authored
      For some reason a portYIELD() is not enough to give the serial task the
      option to run. I tried vTaskDelay() and that works. To not block more than
      needed portYIELD() is still called when the queue is not full and only
      call vTaskDelay() when it is full.
      
      Closes #218
    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;
    	}