-/**
- * File : libsi24.c
- * Author : Robin Krens <robin@robinkrens.nl>
- * Date : 18.01.2023
- * Last Modified Date: 22.01.2023
- * Last Modified By : Robin Krens <robin@robinkrens.nl>
+/* Copyright (C)
+ * 2023 - Robin Krens
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
*/
-
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
}
if (params->enable_ack) {
- uint8_t dyn = (1 << DPL_P0);
- ret += _reg_write(si, SI24_REG_DYNPD, &dyn, 1);
- feature_reg |= (1 << EN_DPL);
- ret += _reg_write(si, SI24_REG_FEATURE, &feature_reg, 1);
if (params->mode == SEND_MODE) {
setup_retr_reg = ARD(params->timeout) | ARC(params->retries);
ret += _reg_write(si, SI24_REG_SETUP_RETR, &setup_retr_reg, 1);
}
}
+ if (params->enable_dynpd) {
+ uint8_t dyn = (1 << DPL_P0);
+ ret += _reg_write(si, SI24_REG_DYNPD, &dyn, 1);
+ feature_reg |= (1 << EN_DPL);
+ ret += _reg_write(si, SI24_REG_FEATURE, &feature_reg, 1);
+ } else { /* fixed payload size */
+ if (params->mode == RECV_MODE) {
+ ret += _reg_write(si, SI24_REG_RX_PW_P0, (uint8_t *) ¶ms->payload, 1);
+ }
+ }
+
uint8_t aw = AW_5;
ret += _reg_write(si, SI24_REG_SETUP_AW, &aw, 1);
uint8_t ch = 0x1;
ret += _reg_write(si, SI24_REG_EN_RXADDR, &ch, 1);
ret += _reg_write(si, SI24_REG_RX_ADDR_P0, params->mac_addr, sizeof(params->mac_addr));
- ret += _reg_write(si, SI24_REG_RX_PW_P0, (uint8_t *) ¶ms->payload, 1);
} else {
ret += _reg_write(si, SI24_REG_TX_ADDR, params->mac_addr, sizeof(params->mac_addr));
}
return -1;
}
- for (size_t idx = 0; idx < size; idx += si->opts->payload) {
- sz = (size - idx) < si->opts->payload ? (size - idx) : si->opts->payload;
+ int payload = si->opts->payload;
+
+ if (si->opts->enable_dynpd)
+ payload = size > 32 ? 32 : size;
+
+ for (size_t idx = 0; idx < size; idx += payload) {
+ sz = (size - idx) < payload ? (size - idx) : payload;
if (si->opts->enable_ack) {
_reg_write(si, SI24_W_TX_PAYLOAD, buf + idx, sz);
si->ctl->chip_enable(1);
while(!(fifo_flags & (1 << RX_EMPTY)) &&
bytes_read < size) {
+ if (si->opts->enable_dynpd) {
+ uint8_t d_sz = 0;
+ _reg_read(si, SI24_RX_PL_WID, &d_sz, 1);
+ p_size = d_sz;
+ }
int m_size = (size - bytes_read) > p_size ? p_size : (size - bytes_read);
_reg_read(si, SI24_R_RX_PAYLOAD, tmpbuf, m_size);
{
free(si);
}
-
-/* hardware linkage */
-int spi_w_r(unsigned char *data, size_t sz)
-{
- if (sz >= 2)
- data[1] = (1 << RX_DR);
- return sz;
-}
-
-void ce(unsigned val)
-{
- (void) val;
-}
-
-void eh(si24_t *si, si24_event_t * e)
-{
- (void) si;
-
- switch(e->type) {
- case EV_TX_COMPLETE:
- printf("SENT SUCCESFUL\n");
- break;
- case EV_RX_COMPLETE:
- printf("RECV COMPLETE\n");
- break;
- case EV_RX_EMPTY:
- printf("NO NEW DATA\n");
- break;
- case EV_ERR_TIMEOUT:
- printf("TIMEOUT\n");
- break;
- default:
- printf("EVENT: %x\n", e->type);
- break;
- }
-}
-
-int main(void)
-{
- /* const unsigned char buf[] = "THIS IS A WIRELESS TEST MESSAGE!";*/
- unsigned char recv_buf[29];
-
- si24_ioctl_t ctl = {
- .write_and_read = spi_w_r,
- .chip_enable = ce,
- };
-
- const si24_opts_t opts = {
- .mode = RECV_MODE,
- .enable_ack = 1,
- .non_blocking = 0,
- .enable_crc = 1,
- .enable_dynpd = 1,
- .crc = TWO_BYTE,
- .ioctl = &ctl,
- .speed = MBPS2,
- .txpwr = PLUS4DB,
- .payload = 5,
- .timeout = 1,
- .retries = 5,
- .mac_addr = 0xAAAAAAAAAA
- };
-
- struct si24_t * si = si24_init(&opts, eh);
- /* si24_send(si, buf, sizeof(buf)); */
- printf("READ: %ld\n", si24_recv(si, recv_buf, sizeof(recv_buf)));
-
-}