=====================================================================
=                CPI-RAS Software for ARM Linux                     =
=                                                                   =
=                                                      Ver1.06      =
=                                                  CONTEC Co.,Ltd.  =
=====================================================================

Contents
=======
  Introduction
  About the Product
  Restrictions
  Note
  How to install
  How to uninstall
  File Structure
  Version up history


Introduction
============
  The explanation of CPI-RAS Software for ARM is described as follows. You must read it because some contents are 
  not described in help.


About the Product
===========
- CPI-RAS Software for ARM supplies the set of functions for controlling our board by the driver and the shared 
  library in module.

- The basic functionality of input and output is provided.

- Start up the driver and use it, by using the script files for starting the driver.

- Sample source code is attached.


Restrictions
============
  The operation check environment is as follows. 
  Some of the contents below are described together with the confirmation information of past versions. 
  Please note that we have not confirmed the combination with all models and distributions(versions).
  In addition, we do not guarantee the operation in combination with all the listed models and each 
  distribution(version).
  * The contents below are as of the release. It may not match the support status of each distribution.
  * For operation confirmation information for individual models, see the contents of the operation 
  confirmation document for each model.


  Products
  ------------------
  [CPI series All-in-one Models]

    Supporting models
      CPI-PS10CM4
      CPI-MS10CM4

    Distribution                             Kernel version
    ------------------------------------     ------------------
       Release: March 15th 2024(bookworm)    6.6.20

  [CPI-RAS Models]

    Supporting Raspberry Pi models
      Rasberry Pi 5 (Only 64bit OS)
      Rasberry Pi 4 Model B  
      Rasberry Pi 3 Model B+

    Distribution                             Kernel version
    ------------------------------------     ------------------
     <32bit OS>
      Raspberry Pi OS 
       Release: May 13th 2025(bookworm)      6.12.25
       Release: March 15th 2024(bookworm)    6.6.20
       Release: May 3th 2023(bullseye)       6.1.21
       Release: April 4th 2022(bullseye)     5.15.32
       Release: March 4th 2021(buster)       5.10.17

      Raspberry Pi OS Legacy
       Release: March 12th 2024(bullseye)    6.1.21
       Release: May 3th 2023(buster)         5.10.103
       Release: April 4th 2022(buster)       5.10.103

      Ubuntu Server
       Ubuntu 22.04 LTS                      5.15.0-1005-raspi

     <64bit OS>
      Raspberry Pi OS 
       Release: May 13th 2025(bookworm)      6.12.25
       Release: March 15th 2024(bookworm)    6.6.20
       Release: May 3th 2023(bullseye)       6.1.21
       Release: April 4th 2022(bullseye)     5.15.32
       Release: March 4th 2021(buster)       5.10.17

      Ubuntu Server
       Ubuntu 24.04.2 LTS                    6.8.0-1018-raspi
       Ubuntu 22.04 LTS                      5.15.0-1005-raspi
       Ubuntu 20.04.2 LTS                    5.4.0-1028-raspi

    Supporting Tinker Board models *
     Tinker Board 2
     Tinker Board 2S

    Distribution                             Kernel version
    ------------------------------------     ------------------
     <64bit OS>
       Tinker Board 2/2S Debian 11 V3.0.11   5.10.160
       Tinker Board 2/2S Debian 10 v2.1.16   4.19.232

  * Tinker Board models do not support RTC funcion of CPI-RAS. Please use the built-in RTC.

  Please note that we have not verified the operation of distributions and versions other than the above.

  Support Program language
  ------------------
    - GCC     (Recommened Version 7.5 - 12.2)
    - G++     (Recommened Version 7.5 - 12.2)
    - Python3 (Recommened Version 3.6 - 3.11)

Note
==============
Legal Information for using the source code of the sample.

Use of the source code constitutes acceptance of the terms shown below.

  - Copyright 2017 CONTEC Co.,LTD. ALL RIGHTS RESERVED.

  - The source code is only for controlling our hardware, you can change the
    source code to create the new sample, and the created sample can be
     redistributed.

  - When you integrate the created sample into the product and open the source
    code, you should specifically disclose this legal information regardless of
    the source code being changed or not.

  - The change of the source code is as for you. and we can not reply to the
    questions about the source code, please refer to the book.

  - We don't take responsibility for the damage caused by modifying the source
    code and redistributing, or for the requests from third party.

To install and setup the sample, it is required to startup with root authority.

Raspberry Pi 5 support

  Raspberry Pi 5 is supported that released after of the following OS.

    Raspberry Pi OS : Octorber 10 2023 (bookworm)
    Ubuntu Server   : Ubuntu 24.04 LTS

  Raspberry Pi 5 has built-in RTC, so RTC has priority.
  If you want to use RTC of CPI-RAS, RTC of Raspberry Pi 5 must be disabled.
  To disable RTC, edit config.txt and add the following parameters.

    dtparam=rtc=off

  CPI-RAS supplies 5V 5A power to Raspberry Pi.
  Raspberry Pi 5 may display a power warning message.
  In this case, you can avoid the warning message by setting the following:

  1. Execute the following command to configure EEPROM:

    $ sudo rpi-eeprom-config -e

    Add the following in the edit screen:

     PSU_MAX_CURRENT=5000

   2. Edit config.txt and add the following parameters:

    usb_max_current_enable=1

How to install
==================
  The driver is provided in a compressed file. You can use the following
command in shell to copy/extract it.
If you want to change the library install path to a location, such as /usr/lib,
you should find the Makefile and change the install path in advance.
Also, please note that the module may not be loaded normally when the security function 
such as SELinux is enabled.

Please install the required packages in advance.


-XXX is driver's version.

  # tar xvf CPI-RAS_XXX.tgz

..................................
 Install for RAS Library
..................................
 When the following procedure is executed, the libraries are compiled and installed in order.

  # cd ./CPI-RAS_XXX
  # sudo make install

 * makefile Execution option
  The following options are available, so please use them as needed.
     install         ... The library related items will be installed.
     uninstall       ... The library related items will be uninstalled.
     sample          ... Build the console sample corresponding to the device.
     clean           ... Delete the intermediate files, executable files, etc. created when "install" and "sample" options are used.

 * When compiling and installing individually, refer to the contents of the help document, ./CPI-RAS_XXX/makefile, 
 the contents of the makefile under each directory, etc., and confirm the installation order and so on.
 * For details on the installed libraries and samples, refer to the help document contents.

..................................
 Compile the console execution sample.
..................................
  (# cd ./CPI-RAS_XXX)
  # make sample

 Of the samples under the sample directory, the sample corresponding to the device is compiled.
 Executable files are created in each sample directory.

..................................
 Install RTC driver for CPI-RAS
..................................

  *You need to connect the Raspberry Pi to the internet to build the driver.
  *Tinker Board models do not support CPI-RAS RTC driver.
   Please use the built-in RTC.

 Updating package of OS, and reboot

  # sudo apt update && sudo apt upgrade
  # sudo reboot

 Install the Raspberry Pi kernel header package.

    <Raspberry Pi OS>
     # sudo apt install raspberrypi-kernel-headers

    <Ubuntu>
     # sudo apt install sudo apt install linux-headers-`uname -r`

 Execute the following commands in Terminal to build the driver, and install the built driver.

  # cd ./CPI-RAS_XXX/rtcDrv
  # sudo make drivers_install

 Load the RTC driver using the following command.

  # sudo sh -c 'echo rx8900 0x32 > /sys/class/i2c-dev/i2c-1/device/new_device'

 Confirm that the driver has been loaded and that the device file has been created using the following commands.

  # lsmod | grep rtc_rv8803
  # ls /dev/rtc

 You can check the operation of RTC driver by the following method.

  - Use the hwclock command on Linux to check the RTC time.

    # sudo hwclock -r

  - Use the following command to set the Linux system time to the RTC time.

    # sudo hwclock -w 

  - Use the following command to set the RTC time to the Linux system time.

    # sudo hwclock -s 

 ................
 Install RTC tool
 ................

 RTC tool is control to the following.

    Get RTC time
    Set RTC time
    Get Alarm time
    Set Alarm time
    Enable / Disable Alarm function
    Get RTC IRQ state
    Clear RTC IRQ

 This tool is created by building from the source code, and install.

  # cd ./CPI-RAS_XXX/rtcDrv
  # sudo make tools_install

 Then RTC tool (rx8900tool) is installed to /usr/local/sbin .
 RTC tool (rx8900tool) gives each function to command and executes it using the sudo command.

  I/F:
       rx8900tool [command] [args]

    Example： Get RTC time
      # sudo rx8900tool get

    command:

        get              Get current the RTC time.
        set              Set the RTC time (UTC).
                         Please set UTC time.
                         Example： 2021-6-1 12:24:00
                           rx8900tool set '2021-06-01 12:24:00'
        get_alarm        Get the alarm time.
                         Those set for everyday, everyhour and every minute are displayed as **.
                         When the alarm function is enabled, [Alarm Enable] is displayed.
                         Also when the alarm function and the alarm flag are enabled, [Alarm Pending] is displayed.
        set_alarm        Set the alarm time (Day, hour and minute).
                         args: 
                           DD-hh:mm [--everyday] [--everyhour] [--everyminute] [--week SUN or MON ... SAT ]
                           WEEK-hh:mm [--everyday] [--everyhour] [--everyminute] [--week SUN or MON ... SAT ]
                         Example： If set at 12:24 on the 15th
                           rx8900tool set_alarm 15-12:24
                         Example： If set at 12:24 on the Wednesday
                           rx8900tool set_alarm WED-12:24
                         Example： If set at 12:24 on the Monday, Wednesday and Friday
                           rx8900tool set_alarm 01-12:24 --week MON --week WED --week FRI
                         Example： If set at 12:24 on the everyday
                           rx8900tool set_alarm 00-12:24 --everyday
                         Example： If set at 24min of everyhour on the 15th
                           rx8900tool set_alarm 15-00:24 --everyhour
                         Example： If set at every minute of 12 oclock on the 15th
                           rx8900tool set_alarm 15-12:00 --everyminute
        enable_alarm     Enable the alarm function.
        disable_alarm    Disable the alarm function.
        get_irq          Get the IRQ flag of RTC.
                         IRQ flag 
                           [UF] Update flag
                           [AF] Alarm flag
        clear_irq        Clear the IRQ flag.
                         Only the alarm flag is cleared.
                         The update flag is cleared, but it is set every second.

 ................
 Alarm usage example
 ................

  When the power is supplied to CPI-RAS and the power is not supplied to Raspberry Pi (LED of CPI-RAS is off),
  Raspberry Pi can be started automatically by the alarm function.

    Steps：

      1. Set the alarm time that you want it using by RTC tool.

        Example： If set at 09:00 on the everyday.

         # sudo rx8900tool set_alarm 00-09:00 --everyday

      2. Clear the IRQ flag of RTC.

         # sudo rx8900tool clear_irq

      3. Shutdown Raspberry Pi.

         # sudo shutdown -h now

      4. Press and hold the CPI-RAS button to turn off the LED of CPI-RAS, and turn off the power supply to the Raspberry Pi.

      5. The Raspberry Pi will start at the alarm time.

Alarm configuration with wakealarm on SYSFS interface
======================

  You can set an alarm for a specified time in /sys/class/rtc/rtc0/wakealarm by kernel version 6.1 later.

    Example 1：Alarm set after 10 seconds

        # echo +10 | sudo tee /sys/class/rtc/rtc0/wakealarm

    Example 2：Alarm set for 4/1 9:00

        # date -d "4/1 9:00" +%s | sudo tee /sys/class/rtc/rtc0/wakealarm

    Example 3：Alarm cancellation  (Disabled alarm IRQ）

        # echo 0 | sudo tee /sys/class/rtc/rtc0/wakealarm

  If you try to set an alarm when wakealarm has already been set, an error will occur.
  If you want to set the alarm again, first cancel the alarm and then set the alarm again.

How to uninstall
======================
  ./CPI-RAS_XXX You can uninstall from the make scripts below.
  The created directory created during installation and the extracted files are deleted.

 ................
 Uninstall RAS Library
 ................

 # cd ./CPI-RAS_XXX
 # make uninstall_all

 ................
 Uninstall RTC tool
 ................

 # cd ./CPI-RAS_XXX/rtcDrv
 # make tools_uninstall

  If you have changed the installation destination, etc., the uninstall process may not be performed 
  properly, so please check the contents in advance.
  Also, when uninstalling, do not use a different version than the one used during installation. 
  It may not be processed normally.

File Structure
============================
  ・This compressed file has the following configuration.
  /<User Directory>/CPI-RAS_XXX
    CPI-RAS_readme_e.txt ............ README file (English)
    CPI-RAS_readme_j.txt ............ README file (Japanese)
    EULA_EN.txt ..................... License Agreement (English)
    EULA_JP.txt ..................... License Agreement (Japanese)

    /help ........................... help file storage directory (Please refer to help for API list and sample program details.)
        /en ......................... English version
            corashelp.htm ........... html help files
            data/ ................... Help data
        /jp ......................... Japanese version
            corashelp.htm ........... html help files
            data/ ................... Help data

    /library
        /include
            mtdll_arm.h ........ Shared library header file
            mtdll_arm.py ....... Shared library define file for python

        /arm64 .............. 64bit Shared library
            libi2c_contec.so.x.x.x
            libmtdll_arm.so.x.x
        /arm32 .............. 32bit Shared library
            libi2c_contec.so.x.x.x
            libmtdll_arm.so.x.x
        Makefile ........... Makefile for installing
                            (make install | make uninstall)
        ・"make install" copies the following files to the system.

          /usr/local/lib/libi2c_contec.so ........... Shared library
          /usr/local/lib/libi2c_contec.so.x.x ....... Shared library
          /usr/local/lib/libmtdll_arm.so ............ Shared library
          /usr/local/lib/libmtdll_arm.so.x.x ........ Shared library

    /samples
      /gcc ........................ Sample for gcc
        /console_samples .......... Sample source code storage directory
            /dio .................. General purpose input / output control sample program
            /hwmon ................ Hardware monitor sample program
            /sled ................. Status LED control sample program
            /wdt .................. Watchdog timer control sample program
      /g++ ........................ Sample for g++
        /console_samples .......... Sample source code storage directory
            /dio .................. General purpose input / output control sample program
            /hwmon ................ Hardware monitor sample program
            /sled ................. Status LED control sample program
            /wdt .................. Watchdog timer control sample program
      /python ..................... Sample for gcc
        /console_samples .......... Sample source code storage directory
            /dio .................. General purpose input / output control sample program
            /hwmon ................ Hardware monitor sample program
            /sled ................. Status LED control sample program
            /wdt .................. Watchdog timer control sample program

    /rtcDrv ....................... Drivers and tools for RTC
      Makefile .................... Makefile for installing

      /rv8803drv .................. RTC driver source code
      /rx8900tool ................. RTC tool source code

Version up history CORAS(LNX) for ARM
=====================================
  Ver. 1.06(Ver.Jun.2025)
  ------------------------------
  - Added supporting modeles below.
      Raspberry Pi 5
      CPI-PS10CM4
      CPI-MS10CM4
  - Update Help files.
      Added sample programs in Function Reference.
  - Improved MT_Open().

  Ver. 1.05(Ver.Apl.2024)
  ------------------------------
  - Added supporting models below. (Excludes RTC function)
      Tinker Board 2
      Tinker Board 2S
  - Added supporting distributions below.
      Release: March 15th 2024(bookworm)    6.6.20
  - RTC driver supports kernel version 6.6
  - Supported RTC wakealarm by Sysfs Interface  (kernel version 6.1 later)
  - Improved MT_Open().

  Ver. 1.04(Ver.Aug.2023)
  -----------------------------
  - Added sample program for g++.
  - Fixed the issue that opens normally even if the CPI-RAS board is not connected.
  - Fixed the issue that RTC driver is not installed correctly when it is in .ko.xz format.
  - Improved the help files.

  Ver. 1.03(Ver.May.2022)
  -----------------------------
  - RTC driver supports kernel version 5.15
  - Added Raspberry Pi OS bullseye (April 4th 2022) and Ubuntu 22.04 LTS to the confirmed distribution.

  Ver. 1.02(Ver.Dec.2021)
  -----------------------------
  - Include the driver and tool for RTC of CPI-RAS
  - Fix issue the missing resource release in MT_Close()

  Ver. 1.01(Ver.Aug.2021)
  -----------------------------
   - Support Python language

  Ver. 1.00(Ver.May.2021)
  -----------------------------
   - First Release
