]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Commands modified to use only RPP API from Carlos
authorMichal Horn <michal@michal-laptop.(none)>
Tue, 18 Jun 2013 14:42:33 +0000 (16:42 +0200)
committerMichal Horn <michal@michal-laptop.(none)>
Tue, 18 Jun 2013 14:42:33 +0000 (16:42 +0200)
 - DAC commands changed
 - DIN commands changed
 - HBR commands changed
 - LOUT commands changed

rpp/lib/cmdproc/src/commands/cmd_dac.c
rpp/lib/cmdproc/src/commands/cmd_din.c
rpp/lib/cmdproc/src/commands/cmd_hbr.c
rpp/lib/cmdproc/src/commands/cmd_lout.c

index 03037fb59181323f828d6efe0146c613ee872ff6..5329d5b57df40ec038324c84c513d7000a375f2c 100644 (file)
 #include "cmdproc_utils.h"
 #include "rpp/rpp.h"
 
-/**
- *     @brief  Command for setting and getting voltage on selected DAC pin.
- *
- *     Command syntax: dacpinval##:V   - ## specifies number of the DAC pin in range 1-4
- *                                                                     - V specifies voltage in mV
- *
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_dac_pin_value(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+
+int cmd_do_dac_pin_setup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       int opchar;
+       uint8_t pin;
+       int ret;
+       boolean_t enabled;
        char *p;
+
+       if((opchar=cmd_opchar_check(cmd_io,des,param))<0)
+               return opchar;
+       p=param[1];
+       if(si_long(&p,(long*)&pin,0) < 10)
+               return -CMDERR_BADPAR;
+       p=param[3];
+       if(si_long(&p,(long*)&enabled,10) < 0)
+               return -CMDERR_BADPAR;
+       ret = rpp_aout_setup(pin, enabled);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
+               return -CMDERR_BADPAR;
+       }
+
+       if (rpp_aout_update() == FAILURE) {
+               rpp_sci_printf("DAC update failed.");
+               return -CMDERR_EIO;
+       }
+
+       return cmd_opchar_replong(cmd_io, param, enabled, 0, 10);
+}
+
+int cmd_do_dac_pin_set_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
        int opchar;
-       int pin;
-       int voltage;
+       uint8_t pin;
+       int ret;
+       uint8_t val;
+       char *p;
 
-       if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+       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;
-       pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
-       if (pin > 4 || pin < 0) return -CMDERR_BADPAR;
-       if(opchar=='?') {
+       if(si_long(&p,(long*)&pin,0) < 10)
+               return -CMDERR_BADPAR;
+       p=param[3];
+       if(si_long(&p,(long*)&val,10) < 0)
+               return -CMDERR_BADPAR;
+       ret = rpp_aout_set(pin, val);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
                return -CMDERR_BADPAR;
        }
-       else {
-               p=param[3];
-               if(si_long(&p,(long*)&voltage,10)<0) return -CMDERR_BADPAR;
-               rpp_aout_set_voltage(pin, voltage);
-               rpp_aout_update();
-               return cmd_opchar_replong(cmd_io, param, voltage, 0, 10);
+       else if (ret == -2) {
+               rpp_sci_printf("Value out of range.");
+               return -CMDERR_BADPAR;
        }
+
+       if (rpp_aout_update() == FAILURE) {
+               rpp_sci_printf("DAC update failed.");
+               return -CMDERR_EIO;
+       }
+       return cmd_opchar_replong(cmd_io, param, val, 0, 10);
 }
 
+int cmd_do_dac_pin_set_voltage(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       int opchar;
+       uint8_t pin;
+       int ret;
+       uint16_t mV;
+       char *p;
+
+       if((opchar=cmd_opchar_check(cmd_io,des,param))<0)
+               return opchar;
+       p=param[1];
+       if(si_long(&p,(long*)&pin,0) < 10)
+               return -CMDERR_BADPAR;
+       p=param[3];
+       if(si_long(&p,(long*)&mV,10) < 0)
+               return -CMDERR_BADPAR;
+       ret = rpp_aout_set_voltage(pin, mV);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
+               return -CMDERR_BADPAR;
+       }
+       else if (ret == -2) {
+               rpp_sci_printf("Voltage out of range.");
+               return -CMDERR_BADPAR;
+       }
+
+       if (rpp_aout_update() == FAILURE) {
+               rpp_sci_printf("DAC update failed.");
+               return -CMDERR_EIO;
+       }
+       return cmd_opchar_replong(cmd_io, param, mV, 0, 10);
+}
+
+/** Descriptor of command for dac pin voltage set/get */
+cmd_des_t const cmd_des_dac_pin_setup = {
+       0, CDESM_OPCHR|CDESM_WR,
+       "dacpinsetup#","\tdacpinsetupX:Y - Enables or disables DAC pin number X. Y equal 1 means enable, 0 means disable.\r\n",
+       cmd_do_dac_pin_setup, (void *)&cmd_list_dac
+};
+
+/** Descriptor of command for dac pin voltage set/get */
+cmd_des_t const cmd_des_dac_pin_set_val = {
+       0, CDESM_OPCHR|CDESM_WR,
+       "dacpinval#","\tdacpinvalX:Y - Sets value Y to pin DAC X.\r\n",
+       cmd_do_dac_pin_set_val, (void *)&cmd_list_dac
+};
+
 /** Descriptor of command for dac pin voltage set/get */
-cmd_des_t const cmd_des_dac_val={
-       0, CDESM_OPCHR|CDESM_RW,
-       "dacpinval#","\tdacpinvalX:Y - DACX <- Y mV\r\n\t\tdacpinvalX? - Get DACX voltage in mV\r\n\t\tX = <1;4>",
-       cmd_do_dac_pin_value, (void *)&cmd_list_dac
+cmd_des_t const cmd_des_dac_pin_set_voltage = {
+       0, CDESM_OPCHR|CDESM_WR,
+       "dacpinvoltage#","\tdacpinvoltageX:Y - Sets voltage Y mV to pin DAC X.\r\n",
+       cmd_do_dac_pin_set_voltage, (void *)&cmd_list_dac
 };
 
 /** List of commands for dac, defined as external */
 cmd_des_t const *cmd_list_dac[]={
-  &cmd_des_dac_val,
-  NULL
+       &cmd_des_dac_pin_setup,
+       &cmd_des_dac_pin_set_val,
+       &cmd_des_dac_pin_set_voltage,
+       NULL
 };
index cb96eca0f7a4b97d58935f10e3d4b4e272286275..a78659bb1d3f136c36c81f330cfbe5fe4c86d023 100644 (file)
 #include "rpp/rpp.h"
 #include "hal/hal.h"
 
-/**    @brief  Set pins on DIN port to be active or tri-state.
- *
- * Function expects two hexa numbers after ':' in brackets, ie command:(BB,AA).
- * First number sets state of pins SG0 - SG13, second number sets state of pins SP0 - SP7.
- * Bits are assigned from the left to the right pins SP0, SP1...SP7 and SG0, SG1..SG13.
- * 1 set the pin to be tri-state, 0 set the pin to be active.
- *
- * Function creates, sends two SPI commands. One is for SP and the second one is for SG pins.
- * Command receive response from the second command.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_din_st_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-         char *p;
-         int opchar;
-         int i;
-         uint32_t spi_resp;
-         uint32_t values[MAX_PARAM_VALUES_NUM];
-
-         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-         if(opchar==':'){
-           p=param[3];
-               si_skspace(&p);
-               i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
-               if (i != 2)
-                       return -CMDERR_BADPAR;
-           din_set_stat(values[1], values[0]);
-           spi_resp=din_spi_transfer();
-           return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
-         }
-         else return -CMDERR_OPCHAR;
-}
-
-/**    @brief  Enables or disables wake-up and interrupt function for pins on DIN port.
- *
- * Function expects two hexa numbers after ':' in brackets, ie command:(BB,AA).
- * First number sets pins SG0 - SG13, second number sets pins SP0 - SP7.
- * Bits are assigned from the left to the right to pins SP0, SP1...SP7 and SG0, SG1..SG13.
- * 1 - enable interrupt and wake-up function on the pin, 0 - disable those function on the pin.
- *
- * Function creates, sends two SPI commands. One is for SP and the second one is for SG pins.
- * Command receive response from the second command.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_din_int_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-         char *p;
-         int opchar;
-         int i;
-         uint32_t spi_resp;
-         uint32_t values[MAX_PARAM_VALUES_NUM];
-
-         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-         if(opchar==':'){
-           p=param[3];
-               si_skspace(&p);
-               i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
-               if (i != 2)
-                       return -CMDERR_BADPAR;
-
-           din_set_int(values[1], values[0]);
-           spi_resp=din_spi_transfer();
-           return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
-         }
-         else return -CMDERR_OPCHAR;
-}
-
-/**    @brief  Send reset command to DIN
- *
- * Function creates, sends SPI command that resets chip MC33972 and receive response.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_din_reset(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-       din_reset();
-       uint32_t spi_resp = din_spi_transfer();
-       rpp_sci_printf("dinreset: %h", spi_resp);
-       return 0;
-}
-
-/**    @brief  Send switch status command to DIN
- *
- * Function creates, sends SPI command that poll new switches state and receive response.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_din_switch_st(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-       din_switch_st();
-       uint32_t spi_resp = din_spi_transfer();
-       rpp_sci_printf("dinswst: %h", spi_resp);
-       return 0;
-}
-
-/**    @brief  Set programable pins as switch-to-battery or switch-to-ground
- *
- * Function expects one hexa number after ':' in brackets, ie command:(AA).
- * The number sets pins SP0 - SP7.
- * Bits are assigned from the left to the right to pins SP0, SP1...SP7.
- * 1 - set pin as switch-to-battery, 0 - set pin as switch-to-ground.
- *
- * Function creates, sends SPI command and receive response.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_din_pr_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-         char *p;
-         int opchar;
-         int i;
-         uint32_t spi_resp;
-         uint32_t values[MAX_PARAM_VALUES_NUM];
-
-         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-         if(opchar==':'){
-           p=param[3];
-               si_skspace(&p);
-               i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
-               if (i != 1)
-                       return -CMDERR_BADPAR;
-
-           din_set_pr(values[0]);
-           spi_resp=din_spi_transfer();
-           return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
-         }
-         else return -CMDERR_OPCHAR;
+int cmd_do_din_setup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       char *p;
+       int opchar;
+       int ret;
+       int i;
+       uint8_t pin;
+       boolean_t pull_type;
+       boolean_t active;
+       boolean_t can_wake;
+       uint32_t values[MAX_PARAM_VALUES_NUM];
+
+       p = param[1];
+       if(si_long(&p,(long*)&pin, 10) < 10)
+               return -CMDERR_BADPAR;
+       if((opchar=cmd_opchar_check(cmd_io,des,param)) < 0)
+               return opchar;
+       p=param[3];
+       si_skspace(&p);
+       i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+       if (i != 3)
+               return -CMDERR_BADPAR;
+       pull_type = values[0];
+       active = values[1];
+       can_wake = values[2];
+       ret = rpp_din_setup(pin, pull_type, active, can_wake);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
+               return -CMDERR_BADPAR;
+       }
+       else if (ret == -2) {
+               rpp_sci_printf("Selected pin is not programmable to switch to battery.");
+               return -CMDERR_BADPAR;
+       }
+       if (rpp_din_update() == FAILURE) {
+               rpp_sci_printf("DIN SPI transfer failed.");
+               return -CMDERR_EIO;
+       }
+       return cmd_opchar_replong(cmd_io, param, can_wake|active<<8|pull_type<<16, 0, 16);
 }
 
-/**    @brief  Get state of DIN port as 16-b word
- *
- * Function creates, sends SPI command that poll new switches state,
- * receives response and filters just the pins, that are connected to the MC33972.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_din_val_word(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-         int opchar;
-         uint32_t spi_resp;
+int cmd_do_din_get(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       char *p;
+       int opchar;
+       int value;
+       uint8_t pin;
+       boolean_t var_tr;
+
+       if((opchar=cmd_opchar_check(cmd_io,des,param)) < 0)
+               return opchar;
+       p = param[1];
+       if(si_long(&p,(long*)&pin, 10) < 10)
+               return -CMDERR_BADPAR;
+       p = param[3];
+       if(si_long(&p,(long*)&var_tr, 10) < 0)
+               return -CMDERR_BADPAR;
 
-         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+       if (rpp_din_update() == FAILURE) {
+               rpp_sci_printf("DIN SPI transfer failed.");
+               return -CMDERR_EIO;
+       }
 
-         if(opchar=='?') {
-           din_switch_st();
-               din_spi_transfer();
-               spi_resp=din_get_val_word();
-           return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
-         }
-         else return -CMDERR_OPCHAR;
+       value = rpp_din_get(pin, var_tr);
+       if (value == -1) {
+               rpp_sci_printf("Pin out of range.");
+               return -CMDERR_BADPAR;
+       }
+       else if (value == -2) {
+               rpp_sci_printf("Selected pin can not be read with threshold");
+               return -CMDERR_BADPAR;
+       }
+       return cmd_opchar_replong(cmd_io, param, value, 0, 16);
 }
 
-/**    @brief  Get state of DIN port in human readable form
- *
- * Function creates, sends SPI command that poll new switches state,
- * receives response and translates it to human readable form.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_din_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-       uint32_t numCmdDesc;
-       int i;
-       uint32_t numFieldDesc;
-
-       din_switch_st();
-       uint32_t din_spi_resp = din_spi_transfer();
+int cmd_do_din_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       char *p;
+       int opchar;
+       int value;
+       uint8_t pin;
 
-       spitr_reg_translate_table_t translatedData;
+       if((opchar=cmd_opchar_check(cmd_io,des,param)) < 0)
+               return opchar;
+       p = param[1];
+       if(si_long(&p,(long*)&pin, 10) < 10)
+               return -CMDERR_BADPAR;
 
-       const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_DINSPI, -1, &numCmdDesc);
-       if(cmdDesc == NULL) return -CMDERR_BADREG;
+       if (rpp_din_update() == FAILURE) {
+               rpp_sci_printf("DIN SPI transfer failed.");
+               return -CMDERR_EIO;
+       }
 
-       const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, din_spi_get_cmd(), &numFieldDesc);
-       if (fieldDescs == NULL)
+       value = rpp_din_diag(pin);
+       if (value == -1) {
+               rpp_sci_printf("Pin out of range.");
                return -CMDERR_BADPAR;
-       uint32_t lsbResponse = 0 | ((din_spi_resp & 0xFF) << 16 ) | ((din_spi_resp & 0xFF0000) >> 16) | (din_spi_resp & 0xFF00);
-       spitr_fill_tr_table(fieldDescs, numFieldDesc, lsbResponse, &translatedData);
-
-       for (i = 0; i < translatedData.num_rows; i++) {
-               rpp_sci_printf("%s: %h\r\n", translatedData.row[i].field_name, translatedData.row[i].value);
        }
-       return cmd_opchar_replong(cmd_io, param, din_spi_resp, 0, 16);
+       return cmd_opchar_replong(cmd_io, param, value, 0, 16);
 }
 
-
-
 /** Command descriptor for din state command */
-cmd_des_t const cmd_des_din_st_word={
-       0, CDESM_OPCHR|CDESM_WR,
-       "dinportst","\tdinportst:(wrsg,wrsp) - writes word wr (8b) into din sg and sp. 1 - tri-state, 0 - active.",
-       cmd_do_din_st_wr, (void *)&cmd_list_din
-};
-
-/** Command descriptor for din switch-to-ground/battery command */
-cmd_des_t const cmd_des_din_pr_word={
-       0, CDESM_OPCHR|CDESM_WR,
-       "dinportpr","\tdinportpr:(wr) - writes word wr (8b) into din. 1 - switch-to-bat, 0 - switch-to-gnd.",
-       cmd_do_din_pr_wr, (void *)&cmd_list_din
-};
-
-/** Command descriptor for din enable interrupts command */
-cmd_des_t const cmd_des_din_int_word={
+cmd_des_t const cmd_des_din_setup={
        0, CDESM_OPCHR|CDESM_WR,
-       "dinportint","\tdinportint:(wrsg, wrsp) - writes word wr (16b) into din sg and sp. 1 - enable interrupt, 0 - disable interrupt.",
-       cmd_do_din_int_wr, (void *)&cmd_list_din
+       "dinsetup#","\tdinsetupX:(pull-type,active,can-wake) - Sets up DIN X pin.\r\n"
+       "\tPull-type: 1 - pull up (switch-to-ground); 0 - pull down (switch-to-battery)\r\n"
+       "\tActive: 1 - tri-state; 0 - active\r\n"
+       "\tCan-wake: 1 - pin can wake module up and set an interrupt; 0 - wake up and interrupt disabled.",
+       cmd_do_din_setup, (void *)&cmd_list_din
 };
 
-/** Command descriptor for din reset command */
-cmd_des_t const cmd_des_din_rst={
-       0, 0,
-       "dinreset","\tdinreset - send reset command to DIN",
-       cmd_do_din_reset, (void *)&cmd_list_din
-};
-
-/** Command descriptor for din switch state command */
-cmd_des_t const cmd_des_din_sw_st={
-       0, 0,
-       "dinswst","\tdinswst - Send switch status to DIN",
-       cmd_do_din_switch_st, (void *)&cmd_list_din
-};
-
-/** Command descriptor for din get value command */
-cmd_des_t const cmd_des_din_val_word={
+/** Command descriptor for din state command */
+cmd_des_t const cmd_des_din_get={
        0, CDESM_OPCHR|CDESM_RD,
-       "dinportval","\tdinportval? - reads values from DIN port as 16b word",
-       cmd_do_din_val_word, (void *)&cmd_list_din
+       "dinget#","\tdingetX? Read value from DIN X pin",
+       cmd_do_din_get, (void *)&cmd_list_din
 };
 
-/** Command descriptor for din get state command */
-cmd_des_t const cmd_des_din_stat={
-       0, 0,
-       "dinstat","\tdinstat - get DIN status in human readable form",
-       cmd_do_din_status, (void *)&cmd_list_din
+/** Command descriptor for din state command */
+cmd_des_t const cmd_des_din_diag={
+       0, CDESM_OPCHR|CDESM_RD,
+       "dindiag#","\tdindiagX? Read diagnostic value from DIN X pin",
+       cmd_do_din_diag, (void *)&cmd_list_din
 };
 
 /** List of commands for din, defined as external */
 cmd_des_t const *cmd_list_din[]={
-  &cmd_des_din_st_word,
-  &cmd_des_din_pr_word,
-  &cmd_des_din_int_word,
-  &cmd_des_din_rst,
-  &cmd_des_din_sw_st,
-  &cmd_des_din_val_word,
-  &cmd_des_din_stat,
+  &cmd_des_din_setup,
+  &cmd_des_din_get,
+  &cmd_des_din_diag,
   NULL
 };
index 03c594236241406dae4991e576410ef21419990a..fc77ed9b91adca308e92de1ae09e0cafaa19c857 100644 (file)
 #include "drv/drv.h"
 
 
-/**
- *     @brief  Start periodic HBR watchdog reset.
- *
- *     Command syntax: hbrwdg
- *
- *     Command, if launched for the first time, creates new thread, which
- *     is sending watchdog reset command to H-bridge each 10ms.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     always 0
- */
-int cmd_do_hbr_wdg(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-       int ret = drv_hbr_wdg_start();
-       if (ret == FAILURE) {
-               rpp_sci_printf("FAILED\r\n");
-       }
-       else {
-               rpp_sci_printf("SUCCESS\r\n");
-       }
-       return 0;
-}
-
-/**
- *     @brief  Set or get actual pwm parameters
- *
- *     Command syntax: hbrpwm:(p,d)    - set p as a period in us and D as duty cycle in % of the period.
- *                                     hbrpwm? - Get actual PWM parameters, period in us and duty cycle in % of the period.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_hbr_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-         char *p;
-         int opchar;
-         int i;
-         uint32_t values[MAX_PARAM_VALUES_NUM];
-
-         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-         if(opchar==':'){
-           p=param[3];
-               si_skspace(&p);
-               i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
-               if (i < 0)
-                       return i;
-               if (i != 2)
-                       return -CMDERR_BADPAR;
-               if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
-               drv_hbr_pwm_set_signal((double)values[0], values[1]);
-           return 0;
-         }
-         else{
-               double period = drv_hbr_pwm_get_period();
-               uint32_t duty = drv_hbr_pwm_get_duty();
+int cmd_do_hbr_enable(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       char *p;
+       int opchar;
+       uint32_t period;
+       int ret;
 
-               rpp_sci_printf("hbr_pwm_period: %d\r\nhbr_pwm_duty: %d/%", period, duty);
-           return 0;
-         }
-}
+       if((opchar=cmd_opchar_check(cmd_io,des,param)) < 0)
+               return opchar;
+       p = param[3];
+       if(si_long(&p,(long*)&period, 10) < 10)
+               return -CMDERR_BADPAR;
 
-/**
- *     @brief  Start PWM, if it was previously set by hbrpwm command
- *
- *     Command syntax: hbrpwmstart
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_hbr_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       int ret = drv_hbr_pwm_start();
-       if (ret == -1) {
-               rpp_sci_printf("PWM was not initialized.\r\n");
-               return -CMDERR_BADCFG;
-       }
-       else {
-               return 0;
+       ret = rpp_hbr_enable(period);
+       if (ret == FAILURE) {
+               rpp_sci_printf("Enable procedure failed.");
        }
-}
 
-/**
- *     @brief  Stop PWM
- *
- *     Command syntax: hbrpwmstop
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_hbr_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       drv_hbr_pwm_stop();
-       return 0;
+       return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
 }
 
-/**
- *     @brief  Set or Get HBR_EN
- *
- *     Command syntax: hbren:v - set v to HBR_EN pin
- *                                     hbren?  - get value from HBR_EN
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_hbr_en(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-       int val;
-       char* p;
+int cmd_do_hbr_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       char *p;
        int opchar;
+       int8_t cmd;
+       int ret;
 
-       if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+       if((opchar=cmd_opchar_check(cmd_io,des,param)) < 0)
+               return opchar;
+       p = param[3];
+       if(si_long(&p,(long*)&cmd, 10) < 10)
+               return -CMDERR_BADPAR;
 
-       if(opchar==':'){
-               p=param[3];
-               si_skspace(&p);
-               if(si_long(&p,(long*)&val,0)<0) return -CMDERR_BADPAR;
-               if (val != 1 && val != 0) return -CMDERR_BADPAR;
-               drv_hbr_set_en(val);
-               return cmd_opchar_replong(cmd_io, param, val, 0, 16);
+       ret = rpp_hbr_control(cmd/((double)100));
+       if (ret == -1) {
+               rpp_sci_printf("H-bridge not enabled.");
+               return -1;
        }
-       else{
-               val = drv_hbr_get_en();
-               return cmd_opchar_replong(cmd_io, param, val, 0, 16);
+       else if (ret == -2) {
+               rpp_sci_printf("Command out of range.");
+               return -CMDERR_BADPAR;
        }
+       return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
 }
 
-/**
- *     @brief  Set or get HBR_DIR
- *
- *     Command syntax: hbrdir:v - set v to HBR_DIR pin
- *                                     hbrdir?  - get value from HBR_DIR
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_hbr_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-       int dir;
-       char* p;
-       int opchar;
-
-       if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-       if(opchar==':'){
-               p=param[3];
-               si_skspace(&p);
-               if(si_long(&p,(long*)&dir,0)<0) return -CMDERR_BADPAR;
-               if (dir != 1 && dir != 0) return -CMDERR_BADPAR;
-               drv_hbr_set_dir(dir);
-               return cmd_opchar_replong(cmd_io, param, dir, 0, 16);
-       }
-       else{
-               dir = drv_hbr_get_dir();
-               return cmd_opchar_replong(cmd_io, param, dir, 0, 16);
+int cmd_do_hbr_disable(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       int ret;
+       ret = rpp_hbr_disable();
+       if (ret == FAILURE) {
+               rpp_sci_printf("H-bridge already disabled.");
        }
+       return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
 }
 
 /** Command descriptor for HBR reset watchdog command */
-cmd_des_t const cmd_des_hbr_wdg={
-    0, 0,
-    "hbrwdg","Send repeated HBR WDG reset command",
-    cmd_do_hbr_wdg, (void *)&cmd_list_hbr
+cmd_des_t const cmd_des_hbr_enable = {
+    0, CDESM_OPCHR|CDESM_WR,
+    "hbrenable","Enables H-bridge with given period.",
+    cmd_do_hbr_enable, (void *)&cmd_list_hbr
 };
 
-/** Command descriptor for HBR set PWM command */
-cmd_des_t const cmd_des_hbr_pwm={
-    0, CDESM_OPCHR|CDESM_RW,
-    "hbrpwm*","\t- hbrpwm:(period,duty) set pwm period in us and duty in % of period\r\n\t\thbrpwm? read period in us and duty in % of period from hbrpwm.",
-       cmd_do_hbr_pwm, (void *)&cmd_list_hbr
-};
-
-/** Command descriptor for PWM start command */
-cmd_des_t const cmd_des_hbr_pwm_start={
-    0, 0,
-    "hbrpwmstart","\t- hbrpwmstart - Start generating of pwm signal on HBR",
-       cmd_do_hbr_pwm_start, (void *)&cmd_list_hbr
+/** Command descriptor for HBR reset watchdog command */
+cmd_des_t const cmd_des_hbr_control = {
+    0, CDESM_OPCHR|CDESM_WR,
+    "hbrcontrol","Sets direction and PWM duty cycle <-100; 100>",
+    cmd_do_hbr_control, (void *)&cmd_list_hbr
 };
 
-/** Command descriptor for PWM stop command */
-cmd_des_t const cmd_des_hbr_pwm_stop={
+/** Command descriptor for HBR reset watchdog command */
+cmd_des_t const cmd_des_hbr_disable = {
     0, 0,
-    "hbrpwmstop","\t- hbrpwmstop - Stop generating of pwm signal on HBR",
-       cmd_do_hbr_pwm_stop, (void *)&cmd_list_hbr
-};
-
-/** Command descriptor for set/get HBR_EN command */
-cmd_des_t const cmd_des_hbr_en={
-    0, CDESM_OPCHR|CDESM_RW,
-    "hbren","\t- hbren:val set hbr_en to 0 (disable) or 1 (enable) \r\n\t\thbren? Get value of hbr_en pin.",
-       cmd_do_hbr_en, (void *)&cmd_list_hbr
-};
-
-/** Command descriptor for set/get HBR_dir set PWM command */
-cmd_des_t const cmd_des_hbr_dir={
-    0, CDESM_OPCHR|CDESM_RW,
-    "hbrdir","\t- hbrdir:val set hbr_dir to 0 or 1\r\n\t\thbren? Get value of hbr_dir pin.",
-       cmd_do_hbr_dir, (void *)&cmd_list_hbr
+    "hbrdisable","Disables H-bridge",
+    cmd_do_hbr_disable, (void *)&cmd_list_hbr
 };
 
 /** List of commands for hbr, defined as external */
 cmd_des_t const *cmd_list_hbr[]={
-  &cmd_des_hbr_wdg,
-  &cmd_des_hbr_pwm,
-  &cmd_des_hbr_pwm_start,
-  &cmd_des_hbr_pwm_stop,
-  &cmd_des_hbr_en,
-  &cmd_des_hbr_dir,
+  &cmd_des_hbr_enable,
+  &cmd_des_hbr_control,
+  &cmd_des_hbr_disable,
   NULL
 };
index 39d3200b19f5ae3b88594fad1eddef7f532441c0..64b0c4c8d49956801eae49c9cca8953f9121042e 100644 (file)
 #include "cmdproc_utils.h"
 #include "drv/drv.h"
 
-/**
- * @brief      Set and get value on LOUT port
- *
- * Command syntax:     loutwr:(val)    - Set value val to port. 1st bit of val -> LOUT1, 2nd bit of val -> LOUT2 etc.
- *                                     loutwr?         - Get value on LOUT port.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_lout_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
-         char *p;
-         int opchar;
-         int i;
-         uint32_t ret;
-         uint32_t values[MAX_PARAM_VALUES_NUM];
-
-         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-         if(opchar==':'){
-           p=param[3];
-               si_skspace(&p);
-               i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
-               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);
-         }
-}
 
-/**
- * @brief      Set and get value on specified LOUT pin
- *
- * Command syntax:     loutval#:v      - Set value v to pin #. V must be 0 or 1, # in range 1-8
- *                                     loutval#?       - Get value on pin #, in range 1-8.
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-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;
+int cmd_do_lout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       int opchar;
+       uint8_t pin;
+       int ret;
+       uint8_t val;
+       char *p;
+
+       if((opchar=cmd_opchar_check(cmd_io,des,param))<0)
+               return opchar;
+       p=param[1];
+       if(si_long(&p,(long*)&pin,0) < 10)
+               return -CMDERR_BADPAR;
+       p=param[3];
+       if(si_long(&p,(long*)&val,10) < 0)
+               return -CMDERR_BADPAR;
+       ret = rpp_lout_set(pin, val);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
+               return -CMDERR_BADPAR;
+       }
 
-         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 (rpp_lout_update() == FAILURE) {
+               rpp_sci_printf("LOUT update failed.");
+               return -CMDERR_EIO;
+       }
 
-         if(opchar==':'){
-           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{
-               ret = lout_get_pin(pin);
-           return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
-         }
+       return cmd_opchar_replong(cmd_io, param, val, 0, 10);
 }
 
-/**
- * @brief      Get status of LOUT in human readable form
- *
- * Command syntax:     loutstat
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-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;
-       uint32_t numFieldDesc;
+int cmd_do_lout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       int opchar;
+       uint8_t pin;
+       int ret;
+       char *p;
 
+       if((opchar=cmd_opchar_check(cmd_io,des,param))<0)
+               return opchar;
+       p=param[1];
+       if(si_long(&p,(long*)&pin,0) < 10)
+               return -CMDERR_BADPAR;
 
-       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;
+       if (rpp_lout_update() == FAILURE) {
+               rpp_sci_printf("LOUT update failed.");
+               return -CMDERR_EIO;
+       }
 
-       const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, lout_spi_get_cmd(), &numFieldDesc);
-       if (fieldDescs == NULL)
+       ret = rpp_lout_diag(pin);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
                return -CMDERR_BADPAR;
-       ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, lout_spi_get_response(), &translatedData);
-
-       for (i = 0; i < translatedData.num_rows; i++) {
-               rpp_sci_printf("%s: %h\r\n", translatedData.row[i].field_name, translatedData.row[i].value);
        }
+
        return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
 }
 
 /** Command descriptor for lout get/set port value */
-cmd_des_t const cmd_des_lout_wr={
-       0, CDESM_OPCHR|CDESM_RW,
-       "loutwr","\tloutwr:(wr) - writes word wr in LOUT\r\n\t\tloutwr? - reads word from LOUT",
-       cmd_do_lout_wr, (void *)&cmd_list_lout
+cmd_des_t const cmd_des_lout_set={
+       0, CDESM_OPCHR|CDESM_WR,
+       "loutset#","\tloutsetX:Y - Set Y value to LOUT X pin",
+       cmd_do_lout_set, (void *)&cmd_list_lout
 };
 
 /** Command descriptor for lout get/set pin value */
-cmd_des_t const cmd_des_lout_val={
-       0, CDESM_OPCHR|CDESM_RW,
-       "loutval#","\tloutvalX:Y - writes bit Y on LOUTX\r\n\t\tloutvalX? - reads bit from LOUTX",
-       cmd_do_lout_val, (void *)&cmd_list_lout
+cmd_des_t const cmd_des_lout_diag={
+       0, CDESM_OPCHR|CDESM_RD,
+       "loutdiag#","\tloutdiagX? - Reads diag value from LOUT X pin",
+       cmd_do_lout_diag, (void *)&cmd_list_lout
 };
 
-/** Command descriptor for lout get status */
-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_lout
-       };
 
 /** List of commands for hout, defined as external */
 cmd_des_t const *cmd_list_lout[]={
-  &cmd_des_lout_wr,
-  &cmd_des_lout_val,
-  &cmd_des_lout_status,
+  &cmd_des_lout_set,
+  &cmd_des_lout_diag,
   NULL
 };