8.2.4. How to Use Generated Sources from 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.36 Building the HAL library without using HALCoGen on the fly
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      def build(bld):
          """Build the HAL library"""
          source = [
              # list sources here, most likely something like 'source/abc.c',
              # 'source/abc.asm' etc.
          ]
          includes = [
              # list include directories here, most likely 'include'
          ]
          target = f"{bld.env.APPNAME.lower()}-hal"
          cflags = bld.env.CFLAGS_HAL
      
          bld.stlib(
              source=source,
              includes=includes,
              cflags=cflags,
              target=target,
          )
      
    • 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.37 The diff of includes
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      diff --git a/src/app/application/algorithm/wscript b/src/app/application/algorithm/wscript
      index c4d837c4..2d1580fa 100644
      --- a/src/app/application/algorithm/wscript
      +++ b/src/app/application/algorithm/wscript
      @@ -77,6 +77,7 @@ def build(bld):
               os.path.join("..", "..", "main", "include"),
               os.path.join("..", "..", "task", "config"),
               os.path.join("..", "..", "task", "os"),
      +        os.path.join("..", "..", "..", "hal", "include"),
           ]
           includes.extend(bld.env.INCLUDES_OPERATING_SYSTEM)
           cflags = bld.env.CFLAGS_FOXBMS
      diff --git a/src/app/application/wscript b/src/app/application/wscript
      index a9462e21..1fdb5850 100644
      --- a/src/app/application/wscript
      +++ b/src/app/application/wscript
      @@ -88,6 +88,7 @@ def build(bld):
               os.path.join("..", "main", "include"),
               os.path.join("..", "task", "config"),
               os.path.join("..", "task", "os"),
      +        os.path.join("..", "..", "hal", "include"),
           ]
           includes.extend(bld.env.INCLUDES_OPERATING_SYSTEM + bld.env.INCLUDES_MEASUREMENT_IC)
           cflags = bld.env.CFLAGS_FOXBMS
      diff --git a/src/app/driver/measurement-ic/ltc/6806/wscript b/src/app/driver/measurement-ic/ltc/6806/wscript
      index d7ca3af9..0cc6c777 100644
      --- a/src/app/driver/measurement-ic/ltc/6806/wscript
      +++ b/src/app/driver/measurement-ic/ltc/6806/wscript
      @@ -71,6 +71,7 @@ def build(bld):
               os.path.join("..", "..", "..", "..", "engine", "diag"),
               os.path.join("..", "..", "..", "..", "main", "include"),
               os.path.join("..", "..", "..", "..", "task", "os"),
      +        os.path.join("..", "..", "..", "..", "..", "hal", "include"),
           ]
           includes.extend(bld.env.INCLUDES_OPERATING_SYSTEM)
           cflags = bld.env.CFLAGS_FOXBMS
      diff --git a/src/app/driver/wscript b/src/app/driver/wscript
      index c6b42f89..26369502 100644
      --- a/src/app/driver/wscript
      +++ b/src/app/driver/wscript
      @@ -122,6 +122,7 @@ def build(bld):
               os.path.join("..", "main", "include"),
               os.path.join("..", "task", "config"),
               os.path.join("..", "task", "os"),
      +        os.path.join("..", "..", "hal", "include"),
           ]
           includes.extend(bld.env.INCLUDES_OPERATING_SYSTEM + bld.env.INCLUDES_MEASUREMENT_IC)
           cflags = bld.env.CFLAGS_FOXBMS
      diff --git a/src/app/engine/wscript b/src/app/engine/wscript
      index 03873567..118c66b6 100644
      --- a/src/app/engine/wscript
      +++ b/src/app/engine/wscript
      @@ -83,6 +83,7 @@ def build(bld):
               os.path.join("..", "main", "include"),
               os.path.join("..", "task", "os"),
               os.path.join("..", "task", "config"),
      +        os.path.join("..", "..", "hal", "include"),
           ]
           includes.extend(bld.env.INCLUDES_OPERATING_SYSTEM + bld.env.INCLUDES_MEASUREMENT_IC)
           target = f"{bld.env.APPNAME.lower()}-engine"
      diff --git a/src/app/main/wscript b/src/app/main/wscript
      index 1945b079..a47c3e20 100644
      --- a/src/app/main/wscript
      +++ b/src/app/main/wscript
      @@ -69,6 +69,7 @@ def build(bld):
               os.path.join("..", "engine", "hwinfo"),
               os.path.join("..", "task", "os"),
               os.path.join("..", "task", "config"),
      +        os.path.join("..", "..", "hal", "include"),
           ]
           includes.extend(bld.env.INCLUDES_OPERATING_SYSTEM + bld.env.INCLUDES_MEASUREMENT_IC)
           cflags = bld.env.CFLAGS_FOXBMS
      diff --git a/src/app/task/wscript b/src/app/task/wscript
      index d2479891..1b584c01 100644
      --- a/src/app/task/wscript
      +++ b/src/app/task/wscript
      @@ -85,6 +85,7 @@ def build(bld):
               os.path.join("..", "engine", "sys_mon"),
               os.path.join("..", "engine", "sys"),
               os.path.join("..", "main", "include"),
      +        os.path.join("..", "..", "hal", "include"),
           ]
           includes.extend(bld.env.INCLUDES_OPERATING_SYSTEM + bld.env.INCLUDES_MEASUREMENT_IC)
           cflags = bld.env.CFLAGS_FOXBMS
      diff --git a/src/os/freertos/wscript b/src/os/freertos/wscript
      index 2d91582e..c32227aa 100644
      --- a/src/os/freertos/wscript
      +++ b/src/os/freertos/wscript
      @@ -66,6 +66,7 @@ def build(bld):
               os.path.join("..", "..", "app", "main", "include"),
               os.path.join("..", "..", "app", "task"),
               os.path.join("..", "..", "app", "task", "config"),
      +        os.path.join("..", "..", "hal", "include"),
           ]
           target = f"{bld.env.APPNAME.lower()}-os"
           cflags = bld.env.CFLAGS_OS