Skip to content

Commit 9a74a01

Browse files
cvejlbofacchinm
authored andcommitted
Update to tiny ilib v91
1 parent 6466f0e commit 9a74a01

File tree

8 files changed

+223
-36
lines changed

8 files changed

+223
-36
lines changed

libraries/NDP/examples/AlexaDemo/AlexaDemo.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ void setup() {
4444
NDP.onMatch(ledBlueOn);
4545
NDP.onEvent(ledGreenOn);
4646
Serial.println("Loading synpackages");
47-
NDP.begin("mcu_fw_120_v90.synpkg");
48-
NDP.load("dsp_firmware_v90.synpkg");
49-
NDP.load("alexa_334_NDP120_B0_v11_v90.synpkg");
47+
NDP.begin("mcu_fw_120_v91.synpkg");
48+
NDP.load("dsp_firmware_v91.synpkg");
49+
NDP.load("alexa_334_NDP120_B0_v11_v91.synpkg");
5050
Serial.println("packages loaded");
5151
NDP.getInfo();
5252
Serial.println("Configure clock");

libraries/NDP/examples/Record_and_stream/Record_and_stream.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ void setup() {
5050

5151
encoder.setOutputStream(Serial);
5252

53-
NDP.begin("mcu_fw_120_v90.synpkg");
54-
NDP.load("dsp_firmware_v90.synpkg");
55-
NDP.load("alexa_334_NDP120_B0_v11_v90.synpkg");
53+
NDP.begin("mcu_fw_120_v91.synpkg");
54+
NDP.load("dsp_firmware_v91.synpkg");
55+
NDP.load("alexa_334_NDP120_B0_v11_v91.synpkg");
5656
NDP.turnOnMicrophone();
5757
int chunk_size = NDP.getAudioChunkSize();
5858
if (chunk_size >= sizeof(data)) {
-20.1 KB
Binary file not shown.
22.1 KB
Binary file not shown.

libraries/syntiant_ilib/src/syntiant_ndp120_tiny.c

+163-27
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ enum {
305305
SYNTIANT_NDP120_GET_NN_GRAPH = 0x67,
306306
SYNTIANT_NDP120_GET_DEBUG_INFO = 0x68,
307307
SYNTIANT_NDP120_GET_NN_FLOW = 0x69,
308-
SYNTIANT_NDP120_GET_AUDIO_CHUNK_SIZE = 0x6a
308+
SYNTIANT_NDP120_GET_AUDIO_CHUNK_SIZE = 0x6a,
309+
SYNTIANT_NDP120_INPUT_CONFIG = 0x6b,
310+
SYNTIANT_NDP120_SET_SPI_DIRECT = 0x6c,
311+
SYNTIANT_NDP120_SWITCH_FLOW_SET_ID = 0x6d
309312
};
310313

311314
enum {
@@ -1135,33 +1138,10 @@ syntiant_ndp120_tiny_poll(struct syntiant_ndp120_tiny_device_s *ndp,
11351138

11361139
*notifications = 0;
11371140

1138-
retry:
1139-
11401141
s = syntiant_ndp120_tiny_read(
11411142
ndp, SYNTIANT_NDP120_SPI_OP, NDP120_SPI_INTSTS, &intsts);
11421143
if (s) goto error;
11431144

1144-
/* this is unlikely, and is probably a result of a reset.
1145-
ignoring this causes false notifications that often
1146-
result in a host crash */
1147-
1148-
if (intsts == 0xFF) {
1149-
uint8_t id;
1150-
uint32_t timeout = 0xffffffff;
1151-
do {
1152-
s = syntiant_ndp120_tiny_read(
1153-
ndp, SYNTIANT_NDP120_SPI_OP, NDP120_SPI_ID0, &id);
1154-
if (s) goto error;
1155-
if (id != 0xFF) {
1156-
goto retry;
1157-
}
1158-
timeout--;
1159-
} while (timeout);
1160-
1161-
*notifications = SYNTIANT_NDP120_NOTIFICATION_ERROR;
1162-
goto error;
1163-
}
1164-
11651145
if (clear) {
11661146
s = syntiant_ndp120_tiny_write(
11671147
ndp, SYNTIANT_NDP120_SPI_OP, NDP120_SPI_INTSTS, intsts);
@@ -1794,7 +1774,7 @@ int syntiant_ndp120_tiny_send_audio_extract(struct syntiant_ndp120_tiny_device_s
17941774
}
17951775
}
17961776

1797-
/* write secure cmd */
1777+
/* write cmd */
17981778
s = syntiant_ndp120_tiny_write(ndp, SYNTIANT_NDP120_MCU_OP, addr, cmd);
17991779
addr += (uint32_t) sizeof(cmd);
18001780
if (s) goto error;
@@ -1808,11 +1788,109 @@ int syntiant_ndp120_tiny_send_audio_extract(struct syntiant_ndp120_tiny_device_s
18081788
s = syntiant_ndp120_tiny_write_block(ndp, SYNTIANT_NDP120_MCU_OP, addr, &extract_from, sizeof(extract_from));
18091789
if (s) goto error;
18101790

1811-
/* send secure command */
1791+
/* send command */
1792+
s = syntiant_ndp120_tiny_do_mailbox_req_no_sync(ndp,
1793+
SYNTIANT_NDP120_MB_MCU_CMD, NULL);
1794+
if (s) goto error;
1795+
1796+
error:
1797+
if (ndp->iif->unsync) {
1798+
s0 = (ndp->iif->unsync)(ndp->iif->d);
1799+
s = s ? s : s0;
1800+
}
1801+
return s;
1802+
}
1803+
1804+
int syntiant_ndp120_tiny_spi_direct_config(struct syntiant_ndp120_tiny_device_s *ndp,
1805+
uint32_t threshold_bytes)
1806+
{
1807+
uint8_t data_8;
1808+
int s0;
1809+
int s = SYNTIANT_NDP120_ERROR_NONE;
1810+
uint32_t addr = SYNTIANT_NDP120_DL_WINDOW_LOWER;
1811+
/*uint32_t address = SYNTIANT_NDP120_OPEN_RAM_RESULTS;*/
1812+
uint32_t cmd = SYNTIANT_NDP120_SET_SPI_DIRECT;
1813+
uint32_t length = sizeof(threshold_bytes);
1814+
if (ndp->iif->sync) {
1815+
s = (ndp->iif->sync)(ndp->iif->d);
1816+
if (s) {
1817+
SYNTIANT_NDP120_PRINTF("Error in syntiant_ndp120_tiny_spi_direct_config\n");
1818+
return s;
1819+
}
1820+
}
1821+
1822+
/* write cmd */
1823+
s = syntiant_ndp120_tiny_write(ndp, SYNTIANT_NDP120_MCU_OP, addr, cmd);
1824+
addr += (uint32_t) sizeof(cmd);
1825+
if (s) goto error;
1826+
/* write the length of payload */
1827+
s = syntiant_ndp120_tiny_write(ndp, SYNTIANT_NDP120_MCU_OP, addr, length);
1828+
if (s) goto error;
1829+
1830+
addr += (uint32_t) sizeof(length);
1831+
/* write payload */
1832+
s = syntiant_ndp120_tiny_write_block(ndp, SYNTIANT_NDP120_MCU_OP, addr, &threshold_bytes, sizeof(threshold_bytes));
1833+
if (s) goto error;
1834+
/* send command */
1835+
s = syntiant_ndp120_tiny_do_mailbox_req_no_sync(ndp,
1836+
SYNTIANT_NDP120_MB_MCU_CMD, NULL);
1837+
if (s) goto error;
1838+
/*enabling watermark interrupt*/
1839+
s = ndp_spi_read(NDP120_SPI_INTCTL, &data_8);
1840+
if(s) goto error;
1841+
data_8 = NDP120_SPI_INTCTL_WM_INTEN_INSERT(data_8, 1);
1842+
ndp_spi_write(NDP120_SPI_INTCTL, data_8);
1843+
1844+
error:
1845+
if (ndp->iif->unsync) {
1846+
s0 = (ndp->iif->unsync)(ndp->iif->d);
1847+
s = s ? s : s0;
1848+
}
1849+
return s;
1850+
}
1851+
1852+
int
1853+
syntiant_ndp120_tiny_switch_dnn_flow(struct syntiant_ndp120_tiny_device_s *ndp,
1854+
uint32_t flow_set_id, uint32_t *input_mode)
1855+
{
1856+
uint8_t data_8;
1857+
int s0;
1858+
int s = SYNTIANT_NDP120_ERROR_NONE;
1859+
uint32_t addr = SYNTIANT_NDP120_DL_WINDOW_LOWER;
1860+
uint32_t address = SYNTIANT_NDP120_OPEN_RAM_RESULTS;
1861+
uint32_t cmd[3] = {SYNTIANT_NDP120_SWITCH_FLOW_SET_ID, sizeof(flow_set_id), 0};
1862+
if (ndp->iif->sync) {
1863+
s = (ndp->iif->sync)(ndp->iif->d);
1864+
if (s) {
1865+
SYNTIANT_NDP120_PRINTF("Error in syntiant_ndp120_tiny_switch_dnn_flow\n");
1866+
return s;
1867+
}
1868+
}
1869+
cmd[2] = flow_set_id;
1870+
1871+
/* write cmd, length of the payload and payload */
1872+
s = syntiant_ndp120_tiny_write_block(ndp, SYNTIANT_NDP120_MCU_OP, addr,
1873+
&cmd, sizeof(cmd));
1874+
if (s) goto error;
1875+
18121876
s = syntiant_ndp120_tiny_do_mailbox_req_no_sync(ndp,
18131877
SYNTIANT_NDP120_MB_MCU_CMD, NULL);
18141878
if (s) goto error;
18151879

1880+
/* read input_mode */
1881+
s = syntiant_ndp120_tiny_read_block(ndp,SYNTIANT_NDP120_MCU_OP, address, input_mode,
1882+
sizeof(*input_mode));
1883+
if (s) goto error;
1884+
1885+
if (*input_mode == SYNTIANT_NDP120_TINY_INPUT_CONFIG_SPI) {
1886+
/*enabling watermark interrupt*/
1887+
s = ndp_spi_read(NDP120_SPI_INTCTL, &data_8);
1888+
if (s) goto error;
1889+
data_8 = NDP120_SPI_INTCTL_WM_INTEN_INSERT(data_8, 1);
1890+
s = ndp_spi_write(NDP120_SPI_INTCTL, data_8);
1891+
if (s) goto error;
1892+
}
1893+
18161894
error:
18171895
if (ndp->iif->unsync) {
18181896
s0 = (ndp->iif->unsync)(ndp->iif->d);
@@ -1821,6 +1899,7 @@ int syntiant_ndp120_tiny_send_audio_extract(struct syntiant_ndp120_tiny_device_s
18211899
return s;
18221900
}
18231901

1902+
18241903
int
18251904
syntiant_ndp120_tiny_get_info(struct syntiant_ndp120_tiny_device_s *ndp,
18261905
struct syntiant_ndp120_tiny_info *idata)
@@ -1834,7 +1913,7 @@ syntiant_ndp120_tiny_get_info(struct syntiant_ndp120_tiny_device_s *ndp,
18341913
if (ndp->iif->sync) {
18351914
s = (ndp->iif->sync)(ndp->iif->d);
18361915
if (s) {
1837-
SYNTIANT_NDP120_PRINTF("Error in syntiant_ndp120_secure_get_info\n");
1916+
SYNTIANT_NDP120_PRINTF("Error in syntiant_ndp120_tiny_get_info\n");
18381917
return s;
18391918
}
18401919
}
@@ -1986,3 +2065,60 @@ int syntiant_ndp120_tiny_get_debug(struct syntiant_ndp120_tiny_device_s *ndp,
19862065
}
19872066
return s;
19882067
}
2068+
2069+
int syntiant_ndp120_tiny_input_config(struct syntiant_ndp120_tiny_device_s *ndp, uint32_t input_mode)
2070+
{
2071+
int s0;
2072+
uint8_t data_8;
2073+
int s = SYNTIANT_NDP120_ERROR_NONE;
2074+
uint32_t addr = SYNTIANT_NDP120_DL_WINDOW_LOWER;
2075+
uint32_t address = SYNTIANT_NDP120_OPEN_RAM_RESULTS;
2076+
uint32_t configured_input = SYNTIANT_NDP120_TINY_GET_INPUT_CONFIG;
2077+
uint32_t data[3] = {SYNTIANT_NDP120_INPUT_CONFIG, sizeof(input_mode), SYNTIANT_NDP120_TINY_GET_INPUT_CONFIG};
2078+
if (ndp->iif->sync) {
2079+
s = (ndp->iif->sync)(ndp->iif->d);
2080+
if (s) {
2081+
SYNTIANT_NDP120_PRINTF("Error in syntiant_ndp120_tiny_input_config\n");
2082+
return s;
2083+
}
2084+
}
2085+
/* write cmd, length of payload, payload */
2086+
s = syntiant_ndp120_tiny_write_block(ndp, SYNTIANT_NDP120_MCU_OP, addr, &data, sizeof(data));
2087+
if (s) goto error;
2088+
2089+
/* send command */
2090+
s = syntiant_ndp120_tiny_do_mailbox_req_no_sync(ndp,SYNTIANT_NDP120_MB_MCU_CMD, NULL);
2091+
if (s) goto error;
2092+
2093+
s = syntiant_ndp120_tiny_read_block(ndp,SYNTIANT_NDP120_MCU_OP, address, &configured_input,sizeof(configured_input));
2094+
if (s) goto error;
2095+
2096+
if(configured_input != input_mode) {
2097+
data[2] = input_mode;
2098+
addr = SYNTIANT_NDP120_DL_WINDOW_LOWER;
2099+
/* write payload */
2100+
s = syntiant_ndp120_tiny_write_block(ndp, SYNTIANT_NDP120_MCU_OP, addr, &data, sizeof(data));
2101+
if (s) goto error;
2102+
2103+
/* send command */
2104+
s = syntiant_ndp120_tiny_do_mailbox_req_no_sync(ndp,SYNTIANT_NDP120_MB_MCU_CMD, NULL);
2105+
if (s) goto error;
2106+
} else {
2107+
s = SYNTIANT_NDP120_ERROR_CONFIG;
2108+
goto error;
2109+
}
2110+
if(input_mode == SYNTIANT_NDP120_TINY_INPUT_CONFIG_SPI) {
2111+
/*enabling watermark interrupt*/
2112+
s = ndp_spi_read(NDP120_SPI_INTCTL, &data_8);
2113+
if(s) goto error;
2114+
data_8 = NDP120_SPI_INTCTL_WM_INTEN_INSERT(data_8, 1);
2115+
s = ndp_spi_write(NDP120_SPI_INTCTL, data_8);
2116+
if (s) goto error;
2117+
}
2118+
error:
2119+
if (ndp->iif->unsync) {
2120+
s0 = (ndp->iif->unsync)(ndp->iif->d);
2121+
s = s ? s : s0;
2122+
}
2123+
return s;
2124+
}

libraries/syntiant_ilib/src/syntiant_ndp120_tiny.h

+54-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
3030
* DEALINGS IN THE SOFTWARE.
3131
*/
32+
3233
#ifndef SYNTIANT_NDP120_TINY_H
3334
#define SYNTIANT_NDP120_TINY_H
3435

@@ -56,9 +57,9 @@ extern "C" {
5657
/** maximum length (in bytes) of various verison strings
5758
*/
5859
#define NDP120_MCU_FW_VER_MAX_LEN (0x20)
59-
#define NDP120_MCU_DSP_FW_VER_MAX_LEN (0x3C)
60-
#define NDP120_MCU_PKG_VER_MAX_LEN (0x80)
61-
#define NDP120_MCU_LABELS_MAX_LEN (0x200)
60+
#define NDP120_MCU_DSP_FW_VER_MAX_LEN (0x20)
61+
#define NDP120_MCU_PKG_VER_MAX_LEN (0x30)
62+
#define NDP120_MCU_LABELS_MAX_LEN (0x2D4)
6263
#define NDP120_MCU_PBI_VER_MAX_LEN (0x10)
6364

6465
/**
@@ -87,6 +88,10 @@ extern "C" {
8788
#define NDP120_SPI_MATCH_WINNER_EXTRACT(x) \
8889
(((x) & NDP120_SPI_MATCH_WINNER_MASK) >> NDP120_SPI_MATCH_WINNER_SHIFT)
8990

91+
#define NDP120_SPI_INTCTL_WM_INTEN_SHIFT 6
92+
#define NDP120_SPI_INTCTL_WM_INTEN_INSERT(x, v) \
93+
((x) | ((v) << NDP120_SPI_INTCTL_WM_INTEN_SHIFT))
94+
9095
/* register array ndp120_spi.maddr[4] */
9196
#define NDP120_SPI_MADDR(i) (0x40U + ((i) << 0))
9297
#define NDP120_SPI_MADDR_COUNT 4
@@ -107,6 +112,19 @@ extern "C" {
107112

108113
#define SYNTIANT_NDP120_TINY_AUDIO_SAMPLES_PER_WORD 2
109114
#define SYNTIANT_NDP120_TINY_AUDIO_SAMPLE_RATE 16000
115+
116+
#define SYNTIANT_NDP120_DEF_SPI_SPEED (1000000)
117+
#define SYNTIANT_NDP120_MAX_SPI_SPEED (8000000)
118+
119+
/**
120+
* @brief secure input config mode
121+
*/
122+
enum syntiant_ndp120_tiny_input_config_mode_e {
123+
SYNTIANT_NDP120_TINY_GET_INPUT_CONFIG = 0,
124+
SYNTIANT_NDP120_TINY_INPUT_CONFIG_PDM = 1,
125+
SYNTIANT_NDP120_TINY_INPUT_CONFIG_SPI = 16
126+
};
127+
110128
/**
111129
* @brief Device info structure holding data about deployed model, fimrware etc.
112130
*/
@@ -504,6 +522,8 @@ enum syntiant_ndp_errors_e {
504522
/**< operation timeout */
505523
SYNTIANT_NDP120_ERROR_MORE = 9,
506524
/**< more data is expected */
525+
SYNTIANT_NDP120_ERROR_CONFIG = 10,
526+
/**< config error */
507527
SYNTIANT_NDP120_ERROR_DATA_REREAD = 13,
508528
/**<data has already been read before */
509529
SYNTIANT_NDP120_ERROR_INVALID_LENGTH = 16,
@@ -846,6 +866,37 @@ int syntiant_ndp120_tiny_get_audio_chunk_size(struct syntiant_ndp120_tiny_device
846866
int syntiant_ndp120_tiny_send_audio_extract(struct syntiant_ndp120_tiny_device_s *ndp,
847867
uint32_t extract_from);
848868

869+
/**
870+
* @brief NDP120 tiny spi direct config
871+
*
872+
* @param ndp NDP state object
873+
* @param threshod_bytes indicates the threshold bytes for SPI FIFO in dsp.
874+
* @return a @c SYNTIANT_NDP_ERROR_* code
875+
*/
876+
int syntiant_ndp120_tiny_spi_direct_config(struct syntiant_ndp120_tiny_device_s *ndp,
877+
uint32_t threshold_bytes);
878+
879+
/**
880+
* @brief NDP120 tiny input config sets the input mode of the dsp.
881+
*
882+
* @param ndp NDP state object
883+
* @param input_mode indicates the input mode like PDM or SPI.
884+
* @return a @c SYNTIANT_NDP_ERROR_* code
885+
*/
886+
int syntiant_ndp120_tiny_input_config(struct syntiant_ndp120_tiny_device_s *ndp,
887+
uint32_t input_mode);
888+
889+
/**
890+
* @brief NDP120 tiny_switch_dnn_flow changes the flow of the dsp indicated by flow_set_id.
891+
*
892+
* @param ndp NDP state object
893+
* @param flow_set_id indicates the flow set id that is to be changed.
894+
* @param input_mode gets the input mode after changing the flow.
895+
* @return a @c SYNTIANT_NDP_ERROR_* code
896+
*/
897+
int syntiant_ndp120_tiny_switch_dnn_flow(struct syntiant_ndp120_tiny_device_s *ndp,
898+
uint32_t flow_set_id, uint32_t *input_mode);
899+
849900
#ifdef __cplusplus
850901
}
851902
#endif

0 commit comments

Comments
 (0)