naspi_extern\slave: SPI Slave External Peripheral Example Application 

Overview
--------
This application shows how to use the simple SPI Slave API and
demonstrates the communication between SPI master and SPI Slave.

The application is written for SPI Slave. SPI Master
resides externally (different board). 

When SPI Master initates a transfer, SPI slave may or may not receive or process
the data. Therefore, this application uses "string pattern" embedded in the transfer 
data to assure the data is received between the master and slave.

This application starts setting 10 buffers with 256 bytes of data (APP_SPI_SLAVE_RAW_DATA_SIZE) 
before the slave receives "string pattern" from the master. It sets the first buffer 
to 0xEE, the second buffer to 0xDD, the third buffer to 0xCC,...etc. 

Once the SPI Slave application receives "string pattern" from the master, it 
will start decoding and processing the opcode.

Note: The SPI Slave must start before the SPI Master.

The opcodes are defined in spi_conf.h:

APP_SPI_DEVICE_OPCODE_WREN    write enable      
APP_SPI_DEVICE_OPCODE_WRDI    write disable
APP_SPI_DEVICE_OPCODE_RDSR    read device status register
APP_SPI_DEVICE_OPCODE_WRSR    write device status register
APP_SPI_DEVICE_OPCODE_READ    read 32 bytes of memory
APP_SPI_DEVICE_OPCODE_WRITE   write 32 bytes of memory

Each opcode will be decoded and responded back to the SPI Master:

    |string pattern|APP_SPI_DEVICE_OPCODE_WREN|
    |string pattern|APP_SPI_DEVICE_OPCODE_WRDI|
    |string pattern|APP_SPI_DEVICE_OPCODE_RDSR|status register value|
    |string pattern|APP_SPI_DEVICE_OPCODE_WRSR|
    |string pattern|APP_SPI_DEVICE_OPCODE_READ|offset hi byte|32 bytes of data|
    |string pattern|APP_SPI_DEVICE_OPCODE_WRITE|offset hi byte|offset lo byte|

Before APP_SPI_DEVICE_OPCODE_WRSR or APP_SPI_DEVICE_OPCODE_WRITE opcode, APP_SPI_DEVICE_OPCODE_WREN
APP_SPI_DEVICE_OPCODE_WREN must be received first. 

The format of the SPI Slave device status register:
       bit   3    2   1   0
           |WREN|BP0|BP1|RDY|

BP0 and BP1 are settable.


The length for each transfer must be 64 bytes of length.

This application is SPI Slave and it waits for SPI Master transfer.


Supported Platforms and Processors
----------------------------------
This application uses the SPI Slave API, thus requires the SPI Module
hardware. With modification, this application can be
ported to other Development board that supports SPI Slave.

Features and APIs being demonstrated
------------------------------------
    SPI Slave
    - NASpiSlaveInitialize()
    - NASpiSlaveEnqueueBuffer()

Required external equipment and setup
-------------------------------------
SPI Slave Board Setup

    1. Find out the GPIO pin for SPI Slave RX, TX, CLK, and CS.
       Refer to the hardware manual for more information about GPIO pins for platform you are using.
    2. Connect RX to SPI Master TX.
       Connect TX to SPI Master RX.
       Connect CLK to SPI Master CLK
       Connect CS to SPI Master CS.
       Connect GND to GND on SPI Master's board
       See below for specific pins for each platform.

       If PLATFORM is not one of the following platforms, specify GPIO pin settings in root.c
       and comment out the error message in Makefile.
-------------------------------------
    For Connectme 9210 platform:

        1. The P3 is used to connect SPI Master and the following GPIO pins are
           used.

            P3[pin 8]  GPIO 7 TX
            P3[pin 7]  GPIO 3 RX
            P3[pin 9]  GPIO 5 CLK
            P3[pin 13] GPIO 0 EN
            P3[pin 16] GND

            If different GPIO pins are used, change it in spi_conf.h
            #define APP_SPI_SLAVE_GPIO_CS       0
            #define APP_SPI_SLAVE_GPIO_CLK      5
            #define APP_SPI_SLAVE_GPIO_RXD      3
            #define APP_SPI_SLAVE_GPIO_TXD      7

        2. Set all switches on SW3 to GPIO selection.

        3. Serial Port A must be disabled (place a jumper on P5 to disable 232).
           Set BSP_STDIO_PORT & BSP_DIALOG_PORT to /com/2 in bsp_sys.h.
           P2 Serial Port 2 will be used for serial output.
           



    For ConnectCore 9P 9215 platform:

        1. The X8 (SPI header) is used to connect SPI Master.
           X8[pin 1] +3.3v
           X8[pin 2] GPIO 7 TX
           X8[pin 3] GPIO 3 RX
           X8[pin 4] GPIO 5 CLK
           X8[pin 5] GPIO 0 EN
           X8[pin 6] GND

           If different GPIO pins are used, change it in spi_conf.h
           #define APP_SPI_SLAVE_GPIO_CS      0
           #define APP_SPI_SLAVE_GPIO_CLK     5
           #define APP_SPI_SLAVE_GPIO_RXD     3
           #define APP_SPI_SLAVE_GPIO_TXD     7
            
    For ConnectCore 9C or ConnectCore Wi-9C platform:
    1. Set appropriate serial port to BSP_SERIAL_SPI_SLAVE_DRIVER in bsp_serial.h and 
       rebuild the BSP.
       Make sure the GPIO Mux for the serial port is not set to BSP_GPIO_MUX_INTERNAL_USE_ONLY.
       i.e. #define BSP_SERIAL_PORT_2 BSP_SERIAL_SPI_SLAVE_DRIVER.
            #define BSP_GPIO_MUX_SERIAL_B BSP_GPIO_MUX_SERIAL_SPI_APP 

    2. The P7 (SPI header) is Port B (BSP_SERIAL_PORT_2 and BSP_GPIO_MUX_SERIAL_B) and is used to connect SPI Master.
           P7[pin 1] +3.3v
           P7[pin 2] GPIO 0 TX_B
           P7[pin 3] GPIO 1 RX_B
           P7[pin 4] GPIO 6 CLK
           P7[pin 5] GPIO 7 EN
           P7[pin 6] GND
            
           If different port is used, update APP_SPI_MASTER_PORT and GPIO pins in spi_conf.h
            #define APP_SPI_SLAVE_PORT         PORTB
            #define APP_SPI_SLAVE_GPIO_CS      7
            #define APP_SPI_SLAVE_GPIO_CLK     6

The application uses the following files located in the
netos\src\linkerScripts directory.  These files are generated
when the BSP is built.

bootldr.dat     bootloader configuration file used to generate the
                file image.bin.  It controls the information placed
                in the bootloader header of the image.

image.ldr       GNU linker script used to build an image that can
                be debugged and used with the bootloader.
                
customize.ldr   Customizable GNU linker script

