Skip to content

Commit

Permalink
fix #28
Browse files Browse the repository at this point in the history
  • Loading branch information
esm-tmori committed Feb 5, 2021
1 parent 7820584 commit 8aaeb85
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
106 changes: 103 additions & 3 deletions src/device/peripheral/athrill_syscall_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,65 @@ static int create_directory(const char* dir)
return ret;
}

#ifdef ENABLE_EXTERNAL_BT_SERIAL
#include "serial_fifo.h"
typedef struct {
int file_descriptor;
AthrillSerialFifoType *fifo;
} ExternalSerialFifoMapType;
typedef enum {
ExternalSerialFifoId_0 = 0,
ExternalSerialFifoId_1,
ExternalSerialFifoId_NUM
} ExternalSerialFifoIdType;
static ExternalSerialFifoMapType external_serial_fifo_map[ExternalSerialFifoId_NUM];
static AthrillSerialFifoType *get_serial_fifo(ExternalSerialFifoIdType id)
{
AthrillSerialFifoType *fifop = NULL;
Std_ReturnType err;
uint32 scid;
if (id == ExternalSerialFifoId_0) {
err = cpuemu_get_devcfg_value("DEVICE_CONFIG_EV3_CH0_SERIAL_ID", (uint32*)&scid);
}
else if (id == ExternalSerialFifoId_1) {
err = cpuemu_get_devcfg_value("DEVICE_CONFIG_EV3_CH1_SERIAL_ID", (uint32*)&scid);
}
else {
return NULL;
}
if (err != STD_E_OK) {
return NULL;
}
athrill_device_get_serial_fifo_buffer(scid, &fifop);
return fifop;
}
static AthrillSerialFifoType *get_serial_fifo_from_fd(int fd)
{
int i;
for (i = 0; i < ExternalSerialFifoId_NUM; i++) {
if (fd == external_serial_fifo_map[i].file_descriptor) {
return external_serial_fifo_map[i].fifo;
}
}
return NULL;
}

static std_bool athrill_ev3_serial_is_opened(ExternalSerialFifoIdType id)
{
if (external_serial_fifo_map[id].file_descriptor > 0) {
return TRUE;
}
else {
return FALSE;
}
}
static void athrill_ev3_serial_set_fd(ExternalSerialFifoIdType id, int fd, AthrillSerialFifoType *fifop)
{
external_serial_fifo_map[id].file_descriptor = fd;
external_serial_fifo_map[id].fifo = fifop;
return;
}
#endif /* ENABLE_EXTERNAL_BT_SERIAL */

char *virtual_file_top = 0;
static char *getVirtualFileName(const char *file_name, char *buf)
Expand Down Expand Up @@ -574,6 +632,17 @@ static void athrill_syscall_read_r(AthrillSyscallArgType *arg)
return;
}

#ifdef ENABLE_EXTERNAL_BT_SERIAL
AthrillSerialFifoType *fifop = get_serial_fifo_from_fd(fd);
if (fifop != NULL) {
arg->ret_value = 0;
arg->ret_errno = 0;
mpthread_lock(fifop->rx_thread);
(void)comm_fifo_buffer_get(&fifop->rd, buf, size, (uint32*)&arg->ret_value);
mpthread_unlock(fifop->rx_thread);
return;
}
#endif /* ENABLE_EXTERNAL_BT_SERIAL */
// if fd has corresponding fd(for write), it is stream
int is_stream = is_stream_fd(fd);

Expand Down Expand Up @@ -611,7 +680,16 @@ static void athrill_syscall_write_r(AthrillSyscallArgType *arg)
return;
}


#ifdef ENABLE_EXTERNAL_BT_SERIAL
AthrillSerialFifoType *fifop = get_serial_fifo_from_fd(fd);
if (fifop != NULL) {
arg->ret_value = 0;
mpthread_lock(fifop->tx_thread);
(void)comm_fifo_buffer_add(&fifop->wr, buf, size, (uint32*)&arg->ret_value);
mpthread_unlock(fifop->tx_thread);
return;
}
#ednfi /* ENABLE_EXTERNAL_BT_SERIAL */
int actual_fd = get_correspond_fd(fd);

arg->ret_value = write(actual_fd, buf, size);
Expand Down Expand Up @@ -908,6 +986,25 @@ static void athrill_syscall_ev3_serial_open(AthrillSyscallArgType *arg)
int fd;
sys_int32 port = arg->body.api_ev3_serial_open.port;

#ifdef ENABLE_EXTERNAL_BT_SERIAL
int scid = 0;
AthrillSerialFifoType *fifop = NULL;

if ( port == SYS_SERIAL_UART ) {
scid = ExternalSerialFifoId_0;
} else if ( port == SYS_SERIAL_BT ) {
scid = ExternalSerialFifoId_1;
}
fifop = get_serial_fifo(scid);
if (fifop == NULL) {
arg->ret_value = -1;
return;
}
else if (athrill_ev3_serial_is_opened(scid) == TRUE) {
arg->ret_value = external_serial_fifo_map[scid].file_descriptor;
return;
}
#endif /* ENABLE_EXTERNAL_BT_SERIAL */
if ( port == SYS_SERIAL_DEFAULT ) {
fd = 0;
} else if ( port == SYS_SERIAL_UART ) {
Expand All @@ -918,11 +1015,14 @@ static void athrill_syscall_ev3_serial_open(AthrillSyscallArgType *arg)
path_base ="__ev3rt_bt"; // BT Default name
(void)cpuemu_get_devcfg_string("DEVICE_CONFIG_BT_BASENAME",&path_base);
fd = create_pipe_pair(path_base);

} else {
fd = -1;
}

#ifdef ENABLE_EXTERNAL_BT_SERIAL
if (fd > 0) {
athrill_ev3_serial_set_fd(scid, fd, fifop);
}
#endif /* ENABLE_EXTERNAL_BT_SERIAL */
arg->ret_value = fd;

//printf("ev3_serial_open() port=%d fd=%d\n",port,fd);
Expand Down
10 changes: 10 additions & 0 deletions src/device/peripheral/serial/fifo/serial_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void athrill_device_init_serial_fifo(void)
ret = cpuemu_get_devcfg_value(serial_fifo_param_buffer, &buffer_size);
if (ret == STD_E_OK) {
uint32 enable_external_device = FALSE;
uint32 disable_cpuio = FALSE;
athrill_serial_fifo[i].rd_raise_delay_count = 0;
athrill_serial_fifo[i].rd_raise_intr = FALSE;
athrill_serial_fifo[i].wr_raise_delay_count = 0;
Expand Down Expand Up @@ -76,6 +77,12 @@ void athrill_device_init_serial_fifo(void)
ASSERT(ret == STD_E_OK);
printf("%s=%u\n", serial_fifo_param_buffer, athrill_serial_fifo[i].wr_intoff);


snprintf(serial_fifo_param_buffer, sizeof(serial_fifo_param_buffer), "DEVICE_CONFIG_SERIAL_FILFO_%d_DISABLE_CPUIO", i);
(void)cpuemu_get_devcfg_value(serial_fifo_param_buffer, &disable_cpuio);
printf("%s=%u\n", serial_fifo_param_buffer, disable_cpuio);
athrill_serial_fifo[i].disable_cpu_io = disable_cpuio;

snprintf(serial_fifo_param_buffer, sizeof(serial_fifo_param_buffer), "DEVICE_CONFIG_SERIAL_FILFO_%d_EXDEV_ENABLE", i);
(void)cpuemu_get_devcfg_value(serial_fifo_param_buffer, &enable_external_device);
printf("%s=%u\n", serial_fifo_param_buffer, enable_external_device);
Expand Down Expand Up @@ -241,6 +248,9 @@ void athrill_device_supply_clock_serial_fifo(DeviceClockType *dev_clock)
if (athrill_serial_fifo[i].rd.data == NULL) {
continue;
}
else if (athrill_serial_fifo[i].disable_cpu_io == TRUE) {
continue;
}
do_serial_fifo_cpu_read(i);
do_serial_fifo_cpu_write(i);
do_serial_fifo_cpu_intr(i);
Expand Down
7 changes: 4 additions & 3 deletions src/device/peripheral/serial/fifo/serial_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ extern void athrill_device_supply_clock_serial_fifo(DeviceClockType *dev_clock);
#define SERIAL_FIFO_RD_BUFFER_LEN 16U
#define SERIAL_FIFO_WR_BUFFER_LEN 16U
typedef struct {
bool is_extdev;
std_bool is_extdev;
std_bool disable_cpu_io;
/*
* read: cpu
* write: external device
Expand All @@ -101,7 +102,7 @@ typedef struct {
uint32 rd_intno;
uint32 rd_intoff;
uint32 rd_raise_delay_count;
bool rd_raise_intr;
std_bool rd_raise_intr;
/*
* read: external device
* write: cpu
Expand All @@ -111,7 +112,7 @@ typedef struct {
uint32 wr_intno;
uint32 wr_intoff;
uint32 wr_raise_delay_count;
bool wr_raise_intr;
std_bool wr_raise_intr;

/*
* for serial ext thread info
Expand Down

0 comments on commit 8aaeb85

Please sign in to comment.