unsigned long PCA9685_writeDATA(unsigned char ucReg, char* cSendData, unsigned int uiSize){ unsigned long result; result = I2CWriteData(I2C_BASE,PCA9685_ADDRESS,ucReg,cSendData,uiSize); return result; }
/*DC*********************************************************************** ** Detailed Conception for the function EEP_TK_PeriodicManagement ** ************************************************************************** Syntax : EXPORTED void EEP_TK_PeriodicManagement (void) Object : Manages EEPROM state machine. See software design for details. Parameters: None Return : None Calls : TBC **********************************************************************EDC*/ EXPORTED void EEP_TK_PeriodicManagement(void) { ke_i2c_op_status eI2COpStatus = I2C_KE_OP_UNDEFINED; ushort usStartingPage = US_NULL; ushort usEndingPage = US_NULL; ushort usEndingAddress = US_NULL; ushort usCurrentAddress = US_NULL; ushort usRemainingBytes = US_NULL; ushort usTemp = US_NULL; switch(eEepromState) { case KE_EEPROM_STATE_IDLE: { /* check for pending READ request */ if (stEepromRequestInfo.eEepOperation == KE_EEP_OP_REQUIRED_READ) { /* set EEPROM FSM state to READ */ eEepromState = KE_EEPROM_STATE_READ; /* set EEPROM status to READ */ EEP_eEepromState = EEP_KE_EEPROM_STATE_READ; } else { /* check for pending WRITE request */ if (stEepromRequestInfo.eEepOperation == KE_EEP_OP_REQUIRED_WRITE) { /* set EEPROM FSM state to WRITE */ eEepromState = KE_EEPROM_STATE_WRITE; /* set EEPROM status to WRITE */ EEP_eEepromState = EEP_KE_EEPROM_STATE_WRITE; } else { /* no pending request; nothing to do */ } } break; } case KE_EEPROM_STATE_READ: { /* check if an I2C operation is not in progress */ if(aeI2COperationStatus != I2C_KE_OP_IN_PROGRESS) { /* send read request to low level */ I2CReadData(stEepromRequestInfo.usAddress, stEepromRequestInfo.usByteNum); /* set EEPROM FSM state to WAIT_READ */ eEepromState = KE_EEPROM_STATE_WAIT_READ; } else { /* wait */ } break; } case KE_EEPROM_STATE_WRITE: { /* check if an I2C operation is not in progress */ if(aeI2COperationStatus != I2C_KE_OP_IN_PROGRESS) { /* update starting address considering bytes already written */ usCurrentAddress = stEepromRequestInfo.usAddress + stEepromRequestInfo.usWrittenBytes; /* update remaining bytes counter */ usRemainingBytes = stEepromRequestInfo.usByteNum - stEepromRequestInfo.usWrittenBytes; /* check if bytes to be written cross EEPROM page boundaries */ usEndingAddress = usCurrentAddress + usRemainingBytes - US_1; usStartingPage = usCurrentAddress / US_EEPROM_PHYS_PAGE_SIZE; usEndingPage = usEndingAddress / US_EEPROM_PHYS_PAGE_SIZE; if (usStartingPage == usEndingPage) { /* no page boundaries crossing detected */ /* send whole EEPROM write request */ I2CWriteData(usCurrentAddress, usRemainingBytes); /* update number of written bytes */ stEepromRequestInfo.usWrittenBytes += usRemainingBytes; } else { /* page boundaries crossing detected */ /* calculate number of bytes up to page bound */ usTemp = ((usStartingPage + US_1) * US_EEPROM_PHYS_PAGE_SIZE) - usCurrentAddress; /* send partial EEPROM write request */ I2CWriteData(usCurrentAddress, usTemp); /* update number of written bytes */ stEepromRequestInfo.usWrittenBytes += usTemp; } /* set EEPROM FSM state to WAIT_WRITE */ eEepromState = KE_EEPROM_STATE_WAIT_WRITE; } else { /* wait */ } break; } case KE_EEPROM_STATE_WAIT_READ: { /* check I2C bus status */ if(aeI2COperationStatus == I2C_KE_OP_IN_PROGRESS) { /* wait */ } else if (aeI2COperationStatus == I2C_KE_OP_FINISHED_SUCCESS) { /* set EEPROM FSM state to IDLE */ eEepromState = KE_EEPROM_STATE_IDLE; /* set EEPROM status to IDLE */ EEP_eEepromState = EEP_KE_EEPROM_STATE_IDLE; /* manage data here if necessary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* DO NOT INVERT FOLLOWING TWO INSTRUCTIONS */ /* notify operation end here if necessary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* reset required operation */ stEepromRequestInfo.eEepOperation = KE_EEP_OP_REQUIRED_NONE; } else if(eI2COpStatus == I2C_KE_OP_ERROR_TIMEOUT) { } else if(eI2COpStatus == I2C_KE_OP_ERROR_MISSING_ACK) { } else if(eI2COpStatus == I2C_KE_OP_ERROR_GENERIC) { } else { /* do nothing */ } break; } case KE_EEPROM_STATE_WAIT_WRITE: { /* set physical EEPROM status to NOT UPDATED */ ePhysEepromStatus = KE_PHYS_EEPROM_STATUS_NOT_UPDATED; /* set EEPROM FSM state to WAIT STATUS */ eEepromState = KE_EEPROM_STATE_WAIT_STATUS; break; } case KE_EEPROM_STATE_WAIT_STATUS: { /* updat physical EEPROM status and check for FREE */ ePhysEepromStatus = KE_PHYS_EEPROM_STATUS_FREE; if (ePhysEepromStatus == KE_PHYS_EEPROM_STATUS_FREE) { /* check for other bytes to write */ if (stEepromRequestInfo.usWrittenBytes < stEepromRequestInfo.usByteNum) { /* set EEPROM FSM state to WRITE */ eEepromState = KE_EEPROM_STATE_WRITE; } else { /* no further bytes to write; return to IDLE state */ eEepromState = KE_EEPROM_STATE_IDLE; /* set EEPROM status to IDLE */ EEP_eEepromState = EEP_KE_EEPROM_STATE_IDLE; /* DO NOT INVERT FOLLOWING TWO INSTRUCTIONS */ /* notify operation end here if necessary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* reset required operation */ stEepromRequestInfo.eEepOperation = KE_EEP_OP_REQUIRED_NONE; } } else { /* nothing to do, wait for status update */ } break; } default: { /* should never arrive here */ break; } } }