WizziCom Modem command handling library.
WizziComModem.h@0:e3f3d9ec19fb, 2017-05-09 (annotated)
- Committer:
- Jeej
- Date:
- Tue May 09 13:47:00 2017 +0000
- Revision:
- 0:e3f3d9ec19fb
WizziCom Modem command handling library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeej | 0:e3f3d9ec19fb | 1 | #ifndef _WIZZI_MODEM_H_ |
Jeej | 0:e3f3d9ec19fb | 2 | #define _WIZZI_MODEM_H_ |
Jeej | 0:e3f3d9ec19fb | 3 | |
Jeej | 0:e3f3d9ec19fb | 4 | #include "mbed.h" |
Jeej | 0:e3f3d9ec19fb | 5 | #include "rtos.h" |
Jeej | 0:e3f3d9ec19fb | 6 | #include "WizziCom.h" |
Jeej | 0:e3f3d9ec19fb | 7 | #include "WizziDebug.h" |
Jeej | 0:e3f3d9ec19fb | 8 | |
Jeej | 0:e3f3d9ec19fb | 9 | #define TYPEDEF_STRUCT_PACKED typedef struct __attribute__((packed)) |
Jeej | 0:e3f3d9ec19fb | 10 | |
Jeej | 0:e3f3d9ec19fb | 11 | |
Jeej | 0:e3f3d9ec19fb | 12 | typedef enum { |
Jeej | 0:e3f3d9ec19fb | 13 | WM_ERR_NONE = 0, |
Jeej | 0:e3f3d9ec19fb | 14 | WM_ERR_NOT_READY = 1, |
Jeej | 0:e3f3d9ec19fb | 15 | WM_ERR_COM_LINK = 2, |
Jeej | 0:e3f3d9ec19fb | 16 | WM_ERR_ILLEGAL_FID = 3, |
Jeej | 0:e3f3d9ec19fb | 17 | WM_ERR_ILLEGAL_FILE_DEF = 4, |
Jeej | 0:e3f3d9ec19fb | 18 | |
Jeej | 0:e3f3d9ec19fb | 19 | WM_ERR_UNKNOWN = 0xff |
Jeej | 0:e3f3d9ec19fb | 20 | } wm_error_code_t; |
Jeej | 0:e3f3d9ec19fb | 21 | |
Jeej | 0:e3f3d9ec19fb | 22 | typedef union { |
Jeej | 0:e3f3d9ec19fb | 23 | uint32_t w; |
Jeej | 0:e3f3d9ec19fb | 24 | struct { |
Jeej | 0:e3f3d9ec19fb | 25 | uint32_t cause : 8; |
Jeej | 0:e3f3d9ec19fb | 26 | uint32_t rfu : 8; |
Jeej | 0:e3f3d9ec19fb | 27 | uint32_t nb_boot :16; |
Jeej | 0:e3f3d9ec19fb | 28 | } bf; |
Jeej | 0:e3f3d9ec19fb | 29 | } boot_status_t; |
Jeej | 0:e3f3d9ec19fb | 30 | |
Jeej | 0:e3f3d9ec19fb | 31 | typedef struct { |
Jeej | 0:e3f3d9ec19fb | 32 | union { |
Jeej | 0:e3f3d9ec19fb | 33 | uint8_t b[8]; |
Jeej | 0:e3f3d9ec19fb | 34 | uint32_t w[2]; |
Jeej | 0:e3f3d9ec19fb | 35 | } uid; |
Jeej | 0:e3f3d9ec19fb | 36 | uint8_t calib; |
Jeej | 0:e3f3d9ec19fb | 37 | } wm_status_t; |
Jeej | 0:e3f3d9ec19fb | 38 | |
Jeej | 0:e3f3d9ec19fb | 39 | |
Jeej | 0:e3f3d9ec19fb | 40 | TYPEDEF_STRUCT_PACKED { |
Jeej | 0:e3f3d9ec19fb | 41 | uint8_t fid; |
Jeej | 0:e3f3d9ec19fb | 42 | uint8_t type; |
Jeej | 0:e3f3d9ec19fb | 43 | uint8_t afid; |
Jeej | 0:e3f3d9ec19fb | 44 | uint8_t ifid; |
Jeej | 0:e3f3d9ec19fb | 45 | uint8_t prop; |
Jeej | 0:e3f3d9ec19fb | 46 | uint8_t perm; |
Jeej | 0:e3f3d9ec19fb | 47 | uint32_t size; |
Jeej | 0:e3f3d9ec19fb | 48 | uint32_t alloc; |
Jeej | 0:e3f3d9ec19fb | 49 | } register_file_param_t; |
Jeej | 0:e3f3d9ec19fb | 50 | |
Jeej | 0:e3f3d9ec19fb | 51 | typedef union { |
Jeej | 0:e3f3d9ec19fb | 52 | uint32_t w; |
Jeej | 0:e3f3d9ec19fb | 53 | struct { |
Jeej | 0:e3f3d9ec19fb | 54 | uint32_t fid : 8; |
Jeej | 0:e3f3d9ec19fb | 55 | uint32_t offset : 12; |
Jeej | 0:e3f3d9ec19fb | 56 | uint32_t size : 12; |
Jeej | 0:e3f3d9ec19fb | 57 | } bf; |
Jeej | 0:e3f3d9ec19fb | 58 | } notify_file_param_t; |
Jeej | 0:e3f3d9ec19fb | 59 | |
Jeej | 0:e3f3d9ec19fb | 60 | class WizziComModem { |
Jeej | 0:e3f3d9ec19fb | 61 | typedef void (*WizziComModemBootCallback)(boot_status_t); |
Jeej | 0:e3f3d9ec19fb | 62 | typedef void (*WizziComModemErrorCallback)(int8_t); |
Jeej | 0:e3f3d9ec19fb | 63 | |
Jeej | 0:e3f3d9ec19fb | 64 | private: |
Jeej | 0:e3f3d9ec19fb | 65 | WizziCom* _com; |
Jeej | 0:e3f3d9ec19fb | 66 | PinName _reset_pin; |
Jeej | 0:e3f3d9ec19fb | 67 | Semaphore _modem_ready; |
Jeej | 0:e3f3d9ec19fb | 68 | Callback<void(boot_status_t)> _boot_callback; |
Jeej | 0:e3f3d9ec19fb | 69 | Callback<void(int8_t)> _error_callback; |
Jeej | 0:e3f3d9ec19fb | 70 | |
Jeej | 0:e3f3d9ec19fb | 71 | void _modem_command(WizziCom* com, WizziComPacket_t* pkt); |
Jeej | 0:e3f3d9ec19fb | 72 | |
Jeej | 0:e3f3d9ec19fb | 73 | public: |
Jeej | 0:e3f3d9ec19fb | 74 | WizziComModem(WizziCom* com, PinName reset_pin = NC); |
Jeej | 0:e3f3d9ec19fb | 75 | ~WizziComModem(); |
Jeej | 0:e3f3d9ec19fb | 76 | |
Jeej | 0:e3f3d9ec19fb | 77 | void attach_boot(WizziComModemBootCallback function); |
Jeej | 0:e3f3d9ec19fb | 78 | |
Jeej | 0:e3f3d9ec19fb | 79 | template<class T> |
Jeej | 0:e3f3d9ec19fb | 80 | void attach_boot(T* object, void (T::*member)(boot_status_t)) |
Jeej | 0:e3f3d9ec19fb | 81 | { |
Jeej | 0:e3f3d9ec19fb | 82 | _boot_callback = callback(object, member); |
Jeej | 0:e3f3d9ec19fb | 83 | } |
Jeej | 0:e3f3d9ec19fb | 84 | |
Jeej | 0:e3f3d9ec19fb | 85 | void attach_error(WizziComModemErrorCallback function); |
Jeej | 0:e3f3d9ec19fb | 86 | |
Jeej | 0:e3f3d9ec19fb | 87 | template<class T> |
Jeej | 0:e3f3d9ec19fb | 88 | void attach_error(T* object, void (T::*member)(boot_status_t)) |
Jeej | 0:e3f3d9ec19fb | 89 | { |
Jeej | 0:e3f3d9ec19fb | 90 | _error_callback = callback(object, member); |
Jeej | 0:e3f3d9ec19fb | 91 | } |
Jeej | 0:e3f3d9ec19fb | 92 | |
Jeej | 0:e3f3d9ec19fb | 93 | void start_dash7(void); |
Jeej | 0:e3f3d9ec19fb | 94 | void stop_dash7(void); |
Jeej | 0:e3f3d9ec19fb | 95 | void software_reset(void); |
Jeej | 0:e3f3d9ec19fb | 96 | void hardware_reset(void); |
Jeej | 0:e3f3d9ec19fb | 97 | }; |
Jeej | 0:e3f3d9ec19fb | 98 | |
Jeej | 0:e3f3d9ec19fb | 99 | #endif |