Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSI Framework and CSI driver #6399

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sahil1dotgupta
Copy link
Contributor

Add CSI Framework

framework/serc/csifw: CSIFW source code
framework/include/csifw: CSIFW headers
apps/examples/csifw_test: Sample csifw app.

Add WIFI CSI Driver

os/drivers/wifi_csi: Add driver source code
os/board: Enable driver register at bootup
build/configs: Enable driver flags

@sahil1dotgupta sahil1dotgupta marked this pull request as ready for review September 16, 2024 09:59
@@ -1650,6 +1669,9 @@ CONFIG_EXAMPLE_LCD_FPS_TEST=5000
#
# CONFIG_EXAMPLES_TAHI is not set
# CONFIG_EXAMPLES_WIFIMANAGER_TEST is not set
# CONFIG_WIFIMANAGER_TEST_TRIAL=5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'# CONFIG_WIFIMANAGER_TEST_TRIAL is not set
'# CONFIG_EXAMPLES_WIFIMANAGER_AP_LIST_ITEMS_COUNT is not set

@@ -1274,6 +1289,9 @@ CONFIG_DEBUG_ERROR=y
# Subsystem Debug Options
#
# CONFIG_DEBUG_AUDIO is not set
CONFIG_DEBUG_WIFICSI=y
CONFIG_DEBUG_WIFICSI_ERROR=y
CONFIG_DEBUG_WIFICSI_INFO=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default is Error

Copy link
Contributor

@sunghan-chang sunghan-chang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. There are so many coding rules violations.
  2. UDP server support to send CSI data to UDP client is not proper in commit rules.

framework/src/csifw/CSILogsDumper.c Show resolved Hide resolved
{
print_log("\n RAW DATA %d\n\n", len);
unsigned long long *buff_tmp = (u64 *)buf;
int buff_len = (len/8) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len / 8


void set_event_listener(csiDataDumpListener listener)
{
gListener = listener;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coding rule violation.
tab for indentation
same as other lines

}
}

CSIFW_RES csi_logs_dumper_init()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add void

fclose(file);
close(sockfd);
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check the warning

return CSIFW_ERROR;
}

if (pthread_create(&gThreadId, NULL, dataTransmitter, NULL) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you create a pthread, you should call pthread_join or pthread_detach. If you don't, it will have a memory leak.

@@ -1031,6 +1031,12 @@ CONFIG_LWNL80211=y
# CONFIG_DEBUG_LWNL80211_VENDOR_DRV_ERROR is not set
CONFIG_NET_LOOPBACK_INTERFACE=y

# WIFI CSI Support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO NOT modify defconfig manually.
After doing through menuconfig, and then copy changes into the defconfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

os/Kconfig.debug Outdated
@@ -45,6 +45,38 @@ config DEBUG_VERBOSE

comment "Subsystem Debug Options"

config DEBUG_WIFICSI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add it by Alphabet order to find it easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

int ret;

csivdbg("minor %d\n", minor);
printf("minor %d\n", minor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated, this line should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if !WIFICSI_DEV_ROOT

config WIFICSI_DEV_PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is difference between WIFICSI_CUSTOM_DEV_PATH and this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsolete, it has been removed now.

Comment on lines 59 to 61
ifeq ($(CONFIG_WIFI_CSI_RTL8730E),y)
CSRCS += rtk_wifi_csi.c
endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The driver should be common. This should be in Make.defs of RTL8730E, not here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done.

* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef __INCLUDE_TINYARA_WIFI_CSI_COMMON_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to distinguish wifi_csi.h and wifi_csi_common.h in usage? How about renaming them to know what it is from the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Copy link
Contributor

@sunghan-chang sunghan-chang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many basic things are missing like license, coding rules, commit rules.

# see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt
#

config EXAMPLES_CSIFW_TEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a framework. How about splitting a commit for app from framework commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 21 to 30
static int print_log(const char *format, ...)
{

va_list args;
va_start(args, format);

vprintf(format, args);
va_end(args);
return 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you let me know why you use this function instead of printf? Any advantage???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to printf.


ifeq ($(CONFIG_CSIFW), y)

CFLAGS += -I${TOPDIR}/os/include
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be unnecessary. Let's remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (upper->crefs > 1) {
upper->crefs--;
} else {
FAR struct wifi_csi_lowerhalf_s *lower = upper->dev;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, corrected.

ret = lower->ops->getcsidata(lower, buf_arg->buffer, buf_arg->buflen);
} else {
csidbg("ERROR: Unsupported operation: getcsidata\n");
ret = ENOTSUP;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ENOSYS is better option.
If driver has not implemented function, then ENOSYS
But driver dosn't support by given configuration or something, then ENOTSUP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh right! thanks.

* call via its callback pointer to our upper-half driver.
*
****************************************************************************/
static inline void wifi_csi_data_ready(FAR struct wifi_csi_upperhalf_s *upper, char *buff, uint32_t csi_data_len)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type need to be changed int, and it should return some of errno if upper->usermq is null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wifi_csi_data_ready is a callback, so where would I check the return type, all callers are themselves void callbacks. (cannot return anything as no one is there to check ret value)

wifi driver sends data ready callback --> void lower_driver_data_readyCB() --> void wifi_csi_callback() --> void wifi_csi_data_ready()

*
* @param[in] raw_callback Callback function for receiving raw CSI data. Pass NULL if raw csi data not required.
* @param[in] parsed_callback Callback function for receiving parsed CSI data. Pass NULL if parsed csi data not required.
* @param[in] interval Data collection interval in microseconds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add description for void *ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

{
if (g_service_state == CSI_COLLECT_STATE_STARTED) {
CSIFW_LOGE(" Already running");
return CSIFW_ERROR;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should provide some kind of CSIFW_ERROR_WRONG_STATE or something

Copy link
Contributor Author

@sahil1dotgupta sahil1dotgupta Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State is an internally maintained f/w property, so I followed the practice to not inform the app about f/w state.
In current case, the app developer will receive error and message that "CSIFW is already started".

But if still the change is needed, please tell, I'll correct it.

}
csi_packet_receiver_start_collect(&g_csifw_config);
ping_generator_start();
g_service_state = CSI_COLLECT_STATE_STARTED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it working based on state, then some kind of pthread_mutex_lock is required. to prevent change state in multiple thread environment

CSIFW_RES csi_service_stop(CSIFW_REASON reason)
{
if (g_service_state != CSI_COLLECT_STATE_STARTED) {
CSIFW_LOGE("Already stopped");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSIFW_LOGE("stop error state : %d\n", g_service_state);
because it can be one of 4 states.

sleep(5);

PRNT_LN3;
csi_action_param_t config = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of app developer can't understand what this config means exactly.
so please refer to below.

some_csi_init_in_framework()
{
	/* Initialize Base value Here */
	g_config.group_num = CSI_GROUP_NUM_1;
	g_config.mode = CSI_MODE_NORMAL;
	g_config.accuracy = CSI_ACCU_1BYTE;
	g_config.ch_opt = CSI_CH_NON_LEGACY;
	g_config.trig_period = 200;
	g_config.data_rate = CSI_DATA_RATE_HIGH...; //0x80 is impossible to understand what it means.
}

csi_set_group_num(int num)
{
	if (state_is_wrong) {
		return CSIFW_ERROR_STATE;
	}
	g_config.group_num = num;
}

A better way is that structure in driver need to be avoided, so it should work without csi_service_set_config based on basic setting value.

Copy link
Contributor Author

@sahil1dotgupta sahil1dotgupta Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually for the application to get data, they must configure what specific kind of csi data is required.

with some_csi_init_in_framework() do you wish to provide option to use default config for an app-developer who does not have info about config? And then provide apis (like csi_set_group_num() )for every config component, so that they can only change the config they are known to?

printf("\n RAW DATA %d\n\n", len);
unsigned long long *buff_tmp = (u64 *)buf;
int buff_len = (len / 8) + 1;
for (int i = 0; i < buff_len; i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to our coding rule, add bracket even if it is single line of code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fixed

sahil1dotgupta and others added 4 commits September 30, 2024 12:20
os/drivers/wifi_csi: Add driver source code
os/board: Enable driver register at bootup
os/include/tinyara/wifi_csi/wifi_csi_struct.h: Define commmon wifi csi kernel constants and structures.
framework/src/csifw: CSIFW source code
framework/include/csifw: CSIFW headers
…lient

framework/src/csifw: CSIFW logger file
tool/csi_datadump: CSI Data dump client file.
framework/src/csifw/CSIPacketReceiver.c: Modify compilation of Ring
buffer code depending on config flags.
build/configs/rtl8730e/loadable_ext_psram/defconfig: Add flag CONFIG_CONFIG_CSIFW_USE_RB
Copy link
Contributor

@sunghan-chang sunghan-chang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still many coding rules violations.

Comment on lines +1 to +3
config ENTRY_CSIFW_TEST
bool "CSI Framework example"
depends on EXAMPLES_CSIFW_TEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use this, you should add config USER_ENTRYPOINT in the Kconfig. Please refer other example.

return 0;
}

void csi_manager_csifw_test_init(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you let me know who executes this?

while (1) {
sleep(2);
}
// sleep(15);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to keep commented codes?

Comment on lines +87 to +88
PRNT_LN1;
PRNT_LN2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you let me know purpose of them, PRNT_LN1, LN2 and LN3?


#if LOG_PARSED_DATA
printf("[APP] Displaying parsed data, csi_data_len: %d\n\n", csi_data_len);
for(int i = 0; i < csi_data_len; i += 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (

Comment on lines +64 to +65
CSIFW_LOGI("PRINTING PARSED DATA"); //csi_sequence, timestamp
printf("\n csi_buff_len (with header): %d, only csi len: 112",csi_buff_len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you use CSIFW_LOGx or printf?

Comment on lines +71 to +80
CSIFW_LOGI("%d,%d,", csi_seq_num, timestamp); //csi_sequence, timestamp

printf("0x%x%x,", csi_buff[1], csi_buff[0]); //csi_signature
printf("0x%x,", csi_buff[2]); //hdr_len
CSIFW_LOGI("%x:%x:%x:%x:%x:%x,", csi_buff[8],csi_buff[7],csi_buff[6],csi_buff[5],csi_buff[4], csi_buff[3]); //mac_addr
CSIFW_LOGI("%x:%x:%x:%x:%x:%x,", csi_buff[14],csi_buff[13],csi_buff[12],csi_buff[11],csi_buff[10], csi_buff[9]); //trig_mac_addr
CSIFW_LOGI("%d,", ((int)csi_buff[31]/2 - 110)); //rssi

// CSIFW_LOGI("%s,",argv[1]); //real
CSIFW_LOGI("%d,", (int)csi_buff[19]); //channel, infered
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we are ok to print all raw data defaultly. I don't mean this highlighted lines only. There are many data printing in the framework.

Comment on lines +113 to +117
CSIFW_RES csi_manager_init(void)
{
CSIFW_LOGI("[CSIFW] initialization function is called\n");
return CSIFW_OK;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function looks unnecessary. Could you check it?

static void csi_data_dump_listener(EVENT event) {
CSIFW_LOGD("csi_data_dump_listener called\n");
gCSIDataDumpEvent = event;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary

Comment on lines +61 to +68
if (!dev) {
csidbg("ERROR: dev null\n");
return;
}
if (!priv) {
csidbg("ERROR: priv null\n");
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case which dev is NOT null and priv is null? I mean that checking priv is necessary?

@sahil1dotgupta
Copy link
Contributor Author

sahil1dotgupta commented Oct 10, 2024

Hello all, thankyou for the suggestions, the pending comments will be resolved soon along with sync-up with internal developments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants