Gas Pressure Display Updated Power control for Pressure sensor added
Dependencies: UniGraphic mbed vt100
afLib/afLib.h@0:37c8ecde13c2, 2018-02-16 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Feb 16 08:27:50 2018 +0000
- Revision:
- 0:37c8ecde13c2
control PSE530 power via PTC5 (pse530_en)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:37c8ecde13c2 | 1 | /** |
Rhyme | 0:37c8ecde13c2 | 2 | * Copyright 2015 Afero, Inc. |
Rhyme | 0:37c8ecde13c2 | 3 | * |
Rhyme | 0:37c8ecde13c2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rhyme | 0:37c8ecde13c2 | 5 | * you may not use this file except in compliance with the License. |
Rhyme | 0:37c8ecde13c2 | 6 | * You may obtain a copy of the License at |
Rhyme | 0:37c8ecde13c2 | 7 | * |
Rhyme | 0:37c8ecde13c2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rhyme | 0:37c8ecde13c2 | 9 | * |
Rhyme | 0:37c8ecde13c2 | 10 | * Unless required by applicable law or agreed to in writing, software |
Rhyme | 0:37c8ecde13c2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rhyme | 0:37c8ecde13c2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rhyme | 0:37c8ecde13c2 | 13 | * See the License for the specific language governing permissions and |
Rhyme | 0:37c8ecde13c2 | 14 | * limitations under the License. |
Rhyme | 0:37c8ecde13c2 | 15 | */ |
Rhyme | 0:37c8ecde13c2 | 16 | |
Rhyme | 0:37c8ecde13c2 | 17 | #ifndef AFLIB_H__ |
Rhyme | 0:37c8ecde13c2 | 18 | #define AFLIB_H__ |
Rhyme | 0:37c8ecde13c2 | 19 | |
Rhyme | 0:37c8ecde13c2 | 20 | #include "mbed.h" |
Rhyme | 0:37c8ecde13c2 | 21 | #include "iafLib.h" |
Rhyme | 0:37c8ecde13c2 | 22 | #include "SPI.h" |
Rhyme | 0:37c8ecde13c2 | 23 | #include "Command.h" |
Rhyme | 0:37c8ecde13c2 | 24 | #include "StatusCommand.h" |
Rhyme | 0:37c8ecde13c2 | 25 | #include "afSPI.h" |
Rhyme | 0:37c8ecde13c2 | 26 | // #include "WatchDogWrapper.hpp" |
Rhyme | 0:37c8ecde13c2 | 27 | |
Rhyme | 0:37c8ecde13c2 | 28 | #define STATE_IDLE 0 |
Rhyme | 0:37c8ecde13c2 | 29 | #define STATE_STATUS_SYNC 1 |
Rhyme | 0:37c8ecde13c2 | 30 | #define STATE_STATUS_ACK 3 |
Rhyme | 0:37c8ecde13c2 | 31 | #define STATE_SEND_BYTES 4 |
Rhyme | 0:37c8ecde13c2 | 32 | #define STATE_RECV_BYTES 5 |
Rhyme | 0:37c8ecde13c2 | 33 | #define STATE_CMD_COMPLETE 6 |
Rhyme | 0:37c8ecde13c2 | 34 | |
Rhyme | 0:37c8ecde13c2 | 35 | #define SPI_FRAME_LEN 16 |
Rhyme | 0:37c8ecde13c2 | 36 | |
Rhyme | 0:37c8ecde13c2 | 37 | #define REQUEST_QUEUE_SIZE 10 |
Rhyme | 0:37c8ecde13c2 | 38 | |
Rhyme | 0:37c8ecde13c2 | 39 | typedef struct { |
Rhyme | 0:37c8ecde13c2 | 40 | uint8_t messageType; |
Rhyme | 0:37c8ecde13c2 | 41 | uint16_t attrId; |
Rhyme | 0:37c8ecde13c2 | 42 | uint8_t requestId; |
Rhyme | 0:37c8ecde13c2 | 43 | uint16_t valueLen; |
Rhyme | 0:37c8ecde13c2 | 44 | uint8_t *p_value; |
Rhyme | 0:37c8ecde13c2 | 45 | } request_t; |
Rhyme | 0:37c8ecde13c2 | 46 | |
Rhyme | 0:37c8ecde13c2 | 47 | class afLib : public iafLib { |
Rhyme | 0:37c8ecde13c2 | 48 | public: |
Rhyme | 0:37c8ecde13c2 | 49 | afLib(PinName mcuInterrupt, isr isrWrapper, |
Rhyme | 0:37c8ecde13c2 | 50 | onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI); |
Rhyme | 0:37c8ecde13c2 | 51 | //wsugi 20161128 |
Rhyme | 0:37c8ecde13c2 | 52 | ~afLib(); |
Rhyme | 0:37c8ecde13c2 | 53 | //wsugi 20161128 |
Rhyme | 0:37c8ecde13c2 | 54 | |
Rhyme | 0:37c8ecde13c2 | 55 | // motoo tanaka 20171116 |
Rhyme | 0:37c8ecde13c2 | 56 | virtual int getRequestId(void) ; |
Rhyme | 0:37c8ecde13c2 | 57 | // motoo tanaka 20171116 |
Rhyme | 0:37c8ecde13c2 | 58 | // motoo tanaka 20171229 |
Rhyme | 0:37c8ecde13c2 | 59 | virtual void disable_irq(void) { fco.disable_irq() ; } |
Rhyme | 0:37c8ecde13c2 | 60 | virtual void enable_irq(void) { fco.enable_irq() ; } |
Rhyme | 0:37c8ecde13c2 | 61 | |
Rhyme | 0:37c8ecde13c2 | 62 | virtual void loop(void); |
Rhyme | 0:37c8ecde13c2 | 63 | |
Rhyme | 0:37c8ecde13c2 | 64 | virtual int getAttribute(const uint16_t attrId); |
Rhyme | 0:37c8ecde13c2 | 65 | |
Rhyme | 0:37c8ecde13c2 | 66 | virtual int setAttributeBool(const uint16_t attrId, const bool value); |
Rhyme | 0:37c8ecde13c2 | 67 | |
Rhyme | 0:37c8ecde13c2 | 68 | virtual int setAttribute8(const uint16_t attrId, const int8_t value); |
Rhyme | 0:37c8ecde13c2 | 69 | |
Rhyme | 0:37c8ecde13c2 | 70 | virtual int setAttribute16(const uint16_t attrId, const int16_t value); |
Rhyme | 0:37c8ecde13c2 | 71 | |
Rhyme | 0:37c8ecde13c2 | 72 | virtual int setAttribute32(const uint16_t attrId, const int32_t value); |
Rhyme | 0:37c8ecde13c2 | 73 | |
Rhyme | 0:37c8ecde13c2 | 74 | virtual int setAttribute64(const uint16_t attrId, const int64_t value); |
Rhyme | 0:37c8ecde13c2 | 75 | |
Rhyme | 0:37c8ecde13c2 | 76 | virtual int setAttribute(const uint16_t attrId, const string &value); |
Rhyme | 0:37c8ecde13c2 | 77 | |
Rhyme | 0:37c8ecde13c2 | 78 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value); |
Rhyme | 0:37c8ecde13c2 | 79 | |
Rhyme | 0:37c8ecde13c2 | 80 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:37c8ecde13c2 | 81 | |
Rhyme | 0:37c8ecde13c2 | 82 | virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:37c8ecde13c2 | 83 | |
Rhyme | 0:37c8ecde13c2 | 84 | virtual bool isIdle(); |
Rhyme | 0:37c8ecde13c2 | 85 | |
Rhyme | 0:37c8ecde13c2 | 86 | virtual void mcuISR(); |
Rhyme | 0:37c8ecde13c2 | 87 | |
Rhyme | 0:37c8ecde13c2 | 88 | private: |
Rhyme | 0:37c8ecde13c2 | 89 | Timeout deathWish; |
Rhyme | 0:37c8ecde13c2 | 90 | Timer *checkLastSync; |
Rhyme | 0:37c8ecde13c2 | 91 | static void kick_the_bucket(); |
Rhyme | 0:37c8ecde13c2 | 92 | afSPI *_theSPI; |
Rhyme | 0:37c8ecde13c2 | 93 | |
Rhyme | 0:37c8ecde13c2 | 94 | //SPISettings _spiSettings; |
Rhyme | 0:37c8ecde13c2 | 95 | volatile int _interrupts_pending; |
Rhyme | 0:37c8ecde13c2 | 96 | int _state; |
Rhyme | 0:37c8ecde13c2 | 97 | uint16_t _bytesToSend; |
Rhyme | 0:37c8ecde13c2 | 98 | uint16_t _bytesToRecv; |
Rhyme | 0:37c8ecde13c2 | 99 | uint8_t _requestId; |
Rhyme | 0:37c8ecde13c2 | 100 | uint16_t _outstandingSetGetAttrId; |
Rhyme | 0:37c8ecde13c2 | 101 | |
Rhyme | 0:37c8ecde13c2 | 102 | // Application Callbacks. |
Rhyme | 0:37c8ecde13c2 | 103 | onAttributeSet _onAttrSet; |
Rhyme | 0:37c8ecde13c2 | 104 | onAttributeSetComplete _onAttrSetComplete; |
Rhyme | 0:37c8ecde13c2 | 105 | |
Rhyme | 0:37c8ecde13c2 | 106 | Command *_writeCmd; |
Rhyme | 0:37c8ecde13c2 | 107 | uint16_t _writeBufferLen; |
Rhyme | 0:37c8ecde13c2 | 108 | uint8_t *_writeBuffer; |
Rhyme | 0:37c8ecde13c2 | 109 | |
Rhyme | 0:37c8ecde13c2 | 110 | Command *_readCmd; |
Rhyme | 0:37c8ecde13c2 | 111 | uint16_t _readBufferLen; |
Rhyme | 0:37c8ecde13c2 | 112 | uint8_t *_readBuffer; |
Rhyme | 0:37c8ecde13c2 | 113 | |
Rhyme | 0:37c8ecde13c2 | 114 | int _writeCmdOffset; |
Rhyme | 0:37c8ecde13c2 | 115 | int _readCmdOffset; |
Rhyme | 0:37c8ecde13c2 | 116 | |
Rhyme | 0:37c8ecde13c2 | 117 | StatusCommand *_txStatus; |
Rhyme | 0:37c8ecde13c2 | 118 | StatusCommand *_rxStatus; |
Rhyme | 0:37c8ecde13c2 | 119 | |
Rhyme | 0:37c8ecde13c2 | 120 | request_t _request; |
Rhyme | 0:37c8ecde13c2 | 121 | request_t _requestQueue[REQUEST_QUEUE_SIZE]; |
Rhyme | 0:37c8ecde13c2 | 122 | |
Rhyme | 0:37c8ecde13c2 | 123 | #ifdef ATTRIBUTE_CLI |
Rhyme | 0:37c8ecde13c2 | 124 | int parseCommand(const char *cmd); |
Rhyme | 0:37c8ecde13c2 | 125 | #endif |
Rhyme | 0:37c8ecde13c2 | 126 | |
Rhyme | 0:37c8ecde13c2 | 127 | void sendCommand(void); |
Rhyme | 0:37c8ecde13c2 | 128 | |
Rhyme | 0:37c8ecde13c2 | 129 | void runStateMachine(void); |
Rhyme | 0:37c8ecde13c2 | 130 | |
Rhyme | 0:37c8ecde13c2 | 131 | void printState(int state); |
Rhyme | 0:37c8ecde13c2 | 132 | |
Rhyme | 0:37c8ecde13c2 | 133 | //void beginSPI(); |
Rhyme | 0:37c8ecde13c2 | 134 | |
Rhyme | 0:37c8ecde13c2 | 135 | //void endSPI(); |
Rhyme | 0:37c8ecde13c2 | 136 | |
Rhyme | 0:37c8ecde13c2 | 137 | int exchangeStatus(StatusCommand *tx, StatusCommand *rx); |
Rhyme | 0:37c8ecde13c2 | 138 | |
Rhyme | 0:37c8ecde13c2 | 139 | bool inSync(StatusCommand *tx, StatusCommand *rx); |
Rhyme | 0:37c8ecde13c2 | 140 | |
Rhyme | 0:37c8ecde13c2 | 141 | int writeStatus(StatusCommand *c); |
Rhyme | 0:37c8ecde13c2 | 142 | |
Rhyme | 0:37c8ecde13c2 | 143 | void sendBytes(); |
Rhyme | 0:37c8ecde13c2 | 144 | |
Rhyme | 0:37c8ecde13c2 | 145 | void recvBytes(); |
Rhyme | 0:37c8ecde13c2 | 146 | |
Rhyme | 0:37c8ecde13c2 | 147 | void dumpBytes(char *label, int len, uint8_t *bytes); |
Rhyme | 0:37c8ecde13c2 | 148 | |
Rhyme | 0:37c8ecde13c2 | 149 | void updateIntsPending(int amount); |
Rhyme | 0:37c8ecde13c2 | 150 | |
Rhyme | 0:37c8ecde13c2 | 151 | void queueInit(void); |
Rhyme | 0:37c8ecde13c2 | 152 | |
Rhyme | 0:37c8ecde13c2 | 153 | int queuePut(uint8_t messageType, uint8_t requestId, const uint16_t attributeId, uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:37c8ecde13c2 | 154 | |
Rhyme | 0:37c8ecde13c2 | 155 | int queueGet(uint8_t *messageType, uint8_t *requestId, uint16_t *attributeId, uint16_t *valueLen, uint8_t **value); |
Rhyme | 0:37c8ecde13c2 | 156 | |
Rhyme | 0:37c8ecde13c2 | 157 | int doGetAttribute(uint8_t requestId, uint16_t attrId); |
Rhyme | 0:37c8ecde13c2 | 158 | |
Rhyme | 0:37c8ecde13c2 | 159 | int doSetAttribute(uint8_t requestId, uint16_t attrId, uint16_t valueLen, uint8_t *value); |
Rhyme | 0:37c8ecde13c2 | 160 | |
Rhyme | 0:37c8ecde13c2 | 161 | int doUpdateAttribute(uint8_t requestId, uint16_t attrId, uint8_t status, uint16_t valueLen, uint8_t *value); |
Rhyme | 0:37c8ecde13c2 | 162 | |
Rhyme | 0:37c8ecde13c2 | 163 | void onStateIdle(void); |
Rhyme | 0:37c8ecde13c2 | 164 | void onStateSync(void); |
Rhyme | 0:37c8ecde13c2 | 165 | void onStateAck(void); |
Rhyme | 0:37c8ecde13c2 | 166 | void onStateSendBytes(void); |
Rhyme | 0:37c8ecde13c2 | 167 | void onStateRecvBytes(void); |
Rhyme | 0:37c8ecde13c2 | 168 | void onStateCmdComplete(void); |
Rhyme | 0:37c8ecde13c2 | 169 | void printTransaction(uint8_t *rbytes, int len); |
Rhyme | 0:37c8ecde13c2 | 170 | InterruptIn fco; |
Rhyme | 0:37c8ecde13c2 | 171 | }; |
Rhyme | 0:37c8ecde13c2 | 172 | |
Rhyme | 0:37c8ecde13c2 | 173 | #endif // AFLIB_H__ |