8.2.2. How to Use Generated Sources from HALCoGen

Note

A documentation of the tool HALCoGen can be found in HALCoGen tool documentation, the Waf tool wrapper for this project in HALCoGen and information on configuring HALCoGen in the context of the toolchain of this project in HALCoGen.

The following steps need to be applied:

  1. Removing the HALCoGen dependency in the compiler tool:

    • remove loading the the f_hcg tool in the configure step.

    • in the class search_swi(Task.Task) the class attribute after needs to be modified. Remove the entry hcg_compiler from the list.

  2. Adding the sources:

    • The generated HAL files need to be copied into the src/hal directory

    • The wscript in src/hal needs to be modified:

      Listing 8.48 Building the HAL library without using HALCoGen on the fly
       1def build(bld):
       2    """Build the HAL library"""
       3    source = [
       4        # list sources here, most likely something like 'source/abc.c',
       5        # 'source/abc.asm' etc.
       6    ]
       7    includes = [
       8        # list include directories here, most likely 'include'
       9    ]
      10    target = f"{bld.env.APPNAME.lower()}-hal"
      11    cflags = bld.env.CFLAGS_HAL
      12
      13    bld.stlib(
      14        source=source,
      15        includes=includes,
      16        cflags=cflags,
      17        target=target,
      18    )
      
    • Add the include directory in all wscript-files where needed. This will affect most wscript-files. This looks e.g., like this for a FreeRTOS and LTC6806 configuration:

      Listing 8.49 The diff of includes
       1diff --git a/src/app/application/algorithm/wscript b/src/app/application/algorithm/wscript
       2index c4d837c4..2d1580fa 100644
       3--- a/src/app/application/algorithm/wscript
       4+++ b/src/app/application/algorithm/wscript
       5@@ -77,6 +77,7 @@ def build(bld):
       6         os.path.join("..", "..", "main", "include"),
       7         os.path.join("..", "..", "task", "config"),
       8         os.path.join("..", "..", "task", "os"),
       9+        os.path.join("..", "..", "..", "hal", "include"),
      10     ]
      11     includes.extend(bld.env.INCLUDES_RTOS)
      12     cflags = bld.env.CFLAGS_FOXBMS
      13diff --git a/src/app/application/wscript b/src/app/application/wscript
      14index a9462e21..1fdb5850 100644
      15--- a/src/app/application/wscript
      16+++ b/src/app/application/wscript
      17@@ -88,6 +88,7 @@ def build(bld):
      18         os.path.join("..", "main", "include"),
      19         os.path.join("..", "task", "config"),
      20         os.path.join("..", "task", "os"),
      21+        os.path.join("..", "..", "hal", "include"),
      22     ]
      23     includes.extend(bld.env.INCLUDES_RTOS + bld.env.INCLUDES_AFE)
      24     cflags = bld.env.CFLAGS_FOXBMS
      25diff --git a/src/app/driver/afe/ltc/6806/wscript b/src/app/driver/afe/ltc/6806/wscript
      26index d7ca3af9..0cc6c777 100644
      27--- a/src/app/driver/afe/ltc/6806/wscript
      28+++ b/src/app/driver/afe/ltc/6806/wscript
      29@@ -71,6 +71,7 @@ def build(bld):
      30         os.path.join("..", "..", "..", "..", "engine", "diag"),
      31         os.path.join("..", "..", "..", "..", "main", "include"),
      32         os.path.join("..", "..", "..", "..", "task", "os"),
      33+        os.path.join("..", "..", "..", "..", "..", "hal", "include"),
      34     ]
      35     includes.extend(bld.env.INCLUDES_RTOS)
      36     cflags = bld.env.CFLAGS_FOXBMS
      37diff --git a/src/app/driver/wscript b/src/app/driver/wscript
      38index c6b42f89..26369502 100644
      39--- a/src/app/driver/wscript
      40+++ b/src/app/driver/wscript
      41@@ -122,6 +122,7 @@ def build(bld):
      42         os.path.join("..", "main", "include"),
      43         os.path.join("..", "task", "config"),
      44         os.path.join("..", "task", "os"),
      45+        os.path.join("..", "..", "hal", "include"),
      46     ]
      47     includes.extend(bld.env.INCLUDES_RTOS + bld.env.INCLUDES_AFE)
      48     cflags = bld.env.CFLAGS_FOXBMS
      49diff --git a/src/app/engine/wscript b/src/app/engine/wscript
      50index 03873567..118c66b6 100644
      51--- a/src/app/engine/wscript
      52+++ b/src/app/engine/wscript
      53@@ -83,6 +83,7 @@ def build(bld):
      54         os.path.join("..", "main", "include"),
      55         os.path.join("..", "task", "os"),
      56         os.path.join("..", "task", "config"),
      57+        os.path.join("..", "..", "hal", "include"),
      58     ]
      59     includes.extend(bld.env.INCLUDES_RTOS + bld.env.INCLUDES_AFE)
      60     target = f"{bld.env.APPNAME.lower()}-engine"
      61diff --git a/src/app/main/wscript b/src/app/main/wscript
      62index 1945b079..a47c3e20 100644
      63--- a/src/app/main/wscript
      64+++ b/src/app/main/wscript
      65@@ -69,6 +69,7 @@ def build(bld):
      66         os.path.join("..", "engine", "hw_info"),
      67         os.path.join("..", "task", "os"),
      68         os.path.join("..", "task", "config"),
      69+        os.path.join("..", "..", "hal", "include"),
      70     ]
      71     includes.extend(bld.env.INCLUDES_RTOS + bld.env.INCLUDES_AFE)
      72     cflags = bld.env.CFLAGS_FOXBMS
      73diff --git a/src/app/task/wscript b/src/app/task/wscript
      74index d2479891..1b584c01 100644
      75--- a/src/app/task/wscript
      76+++ b/src/app/task/wscript
      77@@ -85,6 +85,7 @@ def build(bld):
      78         os.path.join("..", "engine", "sys_mon"),
      79         os.path.join("..", "engine", "sys"),
      80         os.path.join("..", "main", "include"),
      81+        os.path.join("..", "..", "hal", "include"),
      82     ]
      83     includes.extend(bld.env.INCLUDES_RTOS + bld.env.INCLUDES_AFE)
      84     cflags = bld.env.CFLAGS_FOXBMS
      85diff --git a/src/os/freertos/wscript b/src/os/freertos/wscript
      86index 2d91582e..c32227aa 100644
      87--- a/src/os/freertos/wscript
      88+++ b/src/os/freertos/wscript
      89@@ -66,6 +66,7 @@ def build(bld):
      90         os.path.join("..", "..", "app", "main", "include"),
      91         os.path.join("..", "..", "app", "task"),
      92         os.path.join("..", "..", "app", "task", "config"),
      93+        os.path.join("..", "..", "hal", "include"),
      94     ]
      95     target = f"{bld.env.APPNAME.lower()}-os"
      96     cflags = bld.env.CFLAGS_OS