move include files to imxrt_ch438.h on nuttx and change board_ch438_initialize

This commit is contained in:
wgzAIIT 2022-05-06 10:18:22 +08:00
parent e007b5567d
commit 522b8848a2
4 changed files with 120 additions and 92 deletions

View File

@ -21,58 +21,30 @@
/****************************************************************************
* 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>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <debug.h>
#include <poll.h>
#include <fcntl.h>
#include "imxrt_ch438.h"
#define TMP (GPIO_OUTPUT | IOMUX_GOUT_DEFAULT | \
GPIO_PORT3 | GPIO_PIN3)
void CH438Demo(void)
{
int fd1,fd2;
int fd;
int i;
char buffer[256];
int readlen;
fd1 = open("/dev/extuart_dev2", O_RDWR);
write(fd1, "AT+BAUD=?",9);
readlen = read(fd1, buffer, 256);
for(i=0;i<readlen;++i)
while(1)
{
printf("%c(0x%x)\n", buffer[i], buffer[i]);
fd = open("/dev/extuart_dev2", O_RDWR);
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);
}
close(fd1);
up_mdelay(1000);
fd2 = open("/dev/extuart_dev1", O_RDWR);
write(fd2, "AT+BAUD=?",9);
readlen = read(fd2, buffer, 256);
for(i=0;i<readlen;++i)
{
printf("%c(0x%x)\n", buffer[i], buffer[i]);
}
close(fd2);
}

View File

@ -152,7 +152,6 @@ int imxrt_bringup(void)
if (ret != OK)
{
syslog(LOG_ERR, "ERROR: Failed to start USB host services: %d\n", ret);
return ret;
}
#endif
@ -171,7 +170,6 @@ int imxrt_bringup(void)
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret);
return ret;
}
#endif
@ -186,7 +184,12 @@ int imxrt_bringup(void)
#endif
#ifdef CONFIG_BSP_USING_CH438
board_ch438_initialize();
ret = board_ch438_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize ch438 Driver: %d\n", ret);
}
#endif
UNUSED(ret);

View File

@ -18,33 +18,7 @@
* @date 2022.04.26
*/
#include <nuttx/config.h>
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/pthread.h>
#include <nuttx/semaphore.h>
#include <nuttx/time.h>
#include <nuttx/fs/fs.h>
#include <sys/types.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sched.h>
#include <debug.h>
#include <assert.h>
#include <arch/board/board.h>
#include "arm_arch.h"
#include "imxrt_config.h"
#include "imxrt_irq.h"
#include "imxrt_gpio.h"
#include "imxrt_ch438.h"
#include "xidatong.h"
#define CH438PORTNUM 8
#define BUFFERSIZE 128
@ -74,7 +48,7 @@ static ssize_t ch438_write(FAR struct file *filep, FAR const char *buffer, size_
****************************************************************************/
struct ch438_dev_s
{
uint8_t port; /* ch438 port number*/
uint8_t port; /* ch438 port number*/
};
/****************************************************************************
@ -271,14 +245,12 @@ static uint8_t ReadCH438Data(uint8_t addr)
up_udelay(1);
imxrt_gpio_write(CH438_ALE_PIN, false);
up_udelay(1);
CH438SetInput();
up_udelay(1);
imxrt_gpio_write(CH438_NRD_PIN, false);
up_udelay(1);
if (imxrt_gpio_read(CH438_D7_PIN_INPUT)) dat |= 0x80;
@ -292,7 +264,6 @@ static uint8_t ReadCH438Data(uint8_t addr)
imxrt_gpio_write(CH438_NRD_PIN, true);
imxrt_gpio_write(CH438_ALE_PIN, true);
up_udelay(1);
return dat;
@ -341,12 +312,10 @@ static void WriteCH438Data(uint8_t addr, uint8_t dat)
up_udelay(1);
imxrt_gpio_write(CH438_NWR_PIN, false);
up_udelay(1);
imxrt_gpio_write(CH438_NWR_PIN, true);
imxrt_gpio_write(CH438_ALE_PIN, true);
up_udelay(1);
CH438SetInput();
@ -639,39 +608,84 @@ int ch438_register(FAR const char *devpath, uint8_t port)
* ch438 initialize
*
****************************************************************************/
void board_ch438_initialize(void)
int board_ch438_initialize(void)
{
int ret = 0;
Ch438InitDefault();
#ifdef CONFIG_CH438_EXTUART0
ch438_register("/dev/extuart_dev0", 0);
ret = ch438_register("/dev/extuart_dev0", 0);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev0: %d\n", ret);
goto __exit;
}
#endif
#ifdef CONFIG_CH438_EXTUART1
ch438_register("/dev/extuart_dev1", 1);
ret = ch438_register("/dev/extuart_dev1", 1);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev1: %d\n", ret);
goto __exit;
}
#endif
#ifdef CONFIG_CH438_EXTUART2
ch438_register("/dev/extuart_dev2", 2);
ret = ch438_register("/dev/extuart_dev2", 2);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev2: %d\n", ret);
goto __exit;
}
#endif
#ifdef CONFIG_CH438_EXTUART3
ch438_register("/dev/extuart_dev3", 3);
ret = ch438_register("/dev/extuart_dev3", 3);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev3: %d\n", ret);
goto __exit;
}
#endif
#ifdef CONFIG_CH438_EXTUART4
ch438_register("/dev/extuart_dev4", 4);
ret = ch438_register("/dev/extuart_dev4", 4);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev4: %d\n", ret);
goto __exit;
}
#endif
#ifdef CONFIG_CH438_EXTUART5
ch438_register("/dev/extuart_dev5", 5);
ret = ch438_register("/dev/extuart_dev5", 5);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev5: %d\n", ret);
goto __exit;
}
#endif
#ifdef CONFIG_CH438_EXTUART6
ch438_register("/dev/extuart_dev6", 6);
ret = ch438_register("/dev/extuart_dev6", 6);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev6: %d\n", ret);
goto __exit;
}
#endif
#ifdef CONFIG_CH438_EXTUART7
ch438_register("/dev/extuart_dev7", 7);
ret = ch438_register("/dev/extuart_dev7", 7);
if (ret < 0)
{
ch438err("Failed to register /dev/extuart_dev7: %d\n", ret);
goto __exit;
}
#endif
__exit:
return ret;
}

View File

@ -18,9 +18,44 @@
* @date 2022.04.26
*/
#ifndef __QC_TEST_CH438__
#define __QC_TEST_CH438__
#ifndef __BOARDS_ARM_IMXRT_XIDATONG_SRC_IMXRT_CH438_H
#define __BOARDS_ARM_IMXRT_XIDATONG_SRC_IMXRT_CH438_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/pthread.h>
#include <nuttx/semaphore.h>
#include <nuttx/time.h>
#include <nuttx/fs/fs.h>
#include <nuttx/arch.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sched.h>
#include <debug.h>
#include <assert.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <arch/board/board.h>
#include "arm_arch.h"
#include "imxrt_config.h"
#include "imxrt_irq.h"
#include "imxrt_gpio.h"
#include "xidatong.h"
/******************************************************************************************/
@ -300,7 +335,7 @@
#ifdef CONFIG_DEBUG_CH438_ERROR
# define ch438err _err
# define ch438err _err
#else
# define ch438err _none
#endif
@ -320,8 +355,12 @@
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef CONFIG_BSP_USING_CH438
int getInterruptStatus(int argc, char **argv);
void Ch438InitDefault(void);
int ch438_register(FAR const char *devpath,uint8_t port);
void board_ch438_initialize(void);
int board_ch438_initialize(void);
#endif
#endif /* __BOARDS_ARM_IMXRT_XIDATONG_SRC_IMXRT_CH438_H */