Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/unroll csfr clusters #22

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions templates/rust/aurix_core.tera
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ use crate::common::{*};
#[allow(unused_imports)]
use crate::common::sealed;
#[doc = r"{{peri.description | svd_description_to_doc}}"]
#[derive(Copy, Clone, Eq, PartialEq)]
{% set peri_struct = "CsfrCpu" | to_struct_id -%}
{% set reg_base_addr = peri.base_addr[0] -%}
pub struct {{ peri_struct }}{pub(super) ptr: *mut u8}
unsafe impl core::marker::Send for CsfrCpu {}
unsafe impl core::marker::Sync for CsfrCpu {}
impl CsfrCpu {
{% set peri_base_addr = peri.base_addr[0] -%}
unsafe impl core::marker::Send for super::CsfrCpu {}
unsafe impl core::marker::Sync for super::CsfrCpu {}
impl super::CsfrCpu {
{%- for register_name,reg in peri.registers %}
{{macros::register_core_func(types_mod="self",reg=reg, base_addr=reg_base_addr)}}
{{macros::register_core_func(types_mod="self",reg=reg, base_addr=peri_base_addr)}}
{% endfor -%}
{% for cluster_name,cluster in peri.clusters -%}
{{macros::cluster_func(types_mod="self",cluster=cluster)}}
{{macros::cluster_func_csfr(types_mod="self",cluster=cluster, base_addr=peri_base_addr)}}
{% endfor %}

}
{% for register_name,reg in peri.registers -%}
{{macros::register_struct(reg=reg)}}
{{macros::register_struct(reg_name=reg.name,reg=reg)}}
{% endfor %}
{% for cluster_name,cluster in peri.clusters -%}
{{macros::cluster_struct(cluster=cluster)}}
{% for register_name,reg in cluster.registers -%}
{% set cluster_reg_name = cluster.name~"_"~reg.name -%}
{{macros::register_struct(reg_name=cluster_reg_name,reg=reg)}}
{% endfor %}
{% endfor %}


Expand Down
12 changes: 11 additions & 1 deletion templates/rust/lib.tera
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ pub const {{name | upper}}:[{{full_path_struct}};{{ p.base_addr | length }}] = [
{% if ir_csfr %}
#[cfg(any(
{%- set module_struct = "csfr_cpu" | to_struct_id -%}
{%- set full_path_struct = "csfr_cpu" ~ "::" ~ module_struct -%}
{%- set full_path_struct = "self::" ~ module_struct -%}
{% for name,p in ir_csfr.device.peripheral_mod %}
{%- set module_name = p.name | to_mod_id -%}
{% if not loop.last %}feature = "{{module_name}}",{% else %}feature = "{{module_name}}"))]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct {{ module_struct }}{ptr:*mut u8}
{% endif %}
{%- endfor -%}
#[cfg(any(
{%- set module_struct = "csfr_cpu" | to_struct_id -%}
{%- set full_path_struct = "self::" ~ module_struct -%}
{% for name,p in ir_csfr.device.peripheral_mod %}
{%- set module_name = p.name | to_mod_id -%}
{% if not loop.last %}feature = "{{module_name}}",{% else %}feature = "{{module_name}}"))]
Expand Down
64 changes: 60 additions & 4 deletions templates/rust/macros.tera
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,39 @@ pub const fn {{reg.name~index| to_func_id }}(&self)-> crate::common::RegCore<{{r
{%- endmacro -%}


{# Generated core cluster unrolled into register function #}
{%- macro cluster_register_core_func(types_mod,reg,base_addr,cluster_index,cluster) -%}
{%- set reg_struct = cluster.name~"_"~reg.name | to_struct_id -%}
{%- set reg_struct_name = types_mod ~ "::" ~ reg_struct -%}
{%- set reg_addr = base_addr+reg.offset | to_hex -%}
#[doc = r"{{reg.description | svd_description_to_doc}}"]
#[inline(always)]
{% if reg.dim == 1 -%}
{% if cluster.dim == 1 -%}
pub const fn {{cluster.name~"_"~reg.name| to_func_id }}(&self) -> crate::common::RegCore<{{reg_struct_name}}_SPEC, crate::common::{{reg.access}}, {{reg_addr}}> {
unsafe { crate::common::RegCore::new() }
}
{%- else -%}
pub const fn {{cluster.name~"_"~reg.name~cluster_index| to_func_id }}(&self) -> crate::common::RegCore<{{reg_struct_name}}_SPEC, crate::common::{{reg.access}}, {{reg_addr}}> {
unsafe { crate::common::RegCore::new() }
}
{%- endif -%}
{%- else -%}
{%- for reg_index in range(end=reg.dim) -%}
{% if cluster.dim == 1 -%}
pub const fn {{cluster.name~"_"~reg.name~reg_index| to_func_id }}(&self)-> crate::common::RegCore<{{reg_struct_name}}_SPEC, crate::common::{{reg.access}}, {{base_addr+reg.offset+reg_index*reg.dim_increment | to_hex }}> {
unsafe { crate::common::RegCore::new() }
}
{%- else -%}
pub const fn {{cluster.name~"_"~reg.name~"_"~cluster_index~"_"~reg_index| to_func_id }}(&self)-> crate::common::RegCore<{{reg_struct_name}}_SPEC, crate::common::{{reg.access}}, {{base_addr+reg.offset+reg_index*reg.dim_increment | to_hex }}> {
unsafe { crate::common::RegCore::new() }
}
{%- endif -%}
{% endfor -%}
{%- endif -%}
{%- endmacro -%}


{%- macro bitfield_type(field,reg_struct_name,reg_mod_name,turbofish) -%}
{%-if turbofish %}{%set separator = "::"%}{%else%}{%set separator = ""%}{%endif-%}
{%- if not field.enum_type and field.mask == 1 %}
Expand All @@ -73,9 +106,10 @@ pub const fn {{reg.name~index| to_func_id }}(&self)-> crate::common::RegCore<{{r
{%- endmacro -%}


{%- macro register_struct(reg) -%}
{%- set reg_struct_name = reg.name | to_struct_id -%}
{%- set reg_mod_name = reg.name | to_mod_id -%}
{%- macro register_struct(reg_name,reg) -%}
pellico marked this conversation as resolved.
Show resolved Hide resolved
{%- set reg_struct_name = reg_name | to_struct_id -%}
{%- set reg_mod_name = reg_name | to_mod_id -%}


#[doc(hidden)]
#[derive(Copy, Clone,Eq, PartialEq)]
Expand Down Expand Up @@ -156,6 +190,7 @@ pub fn {{cluster_func}}(self) -> [{{cluster_struct_path}};{{cluster.dim}}] {
{%- endif -%}
{%- endmacro -%}


{# Macro to generate structure and module for a cluster#}
{%- macro cluster_struct(cluster) -%}
{%- if not cluster.is_derived_from -%}
Expand All @@ -178,11 +213,32 @@ pub mod {{cluster_mod}} {
#[allow(unused_imports)]
use crate::common::{*};
{% for register_name,reg in cluster.registers -%}
{{self::register_struct(reg=reg)}}
{{self::register_struct(reg_name=reg.name,reg=reg)}}
{% endfor -%}
{% for cluster_name,cluster in cluster.clusters -%}
{{self::cluster_struct(cluster=cluster) }}
{% endfor -%}
}
{%- endif -%} {# if not cluster.is_derived_from #}
{%- endmacro -%}


{# Unroll the cluster register for aurix csfr #}
pellico marked this conversation as resolved.
Show resolved Hide resolved
{%- macro cluster_func_csfr(types_mod,cluster, base_addr) -%}
{%- set cluster_struct_id = cluster.name | to_struct_id -%}
{%- set cluster_base_addr = base_addr+cluster.offset -%}
#[doc = "{{cluster.description | svd_description_to_doc}}"]
#[inline(always)]
{%- if cluster.dim == 1 %}
{% for register_name,reg in cluster.registers -%}
{{self::cluster_register_core_func(types_mod="self",reg=reg, base_addr=cluster_base_addr,cluster_index=0,cluster=cluster)}}
{% endfor -%}
{%- else %}
{%- for index in range(end=cluster.dim) -%}
{%- set current_cluster_addr = cluster_base_addr+index*cluster.dim_increment -%}
{% for register_name,reg in cluster.registers -%}
{{self::cluster_register_core_func(types_mod="self",reg=reg, base_addr=current_cluster_addr,cluster_index=index,cluster=cluster)}}
{% endfor -%}
{% endfor -%}
{%- endif -%}
{%- endmacro -%}
2 changes: 1 addition & 1 deletion templates/rust/peri_mod.tera
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl super::{{ peri_struct }} {
{% endfor %}
}
{% for register_name,reg in peri.registers -%}
{{macros::register_struct(reg=reg)}}
{{macros::register_struct(reg_name=reg.name,reg=reg)}}
{% endfor %}
{% for cluster_name,cluster in peri.clusters -%}
{{macros::cluster_struct(cluster=cluster)}}
Expand Down
Loading