-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 function of allocating fifosize on adc separately #13665
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: zhangkai25 <zhangkai25@xiaomi.com>
[Experimental Bot, please feedback here] No, this PR does not meet all the NuttX requirements. Here's why and how to improve it:
Example of an Improved Summary: "This PR optimizes memory usage in the ADC driver by allocating the FIFO buffer size on demand. Previously, a fixed |
/* Malloc for af_channale and af_data */ | ||
|
||
fifosize = fifo->af_fifosize; | ||
if (fifosize == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If fifo->af_fifosize
is nonzero (I suppose this is set from BSP/arch during ADC initialization, right?), the BSP/arch is also responsible for allocating af_channel
and af_data
? What if this doesn't happen? I would let adc_register
do all the allocation and just set default size if fifo->af_fifosize = 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about skip allocation of af_channel/af_data if it isn't zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When fifosize is not 0, af_data and channel are passed from the lower half of the vendor.The reason why fifosize is equal to 0 is that the vendor layer does not define the fifosize macros of each ADC device separately. Therefore, nuttx still uses CONFIG_ADC_FIFOSIZE uniformly. If the fifosize of each ADC is defined separately on the vendor side, then the judgment of if (fifosize == 0) will not be entered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point was more about what happens if the lower half does not initialize af_data
and af_channel
correctly. There should at least be some check at the end of adc_register
that controls whether both arrays are allocated imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks,I understand what you mean, and will make some changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where the change?
af347d8
to
64c5342
Compare
…leased Signed-off-by: zhangkai25 <zhangkai25@xiaomi.com>
64c5342
to
34ac748
Compare
@@ -771,7 +771,8 @@ int adc_register(FAR const char *path, FAR struct adc_dev_s *dev) | |||
return -ENOMEM; | |||
} | |||
|
|||
fifo->af_data = kmm_malloc(fifo->af_fifosize * 4); | |||
fifo->af_data = kmm_malloc(fifo->af_fifosize * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge to previous patch
Summary
allocating fifosize on demand to optimize memory ,no need to seting adc_fifosize unified
Impact
Allocate fifosize on demand to optimize memory & Fix the situation where af_channel is still being read after it is released
Testing