mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 01:03:33 +08:00
Unfortunately, lot's of whitespace changes, required to satisfy unspecified code style format errors.
This commit is contained in:
@@ -60,33 +60,36 @@ void update_index_from_shmem(void);
|
||||
uint64_t update_from_shmem_prev_time = 0, update_from_shmem_current_time = 0;
|
||||
extern unsigned char *adsp_changed_index;
|
||||
|
||||
struct param_wbuf_s {
|
||||
struct param_wbuf_s
|
||||
{
|
||||
param_t param;
|
||||
union param_value_u val;
|
||||
bool unsaved;
|
||||
};
|
||||
|
||||
|
||||
/*update value and param's change bit in shared memory*/
|
||||
void update_to_shmem(param_t param, union param_value_u value)
|
||||
{
|
||||
if(px4muorb_param_update_to_shmem(param, (unsigned char*)&value, sizeof(value)))
|
||||
if (px4muorb_param_update_to_shmem(param, (unsigned char*) &value,
|
||||
sizeof(value)))
|
||||
PX4_ERR("krait update param %u failed", param);
|
||||
}
|
||||
|
||||
void update_index_from_shmem(void)
|
||||
{
|
||||
if(!adsp_changed_index) {
|
||||
if (!adsp_changed_index) {
|
||||
PX4_ERR("%s no param buffer", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
px4muorb_param_update_index_from_shmem(adsp_changed_index, PARAM_BUFFER_SIZE);
|
||||
px4muorb_param_update_index_from_shmem(adsp_changed_index,
|
||||
PARAM_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
static void update_value_from_shmem(param_t param, union param_value_u *value)
|
||||
{
|
||||
if(px4muorb_param_update_value_from_shmem(param, (unsigned char*)value, sizeof(union param_value_u)))
|
||||
if (px4muorb_param_update_value_from_shmem(param, (unsigned char*) value,
|
||||
sizeof(union param_value_u)))
|
||||
PX4_ERR("%s get param failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
@@ -95,7 +98,7 @@ int update_from_shmem(param_t param, union param_value_u *value)
|
||||
unsigned int byte_changed, bit_changed;
|
||||
unsigned int retval = 0;
|
||||
|
||||
if(!adsp_changed_index) {
|
||||
if (!adsp_changed_index) {
|
||||
PX4_ERR("%s no param buffer", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
@@ -103,7 +106,7 @@ int update_from_shmem(param_t param, union param_value_u *value)
|
||||
update_from_shmem_current_time = hrt_absolute_time();
|
||||
|
||||
if ((update_from_shmem_current_time - update_from_shmem_prev_time)
|
||||
> 1000000) { //update every 1 second
|
||||
> 1000000) { //update every 1 second
|
||||
update_from_shmem_prev_time = update_from_shmem_current_time;
|
||||
update_index_from_shmem();
|
||||
}
|
||||
@@ -119,7 +122,8 @@ int update_from_shmem(param_t param, union param_value_u *value)
|
||||
|
||||
//else {PX4_INFO("no change to param %s", param_name(param));}
|
||||
|
||||
PX4_DEBUG("%s %d bit on adsp index[%d]", (retval) ? "cleared" : "unchanged", bit_changed, byte_changed);
|
||||
PX4_DEBUG("%s %d bit on adsp index[%d]",
|
||||
(retval) ? "cleared" : "unchanged", bit_changed, byte_changed);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2015 Vijay Venkatraman. All rights reserved.
|
||||
@@ -76,23 +75,24 @@ static unsigned log2_for_int(unsigned v)
|
||||
return r;
|
||||
}
|
||||
|
||||
struct param_wbuf_s {
|
||||
param_t param;
|
||||
union param_value_u val;
|
||||
bool unsaved;
|
||||
struct param_wbuf_s
|
||||
{
|
||||
param_t param;
|
||||
union param_value_u val;
|
||||
bool unsaved;
|
||||
};
|
||||
extern struct param_wbuf_s *param_find_changed(param_t param);
|
||||
|
||||
static void *map_memory(off_t target)
|
||||
{
|
||||
|
||||
return (void *)(target + LOCK_SIZE);
|
||||
return (void *) (target + LOCK_SIZE);
|
||||
|
||||
}
|
||||
|
||||
int get_shmem_lock(const char *caller_file_name, int caller_line_number)
|
||||
{
|
||||
unsigned char *lock = (unsigned char *)(MAP_ADDRESS + LOCK_OFFSET);
|
||||
unsigned char *lock = (unsigned char *) (MAP_ADDRESS + LOCK_OFFSET);
|
||||
unsigned int i = 0;
|
||||
|
||||
#ifdef PARAM_LOCK_DEBUG
|
||||
@@ -103,16 +103,19 @@ int get_shmem_lock(const char *caller_file_name, int caller_line_number)
|
||||
i++;
|
||||
usleep(1000);
|
||||
|
||||
if (i > 100) { break; }
|
||||
if (i > 100) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i > 100) {
|
||||
PX4_INFO("Could not get lock, file name: %s, line number: %d.\n",
|
||||
strrchr(caller_file_name, '/'), caller_line_number);
|
||||
strrchr(caller_file_name, '/'), caller_line_number);
|
||||
return -1;
|
||||
|
||||
} else {
|
||||
PX4_DEBUG("Lock acquired, file name: %s, line number: %d\n", caller_file_name, caller_line_number);
|
||||
PX4_DEBUG("Lock acquired, file name: %s, line number: %d\n",
|
||||
caller_file_name, caller_line_number);
|
||||
}
|
||||
|
||||
return 0; //got the lock
|
||||
@@ -121,13 +124,13 @@ int get_shmem_lock(const char *caller_file_name, int caller_line_number)
|
||||
|
||||
void release_shmem_lock(const char *caller_file_name, int caller_line_number)
|
||||
{
|
||||
unsigned char *lock = (unsigned char *)(MAP_ADDRESS + LOCK_OFFSET);
|
||||
unsigned char *lock = (unsigned char *) (MAP_ADDRESS + LOCK_OFFSET);
|
||||
|
||||
*lock = 1;
|
||||
|
||||
#ifdef PARAM_LOCK_DEBUG
|
||||
PX4_INFO("release lock, file name: %s, line number: %d.\n",
|
||||
strrchr(caller_file_name, '/'), caller_line_number);
|
||||
strrchr(caller_file_name, '/'), caller_line_number);
|
||||
#endif
|
||||
|
||||
return;
|
||||
@@ -138,14 +141,14 @@ void init_shared_memory(void)
|
||||
//PX4_INFO("Value at lock address is %d\n", *(unsigned int*)0xfbfc000);
|
||||
int i;
|
||||
|
||||
if(shmem_info_p)
|
||||
if (shmem_info_p)
|
||||
return;
|
||||
|
||||
virt_addr = map_memory(MAP_ADDRESS);
|
||||
shmem_info_p = (struct shmem_info *)virt_addr;
|
||||
shmem_info_p = (struct shmem_info *) virt_addr;
|
||||
|
||||
//init lock as 1
|
||||
unsigned char *lock = (unsigned char *)(MAP_ADDRESS + LOCK_OFFSET);
|
||||
unsigned char *lock = (unsigned char *) (MAP_ADDRESS + LOCK_OFFSET);
|
||||
*lock = 1;
|
||||
|
||||
for (i = 0; i < MAX_SHMEM_PARAMS / 8 + 1; i++) {
|
||||
@@ -157,7 +160,7 @@ void init_shared_memory(void)
|
||||
|
||||
void copy_params_to_shmem(struct param_info_s *param_info_base)
|
||||
{
|
||||
param_t param;
|
||||
param_t param;
|
||||
unsigned int i;
|
||||
|
||||
if (get_shmem_lock(__FILE__, __LINE__) != 0) {
|
||||
@@ -171,9 +174,13 @@ void copy_params_to_shmem(struct param_info_s *param_info_base)
|
||||
//{PX4_INFO("writing to offset %d\n", (unsigned char*)(shmem_info_p->adsp_params[param].name)-(unsigned char*)shmem_info_p);}
|
||||
struct param_wbuf_s *s = param_find_changed(param);
|
||||
|
||||
if (s == NULL) { shmem_info_p->params_val[param] = param_info_base[param].val; }
|
||||
if (s == NULL) {
|
||||
shmem_info_p->params_val[param] = param_info_base[param].val;
|
||||
}
|
||||
|
||||
else { shmem_info_p->params_val[param] = s->val; }
|
||||
else {
|
||||
shmem_info_p->params_val[param] = s->val;
|
||||
}
|
||||
|
||||
#ifdef SHMEM_DEBUG
|
||||
|
||||
@@ -197,7 +204,6 @@ void copy_params_to_shmem(struct param_info_s *param_info_base)
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*update value and param's change bit in shared memory*/
|
||||
void update_to_shmem(param_t param, union param_value_u value)
|
||||
{
|
||||
@@ -224,12 +230,12 @@ void update_to_shmem(param_t param, union param_value_u value)
|
||||
|
||||
if (param_type(param) == PARAM_TYPE_INT32) {
|
||||
PX4_INFO("Set value %d for param %s to shmem, set adsp index %d:%d\n", value.i, param_name(param), byte_changed,
|
||||
bit_changed);
|
||||
bit_changed);
|
||||
}
|
||||
|
||||
else if (param_type(param) == PARAM_TYPE_FLOAT) {
|
||||
PX4_INFO("Set value %f for param %s to shmem, set adsp index %d:%d\n", value.f, param_name(param), byte_changed,
|
||||
bit_changed);
|
||||
bit_changed);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -254,7 +260,9 @@ void update_index_from_shmem(void)
|
||||
|
||||
// If a param has changed, we need to find out which one.
|
||||
// From the byte and bit that is different, we can resolve the param number.
|
||||
unsigned bit = log2_for_int(krait_changed_index[i] ^ shmem_info_p->krait_changed_index[i]);
|
||||
unsigned bit = log2_for_int(
|
||||
krait_changed_index[i]
|
||||
^ shmem_info_p->krait_changed_index[i]);
|
||||
param_t param_to_get = i * 8 + bit;
|
||||
|
||||
// Update our krait_changed_index as well.
|
||||
@@ -269,14 +277,13 @@ void update_index_from_shmem(void)
|
||||
// FIXME: this is a hack but it gets the param so that it gets added
|
||||
// to the local list param_values in param_shmem.c.
|
||||
for (i = 0; i < MAX_SHMEM_PARAMS / 8 + 1; i++) {
|
||||
if(params[i] != 0xFFFF){
|
||||
if (params[i] != 0xFFFF) {
|
||||
int32_t dummy;
|
||||
param_get(params[i], &dummy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void update_value_from_shmem(param_t param, union param_value_u *value)
|
||||
{
|
||||
unsigned int byte_changed, bit_changed;
|
||||
@@ -299,12 +306,12 @@ static void update_value_from_shmem(param_t param, union param_value_u *value)
|
||||
|
||||
if (param_type(param) == PARAM_TYPE_INT32) {
|
||||
PX4_INFO("Got value %d for param %s from shmem, cleared krait index %d:%d\n", value->i, param_name(param), byte_changed,
|
||||
bit_changed);
|
||||
bit_changed);
|
||||
}
|
||||
|
||||
else if (param_type(param) == PARAM_TYPE_FLOAT) {
|
||||
PX4_INFO("Got value %f for param %s from shmem, cleared krait index %d:%d\n", value->f, param_name(param), byte_changed,
|
||||
bit_changed);
|
||||
bit_changed);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -321,7 +328,8 @@ int update_from_shmem(param_t param, union param_value_u *value)
|
||||
|
||||
update_from_shmem_current_time = hrt_absolute_time();
|
||||
|
||||
if ((update_from_shmem_current_time - update_from_shmem_prev_time) > 1000000) { //update every 1 second
|
||||
if ((update_from_shmem_current_time - update_from_shmem_prev_time)
|
||||
> 1000000) { //update every 1 second
|
||||
update_from_shmem_prev_time = update_from_shmem_current_time;
|
||||
update_index_from_shmem();
|
||||
}
|
||||
@@ -337,9 +345,9 @@ int update_from_shmem(param_t param, union param_value_u *value)
|
||||
|
||||
//else {PX4_INFO("no change to param %s\n", param_name(param));}
|
||||
|
||||
PX4_DEBUG("%s %d bit on krait changed index[%d]\n", (retval) ? "cleared" : "unchanged", bit_changed, byte_changed);
|
||||
PX4_DEBUG("%s %d bit on krait changed index[%d]\n",
|
||||
(retval) ? "cleared" : "unchanged", bit_changed, byte_changed);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user