change ch438 on nuttx

This commit is contained in:
wgzAIIT 2022-05-10 11:31:59 +08:00
parent 8d6e9532cf
commit cd5686de2e
1 changed files with 106 additions and 106 deletions

View File

@ -26,7 +26,7 @@
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static FAR void *getInterruptStatus(FAR void *arg);
static FAR void getInterruptStatus(FAR void *arg);
static void CH438SetOutput(void);
static void CH438SetInput(void);
static uint8_t ReadCH438Data(uint8_t addr);
@ -109,7 +109,7 @@ static const struct file_operations g_ch438fops =
* thread task getInterruptStatus
*
****************************************************************************/
static FAR void *getInterruptStatus(FAR void *arg)
static FAR void getInterruptStatus(FAR void *arg)
{
uint8_t i;
while(1)
@ -285,7 +285,7 @@ static void WriteCH438Data(uint8_t addr, uint8_t dat)
****************************************************************************/
static void WriteCH438Block(uint8_t mAddr, uint8_t mLen, char *mBuf)
{
while (mLen--)
while(mLen--)
WriteCH438Data(mAddr, *mBuf++);
}
@ -305,7 +305,7 @@ static void Ch438UartSend(uint8_t ext_uart_no, char *Data, uint16_t Num)
while(1)
{
while((ReadCH438Data(REG_LSR_ADDR) & BIT_LSR_TEMT ) == 0); /* 等待数据发送完毕THR,TSR全空 */
while((ReadCH438Data(REG_LSR_ADDR) & BIT_LSR_TEMT) == 0); /* 等待数据发送完毕THR,TSR全空 */
if(Num <= CH438_BUFFSIZE)
{
WriteCH438Block(REG_THR_ADDR, Num, Data);
@ -338,13 +338,13 @@ uint8_t CH438UARTRcv(uint8_t ext_uart_no, char* buf)
/* Wait for the data to be ready */
while((ReadCH438Data(REG_LSR_ADDR) & BIT_LSR_DATARDY) == 0 );
while((ReadCH438Data(REG_LSR_ADDR) & BIT_LSR_DATARDY) == 0x01 )
while((ReadCH438Data(REG_LSR_ADDR) & BIT_LSR_DATARDY) == 0x01)
{
dat = ReadCH438Data(REG_RBR_ADDR);
buff[ext_uart_no][buff_ptr[ext_uart_no]] = dat;
buff_ptr[ext_uart_no] = buff_ptr[ext_uart_no] + 1;
if (buff_ptr[ext_uart_no] == CH438_BUFFSIZE)
if(buff_ptr[ext_uart_no] == CH438_BUFFSIZE)
buff_ptr[ext_uart_no] = 0;
RcvNum = RcvNum + 1;
}
@ -408,7 +408,7 @@ static void CH438PortInit(uint8_t ext_uart_no, uint32_t baud_rate)
dlab |= 0x80;
WriteCH438Data(REG_LCR_ADDR, dlab);
div = ( Fpclk >> 4 ) / baud_rate;
div = (Fpclk >> 4) / baud_rate;
DLM = div >> 8;
DLL = div & 0xff;
@ -448,12 +448,12 @@ static int ImxrtCh438WriteData(uint8_t ext_uart_no, char *write_buffer, size_t s
write_len = size;;
write_len_continue = size;
if (write_len > CH438_BUFFSIZE)
if(write_len > CH438_BUFFSIZE)
{
if (0 == write_len % CH438_BUFFSIZE)
if(0 == write_len % CH438_BUFFSIZE)
{
write_index = write_len / CH438_BUFFSIZE;
for (i = 0; i < write_index; i ++)
for(i = 0; i < write_index; i ++)
{
Ch438UartSend(ext_uart_no, write_buffer + i * CH438_BUFFSIZE, CH438_BUFFSIZE);
}
@ -461,7 +461,7 @@ static int ImxrtCh438WriteData(uint8_t ext_uart_no, char *write_buffer, size_t s
else
{
write_index = 0;
while (write_len_continue > CH438_BUFFSIZE)
while(write_len_continue > CH438_BUFFSIZE)
{
Ch438UartSend(ext_uart_no, write_buffer + write_index * CH438_BUFFSIZE, CH438_BUFFSIZE);
write_index++;
@ -496,7 +496,7 @@ static size_t ImxrtCh438ReadData(uint8_t ext_uart_no)
pthread_mutex_lock(&mutex[ext_uart_no]);
while(done[ext_uart_no] == false)
pthread_cond_wait(&cond[ext_uart_no], &mutex[ext_uart_no]);
if (done[ext_uart_no] == true)
if(done[ext_uart_no] == true)
{
REG_IIR_ADDR = offsetadd[ext_uart_no] | REG_IIR0_ADDR;
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
@ -555,7 +555,7 @@ static void Ch438InitDefault(void)
for(i = 0; i < CH438PORTNUM; i++)
{
ret = pthread_mutex_init(&mutex[i], NULL);
if (ret != 0)
if(ret != 0)
{
ch438err("pthread_mutex_init failed, status=%d\n", ret);
}
@ -565,7 +565,7 @@ static void Ch438InitDefault(void)
for(i = 0; i < CH438PORTNUM; i++)
{
ret = pthread_cond_init(&cond[i], NULL);
if (ret != 0)
if(ret != 0)
{
ch438err("pthread_cond_init failed, status=%d\n", ret);
}
@ -575,8 +575,8 @@ static void Ch438InitDefault(void)
param.sched_priority = 60;
pthread_attr_setschedparam(&attr, &param);
pthread_attr_setstacksize(&attr, 2048);
ret = pthread_create(&thread, &attr, getInterruptStatus, NULL);
if (ret < 0)
ret = pthread_create(&thread, &attr, (void*)getInterruptStatus, NULL);
if(ret < 0)
{
ch438err("task create failed, status=%d\n", ret);
}
@ -602,7 +602,7 @@ static int ch438_open(FAR struct file *filep)
uint8_t port = priv->port;
DEBUGASSERT(port >= 0 && port < CH438PORTNUM);
if (g_ch438open[port])
if(g_ch438open[port])
{
return -EBUSY;
}
@ -639,7 +639,7 @@ static ssize_t ch438_read(FAR struct file *filep, FAR char *buffer, size_t bufle
length = ImxrtCh438ReadData(port);
memcpy(buffer, buff[port], length);
if (length > buflen)
if(length > buflen)
{
length = buflen;
}
@ -679,7 +679,7 @@ static int ch438_register(FAR const char *devpath, uint8_t port)
DEBUGASSERT(port >= 0 && port < CH438PORTNUM);
priv = (FAR struct ch438_dev_s *)kmm_malloc(sizeof(struct ch438_dev_s));
if (priv == NULL)
if(priv == NULL)
{
ch438err("ERROR: Failed to allocate instance\n");
return -ENOMEM;
@ -689,7 +689,7 @@ static int ch438_register(FAR const char *devpath, uint8_t port)
/* Register the character driver */
ret = register_driver(devpath, &g_ch438fops, 0666, priv);
if (ret < 0)
if(ret < 0)
{
ch438err("ERROR: Failed to register driver: %d\n", ret);
kmm_free(priv);