Skip to content

Commit

Permalink
Merge pull request #455 from Luos-io/fix/phy_nbr
Browse files Browse the repository at this point in the history
Fix the number of allocated phy assertion
  • Loading branch information
nicolas-rabault authored Dec 13, 2023
2 parents 7773eb2 + e8db62c commit 1fd114b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
22 changes: 11 additions & 11 deletions engine/IO/src/luos_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ typedef struct __attribute__((__packed__))
typedef struct
{
// ******************** Phy management ********************
luos_phy_t phy[PHY_NB]; // phy[0] is the local phy, phy[1] is the remote phy.
uint8_t phy_nb; // Number of phy instantiated in the phy_ctx.phy array.
IRQ_STATE phy_irq_states[PHY_NB]; // Store the irq state functions of phys aving one.
luos_phy_t phy[LOCAL_PHY_NB + 1]; // phy[0] is the local phy, phy[1] is the remote phy.
uint8_t phy_nb; // Number of phy instantiated in the phy_ctx.phy array.
IRQ_STATE phy_irq_states[LOCAL_PHY_NB + 1]; // Store the irq state functions of phys aving one.

// ******************** Topology management ********************
port_t topology_source; // The source port. Where we receive the topological detection signal from.
Expand Down Expand Up @@ -137,7 +137,7 @@ void Phy_Reset(void)
memset((void *)phy_ctx.failed_job, 0, sizeof(phy_ctx.failed_job));
phy_ctx.failed_job_nb = 0;
phy_ctx.resetAllNeed = false;
for (uint8_t i = 0; i < PHY_NB; i++)
for (uint8_t i = 0; i <= LOCAL_PHY_NB; i++)
{
Luos_SetIrqState(false);
memset((void *)&phy_ctx.phy[i].job, 0, sizeof(phy_ctx.phy[0].job));
Expand Down Expand Up @@ -241,7 +241,7 @@ void Phy_Loop(void)
******************************************************************************/
luos_phy_t *Phy_Create(JOB_CB job_cb, RUN_TOPO run_topo, RESET_PHY reset_phy)
{
LUOS_ASSERT(phy_ctx.phy_nb < PHY_NB);
LUOS_ASSERT(phy_ctx.phy_nb <= LOCAL_PHY_NB);
return Phy_Get(phy_ctx.phy_nb++, job_cb, run_topo, reset_phy);
}

Expand All @@ -256,7 +256,7 @@ void Phy_SetIrqStateFunciton(IRQ_STATE irq_state)
while (phy_ctx.phy_irq_states[i] != NULL)
{
i++;
if (i >= PHY_NB)
if (i > LOCAL_PHY_NB)
{
// We exceed the number of phy
LUOS_ASSERT(0);
Expand All @@ -280,7 +280,7 @@ void Phy_SetIrqState(bool state)
{
phy_ctx.phy_irq_states[i](state);
i++;
if (i >= PHY_NB)
if (i > LOCAL_PHY_NB)
{
// We exceed the number of phy
LUOS_ASSERT(0);
Expand Down Expand Up @@ -440,7 +440,7 @@ port_t *Phy_GetTopologysource(void)
******************************************************************************/
luos_phy_t *Phy_Get(uint8_t id, JOB_CB job_cb, RUN_TOPO run_topo, RESET_PHY reset_phy)
{
LUOS_ASSERT((id <= PHY_NB)
LUOS_ASSERT((id <= LOCAL_PHY_NB)
&& (job_cb != NULL)
&& (run_topo != NULL));
// Set the callbacks
Expand Down Expand Up @@ -471,7 +471,7 @@ void Phy_DisableSynchro(luos_phy_t *phy_ptr)
******************************************************************************/
luos_phy_t *Phy_GetPhyFromId(uint8_t phy_id)
{
LUOS_ASSERT(phy_id <= PHY_NB);
LUOS_ASSERT(phy_id <= LOCAL_PHY_NB);
return &phy_ctx.phy[phy_id];
}

Expand Down Expand Up @@ -1093,7 +1093,7 @@ inline int Phy_GetJobId(luos_phy_t *phy_ptr, phy_job_t *job)
inline int Phy_GetPhyId(luos_phy_t *phy_ptr)
{
LUOS_ASSERT((phy_ptr >= phy_ctx.phy)
&& (phy_ptr < &phy_ctx.phy[PHY_NB]));
&& (phy_ptr <= &phy_ctx.phy[LOCAL_PHY_NB]));
return ((uintptr_t)phy_ptr - (uintptr_t)phy_ctx.phy) / sizeof(luos_phy_t);
}

Expand Down Expand Up @@ -1176,7 +1176,7 @@ error_return_t Phy_TxAllComplete(void)
******************************************************************************/
void Phy_FiltersInit(void)
{
for (int i = 0; i < PHY_NB; i++)
for (int i = 0; i <= LOCAL_PHY_NB; i++)
{
// Service ID init
memset(phy_ctx.phy[i].services, 0, sizeof(phy_ctx.phy[i].services));
Expand Down
2 changes: 0 additions & 2 deletions engine/engine_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#define LOCAL_PHY_NB 1 // The number of phy layer in the node, by default we have only Luos engine + 1 phy layer
#endif

#define PHY_NB (LOCAL_PHY_NB + 1) // The total number of phy layer in the node including Luos engine

#ifdef MAX_RTB_ENTRY
#error 'MAX_RTB_ENTRY' configuration is deprecated and have been replaced by MAX_NODE_NUMBER and MAX_SERVICE_NUMBER. MAX_RTB_ENTRY is now automatically calculated by the engine based on these values.
#endif
Expand Down
2 changes: 2 additions & 0 deletions examples/projects/l0/button/node_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#define MAX_LOCAL_SERVICE_NUMBER 1
#define MAX_LOCAL_PROFILE_NUMBER 1
#define MAX_MSG_NB 10
#define LOCAL_PHY_NB 2
#define NO_RTB

/*******************************************************************************
* LUOS HAL LIBRARY DEFINITION
Expand Down
1 change: 1 addition & 0 deletions examples/projects/l0/controller_motor/node_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#define MAX_LOCAL_PROFILE_NUMBER 2
#define MAX_MSG_NB 30
#define MSG_BUFFER_SIZE 1024
#define NO_RTB

/*******************************************************************************
* LUOS HAL LIBRARY DEFINITION
Expand Down
4 changes: 2 additions & 2 deletions test/tests_io/test_phy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ void unittest_phy_GetPhyId()

TRY
{
int value = Phy_GetPhyId(&phy_ctx.phy[PHY_NB]);
int value = Phy_GetPhyId(&phy_ctx.phy[LOCAL_PHY_NB + 1]);
}
TEST_ASSERT_TRUE(IS_ASSERT());
END_TRY;
Expand All @@ -1720,7 +1720,7 @@ void unittest_phy_GetPhyId()
{
TRY
{
for (int i = 0; i < PHY_NB; i++)
for (int i = 0; i <= LOCAL_PHY_NB; i++)
{
int value = Phy_GetPhyId(&phy_ctx.phy[i]);
TEST_ASSERT_EQUAL(i, value);
Expand Down

0 comments on commit 1fd114b

Please sign in to comment.