add g_uart_selected array for ch438

This commit is contained in:
wgzAIIT 2022-05-12 11:00:55 +08:00
parent 52aa3c5abd
commit 00e0a48ee7
2 changed files with 82 additions and 46 deletions

View File

@ -36,8 +36,6 @@ void CH438Demo(void)
char buffer[256]; char buffer[256];
int readlen; int readlen;
// while(1)
// {
fd = open("/dev/extuart_dev3", O_RDWR); fd = open("/dev/extuart_dev3", O_RDWR);
m0fd = open("/dev/gpout0", O_RDWR); m0fd = open("/dev/gpout0", O_RDWR);
m1fd = open("/dev/gpout1", O_RDWR); m1fd = open("/dev/gpout1", O_RDWR);
@ -82,6 +80,5 @@ void CH438Demo(void)
} }
close(fd); close(fd);
// }
} }

View File

@ -53,8 +53,8 @@ static int ch438_register(FAR const char *devpath, uint8_t ext_uart_no);
****************************************************************************/ ****************************************************************************/
struct ch438_dev_s struct ch438_dev_s
{ {
sem_t devsem; /* ch438 port devsem */ sem_t devsem; /* ch438 port devsem */
uint8_t port; /* ch438 port number*/ uint8_t port; /* ch438 port number*/
}; };
/**************************************************************************** /****************************************************************************
@ -64,27 +64,56 @@ struct ch438_dev_s
/*mutex of corresponding port*/ /*mutex of corresponding port*/
static pthread_mutex_t mutex[CH438PORTNUM] = static pthread_mutex_t mutex[CH438PORTNUM] =
{ {
PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
}; };
/* Condition variable of corresponding port */ /* Condition variable of corresponding port */
static pthread_cond_t cond[CH438PORTNUM] = static pthread_cond_t cond[CH438PORTNUM] =
{ {
PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER,
PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER,
PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER,
PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER,
PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER,
PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER,
PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER,
PTHREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER
};
/* This array shows whether the current serial port is selected */
static bool const g_uart_selected[CH438PORTNUM] =
{
#ifdef CONFIG_CH438_EXTUART0
[0] = true,
#endif
#ifdef CONFIG_CH438_EXTUART1
[1] = true,
#endif
#ifdef CONFIG_CH438_EXTUART2
[2] = true,
#endif
#ifdef CONFIG_CH438_EXTUART3
[3] = true,
#endif
#ifdef CONFIG_CH438_EXTUART4
[4] = true,
#endif
#ifdef CONFIG_CH438_EXTUART5
[5] = true,
#endif
#ifdef CONFIG_CH438_EXTUART6
[6] = true,
#endif
#ifdef CONFIG_CH438_EXTUART7
[7] = true,
#endif
}; };
/* ch438 Callback work queue structure */ /* ch438 Callback work queue structure */
@ -108,13 +137,13 @@ static volatile bool g_ch438open[CH438PORTNUM] = {false,false,false,false,false,
/* Ch438 POSIX interface */ /* Ch438 POSIX interface */
static const struct file_operations g_ch438fops = static const struct file_operations g_ch438fops =
{ {
ch438_open, ch438_open,
ch438_close, ch438_close,
ch438_read, ch438_read,
ch438_write, ch438_write,
NULL, NULL,
ch438_ioctl, ch438_ioctl,
NULL NULL
}; };
/**************************************************************************** /****************************************************************************
@ -135,7 +164,7 @@ static FAR void getInterruptStatus(FAR void *arg)
{ {
for(i = 0; i < CH438PORTNUM; i++) for(i = 0; i < CH438PORTNUM; i++)
{ {
if(gInterruptStatus & Interruptnum[i]) if(g_uart_selected[i] && (gInterruptStatus & Interruptnum[i]))
{ {
pthread_mutex_lock(&mutex[i]); pthread_mutex_lock(&mutex[i]);
done[i] = true; done[i] = true;
@ -572,6 +601,11 @@ static void Ch438InitDefault(void)
/* Initialize the mutex */ /* Initialize the mutex */
for(i = 0; i < CH438PORTNUM; i++) for(i = 0; i < CH438PORTNUM; i++)
{ {
if(!g_uart_selected[i])
{
continue;
}
ret = pthread_mutex_init(&mutex[i], NULL); ret = pthread_mutex_init(&mutex[i], NULL);
if(ret != 0) if(ret != 0)
{ {
@ -582,6 +616,11 @@ static void Ch438InitDefault(void)
/* Initialize the condition variable */ /* Initialize the condition variable */
for(i = 0; i < CH438PORTNUM; i++) for(i = 0; i < CH438PORTNUM; i++)
{ {
if(!g_uart_selected[i])
{
continue;
}
ret = pthread_cond_init(&cond[i], NULL); ret = pthread_cond_init(&cond[i], NULL);
if(ret != 0) if(ret != 0)
{ {