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

Remove global structure in LCD HAL Layer #6597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abhinav-s235
Copy link
Contributor

Replaced the global LCD HAL layer instance with a local declaration within the lcddev_register() function and passed this instance to LCD_FLUSH_THREAD by converting its address to a string using atoi() function.

@abhinav-s235 abhinav-s235 changed the title os/drivers/lcd/lcd_dev.c: Declare LCD HAL layer instance locally inside lcddev_register() function Remove global structure in LCD HAL Layer Dec 24, 2024

int pid = kernel_thread("LCD Frame flusing", 204, 8192, lcd_flushing_thread, NULL);
itoa((int)lcd_info, parm_buf, 16);
parm[0] = parm_buf;
Copy link
Contributor

Choose a reason for hiding this comment

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

param[0] = itoa((int)lcd_info, parm_buf, 16);

And don't we need to memset parm_buf?

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 know why we need to convert it to ascii and to reconvert to integer.
Is it possible to give the address itself without converting?

Copy link
Contributor Author

@abhinav-s235 abhinav-s235 Dec 26, 2024

Choose a reason for hiding this comment

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

It is not possible to pass the address without converting it to string because kernel_thread() function accept the parameter of type FAR char *const argv[].
int kernel_thread(FAR const char *name, int priority, int stack_size, main_t entry, FAR char *const argv[])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

param[0] = itoa((int)lcd_info, parm_buf, 16);

And don't we need to memset parm_buf?

I don't think it is needed
could you please explain why you think so?

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.

Could you leave why you modify this in the COMMIT description? I can't get why you did.

Comment on lines 427 to 428
char *parm[2];
char parm_buf[9]; /* for storing 32 bit address */
Copy link
Contributor

Choose a reason for hiding this comment

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

The param and param_buf are difficult to distinguish and to know what they are. Could you rename them to know what they are in 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.

The param and param_buf are difficult to distinguish and to know what they are. Could you rename them to know what they are in name?

fixed


int pid = kernel_thread("LCD Frame flusing", 204, 8192, lcd_flushing_thread, NULL);
itoa((int)lcd_info, parm_buf, 16);
parm[0] = parm_buf;
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 know why we need to convert it to ascii and to reconvert to integer.
Is it possible to give the address itself without converting?

…de lcddev_register function

Replaced the global LCD HAL layer instance with a local declaration within the lcddev_register function
and passed this instance to LCD_FLUSH_THREAD by converting its address to a string using atoi() function.
@sunghan-chang
Copy link
Contributor

Could you leave why you modify this in the COMMIT description? I can't get why you did.

@abhinav-s235 Could you check my comment above? I mean why you did below

Replaced the global LCD HAL layer instance with a local declaration within the lcddev_register function
and passed this instance to LCD_FLUSH_THREAD by converting its address to a string using atoi() function.

@abhinav-s235
Copy link
Contributor Author

Could you leave why you modify this in the COMMIT description? I can't get why you did.

Previously, while creating frame flushing thread we were not passing lcd_info pointer to function lcd_flushing_thread() that's why we declared it globally but now we are passing it as a parameter to the lcd_flushing_thread() function there is no need to globally declare it.


int pid = kernel_thread("LCD Frame flusing", 204, 8192, lcd_flushing_thread, NULL);
itoa((int)lcd_info, lcd_info_addr, 16);
task_info[0] = lcd_info_addr;
Copy link
Contributor

Choose a reason for hiding this comment

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

The lcd_info_addr is a local pointer variable. Is it ok in lifecycle? When the flushing thread gets the arg, is it still valid?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sunghan-chang - Yes, it can happen that thread executes after scope of lcd_info_addr is finished.
But to encounter this, if we use dynamic(malloc) lcd_info_addr, in thread function, the passed argument's address changes so we can't free it.
So should we keep static struct *lcd_info as global only ?

@@ -423,13 +424,15 @@ int lcddev_register(struct lcd_dev_s *dev)
{
char devname[16] = { 0, };
int ret;
char *task_info[2];
Copy link
Contributor

Choose a reason for hiding this comment

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

How about flushing_thread_args?

@sunghan-chang
Copy link
Contributor

Could you leave why you modify this in the COMMIT description? I can't get why you did.

Previously, while creating frame flushing thread we were not passing lcd_info pointer to function lcd_flushing_thread() that's why we declared it globally but now we are passing it as a parameter to the lcd_flushing_thread() function there is no need to globally declare it.

The point is you want to remove the global variable. Right? Is that to reduce memory usages?
And Let's leave it at the COMMIT description.

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.

4 participants