Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    emard
    @emard
    Or maybe not really always but thats the first approximation :)
    anways I can later take your example and try to fit :)
    Paul Ruiz
    @pnru_gitlab

    Are you sure that Saxon Linux says that serial is not a TTY? That would be odd in a historical context, where all TTY's were connected via a serial line...

    To set a TTY to raw input mode with ioctl() see this page that explains it in great detail (but is a quick and pleasant read). The call tcgetattr(fd, &termcfg) can be replaced by ioctl(fd, TCGETS, &termcfg) (or TCSETSW for tcsetattr).
    The definitions for termios are e.g. here:
    https://code.woboq.org/gcc/include/bits/termios.h.html
    The Tetris source code has something similar to this in the vt100_initialize subroutine.

    Lawrie Griffiths
    @lawrie
    include <stdio.h>
    #include <unistd.h>
    #include <errno.h>
    
    #define KDGETMODE        0x4B3B
    #define KDSETMODE        0x4B3A 
    
    int main() {
      int r;
      int mode;
    
      r = ioctl(0, KDGETMODE, &mode);
    
      printf("Result: %d\n", r);
      printf("errno: %d\n", errno);
    
      return 0;
    }
    root@buildroot:~# ./a.out
    Result: -1
    errno: 25
    Paul Ruiz
    @pnru_gitlab
    Ah, I read up on KDGET/SETMODE and it is for the console only. It uses ENOTTY to signal that the device is not a console TTY.
    Lawrie Griffiths
    @lawrie
    This works quite well:
    #include <stdio.h>
    #include <unistd.h>
    #include <errno.h>
    
    #define FIONBIO      0x5421
    
    #define TCGETS           0x5401
    #define TCSETS           0x5402
    
    #define ECHO             0000010
    #define ICANON           0000002
    
    typedef unsigned char    cc_t;
    typedef unsigned int     speed_t;
    typedef unsigned int     tcflag_t;
    
    #define NCCS             32
    
    struct termios {
        tcflag_t c_iflag;                /* input mode flags */
        tcflag_t c_oflag;                /* output mode flags */
        tcflag_t c_cflag;                /* control mode flags */
        tcflag_t c_lflag;                /* local mode flags */
        cc_t c_line;                     /* line discipline */
        cc_t c_cc[NCCS];                 /* control characters */
        speed_t c_ispeed;                /* input speed */
        speed_t c_ospeed;                /* output speed */
    #define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
    #define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
      };
    
    int main() {
      int r;
      int mode;
      char buf[2];
      struct termios raw, orig;
    
      buf[1] = 0;
    
      r = ioctl(0, TCGETS, &orig);
      raw = orig;
    
      raw.c_lflag &= ~(ECHO | ICANON);
    
      r = ioctl(0, TCSETS, &raw);
    
      mode = 1;
      r = ioctl(0, FIONBIO, &mode);
    
      do {
        r = read(0, buf, 1);
        if (r > 0)  {
          printf("key is %d\n", buf[0]);
          if (buf[0] == 'q') break;
        } else write(1,"!",1);
      } while (1);
    
      mode = 0;
      r = ioctl(0, FIONBIO, &mode);
    
      r = ioctl(0, TCSETS, &orig);
    
      return 0;
    }
    Dolu1990
    @Dolu1990
    Got I2C on linux using the i2c-gpio driver to work
    I mean, i can the the frame XD
    didn't test with real slave
    Lawrie Griffiths
    @lawrie
    What pins are you using it on? To access the RTC, we will need to make the RTC pins gpioA pins in the lpf file.
    LOCATE COMP "system_hdmiPhy_gpdi_sda" SITE "B19"; # I2C shared with RTC
    LOCATE COMP "system_hdmiPhy_gpdi_scl" SITE "E12"; # I2C shared with RTC C12->E12
    Dolu1990
    @Dolu1990
    I was currently testing on arty A7, i'm now porting it to Ulx3s on those pins
    on ulx
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab How do you think we should implement sleep in the lcc library?
    Dolu1990
    @Dolu1990
    For the RTC, is there anything special to configure on the board to get it alive on I2C ?
    should work without battery i guess
    emard
    @emard
    No board immediately has i2c to RTC. It is called in my constraints gpdi_sda, gpdi_scl. Its not only gpdi but it is shared bus with GPDI and RTC. Maybe I could just have called it i2c_sda i2c_scl :)
    Dolu1990
    @Dolu1990
    Rawrrr
    root@buildroot:~# i2cdetect -y 0
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f 
    70: -- -- -- -- -- -- -- --                         
    root@buildroot:~#
    emard
    @emard
    RTC completey works without battery but of course wont keep time after power off
    Yes 0x6F is RTCs address :)
    This is very promising for RTC and shutdown/wakeup capability :)
    Paul Ruiz
    @pnru_gitlab

    @pnru_gitlab How do you think we should implement sleep in the lcc library?

    See here for some ideas. Untested code.

    Dolu1990
    @Dolu1990
    apparently there is a driver in linux for that rtc (rtc-ds1307.c)
    emard
    @emard
    :) maybe a compatible enough one, as we have MCP7940N (microchip). Most of them RTC are very similar and have important time registers with equal meaning
    our RTC has to be initialized to start ticking. Power on default without battery is to "boot" as stopped.
    Dolu1990
    @Dolu1990
    got the rtc to start counting seconds and read it via :
    i2cset -y 0 0x6F 0x00 0x80
    sleep 4
    i2cget -y 0 0x6F 0x00
    emard
    @emard
    eheheheee it is great, it works!
    Uninitialized RTC outputs 32768Hz to boards internal wakeup pin. In this state board cant shutdown. RTC has to be initialized as alarm in future and its flag cleared, then it is possible that board sleeps in power off until alarm triggers
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab Here is a test of your sleep code:
    #include <stdio.h>
    
    extern int sleep(int sec);
    extern int usleep(int usec);
    
    int main() {
      printf("Sleep for 2 seconds\n");
      sleep(2);
      printf("Sleep for 1M microseconds\n");
      usleep(1000000);
    
      return 0;
    }
    
    root@buildroot:~# time ./a.out
    Sleep for 2 seconds
    Sleep for 1M microseconds
    real    0m 3.02s
    user    0m 0.00s
    sys    0m 0.01s
    Dolu1990
    @Dolu1990
    I pushed the changes for i2c, it require saxon_netlist ; saxon_bitstream; saxon_buildroot_setup; saxon_buildroot_compile
    The sdcard should be completly reupdated.
    I2c mounted in /dev/i2c-0
    emard
    @emard
    Wonderful! I will have something to play :)
    It is not urgent but the proper time handing is what I always expect from each quality OS since DOS :)
    Paul Ruiz
    @pnru_gitlab
    @lawrie Great! I guess the official function prototypes are a bit different from what I have. sleep() uses unsigned int I believe, and sleep() takes a usecond_t type. In the end all the same bits of course.
    Lawrie Griffiths
    @lawrie
    @Dolu1990 @emard I have built a 12F version of the new SaxonSoc version and the i2cdetect works. I have fitted a battery to the clock.
    emard
    @emard
    WOOOWWWW i2c RTC :)))
    Lawrie Griffiths
    @lawrie
    I'll put it all in saxonsoc-ulx3s-bin
    Lawrie Griffiths
    @lawrie
    It is all in the Smp directory. The bistream is the 1core version. There is also a new version of riscv_lcc built on the host, rather than a copy of my manually built one, so not tested much.
    Lawrie Griffiths
    @lawrie
    The new riscv32_lcc does not include the top level riscv_32 directory, so you need to create that diredctory and extract it in that.
    Lawrie Griffiths
    @lawrie
    @emard Don't use the new riscv32_lcc. It is not correct.
    I have deleted iit and the updated bitstream is really there now.
    Lawrie Griffiths
    @lawrie
    @emard there is a new version of riscv32_lcc.tar.gz in Smp/images now. It has the top-level riscv32_lcc directory back and it appears to work now. It should have all the latest updates.
    Lawrie Griffiths
    @lawrie
    @emard I am trying to test whether my RTC keeps the time when I remove the power. Have I got the battery oin the right way? I have the flat side up, away from the board.
    Paul Ruiz
    @pnru_gitlab
    Yes, that is how i have it.
    Lawrie Griffiths
    @lawrie
    It does not seem to be maintaining the time when I unplug it.
    Paul Ruiz
    @pnru_gitlab
    Dud battery?
    Lawrie Griffiths
    @lawrie
    Just trying another one.
    Lawrie Griffiths
    @lawrie
    Which also doesn't seem to work. Should the oscillator keep running when the battery is installed so that setting register 0x00 to 0x80 should not be necessary?