<commit_before>/*
 * Copyright (C) 2016 <NAME> <<EMAIL>>
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     drivers_ethos
 * @{
 *
 * @file
 * @brief       Implementation of a simple ethernet-over-serial driver
 *
 * @author      <NAME> <<EMAIL>>
 *
 * @}
 */

#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>

#include "ethos.h"
#include "periph/uart.h"
#include "tsrb.h"
#include "irq.h"

#include "net/netdev.h"
#include "net/netdev/eth.h"
#include "net/eui64.h"
#include "net/eui_provider.h"
#include "net/ethernet.h"

#ifdef MODULE_ETHOS_STDIO
#include "stdio_uart.h"
#include "isrpipe.h"
extern isrpipe_t ethos_stdio_isrpipe;
#endif

#define ENABLE_DEBUG 0
#include "debug.h"

#define ETHOS_FRAME_TYPE_ERRORED    (0xff)

static void _get_mac_addr(netdev_t *dev, uint8_t* buf);
static void ethos_isr(void *arg, uint8_t c);
static const netdev_driver_t netdev_driver_ethos;

static const uint8_t _esc_esc[] = {ETHOS_ESC_CHAR, (ETHOS_ESC_CHAR ^ 0x20)};
static const uint8_t _esc_delim[] = {ETHOS_ESC_CHAR, (ETHOS_FRAME_DELIMITER ^ 0x20)};

void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t idx,
                 void *inbuf, size_t inbuf_size)
{
    dev->netdev.driver = &netdev_driver_ethos;
    dev->uart = params->uart;
    dev->state = WAIT_FRAMESTART;
    dev->frametype = 0;

    tsrb_init(&dev->inbuf, inbuf, inbuf_size);
    mutex_init(&dev->out_mutex);

    netdev_register(&dev->netdev, NETDEV_ETHOS, idx);
    netdev_eui48_get(&dev->netdev, (eui48_t *)&dev->mac_addr);

    uart_init(params->uart, params->baudrate, ethos_isr, (void*)dev);

    uint8_t frame_delim = ETHOS_FRAME_DELIMITER;
    uart_write(dev->uart, &frame_delim, 1);
    ethos_send_frame(dev, dev->mac_addr, 6, ETHOS_FRAME_TYPE_HELLO);
}

static void _reset_state(ethos_t *dev)
{
    dev->state = WAIT_FRAMESTART;
    dev->frametype = 0;
}

static void _fail_frame(ethos_t *dev)
{
    switch (dev->frametype) {
        case ETHOS_FRAME_TYPE_DATA:
            tsrb_clear(&dev->inbuf);
            /* signal to handler thread that frame is at an end (makes handler thread to
             * truncate frame) */
            tsrb_add_one(&dev->inbuf, ETHOS_FRAME_DELIMITER);
            break;
        case ETHOS_FRAME_TYPE_TEXT:
            tsrb_clear(&ethos_stdio_isrpipe.tsrb);
            /* signal to handler thread that frame is at an end (makes handler thread to
             * truncate frame) */
            isrpipe_write_one(&ethos_stdio_isrpipe, ETHOS_FRAME_DELIMITER);
            break;
        case ETHOS_FRAME_TYPE_ERRORED:
            return;
        default:
            assert(0);
            break;
    }<commit_msg>drivers/ethos: fix build without ethos_stdio<commit_after>/*
 * Copyright (C) 2016 <NAME> <<EMAIL>>
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     drivers_ethos
 * @{
 *
 * @file
 * @brief       Implementation of a simple ethernet-over-serial driver
 *
 * @author      <NAME> <<EMAIL>>
 *
 * @}
 */

#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>

#include "ethos.h"
#include "periph/uart.h"
#include "tsrb.h"
#include "irq.h"

#include "net/netdev.h"
#include "net/netdev/eth.h"
#include "net/eui64.h"
#include "net/eui_provider.h"
#include "net/ethernet.h"

#ifdef MODULE_ETHOS_STDIO
#include "stdio_uart.h"
#include "isrpipe.h"
extern isrpipe_t ethos_stdio_isrpipe;
#endif

#define ENABLE_DEBUG 0
#include "debug.h"

#define ETHOS_FRAME_TYPE_ERRORED    (0xff)

static void _get_mac_addr(netdev_t *dev, uint8_t* buf);
static void ethos_isr(void *arg, uint8_t c);
static const netdev_driver_t netdev_driver_ethos;

static const uint8_t _esc_esc[] = {ETHOS_ESC_CHAR, (ETHOS_ESC_CHAR ^ 0x20)};
static const uint8_t _esc_delim[] = {ETHOS_ESC_CHAR, (ETHOS_FRAME_DELIMITER ^ 0x20)};

void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t idx,
                 void *inbuf, size_t inbuf_size)
{
    dev->netdev.driver = &netdev_driver_ethos;
    dev->uart = params->uart;
    dev->state = WAIT_FRAMESTART;
    dev->frametype = 0;

    tsrb_init(&dev->inbuf, inbuf, inbuf_size);
    mutex_init(&dev->out_mutex);

    netdev_register(&dev->netdev, NETDEV_ETHOS, idx);
    netdev_eui48_get(&dev->netdev, (eui48_t *)&dev->mac_addr);

    uart_init(params->uart, params->baudrate, ethos_isr, (void*)dev);

    uint8_t frame_delim = ETHOS_FRAME_DELIMITER;
    uart_write(dev->uart, &frame_delim, 1);
    ethos_send_frame(dev, dev->mac_addr, 6, ETHOS_FRAME_TYPE_HELLO);
}

static void _reset_state(ethos_t *dev)
{
    dev->state = WAIT_FRAMESTART;
    dev->frametype = 0;
}

static void _fail_frame(ethos_t *dev)
{
    switch (dev->frametype) {
        case ETHOS_FRAME_TYPE_DATA:
            tsrb_clear(&dev->inbuf);
            /* signal to handler thread that frame is at an end (makes handler thread to
             * truncate frame) */
            tsrb_add_one(&dev->inbuf, ETHOS_FRAME_DELIMITER);
            break;
        case ETHOS_FRAME_TYPE_TEXT:
#ifdef MODULE_ETHOS_STDIO
            tsrb_clear(&ethos_stdio_isrpipe.tsrb);
            /* signal to handler thread that frame is at an end (makes handler thread to
             * truncate frame) */
            isrpipe_write_one(&ethos_stdio_isrpipe, ETHOS_FRAME_DELIMITER);
#endif
            break;
        case ETHOS_FRAME_TYPE_ERRORED:
            return;
        default:
            assert(0);
            break;
    }
{'fraction_non_alphanumeric': 0.11729482212046495, 'fraction_numerical': 0.010919337794998239, 'mean_word_length': 3.3384262796027504, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3670858', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2089, 'n_words': 467}