Включение и тестирование локальной обратной связи для UART

Я пытаюсь выполнить внутреннее обратное тестирование UART и внести изменения, приведенные ниже.

 #include <fcntl.h>
 #include <stdio.h>
 #include <termios.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/errno.h>
 #include <sys/types.h>
 #include <unistd.h>


 #define CCSR_BASE  0xfe000000
 #define UART1_BASE 0x11c000
 #define UART1_LEN  0x1000

 static volatile unsigned long  *uartReg = MAP_FAILED;

/* Map in registers. */
static unsigned long  *initMapMem(int fd, unsigned long addr, unsigned long len)
{
     return (unsigned long *) mmap(0, len,
            PROT_READ|PROT_WRITE|PROT_EXEC,MAP_SHARED|MAP_LOCKED, fd, addr);
}

int uartInitialise(void)
{
    int fd;
    int i;

    fd = open("/dev/mem", O_RDWR | O_SYNC) ;

    if (fd < 0)
       {
           fprintf(stderr,"This program needs root privileges.Try sudo /n");
           return -1;
       }

   uartReg  = initMapMem(fd, ((CCSR_BASE) + (UART1_BASE))  , UART1_LEN);

   /* In local loop back mode, data written to UTHR(8 bit) can be read from the 
      receiver buffer register(URBR 8 bit) of the same UART. */

 //    *(uartReg + 0x605 )  = 0x0;

       *(uartReg + (0x600)) = 0xf;

       printf("UART_REG : %#x\n", *(int *)(uartReg + (0x600)); /*Expecting 0xf to read here if loop back mode is set */

       close(fd);

  if (uartReg == MAP_FAILED)
     {
        fprintf(stderr,"Bad, mmap failed\n");
        return -1;
     }

    return 0;
}

 int main()
 {
    int pins;
    int f = open( "/dev/ttyS1", O_RDWR);

    if (f< 0)
    {
        printf("\nout");
        close(f);
     }   

    ioctl( f, TIOCMGET, &pins);
    ioctl( f, TIOCMSET, pins | TIOCM_LOOP);

    if (uartInitialise() < 0) return 1;

    sleep(5);

   ioctl( f, TIOCMGET, &pins);
   ioctl( f, TIOCMSET, pins & ~ TIOCM_LOOP);

 }

root @ amit: ~ # ./loop_back

UART_REG: 0

Но я не получаю ожидаемого результата, может ли кто-нибудь указать мне, что нужно сделать, чтобы провести внутреннее тестирование UART?

Ответы на вопрос(0)

Ваш ответ на вопрос