Skip to content

Commit

Permalink
to fix the issue the tuple struct of peripheral,cluster has been chan…
Browse files Browse the repository at this point in the history
…ged to regular struct.

tuple struct instantiation is the same as function call. Compiler error message is misleading but Rust analyser is better.
Added test case in simple.xml
  • Loading branch information
pellico committed May 7, 2024
1 parent 0699ec0 commit cd992c0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion templates/rust/aurix_core.tera
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::common::sealed;
#[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) *mut u8);
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 {
Expand Down
2 changes: 1 addition & 1 deletion templates/rust/common.tera
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) mod sealed {
fn cast_from(val: A) -> Self;
}

impl CastFrom<u64> for u8 {
impl CastFrom<u64> for u8 {
#[inline(always)]
fn cast_from(val: u64) -> Self {
val as Self
Expand Down
10 changes: 5 additions & 5 deletions templates/rust/lib.tera
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ pub use {{module_name}} as csfr_cpu;
{% set peri_struct = p.name | to_struct_id -%}
#[cfg(feature = "{{module_name}}")] {# Peripheral definition #}
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct {{ peri_struct }}(*mut u8);
pub struct {{ peri_struct }}{ptr:*mut u8}
{# Peripheral instances #}
{%- set module_struct = p.name | to_struct_id -%}
{%- set full_path_struct = "self::" ~ module_struct -%}
#[cfg(feature = "{{module_name}}")]
{%- if p.base_addr | length == 1 %}
pub const {{name | upper}}: {{full_path_struct}} = {{full_path_struct}}({{p.base_addr[0] | to_hex }}u32 as _);
pub const {{name | upper}}: {{full_path_struct}} = {{full_path_struct}}{ptr:{{p.base_addr[0] | to_hex }}u32 as _};
{% else %}
pub const {{name | upper}}:[{{full_path_struct}};{{ p.base_addr | length }}] = [{%- for addr in p.base_addr %} {{full_path_struct}}({{addr | to_hex }}u32 as _), {% endfor -%}];
pub const {{name | upper}}:[{{full_path_struct}};{{ p.base_addr | length }}] = [{%- for addr in p.base_addr %} {{full_path_struct}}{ptr:{{addr | to_hex }}u32 as _}, {% endfor -%}];
{%- endif -%}
{%- endfor -%} {# for name,p in ir.device.peripheral_mod #}
{% if ir_csfr %}
Expand All @@ -60,9 +60,9 @@ pub const {{name | upper}}:[{{full_path_struct}};{{ p.base_addr | length }}] = [
{%- set module_name = p.name | to_mod_id -%}
{% if not loop.last %}feature = "{{module_name}}",{% else %}feature = "{{module_name}}"))]
{%- if p.base_addr | length == 1 %}
pub const {{"csfr_cpu" | upper}}: {{full_path_struct}} = {{full_path_struct}}({{p.base_addr[0] | to_hex }}u32 as _);
pub const {{"csfr_cpu" | upper}}: {{full_path_struct}} = {{full_path_struct}}{ptr:{{p.base_addr[0] | to_hex }}u32 as _};
{% else %}
pub const {{"csfr_cpu" | upper}}:[{{full_path_struct}};{{ p.base_addr | length }}] = [{%- for addr in p.base_addr %} {{full_path_struct}}({{addr | to_hex }}u32 as _), {% endfor -%}];
pub const {{"csfr_cpu" | upper}}:[{{full_path_struct}};{{ p.base_addr | length }}] = [{%- for addr in p.base_addr %} {{full_path_struct}}{ptr:{{addr | to_hex }}u32 as _}, {% endfor -%}];
{% endif %}
{% endif %}
{%- endfor -%}
Expand Down
10 changes: 5 additions & 5 deletions templates/rust/macros.tera
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Unsupported register size
#[inline(always)]
{% if reg.dim == 1 -%}
pub const fn {{reg.name | to_func_id }}(&self) -> crate::common::Reg<{{reg_struct_name}}_SPEC, crate::common::{{reg.access}}> {
unsafe { crate::common::Reg::from_ptr(self.0.add({{reg.offset}}usize)) }
unsafe { crate::common::Reg::from_ptr(self.ptr.add({{reg.offset}}usize)) }
}
{%- else -%}
pub const fn {{reg.name | to_func_id }}(&self) -> [crate::common::Reg<{{reg_struct_name}}_SPEC, crate::common::{{reg.access}}>;{{reg.dim}}] {
unsafe { [
{%- for index in range(end=reg.dim) -%}
crate::common::Reg::from_ptr(self.0.add({{reg.offset | to_hex }}usize + {{index * reg.dim_increment | to_hex }}usize )),
crate::common::Reg::from_ptr(self.ptr.add({{reg.offset | to_hex }}usize + {{index * reg.dim_increment | to_hex }}usize )),
{% endfor -%}
] }
}
Expand Down Expand Up @@ -143,13 +143,13 @@ pub mod {{reg_mod_name}} {
#[inline(always)]
{%- if cluster.dim == 1 %}
pub fn {{cluster_func}}(self) -> {{cluster_struct_path}}{
unsafe { {{cluster_struct_path}}(self.0.add({{cluster.offset}}usize)) }
unsafe { {{cluster_struct_path}}{ptr:self.ptr.add({{cluster.offset}}usize)} }
}
{%- else %}
pub fn {{cluster_func}}(self) -> [{{cluster_struct_path}};{{cluster.dim}}] {
unsafe { [
{%- for index in range(end=cluster.dim) -%}
{{cluster_struct_path}}(self.0.add({{cluster.offset | to_hex}}usize + {{index*cluster.dim_increment | to_hex }}usize)),
{{cluster_struct_path}}{ptr:self.ptr.add({{cluster.offset | to_hex}}usize + {{index*cluster.dim_increment | to_hex }}usize)},
{% endfor -%}
] }
}
Expand All @@ -163,7 +163,7 @@ pub fn {{cluster_func}}(self) -> [{{cluster_struct_path}};{{cluster.dim}}] {
{%- set cluster_mod = cluster.struct_id | to_mod_id -%}
#[doc = "{{cluster.description | svd_description_to_doc}}"]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct {{ cluster_struct }}(pub(crate) *mut u8);
pub struct {{ cluster_struct }}{pub(crate) ptr: *mut u8}
unsafe impl ::core::marker::Send for {{ cluster_struct}} {}
unsafe impl ::core::marker::Sync for {{ cluster_struct }} {}
impl {{cluster_struct}} {
Expand Down

0 comments on commit cd992c0

Please sign in to comment.