forked from xuos/xiuos
ch438 changge mutex and cond
This commit is contained in:
parent
adec8e541c
commit
2b40ba4d1a
|
@ -22,29 +22,66 @@
|
||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "imxrt_ch438.h"
|
#include "imxrt_ch438.h"
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <nuttx/ioexpander/gpio.h>
|
||||||
|
|
||||||
void CH438Demo(void)
|
void CH438Demo(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd,m0fd,m1fd;
|
||||||
int i;
|
int i;
|
||||||
|
char sendbuffer1[4] = {0xC0,0x04,0x01,0x09};
|
||||||
|
char sendbuffer2[6] = {0xC0,0x00,0x03,0x12,0x34,0x61};
|
||||||
|
char sendbuffer3[3] = {0xC1,0x04,0x01};
|
||||||
|
char sendbuffer4[3] = {0xC1,0x00,0x03};
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int readlen;
|
int readlen;
|
||||||
|
|
||||||
while(1)
|
// while(1)
|
||||||
|
// {
|
||||||
|
fd = open("/dev/extuart_dev3", O_RDWR);
|
||||||
|
m0fd = open("/dev/gpout0", O_RDWR);
|
||||||
|
m1fd = open("/dev/gpout1", O_RDWR);
|
||||||
|
ioctl(m0fd, GPIOC_WRITE, (unsigned long)1);
|
||||||
|
ioctl(m1fd, GPIOC_WRITE, (unsigned long)1);
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
write(fd, sendbuffer1,4);
|
||||||
|
sleep(1);
|
||||||
|
readlen = read(fd, buffer, 256);
|
||||||
|
printf("readlen1 = %d\n", readlen);
|
||||||
|
for(i = 0;i< readlen; ++i)
|
||||||
{
|
{
|
||||||
fd = open("/dev/extuart_dev2", O_RDWR);
|
printf("0x%x\n", buffer[i]);
|
||||||
write(fd, "AT+ADDR=?",9);
|
|
||||||
sleep(1);
|
|
||||||
readlen = read(fd, buffer, 256);
|
|
||||||
|
|
||||||
printf("readlen1 = %d\n", readlen);
|
|
||||||
|
|
||||||
for(i = 0;i< readlen; ++i)
|
|
||||||
{
|
|
||||||
printf("%c(0x%x)\n", buffer[i], buffer[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write(fd, sendbuffer2,6);
|
||||||
|
sleep(1);
|
||||||
|
readlen = read(fd, buffer, 256);
|
||||||
|
printf("readlen1 = %d\n", readlen);
|
||||||
|
for(i = 0;i< readlen; ++i)
|
||||||
|
{
|
||||||
|
printf("0x%x\n", buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
write(fd, sendbuffer3,3);
|
||||||
|
sleep(1);
|
||||||
|
readlen = read(fd, buffer, 256);
|
||||||
|
printf("readlen1 = %d\n", readlen);
|
||||||
|
for(i = 0;i< readlen; ++i)
|
||||||
|
{
|
||||||
|
printf("0x%x\n", buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
write(fd, sendbuffer4,3);
|
||||||
|
sleep(1);
|
||||||
|
readlen = read(fd, buffer, 256);
|
||||||
|
printf("readlen1 = %d\n", readlen);
|
||||||
|
for(i = 0;i< readlen; ++i)
|
||||||
|
{
|
||||||
|
printf("0x%x\n", buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,29 @@ struct ch438_dev_s
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t mutex[CH438PORTNUM] =
|
||||||
static pthread_cond_t cond = PTHREAD_COND_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
|
||||||
|
};
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
volatile int done[CH438PORTNUM] = {0};
|
volatile int done[CH438PORTNUM] = {0};
|
||||||
|
|
||||||
static char buff[CH438PORTNUM][BUFFERSIZE];
|
static char buff[CH438PORTNUM][BUFFERSIZE];
|
||||||
|
@ -90,11 +111,11 @@ int getInterruptStatus(int argc, char **argv)
|
||||||
uint8_t ext_uart_no = 0;
|
uint8_t ext_uart_no = 0;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex[ext_uart_no]);
|
||||||
gInterruptStatus = ReadCH438Data(REG_SSR_ADDR);
|
gInterruptStatus = ReadCH438Data(REG_SSR_ADDR);
|
||||||
if(!gInterruptStatus)
|
if(!gInterruptStatus)
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex[ext_uart_no]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +124,8 @@ int getInterruptStatus(int argc, char **argv)
|
||||||
if(gInterruptStatus & Interruptnum[ext_uart_no])
|
if(gInterruptStatus & Interruptnum[ext_uart_no])
|
||||||
{
|
{
|
||||||
done[ext_uart_no] = 1;
|
done[ext_uart_no] = 1;
|
||||||
pthread_cond_signal(&cond);
|
pthread_cond_signal(&cond[ext_uart_no]);
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex[ext_uart_no]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,9 +433,9 @@ static size_t ImxrtCh438ReadData(uint8_t ext_uart_no)
|
||||||
uint8_t REG_LSR_ADDR;
|
uint8_t REG_LSR_ADDR;
|
||||||
uint8_t REG_MSR_ADDR;
|
uint8_t REG_MSR_ADDR;
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex[ext_uart_no]);
|
||||||
while(done[ext_uart_no] == 0)
|
while(done[ext_uart_no] == 0)
|
||||||
pthread_cond_wait(&cond, &mutex);
|
pthread_cond_wait(&cond[ext_uart_no], &mutex[ext_uart_no]);
|
||||||
if (done[ext_uart_no] == 1)
|
if (done[ext_uart_no] == 1)
|
||||||
{
|
{
|
||||||
REG_IIR_ADDR = offsetadd[ext_uart_no] | REG_IIR0_ADDR;
|
REG_IIR_ADDR = offsetadd[ext_uart_no] | REG_IIR0_ADDR;
|
||||||
|
@ -445,7 +466,7 @@ static size_t ImxrtCh438ReadData(uint8_t ext_uart_no)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex[ext_uart_no]);
|
||||||
|
|
||||||
return RevLen;
|
return RevLen;
|
||||||
}
|
}
|
||||||
|
@ -460,22 +481,27 @@ static size_t ImxrtCh438ReadData(uint8_t ext_uart_no)
|
||||||
void Ch438InitDefault(void)
|
void Ch438InitDefault(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
int ret;
|
int ret, i;
|
||||||
|
|
||||||
/* Initialize the mutex */
|
/* Initialize the mutex */
|
||||||
|
|
||||||
ret = pthread_mutex_init(&mutex, NULL);
|
for(i = 0; i < CH438PORTNUM; i++)
|
||||||
if (ret != 0)
|
|
||||||
{
|
{
|
||||||
ch438err("pthread_mutex_init failed, status=%d\n", ret);
|
ret = pthread_mutex_init(&mutex[i], NULL);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
ch438err("pthread_mutex_init failed, status=%d\n", ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the condition variable */
|
/* Initialize the condition variable */
|
||||||
|
for(i = 0; i < CH438PORTNUM; i++)
|
||||||
ret = pthread_cond_init(&cond, NULL);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
{
|
||||||
ch438err("pthread_cond_init failed, status=%d\n", ret);
|
ret = pthread_cond_init(&cond[i], NULL);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
ch438err("pthread_cond_init failed, status=%d\n", ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = task_create("ch438_task", 60, 8192, getInterruptStatus, NULL);
|
ret = task_create("ch438_task", 60, 8192, getInterruptStatus, NULL);
|
||||||
|
|
Loading…
Reference in New Issue