Update revision to use TI's mqtt and Freertos.
Dependencies: mbed client server
Fork of cc3100_Test_mqtt_CM3 by
Revision 0:dbe5e7db3c45, committed 2015-06-06
- Comitter:
- dflet
- Date:
- Sat Jun 06 13:32:15 2015 +0000
- Child:
- 1:718c4be430a4
- Commit message:
- Revision update to include TI's mtqq and Freertos
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FreeRTOS_V8_2_1.lib Sat Jun 06 13:32:15 2015 +0000 @@ -0,0 +1,1 @@ +FreeRTOS_V8_2_1#91ad48ad5687
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cli_uart.cpp Sat Jun 06 13:32:15 2015 +0000
@@ -0,0 +1,62 @@
+
+#include "mbed.h"
+#include "myBoardInit.h"
+#include "cli_uart.h"
+#include "osi.h"
+#include "stdio.h"
+
+OsiLockObj_t g_printLock;
+#if (THIS_BOARD == Seeed_Arch_Max)
+Serial uart(PA_9, PA_10);
+#elif (THIS_BOARD == EA_MBED_LPC4088)
+Serial uart(p37, p31);
+#elif (THIS_BOARD == MBED_BOARD_LPC1768)
+Serial uart(p13, p14);
+#endif
+
+int Uart_Write(unsigned char *inBuff)
+{
+ uint16_t ret, ecount, usLength = strlen((const char *)inBuff);
+ ecount = 0;
+ ret = 0;
+
+ while(!(uart.writeable())){ecount++;if(ecount>3000)break;};
+
+ if(uart.writeable()) {
+
+ if(inBuff == NULL) {
+ printf("Uart Write buffer empty\r\n");
+ return -1;
+ }
+
+ RTOS_MUTEX_ACQUIRE(&g_printLock);
+ ret = usLength;
+
+ while (usLength) {
+ uart.putc(*inBuff);
+ usLength--;
+ inBuff++;
+ }
+
+ RTOS_MUTEX_RELEASE(&g_printLock);
+ } else {
+ printf("Uart Write failed [uart not writeable] now trying printf\r\n");
+ while (usLength) {
+ printf("%c",*inBuff);
+ usLength--;
+ inBuff++;
+ }
+ return -1;
+ }
+
+ return (int)ret;
+
+}
+
+void CLI_Configure(void)
+{
+ uart.baud(115200);
+
+ RTOS_MUTEX_CREATE(&g_printLock);
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cli_uart.h Sat Jun 06 13:32:15 2015 +0000
@@ -0,0 +1,24 @@
+
+
+#ifndef cli_uart_H
+#define cli_uart_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define RTOS_MUTEX_CREATE(x) osi_LockObjCreate(x)
+#define RTOS_MUTEX_ACQUIRE(x) osi_LockObjLock(x, (OsiTime_t) OSI_WAIT_FOREVER)
+#define RTOS_MUTEX_RELEASE(x) osi_LockObjUnlock(x)
+#define RTOS_MUTEX_DELETE(x) osi_LockObjDelete(x)
+
+int32_t Uart_Write(unsigned char *inBuff);
+
+void CLI_Configure(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Jun 06 13:32:15 2015 +0000
@@ -0,0 +1,867 @@
+/*
+ * mqtt_client.c - Sample application to connect to a MQTT broker and
+ * exercise functionalities like subscribe, publish etc.
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ * All rights reserved. Property of Texas Instruments Incorporated.
+ * Restricted rights to use, duplicate or disclose this code are
+ * granted through contract.
+ *
+ * The program may not be used without the written permission of
+ * Texas Instruments Incorporated or against the terms and conditions
+ * stipulated in the agreement under which this program has been supplied,
+ * and under no circumstances can it be used with non-TI connectivity device.
+ *
+ *
+ * Application Name - MQTT Client
+ * Application Overview - This application acts as a MQTT client and connects
+ * to the IBM MQTT broker, simultaneously we can
+ * connect a web client from a web browser. Both
+ * clients can inter-communicate using appropriate
+ * topic names.
+ *
+ * Application Details - http://processors.wiki.ti.com/index.php/CC31xx_MQTT_Client
+ * docs\examples\mqtt_client.pdf
+ *
+ */
+
+/*
+ *
+ *! \addtogroup mqtt_client
+ *! @{
+ *
+ */
+
+/* Standard includes */
+#include "mbed.h"
+
+#include "simplelink_V2/cc3100_simplelink.h"
+#include "simplelink_V2/cc3100_sl_common.h"
+#include "simplelink_V2/G_functions/fPtr_func.h"
+#include "simplelink_V2/cc3100.h"
+#include "cli_uart.h"
+#include "myBoardInit.h"
+
+/* Free-RTOS includes */
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+#include "portmacro.h"
+
+#include "osi.h"
+
+//#include <stdio.h>
+//#include <stdlib.h>
+
+#include "mqtt_client.h"
+#include "sl_mqtt_client.h"
+#include "mqtt_config.h"
+
+using namespace mbed_cc3100;
+using namespace mbed_mqtt;
+
+int32_t demo = 0;
+
+#if (THIS_BOARD == MBED_BOARD_LPC1768)
+//Serial pc(USBTX, USBRX);//lpc1768
+ DigitalOut led1(LED1);
+ DigitalOut led2(LED2);
+// DigitalOut led1(P1_28);/* For LPC1769 */
+// DigitalOut led2(P1_29);/* For LPC1769 */
+cc3100 _cc3100(p16, p17, p9, p10, p8, SPI(p5, p6, p7));//LPC1768 irq, nHib, cs, mosi, miso, sck
+//cc3100 _cc3100(p14, p15, p9, p10, p8, SPI(p11, p12, p13));//LPC1768 irq, nHib, cs, mosi, miso, sck
+#elif (THIS_BOARD == ST_MBED_NUCLEOF411)
+Serial pc(SERIAL_TX, SERIAL_RX);//nucleoF411
+cc3100 _cc3100(PA_9, PC_7, PB_6, SPI(PA_7, PA_6, PA_5));//nucleoF411 irq, nHib, cs, mosi, miso, sck
+#elif (THIS_BOARD == ST_MBED_NUCLEOF401)
+Serial pc(SERIAL_TX, SERIAL_RX);//nucleoF401
+ DigitalOut led1(LED1);
+ DigitalOut led2(LED2);
+cc3100 _cc3100(PA_8, PA_9, PC_7, PB_6, SPI(PA_7, PA_6, PA_5));//nucleoF401 irq, nHib, cs, mosi, miso, sck
+#elif (THIS_BOARD == EA_MBED_LPC4088)
+//Serial pc(USBTX, USBRX);//EA_lpc4088
+ DigitalOut led1(LED1);
+ DigitalOut led2(LED2);
+ DigitalOut led3(LED3);
+ DigitalOut led4(LED4);
+cc3100 _cc3100(p14, p15, p9, p10, p8, SPI(p5, p6, p7));//LPC4088 irq, nHib, cs, mosi, miso, sck
+#elif (THIS_BOARD == ST_MBED_NUCLEOF103)
+Serial pc(SERIAL_TX, SERIAL_RX);
+cc3100 _cc3100(PA_9, PC_7, PB_6, SPI(PA_7, PA_6, PA_5));//nucleoF103 irq, nHib, cs, mosi, miso, sck
+#elif (THIS_BOARD == Seeed_Arch_Max)
+Serial pc(USBTX, USBRX);
+ DigitalOut led1(LED1);
+ DigitalOut led2(LED2);
+ InterruptIn button1(PC_13);
+cc3100 _cc3100(PE_5, PE_4, PE_6, SPI(PB_5, PB_4, PB_3));//Seeed_Arch_Max irq, nHib, cs, mosi, miso, sck
+//SDFileSystem sd(PE_2, PD_11, SPI(PC_3, PC_2, PB_10), "sd", SDFileSystem::SWITCH_NEG_NC, 25000000);
+#elif (THIS_BOARD == LPCXpresso4337)
+/* LPCXpresso4337 not working due to mbed lib */
+//Serial pc(UART0_TX, UART0_RX);
+cc3100 _cc3100(P2_2, P3_5, P1_2, SPI(P1_4, P1_3, PF_4));//LPCXpresso4337 irq, nHib, cs, mosi, miso, sck
+#else
+
+#endif
+
+#define APPLICATION_VERSION "1.1.0"
+#define SL_STOP_TIMEOUT 0xFF
+
+#undef LOOP_FOREVER
+#define LOOP_FOREVER() \
+ {\
+ while(1) \
+ { \
+ osi_Sleep(10); \
+ } \
+ }
+
+
+#define PRINT_BUF_LEN 128
+int8_t print_buf[PRINT_BUF_LEN];
+
+/* Application specific data types */
+typedef struct connection_config
+{
+ SlMqttClientCtxCfg_t broker_config;
+ void *clt_ctx;
+ const char *client_id;
+ uint8_t *usr_name;
+ uint8_t *usr_pwd;
+ bool is_clean;
+ uint32_t keep_alive_time;
+ SlMqttClientCbs_t CallBAcks;
+ int32_t num_topics;
+ char *topic[SUB_TOPIC_COUNT];
+ uint8_t qos[SUB_TOPIC_COUNT];
+ SlMqttWill_t will_params;
+ bool is_connected;
+} connect_config;
+
+/*
+ * GLOBAL VARIABLES -- Start
+ */
+uint32_t g_publishCount = 0;
+OsiMsgQ_t g_PBQueue; /*Message Queue*/
+
+/*
+ * GLOBAL VARIABLES -- End
+ */
+
+/*
+ * STATIC FUNCTION DEFINITIONS -- Start
+ */
+static void displayBanner(void);
+static void Mqtt_Recv(void *application_hndl, const char *topstr, int32_t top_len,
+ const void *payload, int32_t pay_len, bool dup,uint8_t qos, bool retain);
+static void sl_MqttEvt(void *application_hndl,int32_t evt, const void *buf, uint32_t len);
+static void sl_MqttDisconnect(void *application_hndl);
+static int32_t Dummy(const char *inBuff, ...);
+static void MqttClient(void *pvParameters);
+void toggleLed(int ind);
+void initLEDs(void);
+
+/*
+ * STATIC FUNCTION DEFINITIONS -- End
+ */
+
+/*
+ * APPLICATION SPECIFIC DATA -- Start
+ */
+/* Connection configuration */
+connect_config usr_connect_config[] =
+{
+ {
+ {
+ {
+ SL_MQTT_NETCONN_URL,
+ SERVER_ADDRESS,
+ PORT_NUMBER,
+ 0,
+ 0,
+ 0,
+ NULL
+ },
+ SERVER_MODE,
+ true,
+ },
+ NULL,
+ "user1",
+// CLIENT_ID, /* Must be unique */
+ NULL,
+ NULL,
+ true,
+ KEEP_ALIVE_TIMER,
+ {&Mqtt_Recv, &sl_MqttEvt, &sl_MqttDisconnect},
+ SUB_TOPIC_COUNT,
+ {SUB_TOPIC1, SUB_TOPIC2},
+ {QOS2, QOS2},
+ {WILL_TOPIC, WILL_MSG, WILL_QOS, WILL_RETAIN},
+ false
+ }
+};
+
+/* library configuration */
+SlMqttClientLibCfg_t Mqtt_Client =
+{
+ LOOPBACK_PORT_NUMBER,
+ TASK_PRIORITY,
+ RCV_TIMEOUT,
+ true,
+ (int32_t(*)(const char *, ...))Dummy
+};
+
+void initLEDs(void){
+
+#if (THIS_BOARD == EA_MBED_LPC4088)
+ led1 = 1;
+ led2 = 1;
+ led3 = 0;
+ led4 = 0;
+#else
+ led1 = 0;
+ led2 = 0;
+#endif
+
+}
+
+void toggleLed(int ind){
+
+ if(ind == 1){
+ led1 = !led1;
+ }
+ if(ind == 2){
+ led2 = !led2;
+ }
+
+}
+
+/*Publishing topics and messages*/
+const char *pub_topic_1 = PUB_TOPIC_1;
+const char *pub_topic_2 = PUB_TOPIC_2;
+const char *data_1={"Push button sw1 is pressed: Data 1"};
+const char *data_2={"Push button sw2 is pressed: Data 2"};
+void *g_application_hndl = (void*)usr_connect_config;
+/*
+ * APPLICATION SPECIFIC DATA -- End
+ */
+
+/*Dummy print message*/
+static int32_t Dummy(const char *inBuff, ...)
+{
+ return 0;
+}
+
+/*!
+ \brief Defines Mqtt_Pub_Message_Receive event handler.
+ Client App needs to register this event handler with sl_ExtLib_mqtt_Init
+ API. Background receive task invokes this handler whenever MQTT Client
+ receives a Publish Message from the broker.
+
+ \param[out] topstr => pointer to topic of the message
+ \param[out] top_len => topic length
+ \param[out] payload => pointer to payload
+ \param[out] pay_len => payload length
+ \param[out] retain => Tells whether its a Retained message or not
+ \param[out] dup => Tells whether its a duplicate message or not
+ \param[out] qos => Tells the Qos level
+
+ \return none
+ */
+static void
+Mqtt_Recv(void *application_hndl, const char *topstr, int32_t top_len, const void *payload,
+ int32_t pay_len, bool dup,uint8_t qos, bool retain)
+{
+ int8_t *output_str=(int8_t*)malloc(top_len+1);
+ memset(output_str,'\0',top_len+1);
+ strncpy((char*)output_str, topstr, top_len);
+ output_str[top_len]='\0';
+
+ if(strncmp((char*)output_str, SUB_TOPIC1, top_len) == 0)
+ {
+ toggleLed(1);
+ }
+ else if(strncmp((char*)output_str, SUB_TOPIC2, top_len) == 0)
+ {
+ toggleLed(2);
+ }
+
+ Uart_Write((uint8_t*)"\n\r Publish Message Received\r\n");
+
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, "\n\r Topic: %s", output_str);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+ free(output_str);
+
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " [Qos: %d] ", qos);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+
+ if(retain){
+ Uart_Write((uint8_t*)" [Retained]\r\n");
+ }
+ if(dup){
+ Uart_Write((uint8_t*)" [Duplicate]\r\n");
+ }
+ output_str=(int8_t*)malloc(pay_len+1);
+ memset(output_str,'\0',pay_len+1);
+ strncpy((char*)output_str, (const char*)payload, pay_len);
+ output_str[pay_len]='\0';
+
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " \n\r Data is: %s\n\r", (char*)output_str);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+
+ free(output_str);
+
+ return;
+}
+
+/*!
+ \brief Defines sl_MqttEvt event handler.
+ Client App needs to register this event handler with sl_ExtLib_mqtt_Init
+ API. Background receive task invokes this handler whenever MQTT Client
+ receives an ack(whenever user is in non-blocking mode) or encounters an error.
+
+ \param[out] evt => Event that invokes the handler. Event can be of the
+ following types:
+ MQTT_ACK - Ack Received
+ MQTT_ERROR - unknown error
+
+
+ \param[out] buf => points to buffer
+ \param[out] len => buffer length
+
+ \return none
+ */
+static void
+sl_MqttEvt(void *application_hndl,int32_t evt, const void *buf,uint32_t len)
+{
+ int32_t i;
+
+ switch(evt)
+ {
+ case SL_MQTT_CL_EVT_PUBACK:
+ {
+ Uart_Write((uint8_t*)" PubAck:\n\r");
+ }
+ break;
+
+ case SL_MQTT_CL_EVT_SUBACK:
+ {
+ Uart_Write((uint8_t*)"\n\r Granted QoS Levels\n\r");
+
+ for(i=0;i<len;i++)
+ {
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " QoS %d\n\r",((uint8_t*)buf)[i]);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+ }
+ }
+ break;
+
+ case SL_MQTT_CL_EVT_UNSUBACK:
+ {
+ Uart_Write((uint8_t*)" UnSub Ack:\n\r");
+ }
+ break;
+
+ default:
+ {
+ Uart_Write((uint8_t*)" [MQTT EVENT] Unexpected event \n\r");
+ }
+ break;
+ }
+}
+
+/*!
+
+ \brief callback event in case of MQTT disconnection
+
+ \param application_hndl is the handle for the disconnected connection
+
+ \return none
+
+*/
+static void
+sl_MqttDisconnect(void *application_hndl)
+{
+ connect_config *local_con_conf;
+ osi_messages var = BROKER_DISCONNECTION;
+ local_con_conf = (connect_config*)application_hndl;
+ sl_ExtLib_MqttClientUnsub(local_con_conf->clt_ctx, local_con_conf->topic,
+ SUB_TOPIC_COUNT);
+
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " Disconnect from broker %s\r\n",
+ (local_con_conf->broker_config).server_info.server_addr);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+
+ local_con_conf->is_connected = false;
+ sl_ExtLib_MqttClientCtxDelete(local_con_conf->clt_ctx);
+
+ /*
+ * Write message indicating publish message
+ */
+ osi_MsgQWrite(&g_PBQueue, &var, OSI_NO_WAIT);
+}
+
+/*
+ \brief Application defined hook (or callback) function - assert
+
+ \param[in] pcFile - Pointer to the File Name
+ \param[in] ulLine - Line Number
+
+ \return none
+*/
+void vAssertCalled(const int8_t *pcFile, uint32_t ulLine)
+{
+ /* Handle Assert here */
+ while(1)
+ {
+ }
+}
+
+/*
+
+ \brief Application defined idle task hook
+
+ \param none
+
+ \return none
+
+ */
+void vApplicationIdleHook(void)
+{
+ /* Handle Idle Hook for Profiling, Power Management etc */
+}
+
+/*
+
+ \brief Application defined malloc failed hook
+
+ \param none
+
+ \return none
+
+ */
+void vApplicationMallocFailedHook(void)
+{
+ /* Handle Memory Allocation Errors */
+ while(1)
+ {
+ }
+}
+
+/*
+
+ \brief Application defined stack overflow hook
+
+ \param none
+
+ \return none
+
+ */
+void vApplicationStackOverflowHook( OsiTaskHandle *pxTask,
+ int8_t *pcTaskName )
+{
+ /* Handle FreeRTOS Stack Overflow */
+ while(1)
+ {
+ }
+}
+
+/*!
+ \brief Publishes the message on a topic.
+
+ \param[in] clt_ctx - Client context
+ \param[in] publish_topic - Topic on which the message will be published
+ \param[in] publish_data - The message that will be published
+
+ \return none
+ */
+static void
+publishData(void *clt_ctx, const char *publish_topic, uint8_t *publish_data)
+{
+// printf("publishData\n\r");
+ int32_t retVal = -1;
+
+ /*
+ * Send the publish message
+ */
+ retVal = sl_ExtLib_MqttClientSend((void*)clt_ctx,
+ publish_topic ,publish_data, strlen((const char*)publish_data), QOS2, RETAIN);
+ if(retVal < 0)
+ {
+ Uart_Write((uint8_t*)"\n\r CC3100 failed to publish the message\n\r");
+ return;
+ }
+
+ Uart_Write((uint8_t*)"\n\r CC3100 Publishes the following message \n\r");
+
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " Topic: %s\n\r", publish_topic);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " Data: %s\n\r", publish_data);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+}
+
+/*!
+
+ \brief Task implementing MQTT client communication to other web client through
+ a broker
+
+ \param none
+
+ This function
+ 1. Initializes network driver and connects to the default AP
+ 2. Initializes the mqtt library and set up MQTT connection configurations
+ 3. set up the button events and their callbacks(for publishing)
+ 4. handles the callback signals
+
+ \return none
+
+ */
+static void MqttClient(void *pvParameters)
+{
+ //Uart_Write((uint8_t*)"MqttClient\r\n");
+ int32_t retVal = -1;
+ int32_t iCount = 0;
+ int32_t iNumBroker = 0;
+ int32_t iConnBroker = 0;
+ osi_messages RecvQue;
+
+ connect_config *local_con_conf = (connect_config *)g_application_hndl;
+
+ /* Configure LED */
+ initLEDs();
+ _cc3100._spi.button1_InterruptEnable();
+ _cc3100._spi.button2_InterruptEnable();
+// registerButtonIrqHandler(buttonHandler, NULL);
+
+ /*
+ * Following function configures the device to default state by cleaning
+ * the persistent settings stored in NVMEM (viz. connection profiles &
+ * policies, power policy etc)
+ *
+ * Applications may choose to skip this step if the developer is sure
+ * that the device is in its default state at start of application
+ *
+ * Note that all profiles and persistent settings that were done on the
+ * device will be lost
+ */
+ retVal = _cc3100.configureSimpleLinkToDefaultState();
+ if(retVal < 0)
+ {
+ if(DEVICE_NOT_IN_STATION_MODE == retVal)
+ Uart_Write((uint8_t*)" Failed to configure the device in its default state \n\r");
+
+ LOOP_FOREVER();
+ }
+
+ Uart_Write((uint8_t*)" Device is configured in default state \n\r");
+
+ /*
+ * Assumption is that the device is configured in station mode already
+ * and it is in its default state
+ */
+ retVal = _cc3100.sl_Start(0, 0, 0);
+ if ((retVal < 0) ||
+ (ROLE_STA != retVal) )
+ {
+ Uart_Write((uint8_t*)" Failed to start the device \n\r");
+ LOOP_FOREVER();
+ }
+
+ Uart_Write((uint8_t*)" Device started as STATION \n\r");
+
+ /* Connecting to WLAN AP */
+ retVal = _cc3100.establishConnectionWithAP();
+ if(retVal < 0)
+ {
+ Uart_Write((uint8_t*)" Failed to establish connection w/ an AP \n\r");
+ LOOP_FOREVER();
+ }
+
+ Uart_Write((uint8_t*)"\r\n Connection established with AP\n\r");
+
+ /* Initialize MQTT client lib */
+ retVal = sl_ExtLib_MqttClientInit(&Mqtt_Client);
+ if(retVal != 0)
+ {
+ /* lib initialization failed */
+ Uart_Write((uint8_t*)"MQTT Client lib initialization failed\n\r");
+ LOOP_FOREVER();
+ }
+// Uart_Write((uint8_t*)"MQTT Client lib initialized\n\r");
+
+ /*
+ * Connection to the broker
+ */
+ iNumBroker = sizeof(usr_connect_config)/sizeof(connect_config);
+ if(iNumBroker > MAX_BROKER_CONN)
+ {
+ Uart_Write((uint8_t*)"Num of brokers are more then max num of brokers\n\r");
+ LOOP_FOREVER();
+ }
+// Uart_Write((uint8_t*)"Num of brokers %i\n\r",iNumBroker);
+
+ while(iCount < iNumBroker)
+ {
+ /*
+ * create client context
+ */
+
+ local_con_conf[iCount].clt_ctx =
+ sl_ExtLib_MqttClientCtxCreate(&local_con_conf[iCount].broker_config,
+ &local_con_conf[iCount].CallBAcks,
+ &(local_con_conf[iCount]));
+
+ /*
+ * Set Client ID
+ */
+ sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
+ SL_MQTT_PARAM_CLIENT_ID,
+ local_con_conf[iCount].client_id,
+ strlen((local_con_conf[iCount].client_id)));
+
+ /*
+ * Set will Params
+ */
+ if(local_con_conf[iCount].will_params.will_topic != NULL)
+ {
+ sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
+ SL_MQTT_PARAM_WILL_PARAM,
+ &(local_con_conf[iCount].will_params),
+ sizeof(SlMqttWill_t));
+ }
+
+ /*
+ * Setting user name and password
+ */
+ if(local_con_conf[iCount].usr_name != NULL)
+ {
+ sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
+ SL_MQTT_PARAM_USER_NAME,
+ local_con_conf[iCount].usr_name,
+ strlen((const char*)local_con_conf[iCount].usr_name));
+
+ if(local_con_conf[iCount].usr_pwd != NULL)
+ {
+ sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
+ SL_MQTT_PARAM_PASS_WORD,
+ local_con_conf[iCount].usr_pwd,
+ strlen((const char*)local_con_conf[iCount].usr_pwd));
+ }
+ }
+
+ /*
+ * Connecting to the broker
+ */
+ if((sl_ExtLib_MqttClientConnect((void*)local_con_conf[iCount].clt_ctx,
+ local_con_conf[iCount].is_clean,
+ local_con_conf[iCount].keep_alive_time) & 0xFF) != 0)
+ {
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, "\n\r Broker connect failed for conn no. %d \n\r", (int16_t)iCount+1);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+
+ /*
+ * Delete the context for this connection
+ */
+ sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);
+
+ break;
+ }
+ else
+ {
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, "\n\r Success: conn to Broker no. %d \n\r ", (int16_t)iCount+1);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+
+ local_con_conf[iCount].is_connected = true;
+ iConnBroker++;
+ }
+
+ /*
+ * Subscribe to topics
+ */
+ if(sl_ExtLib_MqttClientSub((void*)local_con_conf[iCount].clt_ctx,
+ local_con_conf[iCount].topic,
+ local_con_conf[iCount].qos, SUB_TOPIC_COUNT) < 0)
+ {
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, "\n\r Subscription Error for conn no. %d \n\r", (int16_t)iCount+1);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+
+ Uart_Write((uint8_t*)"Disconnecting from the broker\r\n");
+
+ sl_ExtLib_MqttClientDisconnect(local_con_conf[iCount].clt_ctx);
+ local_con_conf[iCount].is_connected = false;
+
+ /*
+ * Delete the context for this connection
+ */
+ sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);
+ iConnBroker--;
+ break;
+ }
+ else
+ {
+ int32_t iSub;
+
+ Uart_Write((uint8_t*)"Client subscribed on following topics:\n\r");
+ for(iSub = 0; iSub < local_con_conf[iCount].num_topics; iSub++)
+ {
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " %s\n\r", local_con_conf[iCount].topic[iSub]);
+ Uart_Write((uint8_t*)print_buf); Uart_Write((uint8_t*)"\r\n");
+ }
+ }
+ iCount++;
+ }
+
+ if(iConnBroker < 1)
+ {
+ /*
+ * No successful connection to broker
+
+ */
+ Uart_Write((uint8_t*)"No successful connections to a broker\r\n");
+ goto end;
+ }
+
+ iCount = 0;
+
+ for(;;)
+ {
+ Uart_Write((uint8_t*)"Waiting for button push event\r\n");
+ osi_MsgQRead( &g_PBQueue, &RecvQue, OSI_WAIT_FOREVER);
+
+ if(PUSH_BUTTON_1_PRESSED == RecvQue)
+ {
+ publishData((void*)local_con_conf[iCount].clt_ctx, pub_topic_1, (uint8_t*)data_1);
+ _cc3100._spi.button1_InterruptEnable();
+ }
+ else if(PUSH_BUTTON_2_PRESSED == RecvQue)
+ {
+ publishData((void*)local_con_conf[iCount].clt_ctx, pub_topic_2, (uint8_t*)data_2);
+ _cc3100._spi.button2_InterruptEnable();
+ }
+ else if(BROKER_DISCONNECTION == RecvQue)
+ {
+ iConnBroker--;
+ if(iConnBroker < 1)
+ {
+ /*
+ * Device not connected to any broker
+ */
+ Uart_Write((uint8_t*)"\n\r Device not connected to any broker\n\r");
+ goto end;
+ }
+ }
+ //Uart_Write((uint8_t*)"\n\r Unknown event occured\n\r");
+ }
+
+end:
+ /*
+ * De-initializing the client library
+ */
+ sl_ExtLib_MqttClientExit();
+
+ Uart_Write((uint8_t*)"\n\r Exiting the Application\n\r");
+
+ LOOP_FOREVER();
+}
+
+
+/*
+ * Application's entry point
+ */
+int main(int argc, char** argv)
+{
+ int rv = 0;
+// SCB->SHCSR |= 0x00070000;//Enable fault handler.
+// pc.baud(115200);
+
+ CLI_Configure();
+
+ memset(print_buf, 0x00, PRINT_BUF_LEN);
+ sprintf((char*) print_buf, " \r\nSystemCoreClock = %dMHz\r\n ", SystemCoreClock /1000000);
+ rv = Uart_Write((uint8_t *) print_buf);
+ if(rv < 0){
+ while(1){
+ toggleLed(1);
+ wait(0.1);
+ }
+ }
+
+ int32_t retVal = -1;
+
+ //
+ // Display Application Banner
+ //
+ displayBanner();
+
+ createMutex();
+
+ /*
+ * Start the SimpleLink Host
+ */
+ retVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
+ if(retVal < 0)
+ {
+ Uart_Write((uint8_t*)"VStartSimpleLinkSpawnTask Failed\r\n");
+ LOOP_FOREVER();
+ }
+
+// retVal = _cc3100.initializeAppVariables();
+// ASSERT_ON_ERROR(retVal);
+
+// _cc3100.CLR_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE);
+// g_PingPacketsRecv = 0;
+
+ /*
+ * Start the MQTT Client task
+ */
+ osi_MsgQCreate(&g_PBQueue,"PBQueue",sizeof(osi_messages),MAX_QUEUE_MSG);
+ retVal = osi_TaskCreate(MqttClient,
+ (const int8_t *)"Mqtt Client App",
+ OSI_STACK_SIZE, NULL, MQTT_APP_TASK_PRIORITY, NULL );
+
+ if(retVal < 0)
+ {
+ Uart_Write((uint8_t*)"osi_TaskCreate Failed\r\n");
+ LOOP_FOREVER();
+ }
+
+ /*
+ * Start the task scheduler
+ */
+ Uart_Write((uint8_t*)"Start the task scheduler\r\n");
+ osi_start();
+
+ return 0;
+}
+
+/*!
+ \brief This function displays the application's banner
+
+ \param None
+
+ \return None
+*/
+static void displayBanner()
+{
+ Uart_Write((uint8_t*)"\r\n");
+ Uart_Write((uint8_t*)" *************************************************\r\n");
+ Uart_Write((uint8_t*)" MQTT Client Application - Version\r\n");
+ Uart_Write((uint8_t*)" *************************************************\r\n");
+ Uart_Write((uint8_t*)"\r\n");
+}
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Jun 06 13:32:15 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mqtt_V1.lib Sat Jun 06 13:32:15 2015 +0000 @@ -0,0 +1,1 @@ +mqtt_V1#698866e331b2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mqtt_config.h Sat Jun 06 13:32:15 2015 +0000
@@ -0,0 +1,118 @@
+/*
+ * mqtt_config.h - MQTT Client configurations
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 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.
+ *
+ * Neither the name of Texas Instruments Incorporated 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 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 COPYRIGHT
+ * OWNER 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.
+ *
+ */
+
+#ifndef __MQTT_CONFIG_H__
+#define __MQTT_CONFIG_H__
+
+//*****************************************************************************
+//
+// If building with a C++ compiler, make all of the definitions in this header
+// have a C binding.
+//
+//*****************************************************************************
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*Operate Lib in MQTT 3.1 mode.*/
+#define MQTT_3_1_1 false /*MQTT 3.1.1 */
+#define MQTT_3_1 true /*MQTT 3.1 */
+
+#define WILL_TOPIC "Client"
+#define WILL_MSG "Client Stopped"
+#define WILL_QOS QOS2
+#define WILL_RETAIN false
+
+/*Defining Broker IP address and port Number*/
+#define SERVER_ADDRESS "messagesight.demos.ibm.com"
+#define PORT_NUMBER 1883
+
+/* Client ID must be unique*/
+const char* CLIENT_ID = "garfield007";
+#define MAX_BROKER_CONN 1
+#define SERVER_MODE MQTT_3_1
+
+/*Specifying Receive time out for the Receive task*/
+#define RCV_TIMEOUT 30
+
+/* Keep Alive Timer value in seconds.
+ * Maximum time interval between messages received from a client.
+ */
+#define KEEP_ALIVE_TIMER 25
+
+/* Clean session flag. The server must discard any previously
+ * maintained information about the client.
+ */
+#define CLEAN_SESSION true
+
+/* Retain Flag. Used in publish message.
+ * The server should hold on to the publish message after it has
+ * been delivered to the current subscribers.
+ */
+#define RETAIN 1
+
+/* Defining Publish Topics */
+#define PUB_TOPIC_1 "/cc3100/ButtonPressTopic1"
+#define PUB_TOPIC_2 "/cc3100/ButtonPressTopic2"
+
+/* Defining number of subscribe topics */
+#define SUB_TOPIC_COUNT 2
+
+/* Defining Subscription Topics */
+#define SUB_TOPIC1 "/cc3100/ToggleLEDCmdL1"
+#define SUB_TOPIC2 "/cc3100/ToggleLEDCmdL2"
+
+/* Defining QOS levels */
+#define QOS0 0
+#define QOS1 1
+#define QOS2 2
+
+/* Task priorities and OSI Stack Size */
+#define OSI_STACK_SIZE (2048)
+#define SPAWN_TASK_PRIORITY 9 //7
+#define MQTT_APP_TASK_PRIORITY 2 //2
+#define TASK_PRIORITY 2 //3
+
+#define MAX_QUEUE_MSG 10
+
+#define LOOPBACK_PORT_NUMBER 1882
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /*__MQTT_CONFIG_H__*/
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myBoardInit.h Sat Jun 06 13:32:15 2015 +0000 @@ -0,0 +1,41 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef myBoardInit_H +#define myBoardInit_H + + +#define MBED_BOARD_LPC1768 10 +#define ST_MBED_NUCLEOF411 20 +#define EA_MBED_LPC4088 30 +#define ST_MBED_NUCLEOF103 40 +#define ST_MBED_NUCLEOF401 50 +#define Seeed_Arch_Max 60 +#define LPCXpresso4337 70 +#define UNDEFINED 80//add new board here + +#define THIS_BOARD MBED_BOARD_LPC1768 +//#define THIS_BOARD ST_MBED_NUCLEOF411 +//#define THIS_BOARD EA_MBED_LPC4088 +//#define THIS_BOARD ST_MBED_NUCLEOF103 +//#define THIS_BOARD ST_MBED_NUCLEOF401 +//#define THIS_BOARD Seeed_Arch_Max +//#define THIS_BOARD LPCXpresso4337 + + + +#endif + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/oslib/osi.h Sat Jun 06 13:32:15 2015 +0000
@@ -0,0 +1,595 @@
+//*****************************************************************************
+// osi.h
+//
+// MACRO and Function prototypes for TI-RTOS and Free-RTOS API calls
+//
+// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// Redistributions of source code must retain the above copyright
+// notice, this list zof conditions and the following disclaimer.
+//
+// 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.
+//
+// Neither the name of Texas Instruments Incorporated 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 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 COPYRIGHT
+// OWNER 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.
+//
+//*****************************************************************************
+
+#ifndef __OSI_H__
+#define __OSI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "portable.h"
+
+#define OSI_WAIT_FOREVER (0xFFFFFFFF)
+
+#define OSI_NO_WAIT (0)
+
+typedef int OsiReturnVal_e;
+
+#define OSI_OK (0)
+#define OSI_FAILURE (-1)
+#define OSI_OPERATION_FAILED (-2)
+#define OSI_ABORTED (-3)
+#define OSI_INVALID_PARAMS (-4)
+#define OSI_MEMORY_ALLOCATION_FAILURE (-5)
+#define OSI_TIMEOUT (-6)
+#define OSI_EVENTS_IN_USE (-7)
+#define OSI_EVENT_OPEARTION_FAILURE (-8)
+
+/*typedef enum
+{
+ OSI_OK = 0,
+ OSI_FAILURE = -1,
+ OSI_OPERATION_FAILED = -2,
+ OSI_ABORTED = -3,
+ OSI_INVALID_PARAMS = -4,
+ OSI_MEMORY_ALLOCATION_FAILURE = -5,
+ OSI_TIMEOUT = -6,
+ OSI_EVENTS_IN_USE = -7,
+ OSI_EVENT_OPEARTION_FAILURE = -8
+}OsiReturnVal_e;*/
+
+
+//#define ENTER_CRITICAL_SECTION osi_EnterCritical()
+//#define EXIT_CRITICAL_SECTION osi_ExitCritical()
+
+typedef void* OsiMsgQ_t;
+
+ /*!
+ \brief type definition for a time value
+
+ \note On each porting or platform the type could be whatever is needed - integer, pointer to structure etc.
+*/
+typedef uint32_t OsiTime_t;
+//typedef unsigned long OsiTime_t;
+/*!
+ \brief type definition for a sync object container
+
+ Sync object is object used to synchronize between two threads or thread and interrupt handler.
+ One thread is waiting on the object and the other thread send a signal, which then
+ release the waiting thread.
+ The signal must be able to be sent from interrupt context.
+ This object is generally implemented by binary semaphore or events.
+
+ \note On each porting or platform the type could be whatever is needed - integer, structure etc.
+*/
+//typedef unsigned int OsiSyncObj_t;
+typedef void * OsiSyncObj_t;
+
+/*!
+ \brief type definition for a locking object container
+
+ Locking object are used to protect a resource from mutual accesses of two or more threads.
+ The locking object should support re-entrant locks by a signal thread.
+ This object is generally implemented by mutex semaphore
+
+ \note On each porting or platform the type could be whatever is needed - integer, structure etc.
+*/
+//typedef unsigned int OsiLockObj_t;
+typedef void * OsiLockObj_t;
+
+/*!
+ \brief type definition for a spawn entry callback
+
+ the spawn mechanism enable to run a function on different context.
+ This mechanism allow to transfer the execution context from interrupt context to thread context
+ or changing the context from an unknown user thread to general context.
+ The implementation of the spawn mechanism depends on the user's system requirements and could varies
+ from implementation of serialized execution using single thread to creating thread per call
+
+ \note The stack size of the execution thread must be at least of TBD bytes!
+*/
+typedef void (*P_OSI_SPAWN_ENTRY)(void* pValue);
+
+typedef void (*P_OSI_EVENT_HANDLER)(void* pValue);
+
+typedef void (*P_OSI_TASK_ENTRY)(void* pValue);
+
+typedef void (*P_OSI_INTR_ENTRY)(void);
+
+typedef void* OsiTaskHandle;
+
+/*!
+ \brief This function registers an interrupt in NVIC table
+
+ The sync object is used for synchronization between different thread or ISR and
+ a thread.
+
+ \param iIntrNum - Interrupt number to register
+ \param pEntry - Pointer to the interrupt handler
+
+ \return upon successful creation the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_InterruptRegister(int iIntrNum,P_OSI_INTR_ENTRY pEntry,unsigned char ucPriority);
+
+/*!
+ \brief This function De-registers an interrupt in NVIC table
+
+ \param iIntrNum - Interrupt number to register
+ \param pEntry - Pointer to the interrupt handler
+
+ \return upon successful creation the function should return Positive number
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+void osi_InterruptDeRegister(int iIntrNum);
+
+
+/*!
+ \brief This function creates a sync object
+
+ The sync object is used for synchronization between different thread or ISR and
+ a thread.
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful creation the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjCreate(OsiSyncObj_t* pSyncObj);
+
+
+/*!
+ \brief This function deletes a sync object
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful deletion the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjDelete(OsiSyncObj_t* pSyncObj);
+
+/*!
+ \brief This function generates a sync signal for the object.
+
+ All suspended threads waiting on this sync object are resumed
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful signalling the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note the function could be called from ISR context
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjSignal(OsiSyncObj_t* pSyncObj);
+
+/*!
+ \brief This function generates a sync signal for the object.
+ from ISR context.
+
+ All suspended threads waiting on this sync object are resumed
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful signalling the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note the function is called from ISR context
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj);
+
+/*!
+ \brief This function waits for a sync signal of the specific sync object
+
+ \param pSyncObj - pointer to the sync object control block
+ \param Timeout - numeric value specifies the maximum number of mSec to
+ stay suspended while waiting for the sync signal
+ Currently, the simple link driver uses only two values:
+ - OSI_WAIT_FOREVER
+ - OSI_NO_WAIT
+
+ \return upon successful reception of the signal within the timeout window return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjWait(OsiSyncObj_t* pSyncObj , OsiTime_t Timeout);
+
+/*!
+ \brief This function clears a sync object
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful clearing the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjClear(OsiSyncObj_t* pSyncObj);
+
+/*!
+ \brief This function creates a locking object.
+
+ The locking object is used for protecting a shared resources between different
+ threads.
+
+ \param pLockObj - pointer to the locking object control block
+
+ \return upon successful creation the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj);
+
+/*!
+ \brief This function deletes a locking object.
+
+ \param pLockObj - pointer to the locking object control block
+
+ \return upon successful deletion the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj);
+
+/*!
+ \brief This function locks a locking object.
+
+ All other threads that call this function before this thread calls
+ the osi_LockObjUnlock would be suspended
+
+ \param pLockObj - pointer to the locking object control block
+ \param Timeout - numeric value specifies the maximum number of mSec to
+ stay suspended while waiting for the locking object
+ Currently, the simple link driver uses only two values:
+ - OSI_WAIT_FOREVER
+ - OSI_NO_WAIT
+
+
+ \return upon successful reception of the locking object the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout);
+
+/*!
+ \brief This function unlock a locking object.
+
+ \param pLockObj - pointer to the locking object control block
+
+ \return upon successful unlocking the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjUnlock(OsiLockObj_t* pLockObj);
+
+
+/*!
+ \brief This function call the pEntry callback from a different context
+
+ \param pEntry - pointer to the entry callback function
+
+ \param pValue - pointer to any type of memory structure that would be
+ passed to pEntry callback from the execution thread.
+
+ \param flags - execution flags - reserved for future usage
+
+ \return upon successful registration of the spawn the function should return 0
+ (the function is not blocked till the end of the execution of the function
+ and could be returned before the execution is actually completed)
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+/*!
+ \brief This function creates a Task.
+
+ Creates a new Task and add it to the last of tasks that are ready to run
+
+ \param pEntry - pointer to the Task Function
+ \param pcName - Task Name String
+ \param usStackDepth - Stack Size Stack Size in 32-bit long words
+ \param pvParameters - pointer to structure to be passed to the Task Function
+ \param uxPriority - Task Priority
+
+ \return upon successful unlocking the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_TaskCreate(P_OSI_TASK_ENTRY pEntry,const signed char * const pcName,unsigned short usStackDepth,void *pvParameters,uint32_t uxPriority,OsiTaskHandle *pTaskHandle);
+
+/*!
+ \brief This function Deletes a Task.
+
+ Deletes a Task and remove it from list of running task
+
+ \param pTaskHandle - Task Handle
+
+ \note
+ \warning
+*/
+void osi_TaskDelete(OsiTaskHandle* pTaskHandle);
+
+/*!
+ \brief This function call the pEntry callback from a different context
+
+ \param pEntry - pointer to the entry callback function
+
+ \param pValue - pointer to any type of memory structure that would be
+ passed to pEntry callback from the execution thread.
+
+ \param flags - execution flags - reserved for future usage
+
+ \return upon successful registration of the spawn the function should return 0
+ (the function is not blocked till the end of the execution of the function
+ and could be returned before the execution is actually completed)
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , uint32_t flags);
+
+
+/*******************************************************************************
+
+This function creates a message queue that is typically used for inter thread
+communication.
+
+Parameters:
+
+ pMsgQ - pointer to the message queue control block
+ pMsgQName - pointer to the name of the message queue
+ MsgSize - the size of the message.
+
+ NOTICE: THE MESSGAE SIZE MUST BE SMALLER THAN 16
+
+ MaxMsgs - maximum number of messages.
+
+Please note that this function allocates the entire memory required
+for the maximum number of messages (MsgSize * MaxMsgs).
+
+********************************************************************************/
+OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ ,
+ char* pMsgQName,
+ uint32_t MsgSize,
+ uint32_t MaxMsgs);
+
+/*******************************************************************************
+
+This function deletes a specific message queue.
+All threads suspended waiting for a message from this queue are resumed with
+an error return value.
+
+Parameters:
+
+ pMsgQ - pointer to the message queue control block
+
+********************************************************************************/
+OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ);
+
+
+/*******************************************************************************
+
+This function writes a message to a specific message queue.
+
+Notice that the message is copied to the queue from the memory area specified
+by pMsg pointer.
+
+--------------------------------------------------------------------------------
+THIS FUNCTION COULD BE CALLED FROM ISR AS LONG AS THE TIMEOUT PARAMETER IS
+SET TO "OSI_NO_WAIT"
+--------------------------------------------------------------------------------
+
+Parameters:
+
+ pMsgQ - pointer to the message queue control block
+ pMsg - pointer to the message
+ Timeout - numeric value specifies the maximum number of mSec to stay
+ suspended while waiting for available space for the message
+
+********************************************************************************/
+OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout);
+
+
+/*******************************************************************************
+
+This function retrieves a message from the specified message queue. The
+retrieved message is copied from the queue into the memory area specified by
+the pMsg pointer
+
+Parameters:
+
+ pMsgQ - pointer to the message queue control block
+ pMsg - pointer that specify the location where to copy the message
+ Timeout - numeric value specifies the maximum number of mSec to stay
+ suspended while waiting for a message to be available
+
+********************************************************************************/
+OsiReturnVal_e osi_MsgQRead(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout);
+
+/*!
+ \brief This function starts the OS Scheduler
+ \param - void
+ \return - void
+ \note
+ \warning
+*/
+void osi_start();
+
+/*!
+ \brief Allocates Memory on Heap
+ \param Size - Size of the Buffer to be allocated
+ \sa
+ \note
+ \warning
+*/
+void * mem_Malloc(uint32_t Size);
+
+
+/*!
+ \brief Deallocates Memory
+ \param pMem - Pointer to the Buffer to be freed
+ \return void
+ \sa
+ \note
+ \warning
+*/
+void mem_Free(void *pMem);
+
+
+/*!
+ \brief Set Memory
+ \param pBuf - Pointer to the Buffer
+ \param Val - Value to be set
+ \param Size - Size of the memory to be set
+ \sa
+ \note
+ \warning
+*/
+void mem_set(void *pBuf,int Val,size_t Size);
+
+/*!
+ \brief Copy Memory
+ \param pDst - Pointer to the Destination Buffer
+ \param pSrc - Pointer to the Source Buffer
+ \param Size - Size of the memory to be copied
+ \return void
+ \note
+ \warning
+*/
+void mem_copy(void *pDst, void *pSrc,size_t Size);
+
+/*!
+ \brief Enter Critical Section
+ \sa
+ \note
+ \warning
+*/
+uint32_t osi_EnterCritical(void);
+
+/*!
+ \brief Exit Critical Section
+ \sa
+ \note
+ \warning
+*/
+void osi_ExitCritical(uint32_t ulKey);
+
+/*!
+ \brief This function used to save the os context before sleep
+ \param void
+ \return void
+ \note
+ \warning
+*/
+void osi_ContextSave();
+/*!
+ \brief This function used to retrieve the context after sleep
+ \param void
+ \return void
+ \note
+ \warning
+*/
+void osi_ContextRestore();
+
+/*!
+ \brief This function used to suspend the task for the specified number of milli secs
+ \param MilliSecs - Time in millisecs to suspend the task
+ \return void
+ \note
+ \warning
+*/
+void osi_Sleep(unsigned int MilliSecs);
+
+/*!
+ \brief This function used to disable the tasks
+ \param - void
+ \return - Key with the suspended tasks
+ \note
+ \warning
+*/
+uint32_t osi_TaskDisable(void);
+
+/*!
+ \brief This function used to enable all tasks
+ \param unsigned long
+ \return - void
+ \note
+ \warning
+*/
+void osi_TaskEnable(uint32_t);
+/*!
+ \brief structure definition for simple link spawn message
+
+ \note On each porting or platform the type could be whatever is needed - integer, pointer to structure etc.
+*/
+
+typedef struct
+{
+ P_OSI_SPAWN_ENTRY pEntry;
+ void* pValue;
+}tSimpleLinkSpawnMsg;
+
+/* The queue used to send message to simple link spawn task. */
+extern void* xSimpleLinkSpawnQueue;
+
+/* API for SL Task*/
+OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority);
+void VDeleteSimpleLinkSpawnTask( void );
+
+
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/oslib/osi_freertos.c Sat Jun 06 13:32:15 2015 +0000
@@ -0,0 +1,802 @@
+//*****************************************************************************
+// osi_freertos.c
+//
+// Interface APIs for free-rtos function calls
+//
+// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// 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.
+//
+// Neither the name of Texas Instruments Incorporated 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 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 COPYRIGHT
+// OWNER 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.
+//
+//*****************************************************************************
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+#include "portmacro.h"
+#include <osi.h>
+
+
+
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
+//Local function definition
+static void vSimpleLinkSpawnTask( void *pvParameters );
+//Queue Handler
+xQueueHandle xSimpleLinkSpawnQueue = NULL;
+xTaskHandle xSimpleLinkSpawnTaskHndl = NULL;
+// Queue size
+#define slQUEUE_SIZE ( 3 )
+
+
+
+
+
+/*!
+ \brief This function creates a sync object
+
+ The sync object is used for synchronization between different thread or ISR and
+ a thread.
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful creation the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjCreate(OsiSyncObj_t* pSyncObj)
+{
+ //Check for NULL
+ if(NULL == pSyncObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ xSemaphoreHandle *pl_SyncObj = (xSemaphoreHandle *)pSyncObj;
+
+ *pl_SyncObj = xSemaphoreCreateBinary();
+
+ if((xSemaphoreHandle)(*pSyncObj) != NULL)
+ {
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+
+/*!
+ \brief This function deletes a sync object
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful deletion the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjDelete(OsiSyncObj_t* pSyncObj)
+{
+ //Check for NULL
+ if(NULL == pSyncObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ vSemaphoreDelete(*pSyncObj );
+ return OSI_OK;
+}
+
+/*!
+ \brief This function generates a sync signal for the object.
+
+ All suspended threads waiting on this sync object are resumed
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful signaling the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note the function could be called from ISR context
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjSignal(OsiSyncObj_t* pSyncObj)
+{
+ //Check for NULL
+ if(NULL == pSyncObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+
+ if(pdTRUE != xSemaphoreGive( *pSyncObj ))
+ {
+ //In case of Semaphore, you are expected to get this if multiple sem
+ // give is called before sem take
+ return OSI_OK;
+ }
+
+ return OSI_OK;
+}
+/*!
+ \brief This function generates a sync signal for the object
+ from ISR context.
+
+ All suspended threads waiting on this sync object are resumed
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful signalling the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note the function is called from ISR context
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj)
+{
+ //Check for NULL
+ if(NULL == pSyncObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ xHigherPriorityTaskWoken = pdFALSE;
+ if(pdTRUE == xSemaphoreGiveFromISR( *pSyncObj, &xHigherPriorityTaskWoken ))
+ {
+ if( xHigherPriorityTaskWoken )
+ {
+ taskYIELD ();
+ }
+ return OSI_OK;
+ }
+ else
+ {
+ //In case of Semaphore, you are expected to get this if multiple sem
+ // give is called before sem take
+ return OSI_OK;
+ }
+}
+
+/*!
+ \brief This function waits for a sync signal of the specific sync object
+
+ \param pSyncObj - pointer to the sync object control block
+ \param Timeout - numeric value specifies the maximum number of mSec to
+ stay suspended while waiting for the sync signal
+ Currently, the simple link driver uses only two values:
+ - OSI_WAIT_FOREVER
+ - OSI_NO_WAIT
+
+ \return upon successful reception of the signal within the timeout window return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjWait(OsiSyncObj_t* pSyncObj , OsiTime_t Timeout)
+{
+ //Check for NULL
+ if(NULL == pSyncObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ if(pdTRUE == xSemaphoreTake( (xSemaphoreHandle)*pSyncObj, ( portTickType )(Timeout/portTICK_RATE_MS) ))
+ {
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+
+/*!
+ \brief This function clears a sync object
+
+ \param pSyncObj - pointer to the sync object control block
+
+ \return upon successful clearing the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_SyncObjClear(OsiSyncObj_t* pSyncObj)
+{
+ //Check for NULL
+ if(NULL == pSyncObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+
+ if (OSI_OK == osi_SyncObjWait(pSyncObj,0) )
+ {
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+
+/*!
+ \brief This function creates a locking object.
+
+ The locking object is used for protecting a shared resources between different
+ threads.
+
+ \param pLockObj - pointer to the locking object control block
+
+ \return upon successful creation the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj)
+{
+ //Check for NULL
+ if(NULL == pLockObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ *pLockObj = (OsiLockObj_t)xSemaphoreCreateMutex();
+ if(pLockObj != NULL)
+ {
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+
+/*!
+ \brief This function creates a Task.
+
+ Creates a new Task and add it to the last of tasks that are ready to run
+
+ \param pEntry - pointer to the Task Function
+ \param pcName - Task Name String
+ \param usStackDepth - Stack Size in bytes
+ \param pvParameters - pointer to structure to be passed to the Task Function
+ \param uxPriority - Task Priority
+
+ \return upon successful creation the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_TaskCreate(P_OSI_TASK_ENTRY pEntry,const signed char * const pcName,
+ unsigned short usStackDepth, void *pvParameters,
+ uint32_t uxPriority,OsiTaskHandle* pTaskHandle)
+{
+ if(pdPASS == xTaskCreate( pEntry, (const char*) pcName,
+ (usStackDepth/(sizeof( portSTACK_TYPE ))),
+ pvParameters,(unsigned portBASE_TYPE)uxPriority,
+ (xTaskHandle*)pTaskHandle ))
+ {
+ return OSI_OK;
+ }
+
+ return OSI_OPERATION_FAILED;
+}
+
+
+/*!
+ \brief This function Deletes a Task.
+
+ Deletes a Task and remove it from list of running task
+
+ \param pTaskHandle - Task Handle
+
+ \note
+ \warning
+*/
+void osi_TaskDelete(OsiTaskHandle* pTaskHandle)
+{
+ vTaskDelete((xTaskHandle)*pTaskHandle);
+}
+
+
+
+/*!
+ \brief This function deletes a locking object.
+
+ \param pLockObj - pointer to the locking object control block
+
+ \return upon successful deletion the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj)
+{
+ vSemaphoreDelete((xSemaphoreHandle)*pLockObj );
+ return OSI_OK;
+}
+
+/*!
+ \brief This function locks a locking object.
+
+ All other threads that call this function before this thread calls
+ the osi_LockObjUnlock would be suspended
+
+ \param pLockObj - pointer to the locking object control block
+ \param Timeout - numeric value specifies the maximum number of mSec to
+ stay suspended while waiting for the locking object
+ Currently, the simple link driver uses only two values:
+ - OSI_WAIT_FOREVER
+ - OSI_NO_WAIT
+
+
+ \return upon successful reception of the locking object the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout)
+{
+ //Check for NULL
+ if(NULL == pLockObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ //Take Semaphore
+ if(pdTRUE == xSemaphoreTake( *pLockObj, ( portTickType ) (Timeout/portTICK_RATE_MS) ))
+ {
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+
+/*!
+ \brief This function unlock a locking object.
+
+ \param pLockObj - pointer to the locking object control block
+
+ \return upon successful unlocking the function should return 0
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_LockObjUnlock(OsiLockObj_t* pLockObj)
+{
+ //Check for NULL
+ if(NULL == pLockObj)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ //Release Semaphore
+ if(pdTRUE == xSemaphoreGive( *pLockObj ))
+ {
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+
+
+/*!
+ \brief This function call the pEntry callback from a different context
+
+ \param pEntry - pointer to the entry callback function
+
+ \param pValue - pointer to any type of memory structure that would be
+ passed to pEntry callback from the execution thread.
+
+ \param flags - execution flags - reserved for future usage
+
+ \return upon successful registration of the spawn the function should return 0
+ (the function is not blocked till the end of the execution of the function
+ and could be returned before the execution is actually completed)
+ Otherwise, a negative value indicating the error code shall be returned
+ \note
+ \warning
+*/
+
+OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , uint32_t flags)
+{
+
+ tSimpleLinkSpawnMsg Msg;
+ Msg.pEntry = pEntry;
+ Msg.pValue = pValue;
+ xHigherPriorityTaskWoken = pdFALSE;
+
+ if(pdTRUE == xQueueSendFromISR( xSimpleLinkSpawnQueue, &Msg, &xHigherPriorityTaskWoken ))
+ {
+ if( xHigherPriorityTaskWoken )
+ {
+ taskYIELD ();
+ }
+
+ return OSI_OK;
+ }
+ return OSI_OPERATION_FAILED;
+}
+
+
+/*!
+ \brief This is the simplelink spawn task to call SL callback from a different context
+
+ \param pvParameters - pointer to the task parameter
+
+ \return void
+ \note
+ \warning
+*/
+void vSimpleLinkSpawnTask(void *pvParameters)
+{
+ tSimpleLinkSpawnMsg Msg;
+ portBASE_TYPE ret=pdFAIL;
+
+ for(;;)
+ {
+ ret = xQueueReceive( xSimpleLinkSpawnQueue, &Msg, portMAX_DELAY );
+ if(ret == pdPASS)
+ {
+ Msg.pEntry(Msg.pValue);
+ }
+ }
+}
+
+/*!
+ \brief This is the API to create SL spawn task and create the SL queue
+
+ \param uxPriority - task priority
+
+ \return void
+ \note
+ \warning
+*/
+OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority)
+{
+ xSimpleLinkSpawnQueue = xQueueCreate( slQUEUE_SIZE, sizeof( tSimpleLinkSpawnMsg ) );
+ if(0 == xSimpleLinkSpawnQueue)
+ {
+ return OSI_OPERATION_FAILED;
+ }
+ if(pdPASS == xTaskCreate( vSimpleLinkSpawnTask, /*( portCHAR * )*/ "SLSPAWN",\
+ (512/sizeof( portSTACK_TYPE )), NULL, uxPriority, &xSimpleLinkSpawnTaskHndl ))
+ {
+ return OSI_OK;
+ }
+
+ return OSI_OPERATION_FAILED;
+}
+
+/*!
+ \brief This is the API to delete SL spawn task and delete the SL queue
+
+ \param none
+
+ \return void
+ \note
+ \warning
+*/
+void VDeleteSimpleLinkSpawnTask( void )
+{
+ if(0 != xSimpleLinkSpawnTaskHndl)
+ {
+ vTaskDelete( xSimpleLinkSpawnTaskHndl );
+ xSimpleLinkSpawnTaskHndl = 0;
+ }
+
+ if(0 !=xSimpleLinkSpawnQueue)
+ {
+ vQueueDelete( xSimpleLinkSpawnQueue );
+ xSimpleLinkSpawnQueue = 0;
+ }
+}
+
+/*!
+ \brief This function is used to create the MsgQ
+
+ \param pMsgQ - pointer to the message queue
+ \param pMsgQName - msg queue name
+ \param MsgSize - size of message on the queue
+ \param MaxMsgs - max. number of msgs that the queue can hold
+
+ \return - OsiReturnVal_e
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ ,
+ char* pMsgQName,
+ uint32_t MsgSize,
+ uint32_t MaxMsgs)
+{
+ //Check for NULL
+ if(NULL == pMsgQ)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+
+ xQueueHandle handle =0;
+
+ //Create Queue
+ handle = xQueueCreate( MaxMsgs, MsgSize );
+ if (handle==0)
+ {
+ return OSI_OPERATION_FAILED;
+ }
+
+ *pMsgQ = (OsiMsgQ_t)handle;
+ return OSI_OK;
+}
+/*!
+ \brief This function is used to delete the MsgQ
+
+ \param pMsgQ - pointer to the message queue
+
+ \return - OsiReturnVal_e
+ \note
+ \warning
+*/
+OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ)
+{
+ //Check for NULL
+ if(NULL == pMsgQ)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+ vQueueDelete((xQueueHandle) *pMsgQ );
+ return OSI_OK;
+}
+/*!
+ \brief This function is used to write data to the MsgQ
+
+ \param pMsgQ - pointer to the message queue
+ \param pMsg - pointer to the Msg strut to read into
+ \param Timeout - timeout to wait for the Msg to be available
+
+ \return - OsiReturnVal_e
+ \note
+ \warning
+*/
+
+OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
+{
+ //Check for NULL
+ if(NULL == pMsgQ)
+ {
+ return OSI_INVALID_PARAMS;
+ }
+
+ if(pdPASS == xQueueSendFromISR((xQueueHandle) *pMsgQ, pMsg, &xHigherPriorityTaskWoken ))
+ {
+ taskYIELD ();
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+/*!
+ \brief This function is used to read data from the MsgQ
+
+ \param pMsgQ - pointer to the message queue
+ \param pMsg - pointer to the Msg strut to read into
+ \param Timeout - timeout to wait for the Msg to be available
+
+ \return - OsiReturnVal_e
+ \note
+ \warning
+*/
+
+OsiReturnVal_e osi_MsgQRead(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
+{
+ //Check for NULL
+ if(NULL == pMsgQ)
+ {
+ printf("OSI_INVALID_PARAMS\r\n");
+ return OSI_INVALID_PARAMS;
+ }
+
+ if ( Timeout == (OsiTime_t) OSI_WAIT_FOREVER )
+ {
+ Timeout = portMAX_DELAY ;
+ }
+
+ //Receive Item from Queue
+ if( pdTRUE == xQueueReceive((xQueueHandle)*pMsgQ,pMsg,Timeout) )
+ {
+ return OSI_OK;
+ }
+ else
+ {
+ return OSI_OPERATION_FAILED;
+ }
+}
+
+/*!
+ \brief This function to call the memory de-allocation function of the FREERTOS
+
+ \param Size - size of memory to alloc in bytes
+
+ \return - void *
+ \note
+ \warning
+*/
+
+void * mem_Malloc(uint32_t Size)
+{
+
+ return ( void * ) pvPortMalloc( (size_t)Size );
+}
+
+/*!
+ \brief This function to call the memory de-allocation function of the FREERTOS
+
+ \param pMem - pointer to the memory which needs to be freed
+
+ \return - void
+ \note
+ \warning
+*/
+void mem_Free(void *pMem)
+{
+ vPortFree( pMem );
+}
+
+/*!
+ \brief This function call the memset function
+ \param pBuf - pointer to the memory to be fill
+ \param Val - Value to be fill
+ \param Size - Size of the memory which needs to be fill
+ \return - void
+ \note
+ \warning
+*/
+
+void mem_set(void *pBuf,int Val,size_t Size)
+{
+ memset( pBuf,Val,Size);
+
+}
+
+/*!
+ \brief This function call the memcopy function
+ \param pDst - pointer to the destination
+ \param pSrc - pointer to the source
+ \param Size - Size of the memory which needs to be copy
+
+ \return - void
+ \note
+ \warning
+*/
+void mem_copy(void *pDst, void *pSrc,size_t Size)
+{
+ memcpy(pDst,pSrc,Size);
+}
+
+
+/*!
+ \brief This function use to entering into critical section
+ \param void
+ \return - void
+ \note
+ \warning
+*/
+
+uint32_t osi_EnterCritical(void)
+{
+ portENTER_CRITICAL();
+ return 0;
+}
+
+/*!
+ \brief This function use to exit critical section
+ \param void
+ \return - void
+ \note
+ \warning
+*/
+
+void osi_ExitCritical(uint32_t ulKey)
+{
+ portENTER_CRITICAL();
+}
+/*!
+ \brief This function used to start the scheduler
+ \param void
+ \return - void
+ \note
+ \warning
+*/
+void osi_start()
+{
+ vTaskStartScheduler();
+}
+/*!
+ \brief This function used to suspend the task for the specified number of milli secs
+ \param MilliSecs - Time in millisecs to suspend the task
+ \return - void
+ \note
+ \warning
+*/
+void osi_Sleep(unsigned int MilliSecs)
+{
+ portTickType xDelay = MilliSecs / portTICK_RATE_MS;
+ vTaskDelay(xDelay);
+}
+
+
+/*!
+ \brief This function used to disable the tasks
+ \param - void
+ \return - Key with the suspended tasks
+ \note
+ \warning
+*/
+uint32_t osi_TaskDisable(void)
+{
+ vTaskSuspendAll();
+
+ return OSI_OK;
+}
+
+
+/*!
+ \brief This function used to resume all the tasks
+ \param key - returned from suspend tasks
+ \return - void
+ \note
+ \warning
+*/
+void osi_TaskEnable(uint32_t key)
+{
+ xTaskResumeAll();
+}
+
+/*!
+ \brief This function used to save the OS context before sleep
+ \param void
+ \return - void
+ \note
+ \warning
+*/
+void osi_ContextSave()
+{
+
+}
+/*!
+ \brief This function used to restore the OS context after sleep
+ \param void
+ \return - void
+ \note
+ \warning
+*/
+void osi_ContextRestore()
+{
+
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simplelink_V2.lib Sat Jun 06 13:32:15 2015 +0000 @@ -0,0 +1,1 @@ +simplelink_V2#1a07906111ec
