
The MCR20A Wireless UART application functions as an wireless UART bridge between two (one-to-one) or several (one to many) boards. The application can be used with both a TERM, or with software that is capable of opening a serial port and writing to or reading from it. The characters sent or received are not necessarily ASCII printable characters.
Dependencies: fsl_phy_mcr20a fsl_smac mbed-rtos mbed
Fork of mcr20_wireless_uart by
By default, the application uses broadcast addresses for OTA communication. This way, the application can be directly downloaded and run without any user intervention. The following use case assumes no changes have been done to the project.
- Two (or more) MCR20A platforms (plugged into the FRDM-K64F Freescale Freedom Development platform) have to be connected to the PC using the mini/micro-USB cables.
- The code must be downloaded on the platforms via CMSIS-DAP (or other means).
- After that, two or more TERM applications must be opened, and the serial ports must be configured with the same baud rate as the one in the project (default baud rate is 115200). Other necessary serial configurations are 8 bit, no parity, and 1 stop bit.
- To start the setup, each platform must be reset, and one of the (user) push buttons found on the MCR20A platform must be pressed. The user can press any of the non-reset buttons on the FRDM-K64F Freescale Freedom Development platform as well. *This initiates the state machine of the application so user can start.
Documentation
SMAC Demo Applications User Guide
Revision 25:f40bc034cd8b, committed 2015-04-28
- Comitter:
- sam_grove
- Date:
- Tue Apr 28 16:37:24 2015 -0500
- Parent:
- 24:088286081619
- Child:
- 26:56ca40dcfae1
- Commit message:
- Add mem pool management. Dont use malloc with ARM std lib in IRQ context.
Tx running stable. Rx crashing instantly. Not allocating queue before
being needed.
Changed in this revision
--- a/FSL_IEEE802_15_4_PHY/EmbeddedTypes.h Sat Apr 25 01:10:45 2015 -0500 +++ b/FSL_IEEE802_15_4_PHY/EmbeddedTypes.h Tue Apr 28 16:37:24 2015 -0500 @@ -52,6 +52,8 @@ #include <intrinsics.h> #endif +#include "mem.h" + /************************************************************************************ * * TYPE DEFINITIONS @@ -103,8 +105,8 @@ #define gInvalidInstanceId_c (instanceId_t)(-1) typedef uint32_t instanceId_t; -#define MEM_BufferAlloc(size) malloc(size) -#define MEM_BufferFree(ptr) free(ptr) +#define MEM_BufferAlloc(size) myalloc(size) +#define MEM_BufferFree(ptr) myfree(ptr) #define FLib_MemCpy(pDst, pSrc, size) memcpy(pDst, pSrc, size) #define FLib_MemSet(pDst, value, size) memset(pDst, value, size)
--- a/main.cpp Sat Apr 25 01:10:45 2015 -0500 +++ b/main.cpp Tue Apr 28 16:37:24 2015 -0500 @@ -18,8 +18,8 @@ #endif uint32_t gTaskEventFlags; static uint8_t gau8TxDataBuffer[gMaxSmacSDULength_c + sizeof(rxPacket_t)]; -static txPacket_t *gAppTxPacket; -static rxPacket_t *gAppRxPacket; +txPacket_t *gAppTxPacket; +rxPacket_t *gAppRxPacket; static txContextConfig_t txConfigContext; void InitProject(void); @@ -114,6 +114,7 @@ int main() { + InitMem(extmem, sizeof(extmem)); Thread thread(led_thread); thread2 = new Thread(button_thread); eventsThread = new Thread(events_thread);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mem.c Tue Apr 28 16:37:24 2015 -0500 @@ -0,0 +1,126 @@ + +#include <string.h> + + +char extmem[0x1000] __attribute__((at(0x1FFF0800))); + +typedef +struct +{ + int is_available; + int size; +} MCB, *MCB_P; + + +char *mem_start_p; +int max_mem; +int allocated_mem; /* this is the memory in use. */ +int mcb_count; + +char *heap_end; + +MCB_P memallocate(MCB_P ,int ); + +enum {NEW_MCB=0,NO_MCB,REUSE_MCB}; +enum {FREE,IN_USE}; + +void * myalloc(int elem_size) { + /* check whether any chunk (allocated before) is free first */ + + MCB_P p_mcb; + int flag = NO_MCB; + int sz; + + p_mcb = (MCB_P)mem_start_p; + + + sz = sizeof(MCB); + + if ( (elem_size + sz) > (max_mem - (allocated_mem + mcb_count * sz ) ) ) { + return NULL; + } + while ( heap_end > ( (char *)p_mcb + elem_size + sz) ) { //<<-- problem here doesnt iterate the first block + + if ( p_mcb->is_available == 0) { + + if ( p_mcb->size == 0) { + // printf("\NEW mem: %d ",p_mcb->size); + flag = NEW_MCB; + break; + } + if ( p_mcb->size >= (elem_size + sz) ) { + // printf("\REUSE mem: %d ",p_mcb->size); + flag = REUSE_MCB; + break; + } + } + p_mcb = (MCB_P) ( (char *)p_mcb + p_mcb->size); + + + } + + if ( flag != NO_MCB) { + p_mcb->is_available = 1; + + if ( flag == NEW_MCB) { + p_mcb->size = elem_size + sizeof(MCB); + } else if ( flag == REUSE_MCB) { + elem_size = p_mcb->size - sizeof(MCB); + } + mcb_count++; + allocated_mem += elem_size; + return ( (char *) p_mcb + sz); + } + + return NULL; + + + /* if size of the available chunk is equal to greater than required size, use that chunk */ + + +} + +void myfree(void *p) { + /* Mark in MCB that this chunk is free */ + + MCB_P ptr = (MCB_P)p; + ptr--; + + if (ptr->is_available != FREE) { + mcb_count--; + ptr->is_available = FREE; + allocated_mem -= (ptr->size - sizeof(MCB)); + } + + /* Mark in MCB that this chunk is free */ + /* + MCB_P ptr = (MCB_P)p; + ptr--; + + mcb_count--; + ptr->is_available = FREE; + printf("\nAllocated mem: %d ",ptr->size); + allocated_mem -= (ptr->size - sizeof(MCB)); + printf("\nAllocated mem: %d ",allocated_mem); + printf("\nMemory Freed..."); + */ +} + +void * myrealloc(void *p) { + //I would like to implement this + return NULL; +} + +void InitMem(char *ptr, int size_in_bytes) { + /* store the ptr and size_in_bytes in global variable */ + + max_mem = size_in_bytes; + mem_start_p = ptr; + mcb_count = 0; + allocated_mem = 0; + heap_end = mem_start_p + size_in_bytes; + memset(mem_start_p,0x00,max_mem); + myalloc(2); //<<-- myalloc doesnt iterate the first block, added as temporary fix + /* This function is complete :-) */ + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mem.h Tue Apr 28 16:37:24 2015 -0500 @@ -0,0 +1,20 @@ + +#ifndef MEM_H +#define MEM_H + +#ifdef __cplusplus +extern "C" { +#endif + + +extern char extmem[0x1000]; + +void * myalloc(int elem_size); +void myfree(void *p); +void InitMem(char *ptr, int size_in_bytes); + +#ifdef __cplusplus +} +#endif + +#endif