本帖最后由 hzocce 于 2020-4-4 16:04 编辑
按理应该是:
PMBus_Init();
PMBus_SendByte();
PMbus_RecByte();
可是为什么找不到呢?
----------------------------------------------------------------------------------------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----------------------------------------------------------------------------------------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "main.h"
#include "stm32_PMBUS_stack.h"
/** @addtogroup STM32F3xx_HAL_Examples
* @{
*/
/** @addtogroup SMBUS
* @{
*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#ifdef ARP
#ifdef HOST1
static uint32_t ARP_process = 0U;
#else /* HOST1 */
static uint8_t UDID[16] =
{
0x81, 0x23, 0x45, 0x67, 0x78, 0x91, 0xBC, 0xDE, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#endif /* HOST1 */
#ifdef SMB2
static uint8_t UDID2[16] =
{
0x81, 0x23, 0x45, 0x67, 0x78, 0x97, 0xBC, 0xDE, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#endif /* SMB2 */
#endif /* ARP */
#ifdef TEST4
#ifdef HOST1
static uint8_t TEST_PLAN[8] =
{
0x25, 0x1A, 0x10, 0x78, 0x90, 0x14, 0x3D, 0x65
};
#endif /* HOST1 */
#endif /* TEST4 */
uint32_t buttonpress = 0U;
SMBUS_HandleTypeDef handle1, handle2;
uint8_t deviceList[MAX_DEVICE_NUM];
/* Private function prototypes -----------------------------------------------*/
static void SystemClock_Config(void);
static void Error_Handler(void);
static void Error_Check( SMBUS_StackHandleTypeDef *pStackContext);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Callback function notifying about extended command incoming, implementation
is supporting extended command defined by PMBus
* @param pStackContext : Pointer to a SMBUS_StackHandleTypeDef structure that contains
* the configuration information for the specified SMBUS.
* @retval HAL_StatusTypeDef response code. Equal STACK_OK if success, any other value means problem
*/
HAL_StatusTypeDef STACK_SMBUS_ExtendCommand( SMBUS_StackHandleTypeDef *pStackContext )
{
uint16_t size = 0U;
uint8_t *piobuf = NULL;
/* accessing the IO buffer */
piobuf = STACK_SMBUS_GetBuffer( pStackContext );
/*
Extended command must be identified by the value of the actual command code
*/
switch ( piobuf[0] )
{
case 0:
pStackContext->CurrentCommand = (st_command_t *) & EXTENDED_READ_BYTE;
break;
case 1:
pStackContext->CurrentCommand = (st_command_t *) & EXTENDED_READ_WORD;
break;
case 2:
pStackContext->CurrentCommand = (st_command_t *) & EXTENDED_WRITE_BYTE;
/*
size of the bytes yet to be received
*/
size = 1U;
break;
case 3:
pStackContext->CurrentCommand = (st_command_t *) & EXTENDED_WRITE_WORD;
size = 2U;
break;
default:
pStackContext->StateMachine |= SMBUS_SMS_ERROR;
return STACK_ERROR;
}
/*
reading the remaining data (stack won't do that for us this time
*/
if ((pStackContext->CurrentCommand->cmnd_query & WRITE) == WRITE )
{
/*
To make sure the executecommand is called again once the remaining data
is in the buffer
*/
STACK_PMBUS_ExtendExecution(pStackContext);
/*
PEC byte y/n?
*/
if ((pStackContext->StateMachine & SMBUS_SMS_PEC_ACTIVE ) == SMBUS_SMS_PEC_ACTIVE )
{
size += PEC_SIZE;
}
/*
asking the HAL for more bytes to receive
*/
pStackContext->Byte_count += size;
HAL_SMBUS_Slave_Receive_IT( pStackContext->Device, &(pStackContext->Buffer[2]), size, SMBUS_NEXT_FRAME );
}
return STACK_OK;
}
/**
* @brief Callback function notifying slave about command incoming, implementation
is supporting extended command defined by PMBus
* @param pStackContext : Pointer to a SMBUS_StackHandleTypeDef structure that contains
* the configuration information for the specified SMBUS.
* @retval HAL_StatusTypeDef response code. Equal STACK_OK if success, any other value means problem
*/
HAL_StatusTypeDef STACK_SMBUS_ExecuteCommand( SMBUS_StackHandleTypeDef *pStackContext )
{
uint8_t *piobuf = NULL;
/* accessing the IO buffer */
piobuf = STACK_SMBUS_GetBuffer( pStackContext );
if ( piobuf == NULL )
{
pStackContext->StateMachine |= SMBUS_SMS_ERROR;
}
else if ( pStackContext->CurrentCommand == (st_command_t *)&HOST_NOTIFY_PROTOCOL )
{
/* host notify command */
if ( pStackContext->Buffer[0] == SMBUS_ADDR_DEFAULT )
{
/* Usually the Host notify is used for ARP, but may not be limited to it */
#ifdef ARP
#ifdef HOST1
/* case of ARP notify */
ARP_process = 1U;
#endif /* HOST1 */
#endif /* ARP */
}
}
else /* Normal device command execution */
{
/* Zone config command example implementation */
#ifdef PMBUS13
if ( pStackContext->CurrentCommand->cmnd_code == PMBC_ZONE_CONFIG )
{
pStackContext->TheZone.writeZone = pStackContext->Buffer[1];
pStackContext->TheZone.readZone = pStackContext->Buffer[2];
}
else if ( pStackContext->CurrentCommand->cmnd_code == PMBC_ZONE_ACTIVE )
{
pStackContext->TheZone.activeWriteZone = pStackContext->Buffer[1];
pStackContext->TheZone.activeReadZone = pStackContext->Buffer[2];
}
#endif /* PMBUS13 */
/*
first step is to see if we have a case of extended command
*/
if ( pStackContext->CurrentCommand->cmnd_code == PMBC_PMBUS_COMMAND_EXT )
{
BSP_LED_Toggle((Led_TypeDef)((piobuf[0] & 0x07U)));
}
else /* regular command case */
{
BSP_LED_Toggle((Led_TypeDef)(pStackContext->CurrentCommand->cmnd_code & 0x07U));
if ((pStackContext->CurrentCommand->cmnd_query & BLOCK ) == BLOCK )
{
*piobuf = (pStackContext->CurrentCommand->cmnd_master_Rx_size) - 1U;
/* byte size of reply for block read command */
/* One byte for size, rest are [size] of data */
}
}
}
return STACK_OK;
}
/**
* @brief Stub of an error treatment function - set to ignore most errors
* @param pStackContext : Pointer to a SMBUS_StackHandleTypeDef structure that contains
* the configuration information for the specified SMBUS.
* @retval None
*/
static void Error_Check( SMBUS_StackHandleTypeDef *pStackContext)
{
if ( ( STACK_SMBUS_IsBlockingError(pStackContext) ) || ( STACK_SMBUS_IsCmdError( pStackContext ) ) )
{
/* No action, error symptoms are ignored */
pStackContext->StateMachine &= ~(SMBUS_ERROR_CRITICAL | SMBUS_COM_ERROR);
}
else if ((pStackContext->StateMachine & SMBUS_SMS_ERR_PECERR ) ==
SMBUS_SMS_ERR_PECERR ) /* PEC error, we won't wait for any more action */
{
pStackContext->StateMachine |= SMBUS_SMS_READY;
pStackContext->CurrentCommand = NULL;
pStackContext->StateMachine &= ~(SMBUS_SMS_ACTIVE_MASK | SMBUS_SMS_ERR_PECERR);
}
}
/**
* @brief Main program - executes various test sequences
* @param None
* @retval None
*/
int main(void)
{
#ifdef HOST1
uint32_t commandi = 0U;
#ifdef TEST5
SMBUS_ZoneStateTypeDef TheZone;
#endif /* TEST5 */
#endif /* HOST1 */
uint8_t *piobuf;
SMBUS_HandleTypeDef *phandle1;
SMBUS_StackHandleTypeDef *pcontext1;
SMBUS_StackHandleTypeDef context1;
#ifdef SMB2
SMBUS_HandleTypeDef *phandle2;
SMBUS_StackHandleTypeDef *pcontext2;
SMBUS_StackHandleTypeDef context2;
#endif /* SMB2 */
uint32_t index;
/* Reset of all peripherals, Initializes the Flash interface and the systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Configure LEDs */
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
BSP_LED_Init(LED5);
BSP_LED_Init(LED6);
#ifdef STM32F303xC
BSP_LED_Init(LED7);
BSP_LED_Init(LED8);
BSP_LED_Init(LED9);
BSP_LED_Init(LED10);
#endif /*STM32F303xC*/
/* SMBUS instance initialization - smbus 1. */
handle1.Instance = SMBUS1;
handle1.Init.Timing = SMBUS_TIMING_100K;
handle1.Init.AnalogFilter = SMBUS_ANALOGFILTER_ENABLE;
handle1.Init.AddressingMode = SMBUS_ADDRESSINGMODE_7BIT;
#ifdef PMBUS13
handle1.Init.DualAddressMode = SMBUS_DUALADDRESS_ENABLE;
handle1.Init.OwnAddress2 = 0x40U;
handle1.Init.OwnAddress2Masks = SMBUS_OA2_MASK05;
#else /* PMBUS13 */
handle1.Init.DualAddressMode = SMBUS_DUALADDRESS_DISABLE;
handle1.Init.OwnAddress2 = 0U;
handle1.Init.OwnAddress2Masks = SMBUS_OA2_NOMASK;
#endif /* PMBUS13 */
handle1.Init.GeneralCallMode = SMBUS_GENERALCALL_DISABLE;
handle1.Init.NoStretchMode = SMBUS_NOSTRETCH_DISABLE;
#ifdef ARP
#ifdef DEV_PSA
handle1.Init.OwnAddress1 = SMBUS_ADDR_DEVICE;
#else /* DEV_PSA */
handle1.Init.OwnAddress1 = 0U;
#endif /* DEV_PSA */
handle1.Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP;
#else /* ARP */
handle1.Init.OwnAddress1 = SMBUS_ADDR_DEVICE;
handle1.Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE;
#endif /* ARP */
#ifdef USE_PEC
handle1.Init.PacketErrorCheckMode = SMBUS_PEC_ENABLE;
#else
handle1.Init.PacketErrorCheckMode = SMBUS_PEC_DISABLE;
#endif /* USE_PEC */
#ifdef HOST1
handle1.Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_HOST;
handle1.Init.OwnAddress1 = 0U;
#endif /* HOST1 */
handle1.Init.SMBusTimeout = SMBUS_TIMEOUT_DEFAULT;
handle1.pBuffPtr = context1.Buffer;
phandle1 = &handle1;
HAL_SMBUS_Init( phandle1 );
context1.CMD_table = (st_command_t *) & PMBUS_COMMANDS_TAB[0];
context1.CMD_tableSize = PMBUS_COMMANDS_TAB_SIZE;
#ifndef TEST4
#ifndef TEST5
/* Most tests do not use actual PMBUS commands */
context1.CMD_table = (st_command_t *) & PMBUS_COMMANDS_TEST[0];
context1.CMD_tableSize = PMBUS_CMD_TBL_SIZE;
#endif /* TEST4 */
#endif /* TEST5 */
context1.Device = phandle1;
context1.SRByte = 0x55U;
context1.CurrentCommand = NULL;
#ifdef ARP
context1.StateMachine = SMBUS_SMS_NONE;
#ifdef DEV_PSA
context1.OwnAddress = SMBUS_ADDR_DEVICE;
#else /* DEV_PSA */
context1.OwnAddress = 0U;
#endif /* DEV_PSA */
#ifndef HOST1
context1.ARP_UDID = (uint8_t *) &UDID;
#endif /* HOST1 */
#else /* ARP */
context1.StateMachine = SMBUS_SMS_ARP_AR;
context1.OwnAddress = SMBUS_ADDR_DEVICE;
#endif /* ARP */
#ifdef USE_PEC
context1.StateMachine |= SMBUS_SMS_PEC_ACTIVE;
#endif
pcontext1 = &context1;
STACK_SMBUS_Init( pcontext1 );
/* SMBUS instance initialization - smbus 2. */
#ifdef SMB2
handle2.Instance = SMBUS2;
handle2.Init.Timing = SMBUS_TIMING_100K;
handle2.Init.AnalogFilter = SMBUS_ANALOGFILTER_ENABLE;
handle2.Init.AddressingMode = SMBUS_ADDRESSINGMODE_7BIT ;
#ifdef PMBUS13
handle2.Init.DualAddressMode = SMBUS_DUALADDRESS_ENABLE;
handle2.Init.OwnAddress2 = 0x40U;
handle2.Init.OwnAddress2Masks = SMBUS_OA2_MASK05;
#else /* PMBUS13 */
handle2.Init.DualAddressMode = SMBUS_DUALADDRESS_DISABLE;
handle2.Init.OwnAddress2 = 0U;
handle2.Init.OwnAddress2Masks = SMBUS_OA2_NOMASK;
#endif /* PMBUS13 */
handle2.Init.GeneralCallMode = SMBUS_GENERALCALL_DISABLE;
handle2.Init.NoStretchMode = SMBUS_NOSTRETCH_DISABLE;
#ifdef ARP
#ifdef DEV_PSA
handle2.Init.OwnAddress1 = SMBUS_ADDR_DEVICE + 2U;
#else /* DEV_PSA */
handle2.Init.OwnAddress1 = 0U;
#endif /* DEV_PSA */
handle2.Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP ;
#else /* ARP */
handle2.Init.OwnAddress1 = SMBUS_ADDR_DEVICE + 2U;
handle2.Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE ;
#endif /* ARP */
#ifdef USE_PEC
handle2.Init.PacketErrorCheckMode = SMBUS_PEC_ENABLE;
#else
handle2.Init.PacketErrorCheckMode = SMBUS_PEC_DISABLE;
#endif /* USE_PEC */
handle2.Init.SMBusTimeout = SMBUS_TIMEOUT_DEFAULT;
handle2.pBuffPtr = context2.Buffer;
phandle2 = &handle2;
HAL_SMBUS_Init( phandle2 );
#ifdef TEST4
context2.CMD_table = (st_command_t *) & PMBUS_COMMANDS_TAB[0];
context2.CMD_tableSize = PMBUS_COMMANDS_TAB_SIZE;
#else /* TEST4 */
context2.CMD_table = (st_command_t *) & PMBUS_COMMANDS_TEST[0];
context2.CMD_tableSize = PMBUS_CMD_TBL_SIZE;
#endif /* TEST4 */
context2.Device = phandle2;
context2.SRByte = 0x55U;
context2.CurrentCommand = NULL;
#ifdef ARP
context2.StateMachine = SMBUS_SMS_NONE;
context2.ARP_UDID = (uint8_t *) & UDID2;
#ifdef DEV_PSA
context2.OwnAddress = SMBUS_ADDR_DEVICE + 2U;
#else /* DEV_PSA */
context2.OwnAddress = 0U;
#endif /* DEV_PSA */
#else /* ARP */
context2.StateMachine = SMBUS_SMS_ARP_AR;
context2.OwnAddress = SMBUS_ADDR_DEVICE + 2U;
#endif /* ARP */
#ifdef USE_PEC
context2.StateMachine |= SMBUS_SMS_PEC_ACTIVE;
#endif
pcontext2 = &context2;
STACK_SMBUS_Init( pcontext2 );
#endif /*SMB2*/
/* Configure the control */
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
piobuf = STACK_SMBUS_GetBuffer( pcontext1 );
if (piobuf != NULL )
{
for (index = 0U; index < STACK_NBYTE_SIZE; index++)
{
piobuf[index] = 0U;
}
}
#ifdef HOST1
while (1)
{
#ifdef ARP
if ( ARP_process == 1U)
{
for (index = 0U; index < 8U; index++)
{
deviceList[index] = 0U;
}
index = 0U;
/* sending ARP prepare */
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_ARP[0], SMBUS_ADDR_DEFAULT, WRITE);
while ( !STACK_SMBUS_IsReady(pcontext1))
{
Error_Check( pcontext1 );
}
ARP_process ++;
pcontext1->StateMachine &= ~SMBUS_SMS_ERR_ACKF ;
}
while (ARP_process == 2U)
{
/* send ARP getID */
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_ARP[2], SMBUS_ADDR_DEFAULT, READ);
while ( !STACK_SMBUS_IsReady(pcontext1))
{
Error_Check( pcontext1 );
}
if ((pcontext1->Buffer[2] != 0xFFU)
&& (( pcontext1->StateMachine & (SMBUS_SMS_ERR_ACKF | SMBUS_SMS_ERR_PECERR) ) == 0U)) /* not empty answer */
{
/* select a free address */
deviceList[index] = (uint8_t)(2U * index + 0x16U);
piobuf = STACK_SMBUS_GetBuffer( pcontext1 );
if (piobuf == NULL )
{
break;
}
piobuf[0] = 17U;
piobuf[17] = deviceList[index];
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_ARP[3], SMBUS_ADDR_DEFAULT, WRITE);
while ( !STACK_SMBUS_IsReady(pcontext1))
{
Error_Check( pcontext1 );
}
if (STACK_SMBUS_IsCmdError( pcontext1 ))
{
deviceList[index] = 0U;
}
else
{
index++;
index &= 7U;
}
/* Wait until Tamper push-button is pressed ########################*/
while (buttonpress == 0U)
{}
buttonpress = 0U;
}
else
{
pcontext1->StateMachine &= ~(SMBUS_SMS_ERR_PECERR | SMBUS_SMS_ERR_BTO);
ARP_process++;
}
}
#else /* ARP */
deviceList[0] = SMBUS_ADDR_DEVICE;
#endif /* ARP */
BSP_LED_On((Led_TypeDef)(commandi & 0x07U));
HAL_Delay( 250U );
#ifdef TEST5
if (deviceList[0] != 0U)
{
/* TEST5 - sending different Zone commands */
switch (commandi)
{
case 0:
TheZone.writeZone = 0x01U;
TheZone.readZone = 0x05U;
STACK_PMBUS_MasterZoneConfig(pcontext1, SMBUS_ADDR_DEVICE, &TheZone);
break;
case 1:
TheZone.activeWriteZone = 0x01U;
TheZone.activeReadZone = 0x05U;
STACK_PMBUS_MasterZoneActive(pcontext1, &TheZone);
break;
case 2:
pcontext1->Buffer[1] = 0x5aU;
STACK_PMBUS_MasterZoneWrite(pcontext1, (st_command_t *)&PMBUS_COMMANDS_TAB[13] );
break;
case 3:
STACK_PMBUS_MasterReadZoneStatus( pcontext1, 0x00U, 0xFFU);
break;
default:
commandi &= 3U;
break;
}
}
#else
#ifdef TEST4
if (deviceList[0] != 0U)
{
pcontext1->CMD_table = (st_command_t *) & PMBUS_COMMANDS_TAB[0];
/* Test plan is 8 records */
commandi &= 7U;
/* Testing selected PMBUS command codes */
index = TEST_PLAN[commandi];
/* buffer preparation */
if (PMBUS_COMMANDS_TAB[commandi].cmnd_query & BLOCK )
{
piobuf = STACK_SMBUS_GetBuffer( pcontext1 );
piobuf[0] = 5U;
}
/* Command issued */
if ( PMBUS_COMMANDS_TAB[index].cmnd_query & WRITE )
{
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_TAB[index], (uint16_t)deviceList[0], WRITE);
}
else if ( PMBUS_COMMANDS_TAB[index].cmnd_query & READ )
{
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_TAB[index], (uint16_t)deviceList[0], READ);
}
else
{
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_TAB[index], (uint16_t)deviceList[0], 0U);
}
}
#else /* TEST4 */
/* buffer preparation */
if ((PMBUS_COMMANDS_TEST[commandi].cmnd_query & BLOCK) == BLOCK )
{
piobuf = STACK_SMBUS_GetBuffer( pcontext1 );
if ( piobuf == NULL )
{
Error_Check( pcontext1 );
}
else
{
piobuf[0] = PMBUS_COMMANDS_TEST[commandi].cmnd_master_Tx_size - 2U;
}
}
if (deviceList[0] != 0U)
{
#ifdef TEST3
/* writing extended command code */
piobuf = STACK_SMBUS_GetBuffer( pcontext1 );
if ( piobuf == NULL )
{
Error_Check( pcontext1 );
}
else
{
piobuf[0] = (uint8_t)commandi;
}
/* issuing extended commands */
switch (commandi)
{
case 0:
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&EXTENDED_READ_BYTE, (uint16_t)deviceList[0], 0U);
break;
case 1:
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&EXTENDED_READ_WORD, (uint16_t)deviceList[0], 0U);
break;
case 2:
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&EXTENDED_WRITE_BYTE, (uint16_t)deviceList[0], WRITE);
break;
case 3:
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&EXTENDED_WRITE_WORD, (uint16_t)deviceList[0], WRITE);
break;
default:
commandi = 0U;
break;
}
#else /* TEST3 */
if (commandi == 0U)
{
#ifdef TEST2
/* command group test case */
for ( index = 0U; index < 4U; index++)
{
STACK_PMBUS_HostCommandGroup( pcontext1, (st_command_t *)&PMBUS_COMMANDS_TEST[commandi],
SMBUS_ADDR_DEFAULT + (uint16_t)index - 3U,
(index == 3U) ? 1U : 0U );
while
(
( pcontext1->Device->State != HAL_SMBUS_STATE_READY ) &&
( pcontext1->Device->State != HAL_SMBUS_STATE_LISTEN )
)
{}
}
/*
Note: the group command assumes presence of several devices. In their absence it fails to transmit successfully.
We then reset the stack error.
*/
pcontext1->StateMachine |= SMBUS_SMS_READY;
pcontext1->CurrentCommand = NULL;
pcontext1->StateMachine &= ~(SMBUS_SMS_ACTIVE_MASK | SMBUS_ERROR_CRITICAL);
#else /* TEST2 */
/* testing receive byte */
STACK_SMBUS_HostRead( pcontext1, &(context1.SRByte), (uint16_t)deviceList[0]);
#endif /* TEST2 */
}
/* issuing command from test table */
else if (( PMBUS_COMMANDS_TEST[commandi].cmnd_query & READ ) == READ )
{
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_TEST[commandi], (uint16_t)deviceList[0], READ);
}
else if (( PMBUS_COMMANDS_TEST[commandi].cmnd_query & PROCESS_CALL ) == PROCESS_CALL )
{
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_TEST[commandi], (uint16_t)deviceList[0], 0U);
}
else
{
STACK_SMBUS_HostCommand( pcontext1, (st_command_t *)&PMBUS_COMMANDS_TEST[commandi], (uint16_t)deviceList[0], WRITE);
}
#endif /* TEST3 */
}
#endif /* TEST4 */
#endif /* TEST5 */
while ( STACK_SMBUS_IsReady(pcontext1) != SMBUS_SMS_READY)
{
Error_Check( pcontext1 );
}
for (index = 0; index < 8; index++)
{
BSP_LED_Off((Led_TypeDef)index);
}
HAL_Delay( 750U );
if (buttonpress == 1U)
{
/* next test case */
commandi++;
if (commandi >= PMBUS_CMD_TBL_SIZE)
{
commandi = 0U;
}
buttonpress = 0U;
}
}
#else /* HOST1 */
#ifdef ARP
if ( ( context1.OwnAddress == 0U ) || ((context1.StateMachine & SMBUS_SMS_ARP_AR) == 0U ) )
{
STACK_SMBUS_NotifyHost( pcontext1 );
}
#ifdef SMB2
else if ( ( context2.OwnAddress == 0U ) || ((context2.StateMachine & SMBUS_SMS_ARP_AR) == 0U ) )
{
STACK_SMBUS_NotifyHost( pcontext2 );
}
#endif /* SMB2 */
#endif /* ARP */
while (1)
{
HAL_Delay( 200U );
/* Periodically checking error state of the stack */
Error_Check( &context1 );
/* Periodically checking for Quick command */
if ( context1.StateMachine & ( SMBUS_SMS_QUICK_CMD_W | SMBUS_SMS_QUICK_CMD_R ) )
{
BSP_LED_On((Led_TypeDef)0U);
context1.StateMachine &= ~( SMBUS_SMS_QUICK_CMD_W | SMBUS_SMS_QUICK_CMD_R );
}
#ifdef SMB2
Error_Check( &context2 );
if ( context2.StateMachine & ( SMBUS_SMS_QUICK_CMD_W | SMBUS_SMS_QUICK_CMD_R ) )
{
BSP_LED_On((Led_TypeDef)0U);
context2.StateMachine &= ~( SMBUS_SMS_QUICK_CMD_W | SMBUS_SMS_QUICK_CMD_R );
}
context2.StateMachine &= ~SMBUS_SMS_ERR_ARLO;
#endif /* SMB2 */
/* Dim the LED */
for (index = 0; index < 8; index++)
{
BSP_LED_Off((Led_TypeDef)index);
}
/* Cleaning arbitration loss flag */
context1.StateMachine &= ~SMBUS_SMS_ERR_ARLO;
if (buttonpress == 1U)
{
#ifdef ALERT
STACK_SMBUS_SendAlert( pcontext1 );
#else /* ALERT */
STACK_SMBUS_NotifyHost( pcontext1 );
#endif /* ALERT */
buttonpress = 0U;
}
}
#endif /* HOST1 */
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
static void Error_Handler(void)
{
/* User may add here some code to deal with this error */
while (1)
{}
}
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
* System Clock source | PLL (HSI)
* SYSCLK(Hz) | 48000000
* HCLK(Hz) | 48000000
* AHB Prescaler | 1
* APB2 Prescaler | 2
* APB1 Prescaler | 2
* HSI Frequency(Hz) | 8000000
* PLLMUL | 12
* PREDIV | 2
* USB Clock | DISABLE
* Flash Latency(WS) | 2
* Prefetch Buffer | OFF
* @param None
* @retval None
*/
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_PeriphCLKInitTypeDef RCC_Peri = {0};
/* Enable HSI Oscillator and activate PLL with HSI as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Set the I2C clock */
RCC_Peri.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
RCC_Peri.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
HAL_RCCEx_PeriphCLKConfig(&RCC_Peri);
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief EXTI line detection callbacks
* @param GPIO_Pin: Specifies the pins connected EXTI line
* @retval None
*/
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
buttonpress = 1U;
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
Error_Handler();
}
#endif
|