Saturday, January 14, 2023
(Programming) Combining the constant and volatile keywords in C
Monday, November 15, 2021
Programming: Find location of Stack, Heap and current memory
Simple code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
printf("location of code : %p\n", main);
printf("location of heap : %p\n", malloc(100e6));
int x = 3;
printf("location of stack: %p\n", &x);
return 0;
}
Note that %p prints the address of the pointer.
Saturday, May 8, 2021
WiFi: What is phy restart? Why is it important in dense RF environments?
Phy restart on radio drivers typically means if the hardware (radio) is able to sync to the preamble of a packet which has a stronger signal strength while it is already in the process of decoding a packet.
This is typically useful in noisy environments to achieve a "capture effect", where the stronger packet is finally decoded at the rx. radio. If the radio does not support PHY restart then typically such a reception would result in a collision on the rx-side at the radio.
Monday, April 26, 2021
Linux: Nagle's Algorithm and How to Disable it
Nagle's algorithm is a TCP optimization in the kernel stack that waits to aggregate small chunks of bytes before sending packets on a TCP connection. This approach optimizes the amount of frame overhead spent in sending very small packets over the network. However, when the data is fairly sporadic, this could also lead to an increase in the average delay experienced.
Nagle's algorithm running on a host can be disabled by:
echo 1 > /proc/sys/net/ipv4/tcp_low_latency
Monday, November 23, 2020
Linux: Comma separated arguments in an If Statement
What happens when you write code like this:
if ((x,y) == true) {
Is it even a legal condition to put in? If yes, why would you use it?
We have an example you could try out:
bash-4.1$ cat test.cc#include <iostream>using namespace std;int main() {int x = 1, y =0;if ((x,y) == true) {cout << “X TRUE PATH" << endl;} else {cout << “Y FALSE PATH" << endl;}}
Saturday, May 23, 2020
Linux: Where to use packed structures
struct test_A
{
char a;
int b;
char c;
} x;
Gautam Bhanage, "Padding versus Packing in Embedded Systems Programming", Published online at www.bhanage.com. May 2020. [PDF]
Tuesday, June 25, 2019
Linux: How does the kernel invoke the correct driver for the corresponding /dev file ops?
"When devfs is not being used, adding a new driver to the system means assigning a major number to it. The assignment should be made at driver (module) initialization by calling the following function, defined in <linux/fs.h>:
The return value indicates success or failure of the operation. A negative return code signals an error; a 0 or positive return code reports successful completion. The major argument is the major number being requested, name is the name of your device, which will appear in /proc/devices, and fops is the pointer to an array of function pointers" [1]Thus, this will result in the registration of the device driver with a major number with the kernel.
"Once the driver has been registered in the kernel table, its operations are associated with the given major number. Whenever an operation is performed on a character device file associated with that major number, the kernel finds and invokes the proper function from the file_operations structure. For this reason, the pointer passed to register_chrdev should point to a global structure within the driver, not to one local to the module’s initialization function."