napwm: Pulse Width Modulation Example
This application is used to test Pulse Width Modulation APIs
under NET+Works development board.  

This example works on NS9360, NS9210 and NS9215 based development boards.

Application can be used to test 2 PWM modes
1. Basic PWM functions - supported in NS9360 and NS9215
2. Enhanced PWM functions - supported in NS9210 and NS9215

To test the PWM API do the following:
1. Change the GPIO settings based on the processor 
	a. For NS9360 development boards
		1. Configure GPIO pins (36,37,38,39) for PWM output in gpio.h
		   BSP_GPIO_MUX_PWM_0  BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_PWM_1  BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_PWM_2  BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_PWM_3  BSP_GPIO_MUX_USE_PRIMARY_PATH
        2. Make sure BSP_GPIO_MUX_LCD is set to BSP_GPIO_MUX_INTERNAL_USE_ONLY
		3. Configure GPIO pin 65 to logic 0 (BSP_GPIO_INITIAL_STATE_PIN65 to 
		   BSP_GPIO_INITIAL_STATE_OUTPUT_DRIVER_LOGIC0)
	b. For NS9210 development boards
		1. Configure timer 6 and 9 output to a GPIO pin
		   BSP_GPIO_MUX_TIMER_6_OUTPUT 	BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_TIMER_9_OUTPUT 	BSP_GPIO_MUX_USE_PRIMARY_PATH
		2. Make sure both serial PORT A and C are configured as 2 wire, 
                   otherwise you will see GPIO conflict
	c. For NS9215 development boards
		1. Configure timer 8 and 9 output to a GPIO pin
		   BSP_GPIO_MUX_TIMER_8_OUTPUT 	BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_TIMER_9_OUTPUT 	BSP_GPIO_MUX_USE_PRIMARY_PATH
		2. Make sure serial PORT C is configured as 2 wire, otherwise you will
		   see GPIO conflict
		3. Configure GPIO pins (70,71,72,73 and 100) for PWM output in gpio.h
		   BSP_GPIO_MUX_PWM_0  BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_PWM_1  BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_PWM_2  BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_PWM_3  BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_PWM_4  BSP_GPIO_MUX_USE_PRIMARY_PATH
		4. Change following pins if they are set to BSP_GPIO_MUX_USE_2ND_ALTERNATE_PATH
		   BSP_GPIO_MUX_IOP_0_GEN_IO_2  BSP_GPIO_MUX_INTERNAL_USE_ONLY
		   BSP_GPIO_MUX_IOP_1_GEN_IO_2  BSP_GPIO_MUX_INTERNAL_USE_ONLY
		   BSP_GPIO_MUX_IOP_0_GEN_IO_3  BSP_GPIO_MUX_INTERNAL_USE_ONLY
		   BSP_GPIO_MUX_IOP_1_GEN_IO_3  BSP_GPIO_MUX_INTERNAL_USE_ONLY
		5. Change following pins if they are set to BSP_GPIO_MUX_USE_PRIMARY_PATH
		   BSP_GPIO_MUX_IOP_0_GEN_IO_4  BSP_GPIO_MUX_INTERNAL_USE_ONLY
		   BSP_GPIO_MUX_IOP_1_GEN_IO_4  BSP_GPIO_MUX_INTERNAL_USE_ONLY
		   BSP_GPIO_MUX_IOP_0_GEN_IO_5  BSP_GPIO_MUX_INTERNAL_USE_ONLY
		   BSP_GPIO_MUX_IOP_1_GEN_IO_5  BSP_GPIO_MUX_INTERNAL_USE_ONLY        
2.  Build BSP and this application
3.  Connect the scope to the PWM channel (see the note below)
4.  Power up the development board
5.  Start the debugger and download the application to the
    board.
6.  Run the application.
    
The following files are provided with this application:

appconf.h           sets application configuration settings
.\32b\makefile      Make file for the GNU toolset.
readme              this file
root.c              contains the applicationStart() function, that
                    that intern calls the PWM APIs

In addition, the following files in the BSP directory are built
as part of this application:

appconf_api.c   contains run time access to the application configuration

The basic PWM test functions starts with pulse width 1 msec and period 12 msec

1. Opens channel 2
2. Channel 2 uses timer 4 and timer 5 (concatinated). 
   Note: If the channel is already in use then naPwmOpen on that channel
   will fail with "out of resources". In this case the application will 
   continue from step 1 with the next available channel. 
3. If success it starts the PWM with pulse width 1 msec and period 12 msec
4. Waits in this state for 10 seconds
5. Increases the pulse width by one msec after every 10 seconds, until
   pulsewidth equals to 11 msec
6. Stops the channel 2
7. Starts the channel 2 and waits for 10 seconds
8. Stops the channel 2
9. Configures the channel 2 with 4 mseconds pulsewidth and waits for 5 seconds
   No PWM should start at this time because channel is stopped
10. Starts the channel 2 and waits for 5 seconds, make sure channel starts with
    new configuration
11. Stops the channel 2
12. Closes the channel 2
13. Repeats 1 to 12 for channel3 (and channel 4 for NS9215 only)

Enhanced PWM test functions starts at period 20 msec, pulse width 10 msec 
and delay of 0 msec
1. Opens channel 8 (timer 8) using naPwmExtOpen
2. Configures period, pulse width and delay using naPwmExtConfigure
3. Starts (naPwmExtStart) the channel and waits for 10 seconds then calls 
   naPwmExtStop
4. Closees the channel using naPwmExtClose
5. Repeats step 2 to 4, for period += 0.5 msec, pulsewidth -= 1 msec, and 
   delay += 2 msec
6. Repeats 1 to 5 for channel 9 (timer 9)

Enhanced PWM test to start channel synchronously on channel 8 and 9
1. Calls naPwmExtSetSynchronousStart() to reset timer 8 and 9
2. Configures channel 8 with period 20 msec, pulse width 5 msec and delay of
   10 msec then calls naPwmExtStart()
3. Configures channel 9 with period 20 msec, pulse width of 1 msec and delay
   of 0 msec then calls naPwmExtStart ()
4. Calls naPwmExtSetSynchronousStart() to enable timer 8 and 9 at a time 

Note: You can also get the PWM channel output from LCD signal header
In ns9360_a_eng platform
------------------------
Pin 20: PWM Channel 0
Pin 22: PWM Channel 1
Pin 24: PWM Channel 2
Pin 26: PWM Channel 3

In ns9360_a platform
--------------------
Basic PWM signal can be found on LCD/IO connector P11
Pin 10: PWM Channel 0
Pin 9:  PWM Channel 1
Pin 8:  PWM Channel 2
Pin 7:  PWm Channel 3

In connectcore9p9215_a board
----------------------------
PWM Channel 0 - GPIO 70  (X2 - pin 38)
PWM Channel 1 - GPIO 71  (X2 - pin 39)
PWM Channel 2 - GPIO 72  (X2 - pin 40)
PWM Channel 3 - GPIO 73  (X2 - pin 41)
PWM Channel 4 - GPIO 100 (X2 - pin 63)
PWM Channel 6 - Timer 6 output (GPIO 5)  (X2 - pin 8)
PWM Channel 7 - Timer 7 output (GPIO 7)  (X2 - pin 10) 
PWM channel 8 - Timer 8 output (GPIO 8)  (X2 - pin 11)
PWM channel 9 - Timer 9 output (GPIO 13) (X2 - pin 16)

In connectme9210 board
----------------------
(Cannot access PWM channel 0 - PWM channel 4)
PWM Channel 6 - Timer 6 output (GPIO 5)
PWM Channel 7 - Timer 7 output (GPIO 7)
PWM channel 8 - Timer 8 output (GPIO 8)
PWM channel 9 - Timer 9 output (GPIO 13)

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
