stub of SPI write cmd, multicast cmd

sipo
Ondřej Hruška 7 years ago
parent 0f75690310
commit 913f431a54
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      gex.mk
  2. 2
      platform/platform.c
  3. 63
      units/spi/unit_spi.c
  4. 17
      units/spi/unit_spi.h
  5. 1
      utils/error.h

@ -11,6 +11,7 @@ GEX_SRC_DIR = \
User/units/digital_out \
User/units/digital_in \
User/units/i2c \
User/units/spi \
User/TinyFrame \
User/CWPack \
User/tasks

@ -13,6 +13,7 @@
#include "units/neopixel/unit_neopixel.h"
#include "units/i2c/unit_i2c.h"
#include "units/test/unit_test.h"
#include "units/spi/unit_spi.h"
void plat_init_resources(void)
{
@ -77,6 +78,7 @@ void plat_init_resources(void)
ureg_add_type(&UNIT_DIN);
ureg_add_type(&UNIT_NEOPIXEL);
ureg_add_type(&UNIT_I2C);
ureg_add_type(&UNIT_SPI);
// Free all present resources
{

@ -417,27 +417,72 @@ static void USPI_deInit(Unit *unit)
// ------------------------------------------------------------------------
error_t UU_SPI_Multicast(Unit *unit, uint16_t slaves,
const uint8_t *request,
uint32_t req_len)
{
//
return E_NOT_IMPLEMENTED;
}
error_t UU_SPI_Write(Unit *unit, uint8_t slave_num,
const uint8_t *request,
uint8_t *response,
uint32_t req_len,
uint32_t resp_skip,
uint32_t resp_len)
{
//
return E_NOT_IMPLEMENTED;
}
enum PinCmd_ {
CMD_WRITE = 0,
CMD_MULTICAST = 1,
};
/** Handle a request message */
static error_t USPI_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
{
uint16_t addr;
uint32_t len;
uint8_t regnum;
uint32_t size;
uint8_t slave;
uint16_t slaves;
uint16_t req_len;
uint16_t resp_skip;
uint16_t resp_len;
const uint8_t *bb;
// NOTE: 10-bit addresses must have the highest bit set to 1 for indication (0x8000 | addr)
uint32_t len;
switch (command) {
/** Write byte(s) - addr:u16, byte(s) */
/** Write and read byte(s) - slave_num:u8, req_len:u16, resp_skip:u16, resp_len:u16, byte(s) */
case CMD_WRITE:
addr = pp_u16(pp);
const uint8_t *bb = pp_tail(pp, &len);
slave = pp_u8(pp);
req_len = pp_u16(pp);
resp_skip = pp_u16(pp);
resp_len = pp_u16(pp);
bb = pp_tail(pp, &len);
return UU_SPI_Write(unit, addr, bb, len); // TODo implement function + SPI pins mapping
TRY(UU_SPI_Write(unit, slave,
bb, (uint8_t *) unit_tmp512,
req_len, resp_skip, resp_len));
com_respond_buf(frame_id, MSG_SUCCESS, (uint8_t *) unit_tmp512, resp_len);
return E_SUCCESS;
/** Write byte(s) to multiple slaves - slaves:u16, req_len:u16, byte(s) */
case CMD_MULTICAST:
slaves = pp_u16(pp);
req_len = pp_u16(pp);
bb = pp_tail(pp, &len);
TRY(UU_SPI_Multicast(unit, slaves, bb, req_len));
return E_SUCCESS;
default:
return E_UNKNOWN_COMMAND;

@ -30,7 +30,7 @@ extern const UnitDriver UNIT_SPI;
* |<-- resp_len -->|
*
* @param unit - SPI unit
* @param slave_num - slave number (SS pin index)
* @param slave_num - slave number (SS pin index, counted from least significant bit)
* @param request - request bytes buffer
* @param response - response bytes buffer
* @param req_len - number of bytes in the request. Will be right-padded with zeros.
@ -45,4 +45,19 @@ error_t UU_SPI_Write(Unit *unit, uint8_t slave_num,
uint32_t resp_skip,
uint32_t resp_len);
/**
* Write to multiple slaves at once.
* This is similar to UU_SPI_Write, but performs no read and works only if the device
* is configured as tx-only.
*
* @param unit - SPI unit
* @param slaves - bitmap of slaves to write (packed bits representing the SSN pins)
* @param request - request bytes buffer
* @param req_len - length of the request buffer
* @return success
*/
error_t UU_SPI_Multicast(Unit *unit, uint16_t slaves,
const uint8_t *request,
uint32_t req_len);
#endif //GEX_F072_UNIT_SPI_H

@ -42,6 +42,7 @@
X(OVERRUN, NULL) /* used in bulk transfer */ \
X(PROTOCOL_BREACH, NULL) /* eating with the wrong spoon */ \
X(BAD_UNIT_TYPE, NULL) \
X(NOT_IMPLEMENTED, NULL) \
\
/* VFS user errors (those are meant to be shown to user) */ \
X(ERROR_DURING_TRANSFER, "Error during transfer") \

Loading…
Cancel
Save