Merge pull request 'merge code' (#39) from prepare_for_master into ch438

ok
This commit is contained in:
wgzAIIT 2022-04-29 16:56:24 +08:00
commit c0061b66c6
3 changed files with 265 additions and 337 deletions

View File

@ -22,11 +22,13 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <nuttx/arch.h>
#include <unistd.h>
#include <stdint.h>
@ -39,7 +41,6 @@
#include <debug.h>
#include <poll.h>
#include <fcntl.h>
#include <syslog.h>
#include "imxrt_ch438.h"
@ -48,16 +49,22 @@
void CH438Demo(void)
{
int i=0;
syslog(LOG_INFO,"ch438_main\n");
_info("ch438_main\n");
Ch438InitDefault();
ch438_irq_enable();
up_mdelay(1000);
while(1)
{
CH438UARTSend(2,"AT+BAUD=?",9);
syslog(LOG_INFO,"send success\n");
ImxrtCh438ReadData(NULL);
up_mdelay(2000);
up_mdelay(1000);
CH438UARTSend(2,"AT+NAME=?",9);
ImxrtCh438ReadData(NULL);
up_mdelay(1000);
CH438UARTSend(2,"AT+ADDR=?",9);
ImxrtCh438ReadData(NULL);
up_mdelay(1000);
CH438UARTSend(2,"AT+MODE=?",9);
ImxrtCh438ReadData(NULL);
up_mdelay(1000);
}
}

View File

@ -22,7 +22,6 @@
#include <sys/types.h>
#include <errno.h>
#include <syslog.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
@ -41,25 +40,81 @@
#include <nuttx/time.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sched.h>
#include <debug.h>
/****************************************************************************
* Private Data
****************************************************************************/
/* Semaphore for receiving data */
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
volatile int done = 0;
static uint8_t RevLen;
static uint8_t buff[8][128];
static uint8_t buff_ptr[8];
static uint8_t Interruptnum[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,}; /* SSR寄存器中断号对应值 */
static uint8_t offsetadd[] = {0x00,0x10,0x20,0x30,0x08,0x18,0x28,0x38,}; /* 串口号的偏移地址 */
static uint8_t gInterruptStatus;
static pthread_t thr_438;
struct sched_param param;
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void ImxrtCH438Init(void);
static void CH438PortInit(uint8_t ext_uart_no,uint32_t baud_rate);
static void CH438SetOutput(void);
static void CH438SetInput(void);
static uint8_t ReadCH438Data(uint8_t addr);
static void WriteCH438Data(uint8_t addr, uint8_t dat);
static void WriteCH438Block(uint8_t mAddr, uint8_t mLen, uint8_t *mBuf);
static uint8_t CH438UARTRcv(uint8_t ext_uart_no, uint8_t* buf);
static char thr_438_stack[1024];
/****************************************************************************
* Public and Private Functions
****************************************************************************/
static sem_t sem_438; /* 用于接收的信号量 */
/* ch438中断回调函数 */
static int Ch438Irq(int irq, FAR void *context, FAR void *arg)
/****************************************************************************
* Name: getInterruptStatus
*
* Description:
* thread task getInterruptStatus
*
****************************************************************************/
int getInterruptStatus(int argc, char **argv)
{
sem_post(&sem_438);
up_mdelay(500);
return OK;
int ext_uart_no = 2;
while(1)
{
pthread_mutex_lock(&mutex);
gInterruptStatus = ReadCH438Data(REG_SSR_ADDR);
if(!gInterruptStatus)
{
pthread_mutex_unlock(&mutex);
continue;
}
if(gInterruptStatus & Interruptnum[ext_uart_no])
{
done = 1;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
}
}
/****************************************************************************
* Name: CH438SetOutput
*
* Description:
* Configure pin mode to output
*
****************************************************************************/
void CH438SetOutput(void)
{
imxrt_config_gpio(CH438_D0_PIN_OUT);
@ -72,6 +127,14 @@ void CH438SetOutput(void)
imxrt_config_gpio(CH438_D7_PIN_OUT);
}
/****************************************************************************
* Name: CH438SetInput
*
* Description:
* Configure pin mode to input
*
****************************************************************************/
void CH438SetInput(void)
{
imxrt_config_gpio(CH438_D0_PIN_INPUT);
@ -81,125 +144,105 @@ void CH438SetInput(void)
imxrt_config_gpio(CH438_D4_PIN_INPUT);
imxrt_config_gpio(CH438_D5_PIN_INPUT);
imxrt_config_gpio(CH438_D6_PIN_INPUT);
imxrt_config_gpio(CH438_D7_PIN_INPUT);
imxrt_config_gpio(CH438_D7_PIN_INPUT);
}
static uint8_t RevLen ,buff[8][128],buff_ptr[8];
static uint8_t Interruptnum[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,}; /* SSR寄存器中断号对应值 */
static uint8_t offsetadd[] = {0x00,0x10,0x20,0x30,0x08,0x18,0x28,0x38,}; /* 串口号的偏移地址 */
void* ImxrtCh438ReadData(void *parameter)
/****************************************************************************
* Name: ImxrtCh438ReadData
*
* Description:
* Read data from ch438 port
*
****************************************************************************/
void ImxrtCh438ReadData(void *parameter)
{
int result, i;
uint8_t gInterruptStatus;
uint8_t InterruptStatus;
uint8_t ext_uart_no;
static uint8_t dat;
uint8_t REG_LCR_ADDR;
uint8_t REG_DLL_ADDR;
uint8_t REG_DLM_ADDR;
uint8_t REG_IER_ADDR;
uint8_t REG_MCR_ADDR;
uint8_t REG_FCR_ADDR;
uint8_t REG_RBR_ADDR;
uint8_t REG_THR_ADDR;
uint8_t REG_IIR_ADDR;
uint8_t REG_LSR_ADDR;
uint8_t REG_MSR_ADDR;
// struct timespec abstime;
// abstime.tv_sec = 2;
// while (1)
// {
syslog(LOG_INFO, "sem_438 is %d\n",sem_438.semcount);
result = sem_wait(&sem_438);
if (result == OK)
{
gInterruptStatus = ReadCH438Data( REG_SSR_ADDR );
syslog(LOG_INFO,"gInterruptStatus is %d\n", gInterruptStatus);
if(!gInterruptStatus)
{
}
else
{
// for(ext_uart_no=0; ext_uart_no<8; ext_uart_no++)
// {
ext_uart_no = 2;
if( gInterruptStatus & Interruptnum[ext_uart_no] ) /* 检测哪个串口发生中断 */
{
REG_LCR_ADDR = offsetadd[ext_uart_no] | REG_LCR0_ADDR;
REG_DLL_ADDR = offsetadd[ext_uart_no] | REG_DLL0_ADDR;
REG_DLM_ADDR = offsetadd[ext_uart_no] | REG_DLM0_ADDR;
REG_IER_ADDR = offsetadd[ext_uart_no] | REG_IER0_ADDR;
REG_MCR_ADDR = offsetadd[ext_uart_no] | REG_MCR0_ADDR;
REG_FCR_ADDR = offsetadd[ext_uart_no] | REG_FCR0_ADDR;
REG_RBR_ADDR = offsetadd[ext_uart_no] | REG_RBR0_ADDR;
REG_THR_ADDR = offsetadd[ext_uart_no] | REG_THR0_ADDR;
REG_IIR_ADDR = offsetadd[ext_uart_no] | REG_IIR0_ADDR;
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
REG_MSR_ADDR = offsetadd[ext_uart_no] | REG_MSR0_ADDR;
InterruptStatus = ReadCH438Data( REG_IIR_ADDR ) & 0x0f; /* 读串口的中断状态 */
syslog(LOG_INFO,"InterruptStatus is %d\n", InterruptStatus);
switch( InterruptStatus )
{
case INT_NOINT: /* 没有中断 */
break;
case INT_THR_EMPTY: /* THR空中断 */
// ReadCH438Data( REG_IIR_ADDR );
break;
case INT_RCV_OVERTIME: /* 接收超时中断,收到数据后一般是触发这个 。在收到一帧数据后4个数据时间没有后续的数据时触发*/
case INT_RCV_SUCCESS: /* 接收数据可用中断。这是一个数据帧超过缓存了才发生,否则一般是前面的超时中断。处理过程同上面的超时中断 */
RevLen = CH438UARTRcv(ext_uart_no, buff[ext_uart_no]);
for(i=0;i<RevLen;++i)
{
syslog(LOG_INFO,"%c(0x%x) ", buff[ext_uart_no][i], buff[ext_uart_no][i]);
}
for(i=0;i<128;i++)
buff[ext_uart_no][i] = 0;
buff_ptr[ext_uart_no] = 0;
break;
case INT_RCV_LINES: /* 接收线路状态中断 */
ReadCH438Data( REG_LSR_ADDR );
break;
case INT_MODEM_CHANGE: /* MODEM输入变化中断 */
ReadCH438Data( REG_MSR_ADDR );
break;
default:
// ReadCH438Data( REG_IIR_ADDR );
break;
}
}
// }
}
}
pthread_mutex_lock(&mutex);
while(done == 0)
pthread_cond_wait(&cond, &mutex);
if (done == 1)
{
ext_uart_no = 2;
REG_IIR_ADDR = offsetadd[ext_uart_no] | REG_IIR0_ADDR;
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
REG_MSR_ADDR = offsetadd[ext_uart_no] | REG_MSR0_ADDR;
InterruptStatus = ReadCH438Data(REG_IIR_ADDR) & 0x0f; /* 读串口的中断状态 */
_info("InterruptStatus is %d\n", InterruptStatus);
// }
switch( InterruptStatus )
{
case INT_NOINT: /* 没有中断 */
break;
case INT_THR_EMPTY: /* THR空中断 */
break;
case INT_RCV_OVERTIME: /* 接收超时中断,收到数据后一般是触发这个 。在收到一帧数据后4个数据时间没有后续的数据时触发*/
case INT_RCV_SUCCESS: /* 接收数据可用中断。这是一个数据帧超过缓存了才发生,否则一般是前面的超时中断。处理过程同上面的超时中断 */
RevLen = CH438UARTRcv(ext_uart_no, buff[ext_uart_no]);
for(i=0;i<RevLen;++i)
{
_info("%c(0x%x)\n", buff[ext_uart_no][i], buff[ext_uart_no][i]);
}
for(i=0;i<128;i++)
buff[ext_uart_no][i] = 0;
buff_ptr[ext_uart_no] = 0;
break;
case INT_RCV_LINES: /* 接收线路状态中断 */
ReadCH438Data(REG_LSR_ADDR);
break;
case INT_MODEM_CHANGE: /* MODEM输入变化中断 */
ReadCH438Data(REG_MSR_ADDR);
break;
default:
break;
}
}
pthread_mutex_unlock(&mutex);
}
/****************************************************************************
* Name: Ch438InitDefault
*
* Description:
* Ch438 default initialization function
*
****************************************************************************/
void Ch438InitDefault(void)
{
int ret = 0;
sem_init(&sem_438, 0, 0);
syslog(LOG_INFO,"sem_438 init is %d\n",sem_438.semcount);
// attr.priority = 120;
// attr.stacksize = 8192;
// ret = pthread_create(&thr_438, &attr, &ImxrtCh438ReadData, NULL);
if (ret != 0){
syslog(LOG_INFO,"ImxrtCh438ReadData: task create failed, status=%d\n", ret);
}
int ret;
/* Initialize the mutex */
ret = pthread_mutex_init(&mutex, NULL);
if (ret != 0)
{
_info("pthread_mutex_init failed, status=%d\n", ret);
}
/* Initialize the condition variable */
ret = pthread_cond_init(&cond, NULL);
if (ret != 0)
{
_info("pthread_cond_init failed, status=%d\n", ret);
}
ret = task_create("ch438_task", 60, 8192, getInterruptStatus, NULL);
if (ret < 0)
{
_info("task create failed, status=%d\n", ret);
}
ImxrtCH438Init();
CH438PortInit(0,115200);
CH438PortInit(1,115200);
@ -209,47 +252,17 @@ void Ch438InitDefault(void)
CH438PortInit(5,115200);
CH438PortInit(6,115200);
CH438PortInit(7,115200);
up_mdelay(10);
imxrt_config_gpio(CH438_INT_PIN);
irq_attach(IMXRT_IRQ_GPIO3_3, Ch438Irq, NULL);
}
void ch438_irq_enable(void)
{
//重新对每个串口初始化
CH438PortInit(0,115200);
CH438PortInit(1,115200);
CH438PortInit(2,9600);
CH438PortInit(3,9600);
CH438PortInit(4,115200);
CH438PortInit(5,115200);
CH438PortInit(6,115200);
CH438PortInit(7,115200);
/* 使能中断 */
up_enable_irq(IMXRT_IRQ_GPIO3_3);
//以下代码测试用。用于enable时向所有串口发一串数据
up_mdelay(20);
CH438UARTSend(0,"#1234ABCD!",10);
CH438UARTSend(1,"#1234ABCD!",10);
CH438UARTSend(2,"#1234ABCD!",10);
CH438UARTSend(3,"#1234ABCD!",10);
CH438UARTSend(4,"#1234ABCD!",10);
CH438UARTSend(5,"#1234ABCD!",10);
CH438UARTSend(6,"#1234ABCD!",10);
CH438UARTSend(7,"#1234ABCD!",10);
up_mdelay(20);
}
/****************************************************************************
* Name: ImxrtCH438Init
*
* Description:
* ch438 initialization
*
****************************************************************************/
static void ImxrtCH438Init(void)
{
uint8_t dat;
CH438SetOutput();
imxrt_config_gpio(CH438_NWR_PIN);
imxrt_config_gpio(CH438_NRD_PIN);
@ -259,8 +272,15 @@ static void ImxrtCH438Init(void)
imxrt_gpio_write(CH438_NRD_PIN,true);
imxrt_gpio_write(CH438_ALE_PIN,true);
}
static void CH438PortInit( uint8_t ext_uart_no,uint32_t baud_rate )
/****************************************************************************
* Name: CH438PortInit
*
* Description:
* ch438 port initialization
*
****************************************************************************/
static void CH438PortInit(uint8_t ext_uart_no,uint32_t baud_rate)
{
uint32_t div;
uint8_t DLL,DLM,dlab;
@ -270,10 +290,6 @@ static void CH438PortInit( uint8_t ext_uart_no,uint32_t baud_rate )
uint8_t REG_IER_ADDR;
uint8_t REG_MCR_ADDR;
uint8_t REG_FCR_ADDR;
uint8_t REG_RBR_ADDR;
uint8_t REG_THR_ADDR;
uint8_t REG_IIR_ADDR;
uint8_t dat;
REG_LCR_ADDR = offsetadd[ext_uart_no] | REG_LCR0_ADDR;
REG_DLL_ADDR = offsetadd[ext_uart_no] | REG_DLL0_ADDR;
@ -281,24 +297,14 @@ static void CH438PortInit( uint8_t ext_uart_no,uint32_t baud_rate )
REG_IER_ADDR = offsetadd[ext_uart_no] | REG_IER0_ADDR;
REG_MCR_ADDR = offsetadd[ext_uart_no] | REG_MCR0_ADDR;
REG_FCR_ADDR = offsetadd[ext_uart_no] | REG_FCR0_ADDR;
REG_RBR_ADDR = offsetadd[ext_uart_no] | REG_RBR0_ADDR;
REG_THR_ADDR = offsetadd[ext_uart_no] | REG_THR0_ADDR;
REG_IIR_ADDR = offsetadd[ext_uart_no] | REG_IIR0_ADDR;
WriteCH438Data( REG_IER_ADDR, BIT_IER_RESET ); /* 复位该串口 */
WriteCH438Data(REG_IER_ADDR, BIT_IER_RESET); /* 复位该串口 */
up_mdelay(50);
// dat = ReadCH438Data(REG_FCR_ADDR);
// dat = ReadCH438Data(REG_LCR_ADDR);
dlab = ReadCH438Data(REG_IER_ADDR);
dlab &= 0xDF;
WriteCH438Data(REG_IER_ADDR, dlab);
// WriteCH438Data( REG_LCR_ADDR, BIT_LCR_DLAB ); /* 设置DLAB为1 */
dlab = ReadCH438Data(REG_LCR_ADDR);
dlab |= 0x80; //置LCR寄存器DLAB位为1
WriteCH438Data(REG_LCR_ADDR, dlab);
@ -306,50 +312,25 @@ static void CH438PortInit( uint8_t ext_uart_no,uint32_t baud_rate )
div = ( Fpclk >> 4 ) / baud_rate;
DLM = div >> 8;
DLL = div & 0xff;
WriteCH438Data( REG_DLL_ADDR, DLL ); /* 设置波特率 */
WriteCH438Data( REG_DLM_ADDR, DLM );
WriteCH438Data( REG_FCR_ADDR, BIT_FCR_RECVTG1 | BIT_FCR_RECVTG0 | BIT_FCR_FIFOEN ); /* 设置FIFO模式触发点为112字节 */
WriteCH438Data( REG_LCR_ADDR, BIT_LCR_WORDSZ1 | BIT_LCR_WORDSZ0 ); /* 字长8位1位停止位、无校验 */
// if(ext_uart_no==1)
// WriteCH438Data( REG_IER_ADDR, 0x00 ); /* 使能中断 */
// else
WriteCH438Data( REG_IER_ADDR, /*BIT_IER_IEMODEM | BIT_IER_IETHRE | BIT_IER_IELINES | */BIT_IER_IERECV ); /* 使能中断 */
WriteCH438Data( REG_MCR_ADDR, BIT_MCR_OUT2 );// | BIT_MCR_RTS | BIT_MCR_DTR ); /* 允许中断输出,DTR,RTS为1 */
WriteCH438Data(REG_FCR_ADDR,ReadCH438Data(REG_FCR_ADDR)| BIT_FCR_TFIFORST); /* 清空FIFO中的数据 */
WriteCH438Data(REG_DLL_ADDR, DLL); /* 设置波特率 */
WriteCH438Data(REG_DLM_ADDR, DLM);
WriteCH438Data(REG_FCR_ADDR, BIT_FCR_RECVTG1 | BIT_FCR_RECVTG0 | BIT_FCR_FIFOEN); /* 设置FIFO模式触发点为112字节 */
WriteCH438Data(REG_LCR_ADDR, BIT_LCR_WORDSZ1 | BIT_LCR_WORDSZ0 ); /* 字长8位1位停止位、无校验 */
WriteCH438Data(REG_IER_ADDR, BIT_IER_IERECV); /* 使能中断 */
WriteCH438Data(REG_MCR_ADDR, BIT_MCR_OUT2);// | BIT_MCR_RTS | BIT_MCR_DTR ); /* 允许中断输出,DTR,RTS为1 */
WriteCH438Data(REG_FCR_ADDR, ReadCH438Data(REG_FCR_ADDR)| BIT_FCR_TFIFORST); /* 清空FIFO中的数据 */
}
/*********************************************************************************************************
** : ReadCH438Data
** : CH438地址读取数据
**  :
**
**  :
**
**  : 2011826
**-------------------------------------------------------------------------------------------------------
** :
**  :
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static uint8_t ReadCH438Data( uint8_t addr )
/****************************************************************************
* Name: ReadCH438Data
*
* Description:
* Read data from ch438 address
*
****************************************************************************/
static uint8_t ReadCH438Data(uint8_t addr)
{
//读函数
//ALE WR RD线空闲都为高电平读取数据时候先将地址放在并口然后拉低ALE锁存地址延时保持
//切换引脚输入拉低RD读信号线延时等待读取并口上数据
//撤销RD撤销ALE
uint8_t dat;
// imxrt_gpio_write(CH438_NCS_PIN,true);
uint8_t dat = 0;
imxrt_gpio_write(CH438_NWR_PIN, true);
imxrt_gpio_write(CH438_NRD_PIN, true);
imxrt_gpio_write(CH438_ALE_PIN, true);
@ -379,7 +360,6 @@ static uint8_t ReadCH438Data( uint8_t addr )
up_udelay(1);
dat = 0;
if (imxrt_gpio_read(CH438_D7_PIN_INPUT)) dat |= 0x80;
if (imxrt_gpio_read(CH438_D6_PIN_INPUT)) dat |= 0x40;
if (imxrt_gpio_read(CH438_D5_PIN_INPUT)) dat |= 0x20;
@ -397,8 +377,15 @@ static uint8_t ReadCH438Data( uint8_t addr )
return dat;
}
static void WriteCH438Data( uint8_t addr, uint8_t dat)
/****************************************************************************
* Name: WriteCH438Data
*
* Description:
* write data to ch438 address
*
****************************************************************************/
static void WriteCH438Data(uint8_t addr, uint8_t dat)
{
imxrt_gpio_write(CH438_ALE_PIN, true);
imxrt_gpio_write(CH438_NRD_PIN, true);
@ -447,133 +434,76 @@ static void WriteCH438Data( uint8_t addr, uint8_t dat)
}
/*********************************************************************************************************
** : WriteCH438Block
** : CH438地址写入数据块
**  : CH438寄存器地址,,
**
**  :
**
**  : 2011826
**-------------------------------------------------------------------------------------------------------
** :
**  :
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static void WriteCH438Block( uint8_t mAddr, uint8_t mLen, uint8_t *mBuf )
/****************************************************************************
* Name: WriteCH438Block
*
* Description:
* Write data block from ch438 address
*
****************************************************************************/
static void WriteCH438Block(uint8_t mAddr, uint8_t mLen, uint8_t *mBuf)
{
while ( mLen -- )
WriteCH438Data( mAddr, *mBuf++ );
while (mLen--)
WriteCH438Data(mAddr, *mBuf++);
}
///*********************************************************************************************************
//** 函数名称: CH438UARTSend
//** 功能描述: 功能函数启用FIFO模式, 用于CH438串口0 发送多字节数据 单次最多发送128字节数据
//** 输 入: 发送数据缓冲区地址, 发送数据块长度
//**
//** 输 出: 无
//**
//** 日 期: 2011年8月26日
//**-------------------------------------------------------------------------------------------------------
//** 修改人:
//** 日 期:
//**-------------------------------------------------------------------------------------------------------
//********************************************************************************************************/
void CH438UARTSend( uint8_t ext_uart_no, uint8_t *Data, uint8_t Num )
/****************************************************************************
* Name: CH438UARTSend
*
* Description:
* Enable FIFO mode, which is used for ch438 serial port to send multi byte data,
* with a maximum of 128 bytes of data sent at a time
*
****************************************************************************/
void CH438UARTSend(uint8_t ext_uart_no, uint8_t *Data, uint8_t Num)
{
uint8_t REG_LSR_ADDR,REG_THR_ADDR;
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
REG_THR_ADDR = offsetadd[ext_uart_no] | REG_THR0_ADDR;
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
REG_THR_ADDR = offsetadd[ext_uart_no] | REG_THR0_ADDR;
while( 1 )
while(1)
{
while( ( ReadCH438Data( REG_LSR_ADDR ) & BIT_LSR_TEMT ) == 0 ); /* 等待数据发送完毕THR,TSR全空 */
if( Num <= 128 )
while((ReadCH438Data(REG_LSR_ADDR) & BIT_LSR_TEMT ) == 0); /* 等待数据发送完毕THR,TSR全空 */
if(Num <= 128)
{
WriteCH438Block( REG_THR_ADDR, Num, Data );
WriteCH438Block(REG_THR_ADDR, Num, Data);
break;
}
else
{
WriteCH438Block( REG_THR_ADDR, 128, Data );
WriteCH438Block(REG_THR_ADDR, 128, Data);
Num -= 128;
Data += 128;
}
}
}
/*********************************************************************************************************
** : CH438UARTRcv
** : FIFO模式, CH438串口0
**  :
**
**  :
**
**  : 2011826
**-------------------------------------------------------------------------------------------------------
** :
**  :
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8_t CH438UARTRcv( uint8_t ext_uart_no, uint8_t* buf )
/****************************************************************************
* Name: CH438UARTRcv
*
* Description:
* Disable FIFO mode for ch438 serial port to receive multi byte data
*
****************************************************************************/
uint8_t CH438UARTRcv(uint8_t ext_uart_no, uint8_t* buf)
{
uint8_t RcvNum = 0;
uint8_t dat = 0;
uint8_t REG_LSR_ADDR,REG_RBR_ADDR;
uint8_t *p_rev;
p_rev = buf;
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
REG_RBR_ADDR = offsetadd[ext_uart_no] | REG_RBR0_ADDR;
// if( !( ReadCH438Data( REG_LSR_ADDR ) & ( BIT_LSR_BREAKINT | BIT_LSR_FRAMEERR | BIT_LSR_PARERR | BIT_LSR_OVERR ) ) ) /* b1-b4无错误 */
// if( !( dat & ( BIT_LSR_BREAKINT | BIT_LSR_FRAMEERR | BIT_LSR_PARERR | BIT_LSR_OVERR ) ) ) /* b1-b4无错误 */ 不用管这有没有错误,只管 DATAREADY
{
REG_LSR_ADDR = offsetadd[ext_uart_no] | REG_LSR0_ADDR;
REG_RBR_ADDR = offsetadd[ext_uart_no] | REG_RBR0_ADDR;
while( ( ReadCH438Data( REG_LSR_ADDR ) & BIT_LSR_DATARDY ) == 0 ); /* 等待数据准备好 */
while( ( ReadCH438Data( REG_LSR_ADDR ) & BIT_LSR_DATARDY ) == 0x01 )
{
// *buf++ = ReadCH438Data( REG_RBR_ADDR ); /* 从接收缓冲寄存器读出数据 */
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] == 128)
buff_ptr[ext_uart_no] = 0;
RcvNum = RcvNum + 1;
}
}
// else ReadCH438Data( REG_RBR_ADDR );
return( RcvNum );
while((ReadCH438Data(REG_LSR_ADDR) & BIT_LSR_DATARDY) == 0 ); /* 等待数据准备好 */
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] == 128)
buff_ptr[ext_uart_no] = 0;
RcvNum = RcvNum + 1;
}
return RcvNum;
}

View File

@ -299,19 +299,10 @@
GPIO_PORT1 | GPIO_PIN29)
static void ImxrtCH438Init(void);
static void CH438PortInit( uint8_t ext_uart_no,uint32_t baud_rate );
static void CH438SetOutput(void);
static void CH438SetInput(void);
static uint8_t ReadCH438Data( uint8_t addr );
static void WriteCH438Data( uint8_t addr, uint8_t dat);
static void WriteCH438Block( uint8_t mAddr, uint8_t mLen, uint8_t *mBuf ) ;
void CH438UARTSend( uint8_t ext_uart_no,uint8_t *Data, uint8_t Num );
static uint8_t CH438UARTRcv( uint8_t ext_uart_no, uint8_t* buf );
void CH438UARTSend(uint8_t ext_uart_no,uint8_t *Data, uint8_t Num);
void Ch438InitDefault(void);
void ch438_irq_enable(void);
void *ImxrtCh438ReadData(void *parameter);
void ImxrtCh438ReadData(void *parameter);
int getInterruptStatus(int argc, char **argv);
#endif