发表于:2002-10-17 17:39:00
3楼
#pragma app_buf_out_size 50
#pragma app_buf_out_count 1
#pragma net_buf_out_size 50
#pragma net_buf_out_count 1
#pragma app_buf_in_size 50
#pragma app_buf_in_count 5
#pragma net_buf_in_size 50
#pragma net_buf_in_count 5
////////////////////////////// Include Files ////////////////////////////////
#include <snvt_rq.h>
#include <control.h>
#include <access.h>
#include <addrdefs.h>
#include <stddef.h>
void update_nv_table(void);
void update_address_table(void);
boolean CRC_CHK(unsigned int *pt,unsigned int Msg_Len);
typedef struct {
unsigned int address;
unsigned int index;
unsigned int data[24];
}NV_commend;
//////////////////////////////// Constants //////////////////////////////////
const boolean EVER = TRUE; // avoid compiler warning
#define BUF_SIZE 256
#define MODBUS_LON_CH 01 //define modbus_lon channel code
#define SioInv 15
#define SioOver 255
#define MAX_addr 40
#define MAX_data 46
#define HEAT 30
///////////////////////////// LONMARK Objects ///////////////////////////////
network output SNVT_count nvoWrite;
network output SNVT_count nviRead ;
network output SNVT_count nvoLen ;
network input NV_commend nvi_order;
network output SNVT_count nvo_order;
/////////////////////////////////////////////////////////////////////////////
config network input SNVT_char_ascii baudBit=0x18;
config network input unsigned short StandNumber=1;
////////////////////////////////// Timers ///////////////////////////////////
mtimer repeating tmSioInv=SioInv; //= SioInv;
unsigned int read_sio_lon,write_sio_lon;
far unsigned int buf_sio_lon[BUF_SIZE]; //最大内存为7Kbyte=7168byte
far unsigned short CRC_buf[BUF_SIZE]; //CRC校验缓存区
far node_data node;
far unsigned short EU2804state[MAX_addr];
msg_tag MODBUS_ASK;
//////////////////////////// Function Prototypes ////////////////////////////
void init_comm(void);
void readSioPort(void);
/////////////////////////////// I/O Objects /////////////////////////////////
/////////////////////////////////// Tasks ///////////////////////////////////
when (reset)
{}
/////////////////////////////////////////////////////////////////////////////
when (EVER) // do this as fast as possible
{
readSioPort();
}
when (nv_update_occurs(nvi_order)){
unsigned int i;
if(nvi_order.address>=MAX_addr) return;
if(nvi_order.index==1){
for(i=0;i<22;i++) {
node.EU2804data[nvi_order.address][i]=nvi_order.data[i];
}
}
if(nvi_order.index==2){
for(i=0;i<24;i++){
node.EU2804data[nvi_order.address][i+22]=nvi_order.data[i];
}
}
}
///////////////////////////////// Functions /////////////////////////////////
void init_comm(void)
{ //initiat sio 16c550
pSio->sioLcr = 0x80;
pBaud->sioLlr = baudBit; //Baud=9600 in OSC 3.6864MHz
pBaud->sioMlr = 0x00;
pSio->sioIer = 0x00;
pSio->sioIsr = 0x01; //set FIFO mode
pSio->sioLcr = 0x03;
pSio->sioMcr = 0x03;
}
/////////////////////////////////////////////////////////////////////////////
void readSioPort(void) // do this as fast as possible
{ // read FROM sio data port TO buffer (buf_sio_lon)
while(0x1 & pSio->sioLsr){
while(0x1 & pSio->sioLsr){
buf_sio_lon[write_sio_lon++] = pSio->sioData;
}
delay(20);
watchdog_update(); //post_events();
tmSioInv = SioInv;
nvoWrite = write_sio_lon;
}
}