diff --git a/firmware/ec/.cproject b/firmware/ec/.cproject index 182396df19..7fa4929253 100644 --- a/firmware/ec/.cproject +++ b/firmware/ec/.cproject @@ -42,6 +42,7 @@ + @@ -113,7 +114,7 @@ - + @@ -230,7 +231,7 @@ - + @@ -260,4 +261,5 @@ + diff --git a/firmware/ec/.settings/org.eclipse.core.resources.prefs b/firmware/ec/.settings/org.eclipse.core.resources.prefs index 37e1dc8e52..bcaa2bd97f 100755 --- a/firmware/ec/.settings/org.eclipse.core.resources.prefs +++ b/firmware/ec/.settings/org.eclipse.core.resources.prefs @@ -3,8 +3,8 @@ encoding//Debug/config/oc-sdr/subdir_rules.mk=UTF-8 encoding//Debug/config/oc-sdr/subdir_vars.mk=UTF-8 encoding//Debug/makefile=UTF-8 encoding//Debug/objects.mk=UTF-8 -encoding//Debug/platform/oc-sdr/cfg/subdir_rules.mk=UTF-8 -encoding//Debug/platform/oc-sdr/cfg/subdir_vars.mk=UTF-8 +encoding//Debug/platform/oc-sdr/schema/cfg/subdir_rules.mk=UTF-8 +encoding//Debug/platform/oc-sdr/schema/cfg/subdir_vars.mk=UTF-8 encoding//Debug/platform/oc-sdr/schema/subdir_rules.mk=UTF-8 encoding//Debug/platform/oc-sdr/schema/subdir_vars.mk=UTF-8 encoding//Debug/platform/oc-sdr/subdir_rules.mk=UTF-8 @@ -30,6 +30,8 @@ encoding//Debug/src/devices/uart/subdir_rules.mk=UTF-8 encoding//Debug/src/devices/uart/subdir_vars.mk=UTF-8 encoding//Debug/src/drivers/subdir_rules.mk=UTF-8 encoding//Debug/src/drivers/subdir_vars.mk=UTF-8 +encoding//Debug/src/filesystem/subdir_rules.mk=UTF-8 +encoding//Debug/src/filesystem/subdir_vars.mk=UTF-8 encoding//Debug/src/helpers/subdir_rules.mk=UTF-8 encoding//Debug/src/helpers/subdir_vars.mk=UTF-8 encoding//Debug/src/interfaces/Ethernet/subdir_rules.mk=UTF-8 @@ -56,6 +58,8 @@ encoding//Debug/src/subsystem/hci/led/subdir_rules.mk=UTF-8 encoding//Debug/src/subsystem/hci/led/subdir_vars.mk=UTF-8 encoding//Debug/src/subsystem/hci/subdir_rules.mk=UTF-8 encoding//Debug/src/subsystem/hci/subdir_vars.mk=UTF-8 +encoding//Debug/src/subsystem/health/subdir_rules.mk=UTF-8 +encoding//Debug/src/subsystem/health/subdir_vars.mk=UTF-8 encoding//Debug/src/subsystem/obc/subdir_rules.mk=UTF-8 encoding//Debug/src/subsystem/obc/subdir_vars.mk=UTF-8 encoding//Debug/src/subsystem/power/subdir_rules.mk=UTF-8 diff --git a/firmware/ec/OpenCellular.cfg b/firmware/ec/OpenCellular.cfg index fdc9dca5e1..ba7308d578 100644 --- a/firmware/ec/OpenCellular.cfg +++ b/firmware/ec/OpenCellular.cfg @@ -12,9 +12,9 @@ var Timer = xdc.useModule('ti.sysbios.hal.Timer'); var Mailbox = xdc.useModule('ti.sysbios.knl.Mailbox'); var Global = xdc.useModule('ti.ndk.config.Global'); var Tcp = xdc.useModule('ti.ndk.config.Tcp'); -var Ip = xdc.useModule('ti.ndk.config.Ip'); var Icmp = xdc.useModule('ti.ndk.config.Icmp'); var DhcpClient = xdc.useModule('ti.ndk.config.DhcpClient'); +var Event = xdc.useModule('ti.sysbios.knl.Event'); /* * Default value is family dependent. For example, Linux systems often only * support a minimum period of 10000 us and multiples of 10000 us. @@ -579,7 +579,17 @@ Program.global.m3Hwi1 = m3Hwi.create(60, "&uDMAIntHandler", m3Hwi1Params); m3Hwi2Params.instance.name = "m3Hwi2"; m3Hwi2Params.enableInt = false; Program.global.m3Hwi2 = m3Hwi.create(61, "&uDMAErrorHandler", m3Hwi2Params);*/ +/* WatchDog */ +var m3Hwi0Params = new m3Hwi.Params(); +m3Hwi0Params.instance.name = "m3Hwi0"; +m3Hwi0Params.enableInt = false; +Program.global.m3Hwi0 = m3Hwi.create(34, "&WatchdogIntHandler", m3Hwi0Params); +/* UART3 */ +var m3Hwi0Params = new m3Hwi.Params(); +m3Hwi0Params.instance.name = "m3Hwi0"; +m3Hwi0Params.enableInt = false; +Program.global.m3Hwi0 = m3Hwi.create(72, "&UART3IntHandler", m3Hwi0Params); /* ================ Application Specific Instances ================ */ /* ================ NDK configuration ================ */ var Ndk = xdc.loadPackage('ti.ndk.config'); @@ -607,7 +617,5 @@ Global.lowTaskPriLevel = 7; Global.normTaskPriLevel = 8; Global.highTaskPriLevel = 9; Global.kernTaskPriLevel = 11; - -Ip.autoIp = false; -Ip.address = "192.168.1.2"; -Ip.mask = "255.255.255.0"; +var Ip = xdc.module('ti.ndk.config.Ip'); +Ip.autoIp = true; diff --git a/firmware/ec/inc/common/global_header.h b/firmware/ec/inc/common/global_header.h index 3a362b632e..987ce906f6 100644 --- a/firmware/ec/inc/common/global_header.h +++ b/firmware/ec/inc/common/global_header.h @@ -20,6 +20,12 @@ /* XDCtools Header files */ #include /* For System_printf */ +/*Maximum monitored task limit.*/ +#define MAX_TASK_LIMIT 32 + +/* Time Period for semaphore wait in task. After this 40 sec watchdog is kicked */ +#define OC_TASK_WAIT_TIME (40000) +#define OC_SYS_TICK (1000) #if 1 # define DEBUG(...) \ { \ diff --git a/firmware/ec/inc/interfaces/uartdma.h b/firmware/ec/inc/interfaces/uartdma.h index 7d9569a9e0..c4979dee86 100644 --- a/firmware/ec/inc/interfaces/uartdma.h +++ b/firmware/ec/inc/interfaces/uartdma.h @@ -18,13 +18,13 @@ * MACROS DEFINITION *****************************************************************************/ #define OCUARTDMA_TASK_PRIORITY 7 -#define OCUARTDMA_TASK_STACK_SIZE 1024 +#define OCUARTDMA_TASK_STACK_SIZE 2048 #define OCUARTDMATX_TASK_PRIORITY 7 -#define OCUARTDMATX_TASK_STACK_SIZE 1024 +#define OCUARTDMATX_TASK_STACK_SIZE 2048 -#define UART_TXBUF_SIZE OCMP_FRAME_TOTAL_LENGTH -#define UART_RXBUF_SIZE OCMP_FRAME_TOTAL_LENGTH +#define UART_TXBUF_SIZE 128 +#define UART_RXBUF_SIZE 128 /***************************************************************************** * HANDLE DECLARATIONS diff --git a/firmware/ec/inc/subsystem/watchdog/watchdog.h b/firmware/ec/inc/subsystem/health/keepAlive.h similarity index 78% rename from firmware/ec/inc/subsystem/watchdog/watchdog.h rename to firmware/ec/inc/subsystem/health/keepAlive.h index 109808eba5..556dae06aa 100644 --- a/firmware/ec/inc/subsystem/watchdog/watchdog.h +++ b/firmware/ec/inc/subsystem/health/keepAlive.h @@ -6,13 +6,13 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ -#ifndef WATCHDOG_H_ -#define WATCHDOG_H_ +#ifndef KEEPALIVE_H_ +#define KEEPALIVE_H_ /***************************************************************************** * MACRO DEFINITIONS *****************************************************************************/ -#define WATCHDOG_TASK_STACK_SIZE 1024 -#define WATCHDOG_TASK_PRIORITY 2 +#define KEEPALIVE_TASK_STACK_SIZE 1024 +#define KEEPALIVE_TASK_PRIORITY 2 -#endif /* WATCHDOG_H_ */ +#endif /* KEEPALIVE_H_ */ diff --git a/firmware/ec/inc/utils/oc_watchdog.h b/firmware/ec/inc/utils/oc_watchdog.h new file mode 100644 index 0000000000..0a974dcb73 --- /dev/null +++ b/firmware/ec/inc/utils/oc_watchdog.h @@ -0,0 +1,28 @@ +/* + * oc_watchdog.h + * + * Created on: Apr 2, 2019 + * Author: vthakur + */ + +#include "Board.h" +#include "inc/common/global_header.h" +#include "inc/utils/util.h" + + + +#include +#include + +#ifndef _OC_WATCHDOG_H_ +#define _OC_WATCHDOG_H_ + +#define WD_TASK_PRIORITY 3 +#define WD_TASK_STACK_SIZE 8096 + +void wd_createtask(void); + +void wd_kick(Task_Handle task); + + +#endif /* _OC_WATCHDOG_H_ */ diff --git a/firmware/ec/inc/utils/util.h b/firmware/ec/inc/utils/util.h index cf825e1aac..4255966347 100644 --- a/firmware/ec/inc/utils/util.h +++ b/firmware/ec/inc/utils/util.h @@ -52,7 +52,9 @@ extern "C" { #include #include #include +#include #include +#include /********************************************************************* * EXTERNAL VARIABLES @@ -71,6 +73,14 @@ typedef struct { uint8_t state; // Event state; } appEvtHdr_t; + +typedef struct { + uint8_t sno; + bool wdMonitoring; + uint32_t wdEventId; + Task_Handle task_handle; + char* task_name; +} ocTask_t; /********************************************************************* * MACROS */ @@ -195,7 +205,54 @@ uint8_t Util_enqueueMsg(Queue_Handle msgQueue, Semaphore_Handle sem, uint8_t *Util_dequeueMsg(Queue_Handle msgQueue); /********************************************************************* -*********************************************************************/ + * @fn Util_create_task + * + * @brief Creates a task. + * + * @param taskParams - parameters for task. + * taskfxn - task function. + * monitoring - Enable watchdog monitoring. + * + * + * @return boolean + */ +bool Util_create_task(Task_Params* taskParams, Task_FuncPtr taskFxn, bool monitoring); + +/********************************************************************* + * @fn Util_get_task_serial + * + * @brief gets the serial id of task. + * + * @param name - task name + * + * + * @return integer -1 on no task found otherwise serial number of task. + */ +int Util_get_task_serial(char* name); + +/********************************************************************* + * @fn Util_get_task_wd_event_id + * + * @brief gets the serial id of task. + * + * @param name - task name + * + * + * @return uint32_t event id. + */ +uint32_t Util_get_task_wd_event_id(char* name); + +/********************************************************************* + * @fn Util_get_wd_req_evets + * + * @brief gets the required events for Watchdog. + * + * @param None + * + * + * @return event mask. + */ +uint32_t Util_get_wd_req_evets(); #ifdef __cplusplus } diff --git a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT1.c b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT1.c similarity index 100% rename from firmware/ec/platform/oc-sdr/cfg/OC_CONNECT1.c rename to firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT1.c diff --git a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_FE.c b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_FE.c similarity index 100% rename from firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_FE.c rename to firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_FE.c diff --git a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_GBC.c b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_GBC.c similarity index 100% rename from firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_GBC.c rename to firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_GBC.c diff --git a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_LED.c b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_LED.c similarity index 100% rename from firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_LED.c rename to firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_LED.c diff --git a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_SDR.c b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_SDR.c similarity index 100% rename from firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_SDR.c rename to firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_SDR.c diff --git a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_SYNC.c b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_SYNC.c similarity index 100% rename from firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_SYNC.c rename to firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_SYNC.c diff --git a/firmware/ec/src/bigbrother.c b/firmware/ec/src/bigbrother.c index df3d82c6cd..4f7975f3db 100644 --- a/firmware/ec/src/bigbrother.c +++ b/firmware/ec/src/bigbrother.c @@ -26,6 +26,7 @@ #include +//Failed to allocate memory for POST results /* Global Task Configuration Variables */ Task_Struct bigBrotherTask; Char bigBrotherTaskStack[BIGBROTHER_TASK_STACK_SIZE]; @@ -134,7 +135,7 @@ static ReturnStatus bigbrother_process_rx_msg(uint8_t *pMsg) LOGGER_DEBUG("BIGBROTHER:INFO:: Processing Big Brother RX Message.\n"); OCMPMessageFrame *pOCMPMessageFrame = (OCMPMessageFrame *)pMsg; if (pOCMPMessageFrame != NULL) { - LOGGER_DEBUG("BIGBROTHER:INFO:: RX Msg recieved with Length: 0x%x," + LOGGER_DEBUG("BIGBROTHER:INFO:: RX Msg received with Length: 0x%x," "Interface: 0x%x, Seq.No: 0x%x, TimeStamp: 0x%x.\n", pOCMPMessageFrame->header.ocmpFrameLen, pOCMPMessageFrame->header.ocmpInterface, @@ -148,7 +149,7 @@ static ReturnStatus bigbrother_process_rx_msg(uint8_t *pMsg) free(pMsg); } } else { - LOGGER_ERROR("BIGBROTHER:ERROR:: No message recieved.\n"); + LOGGER_ERROR("BIGBROTHER:ERROR:: No message received.\n"); free(pMsg); } return status; @@ -310,9 +311,19 @@ static void bigborther_spwan_task(void) /* Launches other tasks */ usb_rx_createtask(); // P - 05 usb_tx_createtask(); // P - 04 + + /*UART task*/ + uartdma_rx_createtask(); + uartdma_tx_createtask(); + + /* Gossiper*/ gossiper_createtask(); // P - 06 + + /* EBMP */ ebmp_create_task(); - watchdog_create_task(); + + /* KEEP ALIVE MC <--> EC */ + keep_alive_create_task(); /* Initialize subsystem interface to set up interfaces and launch * subsystem tasks */ @@ -372,8 +383,9 @@ static void bigbrother_taskfxn(UArg a0, UArg a1) bigborther_spwan_task(); // Perform POST bigborther_initiate_post(); + Task_Handle task_handle = Task_self(); while (true) { - if (Semaphore_pend(semBigBrotherMsg, BIOS_WAIT_FOREVER)) { + if (Semaphore_pend(semBigBrotherMsg, OC_TASK_WAIT_TIME)) { while (!Queue_empty(bigBrotherRxMsgQueue)) { uint8_t *pWrite = (uint8_t *)Util_dequeueMsg(bigBrotherRxMsgQueue); @@ -389,6 +401,8 @@ static void bigbrother_taskfxn(UArg a0, UArg a1) } } } + + wd_kick(task_handle); } } @@ -407,9 +421,10 @@ void bigbrother_createtask(void) Task_Params taskParams; // Configure task Task_Params_init(&taskParams); + taskParams.instance->name= "Bigbrother_t"; taskParams.stack = bigBrotherTaskStack; taskParams.stackSize = BIGBROTHER_TASK_STACK_SIZE; taskParams.priority = BIGBROTHER_TASK_PRIORITY; - Task_construct(&bigBrotherTask, bigbrother_taskfxn, &taskParams, NULL); + Util_create_task(&taskParams, &bigbrother_taskfxn, true); LOGGER_DEBUG("BIGBROTHER:INFO::Creating a BigBrother task.\n"); } diff --git a/firmware/ec/src/comm/gossiper.c b/firmware/ec/src/comm/gossiper.c index 2fc033c134..a3075aef50 100644 --- a/firmware/ec/src/comm/gossiper.c +++ b/firmware/ec/src/comm/gossiper.c @@ -89,10 +89,12 @@ void gossiper_createtask(void) Task_Params taskParams; // Configure task Task_Params_init(&taskParams); + taskParams.instance->name = "Gossiper_t"; taskParams.stack = gossiperTaskStack; taskParams.stackSize = GOSSIPER_TASK_STACK_SIZE; taskParams.priority = GOSSIPER_TASK_PRIORITY; - Task_construct(&gossiperTask, gossiper_taskfxn, &taskParams, NULL); + //Task_construct(&gossiperTask, gossiper_taskfxn, &taskParams, NULL); + Util_create_task(&taskParams, &gossiper_taskfxn, true); LOGGER_DEBUG("GOSSIPER:INFO::Creating a Gossiper task.\n"); } @@ -141,8 +143,9 @@ static void gossiper_init(void) static void gossiper_taskfxn(UArg a0, UArg a1) { gossiper_init(); + Task_Handle task_handle = Task_self(); while (true) { - if (Semaphore_pend(semGossiperMsg, BIOS_WAIT_FOREVER)) { + if (Semaphore_pend(semGossiperMsg, OC_TASK_WAIT_TIME)) { /* Gossiper RX Messgaes */ while (!Queue_empty(gossiperRxMsgQueue)) { uint8_t *pWrite = @@ -165,6 +168,8 @@ static void gossiper_taskfxn(UArg a0, UArg a1) } } } + + wd_kick(task_handle); } } diff --git a/firmware/ec/src/devices/eth_sw.c b/firmware/ec/src/devices/eth_sw.c index 0272d847c5..c0c3afa98b 100644 --- a/firmware/ec/src/devices/eth_sw.c +++ b/firmware/ec/src/devices/eth_sw.c @@ -538,7 +538,6 @@ ReturnStatus eth_sw_config_tiva_client(void *driver, void *params) int count = 0; Eth_TcpClient_Params *s_eth_tcpParams = (Eth_TcpClient_Params *)params; - Task_Handle taskHandle_client; Task_Params taskParams; Error_Block eb; @@ -562,13 +561,12 @@ ReturnStatus eth_sw_config_tiva_client(void *driver, void *params) * arg0 will be the port that this task sends the test data to. */ Task_Params_init(&taskParams); + taskParams.instance->name="TCPHandlerClient_t"; taskParams.stack = ethTivaClientTaskStack; taskParams.stackSize = TCPHANDLERSTACK; taskParams.priority = ETHTIVACLEINT_TASK_PRIORITY; taskParams.arg0 = s_eth_tcpParams->tcpPort; - - taskHandle_client = - Task_create((Task_FuncPtr)tcpHandler_client, &taskParams, &eb); + bool taskHandle_client = Util_create_task(&taskParams, &tcpHandler_client, false); if (taskHandle_client == NULL) { System_printf("Failed to create taskHandle_client Task\n"); } diff --git a/firmware/ec/src/devices/g510.c b/firmware/ec/src/devices/g510.c index e05bb22cca..9ec998c102 100644 --- a/firmware/ec/src/devices/g510.c +++ b/firmware/ec/src/devices/g510.c @@ -304,11 +304,13 @@ ePostCode g510_task_init(void *driver, const void *config, /* Create a task */ Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name = "TestModule_t"; taskParams.stack = testmodTaskStack; taskParams.stackSize = TESTMOD_TASK_STACK_SIZE; taskParams.priority = TESTMOD_TASK_PRIORITY; taskParams.arg0 = (intptr_t)alert_token; - Task_Handle task = Task_create(testModule_task, &taskParams, NULL); + //Task_Handle task = Task_create(testModule_task, &taskParams, NULL); + bool task = Util_create_task(&taskParams, &testModule_task, false); if (!task) { LOGGER("TESTMOD::FATAL: Unable to start G510 task\n"); Semaphore_delete(&sem_simReady); diff --git a/firmware/ec/src/devices/i2c/threaded_int.c b/firmware/ec/src/devices/i2c/threaded_int.c index daf9939e54..a2318661b3 100644 --- a/firmware/ec/src/devices/i2c/threaded_int.c +++ b/firmware/ec/src/devices/i2c/threaded_int.c @@ -90,12 +90,13 @@ void ThreadedInt_Init(OcGpio_Pin *irqPin, ThreadedInt_Callback cb, // TODO: look into error block and see if I should use it Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name = "ThreadedInterrupt_t"; taskParams.stackSize = TI_TASKSTACKSIZE; taskParams.priority = TI_TASKPRIORITY; taskParams.arg0 = (uintptr_t)&s_intConfigs[devNum]; - Task_Handle task = Task_create(ThreadedInt_Task, &taskParams, NULL); + bool task = Util_create_task(&taskParams, &ThreadedInt_Task, false); if (!task) { - DEBUG("ThrdInt::FATAL: Unable to start interrupt task\n"); + LOGGER_ERROR("ThrdInt::FATAL: Unable to start interrupt task\n"); Semaphore_delete(&sem); s_numDevices--; return; diff --git a/firmware/ec/src/devices/uart/at_cmd.c b/firmware/ec/src/devices/uart/at_cmd.c index 5ee4c92e9a..1d29f44380 100644 --- a/firmware/ec/src/devices/uart/at_cmd.c +++ b/firmware/ec/src/devices/uart/at_cmd.c @@ -435,11 +435,12 @@ AT_Handle AT_cmd_init(UART_Handle hCom, const AT_UnsolicitedRes *resList, // Create the input reader task Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name = "ATCMD_read_t"; taskParams.stackSize = AT_READ_TASK_STACK_SIZE; taskParams.priority = AT_READ_TASK_PRIORITY; taskParams.arg0 = (uintptr_t)handle; - Task_Handle thread = Task_create(ReadThread, &taskParams, NULL); - + //Task_Handle thread = Task_create(ReadThread, &taskParams, NULL); + bool thread = Util_create_task(&taskParams, &ReadThread, false) ; if (!thread) { LOGGER_ERROR("Fatal - unable to start input thread\n"); free(handle); diff --git a/firmware/ec/src/filesystem/fs_wrapper.c b/firmware/ec/src/filesystem/fs_wrapper.c index 3d4183af9b..3f8029f249 100644 --- a/firmware/ec/src/filesystem/fs_wrapper.c +++ b/firmware/ec/src/filesystem/fs_wrapper.c @@ -404,6 +404,7 @@ static bool fs_wrapper_msgHandler(FILESystemStruct *fileSysStruct) void fs_wrapper_fileSystem_init(UArg arg0, UArg arg1) { uint8_t index = 0; + FILESystemStruct *fileSysStruct; memset(&lfs, 0, sizeof(lfs)); memset(&file, 0, sizeof(file)); @@ -449,9 +450,9 @@ void fs_wrapper_fileSystem_init(UArg arg0, UArg arg1) } index++; } - + Task_Handle task_handle = Task_self(); while (true) { - if (Semaphore_pend(semFilesysMsg, BIOS_WAIT_FOREVER)) { + if (Semaphore_pend(semFilesysMsg, OC_TASK_WAIT_TIME)) { while (!Queue_empty(fsRxMsgQueue)) { fileSysStruct = (FILESystemStruct *)Util_dequeueMsg(fsRxMsgQueue); @@ -463,6 +464,7 @@ void fs_wrapper_fileSystem_init(UArg arg0, UArg arg1) } } } + wd_kick(task_handle); } } } diff --git a/firmware/ec/src/interfaces/Ethernet/tcp_tx_rx.c b/firmware/ec/src/interfaces/Ethernet/tcp_tx_rx.c index e7625e7e03..0e179e364f 100644 --- a/firmware/ec/src/interfaces/Ethernet/tcp_tx_rx.c +++ b/firmware/ec/src/interfaces/Ethernet/tcp_tx_rx.c @@ -61,17 +61,18 @@ Void tcp_Tx_Worker(UArg arg0, UArg arg1) int clientfd = (int)arg0; int bytesSent; uint8_t *buffer; - + Task_Handle task_handle = Task_self(); LOGGER_DEBUG("tcpWorker: start clientfd = 0x%x\n", clientfd); - while (clientfd) { - Semaphore_pend(ethTxsem, BIOS_WAIT_FOREVER); + Semaphore_pend(ethTxsem, OC_TASK_WAIT_TIME); { - buffer = Util_dequeueMsg(ethTxMsgQueue); - bytesSent = send(clientfd, buffer, TCPPACKETSIZE, 0); - if (bytesSent < 0) { - LOGGER_DEBUG("Error: send failed.\n"); - break; + while (!Queue_empty(ethTxMsgQueue)) { + buffer = Util_dequeueMsg(ethTxMsgQueue); + bytesSent = send(clientfd, buffer, TCPPACKETSIZE, 0); + if (bytesSent < 0) { + LOGGER_DEBUG("Error: send failed.\n"); + break; + } } } } @@ -87,7 +88,7 @@ Void tcp_Rx_Worker(UArg arg0, UArg arg1) { int clientfd = (int)arg0; char buffer[TCPPACKETSIZE]; - + Task_Handle task_handle = Task_self(); LOGGER_DEBUG("tcpWorker: start clientfd = 0x%x\n", clientfd); while ((bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0)) > 0) { Util_enqueueMsg(gossiperRxMsgQueue, semGossiperMsg, (uint8_t *)buffer); @@ -181,18 +182,19 @@ Void tcpHandler_client(UArg arg0, UArg arg1) Void tcpHandler(UArg arg0, UArg arg1) { int status; - int clientfd; int server; + int clientfd; + fd_set active_fd_set, read_fd_set; + struct timeval timeout; struct sockaddr_in localAddr; struct sockaddr_in clientAddr; int optval; int optlen = sizeof(optval); socklen_t addrlen = sizeof(clientAddr); - Task_Handle task_Tx_Handle; Task_Params task_Tx_Params; - Task_Handle task_Rx_Handle; Task_Params task_Rx_Params; Error_Block eb; + Task_Handle task_handle = Task_self(); server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (server == -1) { @@ -223,6 +225,76 @@ Void tcpHandler(UArg arg0, UArg arg1) goto shutdown; } + /* Initialize the set of active sockets. */ + FD_ZERO (&active_fd_set); + FD_SET (server, &active_fd_set); + + /* Timeout */ + timeout.tv_sec = OC_TASK_WAIT_TIME/OC_SYS_TICK; + timeout.tv_usec = 0; + + while (1) + { + /* Block until input arrives on one or more active sockets. */ + read_fd_set = active_fd_set; + System_printf("Select wait...\n"); + System_flush(); + status = select (server + 1, &read_fd_set, NULL, NULL, &timeout); + if ( status < 0 ) + { + System_printf("Error: Failed to create new Task\n"); + goto shutdown; + } + + if ( status == 0 ) { + /* Kick to watchdog */ + wd_kick(task_handle); + } else { + /* Service all the sockets with input pending. */ + if (FD_ISSET (server, &read_fd_set)) + { + /* Connection request on original socket. */ + if (((clientfd = accept(server, (struct sockaddr *)&clientAddr, &addrlen)) != -1)) + { + LOGGER_DEBUG("tcpHandler: Creating thread clientfd = %d\n", clientfd); + + /* Init the Error_Block */ + Error_init(&eb); + + /* Initialize the defaults and set the parameters. */ + Task_Params_init(&task_Tx_Params); + task_Tx_Params.instance->name = "TcpTxWorker_t"; + task_Tx_Params.arg0 = (UArg)clientfd; + task_Tx_Params.stackSize = 1280; + bool task_Tx_Handle = Util_create_task(&task_Tx_Params, &tcp_Tx_Worker, false) ; + //Task_create((Task_FuncPtr)tcp_Tx_Worker, &task_Tx_Params, &eb); + if (task_Tx_Handle == NULL) { + LOGGER_DEBUG("Error: Failed to create new Task\n"); + close(clientfd); + } + + /* Initialize the defaults and set the parameters. */ + Task_Params_init(&task_Rx_Params); + task_Rx_Params.instance->name="TcpRxWorker_t"; + task_Rx_Params.arg0 = (UArg)clientfd; + task_Rx_Params.stackSize = 1280; + bool task_Rx_Handle = Util_create_task(&task_Rx_Params, &tcp_Rx_Worker, false) ; + //Task_create((Task_FuncPtr)tcp_Rx_Worker, &task_Rx_Params, &eb); + if (task_Rx_Handle == NULL) { + LOGGER_DEBUG("Error: Failed to create new Task\n"); + close(clientfd); + } + + /* addrlen is a value-result param, must reset for next accept call */ + addrlen = sizeof(clientAddr); + } + } + /* In case if too busy serving request. Its good to kick watchdog */ + wd_kick(task_handle); + } + } + +#if 0 while ((clientfd = accept(server, (struct sockaddr *)&clientAddr, &addrlen)) != -1) { LOGGER_DEBUG("tcpHandler: Creating thread clientfd = %d\n", clientfd); @@ -232,10 +304,11 @@ Void tcpHandler(UArg arg0, UArg arg1) /* Initialize the defaults and set the parameters. */ Task_Params_init(&task_Tx_Params); + task_Tx_Params.instance->name = "TcpTxWorker_t"; task_Tx_Params.arg0 = (UArg)clientfd; task_Tx_Params.stackSize = 1280; - task_Tx_Handle = - Task_create((Task_FuncPtr)tcp_Tx_Worker, &task_Tx_Params, &eb); + bool task_Tx_Handle = Util_create_task(&task_Tx_Params, &tcp_Tx_Worker, false) ; + //Task_create((Task_FuncPtr)tcp_Tx_Worker, &task_Tx_Params, &eb); if (task_Tx_Handle == NULL) { LOGGER_DEBUG("Error: Failed to create new Task\n"); close(clientfd); @@ -243,10 +316,11 @@ Void tcpHandler(UArg arg0, UArg arg1) /* Initialize the defaults and set the parameters. */ Task_Params_init(&task_Rx_Params); + task_Rx_Params.instance->name="TcpRxWorker_t"; task_Rx_Params.arg0 = (UArg)clientfd; task_Rx_Params.stackSize = 1280; - task_Rx_Handle = - Task_create((Task_FuncPtr)tcp_Rx_Worker, &task_Rx_Params, &eb); + bool task_Rx_Handle = Util_create_task(&task_Rx_Params, &tcp_Rx_Worker, false) ; + //Task_create((Task_FuncPtr)tcp_Rx_Worker, &task_Rx_Params, &eb); if (task_Rx_Handle == NULL) { LOGGER_DEBUG("Error: Failed to create new Task\n"); close(clientfd); @@ -257,8 +331,8 @@ Void tcpHandler(UArg arg0, UArg arg1) } LOGGER_DEBUG("Error: accept failed.\n"); - -shutdown: +#endif + shutdown: if (server > 0) { close(server); } @@ -309,7 +383,7 @@ int ethernet_start(void) */ void netOpenHook() { - Task_Handle taskHandle; + Task_Params taskParams; Error_Block eb; @@ -321,10 +395,11 @@ void netOpenHook() * arg0 will be the port that this task listens to. */ Task_Params_init(&taskParams); + taskParams.instance->name = "TCPHandler_t"; taskParams.stackSize = TCPHANDLERSTACK; taskParams.priority = 1; taskParams.arg0 = TCPPORT; - taskHandle = Task_create((Task_FuncPtr)tcpHandler, &taskParams, &eb); + bool taskHandle = Util_create_task(&taskParams, &tcpHandler, true); if (taskHandle == NULL) { LOGGER_DEBUG("netOpenHook: Failed to create tcpHandler Task\n"); } diff --git a/firmware/ec/src/interfaces/UART/uartdma.c b/firmware/ec/src/interfaces/UART/uartdma.c index c1be99eb4c..7de6609898 100644 --- a/firmware/ec/src/interfaces/UART/uartdma.c +++ b/firmware/ec/src/interfaces/UART/uartdma.c @@ -93,6 +93,45 @@ void uDMAErrorHandler(void) } } +/***************************************************************************** + * + * The interrupt handler for UART3. + * + *****************************************************************************/ +void UART3IntHandler(void) +{ + uint32_t ui32Status; + uint32_t ui32Mode; + ui32Status = UARTIntStatus(UART3_BASE, 1); + + /* Clear any pending status*/ + UARTIntClear(UART3_BASE, ui32Status); + + /*Primary Buffer*/ + ui32Mode = uDMAChannelModeGet(UDMA_CHANNEL_ADC2 | UDMA_PRI_SELECT); + if (ui32Mode == UDMA_MODE_STOP) { + uDMAChannelTransferSet( + UDMA_CHANNEL_ADC2 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, + (void *)(UART3_BASE + UART_O_DR), ui8RxBufA, sizeof(ui8RxBufA)); + /*Preparing message to send to UART RX Queue*/ + memset(ui8uartdmaRxBuf, '\0', UART_RXBUF_SIZE); + memcpy(ui8uartdmaRxBuf, ui8RxBufA, sizeof(ui8RxBufA)); + Semaphore_post(semUART); + } + + /*Alternate Buffer*/ + ui32Mode = uDMAChannelModeGet(UDMA_CHANNEL_ADC2 | UDMA_ALT_SELECT); + if (ui32Mode == UDMA_MODE_STOP) { + uDMAChannelTransferSet( + UDMA_CHANNEL_ADC2 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, + (void *)(UART3_BASE + UART_O_DR), ui8RxBufB, sizeof(ui8RxBufB)); + /*Preparing message to send to UART RX Queue*/ + memset(ui8uartdmaRxBuf, '\0', UART_RXBUF_SIZE); + memcpy(ui8uartdmaRxBuf, ui8RxBufB, sizeof(ui8RxBufB)); + Semaphore_post(semUART); + } +} + /***************************************************************************** * * The interrupt handler for UART4. @@ -156,21 +195,21 @@ void ConfigureUART(void) "UARTDMACTR:INFO::Configuring UART interface for communication.\n"); /* Enable the GPIO Peripheral used by the UART.*/ - SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); /* Enable UART3 */ - SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4); - SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART4); + SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); + SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART3); /* Configure GPIO Pins for UART mode.*/ - GPIOPinConfigure(GPIO_PK0_U4RX); - GPIOPinConfigure(GPIO_PK1_U4TX); - GPIOPinTypeUART(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1); + GPIOPinConfigure(GPIO_PA4_U3RX); + GPIOPinConfigure(GPIO_PA5_U3TX); + GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5); } /**************************************************************************** * - * Initializes the UART3 peripheral and sets up the TX and RX uDMA channels. + * Initializes the UART4 peripheral and sets up the TX and RX uDMA channels. *****************************************************************************/ void InitUART4Transfer(void) { @@ -250,6 +289,89 @@ void InitUART4Transfer(void) IntEnable(INT_UART4); } + +/**************************************************************************** + * + * Initializes the UART3 peripheral and sets up the TX and RX uDMA channels. + *****************************************************************************/ +void InitUART3Transfer(void) +{ + LOGGER_DEBUG( + "UARTDMACTR:INFO::Configuring UART interrupt and uDMA channel for communication to GPP.\n"); + uint_fast16_t ui16Idx; + const uint32_t SysClock = 120000000; + + /* TX buffer init to 0.*/ + for (ui16Idx = 0; ui16Idx < UART_TXBUF_SIZE; ui16Idx++) { + ui8TxBuf[ui16Idx] = 0; + } + + /* Enable the UART peripheral, and configure it to operate even if the CPU + * is in sleep.*/ + SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); + SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART3); + + /* Configure the UART communication parameters.*/ + + UARTConfigSetExpClk(UART3_BASE, SysClock, 115200, + UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | + UART_CONFIG_PAR_NONE); + + /* Set both the TX and RX trigger thresholds to 4. */ + UARTFIFOLevelSet(UART3_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); + + /* Enable the UART for operation, and enable the uDMA interface for both TX + * and RX channels.*/ + UARTEnable(UART3_BASE); + UARTDMAEnable(UART3_BASE, UART_DMA_RX | UART_DMA_TX); + + uDMAChannelAttributeDisable( + UDMA_CHANNEL_ADC2, UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | + UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); + + uDMAChannelControlSet(UDMA_CHANNEL_ADC2 | UDMA_PRI_SELECT, + UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | + UDMA_ARB_4); + + uDMAChannelControlSet(UDMA_CHANNEL_ADC2 | UDMA_ALT_SELECT, + UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | + UDMA_ARB_4); + + uDMAChannelTransferSet(UDMA_CHANNEL_ADC2 | UDMA_PRI_SELECT, + UDMA_MODE_PINGPONG, (void *)(UART3_BASE + UART_O_DR), + ui8RxBufA, sizeof(ui8RxBufA)); + + uDMAChannelTransferSet(UDMA_CHANNEL_ADC2 | UDMA_ALT_SELECT, + UDMA_MODE_PINGPONG, (void *)(UART3_BASE + UART_O_DR), + ui8RxBufB, sizeof(ui8RxBufB)); + + uDMAChannelAttributeDisable(UDMA_CHANNEL_ADC3, + UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | + UDMA_ATTR_REQMASK); + + uDMAChannelAttributeEnable(UDMA_CHANNEL_ADC3, UDMA_ATTR_USEBURST); + + uDMAChannelControlSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, + UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE | + UDMA_ARB_4); + + uDMAChannelTransferSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, + UDMA_MODE_BASIC, ui8TxBuf, + (void *)(UART3_BASE + UART_O_DR), sizeof(ui8TxBuf)); + + uDMAChannelAssign(UDMA_CH16_UART3RX); + uDMAChannelAssign(UDMA_CH17_UART3TX); + + uDMAChannelEnable(UDMA_CHANNEL_ADC2); //16 + uDMAChannelEnable(UDMA_CHANNEL_ADC3); //17 + + /* Enable the UART DMA TX/RX interrupts.*/ + UARTIntEnable(UART3_BASE, UART_INT_DMARX); + + /* Enable the UART peripheral interrupts.*/ + IntEnable(INT_UART3); +} + /***************************************************************************** * Intialize UART uDMA for the data transfer. This will initialise both Tx and * Rx Channel associated with UART Tx and Rx @@ -262,7 +384,7 @@ void uartdma_init(void) IntEnable(INT_UDMAERR); uDMAEnable(); uDMAControlBaseSet(pui8ControlTable); - InitUART4Transfer(); + InitUART3Transfer(); } /***************************************************************************** @@ -270,12 +392,6 @@ void uartdma_init(void) ****************************************************************************/ void uartDMAinterface_init(void) { - /* Configure UART */ - ConfigureUART(); - - /* Initialize UART */ - uartdma_init(); - /*UART RX Semaphore */ LOGGER_DEBUG("UARTDMACTR:INFO:: uartDMA interface intialization.\n"); semUART = Semaphore_create(0, NULL, NULL); @@ -289,6 +405,12 @@ void uartDMAinterface_init(void) "UARTDMACTR:INFO::Constructing message Queue 0x%x for UART RX OCMP Messages.\n", uartRxMsgQueue); + /* Configure UART */ + ConfigureUART(); + + /* Initialize UART */ + uartdma_init(); + LOGGER_DEBUG("UARTDMACTR:INFO::Waiting for OCMP UART RX messgaes....!!!\n"); } @@ -299,10 +421,14 @@ static void uartdma_rx_taskfxn(UArg arg0, UArg arg1) { // Initialize application uartDMAinterface_init(); + static int i = 0; // Application main loop while (true) { if (Semaphore_pend(semUART, BIOS_WAIT_FOREVER)) { + LOGGER_DEBUG("Received packet %d total size %d\n",i , i*256); + i++; +#if 0 /* Reset Uart DMA if the SOF is not equal to 0X55 */ if (ui8uartdmaRxBuf[0] != OCMP_MSG_SOF) { resetUARTDMA(); @@ -330,7 +456,9 @@ static void uartdma_rx_taskfxn(UArg arg0, UArg arg1) UART_RXBUF_SIZE); } } +#endif } + } } @@ -382,7 +510,7 @@ static ReturnStatus uartdma_process_tx_message(uint8_t *pMsg) #endif uDMAChannelTransferSet( UDMA_CHANNEL_TMR0B | UDMA_PRI_SELECT, UDMA_MODE_BASIC, ui8TxBuf, - (void *)(UART4_BASE + UART_O_DR), sizeof(ui8TxBuf)); + (void *)(UART3_BASE + UART_O_DR), sizeof(ui8TxBuf)); uDMAChannelEnable(UDMA_CHANNEL_TMR0B); } else { status = RETURN_NOTOK; @@ -427,12 +555,13 @@ void uartdma_rx_createtask(void) { Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name="IFUARTDMARX_t"; taskParams.stackSize = OCUARTDMA_TASK_STACK_SIZE; taskParams.stack = &ocUARTDMATaskStack; - taskParams.instance->name = "UART_DMA_TASK"; taskParams.priority = OCUARTDMA_TASK_PRIORITY; - Task_construct(&ocUARTDMATask, (Task_FuncPtr)uartdma_rx_taskfxn, - &taskParams, NULL); + Util_create_task(&taskParams, &uartdma_rx_taskfxn, true); + //Task_construct(&ocUARTDMATask, (Task_FuncPtr)uartdma_rx_taskfxn, + // &taskParams, NULL); LOGGER_DEBUG("UARTDMACTRl:INFO::Creating UART DMA task function.\n"); } @@ -450,11 +579,12 @@ void uartdma_tx_createtask(void) { Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name="IFUARTDMATX_t"; taskParams.stackSize = OCUARTDMATX_TASK_STACK_SIZE; taskParams.stack = &ocUARTDMATxTaskStack; - taskParams.instance->name = "UART_DMA_TX_TASK"; taskParams.priority = OCUARTDMATX_TASK_PRIORITY; - Task_construct(&ocUARTDMATxTask, (Task_FuncPtr)uartdma_tx_taskfxn, - &taskParams, NULL); + Util_create_task(&taskParams, &uartdma_tx_taskfxn, true); + //Task_construct(&ocUARTDMATxTask, (Task_FuncPtr)uartdma_tx_taskfxn, + // &taskParams, NULL); LOGGER_DEBUG("UARTDMACTRl:INFO::Creating UART DMA TX task function.\n"); } diff --git a/firmware/ec/src/interfaces/USB/usb.c b/firmware/ec/src/interfaces/USB/usb.c index 86872c8874..6357917b97 100644 --- a/firmware/ec/src/interfaces/USB/usb.c +++ b/firmware/ec/src/interfaces/USB/usb.c @@ -138,13 +138,21 @@ void usb_rx_taskinit(void) *****************************************************************************/ void usb_tx_taskfxn(UArg arg0, UArg arg1) { + Task_Handle task_handle = Task_self(); /* USB TX Task init*/ usb_tx_taskinit(); while (true) { /* Block while the device is NOT connected to the USB */ - USBCDCD_waitForConnect(BIOS_WAIT_FOREVER); - if (Semaphore_pend(semUSBTX, BIOS_WAIT_FOREVER)) { + + while (true) { + if(USBCDCD_waitForConnect(OC_TASK_WAIT_TIME)) + { + break; + } + wd_kick(task_handle); + }; + if (Semaphore_pend(semUSBTX, OC_TASK_WAIT_TIME)) { /* OCMP UART TX Messgaes */ while (!Queue_empty(usbTxMsgQueue)) { uint8_t *pWrite = (uint8_t *)Util_dequeueMsg(usbTxMsgQueue); @@ -165,7 +173,9 @@ void usb_tx_taskfxn(UArg arg0, UArg arg1) } free(pWrite); } + } + wd_kick(task_handle); } } @@ -191,12 +201,20 @@ void usb_rx_taskfxn(UArg arg0, UArg arg1) /* USB RX Task init*/ usb_rx_taskinit(); + Task_Handle task_handle = Task_self(); + while (true) { /* Block while the device is NOT connected to the USB */ - USBCDCD_waitForConnect(BIOS_WAIT_FOREVER); + while (true) { + if(USBCDCD_waitForConnect(OC_TASK_WAIT_TIME)) + { + break; + } + wd_kick(task_handle); + }; received = - USBCDCD_receiveData(ui8RxBuf, USB_FRAME_LENGTH, BIOS_WAIT_FOREVER); + USBCDCD_receiveData(ui8RxBuf, USB_FRAME_LENGTH, OC_TASK_WAIT_TIME ); ui8RxBuf[received] = '\0'; if (received && (ui8RxBuf[0] == 0x55)) { /* OCMP USB RX Messgaes */ @@ -222,6 +240,8 @@ void usb_rx_taskfxn(UArg arg0, UArg arg1) USB_FRAME_LENGTH); } } + + wd_kick(task_handle); } } @@ -239,12 +259,13 @@ void usb_tx_createtask(void) { Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name = "IFUSBTX_t"; taskParams.stackSize = OCUSB_TX_TASK_STACK_SIZE; taskParams.stack = &ocUSBTxTaskStack; - taskParams.instance->name = "USB_TX_TASK"; taskParams.priority = OCUSB_TX_TASK_PRIORITY; - Task_construct(&ocUSBTxTask, (Task_FuncPtr)usb_tx_taskfxn, &taskParams, - NULL); + Util_create_task(&taskParams, &usb_tx_taskfxn, true); + //Task_construct(&ocUSBTxTask, (Task_FuncPtr)usb_tx_taskfxn, &taskParams, + // NULL); LOGGER_DEBUG("USBTX:INFO:: Creating USB TX task function.\n"); } @@ -262,11 +283,12 @@ void usb_rx_createtask(void) { Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name = "IFUSBRX_t"; taskParams.stackSize = OCUSB_RX_TASK_STACK_SIZE; taskParams.stack = &ocUSBRxTaskStack; - taskParams.instance->name = "USB_RX_TASK"; taskParams.priority = OCUSB_RX_TASK_PRIORITY; - Task_construct(&ocUSBRxTask, (Task_FuncPtr)usb_rx_taskfxn, &taskParams, - NULL); + Util_create_task(&taskParams, &usb_rx_taskfxn, true); + //Task_construct(&ocUSBRxTask, (Task_FuncPtr)usb_rx_taskfxn, &taskParams, + // NULL); LOGGER_DEBUG("USBRX:INFO:: Creating USB RX task function.\n"); } diff --git a/firmware/ec/src/main.c b/firmware/ec/src/main.c index da02641e65..4ea8d16961 100644 --- a/firmware/ec/src/main.c +++ b/firmware/ec/src/main.c @@ -75,6 +75,9 @@ int main(void) Board_initUART(); ethernet_start(); bigbrother_createtask(); +#ifdef OC_Watchdog + wd_createtask(); +#endif /* Start BIOS */ BIOS_start(); return (0); diff --git a/firmware/ec/src/post/post.c b/firmware/ec/src/post/post.c index c7f8046f15..9a86ec1250 100644 --- a/firmware/ec/src/post/post.c +++ b/firmware/ec/src/post/post.c @@ -103,6 +103,14 @@ void _post_complete() "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"); LOGGER_DEBUG( "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"); + +#ifdef POST_READ_DATA_TEST + LOGGER_DEBUG("Starting Post read request test.\n"); + OCMPMessageFrame *postExeMsg = create_ocmp_msg_frame( + OC_SS_SYS, OCMP_MSG_TYPE_POST, OCMP_AXN_TYPE_GET, 0x01, 0x01, 0x00); + Util_enqueueMsg(bigBrotherRxMsgQueue, semBigBrotherMsg, + (uint8_t *)postExeMsg); +#endif } /***************************************************************************** @@ -249,7 +257,7 @@ static ReturnStatus post_process_msg(OCMPSubsystem OC_subSystem) *****************************************************************************/ static OCMPMessageFrame *post_create_execute_msg(OCMPSubsystem OC_subSystem) { - LOGGER_DEBUG("POST:INFO::Activation POST for SS %d.", OC_subSystem); + LOGGER_DEBUG("POST:INFO::Activation POST for SS %d.\n", OC_subSystem); OCMPMessageFrame *postExeMsg = create_ocmp_msg_frame( OC_subSystem, OCMP_MSG_TYPE_POST, OCMP_AXN_TYPE_ACTIVE, 0x00, 0x00, 1); return postExeMsg; @@ -398,9 +406,11 @@ static void post_task_init(void) ******************************************************************************/ static void post_taskfxn(UArg a0, UArg a1) { + post_task_init(); + Task_Handle task_handle = Task_self(); while (true) { - if (Semaphore_pend(semPOSTMsg, BIOS_WAIT_FOREVER)) { + if (Semaphore_pend(semPOSTMsg, OC_TASK_WAIT_TIME)) { while (!Queue_empty(postRxMsgQueue)) { OCMPMessageFrame *pWrite = (OCMPMessageFrame *)Util_dequeueMsg(postRxMsgQueue); @@ -408,7 +418,9 @@ static void post_taskfxn(UArg a0, UArg a1) post_process_rx_msg(pWrite); } } + } + wd_kick(task_handle); } } @@ -428,8 +440,10 @@ void post_createtask(void) // Configure task Task_Params_init(&taskParams); + taskParams.instance->name = "POST_t"; taskParams.stack = postTaskStack; taskParams.stackSize = POST_TASK_STACK_SIZE; taskParams.priority = OC_POST_TASKPRIORITY; - Task_construct(&postTask, post_taskfxn, &taskParams, NULL); + Util_create_task(&taskParams, &post_taskfxn, true); + //Task_construct(&postTask, post_taskfxn, &taskParams, NULL); } diff --git a/firmware/ec/src/registry/SSRegistry.c b/firmware/ec/src/registry/SSRegistry.c index 1200aa5f6c..8fc902eb88 100644 --- a/firmware/ec/src/registry/SSRegistry.c +++ b/firmware/ec/src/registry/SSRegistry.c @@ -390,9 +390,9 @@ static void _subsystem_event_loop(UArg a0, UArg a1) } // const Component *component = &sys_schema[a1]; - + Task_Handle task_handle = Task_self(); while (1) { - if (Semaphore_pend(ss->sem, BIOS_WAIT_FOREVER)) { + if (Semaphore_pend(ss->sem, OC_TASK_WAIT_TIME)) { while (!Queue_empty(ss->msgQueue)) { OCMPMessageFrame *pMsg = (OCMPMessageFrame *)Util_dequeueMsg(ss->msgQueue); @@ -407,6 +407,8 @@ static void _subsystem_event_loop(UArg a0, UArg a1) } } } + + wd_kick(task_handle); } } @@ -444,17 +446,32 @@ static void subsystem_init(OCMPSubsystem ss_id) ss_id); } - /* Spin up the task */ - Task_Params taskParams; - Task_Params_init(&taskParams); - taskParams.stack = OC_task_stack[ss_id]; // ss->taskStack; - taskParams.stackSize = OC_TASK_STACK_SIZE; // ss->taskStackSize; - taskParams.priority = OC_TASK_PRIORITY; // ss->taskPriority; - taskParams.arg0 = (UArg)ss; - taskParams.arg1 = ss_id; - Task_construct(&ss->taskStruct, _subsystem_event_loop, &taskParams, NULL); - LOGGER_DEBUG("SS REG:DEBUG:: Creating Task for Subsystem %d\n", ss_id); + + char* name = malloc(sizeof(char)*15); + if(name) { + /* Spin up the task */ + Task_Params taskParams; + Task_Params_init(&taskParams); + /* Concatenate the SSID to name*/ + memset(name,'\0',15); + strcpy(name,"SubSystem_t-"); + char postfix[3]={'\0'}; + sprintf(postfix, "%02d", ss_id); + strcat(name,postfix); + taskParams.instance->name = name; + taskParams.stack = OC_task_stack[ss_id]; // ss->taskStack; + taskParams.stackSize = OC_TASK_STACK_SIZE; // ss->taskStackSize; + taskParams.priority = OC_TASK_PRIORITY; // ss->taskPriority; + taskParams.arg0 = (UArg)ss; + taskParams.arg1 = ss_id; + Util_create_task(&taskParams, &_subsystem_event_loop, true); + //Task_construct(&ss->taskStruct, _subsystem_event_loop, &taskParams, NULL); + LOGGER_DEBUG("SS REG:DEBUG:: Creating Task for Subsystem %d\n", ss_id); + + } else { + LOGGER_ERROR("SS REG:DEBUG:: Creating Task for Subsystem %d failed.\n", ss_id); + } } void SSRegistry_init(void) diff --git a/firmware/ec/src/registry/SSRegistry.h b/firmware/ec/src/registry/SSRegistry.h index 5a44398b01..6a097b209e 100644 --- a/firmware/ec/src/registry/SSRegistry.h +++ b/firmware/ec/src/registry/SSRegistry.h @@ -35,6 +35,7 @@ typedef struct OCSubsystem { Semaphore_Struct semStruct; Task_Struct taskStruct; eSubSystemStates state; + UInt wd_event; } OCSubsystem; /** diff --git a/firmware/ec/src/subsystem/gpp/ebmp.c b/firmware/ec/src/subsystem/gpp/ebmp.c index d6f38d8683..8fbfba9bb8 100644 --- a/firmware/ec/src/subsystem/gpp/ebmp.c +++ b/firmware/ec/src/subsystem/gpp/ebmp.c @@ -62,7 +62,7 @@ static OcGpio_Pin *pin_ap_boot_alert2; //***************************************************************************** // EXTERN FUNCTIONS //***************************************************************************** -extern void watchdog_reset_ap(void); +extern void keepAlive_reset_ap(void); /****************************************************************************** ** FUNCTION NAME : ebmp_restart_timer @@ -111,7 +111,7 @@ void ebmp_boot_monitor_timeout(void) *********************************************/ // send_msg_big_brother(); Clock_stop(bootProgressClk); - // watchdog_reset_ap(); + // keepAlive_reset_ap(); } } else { /***************************************************** @@ -400,8 +400,10 @@ void ebmp_create_task(void) Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name = "GPPEBMP_t"; taskParams.stack = ebmpTaskStack; taskParams.stackSize = EBMP_TASK_STACK_SIZE; taskParams.priority = EBMP_TASK_PRIORITY; - Task_construct(&ebmpTask, ebmp_task_fxn, &taskParams, NULL); + Util_create_task(&taskParams, &ebmp_task_fxn, false) ; + //Task_construct(&ebmpTask, ebmp_task_fxn, &taskParams, NULL); } diff --git a/firmware/ec/src/subsystem/gpp/gpp.c b/firmware/ec/src/subsystem/gpp/gpp.c index 15ef0b14df..1abb558466 100644 --- a/firmware/ec/src/subsystem/gpp/gpp.c +++ b/firmware/ec/src/subsystem/gpp/gpp.c @@ -62,8 +62,8 @@ bool gpp_pmic_control(Gpp_gpioCfg *driver, uint8_t control) * Embedded Controller(EC) by toggling two GPIO's.ebmp_init is a * function where we register the required GPIO's for interrupts if AP * move from one boot process state to other.*/ - ebmp_init(driver); - SysCtlDelay(100); + //ebmp_init(driver); + //SysCtlDelay(100); OcGpio_write(&driver->pin_ap_12v_onoff, true); SysCtlDelay(100); diff --git a/firmware/ec/src/subsystem/hci/led/hci_led.c b/firmware/ec/src/subsystem/hci/led/hci_led.c index 0ced21b293..2b478da912 100644 --- a/firmware/ec/src/subsystem/hci/led/hci_led.c +++ b/firmware/ec/src/subsystem/hci/led/hci_led.c @@ -72,10 +72,11 @@ void HCI_LedTaskInit(void) /* Create a task */ Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name = "HCILed_t"; taskParams.stack = hciLedTaskStack; taskParams.stackSize = HCI_LED_TASK_STACK_SIZE; taskParams.priority = HCI_LED_TASK_PRIORITY; - Task_Handle task = Task_create(HCI_LedTaskFxn, &taskParams, NULL); + bool task = Util_create_task(&taskParams, &HCI_LedTaskFxn, false); if (!task) { DEBUG("HCI::FATAL: Unable to start Led Polling task\n"); return; diff --git a/firmware/ec/src/subsystem/watchdog/watchdog.c b/firmware/ec/src/subsystem/health/keepAlive.c similarity index 62% rename from firmware/ec/src/subsystem/watchdog/watchdog.c rename to firmware/ec/src/subsystem/health/keepAlive.c index 2ff94892df..7765904245 100644 --- a/firmware/ec/src/subsystem/watchdog/watchdog.c +++ b/firmware/ec/src/subsystem/health/keepAlive.c @@ -10,13 +10,12 @@ //***************************************************************************** // HEADER FILES //***************************************************************************** -#include "inc/subsystem/watchdog/watchdog.h" - #include "common/inc/global/ocmp_frame.h" #include "drivers/OcGpio.h" #include "inc/common/bigbrother.h" #include "inc/common/global_header.h" #include "inc/subsystem/gpp/gpp.h" +#include "inc/subsystem/health/keepalive.h" #include "inc/utils/util.h" #include @@ -28,12 +27,12 @@ // HANDLES DEFINITION //***************************************************************************** /* Global Task Configuration Variables */ -static Task_Struct WatchdogTask; -static Char WatchdogTaskStack[WATCHDOG_TASK_STACK_SIZE]; +static Task_Struct keepAliveTask; +static Char keepAliveTaskStack[KEEPALIVE_TASK_STACK_SIZE]; /* Queue Handles */ -Semaphore_Handle watchdogSem; -Queue_Handle watchdogMsgQueue; +Semaphore_Handle keepAliveSem; +Queue_Handle keepAliveMsgQueue; /* Clock Handle */ Clock_Handle watchdog; @@ -68,9 +67,9 @@ uint32_t timeup = 60; extern const void *sys_config[]; /******************************************************************************* - * watchdog_reset_ap : Command the GPP task to reset AP + * keepAlive_reset_ap : Command the GPP task to reset AP ******************************************************************************/ -void watchdog_reset_ap(void) +void keepAlive_reset_ap(void) { uint32_t delay = 0; const Gpp_gpioCfg *cfg = sys_config[OC_SS_GPP]; @@ -82,45 +81,45 @@ void watchdog_reset_ap(void) OcGpio_write(&cfg->pin_ec_reset_to_proc, true); - // OCMPMessageFrame * pWatchdogMsg = (OCMPMessageFrame *) + // OCMPMessageFrame * pKeepAliveMsg = (OCMPMessageFrame *) // malloc(sizeof(32)); /* For now only AP reset is being applied directly to see the effect*/ return; } /******************************************************************************* - * watchdog_send_messages : Processes the watchdog TX Messages + * keepAlive_send_messages : Processes the watchdog TX Messages ******************************************************************************/ -void watchdog_send_messages(OCMPMessageFrame *pWatchdogMsg) +void keepAlive_send_messages(OCMPMessageFrame *pKeepAliveMsg) { - if (pWatchdogMsg != NULL) { + if (pKeepAliveMsg != NULL) { Util_enqueueMsg(bigBrotherTxMsgQueue, semBigBrotherMsg, - (uint8_t *)pWatchdogMsg); + (uint8_t *)pKeepAliveMsg); } else { LOGGER_DEBUG("WATCHDOG:ERROR:: pointer NULL!!??"); } } /***************************************************************************** - * watchdog_send_cmd_message: fill the msg structure and send it over UART + * keepalive_send_cmd_message: fill the msg structure and send it over UART ****************************************************************************/ -void watchdog_send_cmd_message(void) +void keepalive_send_cmd_message(void) { - OCMPMessageFrame *pWatchdogMsg = (OCMPMessageFrame *)malloc(32); - pWatchdogMsg->header.ocmpInterface = OCMP_COMM_IFACE_UART; - pWatchdogMsg->header.ocmpSof = OCMP_MSG_SOF; - pWatchdogMsg->message.subsystem = OC_SS_WD; - pWatchdogMsg->message.msgtype = OCMP_MSG_TYPE_STATUS; - pWatchdogMsg->message.action = OCMP_AXN_TYPE_SET; - watchdog_send_messages(pWatchdogMsg); + OCMPMessageFrame *pKeepAliveMsg = (OCMPMessageFrame *)malloc(32); + pKeepAliveMsg->header.ocmpInterface = OCMP_COMM_IFACE_UART; + pKeepAliveMsg->header.ocmpSof = OCMP_MSG_SOF; + pKeepAliveMsg->message.subsystem = OC_SS_WD; + pKeepAliveMsg->message.msgtype = OCMP_MSG_TYPE_STATUS; + pKeepAliveMsg->message.action = OCMP_AXN_TYPE_SET; + keepAlive_send_messages(pKeepAliveMsg); } /***************************************************************************** - * watchdog_call : This clock function will be called every 1 sec. It checks + * keepalive_call : This clock function will be called every 1 sec. It checks * if watchdog command is received or not? If not then it resets * the AP or send command to BMS to reset the AP *****************************************************************************/ -Void watchdog_call(UArg arg0) +Void keepalive_call(UArg arg0) { if (apUp && (localCounter < timeup)) { /* Watchdog command is recieved properly */ @@ -130,7 +129,7 @@ Void watchdog_call(UArg arg0) } else { localCounter += 1; if ((localCounter % reinterationTime) == 0) - Semaphore_post(watchdogSem); + Semaphore_post(keepAliveSem); // send_wdt_cmd(); } } else { @@ -141,78 +140,81 @@ Void watchdog_call(UArg arg0) } /***************************************************************************** - * watchdog_process_msg : Sets the watchdog_cmd_received variable. So next clock + * keepalive_process_msg : Sets the keepalive_cmd_received variable. So next clock * tick at 10msec will be able to reset the local_counter * and respond back with "reply". *****************************************************************************/ -void watchdog_process_msg(OCMPMessageFrame *pWatchdogMsg) +void keepalive_process_msg(OCMPMessageFrame *pKeepAliveMsg) { - if (pWatchdogMsg->message.msgtype == OCMP_MSG_TYPE_CONFIG) { - // set_config_watchdog(pWatchdogMsg); - pWatchdogMsg->message.action = OCMP_AXN_TYPE_REPLY; - watchdog_send_messages(pWatchdogMsg); - } else if (pWatchdogMsg->message.msgtype == OCMP_MSG_TYPE_STATUS) { + if (pKeepAliveMsg->message.msgtype == OCMP_MSG_TYPE_CONFIG) { + // set_config_watchdog(pKeepAliveMsg); + pKeepAliveMsg->message.action = OCMP_AXN_TYPE_REPLY; + keepAlive_send_messages(pKeepAliveMsg); + } else if (pKeepAliveMsg->message.msgtype == OCMP_MSG_TYPE_STATUS) { watchdogCmdReceived = 1; - free((uint8_t *)pWatchdogMsg); + free((uint8_t *)pKeepAliveMsg); } } /***************************************************************************** - * watchdog_task_init : Function initializes the IPC objects for Watchdog task + * keepalive_task_init : Function initializes the IPC objects for Watchdog task *****************************************************************************/ -void watchdog_task_init(void) +void keepalive_task_init(void) { /* Create Semaphore for RX Watchdog Message Queue */ - watchdogSem = Semaphore_create(0, NULL, NULL); - if (watchdogSem == NULL) + keepAliveSem = Semaphore_create(0, NULL, NULL); + if (keepAliveSem == NULL) LOGGER_DEBUG( "WATCHDOG:ERROR:: Failed in Creating Watchdog Semaphore.\n"); /* Create Wathcdog control Queue used by Big brother */ - watchdogMsgQueue = Queue_create(NULL, NULL); - if (watchdogMsgQueue == NULL) + keepAliveMsgQueue = Queue_create(NULL, NULL); + if (keepAliveMsgQueue == NULL) LOGGER_DEBUG( "WATCHDOG:ERROR:: Failed in Constructing Watchdog Message Queue.\n"); } /***************************************************************************** - * watchdog_task_fxn : Handles Watchdog Module + * keepalive_task_fxn : Handles Watchdog Module *****************************************************************************/ -void watchdog_task_fxn(UArg a0, UArg a1) +void keepalive_task_fxn(UArg a0, UArg a1) { - watchdog_task_init(); + keepalive_task_init(); + Task_Handle task_handle = Task_self(); // Clock_start(watchdog); while (1) { - if (Semaphore_pend(watchdogSem, BIOS_WAIT_FOREVER)) { - if (!Queue_empty(watchdogMsgQueue)) { - OCMPMessageFrame *pWatchdogMsg = - (OCMPMessageFrame *)Util_dequeueMsg(watchdogMsgQueue); + if (Semaphore_pend(keepAliveSem, OC_TASK_WAIT_TIME)) { + if (!Queue_empty(keepAliveMsgQueue)) { + OCMPMessageFrame *pKeepAliveMsg = + (OCMPMessageFrame *)Util_dequeueMsg(keepAliveMsgQueue); - if (pWatchdogMsg) { - watchdog_process_msg(pWatchdogMsg); + if (pKeepAliveMsg) { + keepalive_process_msg(pKeepAliveMsg); } } else { - watchdog_send_cmd_message(); + keepalive_send_cmd_message(); } } + wd_kick(task_handle); } } /***************************************************************************** - * watchdog_create_task : Creates task for Watchdog + * keep_alive_create_task : Creates task for Watchdog *****************************************************************************/ -void watchdog_create_task(void) +void keep_alive_create_task(void) { Task_Params taskParams; Task_Params_init(&taskParams); - taskParams.stack = WatchdogTaskStack; - taskParams.stackSize = WATCHDOG_TASK_STACK_SIZE; - taskParams.priority = WATCHDOG_TASK_PRIORITY; + taskParams.instance->name = "KeepAlive_t"; + taskParams.stack = keepAliveTaskStack; + taskParams.stackSize = KEEPALIVE_TASK_STACK_SIZE; + taskParams.priority = KEEPALIVE_TASK_PRIORITY; + Util_create_task(&taskParams, &keepalive_task_fxn, true); + //Task_construct(&keepAliveTask, watchdog_task_fxn, &taskParams, NULL); - Task_construct(&WatchdogTask, watchdog_task_fxn, &taskParams, NULL); - - LOGGER_DEBUG("WATCHDOG:INFO:: Creating Watchdog Task.\n"); + LOGGER_DEBUG("HEALTH:INFO:: Creating Watchdog Task.\n"); } diff --git a/firmware/ec/src/subsystem/rffe/rffe_powermonitor.c b/firmware/ec/src/subsystem/rffe/rffe_powermonitor.c index 8b8d8520c3..ed7faa492d 100644 --- a/firmware/ec/src/subsystem/rffe/rffe_powermonitor.c +++ b/firmware/ec/src/subsystem/rffe/rffe_powermonitor.c @@ -212,11 +212,13 @@ void rffe_powermonitor_createtask(void) Task_Params taskParams; /* Configure RF Power Monitor task */ Task_Params_init(&taskParams); + taskParams.instance->name = "RFFEPwrMonitor_t"; taskParams.stack = rffePowerMonitorTaskStack; taskParams.stackSize = RFFEPOWERMONITOR_TASK_STACK_SIZE; taskParams.priority = RFFEPOWERMONITOR_TASK_PRIORITY; - Task_construct(&rffePowerMonitorTask, rffe_powermonitor_task_fxn, - &taskParams, NULL); + Util_create_task(&taskParams, &rffe_powermonitor_task_fxn, true); + //Task_construct(&rffePowerMonitorTask, rffe_powermonitor_task_fxn, + // &taskParams, NULL); DEBUG("RFPOWERMONITOR:INFO:: Creating a RF FE Power Monitoring Task.\n"); } diff --git a/firmware/ec/src/subsystem/sync/sync.c b/firmware/ec/src/subsystem/sync/sync.c index 47d383e3e6..251942b4dc 100644 --- a/firmware/ec/src/subsystem/sync/sync.c +++ b/firmware/ec/src/subsystem/sync/sync.c @@ -108,10 +108,11 @@ static void SYNC_GpsTaskInit(void) /* Create a task */ Task_Params taskParams; Task_Params_init(&taskParams); + taskParams.instance->name="SYNCGPS_t"; taskParams.stack = syncGpsTaskStack; taskParams.stackSize = SYNC_GPS_TASK_STACK_SIZE; taskParams.priority = SYNC_GPS_TASK_PRIORITY; - Task_Handle task = Task_create(SYNC_GpsTaskFxn, &taskParams, NULL); + bool task = Util_create_task(&taskParams, &SYNC_GpsTaskFxn, false); if (!task) { DEBUG("SYNC::FATAL: Unable to start Gps Polling task\n"); Semaphore_delete(&gpsSem); diff --git a/firmware/ec/src/subsystem/sys/sys.c b/firmware/ec/src/subsystem/sys/sys.c index f7f4fde7ae..0638687eba 100644 --- a/firmware/ec/src/subsystem/sys/sys.c +++ b/firmware/ec/src/subsystem/sys/sys.c @@ -145,6 +145,11 @@ bool SYS_post_get_results(void **getpostResult) "BIGBROTHER:ERROR:: Failed to allocate memory for POST results.\n"); } memcpy(((OCMPMessageFrame *)getpostResult), postResultMsg, 64); + SysCtlDelay(100); + if(postResultMsg) { + /* Free memory which was allocated for post frame.*/ + free(postResultMsg); + } return status; } @@ -196,11 +201,12 @@ bool sys_post_init(void *driver, void *returnValue) Task_Params_init(&taskParams); taskParams.stackSize = OCFS_TASK_STACK_SIZE; taskParams.stack = &ocFSTaskStack; - taskParams.instance->name = "FS_TASK"; + taskParams.instance->name = "FileSys_t"; taskParams.priority = OCFS_TASK_PRIORITY; taskParams.arg0 = (UArg)driver; taskParams.arg1 = (UArg)returnValue; - Task_construct(&ocFSTask, fs_wrapper_fileSystem_init, &taskParams, NULL); + Util_create_task(&taskParams, &fs_wrapper_fileSystem_init, true); + //Task_construct(&ocFSTask, fs_wrapper_fileSystem_init, &taskParams, NULL); LOGGER_DEBUG("FS:INFO:: Creating filesystem task function.\n"); return true; } diff --git a/firmware/ec/src/utils/oc_watchdog.c b/firmware/ec/src/utils/oc_watchdog.c new file mode 100644 index 0000000000..d37edb78f2 --- /dev/null +++ b/firmware/ec/src/utils/oc_watchdog.c @@ -0,0 +1,201 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#include +#include +#include + +#include "inc/hw_types.h" +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "inc/utils/oc_watchdog.h" + +UInt g_events; +uint32_t g_reqEvents = 0x0000; +static uint8_t intInterval = 1; +static uint32_t testcount = 1; + +Event_Handle WD_Event; +Error_Block eb; + +#define MAX_WD_TIME_OUT (0xFFFFFFFF) /*35 seconds*/ +#define SET_EVENT(x) ((1<<(x))| g_events) + +Task_Struct wdTask; +Char wdTaskStack[WD_TASK_STACK_SIZE]; + +Semaphore_Handle semWDRx; + +extern ocTask_t ocTask[MAX_TASK_LIMIT]; + +void WatchdogIntHandler(void) +{ + /* If Watchdog Interrupt is created */ + if(WatchdogIntStatus(WATCHDOG0_BASE, true)) { + /* Watchdog interval is of 35 seconds * 4 */ + /* For first three intervals (1-2-3)Watchdog will be feed automatically */ + /* For every fourth interval Watchdog will check the status for tasks*/ + if((intInterval%5)==0) { + /* What events Should I expect.*/ + uint32_t expectedEvents = Util_get_wd_req_evets(); + if(g_events == expectedEvents) { + /*Feed watchdog*/ + WatchdogIntClear(WATCHDOG0_BASE); + /*Clear counters*/ + g_events = 0x0000; + intInterval = 1; + } else { + /* Giving soft reset to device.*/ + SysCtlReset(); + } + } else { + /*Feed Watchdog without checks*/ + /*This is to give enough free time for EC tasks 4*35 seconds*/ + WatchdogIntClear(WATCHDOG0_BASE); + intInterval++; + } + testcount++; + } +} + +/***************************************************************************** + ** FUNCTION NAME : wd_task_init + ** + ** DESCRIPTION : Initializes the pre-requisites for Watchdog. + ** + ** ARGUMENTS : None + ** + ** RETURN TYPE : None + ** + *****************************************************************************/ +static void wd_task_init(void) +{ + /* Create Semaphore for RX Message Queue */ + semWDRx = Semaphore_create(0, NULL, NULL); + + /* using events for intererupt*/ + /* create an Event object. All events are binary */ + WD_Event = Event_create(NULL, &eb); + if (WD_Event == NULL) { + LOGGER_DEBUG("WD Event creation failed."); + } +} + +/***************************************************************************** + ** FUNCTION NAME : wd_hw_init + ** + ** DESCRIPTION : Initializes the hardware for Watchdog. + ** + ** ARGUMENTS : None + ** + ** RETURN TYPE : None + ** + *****************************************************************************/ +void wd_hw_init() +{ + /* Enable watchdog 0 */ + SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0); + + /*Enable watchdog interrupt*/ + IntEnable(INT_WATCHDOG); + + /* Watch dog period*/ + WatchdogReloadSet(WATCHDOG0_BASE,MAX_WD_TIME_OUT); + + /*Enable reset generation from the watchdog timer.*/ + WatchdogResetEnable(WATCHDOG0_BASE); + + /* Set debug stall mode */ + WatchdogStallEnable(WATCHDOG0_BASE); + + /*Enable the watchdog timer.*/ + WatchdogEnable(WATCHDOG0_BASE); + + /* Interrupt call back is set in the RTOS CFG. */ +} +/***************************************************************************** + ** FUNCTION NAME : wd_taskfxn + ** + ** DESCRIPTION : handles the health state for all tasks. + ** + ** ARGUMENTS : None + ** + ** RETURN TYPE : None + ** + *****************************************************************************/ +static void wd_taskfxn(UArg a0, UArg a1) +{ + uint32_t event =0x0000; + wd_task_init(); + + /* Initialize HW for Watchdog */ + wd_hw_init(); + + while (TRUE) { + /* Wait for ALL of the ISR events to be posted */ + /* AND mask is set. It can be altered to OR mask and we can add few more error handling per task.*/ + /*g_events = Event_pend(WD_Event, (Event_Id_00 + Event_Id_01 + Event_Id_02 + + Event_Id_01 + Event_Id_02 + Event_Id_03 + Event_Id_04 + Event_Id_05 + + Event_Id_06 + Event_Id_07 + Event_Id_08 + Event_Id_09 + Event_Id_10 + + Event_Id_11 + Event_Id_12 + Event_Id_13 + Event_Id_14 + Event_Id_15 + + Event_Id_16 + Event_Id_17 + Event_Id_18 + Event_Id_19 + Event_Id_20 + + Event_Id_21 + Event_Id_22 + Event_Id_23 + Event_Id_24 + Event_Id_25 + + Event_Id_26 + Event_Id_27 + Event_Id_28 + Event_Id_29 + Event_Id_30 + + Event_Id_31 ), Event_Id_NONE, BIOS_WAIT_FOREVER);*/ + event = Event_pend(WD_Event, Event_Id_NONE, (Event_Id_00 + Event_Id_01 + Event_Id_02 + Event_Id_03 + Event_Id_04 + Event_Id_05 + Event_Id_06 + Event_Id_07 + Event_Id_08 + Event_Id_09 + Event_Id_10 + Event_Id_11 + Event_Id_12 + Event_Id_13 + Event_Id_14 + Event_Id_15 + Event_Id_16 + Event_Id_17 + Event_Id_18), BIOS_WAIT_FOREVER); + { + /* All the tasks have reported.*/ + g_events |= event; + LOGGER_DEBUG("WATCHDOG:INFO::WD[%d] Interval %d : Collected events are 0x%08x with recent event 0x%08x.\n",testcount, intInterval, g_events, event); + } + } +} + +/***************************************************************************** + ** FUNCTION NAME : wd_createtask + ** + ** DESCRIPTION : Creates task for Watchdog + ** + ** ARGUMENTS : None + ** + ** RETURN TYPE : None + ** + *****************************************************************************/ +void wd_createtask(void) +{ + Task_Params taskParams; + // Configure task + Task_Params_init(&taskParams); + taskParams.instance->name = "Watchdog_t"; + taskParams.stack =wdTaskStack; + taskParams.stackSize = WD_TASK_STACK_SIZE; + taskParams.priority = WD_TASK_PRIORITY; + Util_create_task(&taskParams, &wd_taskfxn, false); + LOGGER_DEBUG("WATCHDOG:INFO::Creating a Watchdog task.\n"); +} + +void wd_kick(Task_Handle task) +{ +#ifdef OC_Watchdog + ocTask_t* taskEnv = (ocTask_t*)Task_getEnv(task); + Event_post(WD_Event, taskEnv->wdEventId); + LOGGER_DEBUG("WATCHDOG:INFO::Task[%s] Feed Watchdog with event 0x%x.\n",(taskEnv->task_name), (taskEnv->wdEventId)); +#endif +} + + + + diff --git a/firmware/ec/src/utils/swupdate.c b/firmware/ec/src/utils/swupdate.c index b07993e09c..53679572c3 100644 --- a/firmware/ec/src/utils/swupdate.c +++ b/firmware/ec/src/utils/swupdate.c @@ -198,9 +198,10 @@ static void sw_update_worker(UArg arg0, UArg arg1) struct sockaddr_in localAddr; struct sockaddr_in clientAddr; socklen_t addrlen; - + struct timeval timeout; int8_t buffer[MPACKET_LEN]; + Task_Handle task_handle = Task_self(); server = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (server == -1) { System_printf("Error: socket not created.\n"); @@ -218,6 +219,8 @@ static void sw_update_worker(UArg arg0, UArg arg1) goto shutdown; } + timeout.tv_sec = 20; + timeout.tv_usec = 0; do { /* * readSet and addrlen are value-result arguments, which must be reset @@ -239,6 +242,7 @@ static void sw_update_worker(UArg arg0, UArg arg1) } } } + } while (status > 0); shutdown: @@ -316,9 +320,10 @@ void SoftwareUpdateInit(tSoftwareUpdateRequested pfnCallback) /* Start listening for magic packet */ Task_Params task_sw_update_Params; Task_Params_init(&task_sw_update_Params); + task_sw_update_Params.instance->name="SWUpdate_t"; task_sw_update_Params.arg0 = MPACKET_PORT; task_sw_update_Params.stackSize = 1024; - if (!Task_create(sw_update_worker, &task_sw_update_Params, NULL)) { + if (!Util_create_task(&task_sw_update_Params, &sw_update_worker, false)) { System_printf("Error: Failed to create sw update task\n"); } } diff --git a/firmware/ec/src/utils/util.c b/firmware/ec/src/utils/util.c index 62fac4248c..3e9596686e 100644 --- a/firmware/ec/src/utils/util.c +++ b/firmware/ec/src/utils/util.c @@ -48,6 +48,8 @@ #include #include +#include "inc/common/global_header.h" + /********************************************************************* * TYPEDEFS */ @@ -66,10 +68,13 @@ typedef struct _queueRec_ { * EXTERNAL VARIABLES */ +ocTask_t ocTask[MAX_TASK_LIMIT]; +extern uint32_t g_reqEvents; /********************************************************************* * LOCAL VARIABLES */ - +static wdTaskCount = 0; +static ocTaskCount = 0; /********************************************************************* * PUBLIC FUNCTIONS */ @@ -314,3 +319,76 @@ uint8_t *Util_dequeueMsg(Queue_Handle msgQueue) return NULL; } + +bool Util_create_task(Task_Params* taskParams, Task_FuncPtr taskFxn, bool monitoring) +{ + bool rc = false; + Error_Block eb; + Error_init(&eb); + Task_Handle task_handle; + taskParams->env = &ocTask[ocTaskCount];//taskParams->instance->name; + task_handle = Task_create(taskFxn, taskParams, &eb); + if (task_handle == NULL) { + LOGGER_ERROR("TASK:ERROR::Failed creating task %s.\n",taskParams->instance->name); + } else { + LOGGER_DEBUG("TASK:INFO::Task %s is created.\n",taskParams->instance->name); + ocTask[ocTaskCount].sno = ocTaskCount; + ocTask[ocTaskCount].task_name = taskParams->instance->name; + ocTask[ocTaskCount].task_handle = task_handle; + ocTask[ocTaskCount].wdMonitoring = monitoring; + if(monitoring) { + /* Set WD Event for Task */ + ocTask[ocTaskCount].wdEventId = (1<instance->name,(monitoring==true?"added": "not added"),(wdTaskCount-1)); + ocTaskCount++; + rc = true; + } + return rc; +} + +int Util_get_task_serial(char* name) +{ + uint8_t iter = 0; + int serialNu = -1; + for(;iter