Skip to content

Decouple stse_init() into Platform, Bus, and Device Initialization #104

Description

@parmi93

The stse_init() API currently performs the same initialization steps every time it is called.

At the moment, stse_init() invokes the following functions for every STSAFE device being initialized:

  • stse_platform_i2c_init() or stse_platform_st1wire_init()
  • stse_platform_generate_random_init()
  • stse_platform_delay_init()
  • stse_platform_power_init()
  • stse_device_power_on()
  • stse_platform_crc16_init()
  • stse_platform_crypto_init()
  • stsafea_perso_info_update()

However, several of these initialization steps are not device-specific. A cleaner approach would be to split the initialization process into three distinct phases: platform initialization, bus initialization, and device initialization. This could be achieved by introducing the following APIs:

  1. stse_ReturnCode_t stse_init_platform(void *pArg);

    This function would internally call:

    • stse_platform_generate_random_init(pArg)
    • stse_platform_delay_init(pArg)
    • stse_platform_power_init(pArg)
    • stse_platform_crc16_init(pArg)
    • stse_platform_crypto_init(pArg)
  2. stse_ReturnCode_t stse_init_bus(stse_io_t *io, void *pArg);

    This function would initialize the communication bus by calling either:

    • stse_platform_i2c_init(io->busID, pArg), or
    • stse_platform_st1wire_init(io->busID, pArg)

    depending on the value of io->BusType.

  3. stse_ReturnCode_t stse_init_device(stse_Handle_t *pSTSE, stse_io_t *io, void *pArg);

    This function would:

    • associate the communication interface with the device handle by assigning pSTSE->io = io (store the pointer rather than copying the entire stse_io_t structure);
    • call stse_device_power_on(pSTSE);
    • call stsafea_perso_info_update(pSTSE).

Splitting the initialization into these three phases also avoids repeatedly invoking the platform and bus initialization routines every time a new device is initialized, preventing unnecessary attempts to reinitialize components that have already been initialized.

In addition, this design would allow reducing the size of stse_Handle_t. Currently, each device handle contains its own copy of stse_io_t io. Replacing this with a pointer (stse_io_t *io) would avoid duplicating the bus configuration for every device and reduce the size of stse_Handle_t by approximately 51 bytes on 32-bit platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions