#define UART_RING_BUFSIZE256 uint8_t buffer[UART_RING_BUFSIZE]; uint8_t z = (uint8_t)sizeof(buffer); |
#include <stdio.h> #include <stdlib.h> #define SIZE 10 int main() { int a[SIZE]; printf("size of a=%i\n", (int)sizeof(a)); return 0; } |
uint32_t UARTReceive(LPC_UART_TypeDef *UARTPort, uint8_t *rxbuf, uint32_t buflen) { uint8_t* data = (uint8_t *) rxbuf; <--- BREAKPOINT HERE SHOWS 0 FOR buflen ! uint8_t temp_tail; uint8_t prev = 99; uint32_t bytes = 0; /* Temporarily lock out UART receive interrupts during this read so the UART receive interrupt won't cause problems with the index values */ UART_IntConfig(UARTPort, UART_INTCFG_RBR, DISABLE); // check for cr lf (\r\n) in the rb buffer. if found -> copy all from // the beginning to the \r\n and move everything after to the beginning. temp_tail = rb.rx_tail; while(!(__BUF_IS_EMPTY(rb.rx_head, temp_tail)) && bytes < UART_RING_BUFSIZE) { *data = rb.rx[temp_tail]; data ++; bytes ++; if(prev == '\r' && rb.rx[temp_tail] == '\n') { // gotcha // set rb.rx_tail __BUF_INCR(temp_tail); rb.rx_tail = temp_tail; *data = '\0'; // enable interrupt UART_IntConfig(UARTPort, UART_INTCFG_RBR, ENABLE); // return bytes to say we have a full line return bytes; } prev = rb.rx[temp_tail]; __BUF_INCR(temp_tail); } /* Re-enable UART interrupts */ UART_IntConfig(UARTPort, UART_INTCFG_RBR, ENABLE); // if we are here it means a whole line was not found -> return 0 return 0; } |
bytes = UARTReceive((LPC_UART_TypeDef*)LPC_UART0, buffer, (uint32_t)256); |
bytes = UARTReceive((LPC_UART_TypeDef*)LPC_UART0, buffer, (uint32_t)sizeof(buffer)); |
uint32_t UARTReceive(LPC_UART_TypeDef *UARTPort, uint8_t *rxbuf, uint32_t buflen); |
#include <stdio.h> #include <stdlib.h> #define SIZE 10 typedef unsigned char uint8_t; int main() { uint8_t a[SIZE]; printf("size of a=%i\n", (uint8_t)sizeof(a)); return 0; } |
uint8_t buflen = (uint8_t)UART_RING_BUFSIZE; |