Created
January 19, 2023 14:29
-
-
Save jepler/709fede32eab2f823ace7339a839ba9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 1a5d57a5102c67358affbfd1560ccbbf692deddc Mon Sep 17 00:00:00 2001 | |
From: Jeff Epler <jepler@gmail.com> | |
Date: Thu, 19 Jan 2023 07:57:06 -0600 | |
Subject: [PATCH] clear bspi fifos before starting fifo writes | |
--- | |
src/hal/drivers/mesa-hostmot2/bspi.c | 24 ++++++++++++++++++------ | |
src/hal/drivers/mesa-hostmot2/hostmot2.h | 1 + | |
2 files changed, 19 insertions(+), 6 deletions(-) | |
diff --git a/src/hal/drivers/mesa-hostmot2/bspi.c b/src/hal/drivers/mesa-hostmot2/bspi.c | |
index 1b9a491474..9397133d61 100644 | |
--- a/src/hal/drivers/mesa-hostmot2/bspi.c | |
+++ b/src/hal/drivers/mesa-hostmot2/bspi.c | |
@@ -26,9 +26,10 @@ | |
int hm2_bspi_parse_md(hostmot2_t *hm2, int md_index) | |
{ | |
- // All this function actually does is allocate memory | |
- // and give the bspi modules names. | |
- | |
+ // This function | |
+ // * Allocates memory | |
+ // * gives the bspi module names | |
+ // * sets up a tram write to clear the TX and RX fifos every period | |
// | |
// some standard sanity checks | |
@@ -78,11 +79,11 @@ int hm2_bspi_parse_md(hostmot2_t *hm2, int md_index) | |
hm2->bspi.instance = (hm2_bspi_instance_t *)hal_malloc(hm2->bspi.num_instances | |
* sizeof(hm2_bspi_instance_t)); | |
if (hm2->bspi.instance == NULL) { | |
- HM2_ERR("out of memory!\n"); | |
+ HM2_ERR("out of memory allocatin bspi instances!\n"); | |
r = -ENOMEM; | |
goto fail0; | |
} | |
- | |
+ | |
for (i = 0 ; i < hm2->bspi.num_instances ; i++){ | |
hm2_bspi_instance_t *chan = &hm2->bspi.instance[i]; | |
chan->clock_freq = md->clock_freq; | |
@@ -97,8 +98,19 @@ int hm2_bspi_parse_md(hostmot2_t *hm2, int md_index) | |
for (j = 0 ; j < 16 ; j++ ){ | |
chan->addr[j] = chan->base_address + j * sizeof(rtapi_u32); | |
} | |
- | |
} | |
+ | |
+ // Any write to the FIFO count register clears both the TX and RX fifos. | |
+ // Doing this early before the individual frame writes ensures that | |
+ // any weird timing issues that caused the FIFOs to be read back before | |
+ // they were full only causes a transient problem, rather than causing | |
+ // data to be skewed for the balance of the HAL session. | |
+ r = hm2_register_tram_write_region(hm2, hm2->bspi.instance[0].count_addr, (hm2->bspi.num_instances * sizeof(rtapi_u32)), &hm2->bspi.clear_fifos_reg); | |
+ if (r < 0) { | |
+ HM2_ERR("error registering tram write region for BSPI Fifo Clear register (%d)\n", r); | |
+ goto fail0; | |
+ } | |
+ | |
return hm2->bspi.num_instances; | |
fail0: | |
return r; | |
diff --git a/src/hal/drivers/mesa-hostmot2/hostmot2.h b/src/hal/drivers/mesa-hostmot2/hostmot2.h | |
index 2f3a081e42..fc0772013d 100644 | |
--- a/src/hal/drivers/mesa-hostmot2/hostmot2.h | |
+++ b/src/hal/drivers/mesa-hostmot2/hostmot2.h | |
@@ -1270,6 +1270,7 @@ typedef struct { | |
hm2_bspi_instance_t *instance; | |
rtapi_u8 instances; | |
rtapi_u8 num_registers; | |
+ rtapi_u32 *clear_fifos_reg; | |
} hm2_bspi_t; | |
// | |
-- | |
2.34.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment