
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
Diff: NSDL/nsdl_support.cpp
- Revision:
- 18:b02fc0e53df8
- Parent:
- 17:52cfd7db8da3
- Child:
- 19:71b793021c78
--- a/NSDL/nsdl_support.cpp Wed Mar 18 18:52:47 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,212 +0,0 @@ -// NSDL library support functions - -#include "mbed.h" -#include "nsdl_support.h" -#include "mbed.h" - -#include "socket_api.h" - -#define COAP_UDP_PORT 5683 -extern uint8_t NSP_address_bytes[]; -static ns_address_t app_dest; - -#define MEM_VALID(x) \ - int s##x=0;\ - int *h##x = new int [1];\ - std::printf("[stack]0x%08x\t[heap]0x%08x\t[memory avail]%d bytes \tLine: %d %s\r\n", &s##x, h##x, &s##x-h##x, __LINE__, __FILE__);\ - if (h##x > &s##x)\ - printf("collision\n");\ - else\ - delete [] h##x;\ - __nop() - -extern char endpoint_name[24]; -extern uint8_t ep_type[]; -extern uint8_t lifetime_ptr[]; -char null_ep_name[] = ""; -uint8_t null_ep_type[] = ""; -uint8_t null_lifetime_ptr[] = ""; -bool nsdl_reg_update_needed = false; - -extern int8_t coap_udp_socket; - -void *nsdl_alloc(uint16_t size) -{ - void *buf = malloc(size); - return buf; -} - -void nsdl_free(void* ptr_to_free) -{ - free(ptr_to_free); -} - -/* - * Create a static resoure - * Only get is allowed - */ -void nsdl_create_static_resource(sn_nsdl_resource_info_s *resource_structure, uint16_t pt_len, uint8_t *pt, uint16_t rpp_len, uint8_t *rpp_ptr, uint8_t *rsc, uint16_t rsc_len) -{ - resource_structure->access = SN_GRS_GET_ALLOWED; - resource_structure->mode = SN_GRS_STATIC; - resource_structure->pathlen = pt_len; - resource_structure->path = pt; - resource_structure->resource_parameters_ptr->resource_type_len = rpp_len; - resource_structure->resource_parameters_ptr->resource_type_ptr = rpp_ptr; - resource_structure->resource = rsc; - resource_structure->resourcelen = rsc_len; - sn_nsdl_create_resource(resource_structure); -} - -void nsdl_create_dynamic_resource(sn_nsdl_resource_info_s *resource_structure, uint16_t pt_len, uint8_t *pt, uint16_t rpp_len, uint8_t *rpp_ptr, uint8_t is_observable, sn_grs_dyn_res_callback_t callback_ptr, int access_right) -{ - resource_structure->access = (sn_grs_resource_acl_e)access_right; - resource_structure->resource = 0; - resource_structure->resourcelen = 0; - resource_structure->sn_grs_dyn_res_callback = callback_ptr; - resource_structure->mode = SN_GRS_DYNAMIC; - resource_structure->pathlen = pt_len; - resource_structure->path = pt; - resource_structure->resource_parameters_ptr->resource_type_len = rpp_len; - resource_structure->resource_parameters_ptr->resource_type_ptr = rpp_ptr; - resource_structure->resource_parameters_ptr->observable = is_observable; - sn_nsdl_create_resource(resource_structure); -} - -sn_nsdl_ep_parameters_s* nsdl_init_register_endpoint(sn_nsdl_ep_parameters_s *endpoint_structure, uint8_t* name, uint8_t* typename_ptr, uint8_t *lifetime_ptr) -{ - if (NULL == endpoint_structure) - { - endpoint_structure = (sn_nsdl_ep_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_ep_parameters_s)); - } - if (endpoint_structure) - { - memset(endpoint_structure, 0, sizeof(sn_nsdl_ep_parameters_s)); - endpoint_structure->endpoint_name_ptr = name; - endpoint_structure->endpoint_name_len = strlen((char*)name); - endpoint_structure->type_ptr = typename_ptr; - endpoint_structure->type_len = strlen((char*)typename_ptr); - endpoint_structure->lifetime_ptr = lifetime_ptr; - endpoint_structure->lifetime_len = strlen((char*)lifetime_ptr); - } - return endpoint_structure; -} - -void nsdl_clean_register_endpoint(sn_nsdl_ep_parameters_s **endpoint_structure) -{ - if (*endpoint_structure) - { - nsdl_free(*endpoint_structure); - *endpoint_structure = NULL; - } -} - -static uint8_t tx_cb(sn_nsdl_capab_e protocol, uint8_t *data_ptr, uint16_t datalen, sn_nsdl_addr_s *address_prt) -{ - printf("TX callback!\n\rSending %d bytes...", datalen); - - int8_t socket_ret_value = 0; - memcpy(app_dest.address, address_prt->addr_ptr, 16); - app_dest.identifier = address_prt->port; - app_dest.type = ADDRESS_IPV6; - - socket_ret_value = socket_sendto(coap_udp_socket, &app_dest, data_ptr, datalen); - if(socket_ret_value != 0) - { - printf("Failed\r\n"); - return 0;//failed - } - else - { - printf("Ok\r\n"); - return 1; // success - } -} - -static uint8_t rx_cb(sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr) -{ - printf("RX callback!\r\n"); - printf("msg_code: %d \r\n", coap_packet_ptr->msg_code); - printf("Payload length: %d bytes\r\n", coap_packet_ptr->payload_len); - int i; - printf("Payload:'"); - for (i=0; i < coap_packet_ptr->payload_len; i++) - printf("%c", *(coap_packet_ptr->payload_ptr + i)); - printf("' \r\n"); - if (coap_packet_ptr->options_list_ptr && coap_packet_ptr->options_list_ptr->location_path_ptr) - { - printf("Location: /"); - int i; - for (i=0; i < coap_packet_ptr->options_list_ptr->location_path_len; i++) printf("%c", (char)(coap_packet_ptr->options_list_ptr->location_path_ptr[i])); - printf(" \r\n"); - } - //sn_coap_packet_debug(coap_packet_ptr); - return 0; -} - - -void NSP_registration( ) { - sn_nsdl_ep_parameters_s *endpoint_ptr = NULL; - - endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr); - if(sn_nsdl_register_endpoint(endpoint_ptr) != 0) - printf("NSP re-registering failed\r\n"); - else - printf("NSP re-registering OK\r\n"); - nsdl_clean_register_endpoint(&endpoint_ptr); -} - - -void nsdl_init() -{ - //uint8_t nsp_addr[4]; - sn_nsdl_mem_s memory_cbs; - - /* Initialize libNsdl */ - memory_cbs.sn_nsdl_alloc = &nsdl_alloc; - memory_cbs.sn_nsdl_free = &nsdl_free; - if(sn_nsdl_init(&tx_cb, &rx_cb, &memory_cbs) == -1) - printf("libNsdl init failed\r\n"); - else - printf("libNsdl init done\r\n"); - /* Set nsp address for library */ - set_NSP_address(NSP_address_bytes, COAP_UDP_PORT, SN_NSDL_ADDRESS_TYPE_IPV6); -} - -void nsdl_reg_update() - { - sn_nsdl_ep_parameters_s *endpoint_ptr = NULL; -// endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr); -// reg update should be invoked with null parameters if nothing is changing - endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)null_ep_name, null_ep_type, null_lifetime_ptr); - if(sn_nsdl_update_registration(endpoint_ptr) != 0) - printf("NSP re-registering failed\r\n"); - else - printf("NSP re-registering OK\r\n"); - nsdl_clean_register_endpoint(&endpoint_ptr); - } - -void nsdl_reg_update_timeout() - { - nsdl_reg_update_needed = true; - } - -void nsdl_event_loop() -{ - - sn_nsdl_addr_s received_packet_address; - uint8_t received_address[4]; - - memset(&received_packet_address, 0, sizeof(sn_nsdl_addr_s)); - received_packet_address.addr_ptr = received_address; - - while(1) - { - // pc.printf("checking reg timeout\r\n"); - if (nsdl_reg_update_needed) - { - nsdl_reg_update_needed = false; - nsdl_reg_update(); - } - } -}