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 Freescale

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

mem.c

Committer:
sam_grove
Date:
2015-04-28
Revision:
25:f40bc034cd8b

File content as of revision 25:f40bc034cd8b:

#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 :-) */
 
}