Skip to content

Commit

Permalink
Increase message size. Add gdb script.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmo committed Jan 10, 2018
1 parent a274a43 commit 7e36e3a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
14 changes: 14 additions & 0 deletions .gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define btload
file build/bbc-microbit-classic-gcc-nosd/source/pyb-radio-module
target extended-remote /dev/ttyACM0
monitor swdp_scan
attach 1
set mem inaccessible-by-default off
mon erase_mass
load
end

define btreset
set mem inaccessible-by-default off
set *0xe000ed0c = 0x05fa << 16 | (1 << 2)
end
4 changes: 2 additions & 2 deletions inc/SPISlaveExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DEALINGS IN THE SOFTWARE.

#include "mbed.h"

const uint8_t SPI_IOBUF_SIZE = 64;
const uint16_t SPI_IOBUF_SIZE = 255;

typedef enum {
SPI_OP_SUCCESS,
Expand Down Expand Up @@ -68,7 +68,7 @@ class SPISlaveExt : public SPISlave {
* buffer is where we should place bytes
* maxLen is the size of the buffer
* release tells us whether to release the CPU semaphore after operating.
* If we want to respond we should keep hold of the semaphore, however
* If we want to respond we should keep hold of the semaphore, however
* we MUST then call release before the device will send any messages.
*
*/
Expand Down
6 changes: 3 additions & 3 deletions source/SPIRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern SPISlaveExt spi;

// Radio messages buffer
extern uint8_t radio_buffer_len;
extern uint8_t radio_buffer[64];
extern uint8_t radio_buffer[SPI_IOBUF_SIZE];
// Version info prototype
const char* version_info(void);

Expand Down Expand Up @@ -68,7 +68,7 @@ uint8_t validate_packet(const uint8_t *io_buffer, const uint32_t length) {
spi_op_status_t craft_packet(uint8_t *io_buffer, spi_radio_responses_t resp,
const uint8_t *msg, const uint32_t length) {
// Check that our message isn't too long
if (length > 61)
if (length > SPI_IOBUF_SIZE - 4)
return SPI_OP_INSUFFICIENT_BUFFER;

// Calculate our checksum
Expand Down Expand Up @@ -178,7 +178,7 @@ void spi_cmd_switch(spi_radio_cmds_t cmd, uint8_t *io_buffer, const uint32_t len
spi.reply(SPI_INVALID_LENGTH);
break;
}
if (check > 61) {
if (check > SPI_IOBUF_SIZE - 4) {
spi.reply(SPI_REPLY_OVERFLOW);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ SPISlaveExt spi(P0_22, P0_23, P0_21, P0_24); // MOSI, MISO, SCLK, CS

// Allocate space for a message buffer
uint8_t radio_buffer_len;
uint8_t radio_buffer[64];
uint8_t io_buffer[64];
uint8_t radio_buffer[SPI_IOBUF_SIZE];
uint8_t io_buffer[SPI_IOBUF_SIZE];

void onRadioMsg(MicroBitEvent e) {
ManagedString s = module.radio.datagram.recv();
Expand Down Expand Up @@ -90,7 +90,7 @@ int main()
spi.release();
// If we have, handle it
if (r) {
spi_op_status_t success = spi.read_buffer(io_buffer, 64, 0);
spi_op_status_t success = spi.read_buffer(io_buffer, sizeof(io_buffer), 0);
if (success != SPI_OP_SUCCESS)
continue;
spi_radio_cmds_t cmd = (spi_radio_cmds_t) io_buffer[0];
Expand Down

0 comments on commit 7e36e3a

Please # to comment.