00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdio.h>
00016 #include "mscbemb.h"
00017 #include "Devices/Time.h"
00018 #include "Protocols/SmaRTC.h"
00019
00020
00021 unsigned char idata _n_sub_addr = 1;
00022
00023
00024 char code node_name[] = "P0DPS";
00025 char idata svn_rev_code[] = "$Rev: 959 $";
00026
00027 #define ALL_RESET 0xF
00028
00029
00030 struct {
00031 unsigned char error;
00032 unsigned char control;
00033 unsigned char status;
00034 unsigned char active;
00035 unsigned char v5mon;
00036 unsigned char v15mon;
00037 unsigned long mytime;
00038 char date[24];
00039 } xdata user_data;
00040
00041 MSCB_INFO_VAR code vars[] = {
00042
00043 1, UNIT_BYTE, 0, 0, 0, "Error", &user_data.error,
00044 1, UNIT_BYTE, 0, 0, 0, "Control", &user_data.control,
00045 1, UNIT_BYTE, 0, 0, 0, "Status", &user_data.status,
00046 1, UNIT_BYTE, 0, 0, 0, "Active", &user_data.active,
00047 1, UNIT_BYTE, 0, 0, 0, "V5_Mon", &user_data.v5mon,
00048 1, UNIT_BYTE, 0, 0, 0, "V15_Mon", &user_data.v15mon,
00049 4, UNIT_BYTE, 0, 0, MSCBF_HIDDEN, "BinDate", &user_data.mytime,
00050 24, UNIT_STRING, 0, 0, MSCBF_HIDDEN, "Date", &user_data.date[0],
00051 0
00052 };
00053
00054 MSCB_INFO_VAR *variables = vars;
00055
00056 sbit RESET_1 = P1 ^ 0;
00057 sbit RESET_2 = P1 ^ 1;
00058 sbit RESET_3 = P1 ^ 2;
00059 sbit RESET_4 = P1 ^ 3;
00060
00061 sbit V5MON_1 = P1 ^ 4;
00062 sbit V5MON_2 = P1 ^ 5;
00063 sbit V5MON_3 = P1 ^ 6;
00064 sbit V5MON_4 = P1 ^ 7;
00065
00066 sbit V15MON_1 = P2 ^ 0;
00067 sbit V15MON_2 = P2 ^ 1;
00068 sbit V15MON_3 = P2 ^ 2;
00069 sbit V15MON_4 = P2 ^ 3;
00070
00071 sbit ACTIVE_1 = P2 ^ 4;
00072 sbit ACTIVE_2 = P2 ^ 5;
00073 sbit ACTIVE_3 = P2 ^ 6;
00074 sbit ACTIVE_4 = P2 ^ 7;
00075
00076 sbit DATA_OEn = P0 ^ 3;
00077 sbit CNTRL_OEn = P0 ^ 0;
00078
00079
00080
00081
00082
00083
00084
00085 unsigned char user_func(unsigned char *data_in, unsigned char *data_out);
00086 unsigned char user_read(unsigned char index);
00087 void user_write(unsigned char index) reentrant;
00088 void PulseReset(unsigned char ch);
00089
00090
00091 void PulseReset(unsigned char ch)
00092 {
00093 if (ch == ALL_RESET) {
00094 P1 |= 0x0F;
00095 delay_us(100);
00096 P1 &= ~0x0F;
00097 } else {
00098 P1 |= (1<<ch);
00099 delay_us(100);
00100 P1 &= ~(1<<ch);
00101 }
00102
00103 }
00104
00105
00106 extern SYS_INFO sys_info;
00107
00108 void user_init (unsigned char init)
00109 {
00110 char xdata i;
00111
00112
00113 for (i = 0; i < 4; i++) {
00114 if (svn_rev_code[6 + i] < 48) {
00115 svn_rev_code[6 + i] = '0';
00116 }
00117 }
00118 sys_info.svn_revision = (svn_rev_code[6] - '0') * 1000 +
00119 (svn_rev_code[7] - '0') * 100 +
00120 (svn_rev_code[8] - '0') * 10 + (svn_rev_code[9] - '0');
00121
00122 if (init);
00123
00124
00125 sys_info.group_addr = 600;
00126
00127
00128
00129 P1MDOUT |= 0x0F;
00130 RESET_1 = RESET_2 = RESET_3 = RESET_4 = 0;
00131
00132
00133 P1MDOUT &= ~0xF0;
00134 V5MON_1 = V5MON_2 = V5MON_3 = V5MON_4 = 0;
00135
00136
00137 P2MDOUT &= ~0x0F;
00138 V15MON_1 = V15MON_2 = V15MON_3 = V15MON_4 = 0;
00139
00140
00141 P2MDOUT &= ~0xF0;
00142 ACTIVE_1 = ACTIVE_2 = ACTIVE_3 = ACTIVE_4 = 0;
00143
00144
00145 P0MDOUT &= ~0x09;
00146 DATA_OEn = CNTRL_OEn = 0;
00147
00148
00149 user_data.error = 0;
00150 user_data.control = 0;
00151 user_data.status = 0;
00152 user_data.active = 0;
00153 user_data.v5mon = 0;
00154 user_data.v15mon = 0;
00155
00156
00157 SmaRTCInit();
00158
00159 if (init) {
00160 }
00161 }
00162
00163
00164
00165 #pragma NOAREGS
00166
00167 void user_write(unsigned char index) reentrant
00168 {
00169 if (index == 1) {
00170 if (user_data.control >= 0x0F) {
00171 PulseReset(ALL_RESET);
00172 } else {
00173 if (user_data.control & 0x1) PulseReset(1);
00174 if (user_data.control & 0x2) PulseReset(2);
00175 if (user_data.control & 0x4) PulseReset(3);
00176 if (user_data.control & 0x8) PulseReset(4);
00177 }
00178 user_data.control = 0;
00179 }
00180 if (index == 6)
00181 SmaRTCSetTime(user_data.mytime);
00182 }
00183
00184
00185 unsigned char user_read(unsigned char index)
00186 {
00187 if (index);
00188 return 0;
00189 }
00190
00191
00192 unsigned char user_func(unsigned char *data_in, unsigned char *data_out)
00193 {
00194
00195 data_out[0] = data_in[0];
00196 data_out[1] = data_in[1];
00197 return 2;
00198 }
00199
00200
00201 void user_loop(void)
00202 {
00203 unsigned char v5mon, v15mon, active;
00204 unsigned long int ltime;
00205 char xdata mydate[12];
00206
00207
00208 v5mon = ((P1 & 0xF0) >> 4);
00209 v15mon = (P2 & 0x0F);
00210 active = ((P2 & 0xF0) >> 4);
00211
00212
00213 DISABLE_INTERRUPTS;
00214 user_data.v5mon = v5mon;
00215 user_data.v15mon = v15mon;
00216 user_data.active = active;
00217 ENABLE_INTERRUPTS;
00218
00219
00220 ltime = SmaRTCRead();
00221 user_data.mytime = ltime;
00222 ascTime(&mydate[0], ltime);
00223 sprintf(user_data.date, "%s", mydate);
00224
00225
00226 delay_ms(250);
00227
00228
00229 led_blink(1, 1, 250);
00230 }
00231