Code refactoring and cleanup
This commit is contained in:
parent
f5ce0d21d4
commit
1ec150a06a
@ -43,8 +43,8 @@ static uint8_t hcp_txrx_buffer[MTU];
|
||||
static uint8_t hcp_data_buffer[DATA_BUFFER_SIZE];
|
||||
|
||||
static HCP_comm_t hcp_chain = {
|
||||
.read = platform_bmlite_receive,
|
||||
.write = platform_bmlite_send,
|
||||
.read = platform_bmlite_spi_receive,
|
||||
.write = platform_bmlite_spi_send,
|
||||
.pkt_buffer = hcp_data_buffer,
|
||||
.txrx_buffer = hcp_txrx_buffer,
|
||||
.pkt_size = 0,
|
||||
|
||||
@ -36,8 +36,8 @@ static uint8_t hcp_txrx_buffer[MTU];
|
||||
static uint8_t hcp_data_buffer[DATA_BUFFER_SIZE];
|
||||
|
||||
static HCP_comm_t hcp_chain = {
|
||||
.read = platform_bmlite_receive,
|
||||
.write = platform_bmlite_send,
|
||||
.read = platform_bmlite_spi_receive,
|
||||
.write = platform_bmlite_spi_send,
|
||||
.pkt_buffer = hcp_data_buffer,
|
||||
.txrx_buffer = hcp_txrx_buffer,
|
||||
.pkt_size = 0,
|
||||
|
||||
@ -54,7 +54,7 @@ void platform_bmlite_reset(void);
|
||||
*
|
||||
* @return ::fpc_com_result_t
|
||||
*/
|
||||
fpc_bep_result_t platform_bmlite_send(uint16_t size, const uint8_t *data, uint32_t timeout,
|
||||
fpc_bep_result_t platform_bmlite_spi_send(uint16_t size, const uint8_t *data, uint32_t timeout,
|
||||
void *session);
|
||||
|
||||
/**
|
||||
@ -66,7 +66,7 @@ fpc_bep_result_t platform_bmlite_send(uint16_t size, const uint8_t *data, uint32
|
||||
*
|
||||
* @return ::fpc_com_result_t
|
||||
*/
|
||||
fpc_bep_result_t platform_bmlite_receive(uint16_t size, uint8_t *data, uint32_t timeout,
|
||||
fpc_bep_result_t platform_bmlite_spi_receive(uint16_t size, uint8_t *data, uint32_t timeout,
|
||||
void *session);
|
||||
|
||||
/**
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
#include "hcp_tiny.h"
|
||||
#include "bmlite_if.h"
|
||||
#include "bmlite_hal.h"
|
||||
#include "platform.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bmlite_if_callbacks.h"
|
||||
|
||||
@ -16,11 +16,8 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "fpc_crc.h"
|
||||
#include "fpc_hcp_common.h"
|
||||
#include "hcp_tiny.h"
|
||||
|
||||
#include "bmlite_if_callbacks.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
@ -52,7 +52,7 @@ void platform_bmlite_reset(void)
|
||||
hal_timebase_busy_wait(100);
|
||||
}
|
||||
|
||||
fpc_bep_result_t platform_bmlite_send(uint16_t size, const uint8_t *data, uint32_t timeout,
|
||||
fpc_bep_result_t platform_bmlite_spi_send(uint16_t size, const uint8_t *data, uint32_t timeout,
|
||||
void *session)
|
||||
{
|
||||
uint8_t buff[size];
|
||||
@ -66,7 +66,7 @@ fpc_bep_result_t platform_bmlite_send(uint16_t size, const uint8_t *data, uint32
|
||||
return hal_bmlite_spi_write_read((uint8_t *)data, buff, size, false);
|
||||
}
|
||||
|
||||
fpc_bep_result_t platform_bmlite_receive(uint16_t size, uint8_t *data, uint32_t timeout,
|
||||
fpc_bep_result_t platform_bmlite_spi_receive(uint16_t size, uint8_t *data, uint32_t timeout,
|
||||
void *session)
|
||||
{
|
||||
volatile uint32_t start_time = hal_timebase_get_tick();
|
||||
|
||||
@ -88,8 +88,8 @@ fpc_bep_result_t hal_board_init(void *params)
|
||||
p->hcp_comm->read = rpi_com_receive;
|
||||
p->hcp_comm->write = rpi_com_send;
|
||||
} else {
|
||||
p->hcp_comm->read = platform_bmlite_receive;
|
||||
p->hcp_comm->write = platform_bmlite_send;
|
||||
p->hcp_comm->read = platform_bmlite_spi_receive;
|
||||
p->hcp_comm->write = platform_bmlite_spi_send;
|
||||
}
|
||||
|
||||
p->hcp_comm->phy_rx_timeout = p->timeout*1000;
|
||||
|
||||
@ -39,10 +39,10 @@ Platform-independent interface implemented in [platform.c](BMLite_sdk/src/platfo
|
||||
| :-------- | :-------- |
|
||||
| fpc_bep_result_t **platform_init**(void *params) | Initilalizes hardware |
|
||||
| void **platform_bmlite_reset**(void) | Implements BM-Lite HW Reset |
|
||||
| fpc_bep_result_t **platform_bmlite_send**(uint16_t size, const uint8_t *data, uint32_t timeout, void *session) | Send data packet to FPC BM-Lite |
|
||||
| fpc_bep_result_t **platform_bmlite_receive**(uint16_t size, uint8_t *data, uint32_t timeout, void *session) | Receive data packet from FPC BM-Lite. If timeout = **0**, the function will wait for data from BM-Lite indefinitely. The waiting loop will be breaked if **hal_check_button_pressed()** returns non-zero value. It is recommended to do HW or SW reset of BM-Lite if **platform_bmlite_receive()** returns **FPC_BEP_RESULT_TIMEOUT** in order to return is into known state. |
|
||||
| fpc_bep_result_t **platform_bmlite_spi_send**(uint16_t size, const uint8_t *data, uint32_t timeout, void *session) | Send data packet to FPC BM-Lite |
|
||||
| fpc_bep_result_t **platform_bmlite_spi_receive**(uint16_t size, uint8_t *data, uint32_t timeout, void *session) | Receive data packet from FPC BM-Lite. If timeout = **0**, the function will wait for data from BM-Lite indefinitely. The waiting loop will be breaked if **hal_check_button_pressed()** returns non-zero value. It is recommended to do HW or SW reset of BM-Lite if **platform_bmlite_spi_receive()** returns **FPC_BEP_RESULT_TIMEOUT** in order to return is into known state. |
|
||||
|
||||
Currently **platform_bmlite_send()** and **platform_bmlite_receive()** are implemented for SPI interface. For UART interface there is no need to wait for **IRQ** pin ready. However because in UART mode there is no signal from FPC-BM-LIte that it will send data, I would recommend to use UART interrupt or DMA to receive data from UART and store it to a separate buffer and read data in **platform_bmlite_receive()** from that buffer. Activation UART data reading only inside **platform_bmlite_receive()** could lead to loosing some incoming data and causing HCP protocol errors.
|
||||
Currently **platform_bmlite_spi_send()** and **platform_bmlite_spi_receive()** are implemented for SPI interface. For UART interface there is no need to wait for **IRQ** pin ready. However because in UART mode there is no signal from FPC-BM-LIte that it will send data, I would recommend to use UART interrupt or DMA to receive data from UART and store it to a separate buffer and read data in **platform_bmlite_spi_receive()** from that buffer. Activation UART data reading only inside **platform_bmlite_spi_receive()** could lead to loosing some incoming data and causing HCP protocol errors.
|
||||
|
||||
------------
|
||||
|
||||
@ -67,7 +67,7 @@ For porting the project to a new microcontroller, all functions from [bmlite_hal
|
||||
| HAL Function | Description |
|
||||
| :------------ | :------------ |
|
||||
| uint32_t **hal_get_button_press_time**(void) | How long UI button was pressed last time. Also it should reset button pressed time counter |
|
||||
| uint32_t **hal_check_button_pressed**(void) | Used for breaking waiting in **platform_bmlite_receive()** if returns non-zero |
|
||||
| uint32_t **hal_check_button_pressed**(void) | Used for breaking waiting in **platform_bmlite_spi_receive()** if returns non-zero |
|
||||
| void **hal_set_leds**(platform_led_status_t status, uint16_t mode) | Set LED(s) state according to status and mode. |
|
||||
|
||||
------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user