I2C hang recover function added
Dependencies: UniGraphic mbed vt100
In this version, check_i2c_pins function was added in edge_mgr.cpp.
プログラムの起動時、I2Cモジュールを初期化する前に、I2Cに使用するピンの電位を確認し
もし一方でも Low に張り付いていた場合、SCL を GPIO 出力に設定して
所定回数 (I2C_UNLOCK_TRIAL_CYCLE) 反転させることにより、疑似リセットクロックを生成します。
その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。
afLib/afLib.h@2:de22987be9ba, 2018-06-18 (annotated)
- Committer:
- gaku_miyagawa
- Date:
- Mon Jun 18 02:55:38 2018 +0000
- Revision:
- 2:de22987be9ba
- Parent:
- 0:d895cd1cd897
SBU SPECIAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:d895cd1cd897 | 1 | /** |
Rhyme | 0:d895cd1cd897 | 2 | * Copyright 2015 Afero, Inc. |
Rhyme | 0:d895cd1cd897 | 3 | * |
Rhyme | 0:d895cd1cd897 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rhyme | 0:d895cd1cd897 | 5 | * you may not use this file except in compliance with the License. |
Rhyme | 0:d895cd1cd897 | 6 | * You may obtain a copy of the License at |
Rhyme | 0:d895cd1cd897 | 7 | * |
Rhyme | 0:d895cd1cd897 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rhyme | 0:d895cd1cd897 | 9 | * |
Rhyme | 0:d895cd1cd897 | 10 | * Unless required by applicable law or agreed to in writing, software |
Rhyme | 0:d895cd1cd897 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rhyme | 0:d895cd1cd897 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rhyme | 0:d895cd1cd897 | 13 | * See the License for the specific language governing permissions and |
Rhyme | 0:d895cd1cd897 | 14 | * limitations under the License. |
Rhyme | 0:d895cd1cd897 | 15 | */ |
Rhyme | 0:d895cd1cd897 | 16 | |
Rhyme | 0:d895cd1cd897 | 17 | #ifndef AFLIB_H__ |
Rhyme | 0:d895cd1cd897 | 18 | #define AFLIB_H__ |
Rhyme | 0:d895cd1cd897 | 19 | |
Rhyme | 0:d895cd1cd897 | 20 | #include "mbed.h" |
Rhyme | 0:d895cd1cd897 | 21 | #include "iafLib.h" |
Rhyme | 0:d895cd1cd897 | 22 | #include "SPI.h" |
Rhyme | 0:d895cd1cd897 | 23 | #include "Command.h" |
Rhyme | 0:d895cd1cd897 | 24 | #include "StatusCommand.h" |
Rhyme | 0:d895cd1cd897 | 25 | #include "afSPI.h" |
Rhyme | 0:d895cd1cd897 | 26 | // #include "WatchDogWrapper.hpp" |
Rhyme | 0:d895cd1cd897 | 27 | |
Rhyme | 0:d895cd1cd897 | 28 | #define STATE_IDLE 0 |
Rhyme | 0:d895cd1cd897 | 29 | #define STATE_STATUS_SYNC 1 |
Rhyme | 0:d895cd1cd897 | 30 | #define STATE_STATUS_ACK 3 |
Rhyme | 0:d895cd1cd897 | 31 | #define STATE_SEND_BYTES 4 |
Rhyme | 0:d895cd1cd897 | 32 | #define STATE_RECV_BYTES 5 |
Rhyme | 0:d895cd1cd897 | 33 | #define STATE_CMD_COMPLETE 6 |
Rhyme | 0:d895cd1cd897 | 34 | |
Rhyme | 0:d895cd1cd897 | 35 | #define SPI_FRAME_LEN 16 |
Rhyme | 0:d895cd1cd897 | 36 | |
Rhyme | 0:d895cd1cd897 | 37 | #define REQUEST_QUEUE_SIZE 10 |
Rhyme | 0:d895cd1cd897 | 38 | |
Rhyme | 0:d895cd1cd897 | 39 | typedef struct { |
Rhyme | 0:d895cd1cd897 | 40 | uint8_t messageType; |
Rhyme | 0:d895cd1cd897 | 41 | uint16_t attrId; |
Rhyme | 0:d895cd1cd897 | 42 | uint8_t requestId; |
Rhyme | 0:d895cd1cd897 | 43 | uint16_t valueLen; |
Rhyme | 0:d895cd1cd897 | 44 | uint8_t *p_value; |
Rhyme | 0:d895cd1cd897 | 45 | } request_t; |
Rhyme | 0:d895cd1cd897 | 46 | |
Rhyme | 0:d895cd1cd897 | 47 | class afLib : public iafLib { |
Rhyme | 0:d895cd1cd897 | 48 | public: |
Rhyme | 0:d895cd1cd897 | 49 | afLib(PinName mcuInterrupt, isr isrWrapper, |
Rhyme | 0:d895cd1cd897 | 50 | onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI); |
Rhyme | 0:d895cd1cd897 | 51 | //wsugi 20161128 |
Rhyme | 0:d895cd1cd897 | 52 | ~afLib(); |
Rhyme | 0:d895cd1cd897 | 53 | //wsugi 20161128 |
Rhyme | 0:d895cd1cd897 | 54 | |
Rhyme | 0:d895cd1cd897 | 55 | // motoo tanaka 20171116 |
Rhyme | 0:d895cd1cd897 | 56 | virtual int getRequestId(void) ; |
Rhyme | 0:d895cd1cd897 | 57 | // motoo tanaka 20171116 |
Rhyme | 0:d895cd1cd897 | 58 | // motoo tanaka 20171229 |
Rhyme | 0:d895cd1cd897 | 59 | virtual void disable_irq(void) { fco.disable_irq() ; } |
Rhyme | 0:d895cd1cd897 | 60 | virtual void enable_irq(void) { fco.enable_irq() ; } |
Rhyme | 0:d895cd1cd897 | 61 | |
Rhyme | 0:d895cd1cd897 | 62 | virtual void loop(void); |
Rhyme | 0:d895cd1cd897 | 63 | |
Rhyme | 0:d895cd1cd897 | 64 | virtual int getAttribute(const uint16_t attrId); |
Rhyme | 0:d895cd1cd897 | 65 | |
Rhyme | 0:d895cd1cd897 | 66 | virtual int setAttributeBool(const uint16_t attrId, const bool value); |
Rhyme | 0:d895cd1cd897 | 67 | |
Rhyme | 0:d895cd1cd897 | 68 | virtual int setAttribute8(const uint16_t attrId, const int8_t value); |
Rhyme | 0:d895cd1cd897 | 69 | |
Rhyme | 0:d895cd1cd897 | 70 | virtual int setAttribute16(const uint16_t attrId, const int16_t value); |
Rhyme | 0:d895cd1cd897 | 71 | |
Rhyme | 0:d895cd1cd897 | 72 | virtual int setAttribute32(const uint16_t attrId, const int32_t value); |
Rhyme | 0:d895cd1cd897 | 73 | |
Rhyme | 0:d895cd1cd897 | 74 | virtual int setAttribute64(const uint16_t attrId, const int64_t value); |
Rhyme | 0:d895cd1cd897 | 75 | |
Rhyme | 0:d895cd1cd897 | 76 | virtual int setAttribute(const uint16_t attrId, const string &value); |
Rhyme | 0:d895cd1cd897 | 77 | |
Rhyme | 0:d895cd1cd897 | 78 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value); |
Rhyme | 0:d895cd1cd897 | 79 | |
Rhyme | 0:d895cd1cd897 | 80 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:d895cd1cd897 | 81 | |
Rhyme | 0:d895cd1cd897 | 82 | virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:d895cd1cd897 | 83 | |
Rhyme | 0:d895cd1cd897 | 84 | virtual bool isIdle(); |
Rhyme | 0:d895cd1cd897 | 85 | |
Rhyme | 0:d895cd1cd897 | 86 | virtual void mcuISR(); |
Rhyme | 0:d895cd1cd897 | 87 | |
Rhyme | 0:d895cd1cd897 | 88 | private: |
Rhyme | 0:d895cd1cd897 | 89 | Timeout deathWish; |
Rhyme | 0:d895cd1cd897 | 90 | Timer *checkLastSync; |
Rhyme | 0:d895cd1cd897 | 91 | static void kick_the_bucket(); |
Rhyme | 0:d895cd1cd897 | 92 | afSPI *_theSPI; |
Rhyme | 0:d895cd1cd897 | 93 | |
Rhyme | 0:d895cd1cd897 | 94 | //SPISettings _spiSettings; |
Rhyme | 0:d895cd1cd897 | 95 | volatile int _interrupts_pending; |
Rhyme | 0:d895cd1cd897 | 96 | int _state; |
Rhyme | 0:d895cd1cd897 | 97 | uint16_t _bytesToSend; |
Rhyme | 0:d895cd1cd897 | 98 | uint16_t _bytesToRecv; |
Rhyme | 0:d895cd1cd897 | 99 | uint8_t _requestId; |
Rhyme | 0:d895cd1cd897 | 100 | uint16_t _outstandingSetGetAttrId; |
Rhyme | 0:d895cd1cd897 | 101 | |
Rhyme | 0:d895cd1cd897 | 102 | // Application Callbacks. |
Rhyme | 0:d895cd1cd897 | 103 | onAttributeSet _onAttrSet; |
Rhyme | 0:d895cd1cd897 | 104 | onAttributeSetComplete _onAttrSetComplete; |
Rhyme | 0:d895cd1cd897 | 105 | |
Rhyme | 0:d895cd1cd897 | 106 | Command *_writeCmd; |
Rhyme | 0:d895cd1cd897 | 107 | uint16_t _writeBufferLen; |
Rhyme | 0:d895cd1cd897 | 108 | uint8_t *_writeBuffer; |
Rhyme | 0:d895cd1cd897 | 109 | |
Rhyme | 0:d895cd1cd897 | 110 | Command *_readCmd; |
Rhyme | 0:d895cd1cd897 | 111 | uint16_t _readBufferLen; |
Rhyme | 0:d895cd1cd897 | 112 | uint8_t *_readBuffer; |
Rhyme | 0:d895cd1cd897 | 113 | |
Rhyme | 0:d895cd1cd897 | 114 | int _writeCmdOffset; |
Rhyme | 0:d895cd1cd897 | 115 | int _readCmdOffset; |
Rhyme | 0:d895cd1cd897 | 116 | |
Rhyme | 0:d895cd1cd897 | 117 | StatusCommand *_txStatus; |
Rhyme | 0:d895cd1cd897 | 118 | StatusCommand *_rxStatus; |
Rhyme | 0:d895cd1cd897 | 119 | |
Rhyme | 0:d895cd1cd897 | 120 | request_t _request; |
Rhyme | 0:d895cd1cd897 | 121 | request_t _requestQueue[REQUEST_QUEUE_SIZE]; |
Rhyme | 0:d895cd1cd897 | 122 | |
Rhyme | 0:d895cd1cd897 | 123 | #ifdef ATTRIBUTE_CLI |
Rhyme | 0:d895cd1cd897 | 124 | int parseCommand(const char *cmd); |
Rhyme | 0:d895cd1cd897 | 125 | #endif |
Rhyme | 0:d895cd1cd897 | 126 | |
Rhyme | 0:d895cd1cd897 | 127 | void sendCommand(void); |
Rhyme | 0:d895cd1cd897 | 128 | |
Rhyme | 0:d895cd1cd897 | 129 | void runStateMachine(void); |
Rhyme | 0:d895cd1cd897 | 130 | |
Rhyme | 0:d895cd1cd897 | 131 | void printState(int state); |
Rhyme | 0:d895cd1cd897 | 132 | |
Rhyme | 0:d895cd1cd897 | 133 | //void beginSPI(); |
Rhyme | 0:d895cd1cd897 | 134 | |
Rhyme | 0:d895cd1cd897 | 135 | //void endSPI(); |
Rhyme | 0:d895cd1cd897 | 136 | |
Rhyme | 0:d895cd1cd897 | 137 | int exchangeStatus(StatusCommand *tx, StatusCommand *rx); |
Rhyme | 0:d895cd1cd897 | 138 | |
Rhyme | 0:d895cd1cd897 | 139 | bool inSync(StatusCommand *tx, StatusCommand *rx); |
Rhyme | 0:d895cd1cd897 | 140 | |
Rhyme | 0:d895cd1cd897 | 141 | int writeStatus(StatusCommand *c); |
Rhyme | 0:d895cd1cd897 | 142 | |
Rhyme | 0:d895cd1cd897 | 143 | void sendBytes(); |
Rhyme | 0:d895cd1cd897 | 144 | |
Rhyme | 0:d895cd1cd897 | 145 | void recvBytes(); |
Rhyme | 0:d895cd1cd897 | 146 | |
Rhyme | 0:d895cd1cd897 | 147 | void dumpBytes(char *label, int len, uint8_t *bytes); |
Rhyme | 0:d895cd1cd897 | 148 | |
Rhyme | 0:d895cd1cd897 | 149 | void updateIntsPending(int amount); |
Rhyme | 0:d895cd1cd897 | 150 | |
Rhyme | 0:d895cd1cd897 | 151 | void queueInit(void); |
Rhyme | 0:d895cd1cd897 | 152 | |
Rhyme | 0:d895cd1cd897 | 153 | int queuePut(uint8_t messageType, uint8_t requestId, const uint16_t attributeId, uint16_t valueLen, const uint8_t *value); |
Rhyme | 0:d895cd1cd897 | 154 | |
Rhyme | 0:d895cd1cd897 | 155 | int queueGet(uint8_t *messageType, uint8_t *requestId, uint16_t *attributeId, uint16_t *valueLen, uint8_t **value); |
Rhyme | 0:d895cd1cd897 | 156 | |
Rhyme | 0:d895cd1cd897 | 157 | int doGetAttribute(uint8_t requestId, uint16_t attrId); |
Rhyme | 0:d895cd1cd897 | 158 | |
Rhyme | 0:d895cd1cd897 | 159 | int doSetAttribute(uint8_t requestId, uint16_t attrId, uint16_t valueLen, uint8_t *value); |
Rhyme | 0:d895cd1cd897 | 160 | |
Rhyme | 0:d895cd1cd897 | 161 | int doUpdateAttribute(uint8_t requestId, uint16_t attrId, uint8_t status, uint16_t valueLen, uint8_t *value); |
Rhyme | 0:d895cd1cd897 | 162 | |
Rhyme | 0:d895cd1cd897 | 163 | void onStateIdle(void); |
Rhyme | 0:d895cd1cd897 | 164 | void onStateSync(void); |
Rhyme | 0:d895cd1cd897 | 165 | void onStateAck(void); |
Rhyme | 0:d895cd1cd897 | 166 | void onStateSendBytes(void); |
Rhyme | 0:d895cd1cd897 | 167 | void onStateRecvBytes(void); |
Rhyme | 0:d895cd1cd897 | 168 | void onStateCmdComplete(void); |
Rhyme | 0:d895cd1cd897 | 169 | void printTransaction(uint8_t *rbytes, int len); |
Rhyme | 0:d895cd1cd897 | 170 | InterruptIn fco; |
Rhyme | 0:d895cd1cd897 | 171 | }; |
Rhyme | 0:d895cd1cd897 | 172 | |
Rhyme | 0:d895cd1cd897 | 173 | #endif // AFLIB_H__ |