* Authors:
* - Michal Horn
*
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*
* File : cmd_spi.c
*
*/
int cmd_do_spi_translate(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
{
- char *p;
- int i;
- uint32_t ret;
- uint32_t values[MAX_PARAM_VALUES_NUM];
- uint32_t numFieldDesc;
- uint32_t numCmdDesc;
uint32_t command;
uint32_t response;
- spitr_reg_translate_table_t translatedData;
char peripheralName[32];
char spareParams;
- p = param[1];
- if (sscanf(p, "%31s ", peripheralName) != 1)
+ if (sscanf(param[1], "%31s ", peripheralName) != 1)
return -CMDERR_BADPAR;
- const spitr_cmd_map_t *cmdDesc = cmdDesc = get_spi_cmd_map(peripheralName, -1, &numCmdDesc);
- if (cmdDesc == NULL) return -CMDERR_BADREG;
+ const spitr_port_cmds_t *cmds = spitr_get_cmds_by_port_name(peripheralName);
+ if (cmds == NULL) return -CMDERR_BADREG;
if (param[2] != NULL) { // More parameters expected
- p = param[2];
- if (sscanf(p, "%x %x %1s", &values[0], &values[1], &spareParams) != 2)
+ if (sscanf(param[2], "%x %x %1s", &command, &response, &spareParams) != 2)
return -CMDERR_BADPAR;
- command = values[0];
- response = values[1];
- const spitr_field_desc_t *fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, command, &numFieldDesc);
- if (fieldDescs == NULL)
- return -CMDERR_BADPAR;
+ const spitr_cmd_desc_t *cmd_desc = get_spi_cmd_desc(cmds, command);
+ if (!cmd_desc)
+ return -CMDERR_BADCMD;
- ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, response, &translatedData);
+ spitr_print_resp(cmd_desc, response);
- for (i = 0; i < translatedData.num_rows; i++) {
- rpp_sci_printf("%s: %x\r\n", translatedData.row[i].field_name, translatedData.row[i].value);
- }
- return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
+ return cmd_opchar_replong(cmd_io, param, 0, 0, 10);
}
else
return -CMDERR_BADPAR;
uint8_t spi_test_buf_tx[TEST_BUF];
uint8_t spi_test_buf_rx[TEST_BUF];
-int spimst_print_rx(struct spi_drv *ifc, int status, int addr, uint8_t *buf)
+int spimst_print_rx(int status, uint8_t *buf)
{
int i;
return -1;
}
- rpp_sci_printf("spirx:%#x(", addr);
+ rpp_sci_printf("spirx:(");
for (i = 0; i < status; i++) {
rpp_sci_printf("%#x", buf[i]);
if (i < status-1)
*/
int cmd_do_spimst(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
{
- spi_drv_t *ifc;
int i;
char *p;
char *token;
int ret;
- unsigned int addr;
unsigned int rq_len;
- int spi;
+ enum spi_device dev;
int values[MAX_PARAM_VALUES_NUM];
p = param[1];
- if (sscanf(p, "%d", &spi) != 1)
+ if (sscanf(p, "%d", &i) != 1)
return -CMDERR_BADPAR;
- p = param[2];
- if (sscanf(p, " %d", &addr) != 1)
+ dev = (enum spi_device)i;
+ if (dev >= _SPIDEV_COUNT)
return -CMDERR_BADPAR;
token = strtok(p, " ");
token = strtok(NULL, " ");
i++;
}
-
- ifc = spi_find_drv(NULL, spi);
- if (ifc == NULL)
- return -CMDERR_NODEV;
-
- if (!(ifc->flags & SPI_IFC_ON))
- //if (spi_tms570_init(ifc) < 0)
- return -CMDERR_BADCFG;
-
rq_len = i;
- ret = spi_transfer(ifc, addr, rq_len, spi_test_buf_tx, spi_test_buf_rx);
- spimst_print_rx(ifc, ret, addr, spi_test_buf_rx);
+ ret = spi_transfer(dev, rq_len, spi_test_buf_tx, spi_test_buf_rx);
+ spimst_print_rx(ret, spi_test_buf_rx);
return 0;
}