How to use TX2 timer

hi, i want to generate a 1ms timer to do smoething, but i do not know how to use the timer of TX2. somebody help me。

No sure if below example help on you.

this mykmod_timer is for kernel , i just want to get some date from spi interface repeatly in user space.

I believe there are a lot of system API or C API about timing. You can googling to find what you want.

Btw, the answer you see is for kernel space. If you are just operating in ordinary user space the answer changes.

EDIT: Missed one reply, I see it is user space. In C there are an enormous number of examples you can find via:
https://www.google.com/search?ei=bb1HYKb0PIKO9PwPm4mR0Ag&q=linux+c+timer+example&oq=linux+c+timer+example&gs_lcp=Cgdnd3Mtd2l6EAMyBggAEAcQHjIGCAAQBxAeMgYIABAHEB4yAggAMgYIABAIEB4yBggAEAgQHjoHCAAQRxCwA1CUKliUKmDyK2gBcAJ4AIABR4gBfJIBATKYAQCgAQGqAQdnd3Mtd2l6yAEIwAEB&sclient=gws-wiz&ved=0ahUKEwjm3t7R6qPvAhUCB50JHZtEBIoQ4dUDCAw&uact=5

Similarly, you could replace “C” with “python” if using another language. The user space timers have been around a very long time.

thanks, could you please introduce some python examples about timer?

I’m not much of a Python guy (I tend to prefer C/C++), but lots of examples:
Google search linux python timer examples

thanks!
hi, i have another question.i want to get sda UUID by shell cmd.
i get UUID using shell"sudo blkid | grep /dev/sda1 | grep UUID | awk {‘print $3’}",result is “UUID=“17F5F7635D753BDB””,but i only want to get the vaule between the first "character “””and the last character “”,for example, the value i want to get is 17F5F7635D753BDB, sorry about not good at shell,can you help me to get the value using shell or any other way?

FYI, you don’t need “sudo” if you are just reading from blkid. Doesn’t hurt though. I also tend to use “gawk” for consistency, though in most cases just plain “awk” will give the same result. If something seems odd, then you might try “gawk” instead of “awk” (you might need “sudo apt-get install gawk”, but this is already present on most systems). Also, you don’t need egrep, but for extended regular expressions I tend to use egrep (it is worth learning extended regular expressions for egrep, just not for this case).

Some example data is useful, so pretend this is your “sda1”:

/dev/sda1: LABEL="mypartition" UUID="1234abcd-12ab-34cd-56ef-7890abcdef" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="xy123456-z123-abcd-1234567890ab"

Up to the “grep” it is correct, so, the first piece, but substituting echo of my sample data for blkid (will substitute back to blkid at the end), and separating the echo line with a backslash so it is more clear (that way later on it is easy to substitute the echo for blkid):

echo '/dev/sda1: LABEL="mypartition" UUID="1234abcd-12ab-34cd-56ef-7890abcdef" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="xy123456-z123-abcd-1234567890ab"' \
| grep 'dev.sda1'

(this is an unedited list of the sda1 line, and I added the “dev.” as good practice since in theory “sda1” might appear elsewhere in some programs, e.g., in some weird RAID cases)

Next I am going to convert this to a single awk file without blkid (the “id_line” is for testing, will substitute later for blkid):

touch alt_blkid.awk
# Edit alt_blkid.awk with your favorite editor, content will start as (uses sample data only at this
# point...this comment is not part of the file):
BEGIN {
	sda1_line="/dev/sda1: LABEL=\"stuff\" UUID=\"1234abcd-12ab-34cd-56ef-7890abcdef\" TYPE=\"ext4\" PARTLABEL=\"Linux filesystem\" PARTUUID=\"pqrsabcd-12ab-34cd-56ef-7890abcdef\"";

	printf "TESTING block id:\n\t%s\n", sda1_line;

	# Find out if this is "`/dev/sda1`".
	start=match(sda1_line, /^[/]dev[/]sda1[:]/);
	if (start > 0)
		printf "sda1 token at start index %d, this is /dev/sda1.\n", start;
	else {
		printf "No sda1 match, start is %d.\n", start;	if (verbose) {
		printf("TESTING block id:\n\t%s\n", uuid_line);
	}

		exit;
	}

	# Now we need the UUID (one could also find the PARTID or LABEL).
	start=match(sda1_line, /UUID=["]/);
	if (start == 0) {
		printf "No UUID match, start is %d.\n", start;
		exit;
	}
	
	printf "UUID token starts at index %d.\n", start;
	# This is actually the first of several steps:
	token=substr(sda1_line, start);
	printf "Token:\n\t%s\n", token;
	# First space is not part of the token:
	end=match(token, / /);
	# This leaves quotes, you might want to end here:
	token=substr(token, 6, end - 6);
	# Remove leading and trailing quotes:
	token=substr(token, 2, length(token) - 2);
	# Final answer, no newline...useful for substitutions.
	# Comment out other previous print lines if this is what you need.
	printf("%s", token);
}

Now run this ("awk" probably works the same as “gawk”, normally I would only use “gawk”, but sticking to “awk” for this):
awk -f ./alt_blkid.awk

Final Edits to Use Actual UUID:
(this cuts out test data and instead uses blkid)

BEGIN {
	# To see only the resulting UUID, use verbose=0; to see
	# debug output, use verbose=1.
	#verbose=0;
	verbose=1;
	if (verbose) {
		print("You are using verbose mode. Consider setting verbose=0.");
	}
	device="/dev/sda1";
	# Don't bother with grep, use blkid with argument "device".
	cmd = sprintf("blkid %s", device);
	
	# We know this is only one line, but pretend multi-line anyway.
	# This isn't enough for real multi-line, but included for clarity.
	while ((cmd | getline uuid_line) > 0) {
		if (verbose) {
			printf("uuid_line: %s\n", uuid_line);
		}
	}
	if (verbose) {
		printf("DEVICE: %s\n", device);
		printf("CMD: %s\n", cmd);
		printf("DATA:\n\t%s\n", uuid_line);
	}

	# Find out if this is "`/dev/sda1`".
	start=match(uuid_line, /^[/]dev[/]sda1[:]/);
	if (start > 0) {
		if (verbose) {
			printf("sda1 token at start index %d, this is /dev/sda1.\n", start);
		}
	}
	else {
		if (verbose) {
			printf "No sda1 match, start is %d.\n", start;
		}
		exit;
	}

	# Now we need the UUID (one could also find the PARTID or LABEL).
	start=match(uuid_line, /UUID=["]/);
	if (start == 0) {
		if (verbose) {
			printf("No UUID match, start is %d.\n", start);
		}
		exit;
	}
	
	if (verbose) {
		printf("UUID token starts at index %d.\n", start);
	}
	# This is actually the first of several steps:
	token=substr(uuid_line, start);
	if (verbose) {
		printf("Initial token:\n\t%s\n", token);
	}
	# First space is not part of the token:
	end=match(token, / /);
	# This leaves quotes, you might want to end here:
	token=substr(token, 6, end - 6);
	# Remove leading and trailing quotes:
	token=substr(token, 2, length(token) - 2);
	# Final answer, no newline...useful for substitutions.
	# Comment out other previous print lines if this is what you need.
	# This printf includes a newline, but comment this out, and
	# uncomment the next line if you choose to not use a newline:
	if (verbose) {
		printf("Final token:\n%s\n", token);
	} else {
		printf("%s", token);
	}
}

In the above note that if you uncomment “verbose=0” and comment out “verbose=1”, then all that ugly debug output won’t show up, and you can use the program directly for your purposes. You could also set “device” to something other than “/dev/sda1”. Other fields could be extracted as well.

Btw, I really like awk/gawk! I think people often underestimate how useful it is.