==============================================================================================
                              PDL Project for FM4 Family 
==============================================================================================

Copyright (C) 2013 Spansion LLC. All Rights Reserved. 

This software is owned and published by: 
Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA  94088-3453 ("Spansion").

BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND 
BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.

This software contains source code for use with Spansion 
components. This software is licensed by Spansion to be adapted only 
for use in systems utilizing Spansion components. Spansion shall not be 
responsible for misuse or illegal use of this software for devices not 
supported herein.  Spansion is providing this software "AS IS" and will 
not be responsible for issues arising from incorrect user implementation 
of the software.  

SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS), 
ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING, 
WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED 
WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED 
WARRANTY OF NONINFRINGEMENT.  
SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT, 
NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT 
LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, 
LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR 
INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA, 
SAVINGS OR PROFITS, 
EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED 
FROM, THE SOFTWARE.  

This software may be replicated in part or whole for the licensed use, 
with the restriction that this Disclaimer and Copyright notice must be 
included with each copy of this software, whether used in part or whole, 
at all times.                                                                                         
                                                                                                                                                   
==========================================================================
 
History
Date        Ver   IAR    ARM    Description
2013-06-26  0.1   6.50   4.70   first version (alpha release)
2013-08-23  0.2   6.50   4.70   second version
2013-10-16  0.3   6.50   4.70   third version
2013-10-31  1.0   6.50   4.70   first version (1st release)
2014-01-16  1.1   6.50   4.70   bugs found on v1.0 are fixed
                                SD I/F driver/example added
                                USB driver/example added 

==========================================================================

PDL (Peripheral Driver Library)

This library contains driver modules for the following peripherals and
resources:

- ADC   Analog Digital Cionverter
- BT    Base Time
- CAN   Controller Area Network
- CLK   Clock Module
- CRC   Cyclic Redundancy Check
- CR    High-CR trimming
- CSV   Clock supervisor
- DAC   Digital Analog Converter
- DMA   Direc Memory Access
- DT    Dual Timer
- DTSC  Descriptor System data Transfer Controller
- EXINT External Interrupt
- EXTIF External Bus Inerface
- Flash Main/Work Flash operation
- GPIO  General Purpose Inoput/Output Ports (only header file)
- LPM   Low Power Modes
- LVD   Low Voltage Detection
- MFS   Multi Function Serial Interface
- MFT   Multi Function Timer
- QPRC  Quad Decoder and Position/Revolution Counter
- RESET Reset Cause Register
- RTC   Real Time Clock
- SD    SD card interface   
- UID   Unique ID
- USB   Universal Serial Bus
- WC    Watch Counter
- WDG   Watch Dog Timer

For almost all peripheral modules there is several example code available.
These examples are located in the example folder and its sub folders (see
below at the PDL's directory tree).


The following examples are available:
-------------------------------------

- ADC
  - adc_scan_irq_bt          ADC scan sample with interrupt mode triggered by base timer
  - adc_scan_dma             Usage of ADC together with DMA in demand transfer mode
  - adc_scan_irq_sw          ADC scan conversion with usage of interrupt callback triggered by software
  - adc_scan_irq_mft         ADC scan conversion with usage of interrupt callback triggered by MFT
  - adc_scan_polling_sw      ADC scan conversion with polling for finished conversion triggered by software
  - adc_prio_irq_sw          ADC priority conversion with usage of interrupt callback triggered by software
  - adc_prio_polling_sw      ADC priority conversion with polling for finished conversion triggered by software
                      
- BT
  - bt_iomode        Base Timer IO modes demonstration             
  - bt_ppg           Base Timer configured as Programmable Pulse Generator
  - bt_pwc           Base Timer configured as Pulse Width Counter
  - bt_pwm           Base Timer configured as Pulse With Modulator
  - bt_rt            Base Timer configured as Reload Timer
          
- CAN 
  - can_simple       CAN communication with CANoe           
                     
- CLK  
  - clk_gating       Clock gating setting 
  - clk_init         User clock initialization

- CR
  - cr_trimming      CR trimming procedure demonstration       
                     
- CRC                
  - crc_16_32        Calculation of CRC-16 and CRC-32

- CSV
  - csv_reset        CSV reset demonstration when main/sub clock frequency is abnormal
  - fcs_int          FCS interrupt demonstration when main clock frequency is abnormal
  - fcs_reset        CSV reset demonstration when main clock frequency is abnormal
               
- DAC                
  - dac_sine_wave    DAC channels generate sine wave tones
                     
- DMA                
  - dma_software     The DMA perform a sotware block transfer (For demand transfer see ADC)

- DSTC
  - dstc_hw_transfer DSTC triggered by peripheral (BT0)
  - dstc_sw_transfer DSTC software transfer
                     
- DT                 
  - dt_unuse_int     Dual Timer configured as periodic mode for ch.0 and one-shot mode for ch.1 with usage interruption callback
  - dt_use_int       Dual Timer configured as periodic mode for ch.0 and one-shot mode for ch.1 with polling for interruption

- DSTC
  - sw_transfer      Perform DSTC transfer by software trigger
  - hw_transfer      Perform DSTC transfer by hardware trigger

- EXINT
  - exint_simple     Simple external interrupt occurence demonstration

- EXTIF              (no example)

- Flash
  - main_flash_test  Main Flash operation test
  - work_flash_test  Work Flash operation test
                     
- GPIO
  - gpio_parameterized_ports  New macros with aibility of port parameterization              
  - gpio_ports                Simple Port setting and Port read-out

- LPM
  - lpm_bu_reg       Reading and writing to Backup Registers
  - lpm_sleep_stop   MCU is set to sleep and stop mode, EXINT0 wakes up MCU
                    
- LVD                
  - lvd_unuse_int_27 LVD interrupts when voltage is vicinity of 2.7 volts. Interruption detection uses polling
  - lvd_unuse_int_28 LVD interrupts when voltage is vicinity of 2.8 volts. Interruption detection uses polling
  - lvd_unuse_int_30 LVD interrupts when voltage is vicinity of 3.0 volts. Interruption detection uses polling
  - lvd_use_int_26   LVD interrupts when voltage is vicinity of 2.6 volts. Interruption detection uses callback
  - lvd_use_int_28   LVD interrupts when voltage is vicinity of 2.8 volts. Interruption detection uses callback
  - lvd_use_int_32   LVD interrupts when voltage is vicinity of 3.2 volts. Interruption detection uses callback
                     
- MFS                
  - High Level       The samples used High Level MFS driver.
    - CSIO
      - mfs_csio_normal_master_unuse_int           MFS performs as CSIO master mode by unusing interruption
      - mfs_csio_normal_master_unuse_int_with_tmr  MFS performs as CSIO master mode by unusing interruption and using timer mode
      - mfs_csio_normal_master_use_int             MFS performs as CSIO master mode by using interruption
      - mfs_csio_normal_master_use_int_with_tmr    MFS performs as CSIO master mode by using interruption and using timer mode
      - mfs_csio_normal_slave_use_int              MFS performs as CSIO slave mode by using interruption
      - mfs_csio_spi_master_unuse_int              MFS performs as SPI master mode by unusing interruption and controling CS by GPIO
      - mfs_csio_spi_master_unuse_int_with_cs      MFS performs as SPI master mode by unusing interruption and controling CS by peripheral
      - mfs_csio_spi_master_use_int                MFS performs as SPI master mode by using interruption and controling CS by GPIO
      - mfs_csio_spi_master_use_int_with_cs        MFS performs as SPI master mode by using interruption and controling CS by peripheral
      - mfs_csio_spi_slave_use_int                 MFS performs as SPI slave mode by using interruption and unusing CS peripheral
      - mfs_csio_spi_slave_use_int_with_cs         MFS performs as SPI slave mode by using interruption and using CS peripheral
    - LIN
      - mfs_lin      MFS performs as LIN master and slave mode communicating on same MCU
    - UART
      - mfs_uart_unuse_int  MFS performs as UART normal mode by unusing interruption
      - mfs_uart_use_int    MFS performs as UART normal mode by using interruption
  - Low Level        The samples used Low Level MFS driver.
    - CSIO
      - mfs_csio_normal_master_unuse_int           MFS performs as CSIO master mode by unusing interruption
      - mfs_csio_normal_master_unuse_int_with_tmr  MFS performs as CSIO master mode by unusing interruption and using timer mode
      - mfs_csio_normal_master_use_int             MFS performs as CSIO master mode by using interruption
      - mfs_csio_normal_master_use_int_with_tmr    MFS performs as CSIO master mode by using interruption and using timer mode
      - mfs_csio_normal_slave_use_int              MFS performs as CSIO slave mode by using interruption
      - mfs_csio_spi_master_unuse_int              MFS performs as SPI master mode by unusing interruption and controling CS by GPIO
      - mfs_csio_spi_master_unuse_int_with_cs      MFS performs as SPI master mode by unusing interruption and controling CS by peripheral
      - mfs_csio_spi_master_use_int                MFS performs as SPI master mode by using interruption and controling CS by GPIO
      - mfs_csio_spi_master_use_int_with_cs        MFS performs as SPI master mode by using interruption and controling CS by peripheral
      - mfs_csio_spi_slave_use_int                 MFS performs as SPI slave mode by using interruption and unusing CS peripheral
      - mfs_csio_spi_slave_use_int_with_cs         MFS performs as SPI slave mode by using interruption and using CS peripheral
    - LIN
      - mfs_lin      MFS performs as LIN master and slave mode communicating on same MCU
    - UART
      - mfs_uart_unuse_int  MFS performs as UART normal mode by unusing interruption
      - mfs_uart_use_int    MFS performs as UART normal mode by using interruption
                     
- MFT                
  - FRT              
    - frt_int        Free-run Timer function with usage of zero/peak match interrupt callback
    - frt_polling    Free-run Timer function with polling for zero/peak match
  - ICU              
    - icu_int        Input Captuer Unit function with usage of interrupt callback
    - icu_polling    Input Captuer Unit function with polling for capture completion
  - OCU
    - ocu_ch_linked  Perform 2 change linked mode of Output Compare Unit   
    - ocu_ch_single  Perform 1-change/low-active/high-active mode of Output Compare Unit
  - WFG
    - wfg_nzcl_dtif_dttix_trig Perform DTIF interrupt triggered DTTIX
    - wfg_nzcl_dtif_sw_trig    Perform DTIF interrupt triggered software
    - wfg_ppg_dead_timer_mode  Perform PPG-dead timer mode of Waveform Generator Unit
    - wfg_rt_dead_timer_mode   Perform RT-dead timer mode of Waveform Generator Unit 
    - wfg_rt_ppg_mode          Perform RT-PPG mode of Waveform Generator Unit
    - wfg_through_mode         Perform through mode of Waveform Generator Unit
    - wfg_timer_ppg_mode       Perform Timer-PPG mode of Waveform Generator Unit

- QPRC
  - qprc_pc_directional       Perform Count mode with direction (mode 3) of Position Counter  
  - qprc_pc_updown            Perform Up/down count mode (mode 1) of Position Counter
  - qprc_pc_phase_diff        Perform Phase different count mode (mode 2) of Position Counter 
  - qprc_rc_pc_ofuf_trig      Perform Revolution Counter mode 2 (triggered by Position Counter)
  - qprc_rc_zin_pcofuf_trig   Perform Revolution Counter mode 3 (triggered by ZIN or Position Counter)
  - qprc_rc_zin_trig          Perform Revolution Counter mode 1 (triggered by ZIN)
         
- RTC
  - rtc_time_count      Usage of time counting and alarm interruption for RTC
  - rtc_timer_interval  Usage of time counting and timer interval mode for RTC
  - rtc_timer_oneshot   Usage of time counting and timer one shot mode for RTC

- SD
  - sd_sector_wr      Write/read to/from a sector of SD card via SD I/F

- UID
  - uid_read          Several methods to read the Unique ID

- USB
  - usbdevice_cdc_virtual com port          MCU acting as virtual COM port using Communications Device Class
  - usbdevice_hid_data_cdc_virtual_com_port MCU acting as composition device with HID and CDC
  - usbdevice_hid_data_communication        Data communication using HID class
  - usbdevice_hid_joystick                  MCU acting as a joystick
  - usbdevice_hid_keyboard                  MCU acting as a keyboard (writing a text)
  - usbdevice_hid_mouse                     MCU acting as mouse
  - usbdevice_hid_keyboard_mouse            MCU acting as composition 
  - usbdevice_libusb                        Usage of LibUSB
  - usbdevice_lineprinter                   Data communication via USB Printer and CDC Class
  - usbhost_keyboard_mouse                  MCU is recognizing a USB keyoard and mouse

- WC
  - wc_int            Watch Counter function with usage of interrupt callback
  - wc_polling        Watch Counter function with polling for interrupt occurrence

- WDG
  - hwwdg             Usage of hardware watchdog
  - swwdg
    - swwdg_normal    Usage of normal mode for software watchdog
    - swwdg_normal    Usage of window mode for software watchdog


Usage of example code:
----------------------

Each example code consists of a 'main.c' and a 'pdl_user.h' module.
The main module contains the example code, where 'pdl_user.h'
contains all necessary settings and definitions for the example
itself.
To use and compile an example, just copy these two modules
to the 'template/source' folder, overwriting the modules located
there. The overwritten modules have backups in the 'template/
source/backup' folder for recovery.
All adjustments for IAR Workbench and ARM/KEIL uVision IDE are
done in the template project and will fit to the example code.
Follow the explanations and advices in the main.c module's
description in the comment lines at the top.


Clock settings used in system_mbxxx.c/.h:
-----------------------------------------
Crystal:  4 MHz
HCLK:   160 MHz
PCLK0:   80 MHz
PCLK1:   80 MHz
PCLK2:   80 MHz


Folder structure of the PDL project:
------------------------------------

mb9bfxxx_pdl-vxy
 !
 +-- common
 !
 +-- example
 !    !
 !    +-- adc
 !    !    ! 
 !    !    +-- adc_dma
 !    !    +-- adc_irq
 !    !    +-- adc_polling
 !    !   ...
 !    !
 !    +-- bt
 !    !    !
 !   ...   +-- ...
 !
 +-- libray
 !    !
 !    +-- driver
 !    !    !
 !    !    +-- adc
 !    !    +-- bt
 !    !    +-- ...
 !    !   ...
 !    !
 !    +-- highlevel
 !    !    !
 !    !    +-- mfs
 !    !    +-- sd
 !    !   ...
 !    !
 !    +-- midware
 !         !
 !         +-- usb
 !              !
 !              +-- device
 !              +-- host
 !
 +-- template
       !
       +-- ARM
       !    !
       !    +-- output
       !         !
       !         +-- debug
       !         +-- release
       !
       +-- IAR
       !    !
       !    +-- config
       !    !    !
       !    !    +-- flashloader
       !    !
       !    +-- debug
       !    !    !
       !    !    +-- exe
       !    !    +-- list
       !    !    +-- obj
       !    !
       !    +-- release 
       !    !    !
       !    !    +-- exe
       !    !    +-- list
       !    !    +-- obj
       !    !
       !    +-- settings
       !
       +-- source
            !
            +-- backup

