aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test/mgmt-misc.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-04-16 15:55:14 -0400
committerRob Austein <sra@hactrn.net>2017-04-16 15:55:14 -0400
commitbb6d9e870fb51833137e82063a3ab08930820a2d (patch)
tree91501087fdfa7536909dd8cdff4d7e1d0929e7e9 /projects/cli-test/mgmt-misc.c
parenta2e32d326c342a965b733c9a42cfd1568b2afed4 (diff)
Switch to libhal's CRC-32 code.
Diffstat (limited to 'projects/cli-test/mgmt-misc.c')
-rw-r--r--projects/cli-test/mgmt-misc.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/projects/cli-test/mgmt-misc.c b/projects/cli-test/mgmt-misc.c
index b7b4fcc..7db08f2 100644
--- a/projects/cli-test/mgmt-misc.c
+++ b/projects/cli-test/mgmt-misc.c
@@ -32,28 +32,32 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#define HAL_OK CMSIS_HAL_OK
#include "stm-init.h"
#include "stm-uart.h"
-
#include "mgmt-cli.h"
#include "mgmt-misc.h"
+#undef HAL_OK
-#include <string.h>
-
+#define HAL_OK LIBHAL_OK
+#include "hal.h"
+#include "hal_internal.h"
+#undef HAL_OK
-extern uint32_t update_crc(uint32_t crc, uint8_t *buf, int len);
+#include <string.h>
-static volatile uint32_t demo_crc = 0;
+static volatile hal_crc32_t demo_crc;
static int _count_bytes_callback(uint8_t *buf, size_t len) {
- demo_crc = update_crc(demo_crc, buf, len);
+ demo_crc = hal_crc32_update(demo_crc, buf, len);
return 1;
}
int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_callback data_callback)
{
- uint32_t filesize = 0, crc = 0, my_crc = 0, counter = 0;
+ hal_crc32_t crc = 0, my_crc = hal_crc32_init();
+ uint32_t filesize = 0, counter = 0;
size_t n = len;
if (! control_mgmt_uart_dma_rx(DMA_RX_STOP)) {
@@ -63,7 +67,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal
cli_print(cli, "OK, write size (4 bytes), data in %li byte chunks, CRC-32 (4 bytes)", (uint32_t) n);
- if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, 4, 1000) != HAL_OK) {
+ if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 1000) != CMSIS_HAL_OK) {
cli_print(cli, "Receive timed out");
goto fail;
}
@@ -78,12 +82,12 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal
if (filesize < n) n = filesize;
- if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 1000) != HAL_OK) {
+ if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 1000) != CMSIS_HAL_OK) {
cli_print(cli, "Receive timed out");
goto fail;
}
filesize -= n;
- my_crc = update_crc(my_crc, buf, n);
+ my_crc = hal_crc32_update(my_crc, buf, n);
/* After reception of a chunk but before ACKing we have "all" the time in the world to
* calculate CRC and invoke the data_callback.
@@ -97,8 +101,9 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal
uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4);
}
+ my_crc = hal_crc32_finalize(my_crc);
cli_print(cli, "Send CRC-32");
- uart_receive_bytes(STM_UART_MGMT, (void *) &crc, 4, 1000);
+ uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 1000);
cli_print(cli, "CRC-32 0x%x, calculated CRC 0x%x", (unsigned int) crc, (unsigned int) my_crc);
if (crc == my_crc) {
cli_print(cli, "CRC checksum MATCHED");
@@ -115,8 +120,9 @@ static int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv
{
uint8_t buf[FILETRANSFER_UPLOAD_CHUNK_SIZE];
- demo_crc = 0;
+ demo_crc = hal_crc32_init();
cli_receive_data(cli, &buf[0], sizeof(buf), _count_bytes_callback);
+ demo_crc = hal_crc32_finalize(demo_crc);
cli_print(cli, "Demo CRC is: %li/0x%x", demo_crc, (unsigned int) demo_crc);
return CLI_OK;
}