Skip to content

Commit

Permalink
Sync internal repo
Browse files Browse the repository at this point in the history
  • Loading branch information
amrabdelmoghny committed Feb 10, 2022
1 parent 52195e8 commit 6e0d100
Show file tree
Hide file tree
Showing 18 changed files with 508 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -ffunction-sections -O1 -DAPP_USB_MSD -DAWS_CLOUD_DEMO -DCBOR_NO_FLOATING_POINT -DHAVE_CONFIG_H -DWOLFSSL_IGNORE_FILE_WARN -I"../src" -I"../src/config/aws_sdk_wfi32_iot_freertos" -I"../src/config/aws_sdk_wfi32_iot_freertos/driver/wifi/pic32mzw1/include/" -I"../src/config/aws_sdk_wfi32_iot_freertos/library" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/cryptoauthlib" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/cryptoauthlib/crypto" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/cryptoauthlib/pkcs11" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/tcpip/src" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/tcpip/src/common" -I"../src/config/aws_sdk_wfi32_iot_freertos/system/fs/fat_fs/file_system" -I"../src/config/aws_sdk_wfi32_iot_freertos/system/fs/fat_fs/hardware_access" -I"../src/third_party/aws/libraries" -I"../src/third_party/aws/libraries/aws/common/include" -I"../src/third_party/aws/libraries/aws/defender/include" -I"../src/third_party/aws/libraries/aws/jobs/include" -I"../src/third_party/aws/libraries/aws/shadow/include" -I"../src/third_party/aws/libraries/cbor" -I"../src/third_party/aws/libraries/platform" -I"../src/third_party/aws/libraries/platform/types" -I"../src/third_party/aws/libraries/standard/common/include" -I"../src/third_party/aws/libraries/standard/mqtt/include" -I"../src/third_party/aws/libraries/standard/serializer/include" -I"../src/third_party/aws/ports" -I"../src/third_party/aws/ports/common/include" -I"../src/third_party/aws/ports/pic32mzw1/include" -I"../src/third_party/rtos/FreeRTOS/Source/include" -I"../src/third_party/rtos/FreeRTOS/Source/portable/MPLAB/PIC32MZ" -I"../src/third_party/wolfssl" -I"../src/third_party/wolfssl/wolfssl" -DXPRJ_aws_sdk_wfi32_iot_freertos=$(CND_CONF) -no-legacy-libc $(COMPARISON_BUILD) -mdfp="${DFP_DIR}" C:\microchip\harmony_3\w\apps\rio2_h3_cloudO\cloud_sdk_demo\firmware\src\app_ps.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$(MP_EXTRA_CC_PRE) -g -D__DEBUG -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -ffunction-sections -O1 -DAPP_USB_MSD -DAWS_CLOUD_DEMO -DCBOR_NO_FLOATING_POINT -DHAVE_CONFIG_H -DWOLFSSL_IGNORE_FILE_WARN -I"../src" -I"../src/config/aws_sdk_wfi32_iot_freertos" -I"../src/config/aws_sdk_wfi32_iot_freertos/driver/wifi/pic32mzw1/include/" -I"../src/config/aws_sdk_wfi32_iot_freertos/library" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/cryptoauthlib" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/cryptoauthlib/crypto" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/cryptoauthlib/pkcs11" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/tcpip/src" -I"../src/config/aws_sdk_wfi32_iot_freertos/library/tcpip/src/common" -I"../src/config/aws_sdk_wfi32_iot_freertos/system/fs/fat_fs/file_system" -I"../src/config/aws_sdk_wfi32_iot_freertos/system/fs/fat_fs/hardware_access" -I"../src/third_party/aws/libraries" -I"../src/third_party/aws/libraries/aws/common/include" -I"../src/third_party/aws/libraries/aws/defender/include" -I"../src/third_party/aws/libraries/aws/jobs/include" -I"../src/third_party/aws/libraries/aws/shadow/include" -I"../src/third_party/aws/libraries/cbor" -I"../src/third_party/aws/libraries/platform" -I"../src/third_party/aws/libraries/platform/types" -I"../src/third_party/aws/libraries/standard/common/include" -I"../src/third_party/aws/libraries/standard/mqtt/include" -I"../src/third_party/aws/libraries/standard/serializer/include" -I"../src/third_party/aws/ports" -I"../src/third_party/aws/ports/common/include" -I"../src/third_party/aws/ports/pic32mzw1/include" -I"../src/third_party/rtos/FreeRTOS/Source/include" -I"../src/third_party/rtos/FreeRTOS/Source/portable/MPLAB/PIC32MZ" -I"../src/third_party/wolfssl" -I"../src/third_party/wolfssl/wolfssl" -DXPRJ_aws_sdk_wfi32_iot_freertos=$(CND_CONF) -no-legacy-libc $(COMPARISON_BUILD) -mdfp="${DFP_DIR}" C:\microchip\harmony_3\w\apps\rio2_h3_cloudO\cloud_sdk_demo\firmware\src\app_ps.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"metaDataVersion": "1.0.0",
"category": "com.microchip.ide.project",
"content": {
"metaDataVersion": "1.1.0",
"name": "com.microchip.mcu32.mplabx.WFI32-IoT",
"version": "3.6.0",
"displayName": "WFI32-IoT AWS C SDK Out-of-box Dem0",
"projectName": "WFI32-IoT",
"shortDescription": "This example application uses AWS C SDK v4.0 to report temperature and light values to AWS cloud",
"ide": {
"name": "MPLABX",
"semverRange": ">=5.50.0"
},
"compiler": [
{
"name": "XC32",
"semverRange": ">=2.50.0"
}
],
"dfp": {
"name": "PIC32MZ-W_DFP",
"semverRange": "^1.4.193"
},
"configurator": {
"name": "MHC",
"semverRange": ">=3.8.1"
},
"device": {
"metaDataVersion": "1.0.0",
"category": "com.microchip.portal.contentRef",
"content": {
"metaDataVersion": "1.0.0",
"category": "com.microchip.device",
"name": "PIC32MZ1025W104132",
"versionRange": "*"
}
},
"author": "Microchip",
"subcategories": [
[
"Development Kit",
"WFI32-IoT Board"
],
[
"Wireless",
"Wi-Fi"
]
],
"peripherals": [
"Wi-Fi"
],
"keywords": [
"MHC",
"Harmony",
"PIC32MZ1025W104132",
"WFI32",
"WFI32E01",
"PIC32MZ W1 Family",
"wireless",
],
"additionalData": {
"longDescription": {
"metaDataVersion": "1.0.0",
"category": "com.microchip.portal.fileRef",
"content": {
"metaDataVersion": "1.0.0",
"fileName": "./../../../../readme.md",
"mimeType": "text/markdown"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@
<itemPath>../src/app_commands.h</itemPath>
<itemPath>../src/OLEDB.h</itemPath>
<itemPath>../src/app_oled.h</itemPath>
<itemPath>../src/app_ps.h</itemPath>
</logicalFolder>
<logicalFolder name="LinkerScript"
displayName="Linker Files"
Expand Down Expand Up @@ -1437,6 +1438,7 @@
<itemPath>../src/app_commands.c</itemPath>
<itemPath>../src/OLEDB.c</itemPath>
<itemPath>../src/app_oled.c</itemPath>
<itemPath>../src/app_ps.c</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
Expand Down Expand Up @@ -1961,6 +1963,7 @@
<property key="programoptions.preserveprogram.ranges" value="100fffff-100fffff"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.program.otpconfig" value="false"/>
<property key="programoptions.programcalmem" value="false"/>
<property key="programoptions.programuserotp" value="false"/>
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
Expand Down Expand Up @@ -2017,8 +2020,6 @@
value="${communication.interface.default}"/>
<property key="communication.interface.jtag" value="2wire"/>
<property key="communication.speed" value="${communication.speed.default}"/>
<property key="debugoptions.debug-startup" value="Use system settings"/>
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
<property key="debugoptions.simultaneous.debug" value="false"/>
<property key="debugoptions.useswbreakpoints" value="false"/>
<property key="freeze.timers" value="false"/>
Expand All @@ -2036,8 +2037,6 @@
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.ranges" value="10000000-100fffff"/>
<property key="memories.rww" value="true"/>
<property key="programmerToGoFilePath"
value="C:/microchip/harmony_3/w/apps/rio2_h3_cloudO/cloud_sdk_demo/firmware/aws_sdk_wfi32_iot_freertos.X/debug/aws_sdk_wfi32_iot_freertos/aws_sdk_wfi32_iot_freertos_ptg"/>
<property key="programoptions.donoteraseauxmem" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.pgmentry.voltage" value="low"/>
Expand Down
64 changes: 59 additions & 5 deletions demo/cloud_sdk_demo/firmware/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void wifiConnectCallback(DRV_HANDLE handle, WDRV_PIC32MZW_ASSOC_HANDLE as
switch (currentState) {
case WDRV_PIC32MZW_CONN_STATE_DISCONNECTED:
APP_PRNT("WiFi Reconnecting\r\n");
appData.assocHandle = NULL;
appData.assocHandle = (uintptr_t)NULL;
WIFI_DISCONNECTED;
APP_OLEDNotify(APP_OLED_PARAM_WIFI, false);
appData.wlanTaskState = APP_WLAN_RECONNECT;
Expand All @@ -52,10 +52,15 @@ static void wifiConnectCallback(DRV_HANDLE handle, WDRV_PIC32MZW_ASSOC_HANDLE as
appData.assocHandle = assocHandle;
APP_OLEDNotify(APP_OLED_PARAM_WIFI, true);
WIFI_CONNECTED;

WDRV_PIC32MZW_PowerSaveBroadcastTrackingSet(appData.wdrvHandle,true);
WDRV_PIC32MZW_PowerSaveModeSet(appData.wdrvHandle,
WDRV_PIC32MZW_POWERSAVE_WSM_MODE,
WDRV_PIC32MZW_POWERSAVE_PIC_ASYNC_MODE);
break;
case WDRV_PIC32MZW_CONN_STATE_FAILED:
APP_PRNT("WiFi connection failed\r\n");
appData.assocHandle = NULL;
appData.assocHandle = (uintptr_t)NULL;
WIFI_DISCONNECTED;
APP_OLEDNotify(APP_OLED_PARAM_WIFI, false);
appData.wlanTaskState = APP_WLAN_RECONNECT;
Expand Down Expand Up @@ -282,7 +287,9 @@ void APP_Initialize ( void )
void APP_InitializeWlan ( void )
{
appData.wlanTaskState = APP_WLAN_LEDS_START_UP_PATTERN;
appData.assocHandle = NULL;
appData.assocHandle = (uintptr_t)NULL;
appData.wOffRequested = false;
appData.wOnRequested = false;
WIFI_DISCONNECTED;
NTP_NOT_DONE;
IP_ADDR_LOST;
Expand All @@ -308,6 +315,30 @@ void APP_TaskWlan(void)
bool status;
TCPIP_NET_HANDLE netH;
int i, nNets;
WDRV_PIC32MZW_SYS_INIT wdrvPIC32MZW1InitData = {
.pCryptRngCtx = NULL,
.pRegDomName = "GEN",
.powerSaveMode = WDRV_PIC32MZW_POWERSAVE_RUN_MODE,
.powerSavePICCorrelation = WDRV_PIC32MZW_POWERSAVE_PIC_ASYNC_MODE
};

if(appData.wOffRequested){
if(appData.wlanTaskState != APP_WLAN_DEINIT)
appData.wlanTaskState = APP_WLAN_RECONNECT;
else{
APP_DBG(SYS_ERROR_ERROR, "Wi-Fi already off\r\n");
appData.wOffRequested = false;
}
}
else if(appData.wOnRequested){
if(appData.wlanTaskState == APP_WLAN_DEINIT){
appData.wlanTaskState = APP_WLAN_INIT;
}
else{
APP_DBG(SYS_ERROR_ERROR, "Wi-Fi already on\r\n");
appData.wOnRequested = false;
}
}

switch (appData.wlanTaskState)
{
Expand All @@ -322,6 +353,13 @@ void APP_TaskWlan(void)
/* Wait for Wi-Fi module init */
case APP_WLAN_INIT:
{

if(appData.wOnRequested){
PMUCLKCTRLbits.WLDOOFF = 0;
sysObj.drvWifiPIC32MZW1 = WDRV_PIC32MZW_Initialize(WDRV_PIC32MZW_SYS_IDX_0, (SYS_MODULE_INIT*)&wdrvPIC32MZW1InitData);
appData.wOnRequested = false;
}

if (SYS_STATUS_READY == WDRV_PIC32MZW_Status(sysObj.drvWifiPIC32MZW1)) {
APP_DBG(SYS_ERROR_INFO, "WiFi driver opened!\r\n");
appData.wlanTaskState = APP_WLAN_WDRV_INIT_READY;
Expand Down Expand Up @@ -434,9 +472,25 @@ void APP_TaskWlan(void)
TCPIP_STACK_HandlerDeregister(appData.TCPIPEventHandle);
TCPIP_DHCP_HandlerDeRegister(appData.TCPIPDHCPHandle);
WDRV_PIC32MZW_Close(appData.wdrvHandle);
appData.wlanTaskState = APP_WLAN_INIT;
appData.assocHandle = (uintptr_t)NULL;
WIFI_DISCONNECTED;
APP_OLEDNotify(APP_OLED_PARAM_WIFI, false);
APP_manageLed(LED_BLUE, LED_OFF, BLINK_MODE_INVALID);
if(appData.wOffRequested){
//WDRV_PIC32MZW_Deinitialize(sysObj.drvWifiPIC32MZW1);
appData.wOffRequested = false;
appData.wlanTaskState = APP_WLAN_DEINIT;
}
else
appData.wlanTaskState = APP_WLAN_INIT;
break;
}
}

/* WLAN De-init */
case APP_WLAN_DEINIT:
{
break;
}

/* Error */
case APP_WLAN_ERROR:
Expand Down
4 changes: 4 additions & 0 deletions demo/cloud_sdk_demo/firmware/src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef enum
APP_WLAN_WAIT_FOR_SNTP_INIT,
APP_WLAN_IDLE,
APP_WLAN_RECONNECT,
APP_WLAN_DEINIT,
APP_WLAN_ERROR,
} APP_TASK_WLAN_STATES;

Expand Down Expand Up @@ -118,6 +119,9 @@ typedef struct
TCPIP_DHCP_HANDLE TCPIPDHCPHandle;

uint8_t ValidCrednetials;

bool wOffRequested;
bool wOnRequested;

} APP_DATA;
APP_DATA appData;
Expand Down
58 changes: 47 additions & 11 deletions demo/cloud_sdk_demo/firmware/src/app_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
#include "app_ctrl.h"
#include "app_usb_msd.h"
#include "app_oled.h"
#include "app_ps.h"
#include "config.h"
#include <wolfssl/ssl.h>
#include "task.h"
Expand All @@ -60,6 +61,7 @@ SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
static void _APP_Commands_GetUnixTime(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv);
static void _APP_Commands_GetRSSI(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv);
static void _APP_Commands_GetRTCC(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv);
static void _APP_Commands_SetRTCCFreq(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv);
static void _APP_Commands_SelfTester(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv);
static void _APP_Commands_SetDebugLevel(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv);
static void _APP_Commands_SetPowerMode(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv);
Expand All @@ -71,6 +73,7 @@ static const SYS_CMD_DESCRIPTOR appCmdTbl[] = {
{"unixtime", _APP_Commands_GetUnixTime, ": Unix Time"},
{"rssi", _APP_Commands_GetRSSI, ": Get current RSSI"},
{"rtcc", _APP_Commands_GetRTCC, ": Get uptime"},
{"rtcc_freq", _APP_Commands_SetRTCCFreq, ": Set RTCC frequency"},
{"power_mode", _APP_Commands_SetPowerMode, ": Set power mode"},
{"self_tester", _APP_Commands_SelfTester, ": Show board self tester status"},
{"debug", _APP_Commands_SetDebugLevel, ": Set debug level"},
Expand All @@ -85,7 +88,7 @@ static void rssiCallback(DRV_HANDLE handle, WDRV_PIC32MZW_ASSOC_HANDLE assocHand

//******************************************************************************

bool APP_Commands_Init() {
bool APP_Commands_Init() {
if (!SYS_CMD_ADDGRP(appCmdTbl, sizeof (appCmdTbl) / sizeof (*appCmdTbl), "app", ": app commands")) {
SYS_ERROR(SYS_ERROR_ERROR, "Failed to create TCPIP Commands\r\n", 0);
return false;
Expand All @@ -103,21 +106,25 @@ void _APP_Commands_SetDebugLevel(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** a
return;
}
}
APP_CMD_PRNT("Usage: debug <debug level 0:4>\r\n");
APP_CMD_PRNT("debug <level>\r\n");
}

void _APP_Commands_SetPowerMode(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv) {
const void* cmdIoParam = pCmdIO->cmdIoParam;
if (argc == 2){
uint8_t psMode = atoi(argv[1]);
if(LOW_POWER_IDLE_MODE <= psMode && psMode <= LOW_POWER_DEEP_SLEEP_MODE) {
APP_CMD_PRNT("Going to XDS/DS mode\r\n");
PMD3bits.W24GMD = 1;
POWER_LowPowerModeEnter(LOW_POWER_DEEP_SLEEP_MODE);
return;
}
if (argc == 3){
uint8_t a = atoi(argv[1]);
uint8_t b = atoi(argv[2]);
APP_SetSleepMode(a,b);
return;
}
APP_CMD_PRNT("Usage: power_mode <power mode 0:3>\r\n");
APP_CMD_PRNT("power_mode <PIC_PM_MODE> <WIFI_PM_MODE>\r\n"
"a b : PIC PM + Wi-Fi PM \r\n"
"0 0 : IDLE + WSM_ON \r\n"
"0 2 : IDLE + WOFF \r\n"
"1 0 : SLEEP + WSM_ON \r\n"
"1 2 : SLEEP + WOFF \r\n"
"3 - : DS/XDS + - \r\n"
"4 3 : - + WON \r\n");
}

void _APP_Commands_Reboot(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv) {
Expand All @@ -139,6 +146,35 @@ void _APP_Commands_GetRSSI(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv) {
}
}

void _APP_Commands_SetRTCCFreq(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv) {
const void* cmdIoParam = pCmdIO->cmdIoParam;
RTCC_ALARM_MASK mask;
if (argc == 2){
uint8_t freq = atoi(argv[1]);
if((RTCC_ALARM_MASK_HALF_SECOND <= freq && freq <= RTCC_ALARM_MASK_YEAR)
|| freq == RTCC_ALARM_MASK_OFF) {
APP_CMD_PRNT("Setting RTCC frequency %x\r\n", freq);
mask = freq;
if (RTCC_AlarmSet(&appCtrlData.rtccData.sysTime, mask) == false) {
APP_CTRL_DBG(SYS_ERROR_ERROR, "Error setting alarm\r\n");
}
return;
}
}
APP_CMD_PRNT("rtcc_freq <freq> \r\n"
"Half sec: 0 \r\n"
"Sec: 1 \r\n"
"10 sec: 2 \r\n"
"Min: 3 \r\n"
"10 min: 4 \r\n"
"Hour: 5 \r\n"
"Day: 6 \r\n"
"Week: 7 \r\n"
"Month: 8 \r\n"
"Year: 9 \r\n"
"OFF: 255 \r\n");
}

void _APP_Commands_GetRTCC(SYS_CMD_DEVICE_NODE* pCmdIO, int argc, char** argv) {
const void* cmdIoParam = pCmdIO->cmdIoParam;
struct tm *sysTime = &appCtrlData.rtccData.sysTime;
Expand Down
4 changes: 2 additions & 2 deletions demo/cloud_sdk_demo/firmware/src/app_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ void APP_sensorsOff(void);
int16_t APP_readTemp(void);
uint32_t APP_readLight(void);
void APP_manageLed(LED_COLOR, LED_MODE, LED_BLINK_MODE);
void APP_InitializeCtrl (void);
void APP_TaskCtrl ( void );
void APP_CTRL_Initialize (void);
void APP_CTRL_Tasks ( void );

#endif /* _APP_CTRL_H */

Expand Down
Loading

0 comments on commit 6e0d100

Please sign in to comment.