Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    emard
    @emard
    OOOOYEEEE now it works
    root@buildroot:/home/root/rtc# ./date.sh 
    2020-9-22 19:09:
    R0 was missing. those regs must be AND-filetered otherwise we have this
    root@buildroot:/home/root/rtc# ./date.sh 
    2020-9-22 19:11:91
    great achievement i2c !!!!!
    emard
    @emard
    #include <stdio.h>
    #include <stdlib.h>
    
    #define I2C_SLAVE 0x703
    #define O_RDWR 2
    
    int i2c_rtc;
    
    void rtc_open(int addr)
    {
      i2c_rtc = open("/dev/i2c-0", O_RDWR);
      ioctl(i2c_rtc, I2C_SLAVE, addr);
    }
    
    void rtc_read(unsigned char *buf, int reg, int n)
    {
      buf[0] = reg;
      write(i2c_rtc, buf, 1);
      read(i2c_rtc, buf, n);
    }
    
    void i2cdemo(void)
    {
      int i;
      unsigned char buf[7];
      // mask for BCD          SEC   MIN   HOUR  WKDAY DAY   MONTH YEAR
      unsigned char mask[7] = {0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x1F, 0xFF};
    
      rtc_read(buf, 0, sizeof(buf));
      for(i = sizeof(buf)-1; i >= 0; i--)
        printf(" %02x", buf[i] & mask[i]);
      printf("\n");
    }
    
    int main(int argc, char *argv[])
    {
      int i;
      rtc_open(0x6F);
      for(i = 0; i < 60; i++)
      {
        i2cdemo();
        sleep(1);
      }
      return 0;
    }
    root@buildroot:/home/root/rtc# ./a.out 
     20 09 22 02 21 14 27
     20 09 22 02 21 14 28
     20 09 22 02 21 14 29
     20 09 22 02 21 14 30
     20 09 22 02 21 14 31
    emard
    @emard
    Everything works and I hope that also read() of multiple registers does i2c atomic read at which RTC prevents reg update until read is finished
    Dolu1990
    @Dolu1990
    Nice :D
    emard
    @emard
    great stuff, I'playing with it. Can we also have shutdown gpio :)
    Or better to say, can shutdown raise shutdown pin so board powers off really
    Dolu1990
    @Dolu1990
    So, normaly, those feature should be integrated at the opensbi level
    emard
    @emard
    Wherever you suggest is the proper place. From bitstream, this pin needs a kind of "fuze" logic in order not to be triggered at early start of bitstream when the LUTs set up and can do some glitch.. I use some counter that starts from 0 and must be clocked few times. shutdown pin is connected to MSB bit of this counter.
    Lawrie Griffiths
    @lawrie
    @emard That is impressive, doing all the i2c access from C. And it good that lcc and its library had all the features you needed. Some of them only added in the last day or two.
    Dolu1990
    @Dolu1990
    i will add a ulx3s opensbi plateform specific port
    and already try the reboot ^^
    emard
    @emard
    @lawrie great stuff this i2c really, simple and works!
    @Dolu1990 yes reboot would be first step to make. For board shutdown it needs battery, configured RTC with alarm that triggers in the future and power from US2 or from US1 with green power LED set to OFF. I can assist with this
    Dolu1990
    @Dolu1990
    Are you aware of a blackbox to instanciate in the FPGA to be able to reload the bitstream when asked ?
    Or i should use the PROGRAMN FPGA input pin via USER_PROGRAMN from the schematic
    emard
    @emard
    I actually didnt know of blackbox but pulling down programn will reload bitstream from flash. If bitstream is build as multiboot (using command ecpmulti) then programn will jump to next bitstream in FLASH
    For your this blackbox will be better if it works as it will reload current bitstream having saxonsoc in FPGA SRAM (regardless what in FLASH is)
    emard
    @emard
    @pnru_gitlab I have used your hwclock to calculate date but it does it with few days off :) https://github.com/emard/hwclock4saxonsoc can you check whats up wrong
    Paul Ruiz
    @pnru_gitlab
    Again very little time today. I indeed had an issue with being 1 day off when I did that I2C code - maybe my code in date is also off and I now have matched errors on the Cortex :^). Here is a reviewed routine. @lawrie - in this form it is not suitable for c.lib, because it does not take an argument but works on a global var.
    emard
    @emard
    No problem I will find correct formula
    its called sakamoto-gregorian something
    Paul Ruiz
    @pnru_gitlab
    I think I took the algorithm in 4.2BSD as a base (several years ago). If I look at the code at the end of function gtime(), I think my reviewed routine is essentially the same (i.e. should be good).
    emard
    @emard
    Maybe I during editing typed something wrong. I will rewrite :)
    emard
    @emard
    The rewritten version is here now it matches with date -u --date="@<unix_seconds>" https://github.com/emard/hwclock4saxonsoc/blob/master/hwclock.c#L163 I dont know why it works :)
    hwclock -s will set correct system date from RTC
    Dolu1990
    @Dolu1990
    So i checked, the linux risc-v port used do not implement restart, only shutdown XD
    So, i got the shutdown command in linux to successfully restart the FPGA
    emard
    @emard
    Real shutdown is possible with shutdown pin set to 1. after that you can wat few ms and proceed with restart. If RTC has not been setup it will restart otherwise it will shutdown
    It's because althugh commanded to shutdown, RTC and green LED will keep waking up the board and shutdown pin will be ignored
    Dolu1990
    @Dolu1990
    Ahhh ok
    I was asking myself why shutdown wasn't ok ^^
    Lawrie Griffiths
    @lawrie
    @pnru_gitlab Do you know why lcc/bin/libs contains both softfloat and libsoftfloat and why it contains eeprintf? We do not include softfloat and eeprintf in c.lib.
    emard
    @emard
    @Dolu1990 https://github.com/emard/ulx3s/blob/master/doc/MANUAL.md#low-power-mode is somehow tried to explain all prerequisites for real shutdown to happen. When conditions are met for real shutdown LED D11 on bottom side of board will be dimly lit. Only then shutdown pin=1 will be accepterd as real power off, otherwise ignored
    emard
    @emard
    I think after all disks are synced and unmonuted, set shutdown=1 and wait about 100ms - if it can shutdown it will go OFF otherwise it keep powered - then you can proceed to reload FPGA bitstream in order to reboot instead of shutdown
    Dolu1990
    @Dolu1990

    I pushed on SaxonSoc and opensbi the changes. linux shutdown will cleanly trigger the shutdown pin in opensbi after the OS is off.
    It require :
    bitstream update, opensbi update.

    Also, the opensbi plaform used is now a ulx3s dedicated one, so binary path in the opensbi folder changed

    Dolu1990
    @Dolu1990
    basicaly, writing 1 at 0x10bff000 do a restart, writting 2 do a shutdown
    emard
    @emard
    thnx!!!! I will test it tomorrow and with some additional i2c rtc alarm set I can also check wake-on-rtc function now
    Lawrie Griffiths
    @lawrie
    @emard @Dolu1990 I have updated opensbi and the bitstream on my 12F and it is running. Not sure how to test the change.
    Dolu1990
    @Dolu1990
    personnaly, i mesured on the board the shutdown reset
    else, i also tried with openocd via the telnet
    but in short, unless you configure the RTC, you can't realy observe the feature
    Lawrie Griffiths
    @lawrie
    @emard I have updated the 12F 1core bitstream and opensbi (fw_jump.bin@0x340000) in Smp. You will need to flash the new fw_jump.bin@0x340000.
    emard
    @emard
    Yes we have all the parts for RTC party :) I can test it later on actual board with battery!!
    Dolu1990
    @Dolu1990
    so, just for sanity, the linux reboot command is doing nothing
    only shutdown can be used