mini board PCU9669 (and PCA9665) sample code
Dependencies: mbed PCU9669 utility PCA9665 I2C_slaves parallel_bus
Fork of mini_board_PCU9669_old by
Sample code for PCU9669 (PCU9661, PCA9663, PCA9661 and PCA9665) evaluation board.
PCU9669 evaluation board: Mini board PCU9669
User manual is available -> http://www.nxp.com/documents/user_manual/UM10580.pdf
mini_board_libs/PCU9669/transfer_manager.c@5:57c345099873, 2012-03-26 (annotated)
- Committer:
- nxp_ip
- Date:
- Mon Mar 26 06:17:23 2012 +0000
- Revision:
- 5:57c345099873
tempolary version for trouble shooting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxp_ip | 5:57c345099873 | 1 | /** A sample code for "mini board PCU9669/PCA9665" |
nxp_ip | 5:57c345099873 | 2 | * |
nxp_ip | 5:57c345099873 | 3 | * @author Tedd OKANO, NXP Semiconductors |
nxp_ip | 5:57c345099873 | 4 | * @version 0.9 |
nxp_ip | 5:57c345099873 | 5 | * @date 14-Feb-2011 |
nxp_ip | 5:57c345099873 | 6 | * |
nxp_ip | 5:57c345099873 | 7 | * Released under the MIT License: http://mbed.org/license/mit |
nxp_ip | 5:57c345099873 | 8 | * |
nxp_ip | 5:57c345099873 | 9 | * An operation sample of PCU9669/PCA9665 I2C bus controller. |
nxp_ip | 5:57c345099873 | 10 | * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. |
nxp_ip | 5:57c345099873 | 11 | * The bit-banging is poerformed by PortInOut function of mbed library. |
nxp_ip | 5:57c345099873 | 12 | * |
nxp_ip | 5:57c345099873 | 13 | * To make the code porting easier, all codes are partitioned into layers to abstract other parts. |
nxp_ip | 5:57c345099873 | 14 | * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". |
nxp_ip | 5:57c345099873 | 15 | * This module may need to be modified for the porting. |
nxp_ip | 5:57c345099873 | 16 | * |
nxp_ip | 5:57c345099873 | 17 | * All other upper layers are writen in standard-C. |
nxp_ip | 5:57c345099873 | 18 | * |
nxp_ip | 5:57c345099873 | 19 | * base code is written from 05-Sep-2011 to 09-Sep-2011. |
nxp_ip | 5:57c345099873 | 20 | * And demo code has been build on 11-Sep-2011. |
nxp_ip | 5:57c345099873 | 21 | * Debug and code adjustment has been done on 08-Sep-2011. |
nxp_ip | 5:57c345099873 | 22 | * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 |
nxp_ip | 5:57c345099873 | 23 | * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 |
nxp_ip | 5:57c345099873 | 24 | * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. |
nxp_ip | 5:57c345099873 | 25 | * |
nxp_ip | 5:57c345099873 | 26 | * Before builidng the code, please edit the file mini_board_PCU9669/config.h |
nxp_ip | 5:57c345099873 | 27 | * Uncomment the target name what you want to target. |
nxp_ip | 5:57c345099873 | 28 | */ |
nxp_ip | 5:57c345099873 | 29 | |
nxp_ip | 5:57c345099873 | 30 | /* |
nxp_ip | 5:57c345099873 | 31 | * "transfer_manager" is a module to manage I2C bus transfers. |
nxp_ip | 5:57c345099873 | 32 | * In this sample code, single slave access (from START or RESTART condition to STOP or next RESTART |
nxp_ip | 5:57c345099873 | 33 | * condition) is called transaction. |
nxp_ip | 5:57c345099873 | 34 | * |
nxp_ip | 5:57c345099873 | 35 | * In this software, the transaction is a struct (the struct is defined in "transfer_manager.h") |
nxp_ip | 5:57c345099873 | 36 | * |
nxp_ip | 5:57c345099873 | 37 | * typedef struct transaction_st { |
nxp_ip | 5:57c345099873 | 38 | * char i2c_address __attribute__((packed)); |
nxp_ip | 5:57c345099873 | 39 | * char *data __attribute__((packed)); |
nxp_ip | 5:57c345099873 | 40 | * char length __attribute__((packed)); |
nxp_ip | 5:57c345099873 | 41 | * } |
nxp_ip | 5:57c345099873 | 42 | * transaction; |
nxp_ip | 5:57c345099873 | 43 | * |
nxp_ip | 5:57c345099873 | 44 | * The transaction has target I2C slave address pointer to the data array and the data length. |
nxp_ip | 5:57c345099873 | 45 | * Read/write drection is maneged by LSB of the i2c_address. |
nxp_ip | 5:57c345099873 | 46 | * |
nxp_ip | 5:57c345099873 | 47 | * For the reading, in this version, a dummy data array can be used but it need to have actual data |
nxp_ip | 5:57c345099873 | 48 | * because it will be accessed for buffer filling. |
nxp_ip | 5:57c345099873 | 49 | * And transfer manager doesn't readback the buffer. So user need to readback by "buffer_read()" |
nxp_ip | 5:57c345099873 | 50 | * function after transaction executed. |
nxp_ip | 5:57c345099873 | 51 | * |
nxp_ip | 5:57c345099873 | 52 | * A transfer can be represented by array of transaction, i.e... |
nxp_ip | 5:57c345099873 | 53 | * |
nxp_ip | 5:57c345099873 | 54 | * transaction a_sample_of_transfer[]; |
nxp_ip | 5:57c345099873 | 55 | * |
nxp_ip | 5:57c345099873 | 56 | * This array_of_transaction: "transfer" is used for the setting of the registers and buffers. |
nxp_ip | 5:57c345099873 | 57 | * |
nxp_ip | 5:57c345099873 | 58 | * See "main.cpp" for the actual sample of those transfer/transaction usage |
nxp_ip | 5:57c345099873 | 59 | */ |
nxp_ip | 5:57c345099873 | 60 | |
nxp_ip | 5:57c345099873 | 61 | #include "transfer_manager.h" |
nxp_ip | 5:57c345099873 | 62 | #include "PCU9669_access.h" // PCU9669 chip access interface |
nxp_ip | 5:57c345099873 | 63 | |
nxp_ip | 5:57c345099873 | 64 | void setup_transfer( char ch, transaction *t, char n_of_transaction ) { |
nxp_ip | 5:57c345099873 | 65 | int i; |
nxp_ip | 5:57c345099873 | 66 | #ifdef PCU9969_BURST_DATA_ACCESS |
nxp_ip | 5:57c345099873 | 67 | #else |
nxp_ip | 5:57c345099873 | 68 | int j; |
nxp_ip | 5:57c345099873 | 69 | #endif |
nxp_ip | 5:57c345099873 | 70 | |
nxp_ip | 5:57c345099873 | 71 | write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) |
nxp_ip | 5:57c345099873 | 72 | |
nxp_ip | 5:57c345099873 | 73 | for ( i = 0; i < n_of_transaction; i++ ) |
nxp_ip | 5:57c345099873 | 74 | write_ch_register( ch, SLATABLE, (t + i)->i2c_address ); // |
nxp_ip | 5:57c345099873 | 75 | |
nxp_ip | 5:57c345099873 | 76 | write_ch_register( ch, TRANCONFIG, n_of_transaction ); // first byte of TRANCONFIG sets to # of transactions |
nxp_ip | 5:57c345099873 | 77 | write_ch_register( ch, TRANSEL, 0 ); // select #0 transaction |
nxp_ip | 5:57c345099873 | 78 | |
nxp_ip | 5:57c345099873 | 79 | for ( i = 0; i < n_of_transaction; i++ ) |
nxp_ip | 5:57c345099873 | 80 | write_ch_register( ch, TRANCONFIG, (t + i)->length ); |
nxp_ip | 5:57c345099873 | 81 | |
nxp_ip | 5:57c345099873 | 82 | |
nxp_ip | 5:57c345099873 | 83 | #ifdef PCU9969_BURST_DATA_ACCESS |
nxp_ip | 5:57c345099873 | 84 | for ( i = 0; i < n_of_transaction; i++ ) |
nxp_ip | 5:57c345099873 | 85 | write_ch_register_burst( ch, DATA, ((t + i)->data), (t + i)->length ); |
nxp_ip | 5:57c345099873 | 86 | |
nxp_ip | 5:57c345099873 | 87 | #else |
nxp_ip | 5:57c345099873 | 88 | for ( i = 0; i < n_of_transaction; i++ ) |
nxp_ip | 5:57c345099873 | 89 | for ( j = 0; j < (t + i)->length; j++ ) |
nxp_ip | 5:57c345099873 | 90 | write_ch_register( ch, DATA, *(((t + i)->data) + j) ); |
nxp_ip | 5:57c345099873 | 91 | #endif |
nxp_ip | 5:57c345099873 | 92 | } |
nxp_ip | 5:57c345099873 | 93 | |
nxp_ip | 5:57c345099873 | 94 | |
nxp_ip | 5:57c345099873 | 95 | void set_n_of_transaction( char ch, char n_of_transaction ) |
nxp_ip | 5:57c345099873 | 96 | { |
nxp_ip | 5:57c345099873 | 97 | write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) |
nxp_ip | 5:57c345099873 | 98 | write_ch_register( ch, TRANCONFIG, n_of_transaction ); // first byte of TRANCONFIG sets to # of transactions |
nxp_ip | 5:57c345099873 | 99 | } |
nxp_ip | 5:57c345099873 | 100 | |
nxp_ip | 5:57c345099873 | 101 | |
nxp_ip | 5:57c345099873 | 102 | void buffer_overwrite( char ch, char transaction_number, char offset, char *data, char length ) { |
nxp_ip | 5:57c345099873 | 103 | #ifdef PCU9969_BURST_DATA_ACCESS |
nxp_ip | 5:57c345099873 | 104 | #else |
nxp_ip | 5:57c345099873 | 105 | int i; |
nxp_ip | 5:57c345099873 | 106 | #endif |
nxp_ip | 5:57c345099873 | 107 | |
nxp_ip | 5:57c345099873 | 108 | write_ch_register( ch, TRANSEL, transaction_number ); |
nxp_ip | 5:57c345099873 | 109 | write_ch_register( ch, TRANOFS, offset ); |
nxp_ip | 5:57c345099873 | 110 | |
nxp_ip | 5:57c345099873 | 111 | #ifdef PCU9969_BURST_DATA_ACCESS |
nxp_ip | 5:57c345099873 | 112 | write_ch_register_burst( ch, DATA, data, length ); |
nxp_ip | 5:57c345099873 | 113 | #else |
nxp_ip | 5:57c345099873 | 114 | for ( i = 0; i < length; i++ ) |
nxp_ip | 5:57c345099873 | 115 | write_ch_register( ch, DATA, *data++ ); |
nxp_ip | 5:57c345099873 | 116 | #endif |
nxp_ip | 5:57c345099873 | 117 | } |
nxp_ip | 5:57c345099873 | 118 | |
nxp_ip | 5:57c345099873 | 119 | void buffer_read( char ch, char transaction_number, char offset, char *data, char length ) { |
nxp_ip | 5:57c345099873 | 120 | #ifdef PCU9969_BURST_DATA_ACCESS |
nxp_ip | 5:57c345099873 | 121 | #else |
nxp_ip | 5:57c345099873 | 122 | int i; |
nxp_ip | 5:57c345099873 | 123 | #endif |
nxp_ip | 5:57c345099873 | 124 | |
nxp_ip | 5:57c345099873 | 125 | write_ch_register( ch, TRANSEL, transaction_number ); |
nxp_ip | 5:57c345099873 | 126 | write_ch_register( ch, TRANOFS, offset ); |
nxp_ip | 5:57c345099873 | 127 | |
nxp_ip | 5:57c345099873 | 128 | #ifdef PCU9969_BURST_DATA_ACCESS |
nxp_ip | 5:57c345099873 | 129 | read_ch_register_burst( ch, DATA, data, length ); |
nxp_ip | 5:57c345099873 | 130 | #else |
nxp_ip | 5:57c345099873 | 131 | for ( i = 0; i < length; i++ ) |
nxp_ip | 5:57c345099873 | 132 | *data++ = read_ch_register( ch, DATA ); |
nxp_ip | 5:57c345099873 | 133 | #endif |
nxp_ip | 5:57c345099873 | 134 | } |
nxp_ip | 5:57c345099873 | 135 | |
nxp_ip | 5:57c345099873 | 136 | void start( char ch ) { |
nxp_ip | 5:57c345099873 | 137 | write_ch_register( ch, CONTROL, 0x40 ); |
nxp_ip | 5:57c345099873 | 138 | } |
nxp_ip | 5:57c345099873 | 139 | |
nxp_ip | 5:57c345099873 | 140 | void start_by_trigger( char ch, char polarity ) { |
nxp_ip | 5:57c345099873 | 141 | write_ch_register( ch, CONTROL, 0x48 | (polarity ? 0x10 : 0x00 ) ); |
nxp_ip | 5:57c345099873 | 142 | } |
nxp_ip | 5:57c345099873 | 143 | |
nxp_ip | 5:57c345099873 | 144 | void stop( char ch ) { |
nxp_ip | 5:57c345099873 | 145 | write_ch_register( ch, CONTROL, 0x20 ); // set STO bit |
nxp_ip | 5:57c345099873 | 146 | } |
nxp_ip | 5:57c345099873 | 147 | |
nxp_ip | 5:57c345099873 | 148 | /* for test of register access order variation */ |
nxp_ip | 5:57c345099873 | 149 | /* |
nxp_ip | 5:57c345099873 | 150 | void setup_transfer( char ch, transaction *t, char n_of_transaction ) { |
nxp_ip | 5:57c345099873 | 151 | int i; |
nxp_ip | 5:57c345099873 | 152 | int j; |
nxp_ip | 5:57c345099873 | 153 | |
nxp_ip | 5:57c345099873 | 154 | write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) |
nxp_ip | 5:57c345099873 | 155 | write_ch_register( ch, TRANCONFIG, n_of_transaction ); // first byte of TRANCONFIG sets to # of transactions |
nxp_ip | 5:57c345099873 | 156 | write_ch_register( ch, TRANSEL, 0 ); // select #0 transaction |
nxp_ip | 5:57c345099873 | 157 | |
nxp_ip | 5:57c345099873 | 158 | for ( i = 0; i < n_of_transaction; i++ ) { |
nxp_ip | 5:57c345099873 | 159 | write_ch_register( ch, SLATABLE, (t + i)->i2c_address ); // |
nxp_ip | 5:57c345099873 | 160 | write_ch_register( ch, TRANCONFIG, (t + i)->length ); |
nxp_ip | 5:57c345099873 | 161 | write_ch_register_burst( ch, DATA, ((t + i)->data), (t + i)->length ); |
nxp_ip | 5:57c345099873 | 162 | } |
nxp_ip | 5:57c345099873 | 163 | } |
nxp_ip | 5:57c345099873 | 164 | */ |
nxp_ip | 5:57c345099873 | 165 | |
nxp_ip | 5:57c345099873 | 166 | /* |
nxp_ip | 5:57c345099873 | 167 | void single_transaction_buffer_fill( char ch, char slot, transaction *tp ) { |
nxp_ip | 5:57c345099873 | 168 | int i; |
nxp_ip | 5:57c345099873 | 169 | |
nxp_ip | 5:57c345099873 | 170 | write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) |
nxp_ip | 5:57c345099873 | 171 | write_ch_register( ch, TRANSEL, slot ); // select #0 transfer |
nxp_ip | 5:57c345099873 | 172 | write_ch_register( ch, TRANCONFIG, 1 ); // first byte of TRANCONFIG sets to # of transactions |
nxp_ip | 5:57c345099873 | 173 | write_ch_register( ch, TRANCONFIG, tp->length ); // length of first transaction |
nxp_ip | 5:57c345099873 | 174 | write_ch_register( ch, SLATABLE, tp->i2c_address ); // |
nxp_ip | 5:57c345099873 | 175 | |
nxp_ip | 5:57c345099873 | 176 | for ( i = 0; i < length; i++ ) |
nxp_ip | 5:57c345099873 | 177 | write_ch_register( ch, DATA, *data++ ); // |
nxp_ip | 5:57c345099873 | 178 | } |
nxp_ip | 5:57c345099873 | 179 | */ |