versadac  1
versadac - Scalable Recorder Firmware
mb_drivertask.h
1 /*****************************************************************************
2 FILE : MB_DriverTask.h
3 AUTHOR : Karl Wakeham
4 SYSTEM : GNU C++ for ARM
5 DESCRIPTION : Driver class declarations
6 *****************************************************************************/
7 
8 #ifndef __MBDRIVERTASK_H
9 #define __MBDRIVERTASK_H
10 #include "mb.h"
11 #include "fb_modbus.h"
12 
16 /* modes for factory comms */
17 #define MODMODE_NORMAL 0x00
18 #define MODMODE_TRANSFER_REQUEST 0x20
19 #define MODMODE_FCOMMS_AUTHORISED 0xC0
20 // supported factory comms commands (are always low byte = complement of high byte)
21 #define FCOMMS_TRANSFER_REQUEST 0xFFFF // prepare to allow factory comms authorisation
22 #define FCOMMS_AUTHORISE 0x13EC // factory comms authorise key
23 #define FCOMMS_MODBUS 0x00FF // normal mapping
24 #define FCOMMS_RAM 0x01FE // not used (left in for completeness)
25 #define FCOMMS_NVOL 0x02FD // not used (left in for completeness)
26 #define FCOMMS_FLASH_SEG1 0x03FC // not used (left in for completeness)
27 #define FCOMMS_FLASH_SEG2 0x04FB // not used (left in for completeness)
28 #define FCOMMS_FLASH_SEG3 0x05FA // not used (left in for completeness)
29 #define FCOMMS_FEATURES1 0x06F9 // read/write feature word 1
30 #define FCOMMS_FEATURES2 0x07F8 // read/write feature word 2
31 #define FCOMMS_FEATURES3 0x08F7 // read/write feature word 3
32 #define FCOMMS_RESET 0x11EE // reset out of factory comms
33 #define FCOMMS_DTEST_CANCEL 0x12ED // revert back to normal display
34 #define FCOMMS_DTEST1 0x12EE // turn all LED's on
35 #define FCOMMS_DTEST2 0x12EF // test display (All pixels to red)
36 #define FCOMMS_DTEST3 0x12F0 // test display (All pixels to green)
37 #define FCOMMS_DTEST4 0x12F1 // turn all LED's off
38 #define FCOMMS_COLD_START 0x10FE // cold start parameter database
39 #define FCOMMS_CLEAR_MAC_ADDR 0x10FF // clear the mac address to 00:00:00:00:00:00
40 #define FCOMMS_TELEM 0x1AE5 // allow dig o/p in config mode
41 
44 // Define the modbus map regions
45 typedef struct
46 {
47  uint16 start;
48  MB_AddressRegions region;
49  uint16 size;
50  uint8 number;
51  bool lock;
52 } modbus_map;
53 
54 class fb_modbus;
56 class MB_DataCache;
57 
58 class MB_Driver : public OSRunnableTask
59 {
60  public:
61 
62  MB_Driver(fb_modbus *fnblock, MB_ConnectionManager *connectionManager, MB_DataCache *datacache);
63  virtual ~MB_Driver();
64 
65  void runTask();
66 
67  // The following function allows direct access to data via the modbus
68  // memory map using a modbus address, but without having to actually use the modbus protocol
69  static uint8 directModbusAccess(uint16 address, uint16 *data, MB_FunctionCodes cmd);
70  static uint8 mode; //factory comms internal mode
71 
72  private:
73 
74  void processTransaction(void);
75  void createReplyHeader(void);
76  void createException(uint8 error_code);
77  void createReply(uint16 reg_count, uint8 func_code);
78  uint8 processDiagRequest(uint16 z_length);
79  void sendExchangeMessage(exchange_id xid, uint32 *pMsg);
80  uint8 getExchangeMessage(exchange_id xid, uint32 *pMsg);
81  void verbosePrintTransaction(uint8 print_type);
82  uint8 readRegister(uint16 base_address, uint16 count, uint16 data_qty, uint8 connectionNumber, uint16 *direct = NULL);
83  uint8 writeRegister(uint16 base_address, uint16 preset_hi, uint16 preset_lo, uint16 data_qty, uint16 count, uint8 connectionNumber, uint16 *direct = NULL);
84  uint8 readRegisterViaCisp(uint32 address, uint16 *count, uint16 data_qty, uint8 connectionNumber);
85  uint8 writeRegisterViaCisp(uint32 address, uint16 *preset_hi, uint16 *preset_lo, uint16 *count, uint16 data_qty, uint8 connectionNumber);
86  uint8 readFlashRegister(uint16 address);
87  uint8 writeFlashRegister(uint16 address, uint16 offset, uint16 data_qty, uint8 connectionNumber);
88  uint8 readSecurityRegister(uint16 address);
89  bool runtime_lock_required(uint16 address);
90  void factory_command(uint16 z_command);
91  uint16 get_feature_word(uint8 word);
92  uint8 set_feature_word(uint8 z_data_hi, uint8 z_data_lo, uint8 word);
93  bool is_network_TCP_protected(CISP_t z_cisp, exchange_id Xid);
94  uint8 readPublicKeyRegister(uint16 address);
95 
96 #if(0)
97  void checkCommsChannels(void);
98 #endif
99 
100  // Attributes
101  fb_modbus *m_pFnBlock;
102  MB_ConnectionManager *m_pConnectionManager;
103  MB_DataCache *m_pData;
104  uint8 *m_pReply;
105  exchange_id m_d_mbXid; // driver exchange id
106  exchange_id m_c_mbXid; //connection exchange id
107 
108 };
109 
110 #endif // __MBDRIVERTASK_H
111 
Definition: ostask.h:16
Definition: mb_manager.h:24
Definition: fb_modbus.h:20
Definition: mb_drivertask.h:58
Definition: stdtypes.h:213
Definition: mb_drivertask.h:45
Definition: mb_datacache.h:21