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

@ -87,6 +87,35 @@ static pthread_cond_t cond[CH438PORTNUM] =
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 */
static struct work_s g_ch438irqwork; static struct work_s g_ch438irqwork;
@ -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)
{ {