Parallel bus (address 8 bit, data 8 bit) access sample using GPIO pins.

Dependents:   mini_board_PCU9669_demo mini_board_PCU9669

Parallel bus emulation sample code

mbed (LPC1768) does not have parallel bus but it can be emulated by GPIO.
Please find a notebook page for more infomation.

/media/uploads/nxp_ip/parallel-block-diagram.png

/media/uploads/nxp_ip/parallel_access_opt.png

Committer:
nxp_ip
Date:
Tue Aug 28 00:51:36 2012 +0000
Revision:
6:3f4c439ea51b
Parent:
1:5526d3e04b7a
parallel bus read pulse width adjust (for non-burst read also)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:d6ec2b9171cb 1 /** A sample code for "mini board PCU9669/PCA9665"
nxp_ip 0:d6ec2b9171cb 2 *
nxp_ip 0:d6ec2b9171cb 3 * @author Akifumi (Tedd) OKANO, NXP Semiconductors
nxp_ip 1:5526d3e04b7a 4 * @version 1.1
nxp_ip 1:5526d3e04b7a 5 * @date 11-Jul-2012
nxp_ip 0:d6ec2b9171cb 6 *
nxp_ip 0:d6ec2b9171cb 7 * Released under the MIT License: http://mbed.org/license/mit
nxp_ip 0:d6ec2b9171cb 8 *
nxp_ip 0:d6ec2b9171cb 9 * An operation sample of PCU9669/PCA9665 I2C bus controller.
nxp_ip 0:d6ec2b9171cb 10 * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging.
nxp_ip 0:d6ec2b9171cb 11 * The bit-banging is poerformed by PortInOut function of mbed library.
nxp_ip 0:d6ec2b9171cb 12 *
nxp_ip 0:d6ec2b9171cb 13 * To make the code porting easier, all codes are partitioned into layers to abstract other parts.
nxp_ip 0:d6ec2b9171cb 14 * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*".
nxp_ip 0:d6ec2b9171cb 15 * This module may need to be modified for the porting.
nxp_ip 0:d6ec2b9171cb 16 *
nxp_ip 0:d6ec2b9171cb 17 * All other upper layers are writen in standard-C.
nxp_ip 0:d6ec2b9171cb 18 *
nxp_ip 0:d6ec2b9171cb 19 * base code is written from 05-Sep-2011 to 09-Sep-2011.
nxp_ip 0:d6ec2b9171cb 20 * And demo code has been build on 11-Sep-2011.
nxp_ip 0:d6ec2b9171cb 21 * Debug and code adjustment has been done on 08-Sep-2011.
nxp_ip 0:d6ec2b9171cb 22 * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011
nxp_ip 0:d6ec2b9171cb 23 * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012
nxp_ip 0:d6ec2b9171cb 24 * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012.
nxp_ip 0:d6ec2b9171cb 25 *
nxp_ip 0:d6ec2b9171cb 26 * Before builidng the code, please edit the file mini_board_PCU9669/config.h
nxp_ip 0:d6ec2b9171cb 27 * Un-comment the target name what you want to target.
nxp_ip 0:d6ec2b9171cb 28 */
nxp_ip 0:d6ec2b9171cb 29
nxp_ip 0:d6ec2b9171cb 30 /** Hardware abstraction layer module
nxp_ip 0:d6ec2b9171cb 31 *
nxp_ip 0:d6ec2b9171cb 32 * All MCU hardware related code are defined in this module
nxp_ip 0:d6ec2b9171cb 33 * This module may need to be modified when the code is ported to other MCU.
nxp_ip 0:d6ec2b9171cb 34 */
nxp_ip 0:d6ec2b9171cb 35
nxp_ip 0:d6ec2b9171cb 36 #ifndef MINIBOARD_HARDWARE_ABS__
nxp_ip 0:d6ec2b9171cb 37 #define MINIBOARD_HARDWARE_ABS__
nxp_ip 0:d6ec2b9171cb 38
nxp_ip 0:d6ec2b9171cb 39 /** @def BURST_DATA_ACCESS
nxp_ip 0:d6ec2b9171cb 40 *
nxp_ip 0:d6ec2b9171cb 41 * To accelerate multiple bus access on same addess, use BURST_DATA_ACCESS
nxp_ip 0:d6ec2b9171cb 42 * On the mbed emvironment, this burst access enables 3 times faster read/write compare to single access.
nxp_ip 0:d6ec2b9171cb 43 * For code porting, the BURST_DATA_ACCESS code part is not neccesary if the hardware is fast enough.
nxp_ip 0:d6ec2b9171cb 44 */
nxp_ip 0:d6ec2b9171cb 45 #define BURST_DATA_ACCESS
nxp_ip 0:d6ec2b9171cb 46
nxp_ip 0:d6ec2b9171cb 47
nxp_ip 0:d6ec2b9171cb 48 /** @def ASSERT / DEASSERT
nxp_ip 0:d6ec2b9171cb 49 *
nxp_ip 0:d6ec2b9171cb 50 * Reset signal logic difinition
nxp_ip 0:d6ec2b9171cb 51 */
nxp_ip 0:d6ec2b9171cb 52 #define ASSERT 0 // for hardware reset
nxp_ip 0:d6ec2b9171cb 53 #define DEASSERT 1 // for hardware reset
nxp_ip 0:d6ec2b9171cb 54
nxp_ip 0:d6ec2b9171cb 55
nxp_ip 0:d6ec2b9171cb 56 /** Install an ISR
nxp_ip 0:d6ec2b9171cb 57 *
nxp_ip 0:d6ec2b9171cb 58 * Registering function as ISR.
nxp_ip 0:d6ec2b9171cb 59 * The function will be called when the interrupt asserted.
nxp_ip 0:d6ec2b9171cb 60 *
nxp_ip 0:d6ec2b9171cb 61 * @param fptr a pointer to a function
nxp_ip 0:d6ec2b9171cb 62 */
nxp_ip 0:d6ec2b9171cb 63 void install_ISR( void (*fptr)(void) );
nxp_ip 0:d6ec2b9171cb 64
nxp_ip 0:d6ec2b9171cb 65 /** Hardware initialization
nxp_ip 0:d6ec2b9171cb 66 *
nxp_ip 0:d6ec2b9171cb 67 * MCU side initialization should be done in this function.
nxp_ip 0:d6ec2b9171cb 68 * For the mbed, it set the initial state of parallel bus control signal.
nxp_ip 0:d6ec2b9171cb 69 */
nxp_ip 0:d6ec2b9171cb 70 void hardware_initialize( void );
nxp_ip 0:d6ec2b9171cb 71
nxp_ip 0:d6ec2b9171cb 72 /** Reset signal control
nxp_ip 0:d6ec2b9171cb 73 *
nxp_ip 0:d6ec2b9171cb 74 * This function drives the RESET signal line with given state.
nxp_ip 0:d6ec2b9171cb 75 *
nxp_ip 0:d6ec2b9171cb 76 * @param signal the state of RESET signal: ASSERT | DEASSERT
nxp_ip 0:d6ec2b9171cb 77 */
nxp_ip 0:d6ec2b9171cb 78 void hardware_reset( char signal );
nxp_ip 0:d6ec2b9171cb 79
nxp_ip 0:d6ec2b9171cb 80 /** Hardware reset
nxp_ip 0:d6ec2b9171cb 81 *
nxp_ip 0:d6ec2b9171cb 82 * Asserts the RESET signal with required pulse width and waits its recovery time
nxp_ip 0:d6ec2b9171cb 83 *
nxp_ip 0:d6ec2b9171cb 84 * @param reset_pulse_width_us RESET pulse width in micro-seconds
nxp_ip 0:d6ec2b9171cb 85 * @param reset_recovery_us RESET recovery time in micro-seconds (wait time after RESET de-assertion)
nxp_ip 0:d6ec2b9171cb 86 */
nxp_ip 0:d6ec2b9171cb 87 void reset( int reset_pulse_width_us, int reset_recovery_us );
nxp_ip 0:d6ec2b9171cb 88
nxp_ip 0:d6ec2b9171cb 89 /** Triger signal control
nxp_ip 0:d6ec2b9171cb 90 *
nxp_ip 0:d6ec2b9171cb 91 * This function drives the TRIGGER signal line with given state.
nxp_ip 0:d6ec2b9171cb 92 *
nxp_ip 0:d6ec2b9171cb 93 * @param signal the state of TRIGGER signal: ASSERT | DEASSERT
nxp_ip 0:d6ec2b9171cb 94 */
nxp_ip 0:d6ec2b9171cb 95 void hardware_trigger( char signal );
nxp_ip 0:d6ec2b9171cb 96
nxp_ip 0:d6ec2b9171cb 97 /** Write data
nxp_ip 0:d6ec2b9171cb 98 *
nxp_ip 0:d6ec2b9171cb 99 * Writes 1 byte
nxp_ip 0:d6ec2b9171cb 100 *
nxp_ip 0:d6ec2b9171cb 101 * @param addr 8 bit address where the data should be written to
nxp_ip 0:d6ec2b9171cb 102 * @param data 8 bit data which will be written
nxp_ip 0:d6ec2b9171cb 103 * @see read_data()
nxp_ip 0:d6ec2b9171cb 104 */
nxp_ip 0:d6ec2b9171cb 105 void write_data( char addr, char data );
nxp_ip 0:d6ec2b9171cb 106
nxp_ip 0:d6ec2b9171cb 107 /** Read data
nxp_ip 0:d6ec2b9171cb 108 *
nxp_ip 0:d6ec2b9171cb 109 * Reads 1 byte
nxp_ip 0:d6ec2b9171cb 110 *
nxp_ip 0:d6ec2b9171cb 111 * @return 8 bit data which is read from bus
nxp_ip 0:d6ec2b9171cb 112 * @param addr 8 bit address where the data should be read from
nxp_ip 0:d6ec2b9171cb 113 * @see write_data()
nxp_ip 0:d6ec2b9171cb 114 */
nxp_ip 0:d6ec2b9171cb 115 char read_data( char addr );
nxp_ip 0:d6ec2b9171cb 116
nxp_ip 0:d6ec2b9171cb 117 /** Wait micro-seconds
nxp_ip 0:d6ec2b9171cb 118 *
nxp_ip 0:d6ec2b9171cb 119 * Wait function waits given-micro-seconds
nxp_ip 0:d6ec2b9171cb 120 *
nxp_ip 0:d6ec2b9171cb 121 * @param micro-seconds the program should wait (32 bit integer value)
nxp_ip 0:d6ec2b9171cb 122 * @see wait_sec()
nxp_ip 0:d6ec2b9171cb 123 */
nxp_ip 0:d6ec2b9171cb 124 void hw_wait_us( int v );
nxp_ip 0:d6ec2b9171cb 125
nxp_ip 0:d6ec2b9171cb 126 /** Wait seconds
nxp_ip 0:d6ec2b9171cb 127 *
nxp_ip 0:d6ec2b9171cb 128 * Wait function waits given-seconds
nxp_ip 0:d6ec2b9171cb 129 *
nxp_ip 0:d6ec2b9171cb 130 * @param seconds the program should wait (float value)
nxp_ip 0:d6ec2b9171cb 131 * @see hw_wait_us()
nxp_ip 0:d6ec2b9171cb 132 */
nxp_ip 0:d6ec2b9171cb 133 void wait_sec( float );
nxp_ip 0:d6ec2b9171cb 134
nxp_ip 0:d6ec2b9171cb 135
nxp_ip 0:d6ec2b9171cb 136 /** BURST_DATA_ACCESS option code
nxp_ip 0:d6ec2b9171cb 137 *
nxp_ip 0:d6ec2b9171cb 138 * This code is option to accelerate the bus access
nxp_ip 0:d6ec2b9171cb 139 */
nxp_ip 0:d6ec2b9171cb 140 #ifdef BURST_DATA_ACCESS
nxp_ip 0:d6ec2b9171cb 141
nxp_ip 0:d6ec2b9171cb 142 /** Write data
nxp_ip 0:d6ec2b9171cb 143 *
nxp_ip 0:d6ec2b9171cb 144 * Writes multiple bytes to same address.
nxp_ip 0:d6ec2b9171cb 145 * This function suitable to use for the registers like SLATABLE, TRANCONFIG and data buffers (through DATA register).
nxp_ip 0:d6ec2b9171cb 146 * While this access is going, the interrupt will be tempolary disabled (ISR execution will be postponed)
nxp_ip 0:d6ec2b9171cb 147 *
nxp_ip 0:d6ec2b9171cb 148 * @param addr 8 bit address where the data should be written to
nxp_ip 0:d6ec2b9171cb 149 * @param *data pointer to char array. The data in this array will be written
nxp_ip 0:d6ec2b9171cb 150 * @param length length of the data (bytes)
nxp_ip 0:d6ec2b9171cb 151 * @see read_data_burst()
nxp_ip 0:d6ec2b9171cb 152 */
nxp_ip 0:d6ec2b9171cb 153 void write_data_burst( char addr, char *data, char length );
nxp_ip 0:d6ec2b9171cb 154
nxp_ip 0:d6ec2b9171cb 155 /** Read data
nxp_ip 0:d6ec2b9171cb 156 *
nxp_ip 0:d6ec2b9171cb 157 * Reads multiple bytes from same address.
nxp_ip 0:d6ec2b9171cb 158 * This function suitable to use for the registers like SLATABLE, TRANCONFIG and data buffers (through DATA register).
nxp_ip 0:d6ec2b9171cb 159 * While this access is going, the interrupt will be tempolary disabled (ISR execution will be postponed)
nxp_ip 0:d6ec2b9171cb 160 *
nxp_ip 0:d6ec2b9171cb 161 * @param addr 8 bit address where the data should be written to
nxp_ip 0:d6ec2b9171cb 162 * @param *data pointer to char array. The read data will be written to this
nxp_ip 0:d6ec2b9171cb 163 * @param length length of the data (bytes)
nxp_ip 0:d6ec2b9171cb 164 * @see write_data_burst()
nxp_ip 0:d6ec2b9171cb 165 */
nxp_ip 0:d6ec2b9171cb 166 void read_data_burst( char addr, char *data, char length );
nxp_ip 0:d6ec2b9171cb 167 #endif
nxp_ip 0:d6ec2b9171cb 168
nxp_ip 0:d6ec2b9171cb 169 #endif // MINIBOARD_HARDWARE_ABS__
nxp_ip 0:d6ec2b9171cb 170