示例#1
0
/*********************************************************************
 * @fn      Util_rescheduleClock
 *
 * @brief   Reschedule a clock by changing the timeout and period values.
 *
 * @param   pClock - pointer to clock struct
 * @param   clockPeriod - longevity of clock timer in milliseconds
 * @return  none
 */
void Util_rescheduleClock(Clock_Struct *pClock, uint32_t clockPeriod)
{
  bool running;
  uint32_t clockTicks;
  Clock_Handle handle;

  handle = Clock_handle(pClock);
  running = Clock_isActive(handle);

  if (running)
  {
    Clock_stop(handle);
  }

  // Convert period in milliseconds to ticks.
  clockTicks = clockPeriod * (1000 / Clock_tickPeriod);

  Clock_setTimeout(handle, clockTicks);
  Clock_setPeriod(handle, clockTicks);

  if (running)
  {
    Clock_start(handle);
  }
}
示例#2
0
static Int32 IpcFramesInLink_startPrdObj(IpcFramesInLink_Obj * pObj, UInt period,
                                       Bool oneShotMode)
{

    UTILS_assert(pObj->prd.clkHandle != NULL);

    if (FALSE == pObj->prd.clkStarted)
    {
        if (TRUE == oneShotMode)
        {
            Clock_setPeriod(pObj->prd.clkHandle, 0);
        }
        else
        {
            Clock_setPeriod(pObj->prd.clkHandle, period);
        }
        Clock_setTimeout(pObj->prd.clkHandle, period);
        Clock_start(pObj->prd.clkHandle);
        pObj->prd.clkStarted = TRUE;
    }

    return IPC_FRAMES_IN_LINK_S_SUCCESS;
}
示例#3
0
static Int32 IpcFramesInLink_reconfigPrdObj(IpcFramesInLink_Obj * pObj, UInt period)
{

    UTILS_assert(pObj->prd.clkHandle != NULL);

    if (TRUE == pObj->prd.clkStarted)
    {
        Clock_stop(pObj->prd.clkHandle);
    }
    Clock_setPeriod(pObj->prd.clkHandle, 0);
    Clock_setTimeout(pObj->prd.clkHandle, period);
    Clock_start(pObj->prd.clkHandle);
    return IPC_FRAMES_IN_LINK_S_SUCCESS;
}
示例#4
0
/*
 *  ======== tcpHandler ========
 *  Creates new Task to handle new TCP connections.
 */
Void tcpHandler(UArg arg0, UArg arg1) {
	task_Event = AM_Join;
	unsigned char Join_Flag;
	unsigned char *RTC_Result;
	//unsigned char Link_Flag;
	UINT16 Link_Time;
	char *temp;
	int i = 0;
	int JB_Table_Index;
	int PV_Value_Head;
	TaskSleep(5000);	//wait 5 seconds for DHCP ready
	// Allocate the file descriptor environment for this Task
	fdOpenSession((HANDLE) Task_self());
//	network_initial();	//initial network parameter

#if 1

	//// only for alex m4 cpu register test

	int myflashtestfunciton(void);
	int DynFlashProgram(unsigned int *pui32Data, unsigned int ui32Address,
			unsigned int ui32Count);
	int DynFlashErase(unsigned int ui32Address);
	int a;
	bool connect = 1;

	a = myflashtestfunciton();
	UARTprintf("a=%d \n", a);

	uint16_t value = 0;

	//value = EMACPHYRead(0x400EC000, PHY_PHYS_ADDR, EPHY_MISR1);
	// value = EMACPHYRead(0x400EC000, PHY_PHYS_ADDR, EPHY_MISR2);

	value = EMACPHYRead(0x400EC000, 0, 0x00000010);
	UARTprintf("a=%d \n", value);

	connect = EMACSnow_isLinkUp(0);
	UARTprintf("a=%d \n", connect);




#endif
	while (1) {
		switch (task_Event) {
		case AM_Join:
			UARTprintf((const char*) "----Start AM Join (AMtoServer)----\n");
			Join_Flag = Join_Failed;
			do {
				Join_Flag = AM_JoinRequest();
				UARTprintf((const char*) "Join_Flag: %d  \n", Join_Flag);
				TaskSleep(1000);
			} while (Join_Flag != Join_Success);
			task_Event = Update_RTC;
			task_Event = TCPPeriodicLink;
			JB_DVAL = 1;
			//Create_uartHandler();
			UARTprintf((const char*) "----End AM Join (AMtoServer)----\n");
			break;

		case JB_Join:
			UARTprintf((const char*) "----Start JB Join (JBtoServer)----	\n");
			Join_Flag = Join_Failed;
			JB_Table_Index = 0;
			//error_list = fopen("MacList0.txt","w");
			while (JB_Table_Index < JB_Count) {
				if ((member_table[JB_Table_Index].state == JB_Join2AM)
						&& (member_table[JB_Table_Index].Valid > 0)) {
					Join_Flag = JB_JoinRequest(JB_Table_Index);
					if (Join_Flag == Join_Success) {
						member_table[JB_Table_Index].state = JB_Join2Server;
						//UARTprintf((const char*)"AM_Mac[%d] %x %x %x %x %x %x\n",JB_Table_Index,member_table[JB_Table_Index].MAC[5],member_table[JB_Table_Index].MAC[4],member_table[JB_Table_Index].MAC[3],member_table[JB_Table_Index].MAC[2],member_table[JB_Table_Index].MAC[1],member_table[JB_Table_Index].MAC[0]);
						JB_Table_Index++;
					} else {
						;
					}
					Join_Flag = Join_Failed;
					TaskSleep(1000);
				} else
					JB_Table_Index++;
			}
			//fclose(error_list);
			UARTprintf((const char*) "----End JB Join (JBtoServer)----	\n");
			//task_Event = PV_Periodic;
			task_Event = Nothing;
			//JB_DVAL = 1;
			break;

		case PV_Periodic:
			UARTprintf(
					(const char*) "----Start PV Periodic (JBtoServer)----	\n");
			PV_Value_Head = 0;
			while (PV_Value_Head < JB_Count) {
				PV_Value_Head = PV_Periodic_Trans(PV_Value_Head, JB_Count - 1);
				TaskSleep(1000);
			}

			task_Event = Nothing;
			//UARTprintf((const char*)"----==PV_Value_Head %d	==----\n",PV_Value_Head);
			UARTprintf((const char*) "----End PV Periodic (JBtoServer)----	\n");
			break;

		case Update_RTC:
			RTC_Result = Update_RTC_Request();
			if (RTC_Result != NULL) {
				Time_DVAL = 0;
				// RTC Setting
				AM_time.year = RTC_Result[0];
				AM_time.mon = RTC_Result[1];
				AM_time.mday = RTC_Result[2];
				AM_time.hour = RTC_Result[3];
				AM_time.min = RTC_Result[4];
				AM_time.sec = RTC_Result[5];
				free(RTC_Result);
			}
			Time_DVAL = 1;
			task_Event = Nothing;
			UARTprintf((const char*) "Time: %d/%d/%d-%d:%d:%d \n", AM_time.year,
					AM_time.mon, AM_time.mday, AM_time.hour, AM_time.min,
					AM_time.sec);
			Create_uartHandler();

			UARTprintf((const char*) "Old_IP=");
			for (i = 0; i < 4; i++)
				UARTprintf((const char*) ":%d", G_ENVCONFIG.IP[i]);
			UARTprintf((const char*) "\n");

			UARTprintf((const char*) "Old_SN=");
			for (i = 0; i < 8; i++)
				UARTprintf((const char*) ":%d", G_ENVCONFIG.SeriesNumber[i]);
			UARTprintf((const char*) "\n");

			UARTprintf((const char*) "Old_Polling_Time=");
			for (i = 0; i < 2; i++)
				UARTprintf((const char*) ":%d", G_ENVCONFIG.Pollingtime[i]);
			UARTprintf((const char*) "\n");

			UARTprintf((const char*) "Old_MAC=");
			for (i = 0; i < 6; i++)
				UARTprintf((const char*) ":%x", G_ENVCONFIG.Mac[i]);
			UARTprintf((const char*) "\n");

			break;

		case TCPPeriodicLink:
			Time_DVAL = 0;
			//Link_Flag = TCP_Periodic_Link();
			TCP_Periodic_Link();
			//task_Event = Nothing;
			//Time_DVAL = 1;
			task_Event = Update_RTC;
			break;

		case Environment:
			Rewrite_Environment();
			UARTprintf((const char*) "New_IP=");
			for (i = 0; i < 4; i++)
				UARTprintf((const char*) ":%d", G_ENVCONFIG.IP[i]);
			UARTprintf((const char*) "\n");

			UARTprintf((const char*) "New_SN=");
			for (i = 0; i < 8; i++)
				UARTprintf((const char*) ":%d", G_ENVCONFIG.SeriesNumber[i]);
			UARTprintf((const char*) "\n");

			UARTprintf((const char*) "New_Polling_Time=");
			for (i = 0; i < 2; i++)
				UARTprintf((const char*) ":%d", G_ENVCONFIG.Pollingtime[i]);
			UARTprintf((const char*) "\n");

			UARTprintf((const char*) "New_MAC=");
			for (i = 0; i < 6; i++)
				UARTprintf((const char*) ":%x", G_ENVCONFIG.Mac[i]);
			UARTprintf((const char*) "\n");

			TCP_Periodic_Link_time.Updata_Period[1] =
					G_ENVCONFIG.Pollingtime[0];
			TCP_Periodic_Link_time.Updata_Period[0] =
					G_ENVCONFIG.Pollingtime[1];

			temp = (char *) &Link_Time;
			*temp = TCP_Periodic_Link_time.Updata_Period[0];
			*(temp + 1) = TCP_Periodic_Link_time.Updata_Period[1];
			Clock_setPeriod(Periodic_Handle, Link_Time * Time_Tick);
			UARTprintf((const char*) "\n\n== Period Change : %d sec==\n\n",
					Link_Time);

			UARTprintf((const char*) "I'm new 0x80000 = %x \n", *(ptr1));
			UARTprintf((const char*) "I'm new 0x80001 = %x \n", *(ptr1 + 1));
			UARTprintf((const char*) "I'm new 0x80002 = %x \n", *(ptr1 + 2));
			UARTprintf((const char*) "I'm new 0x80003 = %x \n", *(ptr1 + 3));
			task_Event = AM_Join;
			break;

		default:
			UARTprintf((const char*) "tcpHandler Do Nothing T_T \n");
			break;

		} /*  end switch  */
		TaskSleep(7000);
	} /* end while  */
}