]> rtime.felk.cvut.cz Git - rpp-test-sw.git/commitdiff
Simplify frbtsettimer implementation and fix documentation
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 28 Aug 2013 17:37:47 +0000 (19:37 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 28 Aug 2013 17:38:06 +0000 (19:38 +0200)
commands/cmd_fr_basic_test.c

index 08af0393c0e58bdeb6f2fdc9699369ebbba07e8a..f0d197fb6e09f4390167f6f6cb35b593e15eba3b 100644 (file)
@@ -1234,28 +1234,19 @@ int cmd_do_fr_settimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[
        int offset = 0;
        char* token = NULL;
 
-       if (sscanf(param[1], "%d", &timer) != 1) {
-               return -CMDERR_BADPAR;
-       }
-       if ((token = strtok(param[2], " ")) == NULL) {
-               return -CMDERR_BADPAR;
-       }
-       if (sscanf(token, " %d", &cycle) != 1) {
-               return -CMDERR_BADPAR;
-       }
-       if ((token = strtok(NULL, " ")) == NULL) {
-               return -CMDERR_BADPAR;
-       }
-       if (sscanf(token, " %d", &offset) != 1) {
-               return -CMDERR_BADPAR;
-       }
-       if ((token = strtok(NULL, " ")) != NULL) {
+       if (sscanf(param[1], "%i %i %i", &timer, &cycle, &offset) != 3) {
                return -CMDERR_BADPAR;
        }
 
        retVal = rpp_fr_set_timer(0, timer, cycle, offset);
        if (retVal == SUCCESS) {
-               rpp_sci_printf("Timer was set.\r\n");
+               uint8_t i = 0x40;
+               while (i && cycle & i == 0)
+                       i >>= 1;
+               if (!i)
+                       i = 1;
+
+               rpp_sci_printf("Timer was set for every %d-th cycle, offset %d\n", i, cycle & ~i);
        }
        else {
                rpp_sci_printf("General error.\r\n");
@@ -2067,14 +2058,15 @@ cmd_des_t const cmd_des_fr_settimer={
        "   frbtsettimer<TMID> <CYCLE> <OFFSET>\n"
        "where\n"
        "* <TMID> is a number (0, 1) specifying the timer.\n"
-       "* <CYCLE> is a decimal number (0 - 255) specifying the number of the cycle, in which timer interrupt should be requested.\n"
+       "* <CYCLE> is a 7-bit number (0 - 127) specifying the set of cycles, in which timer interrupt should be requested. The first set bit determines the period (1, 2, ..., 64) and the lower bits determine the offset in cycles within the period.\n"
        "* <OFFSET> is a decimal number (0 - 16383) specifying the offset in macroticks, where precisely in the cycle should be the timer interrupt requested.\n"
        "\n"
        "=== Description ===\n"
        "\n"
-       "The command stands for Fr_SetAbsoluteTimer function from the Autosar\n"
-       "specification. It sets the timer selected by the parameter and enables\n"
-       "it.\n"
+       "The command is similar to Fr_SetAbsoluteTimer function from the\n"
+       "Autosar specification. The difference is that the command allows to\n"
+       "specify a set of cycles, not only one of 64 cycles. It sets the timer\n"
+       "selected by the parameter and enables it.\n"
        "\n"
        "=== Example ===\n"
        "\n"