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
Revision 6:1fc6a640d320, committed 2012-03-26
- Comitter:
- nxp_ip
- Date:
- Mon Mar 26 15:23:45 2012 +0000
- Parent:
- 5:57c345099873
- Child:
- 7:87fd13f1faa6
- Commit message:
- version 1.0 release
Changed in this revision
--- a/config.h Mon Mar 26 06:17:23 2012 +0000 +++ b/config.h Mon Mar 26 15:23:45 2012 +0000 @@ -1,8 +1,8 @@ /** A sample code for "mini board PCU9669/PCA9665" * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 + * @author Akifumi (Tedd) OKANO, NXP Semiconductors + * @version 1.0 + * @date 26-Mar-2011 * * Released under the MIT License: http://mbed.org/license/mit * @@ -24,11 +24,11 @@ * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. * * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. + * Un-comment the target name what you want to target. */ -//#define CODE_FOR_PCU9669 +#define CODE_FOR_PCU9669 //#define CODE_FOR_PCA9663 -#define CODE_FOR_PCA9665 +//#define CODE_FOR_PCA9665
--- a/main_PCA9665.c Mon Mar 26 06:17:23 2012 +0000 +++ b/main_PCA9665.c Mon Mar 26 15:23:45 2012 +0000 @@ -1,8 +1,8 @@ /** A sample code for "mini board PCU9669/PCA9665" * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 + * @author Akifumi (Tedd) OKANO, NXP Semiconductors + * @version 1.0 + * @date 26-Mar-2011 * * Released under the MIT License: http://mbed.org/license/mit * @@ -24,7 +24,7 @@ * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. * * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. + * Un-comment the target name what you want to target. */
--- a/main_PCU9669.c Mon Mar 26 06:17:23 2012 +0000 +++ b/main_PCU9669.c Mon Mar 26 15:23:45 2012 +0000 @@ -1,8 +1,8 @@ /** A sample code for "mini board PCU9669/PCA9665" * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 + * @author Akifumi (Tedd) OKANO, NXP Semiconductors + * @version 1.0 + * @date 26-Mar-2011 * * Released under the MIT License: http://mbed.org/license/mit * @@ -24,7 +24,7 @@ * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. * * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. + * Un-comment the target name what you want to target. */ /** @note Application layer module of PCU9669
--- a/mini_board_libs/I2C_slaves.lib Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/nxp_ip/libraries/I2C_slaves/m6vqar \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mini_board_libs/PCA9665.lib Mon Mar 26 15:23:45 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/nxp_ip/libraries/PCA9665/m7gm2b \ No newline at end of file
--- a/mini_board_libs/PCA9665/.lib Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/nxp_ip/libraries/PCA9665/m6vbya \ No newline at end of file
--- a/mini_board_libs/PCA9665/PCA9665_access.c Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,414 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -#include "PCA9665_access.h" -#include "hardware_abs.h" - -#define BUS_CONTINUE 0 -#define BUS_STOP 1 -#define BUS_RELEASE 2 - -typedef enum { - I2CSTA = 0x0, - INDPTR = 0x0, - I2CDAT, - INDIRECT, - I2CCON -} -pca9665_direct_registers; - -typedef enum { - I2CCOUNT, - I2CADR, - I2CSCLL, - I2CSCLH, - I2CTO, - I2CPRESET, - I2CMODE -} -pca9665_indirect_registers; - -typedef enum { - ILLEGAL_START_STOP = 0x00, - MASTER_START_TXed = 0x08, - MASTER_RESTART_TXed = 0x10, - MASTER_SLA_W_ACK = 0x18, - MASTER_SLA_W_NAK = 0x20, - MASTER_DATA_W_ACK = 0x28, - MASTER_DATA_W_NAK = 0x30, - MASTER_ARB_LOST = 0x38, - MASTER_SLA_R_ACK = 0x40, - MASTER_SLA_R_NAK = 0x48, - MASTER_DATA_R_ACK = 0x50, - MASTER_DATA_R_NAK = 0x58, - SLAVE_ADDRESSED_W = 0x60, - SLAVE_AL_ADDRESSED_W = 0x68, - SDA_STUCK = 0x70, - SCL_STUCK = 0x78, - SLAVE_DATA_RX_ACK = 0x80, - SLAVE_DATA_RX_NAK = 0x88, - SLAVE_STOP_OR_RESTART = 0xA0, - SLAVE_ADDRESSED_R = 0xA8, - SLAVE_AL_ADDRESSED_R = 0xB0, - SLAVE_DATA_TX_ACK = 0xB8, - SLAVE_DATA_TX_NAK = 0xC0, - SLAVE_LAST_DATA_TX_ACK = 0xC8, - SLAVE_GENERALCALL = 0xD0, - SLAVE_GENERALCALL_AL = 0xD8, - SLAVE_GENERALCALL_DATA_RX_ACK = 0xE0, - SLAVE_GENERALCALL_DATA_RX_NAK = 0xE8, - IDLE = 0xF8, - ILLEGAL_I2CCOUNT = 0xFC -} -pca9665_status; - -typedef struct _speed_mode_st { - char i2cmode; - char i2cscll; - char i2csclh; -} -speed_mode_st; - -speed_mode_st speed_mode[ 3 ] = { - { 0x00, 0x9D, 0x86 }, - { 0x01, 0x2C, 0x14 }, - { 0x02, 0x011, 0x09 } -}; - -int buffer_mode_enable = DISABLE; -char int_happened = 0; -char op_mode_flag = OP_MODE_MASTER_ONLY; - -void interrupt_handler_PCA9665( void ) { - int_happened = 1; -} - -void PCA9665_init( void ) { - write_data( I2CCON, 0x40 ); - hw_wait_us( 1000 ); - - install_ISR( &interrupt_handler_PCA9665 ); // interrupt service routine install - - // initialize PCA9955 registers -} - -void set_speed_mode( int mode ) { - indirect_write( I2CMODE, speed_mode[ mode ].i2cmode ); - indirect_write( I2CSCLL, speed_mode[ mode ].i2cscll ); - indirect_write( I2CSCLH, speed_mode[ mode ].i2csclh ); -} - -void set_buffer_mode( int mode ) { - buffer_mode_enable = mode; -} - -int i2c_write( char addr, char *dp, char length, char restart_flag ) { - return ( - buffer_mode_enable ? - i2c_write_buffer_mode( addr, dp, length, restart_flag ) - : - i2c_write_byte_mode( addr, dp, length, restart_flag ) - ); -} - -int i2c_read( char addr, char *dp, char length, char restart_flag ) { - return ( - buffer_mode_enable ? - i2c_read_buffer_mode( addr, dp, length, restart_flag ) - : - i2c_read_byte_mode( addr, dp, length, restart_flag ) - ); -} - - -int i2c_write_buffer_mode( char addr, char *dp, char length, char restart_flag ) { - int done = BUS_CONTINUE; - char state; - char return_value = 0xFF; -#ifdef PCA9665_BURST_DATA_ACCESS -#else - int i; -#endif - - if ( 67 < length ) - return ( 0xFE ); - - write_data( I2CCON, 0x61 ); - - while ( !done ) { - if ( int_happened ) { - int_happened = 0; - - state = read_data( I2CSTA ); - - switch ( state ) { - case MASTER_START_TXed : - case MASTER_RESTART_TXed : - indirect_write( I2CCOUNT, length + 1 ); - write_data( I2CDAT, addr & 0xFE ); - -#ifdef PCA9665_BURST_DATA_ACCESS - write_data_burst( I2CDAT, dp, length ); -#else - for ( i = 0; i < length; i++ ) - write_data( I2CDAT, *dp++ ); -#endif - - write_data( I2CCON, 0x41 ); - break; - case MASTER_SLA_W_ACK : // SLA+W TXed - case MASTER_DATA_W_ACK : // DATA TXed - return_value = 0x00; - done = BUS_STOP; - break; - case MASTER_SLA_W_NAK : - case MASTER_DATA_W_NAK : - return_value = 0x01; - done = BUS_STOP; - break; - case MASTER_ARB_LOST : - case SLAVE_AL_ADDRESSED_R : - case SLAVE_AL_ADDRESSED_W : - case SLAVE_GENERALCALL_AL : - /* bus should be released for other master */ - default : - /* unexpected bus error */ - done = BUS_RELEASE; - break; - } - } - } - - if ( OP_MODE_MASTER_ONLY == op_mode_flag ) - done = BUS_STOP; - - if ( (BUS_STOP == done) && !restart_flag ) - write_data( I2CCON, 0x50 ); - - return ( return_value ); -} - -int i2c_read_buffer_mode( char addr, char *dp, char length, char restart_flag ) { - int done = BUS_CONTINUE; - char state; - char return_value = 0xFF; - -#ifdef PCA9665_BURST_DATA_ACCESS -#else - int i; -#endif - - if ( 68 < length ) - return ( 0xFE ); - - if ( !length ) // zero byte read may cause invalid STOP to START signal output - return ( 0 ); - - write_data( I2CCON, 0x61 ); - - while ( !done ) { - if ( int_happened ) { - int_happened = 0; - - state = read_data( I2CSTA ); - - switch ( state ) { - case MASTER_START_TXed : - case MASTER_RESTART_TXed : - write_data( I2CDAT, addr | 0x01 ); - indirect_write( I2CCOUNT, length | 0x80 ); - write_data( I2CCON, 0x41 ); - break; - case MASTER_SLA_R_ACK : // SLA+R TXed - case MASTER_DATA_R_ACK : // DATA RXed - return_value = 0x00; - done = BUS_STOP; - break; - case MASTER_SLA_R_NAK : // SLA+R TXed - return_value = 0x01; - done = BUS_STOP; - break; - case MASTER_DATA_R_NAK : - return_value = length - (indirect_read( I2CCOUNT ) & 0x7F); - done = BUS_STOP; - - break; - case MASTER_ARB_LOST : - case SLAVE_AL_ADDRESSED_R : - case SLAVE_AL_ADDRESSED_W : - case SLAVE_GENERALCALL_AL : - /* bus should be released for other master */ - default : - /* unexpected bus error */ - done = BUS_RELEASE; - break; - } - } - } - -#ifdef PCA9665_BURST_DATA_ACCESS - read_data_burst( I2CDAT, dp, length ); -#else - for ( i = 0; i < length; i++ ) - *dp++ = read_data( I2CDAT ); -#endif - - if ( OP_MODE_MASTER_ONLY == op_mode_flag ) - done = BUS_STOP; - - if ( (BUS_STOP == done) && !restart_flag ) - write_data( I2CCON, 0x50 ); - - return ( return_value ); -} - -int i2c_write_byte_mode( char addr, char *dp, char length, char restart_flag ) { - int done = BUS_CONTINUE; - char state; - - write_data( I2CCON, 0x60 ); - - while ( !done ) { - if ( int_happened ) { - int_happened = 0; - - state = read_data( I2CSTA ); - - switch ( state ) { - case MASTER_START_TXed : - case MASTER_RESTART_TXed : - write_data( I2CDAT, addr & 0xFE ); - write_data( I2CCON, 0x40 ); - break; - case MASTER_DATA_W_ACK : // DATA TXed - length--; - /* FALLTHROUGH */ - case MASTER_SLA_W_ACK : // SLA+W TXed - if ( !length ) { - done = BUS_STOP; - break; - } - write_data( I2CDAT, *dp++ ); - write_data( I2CCON, 0x40 ); - break; - case MASTER_SLA_W_NAK : - case MASTER_DATA_W_NAK : - done = BUS_STOP; - break; - case MASTER_ARB_LOST : - case SLAVE_AL_ADDRESSED_R : - case SLAVE_AL_ADDRESSED_W : - case SLAVE_GENERALCALL_AL : - /* bus should be released for other master */ - default : - /* unexpected bus error */ - done = BUS_RELEASE; - break; - } - } - } - - if ( OP_MODE_MASTER_ONLY == op_mode_flag ) - done = BUS_STOP; - - if ( (BUS_STOP == done) && !restart_flag ) - write_data( I2CCON, 0x50 ); - - return ( length ); -} - -int i2c_read_byte_mode( char addr, char *dp, char length, char restart_flag ) { - int done = BUS_CONTINUE; - char state; - - if ( !length ) // zero byte read may cause invalid STOP to START signal output - return ( 0 ); - - write_data( I2CCON, 0x60 ); - - while ( !done ) { - if ( int_happened ) { - int_happened = 0; - - state = read_data( I2CSTA ); - - switch ( state ) { - case MASTER_START_TXed : - case MASTER_RESTART_TXed : - write_data( I2CDAT, addr | 0x01 ); - write_data( I2CCON, 0x40 ); - break; - case MASTER_DATA_R_NAK : - done = BUS_STOP; - /* FALLTHROUGH */ - case MASTER_DATA_R_ACK : // DATA RXed - *dp++ = read_data( I2CDAT ); - length--; - /* FALLTHROUGH */ - case MASTER_SLA_R_ACK : // SLA+R TXed - if ( !length ) - done = BUS_STOP; - - if ( !done ) - write_data( I2CCON, (length == 1) ? 0x40 : 0xC0 ); - break; - case MASTER_SLA_R_NAK : - done = BUS_STOP; - break; - case MASTER_ARB_LOST : - case SLAVE_AL_ADDRESSED_R : - case SLAVE_AL_ADDRESSED_W : - case SLAVE_GENERALCALL_AL : - /* bus should be released for other master */ - default : - /* unexpected bus error */ - done = BUS_RELEASE; - break; - } - } - } - - if ( OP_MODE_MASTER_ONLY == op_mode_flag ) - done = BUS_STOP; - - if ( (BUS_STOP == done) && !restart_flag ) - write_data( I2CCON, 0x50 ); - - return ( length ); -} - -void indirect_write( char idaddr, char data ) { - write_data( INDPTR, idaddr ); - write_data( INDIRECT, data ); -} - -char indirect_read( char idaddr ) { - write_data( INDPTR, idaddr ); - return ( read_data( INDIRECT ) ); -}
--- a/mini_board_libs/PCA9665/PCA9665_access.h Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -#ifndef MINIBOARD_PCA9665_ACCESS__ -#define MINIBOARD_PCA9665_ACCESS__ - - -#define OP_MODE_BOTH 0 -#define OP_MODE_MASTER_ONLY 1 -#define OP_MODE_SLAVE_ONLY 2 - -#define RESTART_DISABLE 0 -#define STOP RESTART_DISABLE -#define RESTART_ENABLE 1 -#define NEXT_RESTART RESTART_ENABLE - -#define PCA9665_BURST_DATA_ACCESS - - -typedef enum { - SPEED_STD_MODE = 0, - SPEED_FAST_MODE = 1, - SPEED_FAST_MODE_PLUS = 2 -} -speed_mode_val; - -typedef enum { - DISABLE = 0, - ENABLE = 1 -} -buffer_mode_flag; - -void set_speed_mode( int mode ); -void set_buffer_mode( int mode ); - -int i2c_write( char addr, char *dp, char length, char restart_flag ); -int i2c_read( char addr, char *dp, char length, char restart_flag ); - -int i2c_write_buffer_mode( char addr, char *dp, char length, char restart_flag ); -int i2c_read_buffer_mode( char addr, char *dp, char length, char restart_flag ); - -int i2c_write_byte_mode( char addr, char *dp, char length, char restart_flag ); -int i2c_read_byte_mode( char addr, char *dp, char length, char restart_flag ); - -void PCA9665_init( void ); - -void indirect_write( char idaddr, char data ); -char indirect_read( char idaddr ); - -#endif // MINIBOARD_PCA9665_ACCESS__ -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mini_board_libs/PCU9669.lib Mon Mar 26 15:23:45 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/nxp_ip/libraries/PCU9669/m7hiuh \ No newline at end of file
--- a/mini_board_libs/PCU9669/.lib Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/nxp_ip/libraries/PCU9669/m6xbaz \ No newline at end of file
--- a/mini_board_libs/PCU9669/PCU9669_access.c Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -/* - * "PCU9669_access" module abstracts PCU9669 register and data buffer access. - * This gives simple interface to the bus controller. - * All this interface works on "hardware_abs" module. - */ - -#include "PCU9669_access.h" // PCU9669 chip access interface -#include "hardware_abs.h" // Using hardware abstraction interface - -// -// prototypes (module private function prototypes) -// - -int is_bus_controller_ready( void ); -int check_device_ID( char target_id ); -void registers_initialize( void ); - -// variables - -char device_id_code; // keeps CHIP_ID value -char ch_ofst[] = { OFFSET_CH0, OFFSET_CH1, OFFSET_CH2 }; // Address offsets of channel registers - -// Channel register writing function - -void write_ch_register( char ch, char reg, char val ) { - write_data( ch_ofst[ ch ] + reg, val ); -} - -// Channel register reading function - -char read_ch_register( char ch, char reg ) { - return( read_data( ch_ofst[ ch ] + reg ) ); -} - -// Start routine: It checks the bus controller can be accessed, chip-ID value and initializes registers. - -int start_bus_controller( char target_id ) { - if ( is_bus_controller_ready() ) - return 1; - - if ( check_device_ID( target_id ) ) - return 2; - - registers_initialize(); - - return 0; -} - -// (module private finction, called by start_bus_controller) -// checks if the bus controller can be accessed - -int is_bus_controller_ready( void ) { - return ( read_data( CTRLRDY ) ); -} - -// (module private finction, called by start_bus_controller) -// checks if chip-ID value is same as expected. The "TARGET_BUS_CONTROLLER" value can be modified in "PCU9669_access.h" - -int check_device_ID( char target_id ) { - device_id_code = read_data( DEVICE_ID ); -// printf( "Target chip: PC%c96%02X, ID register value = 0x%02X\r\n", device_id_code & 0x80 ? 'U' : 'A', device_id_code & 0x7F, device_id_code ); - - return ( target_id == device_id_code ) ? 0 : -1; -} - -// (module private finction, called by start_bus_controller) -// register initializations. - -void registers_initialize( void ) { - - // The PCU9669 does not require any specical register initializations. - // It can start data transfer with default register settings. - // - // Or, if you need to have specific settings modify this function like following sample. - -#if 0 - write_ch_register( CH_UFM1, SCLPER, 32 ); - write_ch_register( CH_UFM1, SDADLY, 2 ); - write_ch_register( CH_UFM2, SCLPER, 32 ); - write_ch_register( CH_UFM2, SDADLY, 2 ); -#endif -} - -// Next functions are option. -// if the BURST_DATA_ACCESS is defined in "hardware_abs.h", it is propagated to define "PCU9969_BURST_DATA_ACCESS" -// These interface may be useful for table and buffer access - -#ifdef PCU9969_BURST_DATA_ACCESS - -void write_ch_register_burst( char ch, char reg, char *vp, char length ) { - write_data_burst( ch_ofst[ ch ] + reg, vp, length ); -} - -void read_ch_register_burst( char ch, char reg, char *vp, char length ) { - read_data_burst( ch_ofst[ ch ] + reg, vp, length ); -} - -#endif - - -
--- a/mini_board_libs/PCU9669/PCU9669_access.h Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,192 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -/** PCU9669 abstraction layer module - * - * Common access method is abstracted in this module. - * Each channel's registers, global registers and buffer access can be through these interface. - * This module works on top of hardware abstraction layer. - */ - -#ifndef __PCU9669_ACCESS__ -#define __PCU9669_ACCESS__ - -#include "hardware_abs.h" - -/** @def PCU9669_ID / PCA9663_ID / TARGET_BUS_CONTROLLER - * - * Device IDs which can be read from DEVICE_ID register. - * This value may need to be checked before the operation start. - */ -#define PCU9669_ID 0xE9 -#define PCA9663_ID 0x63 -//#define TARGET_BUS_CONTROLLER PCA9663_ID - -/** @def CH_FM_PLUS / CH_UFM1 / CH_UFM2 - * - * Channel number abstracted by its characters. - */ -#define CH_FM_PLUS 0 -#define CH_UFM1 1 -#define CH_UFM2 2 - -#define CH_0 0 -#define CH_1 1 -#define CH_2 2 - -/** @var Register names - * - * PCU9669/9663 internal register name and addesses - */ -typedef enum { - - // channel registers - - CONTROL = 0x00, // These are register offsets. offset base CH0=0xC0, CH1=0xD0, CH2=0xE0 - CHSTATUS, - INTMSK, - SLATABLE, - TRANCONFIG, - DATA, - TRANSEL, - TRANOFS, - BYTECOUNT, - FRAMECNT, - REFRATE, - SCLL, - SCLH, - MODE, - TIMEOUT, - PRESET, - - SCLPER = 0x0B, - SDADLY = 0x0C, - RESERVED = 0x0E, - - // global registers - - CTRLSTATUS = 0xF0, - CTRLINTMSK, - DEVICE_ID = 0xF6, - CTRLPRESET, - CTRLRDY = 0xFF, - - OFFSET_CH0 = 0xC0, - OFFSET_CH1 = 0xD0, - OFFSET_CH2 = 0xE0, - -} RegisterName; - - -/** @var Devide ID code - * - * Keeps the value which is read from DEVICE_ID register - */ -extern char device_id_code; - - -/** Write channel register - * - * Writing 8 bit data into register in specified channel. - * Register address offset of each channels is added in this function. - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param reg target channel register: RegisterName - * @param val target of channel: 8 bit value - * @see read_ch_register() - */ -void write_ch_register( char ch, char reg, char val ); - -/** Read channel register - * - * Read 8 bit data from register in specified channel. - * Register address offset of each channels is added in this function. - * - * @return 8 bit value from the register - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param reg target channel register: RegisterName - * @see write_ch_register() - */ -char read_ch_register( char ch, char reg ); - -/** Starting the bus controller (i.e. PCU9669) - * - * Checks the bus controller get ready, and ChipID is correct - * Then neccesary register initializations are done. - * In this reference code, no register initialization done. - * But if user need to do some, edit a module-private function "registers_initialize()" in "PCU9669_access.cpp" - * - * @return ZERO for no error, 1 for PCU9669 couldn't get ready after reset, 2 for ChipID was not match. - */ -int start_bus_controller( char target_id ); - - -/** BURST_DATA_ACCESS option code - * - * Following code is enabled only when BURST_DATA_ACCESS is defined in "hardware_abs.h" - */ -#ifdef BURST_DATA_ACCESS - -/** @def PCU9669_BURST_DATA_ACCESS - * - * PCU9669_BURST_DATA_ACCESS is defied to let upper layer know the burst access is available. - * This happens onlny BURST_DATA_ACCESS is defined in "hardware_abs.h" - */ -#define PCU9669_BURST_DATA_ACCESS - -/** Write channel register - * - * Write multiple bytes into a register in specified channel. - * Register address offset of each channels is added in this function. - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param reg target channel register: RegisterName - * @param *vp a pointer to char array. The data in the array will be written. - * @param length length of the data (bytes) - * @see read_ch_register_burst() - */ -void write_ch_register_burst( char ch, char reg, char *vp, char length ); - -/** Read channel register - * - * Read multiple bytes from a register in specified channel. - * Register address offset of each channels is added in this function. - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param reg target channel register: RegisterName - * @param *vp a pointer to char array. The data will be read into this. - * @param length length of the data (bytes) - * @see write_ch_register_burst() - */ -void read_ch_register_burst( char ch, char reg, char *vp, char length ); - -#endif // BURST_DATA_ACCESS - -#endif // __PCU9669_ACCESS__ -
--- a/mini_board_libs/PCU9669/transfer_manager.c Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -/* - * "transfer_manager" is a module to manage I2C bus transfers. - * In this sample code, single slave access (from START or RESTART condition to STOP or next RESTART - * condition) is called transaction. - * - * In this software, the transaction is a struct (the struct is defined in "transfer_manager.h") - * - * typedef struct transaction_st { - * char i2c_address __attribute__((packed)); - * char *data __attribute__((packed)); - * char length __attribute__((packed)); - * } - * transaction; - * - * The transaction has target I2C slave address pointer to the data array and the data length. - * Read/write drection is maneged by LSB of the i2c_address. - * - * For the reading, in this version, a dummy data array can be used but it need to have actual data - * because it will be accessed for buffer filling. - * And transfer manager doesn't readback the buffer. So user need to readback by "buffer_read()" - * function after transaction executed. - * - * A transfer can be represented by array of transaction, i.e... - * - * transaction a_sample_of_transfer[]; - * - * This array_of_transaction: "transfer" is used for the setting of the registers and buffers. - * - * See "main.cpp" for the actual sample of those transfer/transaction usage - */ - -#include "transfer_manager.h" -#include "PCU9669_access.h" // PCU9669 chip access interface - -void setup_transfer( char ch, transaction *t, char n_of_transaction ) { - int i; -#ifdef PCU9969_BURST_DATA_ACCESS -#else - int j; -#endif - - write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) - - for ( i = 0; i < n_of_transaction; i++ ) - write_ch_register( ch, SLATABLE, (t + i)->i2c_address ); // - - write_ch_register( ch, TRANCONFIG, n_of_transaction ); // first byte of TRANCONFIG sets to # of transactions - write_ch_register( ch, TRANSEL, 0 ); // select #0 transaction - - for ( i = 0; i < n_of_transaction; i++ ) - write_ch_register( ch, TRANCONFIG, (t + i)->length ); - - -#ifdef PCU9969_BURST_DATA_ACCESS - for ( i = 0; i < n_of_transaction; i++ ) - write_ch_register_burst( ch, DATA, ((t + i)->data), (t + i)->length ); - -#else - for ( i = 0; i < n_of_transaction; i++ ) - for ( j = 0; j < (t + i)->length; j++ ) - write_ch_register( ch, DATA, *(((t + i)->data) + j) ); -#endif -} - - -void set_n_of_transaction( char ch, char n_of_transaction ) -{ - write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) - write_ch_register( ch, TRANCONFIG, n_of_transaction ); // first byte of TRANCONFIG sets to # of transactions -} - - -void buffer_overwrite( char ch, char transaction_number, char offset, char *data, char length ) { -#ifdef PCU9969_BURST_DATA_ACCESS -#else - int i; -#endif - - write_ch_register( ch, TRANSEL, transaction_number ); - write_ch_register( ch, TRANOFS, offset ); - -#ifdef PCU9969_BURST_DATA_ACCESS - write_ch_register_burst( ch, DATA, data, length ); -#else - for ( i = 0; i < length; i++ ) - write_ch_register( ch, DATA, *data++ ); -#endif -} - -void buffer_read( char ch, char transaction_number, char offset, char *data, char length ) { -#ifdef PCU9969_BURST_DATA_ACCESS -#else - int i; -#endif - - write_ch_register( ch, TRANSEL, transaction_number ); - write_ch_register( ch, TRANOFS, offset ); - -#ifdef PCU9969_BURST_DATA_ACCESS - read_ch_register_burst( ch, DATA, data, length ); -#else - for ( i = 0; i < length; i++ ) - *data++ = read_ch_register( ch, DATA ); -#endif -} - -void start( char ch ) { - write_ch_register( ch, CONTROL, 0x40 ); -} - -void start_by_trigger( char ch, char polarity ) { - write_ch_register( ch, CONTROL, 0x48 | (polarity ? 0x10 : 0x00 ) ); -} - -void stop( char ch ) { - write_ch_register( ch, CONTROL, 0x20 ); // set STO bit -} - -/* for test of register access order variation */ -/* -void setup_transfer( char ch, transaction *t, char n_of_transaction ) { - int i; - int j; - - write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) - write_ch_register( ch, TRANCONFIG, n_of_transaction ); // first byte of TRANCONFIG sets to # of transactions - write_ch_register( ch, TRANSEL, 0 ); // select #0 transaction - - for ( i = 0; i < n_of_transaction; i++ ) { - write_ch_register( ch, SLATABLE, (t + i)->i2c_address ); // - write_ch_register( ch, TRANCONFIG, (t + i)->length ); - write_ch_register_burst( ch, DATA, ((t + i)->data), (t + i)->length ); - } -} -*/ - -/* -void single_transaction_buffer_fill( char ch, char slot, transaction *tp ) { - int i; - - write_ch_register( ch, CONTROL, 0x02 ); // AIPTRRST : AutoIncrementPointerReset (for SLATABLE TRANCONFIG and DATA) - write_ch_register( ch, TRANSEL, slot ); // select #0 transfer - write_ch_register( ch, TRANCONFIG, 1 ); // first byte of TRANCONFIG sets to # of transactions - write_ch_register( ch, TRANCONFIG, tp->length ); // length of first transaction - write_ch_register( ch, SLATABLE, tp->i2c_address ); // - - for ( i = 0; i < length; i++ ) - write_ch_register( ch, DATA, *data++ ); // -} -*/
--- a/mini_board_libs/PCU9669/transfer_manager.h Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -/** Data transfer is abstracted on this layer - * - * The transer can be managed by a struct and some functions - */ -#ifndef __TRANSFER_MANAGER__ -#define __TRANSFER_MANAGER__ - -#define TRIGGER_BY_RISING_EDGE 0 -#define TRIGGER_BY_FALLING_EDGE 1 - -/** @typedef transaction - * - * A transaction (single data read/write access to the slave) is managed by this structure - * An array of the transaction makes a transfer. - * The sample of the transfer management can be found in "main.cpp". - */ -typedef struct transaction_st { - char i2c_address __attribute__((packed)); - char *data __attribute__((packed)); - char length __attribute__((packed)); -} -transaction; - -/** Setup transfer - * - * A transfer (consists multiple transactions) will be set into the buffer. - * This function only sets the data. - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param *t a pointer to transaction array. This array represents a transfer. - * @param n_of_transaction number of transactions (how many transactions in this transfer) - * @see setup_transfer() - * @see buffer_overwrite() - * @see buffer_read() - * @see start() - */ -void setup_transfer( char ch, transaction *t, char n_of_transaction ); - -/** Set N of transaction - * - * To modify the N_OF_TRANSACTION - * This can be used to ignore transactions after specified transaction - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param n_of_transaction number of transactions (how many transactions in this transfer) - * @see setup_transfer() - * @see buffer_overwrite() - * @see buffer_read() - * @see start() - */ -void set_n_of_transaction( char ch, char n_of_transaction ); - -/** Buffer overwrite (in a transaction) - * - * Buffer contents in a transaction can be overwritten. - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param transaction_number points the target transaction by number. - * @param offset offset of overwriting start byte - * @param *data pointer to char array, this contents will be written - * @param length number of bytes to overwrite - * @see setup_transfer() - * @see buffer_overwrite() - * @see buffer_read() - * @see start() - */ -void buffer_overwrite( char ch, char transaction_number, char offset, char *data, char length ); - -/** Buffer read (in a transaction) - * - * Buffer read interface. - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @param transaction_number points the target transaction by number. - * @param offset offset of reading start byte - * @param *data pointer to char array, the data will be written here - * @param length number of bytes to read - * @see setup_transfer() - * @see buffer_overwrite() - * @see buffer_read() - * @see start() - */ -void buffer_read( char ch, char transaction_number, char offset, char *data, char length ); - -/** Start transfer - * - * Starts the transfer of specified channel - * - * @param ch target of channel: CH_FM_PLUS | CH_UFM1 | CH_UFM2 - * @see setup_transfer() - * @see buffer_overwrite() - * @see buffer_read() - * @see start() - */ -void start( char ch ); -void start_by_trigger( char ch, char polarity ); -void stop( char ch ); - -// void single_transaction_buffer_fill( char ch, char *data, char length ); - - -#endif // __TRANSFER_MANAGER__ -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mini_board_libs/parallel_bus.lib Mon Mar 26 15:23:45 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/nxp_ip/libraries/parallel_bus/m7i4uc \ No newline at end of file
--- a/mini_board_libs/parallel_bus/.lib Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/nxp_ip/libraries/parallel_bus/m6x9xb \ No newline at end of file
--- a/mini_board_libs/parallel_bus/hardware_abs.c Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -/* - * "hardware_abs" module has been made to abstract hardware: Hardware abstract layer - * This is file which will be modified when the porting done for other MCUs. - */ - -/* - * This sample code has been made for mbed. The code emulates parallel SRAM bus using the mbed's GPIO ports. - * To maximize the port access speed, PortOut and PortInOut libraly used. - */ - -#include "mbed.h" -#include "hardware_abs.h" - -// GPIO port setting - -#define ADDR_MASK 0x07878000 // 8 bit address mask on PORT0: Address value will be set into this bit position -#define DATA_MASK 0x00000FF0 // 8 bit data mask on PORT0: Data value will be appeared on this bit position -#define CONTROL_MASK 0x00000038 // Control signals CS=bit5(pin21), WR=bit4(pin22), RD=bit3(pin23) - -PortOut addr_port( Port0, ADDR_MASK ); -PortInOut data_port( Port0, DATA_MASK ); -PortOut ctrl_port( Port2, CONTROL_MASK ); -InterruptIn int_port( p26 ); - -// The very early version of PCU9669 mini board has different configuration. -// Following part switches the port configuration for those board versions. - -//#define PROTOTYPE_BREADBOARD - -DigitalInOut reset_port( p20 ); -//DigitalOut trig_port( p19 ); - -// Next two macros defines interface for temporaly interrupt disable/enable functions. -// These macros are used to blocking interrupt until a bus access cycle completed. -// Because if the interrupt happened in a cycle, the emulated parallel port state will be disturbed. -// For the mbed, library routine: __disable_irq() / __enable_irq() can be used. - -#define interrupt_enable() __enable_irq() -#define interrupt_disable() __disable_irq() - -// "prev_access_was_write" is a variable to keep the previous data directions. -// Using this flag, successive write and read addess overhead can be reduced. -// This mechanism will not be required if the MCU has parallel port - -char prev_access_was_write; - -// ISR routine installer - -void install_ISR( void (*fptr)(void) ) { - int_port.fall( fptr ); -} - -// Hardware initialize: it defines initial state of the (emulated) parallel bus - -void hardware_initialize( void ) { - prev_access_was_write = 0; - ctrl_port = 0x38; // CS, WR and RD are deaserted (HIGH) - data_port.input(); // data bus set to Hi-Z - reset_port.output(); - reset_port.mode( PullUp ); -} - -// Hardware reset for PCU9669: It asserts RESET signal for 4us and waits 650us after deassert (reset recovery time) - -void reset( int reset_pulse_width_us, int reset_recovery_us ) { - hardware_reset( ASSERT ); // Minimum pulse width is 4us for PCU9669 - hw_wait_us( reset_pulse_width_us ); - hardware_reset( DEASSERT ); // deassert hardware /RESET sgnal - hw_wait_us( reset_recovery_us ); -} - -// Interface to Control hardware RESET signal - -void hardware_reset( char signal ) { - reset_port = signal; -} - -// Interface to Control hardware TRIGGER signal - -void hardware_trigger( char signal ) { -// trig_port = signal; -} - -// Single write cycle on (emulated) parallel bus - -void write_data( char addr, char data ) { - interrupt_disable(); // disable interrupt first - - addr_port = (addr << 19) | (addr << 15); // Address output - ctrl_port = 0x08; // Assert CS and WR signals - - if ( !prev_access_was_write ) // Data bus direction control - data_port.output(); - - prev_access_was_write = 1; - - data_port = data << 4; // Data output - ctrl_port = 0x38; // Deassert CS and WR - - interrupt_enable(); // enable interrupt again -} - - -char read_data( char addr ) { - volatile char tmp; - interrupt_disable(); // disable interrupt first - - if ( prev_access_was_write ) // Data bus direction control - data_port.input(); - - prev_access_was_write = 0; - - addr_port = (addr << 19) | (addr << 15); // Address output - ctrl_port = 0x10; // Assert CS and RD signals - ctrl_port = 0x10; // asserting CS and RD pulse twice (but those are kept LOW) to wait short time till actual read timing - tmp = (data_port >> 4) & 0xFF; // Read data bus into var - ctrl_port = 0x38; // Deassert CS and RD - - interrupt_enable(); // enable interrupt again - - return ( tmp ); -} - -// Wait for micro-seconds - -void hw_wait_us( int v ) { - wait_us( v ); -} - -// Wait for seconds - -void wait_sec( float f ) { - wait( f ); -} - -// Following part is an optionto accerelate bus access. -// If such trick is not required, undefine the "BURST_DATA_ACCESS" and don't touch it. -// -// Next two functions access single address with repeating read/write. -// The repeating read/write are used often for PCU9669 like SLATABLE, TRANCONFIG and DATA (buffer accesses). -// So this accerelation contributes saving MCU time. -// -// For the porting, it may be good idea to modify those routines to DMA access. - -#ifdef BURST_DATA_ACCESS - -void write_data_burst( char addr, char *data, char length ) { - int i; - - interrupt_disable(); // disable interrupt first - - addr_port = (addr << 19) | (addr << 15); // Address output - - if ( !prev_access_was_write ) // Data bus direction control - data_port.output(); - - prev_access_was_write = 1; - - for ( i = 0; i < length; i++ ) { // repeat data write access - ctrl_port = 0x08; - data_port = *(data + i) << 4; - ctrl_port = 0x38; - } - - interrupt_enable(); -} - -void read_data_burst( char addr, char *data, char length ) { - int i; - - interrupt_disable(); // disable interrupt first - - addr_port = (addr << 19) | (addr << 15); // Address output - - if ( prev_access_was_write ) // Data bus direction control - data_port.input(); - - prev_access_was_write = 0; - - for ( i = 0; i < length; i++ ) { // repeat data read access - ctrl_port = 0x10; - ctrl_port = 0x10; - - *(data + i) = (data_port >> 4) & 0xFF; - ctrl_port = 0x38; - } - interrupt_enable(); -} - -#endif -
--- a/mini_board_libs/parallel_bus/hardware_abs.h Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +0,0 @@ -/** A sample code for "mini board PCU9669/PCA9665" - * - * @author Tedd OKANO, NXP Semiconductors - * @version 0.9 - * @date 14-Feb-2011 - * - * Released under the MIT License: http://mbed.org/license/mit - * - * An operation sample of PCU9669/PCA9665 I2C bus controller. - * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. - * The bit-banging is poerformed by PortInOut function of mbed library. - * - * To make the code porting easier, all codes are partitioned into layers to abstract other parts. - * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". - * This module may need to be modified for the porting. - * - * All other upper layers are writen in standard-C. - * - * base code is written from 05-Sep-2011 to 09-Sep-2011. - * And demo code has been build on 11-Sep-2011. - * Debug and code adjustment has been done on 08-Sep-2011. - * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 - * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 - * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. - * - * Before builidng the code, please edit the file mini_board_PCU9669/config.h - * Uncomment the target name what you want to target. - */ - -/** Hardware abstraction layer module - * - * All MCU hardware related code are defined in this module - * This module may need to be modified when the code is ported to other MCU. - */ - -#ifndef MINIBOARD_HARDWARE_ABS__ -#define MINIBOARD_HARDWARE_ABS__ - -/** @def BURST_DATA_ACCESS - * - * To accelerate multiple bus access on same addess, use BURST_DATA_ACCESS - * On the mbed emvironment, this burst access enables 3 times faster read/write compare to single access. - * For code porting, the BURST_DATA_ACCESS code part is not neccesary if the hardware is fast enough. - */ -#define BURST_DATA_ACCESS - - -/** @def ASSERT / DEASSERT - * - * Reset signal logic difinition - */ -#define ASSERT 0 // for hardware reset -#define DEASSERT 1 // for hardware reset - - -/** Install an ISR - * - * Registering function as ISR. - * The function will be called when the interrupt asserted. - * - * @param fptr a pointer to a function - */ -void install_ISR( void (*fptr)(void) ); - -/** Hardware initialization - * - * MCU side initialization should be done in this function. - * For the mbed, it set the initial state of parallel bus control signal. - */ -void hardware_initialize( void ); - -/** Reset signal control - * - * This function drives the RESET signal line with given state. - * - * @param signal the state of RESET signal: ASSERT | DEASSERT - */ -void hardware_reset( char signal ); - -/** Hardware reset - * - * Asserts the RESET signal with required pulse width and waits its recovery time - * - * @param reset_pulse_width_us RESET pulse width in micro-seconds - * @param reset_recovery_us RESET recovery time in micro-seconds (wait time after RESET de-assertion) - */ -void reset( int reset_pulse_width_us, int reset_recovery_us ); - -/** Triger signal control - * - * This function drives the TRIGGER signal line with given state. - * - * @param signal the state of TRIGGER signal: ASSERT | DEASSERT - */ -void hardware_trigger( char signal ); - -/** Write data - * - * Writes 1 byte - * - * @param addr 8 bit address where the data should be written to - * @param data 8 bit data which will be written - * @see read_data() - */ -void write_data( char addr, char data ); - -/** Read data - * - * Reads 1 byte - * - * @return 8 bit data which is read from bus - * @param addr 8 bit address where the data should be read from - * @see write_data() - */ -char read_data( char addr ); - -/** Wait micro-seconds - * - * Wait function waits given-micro-seconds - * - * @param micro-seconds the program should wait (32 bit integer value) - * @see wait_sec() - */ -void hw_wait_us( int v ); - -/** Wait seconds - * - * Wait function waits given-seconds - * - * @param seconds the program should wait (float value) - * @see hw_wait_us() - */ -void wait_sec( float ); - - -/** BURST_DATA_ACCESS option code - * - * This code is option to accelerate the bus access - */ -#ifdef BURST_DATA_ACCESS - -/** Write data - * - * Writes multiple bytes to same address. - * This function suitable to use for the registers like SLATABLE, TRANCONFIG and data buffers (through DATA register). - * While this access is going, the interrupt will be tempolary disabled (ISR execution will be postponed) - * - * @param addr 8 bit address where the data should be written to - * @param *data pointer to char array. The data in this array will be written - * @param length length of the data (bytes) - * @see read_data_burst() - */ -void write_data_burst( char addr, char *data, char length ); - -/** Read data - * - * Reads multiple bytes from same address. - * This function suitable to use for the registers like SLATABLE, TRANCONFIG and data buffers (through DATA register). - * While this access is going, the interrupt will be tempolary disabled (ISR execution will be postponed) - * - * @param addr 8 bit address where the data should be written to - * @param *data pointer to char array. The read data will be written to this - * @param length length of the data (bytes) - * @see write_data_burst() - */ -void read_data_burst( char addr, char *data, char length ); -#endif - -#endif // MINIBOARD_HARDWARE_ABS__ -
--- a/mini_board_libs/utility.lib Mon Mar 26 06:17:23 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/nxp_ip/libraries/utility/m6x939 \ No newline at end of file