]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
lout control commands added
authorMichal Horn <hornmich@fel.cvut.cz>
Mon, 10 Dec 2012 13:57:52 +0000 (14:57 +0100)
committerMichal Horn <hornmich@fel.cvut.cz>
Mon, 10 Dec 2012 13:57:52 +0000 (14:57 +0100)
source/commands.c

index a518d6bc8a6a5eec1059e68ed3a6924523321b77..ec5d489525376777e2f4331ab6df16fc1f4c9ae4 100644 (file)
 #include "port_def.h"
 #include "FlexRay.h"
 #include "spi_resp_transl.h"
+#include "lout_spi.h"
 
 #include "ctype.h"
 #include "utils.h"
 
 #define MAX_PARAM_VALUES_NUM   64
 
+
 /** @brief List in which commands are stored */
 cmd_des_t const **cmd_list;
 
@@ -48,6 +50,32 @@ uint32_t canRecError;
 
 FRAY_ST e_FRAY0_ST;
 
+int read_arg(char **ps, uint32_t *buf, int n)
+{
+       uint32_t val;
+       int c;
+       int i;
+
+       if (si_fndsep(ps, "({") < 0)
+               return -CMDERR_BADSEP;
+       i = 0;
+       si_skspace(ps);
+       if ((**ps != ')') && (**ps != '}'))
+               do {
+                       if (i >= n)
+                               return -CMDERR_BADPAR;
+                       if (si_long(ps, (long*)&val, 16) < 0)
+                               return -CMDERR_BADPAR;
+                       buf[i] = val;
+                       i++;
+                       if ((c = si_fndsep(ps, ",)}")) < 0)
+                               return -CMDERR_BADSEP;
+               } while (c == ',');
+
+       return i;
+}
+
+
 /* ------------------------------
  * User defined command functions
  * ------------------------------
@@ -254,7 +282,7 @@ int vbat1_pwm() {
        int pwm;
        volatile uint8_t val = 1;
        int i, j;
-       int pulse_cnt = 50;
+       int pulse_cnt = 100;
        uint32_t desc;
 
        desc = PIN_DSC_VBAT1EN;
@@ -309,48 +337,95 @@ int cmd_do_power_off(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 
 int cmd_do_lout_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
          char *p;
-         long val;
          int opchar;
-         uint32_t* desc;
-
+         int i;
+         uint32_t ret;
+         uint32_t values[MAX_PARAM_VALUES_NUM];
 
          if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-         char pinName[32];
-         char suffix[32];
-         strcpy(pinName, "VBAT");
-         strncpy(suffix, param[1], param[2]-param[1]);
-         suffix[param[2]-param[1]] = '\0';
-         strcat(pinName, suffix);
 
-         if((desc = hal_gpio_get_pin_dsc(pinName, -1))==NULL) return -CMDERR_BADREG;
+         if(opchar==':'){
+           p=param[3];
+               si_skspace(&p);
+               i = read_arg(&p, values, MAX_PARAM_VALUES_NUM);
+               if (i != 1)
+                       return -CMDERR_BADPAR;
+
+           lout_set_word(values[0]);
+           ret=lout_spi_transfer();
+           return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+         }
+         else{
+               ret = lout_get_word();
+           return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+         }
+}
+
+int cmd_do_lout_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+         char *p;
+         int opchar;
+         int pin;
+         int value;
+         uint32_t ret;
+
+         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+         p=param[1];
+         if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
 
          if(opchar==':'){
-                 p=param[3];
-                 if(si_long(&p,&val,0)<0) return -CMDERR_BADPAR;
-                 si_skspace(&p);
-                 if(*p) return -CMDERR_GARBAG;
-                 if (val == 0) {
-                           hal_gpio_set_value(*desc, val);
-                           hal_gpio_direction_output(*desc, val);
-                           print((uint8_t *)pinName);
-                           print((uint8_t *)": 0, output");
-                 }
-                 else if (val == 1) {
-                           hal_gpio_set_value(*desc, val);
-                           hal_gpio_direction_input(*desc);
-                           print((uint8_t *)pinName);
-                           print((uint8_t *)": 1, input");
-                 }
-                 else {
-                         return -CMDERR_BADPAR;
-                 }
-           return val;
+           p=param[3];
+               if(si_long(&p,(long*)&value,0)<0) return -CMDERR_BADPAR;
+               lout_set_pin(pin, value);
+           ret=lout_spi_transfer();
+           return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
          }
          else{
-               uint32_t pin_value = hal_gpio_get_value(*desc);
-           return cmd_opchar_replong(cmd_io, param, pin_value, 0, 0);
+               ret = lout_get_pin(pin);
+           return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
          }
 }
+unsigned int reverse(unsigned int x)
+{
+    x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
+    x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
+    x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
+    x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
+    return((x >> 16) | (x << 16));
+
+}
+
+int cmd_do_lout_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       uint32_t ret;
+       uint32_t numCmdDesc;
+       int i;
+       char buf[16];
+       uint32_t numFieldDesc;
+
+
+       ret = lout_spi_transfer();
+       spitr_reg_translate_table_t translatedData;
+
+       const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_LOUT, -1, &numCmdDesc);
+       if(cmdDesc == NULL) return -CMDERR_BADREG;
+
+       const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, lout_spi_cmd, &numFieldDesc);
+       if (fieldDescs == NULL)
+               return -CMDERR_BADPAR;
+       uint32_t lsbResponse = 0 | ((lout_spi_response & 0xFF) << 8 ) | ((lout_spi_response & 0xFF00) >> 8) | ((lout_spi_response & 0xFF0000) << 8) | ((lout_spi_response & 0xFF000000) >> 8);
+       lsbResponse = reverse(lsbResponse);
+       ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, lsbResponse, &translatedData);
+
+       for (i = 0; i < translatedData.num_rows; i++) {
+               print((uint8_t *)translatedData.row[i].field_name);
+               print((uint8_t *)": 0x");
+               i2str(buf, translatedData.row[i].value, 0, 16);
+               print((uint8_t *)buf);
+               print((uint8_t *)"\r\n");
+       }
+       return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
+
+
+}
 
 int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
          char *p;
@@ -414,30 +489,6 @@ int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
          }
 }
 
-int read_arg(char **ps, uint32_t *buf, int n)
-{
-       uint32_t val;
-       int c;
-       int i;
-
-       if (si_fndsep(ps, "({") < 0)
-               return -CMDERR_BADSEP;
-       i = 0;
-       si_skspace(ps);
-       if ((**ps != ')') && (**ps != '}'))
-               do {
-                       if (i >= n)
-                               return -CMDERR_BADPAR;
-                       if (si_long(ps, (long*)&val, 16) < 0)
-                               return -CMDERR_BADPAR;
-                       buf[i] = val;
-                       i++;
-                       if ((c = si_fndsep(ps, ",)}")) < 0)
-                               return -CMDERR_BADSEP;
-               } while (c == ',');
-
-       return i;
-}
 
 /**    Read values general command function. According the suffix switch to appropriate reading procedure.
  * @param[in]  cmd_io  Pointer to IO stack
@@ -957,6 +1008,25 @@ cmd_des_t const cmd_des_power_off = {
     cmd_do_power_off, (void *)&cmd_list
 };
 
+cmd_des_t const cmd_des_lout_wr={
+       0, CDESM_OPCHR|CDESM_RW,
+       "loutwr","\tloutwr:(FF) - writes word wr in LOUT\r\n\tloutwr? - reads word from LOUT",
+       cmd_do_lout_wr, (void *)&cmd_list
+};
+
+
+cmd_des_t const cmd_des_lout_val={
+       0, CDESM_OPCHR|CDESM_RW,
+       "loutval#","\tloutvalX:Y - writes bit Y on LOUTX\r\n\tloutvalX? - reads bit from LOUTX",
+       cmd_do_lout_val, (void *)&cmd_list
+};
+
+cmd_des_t const cmd_des_lout_status={
+               0, 0,
+               "loutstat","get LOUT status in human readable format",
+               cmd_do_lout_status, (void *)&cmd_list
+       };
+
 /** @brief command descriptor for test SDRAM */
 cmd_des_t const cmd_des_test_sdram={
     0, 0,
@@ -1086,6 +1156,9 @@ cmd_des_t const *cmd_list_main[]={
   &cmd_des_sleep,
   &cmd_des_power_on,
   &cmd_des_power_off,
+  &cmd_des_lout_wr,
+  &cmd_des_lout_val,
+  &cmd_des_lout_status,
   &cmd_des_vbat1_set_bit,
   &cmd_des_vbat1_clr_bit,
   CMD_DES_INCLUDE_SUBLIST(cmd_list_lowlevel),