← Back to dashboard

File view

plcUpdate.c

1
//$Id: ismUpdate.c,v 1.1 2008-08-21 01:30:17 charlie Exp $
2
3
/*
4
  $Log: ismUpdate.c,v $
5
6
7
*/
8
9
/***************************************************************************************/
10
#memmap xmem   // Try to put as much code in xmem as possible
11
               //   By default, Dynamic C will try to fill up root code first
12
#class auto    // Local variables on the stack
13
               //   By default, Dynamic C puts local variables in the heap
14
#nointerleave  // Compile user functions before library functions
15
               //   in order to get error messages sooner
16
#define UDP_SOCKETS 4	// allow enough for downloader and DHCP
17
#define MAX_UDP_SOCKET_BUFFERS 4
18
#define TCPCONFIG 3
19
#use dcrtcp.lib
20
#define SHOW_MAC_ADDR
21
#define	STDIO_DEBUG_SERIAL	SADR
22
#define	STDIO_DEBUG_BAUD		115200l
23
#define	STDIO_DEBUG_ADDCR
24
25
#define CONNECT_FAIL -10
26
#define OPEN_FAIL -11
27
#define SHORT_READ -12
28
#define NO_FREE_SPACE -12
29
30
#define NET_DEBUG
31
// this will allow read/write support from the UPDateMgr while running user program
32
#define DLM_RW
33
#define DLM_DEBUG
34
#define DLM_VERBOSE
35
#use SHD_DLM.LIB
36
#use WEB_DL.LIB
37
const char my_id[]="EC3100";
38
39
40
int  TestWord;
41
42
43
#use  "plc_constants.lib"
44
#use  "plc_types.lib"
45
#use  "plc_utility.lib"
46
#use  "ism_inputs.lib"
47
#use  "ism_outputs.lib"
48
#use  "ism_display.lib"
49
#use  "ism_keyboard.lib"
50
#use  "ism_setup_state.lib"
51
#use  "ism_accum_state.lib"
52
#use  "ism_main_state.lib"
53
#use  "ism_battery_backup.lib"
54
#use "ism_sequencer.lib"
55
56
57
////////////////////////////////////////////////
58
//  Version
59
#define MAJOR_VERSION "0"
60
#define MINOR_VERSION "00"
61
#define VERSION_STATUS VERSION_STATUS_PRODUCTION
62
#define VERSION_STRING_MAX_LENGTH 16
63
64
#define PRODUCT_NAME_STRING " VMI 3100 MC  "
65
66
67
/////////////////////////////////////////////////
68
//  Function Prototypes
69
70
void Initialize();                   		//Initialize the program
71
72
void test();
73
void MainTask();
74
void testVersion(int pause);
75
void accumIt(char *s, char *(*dspFunc)(), char *(*accumFunc)());
76
char *VersionString();
77
78
root void _my_xexit();
79
80
////////////////////////////////////////////////
81
82
const char blank[2] = "";
83
char verString[VERSION_STRING_MAX_LENGTH + 1];
84
Configuration configuration;
85
int outputWord;
86
int inputWord;
87
char ErrorMessage[ERROR_MESSAGE_LENGTH + 1]; // global error message
88
89
////////////////////////////////////////////////
90
//  Main Program
91
92
int main()
93
{
94
  Ms bootTime;
95
  int clearChordDetected;
96
	int i;
97
	char IPAddr[4];
98
	long start;
99
	int dlRequest, oldDlRequest;
100
101
  clockDoublerOn();
102
	oldDlRequest = 1;
103
	dlRequest = 0;
104
105
  InitializeKbd(KEYSOURCE_BOTH);
106
	//  TestChord(&clearChordDetected, &machineChangeChordDetected);
107
  bootTime = MS_TIMER;
108
109
	printf("My DLM ID: %s\n", my_id);
110
	printf("\nNetwork init\n");
111
	sock_init();
112
	while (ifpending(IF_DEFAULT) == 1)
113
	{
114
		tcp_tick(NULL);
115
	}
116
	// call this before DLM_INIT to set the port if it is not the standard
117
	//	DLM_SetPort(12345);
118
	DLM_Init(my_id);
119
	// lots of useless debug info.
120
	ifconfig(IF_ETH0,IFG_IPADDR,IPAddr,IFS_END);
121
	printf("IP address=%d.%d.%d.%d\n",IPAddr[3],IPAddr[2],IPAddr[1],IPAddr[0]);
122
	printf("ETH_MTU=%d\n",ETH_MTU);
123
	printf("SEGSIZE=%x\n",RdPortI(SEGSIZE));
124
	printf("MMIDR=%x\n",RdPortI(MMIDR));
125
	printf("MECR=%x\n",RdPortI(MECR));
126
	printf("MTCR=%x\n",RdPortI(MTCR));
127
	printf("MB0CR=%x\n",MB0CRShadow);
128
	printf("MB1CR=%x\n",MB1CRShadow);
129
	printf("MB2CR=%x\n",MB2CRShadow);
130
	printf("MB3CR=%x\n",MB3CRShadow);
131
	printf("GCSR=%x\n",GCSRShadow);
132
	printf("GCSRIO=%x\n",RdPortI(GCSR));
133
	printf("STACKSEG=%x\n",RdPortI(STACKSEG));
134
	printf("DATASEG=%x\n",RdPortI(DATASEG));
135
	printf("RAMCS=%x\n",CS_RAM);
136
	printf("Tell Boot loader we have sucesssfully started up\n");
137
	printf("Primary file#: %d\n",ffile_getPrimary());
138
	printf("Backup file#: %d\n",ffile_getBackup());
139
140
  // Initialize everything
141
142
  if (clearChordDetected)
143
  {
144
    //    ClearTestWord();
145
  }
146
  Initialize(); 	// Initialize a bunch of stuff
147
148
	MsDelay(2000);
149
	i=DLM_Reboot(UDPDNLD_MODE_RUN_OK); // this will not reboot
150
	if (i==UDPDNLD_MODE_RUN_PRIMARY)
151
	{
152
		printf("We are the primary program\n");
153
	}
154
	else
155
	{
156
		if (i==UDPDNLD_MODE_RUN_BACKUP)
157
			printf("We are the backup program.\n");
158
		else
159
			printf("DLM_Reboot(UDPDNLD_MODE_RUN_OK) returned %d\n");
160
	}
161
162
163
  MainTask();
164
}
165
166
void MainTask()
167
{
168
  Ms last;
169
  int pass;
170
  int cycleCount;
171
  int i;
172
173
  cycleCount = 1000;
174
  last = MS_TIMER;
175
  pass = 0;
176
  while (1)											// OK, here we go into the endless main loop.
177
  {
178
		tcp_tick(NULL);
179
		dlRequest = DLM_Tick();
180
		if (dlRequest != oldDlRequest)
181
		{
182
			printf("Request = %d\n", dlRequest);
183
		}
184
		oldDlRequest = dlRequest;
185
    if (++pass == cycleCount)
186
    {
187
      printf("Avg=%.3f s\n", (float)(MS_TIMER - last) / 1000 / cycleCount);
188
      last = MS_TIMER;
189
      pass = 0;
190
    }
191
    SetNow();
192
193
    KeyboardScan();
194
    InputRegScan();								// Get the active inputs
195
    MainStateHandler();
196
    HandleAlarmOutputs();
197
    WrOutputs(~outputWord);
198
  }
199
}
200
201
void Initialize()
202
{
203
	outputWord = 0;
204
	configuration.alarmWaitTime = DEFAULT_ALARM_WAIT_TIME;
205
	configuration.runningTurbinesRequired = DEFAULT_RUNNING_TURBINES_REQUIRED;
206
	configuration.runTimeout = DEFAULT_RUN_TIMEOUT;
207
	InitializeUtility();
208
	InitializeInputs();
209
	InitializeOutputs();
210
  InitializeDisplay(0);
211
  DisplayMsgCtr(PRODUCT_NAME_STRING, VersionString());
212
	defineErrorHandler(_my_xexit);
213
	InitializeKbd(KEYSOURCE_BOTH);
214
	InitializeSequencer();
215
  InitializeMainState();
216
}
217
218
219
220
221
char *VersionString()
222
{
223
	char *result;
224
225
	memset(verString, 0, VERSION_STRING_MAX_LENGTH + 1);
226
227
	if (strlen(VERSION_PREAMBLE) + strlen(MAJOR_VERSION) + strlen(".") +
228
			strlen(MINOR_VERSION) + strlen(VERSION_STATUS) <= VERSION_STRING_MAX_LENGTH)
229
	{
230
		strcat(verString, VERSION_PREAMBLE);
231
		strcat(verString, MAJOR_VERSION);
232
		strcat(verString, ".");
233
		strcat(verString, MINOR_VERSION);
234
		strcat(verString, VERSION_STATUS);
235
	}
236
237
	return verString;
238
}
239
240
241