Updated function descriptions in headers

Change-Id: Ie662c726a8892375db5d38b49168673db3aa3174
This commit is contained in:
Andrey Perminov 2020-05-06 12:56:18 -07:00
parent 00bb0d53d0
commit 76a6ac3ff8
3 changed files with 92 additions and 23 deletions

View File

@ -38,25 +38,94 @@ typedef struct {
} HCP_comm_t; } HCP_comm_t;
/** /**
* @brief Helper function for receiving HCP commands * @brief Send prepared command packet to FPC BM-LIte
*
* @param[in] hcp_comm - pointer to HCP_comm struct
*
* @return ::fpc_bep_result_t
*/
fpc_bep_result_t bmlite_send(HCP_comm_t *hcp_comm);
* @param command_id command to send /**
* @param arg_key1 first key to receive * @brief Receive answer from FPC BM-LIte
* @param arg_data1 first argument data *
* @param arg_data1_length first argument data length * @param[in] hcp_comm - pointer to HCP_comm struct
* @param arg_key2 second key to receive *
* @param arg_data2 second argument data
* @param arg_data2_length second argument
* @return ::fpc_bep_result_t * @return ::fpc_bep_result_t
*/ */
fpc_bep_result_t bmlite_receive(HCP_comm_t *hcp_comm); fpc_bep_result_t bmlite_receive(HCP_comm_t *hcp_comm);
fpc_bep_result_t bmlite_send(HCP_comm_t *hcp_comm);
/**
* @brief Send prepared command packet to FPC BM-LIte and receive answer
*
* @param[in] hcp_comm - pointer to HCP_comm struct
*
* Returns result of executing command in BM-LIte in hcp_comm->bep_result
* if communication with BM-Lite was successful.
* Please not that some BM-Lite command does not return result in ARG_RESULT.
* They return data with some other argument instead.
*
* @return ::fpc_bep_result_t
*/
fpc_bep_result_t bmlite_tranceive(HCP_comm_t *hcp_comm); fpc_bep_result_t bmlite_tranceive(HCP_comm_t *hcp_comm);
/**
* @brief Initialize new command for BM-Lite
*
* @param[in] hcp_comm - pointer to HCP_comm struct
* @param[in] cmd - command to send
* @param[in] arg - Argument for the command without parameterd
* Use ARG_NONE and add arguments by bmlite_add_arg() if
* you need to add argument with parameter
*
* @return ::fpc_bep_result_t
*/
fpc_bep_result_t bmlite_init_cmd(HCP_comm_t *hcp_comm, uint16_t cmd, uint16_t arg); fpc_bep_result_t bmlite_init_cmd(HCP_comm_t *hcp_comm, uint16_t cmd, uint16_t arg);
fpc_bep_result_t bmlite_add_arg(HCP_comm_t *hcp_comm, uint16_t arg, void *data, uint16_t size);
/**
* @brief Add argument to command.
* Must be used only after command buffer is initialized by bmlite_init_cmd()
*
* @param[in] hcp_comm - pointer to HCP_comm struct
* @param[in] arg_type - argument key
* @param[in] arg_data - argument data
* @param[in] arg_size - argument data length
*
* @return ::fpc_bep_result_t
*/
fpc_bep_result_t bmlite_add_arg(HCP_comm_t *hcp_comm, uint16_t arg_type, void *arg_data, uint16_t arg_size);
/**
* @brief Search for argument in received answer.
*
* @param[in] hcp_comm - pointer to HCP_comm struct
* @param[in] arg_type - argument key
*
* If found, place pointer to argument data in receiving buffer to hcp_comm->arg.data
* and size of the argument in hcp_comm->arg.size
*
* @return ::fpc_bep_result_t
*/
fpc_bep_result_t bmlite_get_arg(HCP_comm_t *hcp_comm, uint16_t arg_type); fpc_bep_result_t bmlite_get_arg(HCP_comm_t *hcp_comm, uint16_t arg_type);
fpc_bep_result_t bmlite_copy_arg(HCP_comm_t *hcp_comm, uint16_t arg_key, void *arg_data, uint16_t arg_data_length);
/**
* @brief Search for argument in received answer and copyargument's data
* to
*
* @param[in] hcp_comm - pointer to HCP_comm struct
* @param[in] arg_type - argument key
* @param[out] arg_data - pointer for memory to copy argument value
* @param[out] arg_data_size - size of data area for copying argument value
*
* If found, argument's data will be copyed to arg_data
* If received argument's size greater that arg_data_size, the copyed data will be
* truncated to arg_data_size.
* Still hcp_comm->arg.data will be pointed to argument's data in receiving buffer
* and real size of the argument will be hcp_comm->arg.size
*
* @return ::fpc_bep_result_t
*/
fpc_bep_result_t bmlite_copy_arg(HCP_comm_t *hcp_comm, uint16_t arg_key, void *arg_data, uint16_t arg_data_size);

View File

@ -63,21 +63,21 @@ fpc_bep_result_t bmlite_init_cmd(HCP_comm_t *hcp_comm, uint16_t cmd, uint16_t ar
return FPC_BEP_RESULT_OK; return FPC_BEP_RESULT_OK;
} }
fpc_bep_result_t bmlite_add_arg(HCP_comm_t *hcp_comm, uint16_t arg, void *data, uint16_t size) fpc_bep_result_t bmlite_add_arg(HCP_comm_t *hcp_comm, uint16_t arg_type, void *arg_data, uint16_t arg_size)
{ {
if(hcp_comm->pkt_size + 4 + size > hcp_comm->pkt_size_max) { if(hcp_comm->pkt_size + 4 + arg_size > hcp_comm->pkt_size_max) {
bmlite_on_error(BMLITE_ERROR_SEND_CMD, FPC_BEP_RESULT_NO_MEMORY); bmlite_on_error(BMLITE_ERROR_SEND_CMD, FPC_BEP_RESULT_NO_MEMORY);
return FPC_BEP_RESULT_NO_MEMORY; return FPC_BEP_RESULT_NO_MEMORY;
} }
((_HCP_cmd_t *)hcp_comm->pkt_buffer)->args_nr++; ((_HCP_cmd_t *)hcp_comm->pkt_buffer)->args_nr++;
_CMD_arg_t *args = (_CMD_arg_t *)(&hcp_comm->pkt_buffer[hcp_comm->pkt_size]); _CMD_arg_t *args = (_CMD_arg_t *)(&hcp_comm->pkt_buffer[hcp_comm->pkt_size]);
args->arg = arg; args->arg = arg_type;
args->size = size; args->size = arg_size;
if(size) { if(arg_size) {
memcpy(&args->pld, data, size); memcpy(&args->pld, arg_data, arg_size);
} }
hcp_comm->pkt_size += 4 + size; hcp_comm->pkt_size += 4 + arg_size;
return FPC_BEP_RESULT_OK; return FPC_BEP_RESULT_OK;
} }
@ -106,7 +106,7 @@ fpc_bep_result_t bmlite_get_arg(HCP_comm_t *hcp_comm, uint16_t arg_type)
return FPC_BEP_RESULT_INVALID_ARGUMENT; return FPC_BEP_RESULT_INVALID_ARGUMENT;
} }
fpc_bep_result_t bmlite_copy_arg(HCP_comm_t *hcp_comm, uint16_t arg_key, void *arg_data, uint16_t arg_data_length) fpc_bep_result_t bmlite_copy_arg(HCP_comm_t *hcp_comm, uint16_t arg_key, void *arg_data, uint16_t arg_data_size)
{ {
fpc_bep_result_t bep_result; fpc_bep_result_t bep_result;
bep_result = bmlite_get_arg(hcp_comm, arg_key); bep_result = bmlite_get_arg(hcp_comm, arg_key);
@ -115,7 +115,7 @@ fpc_bep_result_t bmlite_copy_arg(HCP_comm_t *hcp_comm, uint16_t arg_key, void *a
bmlite_on_error(BMLITE_ERROR_GET_ARG, FPC_BEP_RESULT_NO_MEMORY); bmlite_on_error(BMLITE_ERROR_GET_ARG, FPC_BEP_RESULT_NO_MEMORY);
return FPC_BEP_RESULT_NO_MEMORY; return FPC_BEP_RESULT_NO_MEMORY;
} }
memcpy(arg_data, hcp_comm->arg.data, HCP_MIN(arg_data_length, hcp_comm->arg.size)); memcpy(arg_data, hcp_comm->arg.data, HCP_MIN(arg_data_size, hcp_comm->arg.size));
} else { } else {
bmlite_on_error(BMLITE_ERROR_GET_ARG, FPC_BEP_RESULT_INVALID_ARGUMENT); bmlite_on_error(BMLITE_ERROR_GET_ARG, FPC_BEP_RESULT_INVALID_ARGUMENT);
return FPC_BEP_RESULT_INVALID_ARGUMENT; return FPC_BEP_RESULT_INVALID_ARGUMENT;

View File

@ -84,7 +84,7 @@ void fpc_sensor_spi_reset(bool state)
} }
} }
bool fpc_sensor_spi_read_irq(void) bool hal_bmlite_get_status(void)
{ {
return digitalRead(BMLITE_IRQ_PIN); return digitalRead(BMLITE_IRQ_PIN);
} }
@ -192,8 +192,8 @@ fpc_bep_result_t platform_spi_receive(uint16_t size, uint8_t *data, uint32_t tim
{ {
volatile uint64_t start_time = platform_get_time(); volatile uint64_t start_time = platform_get_time();
volatile uint64_t curr_time = start_time; volatile uint64_t curr_time = start_time;
// Wait for BM_Lite Ready for timeout or indefinitily if timeout is 0 // Wait for BM_Lite Ready for timeout or indefinitely if timeout is 0
while (!fpc_sensor_spi_read_irq() && while (!hal_bmlite_get_status() &&
(!timeout || (curr_time = platform_get_time()) - start_time < timeout)) { (!timeout || (curr_time = platform_get_time()) - start_time < timeout)) {
//usleep(1); //usleep(1);
} }