67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
/*
|
|
* Copyright (c) 2019, ETH Zurich.
|
|
* All rights reserved.
|
|
*
|
|
* This file is distributed under the terms in the attached LICENSE file.
|
|
* If you do not find this file, copies can be found by writing to:
|
|
* ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
|
|
*/
|
|
|
|
#ifndef SHELLY_H_
|
|
#define SHELLY_H_
|
|
|
|
#define SHELLY_DEBUG_ON 1
|
|
|
|
#if defined(SHELLY_DEBUG_ON)
|
|
#define SHELLY_DEBUG(x...) debug_printf("[SHELLY_DEBUG] " x);
|
|
#else
|
|
#define SHELLY_DEBUG(x, ...) ((void)0)
|
|
#endif
|
|
|
|
#include <drivers/lpuart.h>
|
|
#include <drivers/gic_dist.h>
|
|
#include <aos/ump_chan.h>
|
|
|
|
#define ASCII_NL 10 // < new line
|
|
#define ASCII_CR 13 // < carriage return
|
|
#define ASCII_EOF 4 // < end of file
|
|
#define ASCII_EOT 3 // < end of text
|
|
|
|
#define SHELLY_BUF_SIZE 2048
|
|
|
|
//state that different for each client
|
|
struct shelly_st_local {
|
|
uint32_t client_id;
|
|
struct ump_recv_chan * recv_chan;
|
|
struct ump_send_chan * send_chan;
|
|
|
|
};
|
|
|
|
//state that is shared for all clients
|
|
struct shelly_st_global {
|
|
struct waitset * ws;
|
|
bool did_init_filesystem;
|
|
|
|
void * lpuart_base; // < virtual address of the lpuart device registers
|
|
void * gic_base; // < virtual address of the gic device registers
|
|
|
|
struct lpuart_s * uart_s; // < state of the uart driver
|
|
struct gic_dist_s * gic_s; // < state of the gic driver
|
|
|
|
u_int32_t num_clients;
|
|
char buf[SHELLY_BUF_SIZE];
|
|
size_t buffer_i;
|
|
|
|
struct shelly_st_local * current_getchar_request; // < the getchar request that is currently being served, NULL if there is none.
|
|
};
|
|
|
|
bool is_newline(char c);
|
|
errval_t shelly_write_str(char * str);
|
|
void shelly_reset_buffer(void);
|
|
errval_t shelly_buffer_append(char c);
|
|
static void handle_client_request(void *arg, size_t header_size, void *header_buf, size_t payload_size);
|
|
static void send_response(struct shelly_st_local * local_state, errval_t err, char c, size_t payload_size, void *payload);
|
|
static void init_fs_on_demand(void);
|
|
|
|
#endif // ndef SHELLY_H_
|