Update repo
This commit is contained in:
1 parent
749dab5721
commit
ce65a0f59a
14950 files changed
+4408250
-1
No files matched your search
@@ -0,0 +1,590 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_over_i2c_stack_config.c
|
||||
//
|
||||
// TITLE: PMBUS over I2C Communications Stack Configuration
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
|
||||
#ifdef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "pmbus_over_i2c_stack_config.h"
|
||||
#ifdef TIMEOUT
|
||||
#include "device.h"
|
||||
#endif
|
||||
#ifdef PEC_ENABLED
|
||||
#include "vcu2_crc.h"
|
||||
#endif
|
||||
|
||||
// Function prototypes
|
||||
void PMBus_over_I2C_initTarget(uint32_t base, uint16_t address, uint16_t mask);
|
||||
void PMBus_over_I2C_initControllerMode(uint32_t base, uint16_t address);
|
||||
uint16_t PMBus_over_I2C_getData(uint32_t base, uint16_t *buffer);
|
||||
void PMBus_over_I2C_putData(uint32_t base, uint16_t *buffer, uint16_t nBytes);
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(1)
|
||||
|
||||
#define PMBUS_STACK_TARGET_ADDRESS 0U
|
||||
#define PMBUS_STACK_CONTROLLER_ADDRESS 0x40U
|
||||
#define PMBUS_STACK_TARGET_MASK 0x7FU
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
PMBus_StackObject PMBusStackTarget;
|
||||
PMBus_StackHandle PMBusStackTargetHandle = &PMBusStackTarget;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_initModule
|
||||
// This function is used to initialize the PMBUS stack
|
||||
// Based on the mode of operation (TARGET/CONTROLLER), the PMBus object is
|
||||
// configured
|
||||
//
|
||||
//*****************************************************************************
|
||||
bool PMBusStack_initModule(PMBus_StackHandle handle, const uint32_t moduleBase,
|
||||
uint16_t *buffer, uint16_t *CRCBuffer)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
bool status = false;
|
||||
|
||||
//
|
||||
// Set the module base address
|
||||
//
|
||||
PMBusStackObject_setModuleBase(handle, moduleBase);
|
||||
|
||||
//
|
||||
// Assign the buffer pointer to the object, set the current pointer to
|
||||
// the head of the buffer
|
||||
//
|
||||
PMBusStackObject_setBufferPointer(handle, buffer);
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, buffer);
|
||||
PMBusStackObject_setCRCBufferPointer(handle,CRCBuffer );
|
||||
|
||||
// Reset the I2C Module
|
||||
//
|
||||
I2C_disableModule(PMBusStackObject_getModuleBase(handle));
|
||||
|
||||
//
|
||||
// Initialize depending upon whether in target or controller mode
|
||||
//
|
||||
if(PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_TARGET)
|
||||
{
|
||||
//
|
||||
// Initialize the target module
|
||||
//
|
||||
// Setup a CPU timer
|
||||
#ifdef TIMEOUT
|
||||
initCPUTimers(PMBusStackObject_getTimerBase(handle));
|
||||
|
||||
configCPUTimer(PMBusStackObject_getTimerBase(handle), DEVICE_SYSCLK_FREQ, PMBusStackObject_getTimeout(handle));
|
||||
#endif
|
||||
|
||||
//
|
||||
// Initialize the target module
|
||||
//
|
||||
PMBus_over_I2C_initTarget(PMBusStackObject_getModuleBase(handle),
|
||||
PMBusStackObject_getTargetAddress(handle),
|
||||
PMBusStackObject_getTargetAddressMask(handle));
|
||||
|
||||
|
||||
|
||||
//Enable FIFO Interrupt
|
||||
I2C_setFIFOInterruptLevel(PMBusStackObject_getModuleBase(handle),I2C_FIFO_TX16,I2C_FIFO_RX5);
|
||||
|
||||
|
||||
//
|
||||
// Enable interrupts
|
||||
//
|
||||
I2C_enableInterrupt(PMBusStackObject_getModuleBase(handle),
|
||||
(I2C_INT_STOP_CONDITION | I2C_INT_TX_DATA_RDY | I2C_INT_RXFF ));
|
||||
|
||||
//
|
||||
// Reset the state machine
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
status = true;
|
||||
}
|
||||
else // (PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_CONTROLLER)
|
||||
{
|
||||
|
||||
// Initialize the controller module
|
||||
//
|
||||
PMBus_over_I2C_initControllerMode(PMBusStackObject_getModuleBase(handle), PMBusStackObject_getTargetAddress(handle) );
|
||||
|
||||
//
|
||||
// Enable interrupts
|
||||
//
|
||||
I2C_enableInterrupt(PMBusStackObject_getModuleBase(handle),
|
||||
(I2C_INT_STOP_CONDITION ));
|
||||
|
||||
//
|
||||
// Reset the state machine
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
status = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Take the I2C module out of reset
|
||||
//
|
||||
I2C_enableModule(PMBusStackObject_getModuleBase(handle));
|
||||
|
||||
return(status);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_defaultTransactionHandler
|
||||
// This function is the default transaction handler
|
||||
//
|
||||
//*****************************************************************************
|
||||
int32_t PMBusStack_defaultTransactionHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Replace with an actual handler. This will stop emulation
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBus_over_I2C_initTarget
|
||||
// This function is used to initialize the TARGET mode
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBus_over_I2C_initTarget(uint32_t base, uint16_t address, uint16_t mask)
|
||||
{
|
||||
//
|
||||
// Check the arguments.
|
||||
//
|
||||
ASSERT(I2C_isBaseValid(base));
|
||||
ASSERT(address <= 0x7FU);
|
||||
ASSERT(mask <= 0x7FU);
|
||||
|
||||
EALLOW;
|
||||
|
||||
//
|
||||
// Configure the target in Receive mode
|
||||
//
|
||||
I2C_setConfig(base, I2C_TARGET_RECEIVE_MODE);
|
||||
|
||||
I2C_setBitCount(base, I2C_BITCOUNT_8);
|
||||
|
||||
//
|
||||
// Write the address to own address
|
||||
I2C_setOwnAddress(base, address);
|
||||
|
||||
I2C_setEmulationMode(base, I2C_EMULATION_FREE_RUN);
|
||||
|
||||
//
|
||||
// FIFO and interrupt configuration
|
||||
//
|
||||
I2C_enableFIFO(base);
|
||||
I2C_clearInterruptStatus(base, I2C_INT_TXFF);
|
||||
I2C_clearInterruptStatus(base, I2C_INT_RXFF);
|
||||
I2C_clearStatus(base,I2C_STS_NO_ACK|I2C_STS_ARB_LOST|I2C_STS_REG_ACCESS_RDY|I2C_STS_STOP_CONDITION);
|
||||
|
||||
I2C_disableInterrupt(base, (I2C_INT_ARB_LOST | I2C_INT_NO_ACK));
|
||||
|
||||
|
||||
EDIS;
|
||||
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBus_initControllerMode
|
||||
// This function is used to initialize the CONTROLLER mode
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBus_over_I2C_initControllerMode(uint32_t base, uint16_t address)
|
||||
{
|
||||
//
|
||||
// Check the arguments.
|
||||
//
|
||||
ASSERT(I2C_isBaseValid(base));
|
||||
|
||||
EALLOW;
|
||||
|
||||
//
|
||||
// Write the address to own address
|
||||
I2C_setOwnAddress(base, PMBUS_STACK_CONTROLLER_ADDRESS);
|
||||
|
||||
I2C_setTargetAddress(base, address);
|
||||
|
||||
//
|
||||
// Configure I2C in controller send mode
|
||||
//
|
||||
I2C_setConfig(base, I2C_CONTROLLER_SEND_MODE);
|
||||
|
||||
//
|
||||
// FIFO and interrupt configuration
|
||||
//
|
||||
I2C_enableFIFO(base);
|
||||
I2C_clearInterruptStatus(base, I2C_INT_TXFF);
|
||||
I2C_clearInterruptStatus(base, I2C_INT_RXFF);
|
||||
I2C_clearStatus(base,I2C_STS_NO_ACK|I2C_STS_ARB_LOST|I2C_STS_REG_ACCESS_RDY|I2C_STS_STOP_CONDITION);
|
||||
|
||||
I2C_disableInterrupt(base, (I2C_INT_ADDR_TARGET| I2C_INT_ARB_LOST | I2C_INT_NO_ACK));
|
||||
I2C_setEmulationMode(base, I2C_EMULATION_FREE_RUN);
|
||||
|
||||
EDIS;
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
//
|
||||
//! write to the transmit buffer (Controller mode)
|
||||
//!
|
||||
//! \param base is the base address of the PMBus instance used.
|
||||
//! \param buffer pointer to the message buffer where the transmit bytes
|
||||
//! are stored
|
||||
//! \param nBytes number of transmit bytes, up to 255
|
||||
//!
|
||||
//! This function can write up to 255 bytes in the transmit buffer.
|
||||
//!
|
||||
//! \note
|
||||
//! -# The user must check the UNIT_BUSY bit before attempting the
|
||||
//! first transmission.
|
||||
//! -# The buffer should be at least 4 words long; anything smaller will
|
||||
//! lead to the possibility of memory overrun when a transaction of 4 bytes
|
||||
//! happens.
|
||||
//!
|
||||
//! \return None.
|
||||
//
|
||||
******************************************************************************/
|
||||
void PMBus_over_I2C_putData(uint32_t base, uint16_t *buffer, uint16_t nBytes)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t tx_data = 0U;
|
||||
uint16_t *pBuffer = buffer;
|
||||
|
||||
//
|
||||
// Check the arguments.
|
||||
//
|
||||
ASSERT(I2C_isBaseValid(base));
|
||||
|
||||
/*
|
||||
while(i < nBytes)
|
||||
{
|
||||
tx_data |= (((uint32_t)*pBuffer & 0x000000FFUL) <<
|
||||
((uint32_t)i << 3U));
|
||||
pBuffer++;
|
||||
i++;
|
||||
}
|
||||
*/
|
||||
|
||||
/***************Write******************/
|
||||
if(nBytes != 0)
|
||||
{
|
||||
|
||||
while(nBytes > 0) //check that there are still bytes to send
|
||||
{
|
||||
tx_data = (*pBuffer & 0x000000FFUL);
|
||||
I2C_putData(base,tx_data);
|
||||
//tx_data = tx_data >> (8U);
|
||||
pBuffer++;
|
||||
nBytes--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBus_over_I2C_getData
|
||||
//
|
||||
//
|
||||
//! Read from the receive buffer
|
||||
//!
|
||||
//! \param base is the base address of the PMBus instance used.
|
||||
//! \param buffer pointer to the message buffer where the received bytes
|
||||
//! will be stored
|
||||
//!
|
||||
//! \return num_rx_bytes - Number of bytes that are received.
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint16_t PMBus_over_I2C_getData(uint32_t base, uint16_t *buffer)
|
||||
{
|
||||
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t temp, i;
|
||||
uint16_t num_rx_bytes;
|
||||
|
||||
//
|
||||
// Check the arguments.
|
||||
//
|
||||
ASSERT(I2C_isBaseValid(base));
|
||||
|
||||
//
|
||||
// Get the contents of the Receive buffer.
|
||||
//
|
||||
num_rx_bytes = (uint16_t)I2C_getRxFIFOStatus(base);
|
||||
|
||||
if(num_rx_bytes != 0U)
|
||||
{
|
||||
|
||||
for(i = 0U; i < num_rx_bytes; i++)
|
||||
{
|
||||
temp = HWREG(base + I2C_O_DRR);
|
||||
buffer[i] = (uint16_t)(temp & 0x000000FFUL);
|
||||
//temp = temp >> 8U;
|
||||
}
|
||||
}
|
||||
|
||||
return(num_rx_bytes);
|
||||
|
||||
}
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
uint16_t PMBusTarget_CrcMsgSize = 0;
|
||||
uint16_t PMBusTarget_CrcMsg[5];
|
||||
uint16_t PMBusTarget_CrcControllerGenerated = 0;
|
||||
uint16_t PMBusTarget_CrcTargetGenerated = 0;
|
||||
|
||||
uint16_t calc_PEC(uint16_t *CRCMsgBuffer, uint16_t CRCMsgSize, uint16_t *pMsgBuffer, uint16_t nBytes)
|
||||
{
|
||||
uint16_t crcResultVcu =0U ;
|
||||
uint16_t CRCBuffer[256];
|
||||
uint16_t index =0, u8Index=0;
|
||||
uint16_t count =0;
|
||||
|
||||
// initialize to zero
|
||||
|
||||
// CRCMsgSize - if index is even, use __byte(&CRCBuffer[index],0)
|
||||
|
||||
for(index =0;index<CRCMsgSize;index++)
|
||||
{
|
||||
if(count%2 ==0)
|
||||
{
|
||||
__byte(&CRCBuffer[u8Index],0) = CRCMsgBuffer[index];
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
__byte(&CRCBuffer[u8Index],1) = CRCMsgBuffer[index];
|
||||
count++;
|
||||
}
|
||||
if(count%2==0)
|
||||
{
|
||||
u8Index++;
|
||||
}
|
||||
}
|
||||
|
||||
for(index =0;index<nBytes;index++)
|
||||
{
|
||||
if(count%2 ==0)
|
||||
{
|
||||
__byte(&CRCBuffer[u8Index],0) = pMsgBuffer[index];
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
__byte(&CRCBuffer[u8Index],1) = pMsgBuffer[index];
|
||||
count++;
|
||||
}
|
||||
if(count%2==0)
|
||||
{
|
||||
u8Index++;
|
||||
}
|
||||
}
|
||||
|
||||
CRC_Obj CRC;
|
||||
CRC_Handle handleCRC;
|
||||
// Step 1: Initialize the CRC object
|
||||
CRC.seedValue = 0;
|
||||
CRC.nMsgBytes = nBytes + CRCMsgSize;
|
||||
CRC.parity = CRC_parity_even;
|
||||
CRC.crcResult = 0;
|
||||
CRC.pMsgBuffer = (uint16_t *)&CRCBuffer[0];
|
||||
//CRC.pCrcTable = (uint16_t *)&crc8Table[0];
|
||||
CRC.init = (void (*)(void *))CRC_init8Bit;
|
||||
|
||||
// Step 2: Initialize the handle
|
||||
handleCRC = &CRC;
|
||||
|
||||
//! Now we run the VCU routine on the vector testInput. The
|
||||
//! polynomial employed by the VCU is fixed i.e.
|
||||
//! \f$ x^{8}+x^{2}+x^{1}+1 \f$ (0x07)
|
||||
//! The parity chosen was CRC_parity_even indicating that the CRC will start
|
||||
//! from the low byte of the first word.
|
||||
//!
|
||||
CRC.init(handleCRC);
|
||||
|
||||
CRC.crcResult = 0;
|
||||
CRC.run = (void (*)(void *))CRC_run8Bit;
|
||||
|
||||
// Step 2: Run the VCU 8-bit CRC routine and save the result
|
||||
CRC.run(handleCRC);
|
||||
crcResultVcu = CRC.crcResult & 0x00FF; //We only want one byte (lower);
|
||||
|
||||
return(crcResultVcu);
|
||||
}
|
||||
|
||||
|
||||
bool verifyPEC(uint16_t *CRCMsgBuffer, uint16_t CRCMsgSize, uint16_t *pMsgBuffer, uint16_t nBytes, uint16_t receivedPEC)
|
||||
{
|
||||
uint16_t calcPEC = 0U;
|
||||
bool bVerifyPEC= false;
|
||||
calcPEC=calc_PEC(CRCMsgBuffer, CRCMsgSize,pMsgBuffer,nBytes);
|
||||
|
||||
if(calcPEC ==receivedPEC)
|
||||
{
|
||||
bVerifyPEC =true;
|
||||
}
|
||||
return (bVerifyPEC);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TIMEOUT
|
||||
void
|
||||
configCPUTimer(uint32_t cpuTimer, float freq, float period)
|
||||
{
|
||||
uint32_t temp;
|
||||
|
||||
//
|
||||
// Initialize timer period:
|
||||
//
|
||||
temp = (uint32_t)((freq / 1000000) * period);
|
||||
CPUTimer_setPeriod(cpuTimer, temp);
|
||||
|
||||
//
|
||||
// Set pre-scale counter to divide by 1 (SYSCLKOUT):
|
||||
//
|
||||
CPUTimer_setPreScaler(cpuTimer, 0);
|
||||
|
||||
//
|
||||
// Initializes timer control register. The timer is stopped, reloaded,
|
||||
// free run disabled, and interrupt enabled.
|
||||
// Additionally, the free and soft bits are set
|
||||
//
|
||||
CPUTimer_stopTimer(cpuTimer);
|
||||
CPUTimer_reloadTimerCounter(cpuTimer);
|
||||
CPUTimer_setEmulationMode(cpuTimer,
|
||||
CPUTIMER_EMULATIONMODE_STOPAFTERNEXTDECREMENT);
|
||||
CPUTimer_enableInterrupt(cpuTimer);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
initCPUTimers(uint32_t cpuTimer)
|
||||
{
|
||||
//
|
||||
// Initialize timer period to maximum
|
||||
//
|
||||
CPUTimer_setPeriod(cpuTimer, 0xFFFFFFFF);
|
||||
|
||||
|
||||
//
|
||||
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT)
|
||||
//
|
||||
CPUTimer_setPreScaler(cpuTimer, 0);
|
||||
|
||||
//
|
||||
// Make sure timer is stopped
|
||||
//
|
||||
CPUTimer_stopTimer(cpuTimer);
|
||||
|
||||
//
|
||||
// Reload all counter register with period value
|
||||
//
|
||||
CPUTimer_reloadTimerCounter(cpuTimer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
PMBusStack_targetTimeoutHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
|
||||
//
|
||||
// Set the current state to idle
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
//
|
||||
// Rewind the current pointer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, buffer);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_NONE);
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,196 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_config.c
|
||||
//
|
||||
// TITLE: PMBUS Communications Stack Configuration
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "pmbus_stack_config.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(1)
|
||||
|
||||
#define PMBUS_STACK_TARGET_ADDRESS 0U
|
||||
#define PMBUS_STACK_TARGET_MASK 0x7FU
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
PMBus_StackObject PMBusStackTarget;
|
||||
PMBus_StackHandle PMBusStackTargetHandle = &PMBusStackTarget;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_initModule
|
||||
//
|
||||
//*****************************************************************************
|
||||
bool PMBusStack_initModule(PMBus_StackHandle handle, const uint32_t moduleBase,
|
||||
uint16_t *buffer)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
bool status = false;
|
||||
|
||||
//
|
||||
// Set the module base address
|
||||
//
|
||||
PMBusStackObject_setModuleBase(handle, moduleBase);
|
||||
|
||||
//
|
||||
// Assign the buffer pointer to the object, set the current pointer to
|
||||
// the head of the buffer
|
||||
//
|
||||
PMBusStackObject_setBufferPointer(handle, buffer);
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, buffer);
|
||||
|
||||
//
|
||||
// Reset the PMBUS Module
|
||||
//
|
||||
PMBus_disableModule(PMBusStackObject_getModuleBase(handle));
|
||||
|
||||
//
|
||||
// Take the PMBUS out of reset
|
||||
//
|
||||
PMBus_enableModule(PMBusStackObject_getModuleBase(handle));
|
||||
|
||||
//
|
||||
// Initialize depending upon whether in target or controller mode
|
||||
//
|
||||
if(PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_TARGET)
|
||||
{
|
||||
//
|
||||
// Initialize the target module
|
||||
//
|
||||
PMBus_initTargetMode(PMBusStackObject_getModuleBase(handle),
|
||||
PMBusStackObject_getTargetAddress(handle),
|
||||
PMBusStackObject_getTargetAddressMask(handle));
|
||||
|
||||
//
|
||||
// Configure the target module (writes to the PMBSC register)
|
||||
//
|
||||
PMBus_configTarget(PMBUSA_BASE, (PMBUS_TARGET_ENABLE_PEC_PROCESSING |
|
||||
PMBUS_TARGET_AUTO_ACK_4_BYTES));
|
||||
|
||||
//
|
||||
// Enable interrupts
|
||||
//
|
||||
//I2C - AAS, FIFO Interrupts RX & TX , STOP
|
||||
PMBus_enableInterrupt(PMBusStackObject_getModuleBase(handle),
|
||||
(PMBUS_INT_DATA_READY | PMBUS_INT_DATA_REQUEST |
|
||||
PMBUS_INT_EOM));
|
||||
|
||||
//
|
||||
// Reset the state machine
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
status = true;
|
||||
}
|
||||
else // (PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_CONTROLLER)
|
||||
{
|
||||
//
|
||||
// Zero out the target address and set the mask to 0x7F
|
||||
// (the mask is N/A in controller mode)
|
||||
//
|
||||
PMBusStackObject_setTargetAddress(handle, PMBUS_STACK_TARGET_ADDRESS);
|
||||
PMBusStackObject_setTargetAddressMask(handle, PMBUS_STACK_TARGET_MASK);
|
||||
|
||||
//
|
||||
// Initialize the controller module
|
||||
//
|
||||
PMBus_initControllerMode(PMBusStackObject_getModuleBase(handle));
|
||||
|
||||
//
|
||||
// Enable interrupts
|
||||
//
|
||||
PMBus_enableInterrupt(PMBusStackObject_getModuleBase(handle),
|
||||
(PMBUS_INT_DATA_READY | PMBUS_INT_DATA_REQUEST |
|
||||
PMBUS_INT_EOM | PMBUS_INT_ALERT));
|
||||
|
||||
//
|
||||
// Reset the state machine
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
status = true;
|
||||
}
|
||||
|
||||
return(status);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_defaultTransactionHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
int32_t PMBusStack_defaultTransactionHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Replace with an actual handler. This will stop emulation
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,118 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_handler.c
|
||||
//
|
||||
// TITLE: PMBUS Communications State Machine
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(2)
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Read the status bits once at the start of each state handler
|
||||
// The status bits are cleared on a read, therefore, they should be
|
||||
// read once at the start of each ISR; any subsequent flags will cause
|
||||
// another interrupt
|
||||
//
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
PMBusStackObject_setModuleStatus(handle,
|
||||
PMBus_getStatus(handle->moduleBase));
|
||||
#else
|
||||
PMBusStackObject_setModuleStatus(handle,
|
||||
I2C_getStatus(handle->moduleBase));
|
||||
#endif
|
||||
switch(PMBusStackObject_getNextState(handle))
|
||||
{
|
||||
case PMBUS_STACK_STATE_IDLE:
|
||||
PMBusStack_targetIdleStateHandler(handle);
|
||||
break;
|
||||
case PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM:
|
||||
PMBusStack_targetReceiveByteWaitForEOMStateHandler(handle);
|
||||
break;
|
||||
case PMBUS_STACK_STATE_READ_BLOCK:
|
||||
PMBusStack_targetReadBlockStateHandler(handle);
|
||||
break;
|
||||
case PMBUS_STACK_STATE_READ_WAIT_FOR_EOM:
|
||||
PMBusStack_targetReadWaitForEOMStateHandler(handle);
|
||||
break;
|
||||
case PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL:
|
||||
PMBusStack_targetBlockWriteOrProcessCallStateHandler(handle);
|
||||
break;
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
case PMBUS_STACK_STATE_EXTENDED_COMMAND:
|
||||
PMBusStack_targetExtendedCommandStateHandler(handle);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
PMBusStack_targetIdleStateHandler(handle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_over_i2c_stack_handler_target_block_write_process_call.c
|
||||
//
|
||||
// TITLE: PMBUS_OVER_I2C_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifdef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(5)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetBlockWriteOrProcessCallStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetBlockWriteOrProcessCallStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = 0U;
|
||||
uint16_t *CRCBuffer = PMBusStackObject_getCRCBufferPointer(handle);
|
||||
uint16_t targetAddress;
|
||||
#ifdef TIMEOUT
|
||||
uint32_t timerBase = PMBusStackObject_getTimerBase(handle);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Set the current state to block write/Process Call
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle,
|
||||
PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
|
||||
if(STOP_CONDITION_DETECTED)
|
||||
{
|
||||
//
|
||||
// EOM = 1
|
||||
//
|
||||
if(!(TARGET_TRANSMITTER) != 0U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT != 0, EOM = 1, DATA_READY = 1, DATA_REQUEST = 0
|
||||
// This must be the last few bytes of the block write command
|
||||
// or an extended write byte/word command
|
||||
//
|
||||
|
||||
//
|
||||
// Start saving data in the buffer from the currPtr position
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_over_I2C_getTargetData(base, buffer);
|
||||
|
||||
//
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, (nBytes +
|
||||
PMBusStackObject_getNumOfBytes(handle)));
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_BLOCKWRITE);
|
||||
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
//
|
||||
// Get target address
|
||||
//
|
||||
targetAddress = PMBusStackObject_getTargetAddress(handle);
|
||||
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
PMBusStackObject_setCRCMsgSize(handle, 1U);
|
||||
#endif
|
||||
//
|
||||
// Call the handler for the BLOCKWRITE transaction
|
||||
//
|
||||
handle->transactionHandle[PMBUS_TRANSACTION_BLOCKWRITE](handle);
|
||||
|
||||
//
|
||||
// Set the next state to PMBUS_STACK_STATE_IDLE
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
I2C_clearStatus(base, (I2C_STS_STOP_CONDITION));
|
||||
|
||||
#ifdef TIMEOUT
|
||||
CPUTimer_stopTimer(timerBase);
|
||||
CPUTimer_reloadTimerCounter(timerBase);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 0, EOM = 1, DATA_READY = 0, DATA_REQUEST = 0
|
||||
// End-of-message, no data ready, no data requested, no bytes
|
||||
// received. This must be a write word command
|
||||
//
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the WRITEWORD transaction
|
||||
//
|
||||
handle->transactionHandle[PMBUS_TRANSACTION_WRITEWORD](handle);
|
||||
|
||||
//
|
||||
// Set the next state to PMBUS_STACK_STATE_IDLE
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
#ifdef TIMEOUT
|
||||
CPUTimer_stopTimer(timerBase);
|
||||
CPUTimer_reloadTimerCounter(timerBase);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// EOM = 0
|
||||
//
|
||||
if(TARGET_RECEIVER)
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_READY = 1 RD_BYTE_COUNT = ?
|
||||
// Start saving data in the buffer from the currPtr position
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_over_I2C_getTargetData(base, buffer);
|
||||
|
||||
//
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, (nBytes +
|
||||
PMBusStackObject_getNumOfBytes(handle)));
|
||||
|
||||
//
|
||||
// Stay in the same state, i.e.
|
||||
// PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL
|
||||
//
|
||||
}
|
||||
else if (TARGET_TRANSMITTER)
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_READY = 0 RD_BYTE_COUNT = 0, DATA_REQUEST = 1
|
||||
// This is a Block Write, Read, Process Call
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_BLOCKWRPC);
|
||||
|
||||
//
|
||||
// Call the handler for the BLOCKWRPC transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_BLOCKWRPC](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Rewind the buffer pointer
|
||||
//
|
||||
buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
|
||||
if(nBytes <= 4U)
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_over_I2C_putTargetData(base, buffer, nBytes);
|
||||
}
|
||||
else // nBytes > 4
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, without PEC
|
||||
//
|
||||
PMBus_over_I2C_putTargetData(base, buffer, 4U);
|
||||
|
||||
//
|
||||
// Update the current index into the buffer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[4U]);
|
||||
}
|
||||
//
|
||||
// Proceed to the READ_BLOCK state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_READ_BLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_READY = ? RD_BYTE_COUNT = ?, DATA_REQUEST = 0
|
||||
// A Fault condition
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+575
@@ -0,0 +1,575 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_over_i2c_stack_handler_target_idle.c
|
||||
//
|
||||
// TITLE: PMBUS_OVER_I2C_STACK_STATE_IDLE handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifdef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(3)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetIdleStateHandler
|
||||
// This function is the entry point of the target stack. PMBus will be in IDLE
|
||||
// state before any transaction. Any transaction which is initiated will
|
||||
// trigger an interrupt which will be handled by this function in the ISR.
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetIdleStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint16_t *CRCBuffer = PMBusStackObject_getCRCBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
//bool PEC_validity = handle->PECValidity;
|
||||
uint16_t targetAddress;
|
||||
uint16_t nBytes = 0U;
|
||||
uint16_t command = 0;
|
||||
uint16_t extcommand = 0;
|
||||
uint16_t *currentPointer;
|
||||
#ifdef TIMEOUT
|
||||
uint32_t timerBase;
|
||||
#endif
|
||||
//
|
||||
// Set the current state to idle
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
//
|
||||
// Rewind the current pointer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, buffer);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_NONE);
|
||||
|
||||
#ifdef TIMEOUT
|
||||
timerBase = PMBusStackObject_getTimerBase(handle);
|
||||
CPUTimer_startTimer(timerBase);
|
||||
#endif
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
//
|
||||
// Get target address
|
||||
//
|
||||
targetAddress = PMBusStackObject_getTargetAddress(handle);
|
||||
|
||||
//
|
||||
// reset CRC buffer size
|
||||
//
|
||||
PMBusStackObject_setCRCMsgSize(handle, 0U);
|
||||
#endif
|
||||
//
|
||||
// Check if the unit is busy
|
||||
//
|
||||
if((status & I2C_STS_BUS_BUSY) == 0U) //I2C - Busy flag
|
||||
{
|
||||
//
|
||||
// Neither I2C hardware nor firmware are stuck,
|
||||
//
|
||||
// The user must use the clock low timeout feature to
|
||||
// fire an interrupt off to the CPU, query the comms
|
||||
// stack object, take remedial measures and reset
|
||||
// the state machine prior to returning from the interrupt
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
//nBytes = PMBus_over_I2C_getTargetData(base, buffer) - PEC_validity;
|
||||
nBytes = PMBus_over_I2C_getTargetData(base, buffer);
|
||||
|
||||
#else
|
||||
nBytes = PMBus_over_I2C_getTargetData(base, buffer);
|
||||
#endif
|
||||
|
||||
if(nBytes >= 0x2U)
|
||||
{
|
||||
command = buffer[0];
|
||||
extcommand = buffer[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
command= buffer[0];
|
||||
}
|
||||
if(TARGET_RECEIVER)
|
||||
{
|
||||
|
||||
#if PEC_ENABLED
|
||||
if(nBytes>1)
|
||||
{
|
||||
nBytes = nBytes - 1;
|
||||
}
|
||||
#endif
|
||||
I2C_setConfig(base, I2C_TARGET_RECEIVE_MODE);
|
||||
|
||||
//nBytes = PMBus_over_I2C_getTargetData(base, buffer) - PEC_validity;
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
switch(nBytes)
|
||||
{
|
||||
case I2C_FIFO_RX0:
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_QUICKCOMMAND);
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_QUICKCOMMAND](handle);
|
||||
break;
|
||||
|
||||
|
||||
case I2C_FIFO_RX1: // Call the handler for the SENDBYTE transaction
|
||||
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_SENDBYTE);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
PMBusStackObject_setCRCMsgSize(handle, 1U);
|
||||
#endif
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_SENDBYTE](handle);
|
||||
break;
|
||||
|
||||
case I2C_FIFO_RX2: // Call the handler for the WRITEBYTE transaction
|
||||
PMBusStackObject_isCommandAndTransactionValid(command, PMBUS_TRANSACTION_WRITEBYTE);
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_WRITEBYTE);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
PMBusStackObject_setCRCMsgSize(handle, 1U);
|
||||
#endif
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_WRITEBYTE](handle);
|
||||
break;
|
||||
|
||||
case I2C_FIFO_RX3:
|
||||
// Call the handler for the Extended command Write byte transaction
|
||||
if(command == PMBUS_CMD_MFR_SPECIFIC_COMMAND && extcommand == PMBUS_CMD_STORE_DEFAULT_CODE)
|
||||
{
|
||||
// Call the handler for the Extended Write Byte transaction
|
||||
PMBusStackObject_setNextState(handle,PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
&buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEBYTE);
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command;
|
||||
CRCBuffer[2] = extcommand;
|
||||
CRCBuffer[3] = targetAddress << 1; // store target address + R/W=1
|
||||
PMBusStackObject_setCRCMsgSize(handle, 4U);
|
||||
#endif
|
||||
//
|
||||
// Call the handler for the WRITEBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_WRITEBYTE](handle);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the handler for the WRITEWORD transaction
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_WRITEWORD);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
PMBusStackObject_setCRCMsgSize(handle, 1U);
|
||||
#endif
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_WRITEWORD](handle);
|
||||
}
|
||||
break;
|
||||
|
||||
case I2C_FIFO_RX4:
|
||||
// Call the handler for the Extended Write word transaction
|
||||
if(command == PMBUS_CMD_MFR_SPECIFIC_COMMAND && extcommand == PMBUS_CMD_VOUT_COMMAND)
|
||||
{
|
||||
// Call the handler for the Extended Write Byte transaction
|
||||
PMBusStackObject_setNextState(handle,PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
&buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the WRITEBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_WRITEWORD](handle);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPointer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
¤tPointer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_BLOCKWRPC);
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default: // Unhandled exception
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Set next state to IDLE
|
||||
//
|
||||
if(PMBusStackObject_getTransactionType(handle) == PMBUS_TRANSACTION_BLOCKWRPC)
|
||||
{
|
||||
PMBusStackObject_setNextState(handle,PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
I2C_clearInterruptStatus(base,I2C_INT_RXFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
I2C_clearInterruptStatus(base,I2C_INT_STOP_CONDITION);
|
||||
I2C_clearInterruptStatus(base,I2C_INT_RXFF);
|
||||
#ifdef TIMEOUT
|
||||
CPUTimer_stopTimer(timerBase);
|
||||
CPUTimer_reloadTimerCounter(timerBase);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(TARGET_TRANSMITTER)
|
||||
{
|
||||
|
||||
I2C_setConfig(base, I2C_TARGET_SEND_MODE);
|
||||
|
||||
if(STOP_CONDITION_NOT_DETECTED)
|
||||
{
|
||||
switch(nBytes)
|
||||
{
|
||||
case I2C_FIFO_RXEMPTY:
|
||||
//When you don't receive any command, it is Receive Byte transaction
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_RECEIVEBYTE);
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_RECEIVEBYTE](handle);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
PMBusStackObject_setCRCMsgSize(handle, 1U);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case I2C_FIFO_RX1:
|
||||
if(PMBusStackObject_isCommandAndTransactionValid(command, PMBUS_TRANSACTION_READBYTE))
|
||||
{
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_READBYTE);
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_READBYTE](handle);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command ;
|
||||
CRCBuffer[2] = (targetAddress << 1) + 1; // store target address + R/W=1
|
||||
PMBusStackObject_setCRCMsgSize(handle, 3U);
|
||||
#endif
|
||||
}
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command, PMBUS_TRANSACTION_READWORD))
|
||||
{
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_READWORD);
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_READWORD](handle);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command;
|
||||
CRCBuffer[2] = (targetAddress << 1) + 1; // store target address + R/W=1
|
||||
PMBusStackObject_setCRCMsgSize(handle, 3U);
|
||||
#endif
|
||||
}
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command, PMBUS_TRANSACTION_BLOCKREAD))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_BLOCKREAD);
|
||||
|
||||
//
|
||||
// Call the handler for the READBLOCK transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_BLOCKREAD](handle);
|
||||
|
||||
I2C_disableInterrupt(base, I2C_INT_TX_DATA_RDY);
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
/*
|
||||
if(nBytes <= 4U)
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_over_I2C_putData(base, buffer, nBytes);
|
||||
}
|
||||
else // nBytes > 4
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, without PEC
|
||||
//
|
||||
PMBus_over_I2C_putData(base, buffer, 4U);
|
||||
|
||||
//
|
||||
// Update the current index into the buffer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[4U]);
|
||||
}
|
||||
*/
|
||||
//
|
||||
// Proceed to the READ_BLOCK state
|
||||
//
|
||||
// PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_READ_BLOCK);
|
||||
PMBus_over_I2C_putData(base, buffer, nBytes);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case I2C_FIFO_RX2:
|
||||
// Call the handler for the Extended Read byte transaction
|
||||
if(command == PMBUS_CMD_MFR_SPECIFIC_COMMAND && extcommand == PMBUS_CMD_OPERATION)
|
||||
{
|
||||
//
|
||||
// Set the current state to PMBUS_STACK_STATE_EXTENDED_COMMAND
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
//if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
// PMBUS_TRANSACTION_READBYTE))
|
||||
//{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_READBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the READBYTE transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READBYTE](handle);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command;
|
||||
CRCBuffer[2] = extcommand;
|
||||
CRCBuffer[3] = (targetAddress << 1) + 1; // store target address + R/W=1
|
||||
PMBusStackObject_setCRCMsgSize(handle, 4U);
|
||||
#endif
|
||||
}
|
||||
// Call the handler for the Extended Read word transaction
|
||||
else if(command == PMBUS_CMD_MFR_SPECIFIC_COMMAND && extcommand == PMBUS_CMD_VOUT_COMMAND)
|
||||
{
|
||||
//
|
||||
// Set the current state to PMBUS_STACK_STATE_EXTENDED_COMMAND
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_READWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the READWORD transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READWORD](handle);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command;
|
||||
CRCBuffer[2] = extcommand;
|
||||
CRCBuffer[3] = (targetAddress << 1) + 1; // store target address + R/W=1
|
||||
PMBusStackObject_setCRCMsgSize(handle, 4U);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case I2C_FIFO_RX3:
|
||||
//
|
||||
// RD_BYTE_COUNT = 3, EOM = 0, DATA_READY = 1
|
||||
//
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
currentPointer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
¤tPointer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_BLOCKWRPC);
|
||||
|
||||
|
||||
//
|
||||
// Set the current state to
|
||||
// PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL //Process call
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command;
|
||||
CRCBuffer[2] = buffer[1];
|
||||
CRCBuffer[3] = buffer[2];
|
||||
CRCBuffer[3] = (targetAddress << 1) + 1; // store target address + R/W=1
|
||||
PMBusStackObject_setCRCMsgSize(handle, 4U);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Call the handler for the READWORD transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_BLOCKWRPC](handle);
|
||||
break;
|
||||
default:
|
||||
// Unhandled exception
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(nBytes)
|
||||
{
|
||||
case I2C_FIFO_RX0:
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_QUICKCOMMAND);
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_QUICKCOMMAND](handle);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unhandled exception
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(PMBusStackObject_getTransactionType(handle) != PMBUS_TRANSACTION_BLOCKREAD)
|
||||
{
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
|
||||
I2C_disableInterrupt(base, I2C_INT_TX_DATA_RDY);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
buffer[nBytes] = calc_PEC(CRCBuffer, PMBusStackObject_getCRCBufferSize(handle), buffer[1], nBytes);
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer + PEC.
|
||||
//
|
||||
PMBus_over_I2C_putData(base, buffer, nBytes+1);
|
||||
#else
|
||||
PMBus_over_I2C_putData(base, buffer, nBytes);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_over_i2cstack_handler_target_read_block.c
|
||||
//
|
||||
// TITLE: PMBUS_OVER_I2C_STACK_STATE_READ_BLOCK handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifdef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(4)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetReadBlockStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetReadBlockStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
|
||||
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
uint16_t *currentPointer;
|
||||
uint16_t bytesTransmitted = 0U;
|
||||
uint16_t bytesToTransmit = 0U;
|
||||
#ifdef TIMEOUT
|
||||
uint32_t timerBase = PMBusStackObject_getTimerBase(handle);
|
||||
#endif
|
||||
//
|
||||
// Set the current state to READ_BLOCK
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_READ_BLOCK);
|
||||
|
||||
//
|
||||
// Check if EOM/STOP condition is received
|
||||
//
|
||||
//if((status & I2C_STS_STOP_CONDITION)!=0U)
|
||||
if(STOP_CONDITION_DETECTED)
|
||||
{
|
||||
//
|
||||
// EOM = 1,
|
||||
// Controller has prematurely terminated the block read,
|
||||
// or in the READ/WAIT_FOR_EOM state, only 4 bytes
|
||||
// were required to be sent, and the transaction was complete
|
||||
// NOTE: ACK is required to allow the target to ack its address in
|
||||
// any subsequent transaction.
|
||||
//
|
||||
I2C_clearStatus(base, (I2C_STS_STOP_CONDITION | I2C_INT_TX_DATA_RDY));
|
||||
|
||||
I2C_enableInterrupt(base, I2C_INT_TX_DATA_RDY);
|
||||
|
||||
//
|
||||
// Block Read was successful, return to the
|
||||
// Idle state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
#ifdef TIMEOUT
|
||||
CPUTimer_stopTimer(timerBase);
|
||||
CPUTimer_reloadTimerCounter(timerBase);
|
||||
#endif
|
||||
}
|
||||
else if(TARGET_TRANSMITTER)
|
||||
{
|
||||
//
|
||||
// DATA_REQUEST = 1, EOM = 0, NACK = 0
|
||||
//
|
||||
currentPointer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
bytesTransmitted = (uint16_t)(currentPointer - buffer);
|
||||
bytesToTransmit = nBytes - bytesTransmitted;
|
||||
|
||||
if(bytesToTransmit > 4U)
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, without PEC
|
||||
//
|
||||
|
||||
//PMBus_over_I2C_putData(base, currentPointer, bytesToTransmit);
|
||||
PMBus_over_I2C_putData(base, currentPointer, 4U);
|
||||
|
||||
//
|
||||
// Update the current index into the buffer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
¤tPointer[4U]);
|
||||
}
|
||||
else //bytesToTransmit <= 4U (the last transmission)
|
||||
{
|
||||
//
|
||||
// Put the last few bytes (<=4) to the PMBUS Transmit buffer,
|
||||
// with PEC
|
||||
//
|
||||
PMBus_over_I2C_putData(base, currentPointer, bytesToTransmit);
|
||||
|
||||
//
|
||||
// Return to the EOM State
|
||||
//
|
||||
PMBusStackObject_setNextState(handle,
|
||||
PMBUS_STACK_STATE_READ_WAIT_FOR_EOM);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_over_i2c_stack_handler_target_read_wait_for_eom.c
|
||||
//
|
||||
// TITLE: PMBUS_OVER_I2C_STACK_STATE_READ_WAIT_FOR_EOM handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifdef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(6)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetReadWaitForEOMStateHandler
|
||||
// This function is used to handle the read transaction requests.
|
||||
// The command is decoded to identify which of the read command is received
|
||||
// Depending on the command, it is handled
|
||||
// Once the EOM/Stop condition is recevied, the stack is put into IDLE state
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetReadWaitForEOMStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = 0U;
|
||||
uint16_t command = buffer[0U];
|
||||
#ifdef TIMEOUT
|
||||
uint32_t timerBase = PMBusStackObject_getTimerBase(handle);
|
||||
#endif
|
||||
//
|
||||
// Set the current state to Read/Wait for EOM
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle,
|
||||
PMBUS_STACK_STATE_READ_WAIT_FOR_EOM);
|
||||
|
||||
//
|
||||
// Check if EOM/STOP condition is received
|
||||
//
|
||||
if((status & I2C_STS_STOP_CONDITION)!=0U)
|
||||
{
|
||||
//
|
||||
// EOM/STOP = 1
|
||||
|
||||
|
||||
//
|
||||
// Clear the STOP condition
|
||||
//
|
||||
//PMBus_ackTransaction(base);
|
||||
|
||||
I2C_clearStatus(base, (I2C_STS_STOP_CONDITION | I2C_INT_TX_DATA_RDY));
|
||||
|
||||
I2C_enableInterrupt(base, I2C_INT_TX_DATA_RDY);
|
||||
//
|
||||
// Read byte/word/block was successful, return to the
|
||||
// Idle state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
#ifdef TIMEOUT
|
||||
CPUTimer_stopTimer(timerBase);
|
||||
CPUTimer_reloadTimerCounter(timerBase);
|
||||
#endif
|
||||
}
|
||||
//
|
||||
// At this point the command is already in the buffer
|
||||
//
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_READBYTE))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_READBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the READBYTE transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READBYTE](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_over_I2C_putData(base, buffer, nBytes);
|
||||
|
||||
//
|
||||
// Clear the status
|
||||
//
|
||||
I2C_clearStatus(base, I2C_STS_TX_DATA_RDY);
|
||||
}
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_READWORD))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_READWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the READWORD transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READWORD](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_over_I2C_putData(base, buffer, nBytes);
|
||||
|
||||
I2C_clearStatus(base, I2C_STS_BYTE_SENT);
|
||||
}
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_BLOCKREAD))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_BLOCKREAD);
|
||||
|
||||
//
|
||||
// Call the handler for the READBLOCK transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_BLOCKREAD](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
if(nBytes <= 4U)
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_over_I2C_putData(base, buffer, nBytes);
|
||||
}
|
||||
else // nBytes > 4
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, without PEC
|
||||
//
|
||||
PMBus_over_I2C_putData(base, buffer, 4U);
|
||||
|
||||
//
|
||||
// Update the current index into the buffer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[4U]);
|
||||
}
|
||||
//
|
||||
// Proceed to the READ_BLOCK state
|
||||
//
|
||||
//PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_READ_BLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_over_i2c_stack_handler_target_receive_byte_wait_for_eom.c
|
||||
//
|
||||
// TITLE: PMBUS_OVER_I2C_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifdef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(7)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetReceiveByteWaitForEOMStateHandler
|
||||
// This function is the handler for the STOP condition of Receive byte
|
||||
// transaction
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetReceiveByteWaitForEOMStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
#ifdef TIMEOUT
|
||||
uint32_t timerBase = PMBusStackObject_getTimerBase(handle);
|
||||
#endif
|
||||
//
|
||||
// Set the current state to RECEIVE_BYTE_WAIT_FOR_EOM
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle,
|
||||
PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
|
||||
if(STOP_CONDITION_DETECTED)
|
||||
{
|
||||
//
|
||||
// EOM/STOP = 1
|
||||
// After a DATA_REQUEST/TX_RDY for a receive byte is seen by the target,
|
||||
// it places the requested byte on the line and transitions
|
||||
// from the idle to the receive byte wait-for-eom state
|
||||
//
|
||||
// The only interrupt expected after the received byte is that from an
|
||||
// EOM/STOP. The quick command also has EOM=1 and DATA_READY=0 at the end.
|
||||
// In order to distinguish between the two, if an EOM is received while
|
||||
// in this state it was a receive byte, if an EOM was received in the
|
||||
// idle state it was a quick command
|
||||
//
|
||||
|
||||
//
|
||||
// Clear the STOP condition
|
||||
//
|
||||
// PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
|
||||
I2C_clearStatus(base, (I2C_STS_STOP_CONDITION | I2C_INT_TX_DATA_RDY));
|
||||
|
||||
I2C_enableInterrupt(base, I2C_INT_TX_DATA_RDY);
|
||||
|
||||
//
|
||||
// Return to the idle state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
#ifdef TIMEOUT
|
||||
CPUTimer_stopTimer(timerBase);
|
||||
CPUTimer_reloadTimerCounter(timerBase);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled Exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_over_i2c_stack_handler_target_rx_fifo.c
|
||||
//
|
||||
// TITLE: PMBUS_OVER_I2C_STACK_RX_FIFO handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifdef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(8)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetIdleStateHandler
|
||||
// This function is the entry point of the target stack. PMBus will be in IDLE
|
||||
// state before any transaction. Any transaction which is initiated will
|
||||
// trigger an interrupt which will be handled by this function in the ISR.
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetRxFIFOHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
|
||||
//PMBus_StackHandle handle = pmbusStackTargetHandle;
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint16_t *CRCBuffer = PMBusStackObject_getCRCBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = 0U;
|
||||
uint16_t command = 0;
|
||||
uint16_t extcommand = 0;
|
||||
uint16_t *currentPointer;
|
||||
static bool first_time = true;
|
||||
uint16_t targetAddress;
|
||||
|
||||
if(PMBusStackObject_getCurrentState(handle) == PMBUS_STACK_STATE_IDLE)
|
||||
{
|
||||
//
|
||||
// Rewind the current pointer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, buffer);
|
||||
first_time = true;
|
||||
}
|
||||
|
||||
if(first_time)
|
||||
{
|
||||
//read the bytes and determine the command
|
||||
//nBytes = PMBus_over_I2C_getTargetData(base, buffer) - 1; //excluding PEC
|
||||
nBytes = PMBus_over_I2C_getTargetData(base, buffer);
|
||||
}
|
||||
if(nBytes >= 0x2U)
|
||||
{
|
||||
command = buffer[0];
|
||||
extcommand = buffer[1];
|
||||
}
|
||||
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
|
||||
//
|
||||
// Remove the PEC byte
|
||||
//
|
||||
if(nBytes>1)
|
||||
{
|
||||
nBytes = nBytes - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Get target address
|
||||
//
|
||||
targetAddress = PMBusStackObject_getTargetAddress(handle);
|
||||
|
||||
//
|
||||
// reset CRC buffer size
|
||||
//
|
||||
PMBusStackObject_setCRCMsgSize(handle, 0U);
|
||||
if(command == PMBUS_CMD_MFR_SPECIFIC_COMMAND && extcommand == PMBUS_CMD_STORE_DEFAULT_CODE)
|
||||
{
|
||||
// Call the handler for the Extended Write Byte transaction
|
||||
PMBusStackObject_setNextState(handle,PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
&buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEBYTE);
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command;
|
||||
CRCBuffer[2] = extcommand;
|
||||
CRCBuffer[3] = targetAddress << 1; // store target address
|
||||
PMBusStackObject_setCRCMsgSize(handle, 4U);
|
||||
#endif
|
||||
//
|
||||
// Call the handler for the WRITEBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_WRITEBYTE](handle);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
|
||||
|
||||
}
|
||||
else if(command == PMBUS_CMD_MFR_SPECIFIC_COMMAND && extcommand == PMBUS_CMD_VOUT_COMMAND)
|
||||
{
|
||||
// Call the handler for the Extended Write Byte transaction
|
||||
PMBusStackObject_setNextState(handle,PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
}
|
||||
else //STOP_CONDITION_DETECTED
|
||||
{
|
||||
// Call the handler for the WRITEWORD transaction
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_WRITEWORD);
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
PMBusStackObject_setCRCMsgSize(handle, 1U);
|
||||
#endif
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_WRITEWORD](handle);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
//I2C_clearInterruptStatus(base,I2C_INT_STOP_CONDITION);
|
||||
I2C_clearInterruptStatus(base,I2C_INT_RXFF);
|
||||
}
|
||||
#endif
|
||||
// Call the handler for the Extended Write word transaction
|
||||
if(command == PMBUS_CMD_MFR_SPECIFIC_COMMAND && extcommand == PMBUS_CMD_VOUT_COMMAND)
|
||||
{
|
||||
// Call the handler for the Extended Write Byte transaction
|
||||
PMBusStackObject_setNextState(handle,PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
|
||||
#ifdef PEC_ENABLED
|
||||
CRCBuffer[0] = targetAddress << 1;
|
||||
CRCBuffer[1] = command;
|
||||
CRCBuffer[2] = extcommand;
|
||||
CRCBuffer[3] = targetAddress << 1; // store target address + R/W=1
|
||||
PMBusStackObject_setCRCMsgSize(handle, 4U);
|
||||
//read PEC byte
|
||||
nBytes += PMBus_over_I2C_getTargetData(base, &buffer[nBytes+1]);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
&buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the WRITEBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_WRITEWORD](handle);
|
||||
|
||||
first_time = true;
|
||||
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// RXFFINT gets generated only when atleast 4 bytes are received from controller
|
||||
if(STOP_CONDITION_NOT_DETECTED)
|
||||
{
|
||||
currentPointer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[nBytes]);
|
||||
if (first_time==false)
|
||||
{
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
nBytes = PMBus_over_I2C_getTargetData(base, &buffer[nBytes]);
|
||||
}
|
||||
|
||||
|
||||
if(first_time)
|
||||
{
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, (nBytes +
|
||||
PMBusStackObject_getNumOfBytes(handle)));
|
||||
}
|
||||
first_time = false;
|
||||
|
||||
if(TARGET_RECEIVER)
|
||||
{
|
||||
// Call the handler for the BLOCK WRITE transaction
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_BLOCKWRITE);
|
||||
(void)handle-> transactionHandle[PMBUS_TRANSACTION_BLOCKWRITE](handle);
|
||||
}
|
||||
PMBusStackObject_setCurrentState(handle,PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
PMBusStackObject_setNextState(handle,PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//When STOP condition is detected
|
||||
if(PMBusStackObject_getNextState(handle)!=PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM)
|
||||
{
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
I2C_clearInterruptStatus(base,I2C_INT_RXFF);
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_handler_extended_command.c
|
||||
//
|
||||
// TITLE: PMBUS_STACK_STATE_EXTENDED_COMMAND handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(8)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetExtendedCommandStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetExtendedCommandStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t command = buffer[1U];
|
||||
uint16_t nBytes = 0U;
|
||||
|
||||
|
||||
//
|
||||
// Set the current state to PMBUS_STACK_STATE_EXTENDED_COMMAND
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
|
||||
if((status & PMBUS_PMBSTS_DATA_REQUEST) != 0U)
|
||||
{
|
||||
//
|
||||
// DATA_REQUEST = 1 (an extended read)
|
||||
//
|
||||
if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_READBYTE))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_READBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the READBYTE transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READBYTE](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, nBytes, true);
|
||||
}
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_READWORD))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_READWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the READWORD transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READWORD](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, nBytes, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
else if((status & PMBUS_PMBSTS_EOM) != 0U)
|
||||
{
|
||||
//
|
||||
// EOM = 1, DATA_REQUEST = 0
|
||||
//
|
||||
if(((status & PMBUS_PMBSTS_NACK) != 0U) &&
|
||||
((status & PMBUS_PMBSTS_DATA_READY) == 0U))
|
||||
{
|
||||
//
|
||||
// EOM = 1, NACK = 1, DATA_REQUEST = 0, DATA_READY = 0
|
||||
// Controller NACKs the extended read, ack and
|
||||
// change state to IDLE
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
}
|
||||
else if(((status & PMBUS_PMBSTS_NACK) == 0U) &&
|
||||
((status & PMBUS_PMBSTS_DATA_READY) != 0U))
|
||||
{
|
||||
//
|
||||
// EOM = 1, DATA_READY = 1, NACK = 0, DATA_REQUEST = 0
|
||||
// Controller completes either an ext write byte/word
|
||||
//
|
||||
|
||||
//
|
||||
// Set buffer pointer to the current pointer
|
||||
//
|
||||
buffer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
|
||||
if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) == 2U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 2, EOM = 1, DATA_READY = 1
|
||||
// extended write Byte (Receive buffer has Byte & PEC)
|
||||
//
|
||||
|
||||
//
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
&buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, (nBytes +
|
||||
PMBusStackObject_getNumOfBytes(handle)));
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the WRITEBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_WRITEBYTE](handle);
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
}
|
||||
else if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) == 3U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 3, EOM = 1, DATA_READY = 1
|
||||
// Write word (Receive buffer has Byte #1, Byte #2, PEC)
|
||||
//
|
||||
|
||||
//
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
&buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, (nBytes +
|
||||
PMBusStackObject_getNumOfBytes(handle)));
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the WRITEWORD transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_WRITEWORD](handle);
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
|
||||
//
|
||||
// Set next state to IDLE
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_REQUEST = 0, DATA_READY = X, NACK = X
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_handler_target_block_write_process_call.c
|
||||
//
|
||||
// TITLE: PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(5)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetBlockWriteOrProcessCallStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetBlockWriteOrProcessCallStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = 0U;
|
||||
|
||||
|
||||
//
|
||||
// Set the current state to block write/Process Call
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle,
|
||||
PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
|
||||
if((status & PMBUS_PMBSTS_EOM) != 0U)
|
||||
{
|
||||
//
|
||||
// EOM = 1
|
||||
//
|
||||
if((status & PMBUS_PMBSTS_DATA_READY) != 0U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT != 0, EOM = 1, DATA_READY = 1, DATA_REQUEST = 0
|
||||
// This must be the last few bytes of the block write command
|
||||
// or an extended write byte/word command
|
||||
//
|
||||
|
||||
//
|
||||
// Start saving data in the buffer from the currPtr position
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, (nBytes +
|
||||
PMBusStackObject_getNumOfBytes(handle)));
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_BLOCKWRITE);
|
||||
|
||||
//
|
||||
// Call the handler for the BLOCKWRITE transaction
|
||||
//
|
||||
handle->transactionHandle[PMBUS_TRANSACTION_BLOCKWRITE](handle);
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Set the next state to PMBUS_STACK_STATE_IDLE
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 0, EOM = 1, DATA_READY = 0, DATA_REQUEST = 0
|
||||
// End-of-message, no data ready, no data requested, no bytes
|
||||
// received. This must be a write word command
|
||||
//
|
||||
|
||||
//
|
||||
//ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the WRITEWORD transaction
|
||||
//
|
||||
handle->transactionHandle[PMBUS_TRANSACTION_WRITEWORD](handle);
|
||||
|
||||
//
|
||||
// Set the next state to PMBUS_STACK_STATE_IDLE
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// EOM = 0
|
||||
//
|
||||
if((status & PMBUS_PMBSTS_DATA_READY) != 0U)
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_READY = 1 RD_BYTE_COUNT = ?
|
||||
// Start saving data in the buffer from the currPtr position
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, (nBytes +
|
||||
PMBusStackObject_getNumOfBytes(handle)));
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Stay in the same state, i.e.
|
||||
// PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL
|
||||
//
|
||||
}
|
||||
else if ((status & PMBUS_PMBSTS_DATA_REQUEST) != 0U)
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_READY = 0 RD_BYTE_COUNT = 0, DATA_REQUEST = 1
|
||||
// This is a Block Write, Read, Process Call
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_BLOCKWRPC);
|
||||
|
||||
//
|
||||
// Call the handler for the BLOCKWRPC transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_BLOCKWRPC](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Rewind the buffer pointer
|
||||
//
|
||||
buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
|
||||
if(nBytes <= 4U)
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, nBytes, true);
|
||||
}
|
||||
else // nBytes > 4
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, without PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, 4U, false);
|
||||
|
||||
//
|
||||
// Update the current index into the buffer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[4U]);
|
||||
}
|
||||
//
|
||||
// Proceed to the READ_BLOCK state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_READ_BLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_READY = ? RD_BYTE_COUNT = ?, DATA_REQUEST = 0
|
||||
// A Fault condition
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+449
@@ -0,0 +1,449 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_handler_target_idle.c
|
||||
//
|
||||
// TITLE: PMBUS_STACK_STATE_IDLE handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(3)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetIdleStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetIdleStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = 0U;
|
||||
uint16_t *currentPointer;
|
||||
|
||||
//
|
||||
// Set the current state to idle
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
//
|
||||
// Rewind the current pointer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, buffer);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_NONE);
|
||||
|
||||
//
|
||||
// Check if the unit is busy
|
||||
//
|
||||
if((status & PMBUS_PMBSTS_UNIT_BUSY) == 0U)
|
||||
{
|
||||
//
|
||||
// Neither PMBUS hardware nor firmware are stuck,
|
||||
//
|
||||
// The user must use the clock low timeout feature to
|
||||
// fire an interrupt off to the CPU, query the comms
|
||||
// stack object, take remedial measures and reset
|
||||
// the state machine prior to returning from the interrupt
|
||||
//
|
||||
}
|
||||
|
||||
if((status & PMBUS_PMBSTS_DATA_READY) != 0U)
|
||||
{
|
||||
if((status & PMBUS_PMBSTS_EOM) != 0U)
|
||||
{
|
||||
//
|
||||
// EOM = 1, DATA_READY = 1
|
||||
//
|
||||
if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) == 2U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 2, EOM = 1, DATA_READY = 1
|
||||
// Send Byte (Receive buffer has Byte #0, PEC)
|
||||
//
|
||||
|
||||
//
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_SENDBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the SENDBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_SENDBYTE](handle);
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
}
|
||||
else if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) == 3U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 3, EOM = 1, DATA_READY = 1
|
||||
// Write Byte (Receive buffer has Command, Byte #0, PEC)
|
||||
//
|
||||
|
||||
//
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_WRITEBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the WRITEBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_WRITEBYTE](handle);
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 1, EOM = 1, DATA_READY = 1
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// EOM = 0, DATA_READY = 1
|
||||
//
|
||||
if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) >= 3U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 3/4, EOM = 0, DATA_READY = 1
|
||||
// Read buffer is full, this must either be a write word,
|
||||
// block write or process call
|
||||
//
|
||||
// Read the RXBUF, ack the transaction and then proceed
|
||||
// to the BLOCK_WRITE_OR_PROCESS_CALL state
|
||||
//
|
||||
// Read the data
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
currentPointer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
¤tPointer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Set the next state to
|
||||
// PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL
|
||||
//
|
||||
PMBusStackObject_setNextState(handle,
|
||||
PMBUS_STACK_STATE_BLOCK_WRITE_OR_PROCESS_CALL);
|
||||
}
|
||||
else if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) == 2U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 2, EOM = 0, DATA_READY = 1
|
||||
// This must be either an extended
|
||||
// - Read Byte
|
||||
// - Read Word
|
||||
// - Write Byte
|
||||
// - Write Word
|
||||
//
|
||||
|
||||
//
|
||||
// Read the command
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// Check the first byte for the extended command byte
|
||||
//
|
||||
PMBUS_STACK_ASSERT((buffer[0] ==
|
||||
PMBUS_CMD_MFR_SPECIFIC_COMMAND) ||
|
||||
(buffer[0] == PMBUS_CMD_PMBUS_COMMAND_EXT));
|
||||
|
||||
//
|
||||
// Set the pointer in the buffer to point to the next
|
||||
// available spot
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
&buffer[nBytes]);
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, nBytes);
|
||||
|
||||
//
|
||||
// ACK the command for the target to be able to proceed
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Transition to the state PMBUS_STACK_STATE_EXTENDED_COMMAND
|
||||
//
|
||||
PMBusStackObject_setNextState(handle,
|
||||
PMBUS_STACK_STATE_EXTENDED_COMMAND);
|
||||
}
|
||||
else if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) == 1U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 1, EOM = 0, DATA_READY = 1
|
||||
// This could be either a
|
||||
// - Read Byte
|
||||
// - Read Word
|
||||
// - Block Read
|
||||
// The command determines which read transaction is being
|
||||
// requested by the controller. We need to wait for DATA_REQUEST
|
||||
// to come in
|
||||
//
|
||||
|
||||
//
|
||||
// Read the command
|
||||
//
|
||||
nBytes = PMBus_getTargetData(base, buffer, status);
|
||||
|
||||
//
|
||||
// ACK the command, for the controller to be able to issue
|
||||
// the repeated start, and therby the DATA_REQUEST interrupt
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Transition to the state PMBUS_STATE_READ_WAIT_FOR_EOM
|
||||
//
|
||||
PMBusStackObject_setNextState(handle,
|
||||
PMBUS_STACK_STATE_READ_WAIT_FOR_EOM);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0
|
||||
//
|
||||
if((status & PMBUS_PMBSTS_EOM) == 0U)
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0, EOM = 0
|
||||
//
|
||||
if((status & PMBUS_PMBSTS_DATA_REQUEST) != 0U)
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0, EOM = 0, DATA_REQUEST = 1
|
||||
// This is a receive byte request
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_RECEIVEBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the RECEIVEBYTE transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_RECEIVEBYTE](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, nBytes, true);
|
||||
|
||||
//
|
||||
// Transition to the RECEIVE_BYTE_WAIT_FOR_EOM
|
||||
//
|
||||
PMBusStackObject_setNextState(handle,
|
||||
PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0, EOM = 0, DATA_REQUEST = 0
|
||||
// Unhandled Exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0 EOM = 1
|
||||
//
|
||||
if((status & PMBUS_PMBSTS_DATA_REQUEST) != 0U)
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0, EOM = 1, DATA_REQUEST = 1
|
||||
// Unhandled Exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
|
||||
}
|
||||
else if (((status & PMBUS_PMBSTS_NACK) != 0U) &&
|
||||
((status & PMBUS_PMBSTS_ALERT_EDGE) != 0U))
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0, EOM = 1, NACK = 1, ALERT_EDGE = 1
|
||||
// This is an alert response
|
||||
// ACK the transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
}
|
||||
else if(((status & PMBUS_PMBSTS_RD_BYTE_COUNT_M) >>
|
||||
PMBUS_PMBSTS_RD_BYTE_COUNT_S) == 0U)
|
||||
{
|
||||
//
|
||||
// RD_BYTE_COUNT = 0, EOM = 1, DATA_READY = 0, NACK = 0
|
||||
// Quick Command
|
||||
//
|
||||
|
||||
//
|
||||
// Set the object's nBytes field
|
||||
//
|
||||
PMBusStackObject_setNumOfBytes(handle, 0U);
|
||||
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle,
|
||||
PMBUS_TRANSACTION_QUICKCOMMAND);
|
||||
|
||||
//
|
||||
// Call the handler for the QUCIKCOMMAND transaction
|
||||
//
|
||||
(void)handle->
|
||||
transactionHandle[PMBUS_TRANSACTION_QUICKCOMMAND](handle);
|
||||
|
||||
//
|
||||
// ACK the entire transaction
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0, EOM = 1, DATA_REQUEST = 0,
|
||||
// RD_BYTE_COUNT != 0
|
||||
// Unhandled Exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_handler_target_read_block.c
|
||||
//
|
||||
// TITLE: PMBUS_STACK_STATE_READ_BLOCK handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(4)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetReadBlockStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetReadBlockStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
|
||||
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
uint16_t *currentPointer;
|
||||
uint16_t bytesTransmitted = 0U;
|
||||
uint16_t bytesToTransmit = 0U;
|
||||
|
||||
//
|
||||
// Set the current state to READ_BLOCK
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_READ_BLOCK);
|
||||
|
||||
if(((status & PMBUS_PMBSTS_EOM) != 0U) &&
|
||||
((status & PMBUS_PMBSTS_NACK) != 0U))
|
||||
{
|
||||
//
|
||||
// EOM = 1, NACK = 1
|
||||
// Controller has prematurely terminated the block read,
|
||||
// or in the READ/WAIT_FOR_EOM state, only 4 bytes
|
||||
// were required to be sent, and the transaction was complete
|
||||
// NOTE: ACK is required to allow the target to ack its address in
|
||||
// any subsequent transaction.
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Return to the idle state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
}
|
||||
else if((status & PMBUS_PMBSTS_DATA_REQUEST) != 0U)
|
||||
{
|
||||
//
|
||||
// DATA_REQUEST = 1, EOM = 0, NACK = 0
|
||||
//
|
||||
currentPointer = PMBusStackObject_getCurrentPositionPointer(handle);
|
||||
bytesTransmitted = (uint16_t)(currentPointer - buffer);
|
||||
bytesToTransmit = nBytes - bytesTransmitted;
|
||||
|
||||
if(bytesToTransmit > 4U)
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, without PEC
|
||||
//
|
||||
PMBus_putTargetData(base, currentPointer, 4U, false);
|
||||
|
||||
//
|
||||
// Update the current index into the buffer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle,
|
||||
¤tPointer[4U]);
|
||||
}
|
||||
else //bytesToTransmit <= 4U (the last transmission)
|
||||
{
|
||||
//
|
||||
// Put the last few bytes (<=4) to the PMBUS Transmit buffer,
|
||||
// with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, currentPointer, bytesToTransmit, true);
|
||||
|
||||
//
|
||||
// Return to the EOM State
|
||||
//
|
||||
PMBusStackObject_setNextState(handle,
|
||||
PMBUS_STACK_STATE_READ_WAIT_FOR_EOM);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_handler_target_read_wait_for_eom.c
|
||||
//
|
||||
// TITLE: PMBUS_STACK_STATE_READ_WAIT_FOR_EOM handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(6)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetReadWaitForEOMStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetReadWaitForEOMStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
uint16_t nBytes = 0U;
|
||||
uint16_t command = buffer[0U];
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Set the current state to Read/Wait for EOM
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle,
|
||||
PMBUS_STACK_STATE_READ_WAIT_FOR_EOM);
|
||||
|
||||
if(((status & PMBUS_PMBSTS_EOM) != 0U) &&
|
||||
((status & PMBUS_PMBSTS_NACK) != 0U))
|
||||
{
|
||||
//
|
||||
// EOM = 1, NACK = 1
|
||||
// NOTE: ACK is required to allow the target to ack its address in
|
||||
// any subsequent transaction.
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Read byte/word/block was successful, return to the
|
||||
// Idle state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
}
|
||||
//
|
||||
// At this point the command is already in the buffer
|
||||
//
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_READBYTE))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_READBYTE);
|
||||
|
||||
//
|
||||
// Call the handler for the READBYTE transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READBYTE](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, nBytes, true);
|
||||
}
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_READWORD))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_READWORD);
|
||||
|
||||
//
|
||||
// Call the handler for the READWORD transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_READWORD](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, nBytes, true);
|
||||
}
|
||||
else if(PMBusStackObject_isCommandAndTransactionValid(command,
|
||||
PMBUS_TRANSACTION_BLOCKREAD))
|
||||
{
|
||||
//
|
||||
// Set the object transaction type
|
||||
//
|
||||
PMBusStackObject_setTransactionType(handle, PMBUS_TRANSACTION_BLOCKREAD);
|
||||
|
||||
//
|
||||
// Call the handler for the READBLOCK transaction
|
||||
//
|
||||
(void)handle->transactionHandle[PMBUS_TRANSACTION_BLOCKREAD](handle);
|
||||
|
||||
//
|
||||
// Get the number of bytes to transfer, buffer pointer
|
||||
//
|
||||
nBytes = PMBusStackObject_getNumOfBytes(handle);
|
||||
|
||||
if(nBytes <= 4U)
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, with PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, nBytes, true);
|
||||
}
|
||||
else // nBytes > 4
|
||||
{
|
||||
//
|
||||
// Put the data to the PMBUS Transmit buffer, without PEC
|
||||
//
|
||||
PMBus_putTargetData(base, buffer, 4U, false);
|
||||
|
||||
//
|
||||
// Update the current index into the buffer
|
||||
//
|
||||
PMBusStackObject_setCurrentPositionPointer(handle, &buffer[4U]);
|
||||
}
|
||||
//
|
||||
// Proceed to the READ_BLOCK state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_READ_BLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: pmbus_stack_handler_target_receive_byte_wait_for_eom.c
|
||||
//
|
||||
// TITLE: PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM handler
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
//! Copyright: Copyright (C) 2023 Texas Instruments Incorporated -
|
||||
//! All rights reserved not granted herein.
|
||||
//! Limited License.
|
||||
//!
|
||||
//! Texas Instruments Incorporated grants a world-wide, royalty-free,
|
||||
//! non-exclusive license under copyrights and patents it now or hereafter
|
||||
//! owns or controls to make, have made, use, import, offer to sell and sell
|
||||
//! ("Utilize") this software subject to the terms herein. With respect to the
|
||||
//! foregoing patent license, such license is granted solely to the extent that
|
||||
//! any such patent is necessary to Utilize the software alone. The patent
|
||||
//! license shall not apply to any combinations which include this software,
|
||||
//! other than combinations with devices manufactured by or for TI
|
||||
//! ("TI Devices").
|
||||
//! No hardware patent is licensed hereunder.
|
||||
//!
|
||||
//! Redistributions must preserve existing copyright notices and reproduce this
|
||||
//! license (including the above copyright notice and the disclaimer and
|
||||
//! (if applicable) source code license limitations below) in the documentation
|
||||
//! and/or other materials provided with the distribution.
|
||||
//!
|
||||
//! Redistribution and use in binary form, without modification, are permitted
|
||||
//! provided that the following conditions are met:
|
||||
//!
|
||||
//! * No reverse engineering, decompilation, or disassembly of this software is
|
||||
//! permitted with respect to any software provided in binary form.
|
||||
//! * Any redistribution and use are licensed by TI for use only
|
||||
//! with TI Devices.
|
||||
//! * Nothing shall obligate TI to provide you with source code for the
|
||||
//! software licensed and provided to you in object code.
|
||||
//!
|
||||
//! If software source code is provided to you, modification and redistribution
|
||||
//! of the source code are permitted provided that the following conditions
|
||||
//! are met:
|
||||
//!
|
||||
//! * any redistribution and use of the source code, including any resulting
|
||||
//! derivative works, are licensed by TI for use only with TI Devices.
|
||||
//! * any redistribution and use of any object code compiled from the source
|
||||
//! code and any resulting derivative works, are licensed by TI for use
|
||||
//! only with TI Devices.
|
||||
//!
|
||||
//! Neither the name of Texas Instruments Incorporated nor the names of its
|
||||
//! suppliers may be used to endorse or promote products derived from this
|
||||
//! software without specific prior written permission.
|
||||
//#############################################################################
|
||||
|
||||
#ifndef PMBUS_OVER_I2C
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
#include "pmbus_stack_handler.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
PMBUS_STACK_FILENUM(7)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PMBusStack_targetReceiveByteWaitForEOMStateHandler
|
||||
//
|
||||
//*****************************************************************************
|
||||
void PMBusStack_targetReceiveByteWaitForEOMStateHandler(PMBus_StackHandle handle)
|
||||
{
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint32_t status = PMBusStackObject_getModuleStatus(handle);
|
||||
uint16_t *buffer = PMBusStackObject_getBufferPointer(handle);
|
||||
uint32_t base = PMBusStackObject_getModuleBase(handle);
|
||||
|
||||
//
|
||||
// Set the current state to RECEIVE_BYTE_WAIT_FOR_EOM
|
||||
//
|
||||
PMBusStackObject_setCurrentState(handle,
|
||||
PMBUS_STACK_STATE_RECEIVE_BYTE_WAIT_FOR_EOM);
|
||||
|
||||
if(((status & PMBUS_PMBSTS_EOM) != 0U) &&
|
||||
((status & PMBUS_PMBSTS_NACK) != 0U))
|
||||
{
|
||||
//
|
||||
// DATA_READY = 0, EOM = 1, DATA_REQUEST = 0, NACK = 1
|
||||
// After a DATA_REQUEST for a receive byte is seen by the target,
|
||||
// it places the requested byte (and PEC) on the line and transitions
|
||||
// from the idle to the recevie byte wait-for-eom state
|
||||
//
|
||||
// The only interrupt expected after the recevied byte is that from an
|
||||
// EOM. The quick command also has EOM=1 and DATA_READY=0 at the end.
|
||||
// In order to distinguish between the two, if an EOM is received while
|
||||
// in this state it was a receive byte, if an EOM was recevied in the
|
||||
// idle state it was a quick command
|
||||
//
|
||||
// NOTE: ACK is required to allow the target to ack its address in
|
||||
// any subsequent transaction.
|
||||
//
|
||||
PMBus_ackTransaction(base);
|
||||
|
||||
//
|
||||
// Return to the idle state
|
||||
//
|
||||
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Unhandled Exception
|
||||
//
|
||||
PMBUS_STACK_ASSERT(0);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
Reference in new issue
Block a user