# Shinobi Library

Japanese

### Ver 0.52

1998/06/26

## Contents

List of functions supported by this release of SDK

System functions
sbInit | Initialize Shinobi library
sbExitSystem | Terminate Shinobi system
sbHwInit - NEW - | Perform initialization process before initializing Ninja
sbHwInit2 - NEW - | Perform initialization process after initializing Ninja
sbHwFinish - NEW - | Terminate the hardware operations
File access functions
gdFsInit | Initialize file system
gdFsLoadDir | Get directory information
gdFsChangeDir | Change current directory
gdFsOpen | Open file
gdFsGetFileSize | Get file size
gdFsRead | Read file
gdFsClose | Close file
Memory management functions
syMallocInit | Reserve Malloc heap area
syMalloc | Allocate memory
syFree | Release memory
Peripheral functions
pdGetPeripheral | Get peripheral data
pdGetPeripheralError | Get peripheral status
pdExecPeripheralServer | Server function for getting peripheral data
Function Group for Getting Time Data
syTmrGetCount | Get value of the free running timer
syTmrDiffCount | Get difference of the values of the two timer counts
syTmrCountToMicro | Convert count value to micro seconds
syTmrMicroToCount | Convert micro seconds to count value

Note
In the above functions, gdFsInit, syMallocInit and njInitSystem are executed within the initialization function sbInit. For various reasons, the current release does not include the source code for the sbInit function (it will be made public in a later release). Therefore it is currently not possible to make detailed setting changes. However, because sbInit arguments are passed on unchanged to njInitSystem, you can establish the same Ninja environment by replacing njInitSystem coded for SET2 by sbInit. We apologize for any temporary inconvenience caused by this approach.

# System functions

## 0. Outline

Initializes the KATANA hardware and makes the SHINOBI library ready for use.

The SHINOBI library contains several initialization functions. Calling these functions in a suitable sequence establishes the normal settings. The initialization function source code will be made public in future, allowing it to serve as a sample for library initialization.

* The current release does not include the initialization function source code. It will be made public in a future release. Because this function calls njInitSystem, replace njInitSystem in the SET2 development environment with this function.

## 1. Data structure

## 2. Function specifications

### 2.1 Function list

Function | Operation
--- | ---
sbInit | Initialize SHINOBI library
sbExitSystem | Terminate system
sbHwInit | Perform initialization process before initializing Ninja
sbHwInit2 | Perform initialization process after initializing Ninja
sbHwFinish | Terminate the hardware operations

### 2.2 Function API

sbInit Initialize SHINOBI library | Contents

[Function]
  void sbInit( Int mode, Int frame, Int Count );

[Input]
  mode
    Screen mode (resolution)
    Specifies screen resolution.
  frame
    Frame buffer mode
    Sets the frame buffer color mode
  count
    Frame count
    Specifies the frame count in 1/60 second units.
[Output]
  None

[Return value]
  None

[Operation]
  Initializes the hardware and makes the library ready for use.
  Internally, the function calls njInitSystem and specifies the screenresolution.
  The 2D clip area is set to the same size as the screen.
  Z clip is set to the range -1.0 - -60000.0.
  3D screen projection distance is set to 500.
  Aspect ratio is set to 1.0 for X and Y.
  Color mode is set to NJD_COLOR_MODE_NORMAL.

  Frame count is set in 1/60 units.
  For example, if "2" is specified, frames are changed every 1/30 seconds.
  Frame change is performed with the njWaitVSync function.

  The following screen modes are available.

  Variable name | Screen mode
  --- | ---
  NJD_RESOLUTION_VGA | VGA
  NJD_RESOLUTION_320x240_NTSCNI | NTSC non-interlaced 60 Hz
  NJD_RESOLUTION_320x240_NTSCI | NTSC interlaced 30 Hz
  NJD_RESOLUTION_640x240_NTSCNI | NTSC non-interlaced 60 Hz
  NJD_RESOLUTION_640x240_NTSCI | NTSC interlaced 30 Hz
  NJD_RESOLUTION_640x480_NTSCI | NTSC interlaced 30 Hz
  NJD_RESOLUTION_320x240_PALNI | PAL non-interlaced 50 Hz
  NJD_RESOLUTION_320x240_PALI | PAL interlaced 25 Hz
  NJD_RESOLUTION_640x240_PALNI | PAL non-interlaced 50 Hz
  NJD_RESOLUTION_640x240_PALI | PAL interlaced 25 Hz
  NJD_RESOLUTION_640x480_PALI | PAL interlaced 25 Hz

  The following frame buffer modes are available.

  NJD_FRAMEBUFFER_MODE_RGB565
  NJD_FRAMEBUFFER_MODE_RGB555
  NJD_FRAMEBUFFER_MODE_ARGB4444
  NJD_FRAMEBUFFER_MODE_ARGB1555
  NJD_FRAMEBUFFER_MODE_RGB888
  NJD_FRAMEBUFFER_MODE_ARGB8888

Usage example
  sbInit( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
  Initializes the Shinobi library and sets the screen resolution to VGA
  (640x480), 1 frame, 1/60 seconds.

[Remarks]
  Always perform this at the start of a program.
  Depending on the hardware configuration, some screen modes may not be available. Use this function in place of njInitSystem.
  Because arguments are the same as for njInitSystem, it suffices to change only the function literal to achieve the same operation.
  The source code for this function will be made public in a future release of the SDK. In the current release, this part is supplied in object file format, but the link object file differs, depending on whether the file system is used or not. Link the files as follows:

  File system is used sbinit.obj File system is not used sbinitn.obj

  We apologize for any temporary inconvenience caused by this approach.

sbExitSystem Terminate system | Contents

[Function]
  void sbExitSystem( void )

[Input]
  None

[Output]
  None

[Return value]
  None

[Operation]
  Terminates the system.
  Use in place of njExitSystem.

sbHwInit Perform initialization process before initializing Ninja | Contents

[Function]
  void sbHwInit( void )

[Input]
  None

[Output]
  None

[Return value]
  None

Operation
  This function must be called prior to the initialization of Ninja.
  Initializes hardware mainly.
  This function initializes the following items.

  SH-CPU
  G1-BUS
  Interruption Controller
  Cache
  Timer

Caution
  This function is executed in sbInitSystem.

sbHwInit2 Perform initialization process after initializing Ninja | Contents

[Function]
  void sbHwInit2( void )

[Input]
  None

[Output]
  None

[Return value]
  None

[Operation]
  Initializes the library which should be called after executing Ninja/Kamui.
  The part of interruption management is initialized by this funtion.

sbHwFinish Terminate the hardware operations | Contents

[Function]
  void sbHwFinish( void )

[Input]
  None

[Output]
  None

[Return value]
  None

[Operation]
  Releases the resource of the SH CPU and also does the end processing of hardware.

# File access functions

## 0. Outline

Supplies GD-ROM access functions.

- Directory access
- File open/close
- File read (completion return)

## 1. Data specifications

### 1.1 Constants

Seek mode
  GDFS_SEEK_SET
  GDFS_SEEK_CUR
  GDFS_SEEK_END

Status
  GDFS_STAT_IDLE
  GDFS_STAT_COMPLETE
  GDFS_STAT_READ
  GDFS_STAT_SEEK
  GDFS_STAT_PLAY
  GDFS_STAT_BUSY
  GDFS_STAT_ERR
  GDFS_STAT_FATAL
  GDFS_STAT_UNDEF

Errors
  GDFS_ERR_OK
  GDFS_ERR_RESET
  GDFS_ERR_INIT
  GDFS_ERR_DIRREC
  GDFS_ERR_CANTOPEN
  GDFS_ERR_NOTFOUND
  GDFS_ERR_NOHNDL
  GDFS_ERR_ILLHNDL
  GDFS_ERR_NOTDIR
  GDFS_ERR_DIROVER
  GDFS_ERR_BUSY
  GDFS_ERR_32ALIGN
  GDFS_ERR_SEEK
  GDFS_ERR_OFS
  GDFS_ERR_ILLTMODE
  GDFS_ERR_ILLREQ
  GDFS_ERR_READ
  GDFS_ERR_NOTREAD
  GDFS_ERR_RDTOUT
  GDFS_ERR_TOUT
  GDFS_ERR_EOF
  GDFS_ERR_TRAYOPEND
  GDFS_ERR_HWARE
  GDFS_ERR_MEDIA
  GDFS_ERR_RECOVER
  GDFS_ERR_PROTECT
  GDFS_ERR_ABORT
  GDFS_ERR_NOTREADY
  GDFS_ERR_UNITATTENT
  GDFS_ERR_FATAL
  GDFS_ERR_UNDEF

### 1.2 Data structure

GDFS
  ... File handle

GDFS_DIRREC
  ... Directory record handle

### 1.3 Macros

GDFS_WORK_SIZE(x)
  Argument: x ... Number of files to open simultaneously
  Meaning: Required work buffer size

GDFS_DIRREC_SIZE(x)
  Argument: x ... Number of directory entries
  Meaning: Required directory record buffer size

## 2. Function specifications

### 2.1 Function list

Function | Operation
gdFsInit | Initialize and mount file system
gdFsLoadDir | Get directory information
gdFsChangeDir | Change current directory
gdFsOpen | Open file
gdFsGetFileSize | Get file size
gdFsRead | Read file
gdFsClose | Close file

### 2.2 Function API

gdFsInit Initialize and mount file system | Contents

Function
  Sint32 gdFsInit(Uint32 max_open, void *gdfs_work, Uint32 max_dirent, void *gdfs_dirrec)
[Input]
  max_open
    Number of files that can be opened simultaneously
  gdfs_work
    Work area pointer (supplied from user area)
  max_dirent
    Number of entries in current directory
  gdfs_dirrec
    Buffers for current directory (from user area)
[Output]
  None

[Return value]
  GDFS_ERR_OK
    Normal end
  Other
    Error
[Operation]
  Initializes the library.

[Usage example]
  Uint8 gdfswork[ GDFS_WORK_SIZE(8) ];
  Uint8 gdfscurdir[ GDFS_DIRREC_SIZE(64) ];

  gdFsInit(8, gdfswork, 64, gdfscurdir);

[Caution]
  gdfs_work must be 32-byte aligned. This function is executed from within the sbInit function. In the current SDK release, the source code of the sbInit function is not made public, but this is planned for a future release, in order to allow settings to be made when initializing the file system. The default values in sbInit are as shown below.

      Number of files that can be opened simultaneously: 8
                                      Work area pointer: global variable "gdfswork"
                                                         Uint8 gdfswork [ GDFS_WORK_SIZE(8) ];
                Number of entries for current directory: 1024
                          Buffer for current  directory: gobal variable "gdfsurdir"
                                                         Uint8 gdfscurdir[ GDFS_DIRREC_SIZE(1024) ];

gdFsLoadDir Get directory information | Contents

[Function]
  Uint32 gdFsLoadDir(Sint8 *dirname, GDFS_DIRREC gdfs_dirrec)
[Input]
  dirname
    Directory name
[Output]
  gdfs_dirrec
    Directory record handle
    (To current directory if NULL)
[Return value]
  GDFS_ERR_OK
    Normal end
  Other
    Error
[Operation]
  Read directory record

[Usage example]
  /* Sample 1 */
  /* Read MOVIE directory to g_dir */
  Uint8 dirbuf[ GDFS_DIRREC_SIZE(64) ];
  GDFS_DIRREC g_dir = (GDFS_DIRREC) dirbuf;

  gdFsLoadDir("MOVIE", g_dir);

  /* Sample 2 */
  /* Move current directory to DATA directory */
  gdFsLoadDir("DATA", NULL);

gdFsChangeDir Change current directory | Contents

[Function]
  Uint32 gdFsChangeDir(Sint8 *dirname)

[Input]
  dirname ... Directory name

[Output]
  None

[Return value]
  GDFS_ERR_OK
    Normal end
  Other
    Error
[Operation]
  Change current directory

[Usage example]
  /* Move current directory to DATA directory */
  gdFsChangeDir("WORK");

gdFsOpen Open file | Contents

[Function]
  GDFS gdFsOpen(Sint8 *fname, GDFS_DIRREC gdfs_dirrec)
[Input]
  fname
    File name
  gdfs_dirrec
    Directory record handle for file name search
    (Search current directory if NULL)
[Output]
  None

[Return value]
  NULL
    Fail
  Other
    File handle
[Operation]
  Open file

[Usage example]
  /* Sample 1 (accessing a file in the current directory) */
  GDFS gf;

  gf = gdFsOpen("A.BIN", NULL);

  /* Sample 2 (accessing a file in the current directory) */
  GDFS gf;
  Uint8 dirbuf[ GDFS_DIRREC_SIZE(64) ];
  GDFS_DIRREC g_dir;

  g_dir = gdFsCreateDirhn(dirbuf, 64);
  gdFsLoadDir("MOVIE", g_dir);
  gf = gdFsOpen("SMP.MOV", g_dir);

gdFsGetFileSize Get file size | Contents

[Function]
  Bool gdFsGetFileSize(GDFS gdfs, Uint32 *fsize);
[Input]
  gdfs
    File handle
[Output]
  *fsize
    File size (bytes)
[Return value]
  TRUE / FALSE

[Operation]
  Get file size

[Usage example]
  GDFS gf;
  Uint32 flen;

  gf = gdFsOpen("TEST.BIN", NULL);
  gdFsGetFileSize(gdfs, &flen);

gdFsRead Read file | Contents

[Function]
  Sint32 gdFsRead(GDFS gdfs, Uint32 nsct, void *buf)

[Input]
  gdfs
    File handle
  nsct
    Number of sectors to read
  buf
    Store buffer
[Output]
  None

[Return value]
  GDFS_ERR_OK
    Normal end
  Other
    Error
[Operation]
  Read file (completion return)

[Usage example]
  GDFS gf;
  Uint32 buf[32*2048/4];

  gf = gdFsOpen("TEST.BIN", NULL);
  gdFsRead(gf, 32, buf);
  gdFsClose(gf);

gdFsClose Close file | Contents

[Function]
  void gdFsClose(GDFS gdfs);
[Input]
  gdfs
    File handle
[Output]
  None

[Return value]
  None

[Operation]
  Close file.

[Usage example]
  GDFS gf;

  gf = gdFsOpen("TEST.BIN", NULL);
  gdFsClose(gf);

  # Memory management functions

  ## 0. Outline

  The SHINOBI library performs memory management without relying on the operating system. Except for the initialization function, the conventions of the C standard "malloc" functions apply, only the name before the function is different.

  ## 1. Data structure

  ## 2. Function specifications

  ### 2.1 Function list

  Function | Operation
  syMallocInit | Get and declare memory area for memory management
  syMalloc | Allocate memory
  syFree | Release memory

  ### 2.1 Function API

  syMallocInit Get and declare memory area for memory management | Contents

  [Function]
    Void syMallocInit(Void *heap, Uint32 size);

  [Input]
    heap
      Start address of memory area to be allocated
    size
      Size of memory to be allocated
  [Output]
    None

  [Return value]
    None

  [Operation]
    Specifies the memory area to be managed by the syMalloc library and initializes the library.
    This function is executed from within the sbInit function.
    In the current SDK release, the source code of the sbInit function is not made public, but this is planned for a future release, in order to allow changing the heap start address and size.
    The default values in sbInit are as shown below.

        Heap area start address: end of section B
                      Heap size: 0x00400000

  syMalloc Allocate memory | Contents

  [Function]
    Void *syMalloc(Uint32 size);
  [Input]
    size
      Requested size (byte)
  [Output]
    None
  [Return value]
    Pointer to allocated area
    If NULL, allocation has failed
  [Operation]
    Same as standard C function malloc(size).

  syFree Release memory | Contents

  [Function]
    Void syFree(void *ap);
  [Input]
    Pointer to area to be released
  [Output]
    None
  [Return value]
    None
  [Operation]
    Same as free(*ap)

  # Peripheral functions

  ## 0. Outline

  ### 0.1 Get controller data

  Get device data
  - To get device data, the function pdGetPeripheral() is used.
  - To get the controller input, simply reference the members of this structure.

  ## 1. Data specifications

  ### 1.1 Structure specifications

  ###

  ###

  ###

  ###

  ###

  ##

  ###

  ###

  #

  ##

  ##

  ##

  ###

  ###

      PDS_PERIPHERAL Structure

       Definition

      typedef struct {
      	Uint32 id;
      	Uint32 support;
      	Uint32 on;
      	Uint32 off;
      	Uint32 press;
      	Uint32 release;
      	Uint16 r;
      	Uint16 l;
      	Sint16 x1;
      	Sint16 y1;
      	Sint16 x2;
      	Sint16 y2;
      	Sint8* name;
      	void* extend;
      	Uint32 old;
      } PDS_PERIPHERAL;

      DescriptionThis structure serves for storing the control pad status.

      Members

      id        Device ID
      support   Button/lever support state
      on        Digital button state
      off       Digital button state (reversed)
      press     Digital button down edge state
      release   Digital button up edge state
      r         Analog axis R value (0 - 255)
      l         Analog axis L value (0 - 255)
      x1        Analog axis X1 value (-128 - 127)
      y1        Analog axis Y1 value (-128 - 127)
      x2        Analog axis X2 value (-128 - 127)
      y2        Analog axis Y2 value (-128 - 127)
      name      Device name
      extend    Extended data address (not used)

      oldReserved

      ReferencepdGetPeripheral()

       1.2  Device ID and device name
      The retrieved structure contains information about the device ID (type) and device name.

      Because the format of the device ID according to the Maple bus specification is quite complex, it is not suitable for use by an application. In this library, it is simplified as follows.

       Device              Device ID (id)     Device name string (name)
      Standard control pad PDD_DEV_CONTROLLER Product name of the device

       1.3  Buttons supported by device
      There are many different types of controller devices, which have various kinds of control buttons and levers, such as for example two cross-key pads, two analog channels, etc. The "support" member serves to check which kind of control the device use. The bit assign pattern is shown in the table below. "1" means that a button or lever is present, and "0" means that it is not present.

      Controller devices must have a cross-key A, start button, A button and B button. By programming an application to use only these buttons, compatibility can be assured.

      Button or lever    Constants for bit position specification
      Cross-key A top    PDD_DEV_SUPPORT_KU
      Cross-key A bottom PDD_DEV_SUPPORT_KD
      Cross-key A left   PDD_DEV_SUPPORT_KL
      Cross-key A right  PDD_DEV_SUPPORT_KR
      Cross-key B top    PDD_DEV_SUPPORT_KUB
      Cross-key B bottom PDD_DEV_SUPPORT_KDB
      Cross-key B left   PDD_DEV_SUPPORT_KLB
      Cross-key B right  PDD_DEV_SUPPORT_KRB
      Start button       PDD_DEV_SUPPORT_ST
      A button           PDD_DEV_SUPPORT_TA
      B button           PDD_DEV_SUPPORT_TB
      C button           PDD_DEV_SUPPORT_TC
      X button           PDD_DEV_SUPPORT_TX
      Y button           PDD_DEV_SUPPORT_TY
      Z button           PDD_DEV_SUPPORT_TZ
      D button           PDD_DEV_SUPPORT_TD
      Analog axis R      PDD_DEV_SUPPORT_AR
      Analog axis L      PDD_DEV_SUPPORT_AL
      Analog axis X1     PDD_DEV_SUPPORT_AX1
      Analog axis Y1     PDD_DEV_SUPPORT_AY1
      Analog axis X2     PDD_DEV_SUPPORT_AX2
      Analog axis Y2     PDD_DEV_SUPPORT_AY2

      *  The application should use the device ID and device specifications, or reference this button/lever information in order to ensure appropriate data handling.

       1.3.1  Digital  button data
      Digital button information comprises the four members "on", "off", "press", and "release", which should be used according to the application requirements. A button is assigned to each bit of the member. "1" means that the button is pressed and "0" means that it is released. During initialization with the function pdInitPeripheral(), reverse logic can be selected.

      Digital button     Constants for bit position specification
      Cross-key A top    PDD_DGT_KU
      Cross-key A bottom PDD_DGT_KD
      Cross-key A left   PDD_DGT_KL
      Cross-key A right  PDD_DGT_KR
      A button           PDD_DGT_TA
      B button           PDD_DGT_TB
      C button           PDD_DGT_TC
      D button           PDD_DGT_TD
      X button           PDD_DGT_TX
      Y button           PDD_DGT_TY
      Z button           PDD_DGT_TZ
      L button           PDD_DGT_TL
      R button           PDD_DGT_TR
      Start button       PDD_DGT_ST
      Cross-key B top    PDD_DGT_KUB
      Cross-key B bottom PDD_DGT_KDB
      Cross-key B left   PDD_DGT_KLB
      Cross-key B right  PDD_DGT_KRB

      Member         Meaning
      Uint32 on      When button is pressed (button down), the corresponding bit is "1". When button is not pressed, the bit is "0".
      Uint32 off     Bits are reversed from "on" member. When button is not pressed (button up), the corresponding bit is "1".
      Uint32 press   When button has changed from not pressed to pressed (button down edge), the corresponding bit becomes "1".
      Other bits are "0".
      Uint32 release When button has changed from pressed to not pressed (button up edge), the corresponding bit becomes "1". Other bits are "0".

      *  When negative logic was selected, the bit status for button, on, off, press, release will be reversed.

      Digital LR button information is simulated by the software based on analog LR information. Note that if a device does not have an analog LR button, the bit status will not change. (There are no devices with digital LR buttons in physical form.)

       1.3.2  Analog axis data

      Analog axis information comprises the six members "r", "l", "x1", "y1", "x2", and "y2". For non-connected devices or devices without the respective button or lever, the data are the same as for center position.

      Member   Sign     Range         Center position Lever/ button
      Uint16 r Unsigned 0 - 255                     0 Analog R button
      Uint16 l Unsigned 0 - 255                     0 Analog L button
      Sint16 x1Signed   -128 - 0 - 127              0 Analog lever X1
      Sint16 y1Signed   -128 - 0 - 127              0 Analog lever Y1
      Sint16 x2Signed   -128 - 0 - 127              0 Analog lever X2
      Sint16 y2Signed   -128 - 0 - 127              0 Analog lever Y2

       1.4 Data acquiry error

      If an error occurs during communication with the device according to the Maple bus protocol, correct button data will not be acquired. In such a case, the structure is set to the values shown below.

      Member         Set value
      id,name,extend Previous value
      Digital button All buttons not pressed
      Analog axis    Center position

      The function pdGetPeripheralError() can be used to check whether an error has occurred.

      Error code     Contents
      PDD_ERR_OK     No error
      PDD_ERR_RETRY  Button data could not be acquired normally
      PDD_ERR_GENERICUndefine error

      The library does not contain steps for recovery when an error has occurred, Suitable routines must therefore be written into the application.

       2. Function specifications

       2.1  Function list

       Function             Operation
      pdGetPeripheral       Get controller button status
      pdGetPeripheralError  Get controller error status
      pdExecPeripheralServerGet peripheral data from server

       2.2  Function API

      pdGetPeripheral
      Get controller button statusContents

       [Function]  const PDS_PERIPHERAL* pdGetPeripheral(Uint32 port)
       [Input]  port port number (PDD_PORT_A0/B0/C0/D0)
       [Output]  None
       [Return value]  PDS_PERIPHERAL structure address
       [Operation]  Gets peripheral data.
       [Reference]  PDS_PERIPHERAL structure
       [Usage example]
                const PDS_PERIPHERAL* per;

                per = pdGetPeripheral(PDD_PORT_A0);

                if (per->press & PDD_DGT_ST) {

                  /* Start button was pressed */

                        :

                        :

                }

      pdGetPeripheralError
      Get controller error statusContents

       [Function]  Sint32 pdGetPeripheralError(Uint32 port)
       [Input]

       portPort number (PDD_PORT_A0/B0/C0/D0)

       [Output]  None
       [Return value]

       0No error
       NegativeError value (PDD_ERR_XXXX)

       [Operation]  Gets error code for controller data get process.
       [Usage example]
                Sint32 err;

                err = pdGetPeripheralError(PDD_PORT_B0);

      pdExecPeripheralServer
      Get peripheral data from serverContents

       [Function]  pdExecPeripheralServer
       [Input]  None
       [Output]  None
       [Return value]  None
       [Operation]

       Creates peripheral data for that frame.
       Call this function once at the loop start of one frame.

       [Remarks]  Should be used together with njWaitVSync.

      Function Group for Getting Time Data
       0. Outline

       The KATANA's SH-CPU contains three independent timers as timer units,

       and the SHINOBU library uses Timer0 (one of the three timers) as the

       free running timer. Timer0's initial value cannot be reset and it is

       read-only from user applications. The library user does not need to be

       aware that it is a down counter. The counter clock runs at 1.2 micro

       seconds per count and can measure between 1.28 micro seconds to 91.6

       minutes. It is mainly used for getting time elapsed and for calculating

       program processing time.

       1. Data structure

      No(No particular data type is defined for this function group.)

       2. Function specifications
       2.1  Function list

      FunctionOperation
      syTmrGetCountGet value of the free running timer
      syTmrDiffCountGet difference of the values of the two timer counts
      syTmrCountToMicroConvert count value to micro seconds
      syTmrMicroToCountConvert micro seconds to count value

       2.2  Function API

      syTmrGetCount

      Get value of the free running timer

      Contents

[Function]
  Uint32 syTmrGetCount( void )
[Input]
  No
[Output]
  No
[Return value]
  TMU0 counter value
[Operation]
  Get TMU0 counter value.
[Remarks]
  Due to down counter, 0xffffffff counter value is returned.

  syTmrDiffCount Get difference of the values of the two timer counts | Contents

  [Function]
    Uint32 syTmrDiffCount(Uint32 count1, Uint32 count2)
  [Input]
  count1
    Get first counter value
  count2
    Get second counter value
  [Output]
    None
  [Return value]
    Difference between the two counter values
  [Operation]
    Calculate the difference between the two counter values.

  syTmrCountToMicro Convert count value to micro seconds | Contents

  [Function]
    Uint32 syTmrCountToMicro(Uint32 count)
  [Input]
    count
      Counter value for conversion
  [Output]
    None
  [Return value]
    Value in micro seconds
  [Operation]
    Convert counter value to micro seconds.
  [Remarks]
    Discard fractional part of the value.

  syTmrMicroToCount Convert micro seconds to count value | Contents

  [Function]
    Uint32 syTmrMicroToCount(Uint32 micro)
  [Input]
    micro
      Value in micro seconds for conversion to counter value
  [Output]
    None
  [Return value]
    Counter value
  [Operation]
    Convert micro seconds to counter value.
  [Remarks]
    Discard fractional part of the value.

  ### 3. Usage example

  This example measures the execution time of any function, using the free running timer.

       #include <sg_sytmr.h>            /* Low level timer library header */

       main()
       {
           Uint32 count1, count2, count, micro;

           count1  syTmrGetCount();               /* Begin measurement */

           TestFunc();                             /* Run target function for measurement */

           count2  syTmrGetCount();               /* End measurement */
           count  syTmrDiffCount(count1, count2); /* Get difference of  values of counters */
           micro  syTmrCountToMicro(count);       /* Convert counter value to micro seconds */

           while (1);
       }