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) 反転させることにより、疑似リセットクロックを生成します。

その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。

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?

UserRevisionLine numberNew 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 /**
Rhyme 0:d895cd1cd897 18 * afLib public interface
Rhyme 0:d895cd1cd897 19 *
Rhyme 0:d895cd1cd897 20 * This file defines everything your application should need for commuinicating with the Afero ASR-1 radio module.
Rhyme 0:d895cd1cd897 21 * Is there is anything missing from this file, please post a request on the developer forum and we will see what
Rhyme 0:d895cd1cd897 22 * we can do.
Rhyme 0:d895cd1cd897 23 */
Rhyme 0:d895cd1cd897 24 #ifndef AFLIB_IAFLIB_H
Rhyme 0:d895cd1cd897 25 #define AFLIB_IAFLIB_H
Rhyme 0:d895cd1cd897 26
Rhyme 0:d895cd1cd897 27 #include "mbed.h"
Rhyme 0:d895cd1cd897 28 #include <string>
Rhyme 0:d895cd1cd897 29 using namespace std;
Rhyme 0:d895cd1cd897 30 #include "afErrors.h"
Rhyme 0:d895cd1cd897 31 #include "afSPI.h"
Rhyme 0:d895cd1cd897 32
Rhyme 0:d895cd1cd897 33 #if defined (TARGET_TEENSY3_1)
Rhyme 0:d895cd1cd897 34 #include "USBSerial.h"
Rhyme 0:d895cd1cd897 35 #endif
Rhyme 0:d895cd1cd897 36
Rhyme 0:d895cd1cd897 37 #define afMINIMUM_TIME_BETWEEN_REQUESTS 1000
Rhyme 0:d895cd1cd897 38
Rhyme 0:d895cd1cd897 39 #define MAX_ATTRIBUTE_SIZE 255
Rhyme 0:d895cd1cd897 40
Rhyme 0:d895cd1cd897 41 typedef void (*isr)();
Rhyme 0:d895cd1cd897 42 typedef void (*onAttributeSet)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value);
Rhyme 0:d895cd1cd897 43 typedef void (*onAttributeSetComplete)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value);
Rhyme 0:d895cd1cd897 44
Rhyme 0:d895cd1cd897 45 class iafLib {
Rhyme 0:d895cd1cd897 46 public:
Rhyme 0:d895cd1cd897 47 /**
Rhyme 0:d895cd1cd897 48 * create
Rhyme 0:d895cd1cd897 49 *
Rhyme 0:d895cd1cd897 50 * Create an instance of the afLib object. The afLib is a singleton. Calling this method multiple
Rhyme 0:d895cd1cd897 51 * times will return the same instance.
Rhyme 0:d895cd1cd897 52 *
Rhyme 0:d895cd1cd897 53 * @param mcuInterrupt The Arduino interrupt to be used (returned from digitalPinToInterrupt)
Rhyme 0:d895cd1cd897 54 * @param isrWrapper This is the isr method that must be defined in your sketch
Rhyme 0:d895cd1cd897 55 * @param attrSet Callback for notification of attribute set requests
Rhyme 0:d895cd1cd897 56 * @param attrSetComplete Callback for notification of attribute set request completions
Rhyme 0:d895cd1cd897 57 * @return iafLib * Instance of iafLib
Rhyme 0:d895cd1cd897 58 */
Rhyme 0:d895cd1cd897 59 static iafLib * create(PinName mcuInterrupt, isr isrWrapper,
Rhyme 0:d895cd1cd897 60 onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI);
Rhyme 0:d895cd1cd897 61
Rhyme 0:d895cd1cd897 62 //wsugi 20161128
Rhyme 0:d895cd1cd897 63 static void destroy();
Rhyme 0:d895cd1cd897 64
Rhyme 0:d895cd1cd897 65 /**
Rhyme 0:d895cd1cd897 66 * loop
Rhyme 0:d895cd1cd897 67 *
Rhyme 0:d895cd1cd897 68 * Called by the loop() method in your sketch to give afLib some CPU time
Rhyme 0:d895cd1cd897 69 */
Rhyme 0:d895cd1cd897 70 virtual void loop(void) = 0;
Rhyme 0:d895cd1cd897 71
Rhyme 0:d895cd1cd897 72 /**
Rhyme 0:d895cd1cd897 73 * getAttribute
Rhyme 0:d895cd1cd897 74 *
Rhyme 0:d895cd1cd897 75 * Request the value of an attribute be returned from the ASR-1.
Rhyme 0:d895cd1cd897 76 * Value will be returned in the attrSetComplete callback.
Rhyme 0:d895cd1cd897 77 */
Rhyme 0:d895cd1cd897 78 virtual int getAttribute(const uint16_t attrId) = 0;
Rhyme 0:d895cd1cd897 79
Rhyme 0:d895cd1cd897 80 /**
Rhyme 0:d895cd1cd897 81 * setAttribute
Rhyme 0:d895cd1cd897 82 *
Rhyme 0:d895cd1cd897 83 * Request setting an attribute.
Rhyme 0:d895cd1cd897 84 * For MCU attributes, the attribute value will be updated.
Rhyme 0:d895cd1cd897 85 * For IO attributes, the attribute value will be updated, and then onAttrSetComplete will be called.
Rhyme 0:d895cd1cd897 86 */
Rhyme 0:d895cd1cd897 87 virtual int setAttributeBool(const uint16_t attrId, const bool value) = 0;
Rhyme 0:d895cd1cd897 88
Rhyme 0:d895cd1cd897 89 virtual int setAttribute8(const uint16_t attrId, const int8_t value) = 0;
Rhyme 0:d895cd1cd897 90
Rhyme 0:d895cd1cd897 91 virtual int setAttribute16(const uint16_t attrId, const int16_t value) = 0;
Rhyme 0:d895cd1cd897 92
Rhyme 0:d895cd1cd897 93 virtual int setAttribute32(const uint16_t attrId, const int32_t value) = 0;
Rhyme 0:d895cd1cd897 94
Rhyme 0:d895cd1cd897 95 virtual int setAttribute64(const uint16_t attrId, const int64_t value) = 0;
Rhyme 0:d895cd1cd897 96
Rhyme 0:d895cd1cd897 97 virtual int setAttribute(const uint16_t attrId, const string &value) = 0;
Rhyme 0:d895cd1cd897 98
Rhyme 0:d895cd1cd897 99 virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value) = 0;
Rhyme 0:d895cd1cd897 100
Rhyme 0:d895cd1cd897 101 virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value) = 0;
Rhyme 0:d895cd1cd897 102
Rhyme 0:d895cd1cd897 103 /**
Rhyme 0:d895cd1cd897 104 * setAttributeComplete
Rhyme 0:d895cd1cd897 105 *
Rhyme 0:d895cd1cd897 106 * Call this in response to an onAttrSet. This lets the ASR-1 know that the set request has been handled.
Rhyme 0:d895cd1cd897 107 */
Rhyme 0:d895cd1cd897 108 virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value) = 0;
Rhyme 0:d895cd1cd897 109
Rhyme 0:d895cd1cd897 110 /**
Rhyme 0:d895cd1cd897 111 * isIdle
Rhyme 0:d895cd1cd897 112 *
Rhyme 0:d895cd1cd897 113 * Call to find out of the ASR-1 is currently handling a request.
Rhyme 0:d895cd1cd897 114 *
Rhyme 0:d895cd1cd897 115 * @return true if an operation is in progress
Rhyme 0:d895cd1cd897 116 */
Rhyme 0:d895cd1cd897 117 virtual bool isIdle() = 0;
Rhyme 0:d895cd1cd897 118
Rhyme 0:d895cd1cd897 119 /**
Rhyme 0:d895cd1cd897 120 * mcuISR
Rhyme 0:d895cd1cd897 121 *
Rhyme 0:d895cd1cd897 122 * Called by your sketch to pass the interrupt along to afLib.
Rhyme 0:d895cd1cd897 123 */
Rhyme 0:d895cd1cd897 124 virtual void mcuISR() = 0;
Rhyme 0:d895cd1cd897 125 };
Rhyme 0:d895cd1cd897 126 #endif //AFLIB_IAFLIB_H