From 5704ce08cb307772902778dacdaa2a97d13ae751 Mon Sep 17 00:00:00 2001 From: schneider Date: Sat, 10 Dec 2011 21:39:04 +0100 Subject: [PATCH 1/7] disabled usb interrupts in WriteEP --- firmware/usbcdc/usbhw.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/firmware/usbcdc/usbhw.c b/firmware/usbcdc/usbhw.c index 711190c..6fbf7ee 100644 --- a/firmware/usbcdc/usbhw.c +++ b/firmware/usbcdc/usbhw.c @@ -26,6 +26,7 @@ #include "usbhw.h" #include "usbcore.h" #include "usbuser.h" +#include "basic/basic.h" #include "usb/usbmsc.h" @@ -470,6 +471,10 @@ uint32_t USB_ReadEP (uint32_t EPNum, uint8_t *pData) uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt) { uint32_t n; + + //this seems rather brutal... + //disable all usb related interrupts or WrCmd might block + USB_DEVINTEN = 0; USB_CTRL = ((EPNum & 0x0F) << 2) | CTRL_WR_EN; /* 3 clock cycles to fetch the packet length from RAM. */ @@ -486,6 +491,9 @@ uint32_t USB_WriteEP (uint32_t EPNum, uint8_t *pData, uint32_t cnt) WrCmdEP(EPNum, CMD_VALID_BUF); + //enable interrupts again + USB_DEVINTEN = DEV_STAT_INT | (0xFF<<1) | (USB_SOF_EVENT ? FRAME_INT : 0); + return (cnt); } From 2edc933ce0e547b616a599d6d18b8235f4ac6058 Mon Sep 17 00:00:00 2001 From: schneider Date: Sat, 10 Dec 2011 21:39:32 +0100 Subject: [PATCH 2/7] speed up for cdc --- firmware/usbcdc/Makefile | 1 - firmware/usbcdc/cdc_buf.c | 161 -------------------------------------- firmware/usbcdc/cdc_buf.h | 29 ------- firmware/usbcdc/cdcuser.c | 108 ++++++++++++++++++------- firmware/usbcdc/cdcuser.h | 2 +- firmware/usbcdc/util.c | 31 ++------ 6 files changed, 86 insertions(+), 246 deletions(-) delete mode 100644 firmware/usbcdc/cdc_buf.c delete mode 100644 firmware/usbcdc/cdc_buf.h diff --git a/firmware/usbcdc/Makefile b/firmware/usbcdc/Makefile index 3a9ea98..3019ad4 100644 --- a/firmware/usbcdc/Makefile +++ b/firmware/usbcdc/Makefile @@ -4,7 +4,6 @@ OBJS = OBJS += cdcuser.o -OBJS += cdc_buf.o OBJS += usbcore.o OBJS += usbdesc.o OBJS += usbhw.o diff --git a/firmware/usbcdc/cdc_buf.c b/firmware/usbcdc/cdc_buf.c deleted file mode 100644 index 2a7c1d5..0000000 --- a/firmware/usbcdc/cdc_buf.c +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************* - Copyright (C) 2009 FreakLabs - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - SUCH DAMAGE. - - Originally written by Christopher Wang aka Akiba. - Please post support questions to the FreakLabs forum. -*******************************************************************/ - -/**************************************************************************/ -/*! - @file cdc_buf.c - @author Christopher Wang (Freaklabs) - Modified by: K. Townsend (microBuilder.eu) - @date 19 May 2010 - - Original code taken from the FreakUSB Open Source USB Device Stack - http://freaklabs.org/index.php/FreakUSB-Open-Source-USB-Device-Stack.html - - If it works well, you can thank Akiba at Freaklabs. If it fails - miserably, you can blame me (since parts of it it were rather - ungraciously modified). :-) - -*/ -/**************************************************************************/ - -#include "cdc_buf.h" - -static cdc_buffer_t cdcfifo; - -/**************************************************************************/ -/*! - Gets a pointer to the fifo buffer -*/ -/**************************************************************************/ -cdc_buffer_t *cdcGetBuffer() -{ - return &cdcfifo; -} - -/**************************************************************************/ -/*! - Initialises the RX FIFO buffer -*/ -/**************************************************************************/ -void cdcBufferInit() -{ - cdcfifo.len = 0; -} - -/**************************************************************************/ -/*! - Read one byte out of the RX buffer. This function will return the byte - located at the array index of the read pointer, and then increment the - read pointer index. If the read pointer exceeds the maximum buffer - size, it will roll over to zero. -*/ -/**************************************************************************/ -uint8_t cdcBufferRead() -{ - uint8_t data; - - data = cdcfifo.buf[cdcfifo.rd_ptr]; - cdcfifo.rd_ptr = (cdcfifo.rd_ptr + 1) % CFG_USBCDC_BUFFERSIZE; - cdcfifo.len--; - return data; -} - -/**************************************************************************/ -/*! - Reads x bytes from cdc buffer - */ -/**************************************************************************/ -uint32_t cdcBufferReadLen(uint8_t* buf, uint32_t len) -{ - uint32_t counter, actual; - counter = actual = 0; - - while(counter != len) - { - // Make sure we don't exceed buffer limits - if (cdcfifo.len > 0) - { - buf[counter] = cdcBufferRead(); - actual++; - counter++; - } - else - { - return actual; - } - } - - return actual; -} - -/**************************************************************************/ -/*! - Write one byte into the RX buffer. This function will write one - byte into the array index specified by the write pointer and increment - the write index. If the write index exceeds the max buffer size, then it - will roll over to zero. -*/ -/**************************************************************************/ -void cdcBufferWrite(uint8_t data) -{ - cdcfifo.buf[cdcfifo.wr_ptr] = data; - cdcfifo.wr_ptr = (cdcfifo.wr_ptr + 1) % CFG_USBCDC_BUFFERSIZE; - cdcfifo.len++; -} - -/**************************************************************************/ -/*! - Clear the fifo read and write pointers and set the length to zero. -*/ -/**************************************************************************/ -void cdcBufferClearFIFO() -{ - cdcfifo.rd_ptr = 0; - cdcfifo.wr_ptr = 0; - cdcfifo.len = 0; -} - -/**************************************************************************/ -/*! - Check whether there is any data pending on the RX buffer. -*/ -/**************************************************************************/ -uint8_t cdcBufferDataPending() -{ - if (cdcfifo.len != 0) - { - return 1; - } - - return 0; -} diff --git a/firmware/usbcdc/cdc_buf.h b/firmware/usbcdc/cdc_buf.h deleted file mode 100644 index c5cdfad..0000000 --- a/firmware/usbcdc/cdc_buf.h +++ /dev/null @@ -1,29 +0,0 @@ -/*---------------------------------------------------------------------------- - * Name: cdc_buf.h - * Purpose: usb cdc buffer handling - * Version: V1.00 - *---------------------------------------------------------------------------*/ - -#ifndef __CDC_BUF_H__ -#define __CDC_BUF_H__ - -#include "projectconfig.h" - -// Buffer used for circular fifo -typedef struct _cdc_buffer_t -{ - volatile uint8_t len; - volatile uint8_t wr_ptr; - volatile uint8_t rd_ptr; - uint8_t buf[CFG_USBCDC_BUFFERSIZE]; -} cdc_buffer_t; - -cdc_buffer_t * cdcGetBuffer(); -void cdcBufferInit(); -uint8_t cdcBufferRead(); -uint32_t cdcBufferReadLen(uint8_t* buf, uint32_t len); -void cdcBufferWrite(uint8_t data); -void cdcBufferClearFIFO(); -uint8_t cdcBufferDataPending(); - -#endif diff --git a/firmware/usbcdc/cdcuser.c b/firmware/usbcdc/cdcuser.c index d553f47..222dae2 100644 --- a/firmware/usbcdc/cdcuser.c +++ b/firmware/usbcdc/cdcuser.c @@ -1,4 +1,4 @@ -/*---------------------------------------------------------------------------- +/*----------/BulkBufOut------------------------------------------------------------------ * U S B - K e r n e l *---------------------------------------------------------------------------- * Name: cdcuser.c @@ -17,6 +17,7 @@ *---------------------------------------------------------------------------*/ #include "projectconfig.h" +#include "basic/basic.h" #include "usb.h" #include "usbhw.h" @@ -24,15 +25,14 @@ #include "usbcore.h" #include "cdc.h" #include "cdcuser.h" -#include "cdc_buf.h" -// unsigned char BulkBufIn [64]; // Buffer to store USB IN packet +unsigned char BulkBufIn [64]; // Buffer to store USB IN packet unsigned char BulkBufOut [64]; // Buffer to store USB OUT packet unsigned char NotificationBuf [10]; CDC_LINE_CODING CDC_LineCoding = {CFG_USBCDC_BAUDRATE, 0, 0, 8}; unsigned short CDC_SerialState = 0x0000; -unsigned short CDC_DepInEmpty = 1; // Data IN EP is empty +volatile unsigned char CDC_DepInEmpty = 1; // Data IN EP is empty /*---------------------------------------------------------------------------- We need a buffer for incoming data on USB port because USB receives @@ -61,6 +61,7 @@ typedef struct __CDC_BUF_T } CDC_BUF_T; CDC_BUF_T CDC_OutBuf; // buffer for all CDC Out data +CDC_BUF_T CDC_InBuf; // buffer for all CDC Out data /*---------------------------------------------------------------------------- read data from CDC_OutBuf @@ -116,6 +117,67 @@ int CDC_OutBufAvailChar (int *availChar) } /* end Buffer handling */ +/*---------------------------------------------------------------------------- + read data from CDC_InBuf + *---------------------------------------------------------------------------*/ +int CDC_RdInBuf (char *buffer, const int *length) +{ + int bytesToRead, bytesRead; + + /* Read *length bytes, block if *bytes are not avaialable */ + bytesToRead = *length; + //bytesToRead = (bytesToRead < (*length)) ? bytesToRead : (*length); + bytesRead = bytesToRead; + + + // ... add code to check for underrun + + while (bytesToRead--) { + *buffer++ = CDC_BUF_RD(CDC_InBuf); + } + return (bytesRead); +} + +/*---------------------------------------------------------------------------- + write data to CDC_InBuf + *---------------------------------------------------------------------------*/ +int CDC_WrInBuf (const char *buffer, int *length) +{ + int bytesToWrite, bytesWritten; + + // Write *length bytes + bytesToWrite = *length; + bytesWritten = bytesToWrite; + + //Just block if we can't write all at once + while( CDC_BUF_SIZE - CDC_BUF_COUNT(CDC_InBuf) < bytesToWrite ); + + //uint8_t flush = CDC_DepInEmpty; + while (bytesToWrite--) { + CDC_BUF_WR(CDC_InBuf, *buffer++); // Copy Data to buffer + } + //if( flush == 1 ){ + if( CDC_DepInEmpty && CDC_BUF_COUNT(CDC_InBuf) ){ + CDC_DepInEmpty = 0; + gpioSetValue (RB_LED2, 0); + CDC_BulkIn(); + } + + return (bytesWritten); +} + +/*---------------------------------------------------------------------------- + check if character(s) are available at CDC_OutBuf + *---------------------------------------------------------------------------*/ +int CDC_InBufAvailChar (int *availChar) +{ + *availChar = CDC_BUF_COUNT(CDC_InBuf); + + return (0); +} +/* end Buffer handling */ + + /*---------------------------------------------------------------------------- CDC Initialisation @@ -129,12 +191,8 @@ void CDC_Init (void) CDC_SerialState = CDC_GetSerialState(); CDC_BUF_RESET(CDC_OutBuf); + CDC_BUF_RESET(CDC_InBuf); - // Initialise the CDC buffer. This is required to buffer outgoing - // data (MCU to PC) since data can only be sent 64 bytes per frame - // with at least 1ms between frames. To see how the buffer is used, - // see 'puts' in systeminit.c - cdcBufferInit(); } @@ -277,25 +335,19 @@ uint32_t CDC_SendBreak (unsigned short wDurationOfBreak) { *---------------------------------------------------------------------------*/ void CDC_BulkIn(void) { -// int numBytesRead, numBytesAvail; -// -// // ToDo: Modify BulkIn to send incoming data to USB -// -// ser_AvailChar (&numBytesAvail); -// -// // ... add code to check for overwrite -// -// numBytesRead = ser_Read ((char *)&BulkBufIn[0], &numBytesAvail); -// -// // send over USB -// if (numBytesRead > 0) { -// USB_WriteEP (CDC_DEP_IN, &BulkBufIn[0], numBytesRead); -// } -// else { -// CDC_DepInEmpty = 1; -// } -// -// + int numBytesRead, numBytesAvail; + CDC_InBufAvailChar(&numBytesAvail); + numBytesRead = CDC_RdInBuf(&BulkBufIn[0], &numBytesAvail); + // send over USB + if (numBytesRead > 0) { + //gpioSetValue (RB_LED0, 1); + USB_WriteEP (CDC_DEP_IN, &BulkBufIn[0], numBytesRead); + //gpioSetValue (RB_LED0, 0); + } else { + //USB_WriteEP (CDC_DEP_IN, "test\r\n", 6); + CDC_DepInEmpty = 1; + //gpioSetValue (RB_LED2, 1); + } } diff --git a/firmware/usbcdc/cdcuser.h b/firmware/usbcdc/cdcuser.h index 55cd910..4a2a82b 100644 --- a/firmware/usbcdc/cdcuser.h +++ b/firmware/usbcdc/cdcuser.h @@ -57,7 +57,7 @@ extern void CDC_Init (void); extern unsigned short CDC_GetSerialState (void); /* flow control */ -extern unsigned short CDC_DepInEmpty; // DataEndPoint IN empty +extern volatile unsigned char CDC_DepInEmpty; // DataEndPoint IN empty #endif /* __CDCUSER_H__ */ diff --git a/firmware/usbcdc/util.c b/firmware/usbcdc/util.c index fd3b041..5f3a69a 100644 --- a/firmware/usbcdc/util.c +++ b/firmware/usbcdc/util.c @@ -16,30 +16,9 @@ volatile unsigned int lastTick; int puts(const char * str){ if(!USB_Configuration) return -1; - - while(*str) - cdcBufferWrite(*str++); - - //XXX: This assumes systick is 1ms, which it isn't for us. - // this makes usbserial unnecessary slow. Ah well.... - - // Check if we can flush the buffer now or if we need to wait - unsigned int currentTick = systickGetTicks(); - if (currentTick != lastTick){ - uint8_t frame[64]; - uint32_t bytesRead = 0; - char repeat=0; - while (cdcBufferDataPending()){ - // Read up to 64 bytes as long as possible - bytesRead = cdcBufferReadLen(frame, 64); - USB_WriteEP (CDC_DEP_IN, frame, bytesRead); - if(repeat) - systickDelay(1); - else - repeat=1; - } - lastTick = currentTick; - } + + int len = strlen(str); + CDC_WrInBuf(str, &len); return 0; } @@ -47,8 +26,8 @@ int puts_plus(const char * str){ if(!USB_Configuration) return -1; - while(*str) - cdcBufferWrite(*str++); + int len = strlen(str); + CDC_WrInBuf(str, &len); return 0; } From ba930408f6760b57564141fc3955f4361b6facb8 Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 11 Dec 2011 00:20:38 +0100 Subject: [PATCH 3/7] usbcdc: i don't trust these ring buffers... --- firmware/usbcdc/cdcuser.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/firmware/usbcdc/cdcuser.c b/firmware/usbcdc/cdcuser.c index 222dae2..5f5d436 100644 --- a/firmware/usbcdc/cdcuser.c +++ b/firmware/usbcdc/cdcuser.c @@ -25,6 +25,8 @@ #include "usbcore.h" #include "cdc.h" #include "cdcuser.h" +#include "usbreg.h" + unsigned char BulkBufIn [64]; // Buffer to store USB IN packet unsigned char BulkBufOut [64]; // Buffer to store USB OUT packet @@ -149,19 +151,23 @@ int CDC_WrInBuf (const char *buffer, int *length) bytesToWrite = *length; bytesWritten = bytesToWrite; - //Just block if we can't write all at once - while( CDC_BUF_SIZE - CDC_BUF_COUNT(CDC_InBuf) < bytesToWrite ); + // Just block if we can't write all at once + // These ringbuffers smell buggy, so +1 + while( CDC_BUF_SIZE - CDC_BUF_COUNT(CDC_InBuf) < bytesToWrite+1 ); //uint8_t flush = CDC_DepInEmpty; + + USB_DEVINTEN = 0; while (bytesToWrite--) { CDC_BUF_WR(CDC_InBuf, *buffer++); // Copy Data to buffer } //if( flush == 1 ){ - if( CDC_DepInEmpty && CDC_BUF_COUNT(CDC_InBuf) ){ + //if( CDC_DepInEmpty && CDC_BUF_COUNT(CDC_InBuf) ){ + if( CDC_DepInEmpty ){ CDC_DepInEmpty = 0; - gpioSetValue (RB_LED2, 0); - CDC_BulkIn(); + CDC_BulkIn(); } + USB_DEVINTEN = DEV_STAT_INT | (0xFF<<1) | (USB_SOF_EVENT ? FRAME_INT : 0); return (bytesWritten); } @@ -327,7 +333,6 @@ uint32_t CDC_SendBreak (unsigned short wDurationOfBreak) { return (TRUE); } - /*---------------------------------------------------------------------------- CDC_BulkIn call on DataIn Request Parameters: none From 112bc97dc60f77b3abacd765b643f7f69d6556bd Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 11 Dec 2011 00:26:11 +0100 Subject: [PATCH 4/7] usbcdc: first think, then commit --- firmware/usbcdc/cdcuser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/usbcdc/cdcuser.c b/firmware/usbcdc/cdcuser.c index 5f5d436..fbbb5af 100644 --- a/firmware/usbcdc/cdcuser.c +++ b/firmware/usbcdc/cdcuser.c @@ -152,7 +152,7 @@ int CDC_WrInBuf (const char *buffer, int *length) bytesWritten = bytesToWrite; // Just block if we can't write all at once - // These ringbuffers smell buggy, so +1 + // +1 to prevent an overflow of the ring buffer while( CDC_BUF_SIZE - CDC_BUF_COUNT(CDC_InBuf) < bytesToWrite+1 ); //uint8_t flush = CDC_DepInEmpty; From 69235e7409ecd5169c3651b11fa8973151fcdb47 Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 11 Dec 2011 16:13:29 +0100 Subject: [PATCH 5/7] removed crp --- firmware/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/main.c b/firmware/main.c index 9b02c7c..4dd682b 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -28,7 +28,7 @@ #define CRP_VALUE 0x0 // ANY non-magic value disables CRP #endif -__attribute__ ((used, section("crp"))) const uint32_t the_crp=CRP_VALUE; +//__attribute__ ((used, section("crp"))) const uint32_t the_crp=CRP_VALUE; /**************************************************************************/ From 02036634d477a2694ba887f66b790c013ae9ba4b Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 11 Dec 2011 16:13:46 +0100 Subject: [PATCH 6/7] added rf-io application --- firmware/applications/schneider.c | 208 ++++++++++++++++++++++++------ 1 file changed, 171 insertions(+), 37 deletions(-) diff --git a/firmware/applications/schneider.c b/firmware/applications/schneider.c index 9e7ec11..ee24e29 100644 --- a/firmware/applications/schneider.c +++ b/firmware/applications/schneider.c @@ -6,52 +6,186 @@ #include "basic/basic.h" #include "lcd/render.h" #include "lcd/allfonts.h" +#include "basic/config.h" +#include "basic/byteorder.h" +#include "lcd/lcd.h" +#include "lcd/print.h" +#include "funk/nrf24l01p.h" +#include "usbcdc/usb.h" +#include "usbcdc/usbcore.h" +#include "usbcdc/usbhw.h" +#include "usbcdc/cdcuser.h" +#include "usbcdc/cdc_buf.h" +#include "usbcdc/util.h" +#include "core/ssp/ssp.h" -#include "ecc.c" -void backlightInit(void); +#if CFG_USBMSC +#error "MSC is defined" +#endif +#if !CFG_USBCDC +#error "CDC is not defined" +#endif + +#define CHANNEL 81 +#define MAC "\x1\x2\x3\x2\x1" + +#define UB_NONE 0 +#define UB_ESCAPE '\\' +#define UB_STOP '0' +#define UB_PACKETLEN 128 + +struct NRF_CFG config = { + .channel= CHANNEL, + .txmac= MAC, + .nrmacs=1, + .mac0= MAC, + .maclen ="\x10", +}; + +uint8_t serialmsg_message[UB_PACKETLEN]; +uint8_t serialmsg_len = 0; + +void serialmsg_init(void); +uint8_t serialmsg_put(uint8_t data); +char snd_pkt_no_crc(int size, uint8_t * pkt); + +#define INPUTLEN 99 /**************************************************************************/ -void main_schneider(void) { - //int yctr=8; - int dx=0; - char key; - int ctr = 1; - backlightInit(); - font_direction = FONT_DIR_LTR; // LeftToRight is the default - //yctr=18; - bitstr_parse(poly, "800000000000000000000000000000000000000c9"); - bitstr_parse(coeff_b, "20a601907b8c953ca1481eb10512f78744a3205fd"); - bitstr_parse(base_x, "3f0eba16286a2d57ea0991168d4994637e8343e36"); - bitstr_parse(base_y, "0d51fbc6c71a0094fa2cdd545b11c5c0c797324f1"); - bitstr_parse(base_order, "40000000000000000000292fe77e70c12a4234c33"); +void main_schneider(void) +{ + GLOBAL(daytrig)=10; + GLOBAL(lcdbacklight)=10; + char input[INPUTLEN+1]; - ECIES_generate_key_pair(); // generate a public/private key pair - while (1) { - key= getInput(); - font=&Font_7x8; - - // Easy flashing - if(key==BTN_LEFT){ - DoString(0,8,"Enter ISP!"); - lcdDisplay(); - ISPandReset(); - }; - - // Display nickname - //font = &Font_Ubuntu36pt; - dx=DoString(0,0,"Test"); - dx=DoInt(dx,0,ctr++); - lcdDisplay(); - encryption_decryption_demo("This is encrypted", - "1c56d302cf642a8e1ba4b48cc4fbe2845ee32dce7", - "45f46eb303edf2e62f74bd68368d979e265ee3c03", - "0e10e787036941e6c78daf8a0e8e1dbfac68e26d2"); + usbCDCInit(); + delayms(500); + nrf_init(); + nrf_config_set(&config); + + nrf_rcv_pkt_start(); + while(1){ + int l=INPUTLEN, i, status; + CDC_OutBufAvailChar (&l); + if(l>0){ + CDC_RdOutBuf (input, &l); + for(i=0; i 0 ){ + puts("\\1"); + CDC_WrInBuf(buf, &len); + puts("\\0"); + } } - return; } void tick_schneider(void){ return; }; +inline void xmit_spi(uint8_t dat) { + sspSend(0, (uint8_t*) &dat, 1); +} + +inline void rcv_spi(uint8_t *dat) { + sspReceive(0, dat, 1); +} + +#define CS_LOW() gpioSetValue(RB_SPI_NRF_CS, 0) +#define CS_HIGH() gpioSetValue(RB_SPI_NRF_CS, 1) +#define CE_LOW() gpioSetValue(RB_NRF_CE, 0) +#define CE_HIGH() gpioSetValue(RB_NRF_CE, 1) + +char snd_pkt_no_crc(int size, uint8_t * pkt) +{ + if(size > MAX_PKT) + size=MAX_PKT; + + nrf_write_reg(R_CONFIG, + R_CONFIG_PWR_UP| // Power on + R_CONFIG_EN_CRC // CRC on, single byte + ); + + CS_LOW(); + xmit_spi(C_W_TX_PAYLOAD); + sspSend(0,pkt,size); + CS_HIGH(); + + CE_HIGH(); + delayms(1); // Send it. (only needs >10ys, i think) + CE_LOW(); + + return nrf_cmd_status(C_NOP); +}; + +void serialmsg_init(void) +{ + serialmsg_len = 0; +} + +//returns the message type or UB_NONE +uint8_t serialmsg_put(uint8_t data) +{ + static uint8_t escaped = 0; + static uint8_t msgtype = UB_NONE; + + if( data == UB_ESCAPE && escaped == 0 ){ + //a control code will follow + escaped = 1; + return UB_NONE; + }else if( escaped ){ + escaped = 0; + if( data != UB_ESCAPE ){ + if( data == UB_STOP ){ + uint8_t tmp = msgtype; + msgtype = UB_NONE; + return tmp; + } + msgtype = data; + serialmsg_len=0; + return UB_NONE; + } + } + serialmsg_message[serialmsg_len++] = data; + + //prevent a buffer overflow + if( serialmsg_len == UB_PACKETLEN ) + serialmsg_len--; + + return UB_NONE; +} + + From c02b2279874c6432888602710c0f6b618d52826f Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 11 Dec 2011 16:15:05 +0100 Subject: [PATCH 7/7] added bridge protocol --- firmware/BRIDGE-PROTOCOL | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 firmware/BRIDGE-PROTOCOL diff --git a/firmware/BRIDGE-PROTOCOL b/firmware/BRIDGE-PROTOCOL new file mode 100644 index 0000000..e812eae --- /dev/null +++ b/firmware/BRIDGE-PROTOCOL @@ -0,0 +1,18 @@ +Receiving: +r->h: \1\0 + +Sending: +h->r: \1\0 +r->h: \2\0 + +Settings: +h->r:\3\0 +r->h: \2\0 +h->r:\4\0 +r->h: \2\0 +h->r:\5\0 +r->h: \2\0 +h->r:\6\0 +r->h: \2\0 + +